Skip to content

Commit

Permalink
write-args-file task should delete old stale args file before generat…
Browse files Browse the repository at this point in the history
…ing a new one
  • Loading branch information
n0tl3ss committed Apr 1, 2024
1 parent 6db59ba commit 5ffff01
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ class JavaApplicationFunctionalTest extends AbstractGraalVMMavenFunctionalTest {
then:
buildSucceeded
outputContains "Args file written to: target" + File.separator + "native-image"
when:
mvn '-DquickBuild', '-Pnative', 'native:write-args-file'
then:
buildSucceeded
outputContains "Args file written to: target" + File.separator + "native-image"
file("target/").listFiles().findAll(x->x.name.contains("native-image") && x.name.endsWith(".args")).size() == 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
import org.graalvm.buildtools.utils.NativeImageUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Stream;

/**
* Persists the arguments file to be used by the native-image command. This can be useful in situations where
Expand All @@ -67,6 +71,24 @@ public class WriteArgsFileMojo extends NativeCompileNoForkMojo {
@Override
public void execute() throws MojoExecutionException {
List<String> args = getBuildArgs();

getLog().info("Cleaning old native image build args");

try (Stream<Path> listStream = Files.list(outputDirectory.toPath())) {
listStream.map(path -> path.getFileName().toString())
.filter(f -> f.startsWith("native-image") && f.endsWith("args"))
.map(outputDirectory.toPath()::resolve)
.forEach(file -> {
try {
Files.delete(file);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}

List<String> conversionResult = NativeImageUtils.convertToArgsFile(args, outputDirectory.toPath());
if (conversionResult.size() == 1) {
String argsFileName = conversionResult.get(0).replace("@", "");
Expand Down

0 comments on commit 5ffff01

Please sign in to comment.