33import fi .helsinki .cs .tmc .langs .java .exception .MavenExecutorException ;
44
55import com .google .common .base .Preconditions ;
6+
7+ import org .apache .commons .lang3 .SystemUtils ;
68import org .apache .maven .shared .invoker .DefaultInvocationRequest ;
79import org .apache .maven .shared .invoker .DefaultInvoker ;
810import org .apache .maven .shared .invoker .InvocationOutputHandler ;
911import org .apache .maven .shared .invoker .InvocationRequest ;
1012import org .apache .maven .shared .invoker .InvocationResult ;
1113import org .apache .maven .shared .invoker .MavenInvocationException ;
12-
1314import org .codehaus .plexus .util .cli .CommandLineException ;
14-
1515import org .rauschig .jarchivelib .ArchiveFormat ;
1616import org .rauschig .jarchivelib .Archiver ;
1717import org .rauschig .jarchivelib .ArchiverFactory ;
2929import java .nio .file .StandardCopyOption ;
3030import java .util .Arrays ;
3131
32+
3233public 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