diff --git a/README.md b/README.md index ac4e764..be8c1c4 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ The executable jar file will be created at `target/gis-.jar` For more details, just run: ```shell script -./gis +./gis --help ``` # Comparison @@ -70,3 +70,23 @@ for i in {1..100}; do { time git submodule foreach git fetch; } 2>> git_fe_repor for i in {1..100}; do { time giss fe; } 2>> gis_fe_report done # took 5m11s832ms ``` + +# Code quality + +Use Sonarqube to analyze code: +```shell script +docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:8.9.10-community +``` + +Then go to `http://localhost:9000` +- login (admin/admin), then change your password +- go to `http://localhost:9000/projects` and click "Add a project" +- choose "Manually" +- input "Project key" and "Display name" e.g., "gis" then click "Set Up" +- "Generate a token": enter a name for this token then click "Generate" +- you will get something like this: 302481a5dee289283af983ac713174e2f2ed13da. Click "Continue" +- as shown in the 2nd step, with maven: + ```shell script + mvn sonar:sonar -Dsonar.projectKey=gis -Dsonar.host.url=http://localhost:9000 -Dsonar.login=302481a5dee289283af983ac713174e2f2ed13da + ``` +- after the maven command above succcess, you will have a dashboard about `gis` project diff --git a/src/main/java/org/nqm/command/GitCommand.java b/src/main/java/org/nqm/command/GitCommand.java index c79599a..20a3fd3 100644 --- a/src/main/java/org/nqm/command/GitCommand.java +++ b/src/main/java/org/nqm/command/GitCommand.java @@ -26,6 +26,7 @@ public class GitCommand { private static final String ALL_MODULES = "***"; private static final String ALL_SUBMODULES = "/**"; + private static final String ORIGIN = "origin"; public static final String GIT_STATUS = "status"; @@ -50,7 +51,7 @@ void fetch() { @Command(name = "fetch-origin", aliases = "fo") void fetchOrigin(@Parameters(index = "0", paramLabel = "") String branch) { - forEachModuleDo(path -> deployVertx(path, "fetch", "origin", "%s:%s".formatted(branch, branch))); + forEachModuleDo(path -> deployVertx(path, "fetch", ORIGIN, "%s:%s".formatted(branch, branch))); } @Command(name = "checkout", aliases = "co") @@ -114,7 +115,7 @@ void push(@Parameters(index = "0", paramLabel = "") String branch, if (!isConfirmed("Sure you want to push to remote '%s' [Y/n]".formatted(branch))) { return; } - var args = isNewRemoteBranch ? new String[] { "push", "-u", "origin", branch } : shouldForcePush(isForce); + var args = isNewRemoteBranch ? new String[] { "push", "-u", ORIGIN, branch } : shouldForcePush(isForce); forEachModuleWith( path -> isSameBranchUnderPath(branch, path), path -> deployVertx(path, args)); @@ -122,7 +123,7 @@ void push(@Parameters(index = "0", paramLabel = "") String branch, @Command(name = "remote-prune-origin", aliases = "rpo") void remotePruneOrigin() { - forEachModuleDo(path -> deployVertx(path, "remote", "prune", "origin")); + forEachModuleDo(path -> deployVertx(path, "remote", "prune", ORIGIN)); } @Command(name = "stash") diff --git a/src/main/java/org/nqm/utils/StdOutUtils.java b/src/main/java/org/nqm/utils/StdOutUtils.java index 0606b90..ec620cd 100644 --- a/src/main/java/org/nqm/utils/StdOutUtils.java +++ b/src/main/java/org/nqm/utils/StdOutUtils.java @@ -130,7 +130,7 @@ private static String[] preProcessUntrackFile(String[] fileStats) { var newStats = new String[length + 1]; newStats[0] = fileStats[0]; newStats[1] = " " + UNTRACKED_SYM; - for (int i = 1; i < length; i++) { + for (var i = 1; i < length; i++) { newStats[i + 1] = fileStats[i]; } return newStats; diff --git a/src/main/java/org/nqm/vertx/CommandVerticle.java b/src/main/java/org/nqm/vertx/CommandVerticle.java index 1262c50..2926017 100644 --- a/src/main/java/org/nqm/vertx/CommandVerticle.java +++ b/src/main/java/org/nqm/vertx/CommandVerticle.java @@ -43,7 +43,7 @@ private String[] buildCommandWithArgs(String... args) { var cmdWithArgs = new String[args.length + 1]; cmdWithArgs[0] = GisConfig.GIT_HOME_DIR; var n = args.length; - for (int i = 0; i < n - 1; i++) { + for (var i = 0; i < n - 1; i++) { cmdWithArgs[i + 1] = args[i]; } // for better performance it is to required all '--gis' options to be at the end of cmd @@ -85,11 +85,15 @@ private void safelyPrint(Process pr) { var input = new BufferedReader(new InputStreamReader(pr.getInputStream())); var sb = new StringBuilder(infof("%s", "" + path.getFileName())); var isOneLineOpt = "--gis-one-line".equals(gisOption); + var isStatusCmd = commandWithArgs[1].equals(GitCommand.GIT_STATUS); try { while (isNotBlank(line = input.readLine())) { - sb.append(commandWithArgs[1].equals(GitCommand.GIT_STATUS) - ? isOneLineOpt ? gitStatusOneLine(line) : gitStatus(line) - : "%n %s".formatted(line)); + if (isStatusCmd) { + sb.append(isOneLineOpt ? gitStatusOneLine(line) : gitStatus(line)); + } + else { + sb.append("%n %s".formatted(line)); + } } out.println(sb.toString()); Optional.of(pr.waitFor())