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>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version> <!-- Check for the latest version -->
</dependency>
</dependencies>
<build>

View File

@ -10,9 +10,13 @@ import de.maishai.typedast.typedclass.TypedClass;
import de.maishai.typedast.typedclass.TypedProgram;
import org.antlr.v4.runtime.*;
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.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Formatter;
import java.util.logging.Handler;
@ -137,9 +141,27 @@ public class Compiler {
List<String> sourcePaths = new ArrayList<>();
for (String arg : cmd.getArgs()) {
String sourcePath = arg.endsWith(JAVA_FILE_EXTENSION) ? arg : arg + JAVA_FILE_EXTENSION;
sourcePaths.add(sourcePath);
if (arg.contains("*")) {
sourcePaths.addAll(expandWildcards(arg));
} else {
String sourcePath = arg.endsWith(JAVA_FILE_EXTENSION) ? arg : arg + JAVA_FILE_EXTENSION;
sourcePaths.add(sourcePath);
}
}
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;
}
}