Forráskód Böngészése

Fixed and extended some commands.

code command:
+ Added short names for all options.

build command:
+ Added options for the source directories.
+ Added an option to skip tests. By default, tests are executed.
* Actually fix maven wrapper execution flag on unix systems.

deploy command:
+ Added options for the source directories.
+ Added options for the deploy directories.
HorridoJoho 2 éve
szülő
commit
a30bae7775

+ 23 - 10
src/main/java/com/l2jserver/cli/command/BuildCommand.java

@@ -26,11 +26,11 @@ 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;
 
 import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
 
 /**
  * Build command.
@@ -43,39 +43,52 @@ public class BuildCommand extends AbstractCommand {
 
 	private static final Logger LOG = LoggerFactory.getLogger(BuildCommand.class);
 
+	@Option(names = {"--login-directory", "-lsdir"}, defaultValue = DEFAULT_LOGIN_SOURCE_DIR, description = "Login directory")
+	private String loginDirectory = DEFAULT_LOGIN_SOURCE_DIR;
+	@Option(names = {"--game-directory", "-gsdir"}, defaultValue = DEFAULT_GAME_SOURCE_DIR, description = "Game directory")
+	private String gameDirectory = DEFAULT_GAME_SOURCE_DIR;
+	@Option(names = {"--datapack-directory", "-dpdir"}, defaultValue = DEFAULT_DATAPACK_SOURCE_DIR, description = "DataPack directory")
+	private String datapackDirectory = DEFAULT_DATAPACK_SOURCE_DIR;
+	
+	@Option(names = {"--skip-tests", "-st"}, defaultValue = "true", description = "Skip Tests")
+	private boolean skipTests = true;
+
 	@Override
 	public void run() {
 		try {
 			boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
 
 			Properties properties = new Properties();
-			properties.setProperty("skipTests", "true");
+			if (skipTests) {
+				properties.setProperty("skipTests", "true");
+			}
 
 			System.out.println("Building L2J Loginserver");
-			executeMavenWrapper("install", DEFAULT_LOGIN_SOURCE_DIR, properties, isWindows);
+			executeMavenWrapper("install", loginDirectory, properties, isWindows);
 
 			System.out.println("Building L2J Gameserver");
-			executeMavenWrapper("install", DEFAULT_GAME_SOURCE_DIR, properties, isWindows);
+			executeMavenWrapper("install", gameDirectory, properties, isWindows);
 
 			System.out.println("Building L2J DataPack");
-			executeMavenWrapper("install", DEFAULT_DATAPACK_SOURCE_DIR, properties, isWindows);
+			executeMavenWrapper("install", datapackDirectory, 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 {
-		File mavenExecutable = new File("mvnw" + (isWindows ? ".cmd" : ""));
-		mavenExecutable.setExecutable(true);
+	        throws Exception {
+		String mavenExecutableName = "mvnw" + (isWindows ? ".cmd" : "");
+		File mavenExecutableFile = new File(sourceDir, mavenExecutableName).getAbsoluteFile();
+		mavenExecutableFile.setExecutable(true);
 		
 		InvocationRequest request = new DefaultInvocationRequest();
-		request.setPomFile(new File(sourceDir + "/pom.xml"));
+		request.setPomFile(new File(sourceDir, "pom.xml"));
 		request.setGoals(Collections.singletonList(goal));
 		request.setProperties(properties);
 		Invoker invoker = new DefaultInvoker();
 		invoker.setMavenHome(new File(sourceDir));
-		invoker.setMavenExecutable(mavenExecutable);
+		invoker.setMavenExecutable(mavenExecutableFile);
 		invoker.execute(request);
 	}
 }

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

@@ -43,19 +43,19 @@ public class CodeCommand extends AbstractCommand {
 
 	private static final LoggerProgressMonitor LOGGER_PROGRESS_MONITOR = new LoggerProgressMonitor(LOG);
 
-	@Option(names = "--login-repository", defaultValue = DEFAULT_LOGIN_REPO, description = "Login repository")
+	@Option(names = {"--login-repository", "-lsrepo"}, defaultValue = DEFAULT_LOGIN_REPO, description = "Login repository")
 	private String loginRepository = DEFAULT_LOGIN_REPO;
-	@Option(names = "--game-repository", defaultValue = DEFAULT_GAME_REPO, description = "Game repository")
+	@Option(names = {"--game-repository", "-gsrepo"}, defaultValue = DEFAULT_GAME_REPO, description = "Game repository")
 	private String gameRepository = DEFAULT_GAME_REPO;
-	@Option(names = "--datapack-repository", defaultValue = DEFAULT_DATAPACK_REPO, description = "Datapack repository")
+	@Option(names = {"--datapack-repository", "-dprepo"}, defaultValue = DEFAULT_DATAPACK_REPO, description = "Datapack repository")
 	private String datapackRepository = DEFAULT_DATAPACK_REPO;
 
-	@Option(names = "--login-directory", defaultValue = DEFAULT_LOGIN_SOURCE_DIR, description = "Login directory")
-	private File loginDirectory = new File(DEFAULT_LOGIN_SOURCE_DIR);
-	@Option(names = "--game-directory", defaultValue = DEFAULT_GAME_SOURCE_DIR, description = "Game directory")
-	private File gameDirectory = new File(DEFAULT_GAME_SOURCE_DIR);
-	@Option(names = "--datapack-directory", defaultValue = DEFAULT_DATAPACK_SOURCE_DIR, description = "DataPack directory")
-	private File datapackDirectory = new File(DEFAULT_DATAPACK_SOURCE_DIR);
+	@Option(names = {"--login-directory", "-lsdir"}, defaultValue = DEFAULT_LOGIN_SOURCE_DIR, description = "Login directory")
+	private String loginDirectory = DEFAULT_LOGIN_SOURCE_DIR;
+	@Option(names = {"--game-directory", "-gsdir"}, defaultValue = DEFAULT_GAME_SOURCE_DIR, description = "Game directory")
+	private String gameDirectory = DEFAULT_GAME_SOURCE_DIR;
+	@Option(names = {"--datapack-directory", "-dpdir"}, defaultValue = DEFAULT_DATAPACK_SOURCE_DIR, description = "DataPack directory")
+	private String datapackDirectory = DEFAULT_DATAPACK_SOURCE_DIR;
 
 	@Option(names = "--clone", defaultValue = "ALL", description = "Clone ALL|LOGIN|GAME|DATAPACK")
 	private CloneType cloneType = CloneType.ALL;
@@ -96,8 +96,9 @@ public class CodeCommand extends AbstractCommand {
 		}
 	}
 
-	private void cloneRepository(String repository, File directory) {
+	private void cloneRepository(String repository, String directoryStr) {
 		try {
+			File directory = new File(directoryStr);
 			if (directory.exists()) {
 				Git.open(directory).pull();
 			} else {

+ 21 - 6
src/main/java/com/l2jserver/cli/command/DeployCommand.java

@@ -32,6 +32,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
 
 /**
  * Deploy command.
@@ -42,25 +43,39 @@ import picocli.CommandLine.Command;
 @Command(name = "deploy", aliases = "d")
 public class DeployCommand extends AbstractCommand {
 	private static final Logger LOG = LoggerFactory.getLogger(DeployCommand.class);
+
+	@Option(names = {"--login-source-directory", "-lssrc"}, defaultValue = DEFAULT_LOGIN_SOURCE_DIR, description = "Login directory")
+	private String loginSourceDirectory = DEFAULT_LOGIN_SOURCE_DIR;
+	@Option(names = {"--game-source-directory", "-gssrc"}, defaultValue = DEFAULT_GAME_SOURCE_DIR, description = "Game directory")
+	private String gameSourceDirectory = DEFAULT_GAME_SOURCE_DIR;
+	@Option(names = {"--datapack-source-directory", "-dpsrc"}, defaultValue = DEFAULT_DATAPACK_SOURCE_DIR, description = "DataPack directory")
+	private String datapackSourceDirectory = DEFAULT_DATAPACK_SOURCE_DIR;
+
+	@Option(names = {"--login-deploy-directory", "-lsdepl"}, defaultValue = DEFAULT_LOGIN_SOURCE_DIR, description = "Login directory")
+	private String loginDeployDirectory = DEFAULT_LOGIN_SOURCE_DIR;
+	@Option(names = {"--game-deploy-directory", "-gsdepl"}, defaultValue = DEFAULT_GAME_SOURCE_DIR, description = "Game directory")
+	private String gameDeployDirectory = DEFAULT_GAME_SOURCE_DIR;
+	@Option(names = {"--datapack-deploy-directory", "-dpdepl"}, defaultValue = DEFAULT_DATAPACK_SOURCE_DIR, description = "DataPack directory")
+	private String datapackDeployDirectory = DEFAULT_DATAPACK_SOURCE_DIR;
 	
 	@Override
 	public void run() {
 		try {
 			LOG.info("Deploying L2J Loginserver");
-			processArtifact(Paths.get(DEFAULT_LOGIN_SOURCE_DIR), Paths.get(DEFAULT_LOGIN_DEPLOY_DIR));
+			processArtifact(loginSourceDirectory, loginDeployDirectory);
 			
 			LOG.info("Deploying L2J Gameserver");
-			processArtifact(Paths.get(DEFAULT_GAME_SOURCE_DIR), Paths.get(DEFAULT_GAME_DEPLOY_DIR));
+			processArtifact(gameSourceDirectory, gameDeployDirectory);
 			
 			LOG.info("Deploying L2J DataPack");
-			processArtifact(Paths.get(DEFAULT_DATAPACK_SOURCE_DIR), Paths.get(DEFAULT_GAME_DEPLOY_DIR));
+			processArtifact(datapackSourceDirectory, datapackDeployDirectory);
 		} catch (Exception e) {
 			LOG.error("Unable to deploy components!", e);
 		}
 	}
 
-	public void processArtifact(Path srcDirPath, Path dstDirPath) throws Exception {
-		Files.list(Paths.get(srcDirPath.toString(), "target")).forEach(p->{
+	public void processArtifact(String srcDirPath, String dstDirPathStr) throws Exception {
+		Files.list(Paths.get(srcDirPath, "target")).forEach(p->{
 			if (!p.toString().endsWith(".zip")) {
 				return;
 			}
@@ -68,7 +83,7 @@ public class DeployCommand extends AbstractCommand {
 			LOG.info("Processing zip file {}", p.toString());
 
 			try {
-				processZip(p, dstDirPath);
+				processZip(p, Path.of(dstDirPathStr));
 			} catch (Exception e) {
 				LOG.error("Unable to process zip file!", e);
 			}

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

@@ -24,8 +24,8 @@ package com.l2jserver.cli.model;
  * @version 1.0.0
  */
 public enum CloneType {
-    ALL,
-    LOGIN,
+	ALL,
+	LOGIN,
 	GAME,
 	DATAPACK
 }