Skip to content

Commit

Permalink
Merge pull request #53 from nqminhuit/fix-sonar
Browse files Browse the repository at this point in the history
fix-sonar:
  • Loading branch information
nqminhuit authored Oct 24, 2022
2 parents 88febed + 323ef92 commit 57b3779
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The executable jar file will be created at `target/gis-<version>.jar`

For more details, just run:
```shell script
./gis
./gis --help
```

# Comparison
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions src/main/java/org/nqm/command/GitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -50,7 +51,7 @@ void fetch() {

@Command(name = "fetch-origin", aliases = "fo")
void fetchOrigin(@Parameters(index = "0", paramLabel = "<branch name>") 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")
Expand Down Expand Up @@ -114,15 +115,15 @@ void push(@Parameters(index = "0", paramLabel = "<branch name>") 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));
}

@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")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/nqm/utils/StdOutUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/nqm/vertx/CommandVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 57b3779

Please sign in to comment.