Skip to content

Commit 08d4a02

Browse files
Merge pull request #589 from n0tl3ss/stale-files
2 parents 6db59ba + ca05132 commit 08d4a02

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationFunctionalTest.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ class JavaApplicationFunctionalTest extends AbstractGraalVMMavenFunctionalTest {
121121
then:
122122
buildSucceeded
123123
outputContains "Args file written to: target" + File.separator + "native-image"
124+
125+
when:
126+
mvn '-DquickBuild', '-Pnative', 'native:write-args-file'
127+
128+
then:
129+
buildSucceeded
130+
outputContains "Args file written to: target" + File.separator + "native-image"
131+
file("target/").listFiles().findAll(x->x.name.contains("native-image") && x.name.endsWith(".args")).size() == 1
124132
}
125133
126134
}

native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/WriteArgsFileMojo.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@
4747
import org.graalvm.buildtools.utils.NativeImageUtils;
4848

4949
import java.io.File;
50+
import java.io.IOException;
51+
import java.nio.file.Files;
52+
import java.nio.file.Path;
5053
import java.util.List;
54+
import java.util.stream.Stream;
5155

5256
/**
5357
* Persists the arguments file to be used by the native-image command. This can be useful in situations where
@@ -67,6 +71,24 @@ public class WriteArgsFileMojo extends NativeCompileNoForkMojo {
6771
@Override
6872
public void execute() throws MojoExecutionException {
6973
List<String> args = getBuildArgs();
74+
75+
getLog().debug("Cleaning old native image build args");
76+
77+
try (Stream<Path> listStream = Files.list(outputDirectory.toPath())) {
78+
listStream.map(path -> path.getFileName().toString())
79+
.filter(f -> f.startsWith("native-image") && f.endsWith("args"))
80+
.map(outputDirectory.toPath()::resolve)
81+
.forEach(file -> {
82+
try {
83+
Files.delete(file);
84+
} catch (IOException e) {
85+
throw new RuntimeException(e);
86+
}
87+
});
88+
} catch (IOException e) {
89+
throw new MojoExecutionException(e);
90+
}
91+
7092
List<String> conversionResult = NativeImageUtils.convertToArgsFile(args, outputDirectory.toPath());
7193
if (conversionResult.size() == 1) {
7294
String argsFileName = conversionResult.get(0).replace("@", "");

0 commit comments

Comments
 (0)