To give even more color: here is something I am doodling on:
package dev.mccue.build.java;
import dev.mccue.build.Target;
import dev.mccue.build.file.FileTimes;
import dev.mccue.build.file.PathTarget;
import dev.mccue.tools.javac.Javac;
import dev.mccue.tools.javac.JavacArguments;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
public final class JavacTarget implements Target {
final ArrayList<Path> inputPaths = new ArrayList<>();
final ArrayList<Path> outputPaths = new ArrayList<>();
void parseArgs(List<String> arguments) {
String moduleSourcePath = null;
String module = null;
var iter = arguments.iterator();
while (iter.hasNext()) {
var arg = iter.next();
if (arg.startsWith("@")) {
//TODO: load and parse argfile
inputPaths.add(Path.of(arg.substring(1))); // Argument file
}
else if (arg.equals("-p")
|| arg.equals("-cp")
|| arg.equals("--class-path")
|| arg.equals("-classpath")
|| arg.equals("--boot-class-path")
|| arg.equals("-bootclasspath")
|| arg.equals("--module-path")
|| arg.equals("--upgrade-module-path")
|| arg.equals("--source-path")
|| arg.equals("-sourcepath")
|| arg.equals("-processorpath")
|| arg.equals("--processor-path")
|| arg.equals("--processor-module-path")
|| arg.equals("-extdirs")) {
if (iter.hasNext()) {
Arrays.stream(iter.next().split(File.pathSeparator))
.forEach(path -> inputPaths.add(Path.of(path)));
}
}
else if (arg.equals("--module-source-path")) {
if (iter.hasNext()) {
moduleSourcePath = iter.next();
}
}
else if (arg.equals("-m") || arg.equals("--module")) {
if (iter.hasNext()) {
module = iter.next();
}
}
else if (arg.equals("-d")) {
if (iter.hasNext()) {
outputPaths.add(Path.of(iter.next()));
}
}
else if (arg.equals("-s")) {
if (iter.hasNext()) {
outputPaths.add(Path.of(iter.next()));
}
}
else if (arg.equals("-h")) {
if (iter.hasNext()) {
outputPaths.add(Path.of(iter.next()));
}
}
else if (arg.startsWith("-A")) {
}
else if (arg.startsWith("--add-modules")) {
if (iter.hasNext()) {
iter.next();
}
}
else if (arg.startsWith("-deprecation")) {
}
else if (arg.startsWith("--enable-preview")) {
}
else if (arg.startsWith("-encoding")) {
if (iter.hasNext()) {
iter.next();
}
}
else if (arg.startsWith("-g")) {
}
else if (arg.startsWith("--help")) {
}
else if (arg.startsWith("-help")) {
}
else if (arg.startsWith("-?")) {
}
else if (arg.startsWith("--help-extra")) {
}
else if (arg.startsWith("-X")) {
}
else if (arg.startsWith("--help-lint")) {
}
else if (arg.startsWith("-implicit:")) {
}
else if (arg.startsWith("-J")) {
}
else if (arg.startsWith("--limit-modules")) {
if (iter.hasNext()) {
iter.next();
}
}
else if (arg.startsWith("--module-version")) {
if (iter.hasNext()) {
iter.next();
}
}
else if (arg.startsWith("-nowarn")) {
}
else if (arg.startsWith("-parameters")) {
}
else if (arg.startsWith("-proc:")) {
}
else if (arg.startsWith("-processor")) {
if (iter.hasNext()) {
iter.next();
}
}
else if (arg.startsWith("-profile")) {
if (iter.hasNext()) {
iter.next();
}
}
else if (arg.startsWith("--release")) {
if (iter.hasNext()) {
iter.next();
}
}
else if (arg.startsWith("-source")) {
if (iter.hasNext()) {
iter.next();
}
}
else if (arg.startsWith("--source")) {
if (iter.hasNext()) {
iter.next();
}
}
else if (arg.startsWith("-system")) {
if (iter.hasNext()) {
iter.next();
}
}
else if (arg.startsWith("--target")) {
if (iter.hasNext()) {
iter.next();
}
}
else if (arg.startsWith("-target")) {
if (iter.hasNext()) {
iter.next();
}
}
else if (arg.startsWith("-verbose")) {
}
else if (arg.startsWith("--version")) {
}
else if (arg.startsWith("-version")) {
}
else if (arg.startsWith("-W")) {
}
else {
inputPaths.add(Path.of(arg));
}
if (module != null && moduleSourcePath != null) {
var modules = module.split(",");
for (var m : modules) {
if (moduleSourcePath.contains("*")) {
inputPaths.add(Path.of(moduleSourcePath.replaceFirst("\\*", m)));
}
else {
inputPaths.add(Path.of(moduleSourcePath, m));
}
}
}
}
}
private final JavacArguments arguments = new JavacArguments();
private final List<Target> dependencies = new ArrayList<>();
public JavacTarget() {
}
public JavacTarget(Consumer<? super JavacArguments> consumer) {
consumer.accept(arguments);
parseArgs(this.arguments);
}
public JavacTarget(List<String> arguments) {
this.arguments.addAll(arguments);
parseArgs(this.arguments);
}
public JavacArguments arguments() {
return arguments;
}
@Override
public boolean isUpToDate() throws Exception {
var in = FileTimes.newestFileTime(inputPaths).orElse(null);
var out = FileTimes.newestFileTime(outputPaths).orElse(null);
if (in != null && out != null) {
return in.compareTo(out) < 0;
}
else {
return false;
}
}
@Override
public List<Target> dependencies() {
return outputPaths.stream().<Target>map(PathTarget::cleanDirectory).toList();
}
@Override
public void build() throws Exception {
Javac.run(arguments);
}
@Override
public String toString() {
return "JavacTarget[arguments=" + arguments + ", input=" + inputPaths + ", output=" + outputPaths + "]";
}
}
Hypothetically, you can look at the arguments you would pass to javac and work backwards to what files/folders you need to check for staleness or clear out before running.
View all comments
Show parent comment
-5
u/bowbahdoe Jul 11 '26
To give even more color: here is something I am doodling on:
Hypothetically, you can look at the arguments you would pass to
javacand work backwards to what files/folders you need to check for staleness or clear out before running.You could make a whole program that is just