3
3
import fi .helsinki .cs .tmc .langs .java .exception .MavenExecutorException ;
4
4
5
5
import com .google .common .base .Preconditions ;
6
+
7
+ import org .apache .commons .lang3 .SystemUtils ;
6
8
import org .apache .maven .shared .invoker .DefaultInvocationRequest ;
7
9
import org .apache .maven .shared .invoker .DefaultInvoker ;
8
10
import org .apache .maven .shared .invoker .InvocationOutputHandler ;
9
11
import org .apache .maven .shared .invoker .InvocationRequest ;
10
12
import org .apache .maven .shared .invoker .InvocationResult ;
11
13
import org .apache .maven .shared .invoker .MavenInvocationException ;
12
-
13
14
import org .codehaus .plexus .util .cli .CommandLineException ;
14
-
15
15
import org .rauschig .jarchivelib .ArchiveFormat ;
16
16
import org .rauschig .jarchivelib .Archiver ;
17
17
import org .rauschig .jarchivelib .ArchiverFactory ;
29
29
import java .nio .file .StandardCopyOption ;
30
30
import java .util .Arrays ;
31
31
32
+
32
33
public class MavenInvokatorMavenTaskRunner implements MavenTaskRunner {
33
34
34
35
private static final Logger log = LoggerFactory .getLogger (MavenInvokatorMavenTaskRunner .class );
@@ -104,16 +105,20 @@ private Path useBundledMaven() {
104
105
}
105
106
log .info ("Maven bundle not previously extracted, extracting..." );
106
107
try {
107
-
108
108
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" );
112
112
Files .copy (data , tmpFile , StandardCopyOption .REPLACE_EXISTING );
113
113
Archiver archiver = ArchiverFactory .createArchiver (ArchiveFormat .ZIP );
114
114
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
+ }
115
120
116
- // Add the name of the extracted folder to the path
121
+ // Add the name of the extracted folder to the path
117
122
return mavenHome .resolve ("apache-maven-3.3.9" );
118
123
} catch (IOException e ) {
119
124
throw new RuntimeException (e );
@@ -123,7 +128,7 @@ private Path useBundledMaven() {
123
128
static Path getConfigDirectory () {
124
129
Path configPath ;
125
130
126
- if (System . getProperty ( "os.name" ). toLowerCase (). contains ( "windows" ) ) {
131
+ if (SystemUtils . IS_OS_WINDOWS ) {
127
132
String appdata = System .getenv ("APPDATA" );
128
133
if (appdata == null ) {
129
134
configPath = Paths .get (System .getProperty ("user.home" ));
@@ -142,5 +147,4 @@ static Path getConfigDirectory() {
142
147
}
143
148
return configPath .resolve ("tmc" );
144
149
}
145
-
146
150
}
0 commit comments