add wildcard support from commandline

This commit is contained in:
simon 2024-07-04 16:30:39 +02:00
parent e4d3f1a141
commit 68e1f59ccc
2 changed files with 29 additions and 2 deletions

View File

@ -93,6 +93,11 @@
<artifactId>commons-cli</artifactId> <artifactId>commons-cli</artifactId>
<version>1.8.0</version> <version>1.8.0</version>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version> <!-- Check for the latest version -->
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -10,9 +10,13 @@ import de.maishai.typedast.typedclass.TypedClass;
import de.maishai.typedast.typedclass.TypedProgram; import de.maishai.typedast.typedclass.TypedProgram;
import org.antlr.v4.runtime.*; import org.antlr.v4.runtime.*;
import org.apache.commons.cli.*; import org.apache.commons.cli.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.logging.Formatter; import java.util.logging.Formatter;
import java.util.logging.Handler; import java.util.logging.Handler;
@ -137,9 +141,27 @@ public class Compiler {
List<String> sourcePaths = new ArrayList<>(); List<String> sourcePaths = new ArrayList<>();
for (String arg : cmd.getArgs()) { for (String arg : cmd.getArgs()) {
if (arg.contains("*")) {
sourcePaths.addAll(expandWildcards(arg));
} else {
String sourcePath = arg.endsWith(JAVA_FILE_EXTENSION) ? arg : arg + JAVA_FILE_EXTENSION; String sourcePath = arg.endsWith(JAVA_FILE_EXTENSION) ? arg : arg + JAVA_FILE_EXTENSION;
sourcePaths.add(sourcePath); sourcePaths.add(sourcePath);
} }
}
generateByteCodeFilesFromFiles(sourcePaths); generateByteCodeFilesFromFiles(sourcePaths);
} }
private static List<String> expandWildcards(String pattern) {
List<String> matchingFiles = new ArrayList<>();
try {
File dir = new File(".");
Collection<File> files = FileUtils.listFiles(dir, new WildcardFileFilter(pattern), null);
for (File file : files) {
matchingFiles.add(file.getPath());
}
} catch (Exception e) {
LOGGER.severe("Error expanding wildcards: " + e.getMessage());
}
return matchingFiles;
}
} }