Skip to content

Commit 152f1a5

Browse files
Fix Sonar
1 parent b193b5d commit 152f1a5

File tree

6 files changed

+26
-16
lines changed

6 files changed

+26
-16
lines changed

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@
151151
</executions>
152152
<configuration>
153153
<generateGitPropertiesFile>false</generateGitPropertiesFile>
154-
<!-- <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>-->
155154
<commitIdGenerationMode>full</commitIdGenerationMode>
156155
</configuration>
157156
</plugin>

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/cli/ConsoleOutput.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ private void disableAllLoggers() {
2323
}
2424

2525
private void printOut(String msg, Object... args) {
26-
printf(System.out, msg, args);
26+
printfln(System.out, msg, args);
2727
}
2828

2929
private void printErr(String msg, Object... args) {
30-
printf(System.err, msg, args);
30+
printfln(System.err, msg, args);
3131
}
3232

33-
private void printf(PrintStream dest, String msg, Object... args) {
33+
private void printfln(PrintStream dest, String msg, Object... args) {
3434
dest.printf(msg, args);
3535
dest.println(); // Because "printf" does not print line return
3636
}
3737

3838
public void printDebug(String msg, Object... args) {
3939
// Could not (yet) make Logger level work within native image, so fallback to plain console output (for now)
40-
if (debug && msg != null) {
40+
if (debug) {
4141
printOut(msg, args);
4242
}
4343
}

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/cli/PrettyPrintCommand.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
@NullMarked
2525
class PrettyPrintCommand implements Callable<Integer> {
2626

27+
private static final String DEFAULT_OPTION_FILENAME = ".prettyprint";
28+
2729
@Nullable
2830
@Parameters(index = "0", description = "The path to pretty print", arity = "0..1")
2931
private File target;
@@ -84,9 +86,9 @@ private PrettyPrintOptions detectOptions(Path targetPath, ConsoleOutput output)
8486
return options;
8587
} else {
8688
var potentialOptions = new ArrayList<Path>();
87-
potentialOptions.add(targetPath.resolve(".prettyprint"));
88-
potentialOptions.add(Path.of(".").resolve(".prettyprint"));
89-
potentialOptions.add(Path.of(System.getProperty("user.home")).resolve(".prettyprint"));
89+
potentialOptions.add(targetPath.resolve(DEFAULT_OPTION_FILENAME));
90+
potentialOptions.add(Path.of(".").resolve(DEFAULT_OPTION_FILENAME));
91+
potentialOptions.add(Path.of(System.getProperty("user.home")).resolve(DEFAULT_OPTION_FILENAME));
9092
var options = reader.readOptions(potentialOptions);
9193
if (options != null) {
9294
return options;

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/cli/options/ExternalOptions.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package io.github.computerdaddyguy.jfiletreeprettyprinter.cli.options;
22

33
import jakarta.validation.Valid;
4+
import org.jspecify.annotations.Nullable;
45

56
record ExternalOptions(
6-
Boolean emojis,
7-
@Valid ChildLimit childLimit
7+
@Nullable Boolean emojis,
8+
@Valid @Nullable ChildLimit childLimit
89
) {
910

1011
public ExternalOptions(Boolean emojis, ChildLimit childLimit) {
11-
this.emojis = emojis == null ? false : emojis;
12+
this.emojis = emojis;
1213
this.childLimit = childLimit;
1314
}
1415

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/cli/options/ExternalOptionsReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private ExternalOptions loadAndValidate(Path optionsPath) {
113113
private PrettyPrintOptions mapToOptions(ExternalOptions externalOptions) {
114114
var options = PrettyPrintOptions.createDefault();
115115

116-
if (externalOptions.emojis()) {
116+
if (Boolean.TRUE.equals(externalOptions.emojis())) {
117117
options = options.withDefaultEmojis();
118118
}
119119

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/cli/options/RecordUtils.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@
44
import java.util.Collection;
55
import java.util.List;
66
import org.jspecify.annotations.NullMarked;
7+
import org.jspecify.annotations.Nullable;
78

89
@NullMarked
910
class RecordUtils {
1011

12+
private RecordUtils() {
13+
// Helper class
14+
}
15+
1116
/**
1217
* Inspired from: https://sormuras.github.io/blog/2020-05-06-records-to-text-block.html
1318
*/
14-
static String toTextBlock(Record rec) {
19+
static String toTextBlock(@Nullable Record rec) {
20+
if (rec == null) {
21+
return "null";
22+
}
1523
var lines = new ArrayList<String>();
1624
toTextBlock(lines, "", null, rec, " ");
1725
return String.join(System.lineSeparator(), lines);
1826
}
1927

20-
private static void toTextBlock(List<String> lines, String shift, String attrName, Object value, String indent) {
28+
private static void toTextBlock(List<String> lines, String shift, @Nullable String attrName, Object value, String indent) {
2129
var nested = value.getClass();
2230
if (nested.isRecord()) {
2331
toTextBlockRecord(lines, shift, attrName, (Record) value, indent);
@@ -28,7 +36,7 @@ private static void toTextBlock(List<String> lines, String shift, String attrNam
2836
}
2937
}
3038

31-
private static void toTextBlockRecord(List<String> lines, String shift, String attrName, Record rec, String indent) {
39+
private static void toTextBlockRecord(List<String> lines, String shift, @Nullable String attrName, Record rec, String indent) {
3240
if (attrName == null) {
3341
lines.add(String.format("%s%s", shift, rec.getClass().getSimpleName()));
3442
} else {
@@ -48,7 +56,7 @@ private static void toTextBlockRecord(List<String> lines, String shift, String a
4856
}
4957
}
5058

51-
private static void toTextBlockCollection(List<String> lines, String shift, String attrName, Collection<?> coll, String indent) {
59+
private static void toTextBlockCollection(List<String> lines, String shift, @Nullable String attrName, Collection<?> coll, String indent) {
5260
if (attrName == null) {
5361
lines.add(String.format("%s[", shift));
5462
} else {

0 commit comments

Comments
 (0)