فهرست منبع

Fix build command.

HorridoJoho 3 سال پیش
والد
کامیت
a89fb48b7f

+ 6 - 0
pom.xml

@@ -24,6 +24,7 @@
 		<asciitable.version>0.3.2</asciitable.version>
 		<owner.version>1.0.12</owner.version>
 		<l2j-server-commons.version>2.6.3.0</l2j-server-commons.version>
+		<maven-invoker.version>3.2.0</maven-invoker.version>
 		<!-- Plugins -->
 		<maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
 		<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
@@ -108,6 +109,11 @@
 			<artifactId>owner-java8</artifactId>
 			<version>${owner.version}</version>
 		</dependency>
+		<dependency>
+            <groupId>org.apache.maven.shared</groupId>
+            <artifactId>maven-invoker</artifactId>
+            <version>${maven-invoker.version}</version>
+        </dependency>
 	</dependencies>
 	<build>
 		<plugins>

+ 1 - 1
src/main/java/com/l2jserver/cli/L2JServerCLI.java

@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 L2J Server
+ * Copyright © 2019-2022 L2J Server
  *
  * This file is part of L2J Server.
  *

+ 31 - 7
src/main/java/com/l2jserver/cli/command/BuildCommand.java

@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 L2J Server
+ * Copyright © 2019-2022 L2J Server
  *
  * This file is part of L2J Server.
  *
@@ -18,8 +18,15 @@
  */
 package com.l2jserver.cli.command;
 
-import java.io.IOException;
+import java.io.File;
+import java.util.Collections;
+import java.util.Properties;
 
+import org.apache.maven.shared.invoker.DefaultInvocationRequest;
+import org.apache.maven.shared.invoker.DefaultInvoker;
+import org.apache.maven.shared.invoker.InvocationRequest;
+import org.apache.maven.shared.invoker.Invoker;
+import org.apache.maven.shared.invoker.MavenInvocationException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -34,22 +41,39 @@ import picocli.CommandLine.Command;
  */
 @Command(name = "build", aliases = "b")
 public class BuildCommand extends AbstractCommand {
-    
+
     private static final Logger LOG = LoggerFactory.getLogger(BuildCommand.class);
 
     @Override
     public void run() {
         try {
+            boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
+
+            Properties properties = new Properties();
+            properties.setProperty("skipTests", "true");
+
             System.out.println("Building L2J Loginserver");
-            Runtime.getRuntime().exec(L2JServerCLI.DEFAULT_LOGIN_SOURCE_DIR + "/mvnw install -DskipTests");
+            executeMavenWrapper("install", L2JServerCLI.DEFAULT_LOGIN_SOURCE_DIR, properties, isWindows);
 
             System.out.println("Building L2J Gameserver");
-            Runtime.getRuntime().exec(L2JServerCLI.DEFAULT_LOGIN_SOURCE_DIR + "/mvnw install -DskipTests");
+            executeMavenWrapper("install", L2JServerCLI.DEFAULT_GAME_SOURCE_DIR, properties, isWindows);
 
             System.out.println("Building L2J DataPack");
-            Runtime.getRuntime().exec(L2JServerCLI.DEFAULT_DATAPACK_SOURCE_DIR + "/mvnw compile -DskipTests");
-        } catch (IOException e) {
+            executeMavenWrapper("compile", L2JServerCLI.DEFAULT_DATAPACK_SOURCE_DIR, properties, isWindows);
+        } catch (Exception e) {
             LOG.error("Unable to build the code!", e);
         }
     }
+
+    private final void executeMavenWrapper(String goal, String sourceDir, Properties properties, boolean isWindows)
+            throws MavenInvocationException {
+        InvocationRequest request = new DefaultInvocationRequest();
+        request.setPomFile(new File(sourceDir + "/pom.xml"));
+        request.setGoals(Collections.singletonList("install"));
+        request.setProperties(properties);
+        Invoker invoker = new DefaultInvoker();
+        invoker.setMavenHome(new File(sourceDir));
+        invoker.setMavenExecutable(new File("mvnw" + (isWindows ? ".cmd" : "")));
+        invoker.execute(request);
+    }
 }

+ 1 - 1
src/main/java/com/l2jserver/cli/command/CodeCommand.java

@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 L2J Server
+ * Copyright © 2019-2022 L2J Server
  *
  * This file is part of L2J Server.
  *

+ 1 - 1
src/main/java/com/l2jserver/cli/model/CloneType.java

@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 L2J Server
+ * Copyright © 2019-2022 L2J Server
  *
  * This file is part of L2J Server.
  *