Skip to content

Commit

Permalink
Merge pull request #589 from n0tl3ss/stale-files
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosanchez authored Apr 3, 2024
2 parents 6db59ba + ca05132 commit 08d4a02
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().debug("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 MojoExecutionException(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 08d4a02

Please sign in to comment.