Skip to content

Commit 4880203

Browse files
committed
Fix Sonar issues
1 parent 43e95d4 commit 4880203

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+159
-171
lines changed

build-helper-mojo/src/test/java/com/oracle/wls/buildhelper/FileCopyMojoTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package com.oracle.wls.buildhelper;
@@ -32,14 +32,14 @@ class FileCopyMojoTest {
3232
private MojoTestSupport mojoTestSupport;
3333

3434
@BeforeEach
35-
public void setUp() throws Exception {
35+
void setUp() throws Exception {
3636
mojoTestSupport = new MojoTestSupport(FileCopyMojo.class);
3737
mementos.add(StaticStubSupport.install(FileCopyMojo.class, "executor", copyExecutorStub));
3838
mementos.add(SystemPropertySupport.preserve("user.dir"));
3939
}
4040

4141
@AfterEach
42-
public void tearDown() {
42+
void tearDown() {
4343
mementos.forEach(Memento::revert);
4444
}
4545

build-helper-mojo/src/test/java/com/oracle/wls/buildhelper/GitTagMojoTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package com.oracle.wls.buildhelper;
@@ -107,12 +107,12 @@ void whenGitResponseIsVersionOnly_createVersionProperty() throws Exception {
107107

108108
@Test
109109
void publicConstructorSuppliesLiveExecutor() throws NoSuchFieldException, IllegalAccessException {
110-
GitTagMojo mojo = new GitTagMojo();
110+
GitTagMojo gitTagMojo = new GitTagMojo();
111111

112-
Field field = mojo.getClass().getDeclaredField("executor");
112+
Field field = gitTagMojo.getClass().getDeclaredField("executor");
113113
field.setAccessible(true);
114114

115-
assertThat(field.get(mojo), instanceOf(GitTagExecutor.class));
115+
assertThat(field.get(gitTagMojo), instanceOf(GitTagExecutor.class));
116116
}
117117

118118
@SuppressWarnings("SameParameterValue")

build-helper-mojo/src/test/java/com/oracle/wls/buildhelper/InMemoryFileSystem.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ private void defineFileContents(String filePath, String contents) {
6868
if (!filePath.startsWith(SEPARATOR)) throw new RuntimeException("Must specify full absolute path");
6969
provider.fileContents.put(filePath, contents);
7070

71-
String directoryPath = "";
71+
StringBuilder directoryPath = new StringBuilder();
7272
for (String name : filePath.split(SEPARATOR)) {
7373
if (name.isEmpty()) continue;
74-
directoryPath += (SEPARATOR + name);
75-
if (!provider.fileContents.containsKey(directoryPath))
76-
provider.fileContents.put(directoryPath, DIRECTORY_OBJECT);
74+
directoryPath.append(SEPARATOR).append(name);
75+
String path = directoryPath.toString();
76+
if (!provider.fileContents.containsKey(path))
77+
provider.fileContents.put(path, DIRECTORY_OBJECT);
7778
}
7879
}
7980

build-helper-mojo/src/test/java/com/oracle/wls/buildhelper/InMemoryFileSystemTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
import static org.hamcrest.Matchers.equalTo;
1717
import static org.hamcrest.Matchers.is;
1818
import static org.hamcrest.Matchers.nullValue;
19-
import static org.junit.jupiter.api.Assertions.*;
19+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
2021

2122
class InMemoryFileSystemTest {
2223
static final String CREATED_FILE = "/top/of/the/system/MyFile.txt";
2324
static final String CREATED_FILE_CONTENT = "some text";
2425

2526
private final InMemoryFileSystem fileSystem = InMemoryFileSystem.createInstance();
26-
private final Path SLASH = toPath("/");
27+
private final Path slash = toPath("/");
2728

2829
@BeforeEach
2930
void setUp() {
@@ -39,7 +40,7 @@ void canCreateDummyFile() {
3940
void canReadDummyFile() throws IOException {
4041
try (BufferedReader reader = Files.newBufferedReader(toPath(CREATED_FILE))) {
4142
assertThat(reader.readLine(), equalTo(CREATED_FILE_CONTENT));
42-
};
43+
}
4344
}
4445

4546
@Test
@@ -75,7 +76,7 @@ void resolve_addsToParent() {
7576

7677
@Test
7778
void rootDirIsSlash() {
78-
assertThat(toPath("/a/b/c").getRoot(), equalTo(SLASH));
79+
assertThat(toPath("/a/b/c").getRoot(), equalTo(slash));
7980
}
8081

8182
@Test
@@ -90,12 +91,12 @@ void parentForRelativePath_isNull() {
9091

9192
@Test
9293
void parentForTopLevelSubdirectory_isSlash() {
93-
assertThat(toPath("/subdir").getParent(), equalTo(SLASH));
94+
assertThat(toPath("/subdir").getParent(), equalTo(slash));
9495
}
9596

9697
@Test
9798
void parentForSlash_isNull() {
98-
assertThat(SLASH.getParent(), nullValue());
99+
assertThat(slash.getParent(), nullValue());
99100
}
100101

101102
private Path toPath(String filePath) {
@@ -137,6 +138,6 @@ private void writeToFile(String filePath, String contents) throws IOException {
137138
void whenParentDirectoryPresent_openFileForOutput() throws IOException {
138139
Files.createDirectories(fileSystem.getPath("/a/b/c"));
139140

140-
writeToFile("/a/b/c/NewFile.txt", "something that works");
141+
assertDoesNotThrow(() -> writeToFile("/a/b/c/NewFile.txt", "something that works"));
141142
}
142143
}

build-helper-mojo/src/test/java/com/oracle/wls/buildhelper/JavaxToJakartaMojoTest.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.ArrayList;
2121
import java.util.List;
2222
import java.util.function.Function;
23-
import java.util.stream.Collectors;
2423

2524
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
2625
import static org.hamcrest.MatcherAssert.assertThat;
@@ -29,11 +28,10 @@
2928
import static org.hamcrest.Matchers.containsString;
3029
import static org.hamcrest.Matchers.equalTo;
3130
import static org.hamcrest.Matchers.hasItem;
32-
import static org.hamcrest.Matchers.is;
3331
import static org.hamcrest.Matchers.notNullValue;
3432
import static org.junit.jupiter.api.Assertions.assertThrows;
3533

36-
public class JavaxToJakartaMojoTest {
34+
class JavaxToJakartaMojoTest {
3735
static final String ROOT = "/project";
3836
static final String SOURCE_ROOT = ROOT + "/src/main/java";
3937
static final String GENERATED_SOURCE_ROOT = ROOT + "/target/generated-sources/jakarta";
@@ -51,7 +49,7 @@ public class JavaxToJakartaMojoTest {
5149
Function<String, Path> toPath = inMemoryFileSystem::getPath;
5250

5351
@BeforeEach
54-
public void setUp() throws Exception {
52+
void setUp() throws Exception {
5553
mojoTestSupport = new MojoTestSupport(JavaxToJakartaMojo.class);
5654
mojoTestSupport.getParameterField("compileSourceRoots").set(mojo, List.of(SOURCE_ROOT));
5755
mojoTestSupport.getParameterField("generatedSourcesDirectory").set(mojo, new File(GENERATED_SOURCE_ROOT));
@@ -67,7 +65,7 @@ public void setUp() throws Exception {
6765
}
6866

6967
@AfterEach
70-
public void tearDown() {
68+
void tearDown() {
7169
mementos.forEach(Memento::revert);
7270
}
7371

@@ -109,7 +107,7 @@ void addsGeneratedSourceDirectory() throws MojoExecutionException, MojoFailureEx
109107

110108
@Test
111109
void findsFilesToTransform() throws MojoFailureException {
112-
assertThat(mojo.getFilesToTransform().map(this::toRelativePath).map(Path::toString).collect(Collectors.toList()),
110+
assertThat(mojo.getFilesToTransform().map(this::toRelativePath).map(Path::toString).toList(),
113111
containsInAnyOrder("a/b/c/javax/Servlet1.java", "d/e/f/javax/Servlet2.java"));
114112
}
115113

@@ -138,9 +136,4 @@ void createsJakartaFiles() throws MojoExecutionException, MojoFailureException {
138136
private Path getStandardCompileSourceRoot() {
139137
return projectRoot.resolve("src").resolve("main").resolve("java");
140138
}
141-
142-
private Path getAddedCompileSourceRoot() {
143-
return projectRoot.resolve("target").resolve("generated-sources").resolve("jakarta");
144-
}
145-
146139
}

wls-exporter-core/src/main/java/com/oracle/wls/exporter/AuthenticatedCall.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.List;
1515
import java.util.Map;
1616
import java.util.Optional;
17-
import java.util.Set;
1817
import java.util.stream.Collectors;
1918

2019
import com.oracle.wls.exporter.domain.MBeanSelector;

wls-exporter-core/src/main/java/com/oracle/wls/exporter/ErrorLog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package com.oracle.wls.exporter;
@@ -18,7 +18,7 @@ public void log(Throwable throwable) {
1818

1919
private String toLogMessage(Throwable throwable) {
2020
StringBuilder sb = new StringBuilder(throwable.getClass().getSimpleName());
21-
if (throwable.getMessage() != null && throwable.getMessage().trim().length() > 0)
21+
if (throwable.getMessage() != null && !throwable.getMessage().trim().isEmpty())
2222
sb.append(": ").append(throwable.getMessage());
2323

2424
return sb.toString();

wls-exporter-core/src/main/java/com/oracle/wls/exporter/JsonEntity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2021, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package com.oracle.wls.exporter;
@@ -76,5 +76,6 @@ public boolean isStreaming() {
7676
@Override
7777
@Deprecated
7878
public void consumeContent() {
79+
// no-op
7980
}
8081
}

wls-exporter-core/src/main/java/com/oracle/wls/exporter/UrlBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package com.oracle.wls.exporter;
@@ -116,13 +116,13 @@ private WebHost selectHost() {
116116
}
117117

118118
private Queue<WebHost> initializeHosts() {
119-
final PriorityQueue<WebHost> hosts = new PriorityQueue<>(new PreferSuccesses());
119+
final PriorityQueue<WebHost> webHosts = new PriorityQueue<>(new PreferSuccesses());
120120
for (String hostName : hostNames) {
121121
for (int port : ports) {
122-
hosts.add(new WebHost(hostName, port));
122+
webHosts.add(new WebHost(hostName, port));
123123
}
124124
}
125-
return hosts;
125+
return webHosts;
126126
}
127127

128128
// Informs the builder that the last URL it supplied worked

wls-exporter-core/src/main/java/com/oracle/wls/exporter/WebAppConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2017, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package com.oracle.wls.exporter;

0 commit comments

Comments
 (0)