Skip to content

Commit c0c4924

Browse files
committed
Cleanup and remove tmp file
1 parent 53bf89d commit c0c4924

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

tmc-langs-java/src/main/java/fi/helsinki/cs/tmc/langs/java/maven/MavenInvokatorMavenTaskRunner.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import fi.helsinki.cs.tmc.langs.java.exception.MavenExecutorException;
44

55
import com.google.common.base.Preconditions;
6+
7+
import org.apache.commons.lang3.SystemUtils;
68
import org.apache.maven.shared.invoker.DefaultInvocationRequest;
79
import org.apache.maven.shared.invoker.DefaultInvoker;
810
import org.apache.maven.shared.invoker.InvocationOutputHandler;
911
import org.apache.maven.shared.invoker.InvocationRequest;
1012
import org.apache.maven.shared.invoker.InvocationResult;
1113
import org.apache.maven.shared.invoker.MavenInvocationException;
12-
1314
import org.codehaus.plexus.util.cli.CommandLineException;
14-
1515
import org.rauschig.jarchivelib.ArchiveFormat;
1616
import org.rauschig.jarchivelib.Archiver;
1717
import org.rauschig.jarchivelib.ArchiverFactory;
@@ -29,6 +29,7 @@
2929
import java.nio.file.StandardCopyOption;
3030
import java.util.Arrays;
3131

32+
3233
public class MavenInvokatorMavenTaskRunner implements MavenTaskRunner {
3334

3435
private static final Logger log = LoggerFactory.getLogger(MavenInvokatorMavenTaskRunner.class);
@@ -104,16 +105,20 @@ private Path useBundledMaven() {
104105
}
105106
log.info("Maven bundle not previously extracted, extracting...");
106107
try {
107-
108108
InputStream data = getClass().getResourceAsStream("apache-maven-3.3.9.zip");
109-
Preconditions.checkNotNull(data,
110-
"Couldn't load bundled maven from tmc-langs-java.jar.");
111-
Path tmpFile = File.createTempFile("tmc-maven", "zip").toPath();
109+
Preconditions.checkNotNull(
110+
data, "Couldn't load bundled maven from tmc-langs-java.jar.");
111+
Path tmpFile = Files.createTempFile("tmc-maven", "zip");
112112
Files.copy(data, tmpFile, StandardCopyOption.REPLACE_EXISTING);
113113
Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.ZIP);
114114
archiver.extract(tmpFile.toFile(), mavenHome.toFile());
115+
try {
116+
Files.deleteIfExists(tmpFile);
117+
} catch (IOException e) {
118+
log.warn("Deleting tmp apache-maven.zip failed", e);
119+
}
115120

116-
// Add the name of the extracted folder to the path
121+
// Add the name of the extracted folder to the path
117122
return mavenHome.resolve("apache-maven-3.3.9");
118123
} catch (IOException e) {
119124
throw new RuntimeException(e);
@@ -123,7 +128,7 @@ private Path useBundledMaven() {
123128
static Path getConfigDirectory() {
124129
Path configPath;
125130

126-
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
131+
if (SystemUtils.IS_OS_WINDOWS) {
127132
String appdata = System.getenv("APPDATA");
128133
if (appdata == null) {
129134
configPath = Paths.get(System.getProperty("user.home"));
@@ -142,5 +147,4 @@ static Path getConfigDirectory() {
142147
}
143148
return configPath.resolve("tmc");
144149
}
145-
146150
}

0 commit comments

Comments
 (0)