Skip to content

Commit e520507

Browse files
authored
Merge pull request #28 from nqminhuit/fix-sonarqube
fix sonarqube issues
2 parents 125ffc9 + 19a47a0 commit e520507

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

src/main/java/org/nqm/command/GitCommand.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.nqm.command;
22

3-
import static java.lang.System.out;
3+
import static java.lang.System.out; // NOSONAR
44
import static org.nqm.command.Wrapper.deployVertx;
55
import static org.nqm.command.Wrapper.forEachModuleDo;
66
import static org.nqm.command.Wrapper.forEachModuleWith;
@@ -66,12 +66,12 @@ void checkoutNewBranch(@Parameters(index = "0", paramLabel = "<new_branch_name>"
6666
System.exit(0); // TODO: should centralize system exit to 1 place?
6767
}
6868
Consumer<Path> deployCommand = path -> deployVertx(path, "checkout", "-b", newBranch);
69-
if (streamOf(input).filter(ALL_MODULES::equals).findFirst().isPresent()) {
69+
if (streamOf(input).anyMatch(ALL_MODULES::equals)) {
7070
forEachModuleDo(deployCommand);
7171
return;
7272
}
7373

74-
if (streamOf(input).filter(ALL_SUBMODULES::equals).findFirst().isPresent()) {
74+
if (streamOf(input).anyMatch(ALL_SUBMODULES::equals)) {
7575
forEachSubmoduleDo(deployCommand);
7676
return;
7777
}
@@ -88,7 +88,7 @@ void checkoutNewBranch(@Parameters(index = "0", paramLabel = "<new_branch_name>"
8888
}
8989
}
9090

91-
private static Stream<String> streamOf(String[] input) throws IOException {
91+
private static Stream<String> streamOf(String[] input) {
9292
return Stream.of(input).map(String::trim).distinct();
9393
}
9494

@@ -114,7 +114,7 @@ void push(@Parameters(index = "0", paramLabel = "<branch name>") String branch,
114114

115115
private boolean isSameBranchUnderPath(String branch, Path path) {
116116
try {
117-
var proc = new ProcessBuilder("git", "branch", "--show-current")
117+
var proc = new ProcessBuilder(GisConfig.GIT_HOME_DIR, "branch", "--show-current")
118118
.directory(path.toFile())
119119
.start();
120120
var currentBranch = new BufferedReader(new InputStreamReader(proc.getInputStream())).readLine();
@@ -130,10 +130,7 @@ private boolean isConfirmed(String question) {
130130
out.print(question + " ");
131131
try (var reader = new BufferedReader(new InputStreamReader(System.in))) {
132132
var input = reader.readLine();
133-
return Stream.of(new String[] { "y", "ye", "yes" })
134-
.filter(s -> s.equalsIgnoreCase(input))
135-
.findFirst()
136-
.isPresent();
133+
return Stream.of("y", "ye", "yes").anyMatch(s -> s.equalsIgnoreCase(input));
137134
}
138135
catch (IOException e) {
139136
GisLog.debug(e);

src/main/java/org/nqm/config/GisConfig.java

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ private static VertxOptions vertxOptions() {
1515
options.setEventLoopPoolSize(1);
1616
options.setWorkerPoolSize(1);
1717
options.setInternalBlockingPoolSize(1);
18-
// options.setWarningExceptionTime(100);
1918
options.setBlockedThreadCheckInterval(10000);
2019
return options;
2120
}

src/main/java/org/nqm/config/GisLog.java

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class GisLog {
1111

1212
private static Boolean isDebugEnabled;
1313

14+
private GisLog() {}
15+
1416
public static void setIsDebugEnabled(boolean b) {
1517
if (isDebugEnabled == null) {
1618
isDebugEnabled = b;

src/main/java/org/nqm/utils/StdOutUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.nqm.utils;
22

3-
import static java.lang.System.err;
4-
import static java.lang.System.out;
3+
import static java.lang.System.err; // NOSONAR
4+
import static java.lang.System.out; // NOSONAR
55

66
public class StdOutUtils {
77

src/main/java/org/nqm/vertx/CommandVerticle.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.nqm.vertx;
22

3-
import static java.lang.System.out;
3+
import static java.lang.System.out; // NOSONAR
44
import static java.util.function.Predicate.not;
55
import static org.nqm.utils.GisStringUtils.isNotBlank;
66
import static org.nqm.utils.StdOutUtils.CL_GREEN;
@@ -14,7 +14,7 @@
1414
import java.io.InputStreamReader;
1515
import java.nio.file.Path;
1616
import java.util.Optional;
17-
import java.util.function.Function;
17+
import java.util.function.UnaryOperator;
1818
import java.util.stream.Collectors;
1919
import java.util.stream.Stream;
2020
import org.nqm.config.GisConfig;
@@ -83,7 +83,7 @@ else if (line.startsWith("# branch.ab")) {
8383
}
8484
else {
8585
final var immutableLine = line;
86-
Function<String, String> getFiles = filesChange -> immutableLine.startsWith("2")
86+
UnaryOperator<String> getFiles = filesChange -> immutableLine.startsWith("2")
8787
? Optional.of(filesChange.split("\t")).map(s -> s[1] + " -> " + s[0]).orElse("")
8888
: filesChange;
8989

@@ -102,10 +102,14 @@ else if (line.startsWith("# branch.ab")) {
102102
warnln("Could not perform on module: '%s'".formatted(this.path.getFileName()));
103103
});
104104
}
105-
catch (IOException | InterruptedException e) {
105+
catch (IOException e) {
106106
errln(e.getMessage());
107107
GisLog.debug(e);
108108
}
109+
catch (InterruptedException e) {
110+
GisLog.debug(e);
111+
Thread.currentThread().interrupt();
112+
}
109113
}
110114

111115
private static String buildAheadBehind(String[] splitS) {

src/main/java/org/nqm/vertx/GisVertx.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class GisVertx {
1818
public static final String ADDR_ADD_DIR = "add.dir";
1919
public static final String ADDR_REM_DIR = "remove.dir";
2020

21+
private GisVertx() {}
22+
2123
public static Vertx instance() {
2224
if (vertxInstance == null) {
2325
vertxInstance = Vertx.vertx(VERTX_OPTIONS);
@@ -50,7 +52,7 @@ private static void handleAddProcessedDir(Message<Object> msg) {
5052
private static void handleRemoveProcessedDir(Message<Object> msg) {
5153
processedModules().removeIf(d -> d.equals("" + msg.body()));
5254
GisLog.debug("### queue size = '%s'".formatted(processedModules().size()));
53-
if (processedModules().size() < 1) {
55+
if (processedModules().isEmpty()) {
5456
System.exit(0);
5557
}
5658
}

0 commit comments

Comments
 (0)