Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous code cleanup #399

Merged
merged 3 commits into from
Jan 18, 2023
Merged

Miscellaneous code cleanup #399

merged 3 commits into from
Jan 18, 2023

Conversation

basil
Copy link
Member

@basil basil commented Jan 13, 2023

Fixes IDE warnings and makes the codebase use Java 11 conventions where applicable. While I was here I fixed a minor bug in a call to ProcessBuilder, fueled mostly by my recent usage of the same API in a different pull request in this repository (with which the existing code is now consistent). This passed testing in jenkinsci/bom.

Comment on lines +236 to +239
<exclusion>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed, as we removed the only usage of org.apache.tools.ant.filters.StringInputStream in this PR.

Comment on lines +334 to +339
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
</exclusions>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed, as we switched to SpotBugs annotations in this PR to be consistent with the rest of the Jenkins ecosystem.

@@ -232,7 +232,7 @@ public String getMavenPropertiesFile() {
return mavenPropertiesFile;
}

@Nonnull
@NonNull
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to SpotBugs annotations to be consistent with the rest of the Jenkins ecosystem.

@@ -191,7 +191,7 @@ public PluginCompatReport testPlugins()

// Scan bundled plugins
// If there is any bundled plugin, only these plugins will be taken under the consideration for the PCT run
UpdateSite.Data data = null;
UpdateSite.Data data;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing an unnecessary initialization due to the subsequent if/else block.

@@ -459,7 +459,7 @@ private TestExecutionResult testPluginAgainst(MavenCoordinates coreCoordinates,
System.out.println(String.format("%n%n%n%n%n"));

File pluginCheckoutDir = new File(config.workDirectory.getAbsolutePath() + File.separator + plugin.name + File.separator);
String parentFolder = StringUtils.EMPTY;
String parentFolder = "";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reducing our dependency on Apache Commons Lang. The fewer third-party dependencies, the more maintainable the code.

@@ -27,9 +27,9 @@

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrating from a deprecated method to its non-deprecated equivalent.

@@ -40,7 +40,7 @@
*/
public class VersionComparatorTest {

private static final ImmutableMap<String, Integer> OPERAND_CONVERSION = ImmutableMap.of(
private static final Map<String, Integer> OPERAND_CONVERSION = Map.of(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reducing our dependency on Guava. The fewer third-party dependencies, the more maintainable the code.

Comment on lines +88 to +89
normalizeXmlString(Files.readString(Paths.get(getClass().getResource(resource).toURI()), StandardCharsets.UTF_8)),
normalizeXmlString(FileUtils.readFileToString(pom, StandardCharsets.UTF_8))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reducing our dependency on Apache Commons I/O. The fewer third-party dependencies, the more maintainable the code.

While this was previously using the default character set, this seemed like a bug because our pom.xml files in Git repositories should always be encoded in UTF-8 (as their XML prologs often declare).

@@ -282,15 +279,15 @@ public void testWithoutAlternativeUrl() throws Throwable {
}

@Ignore("TODO broken by GH protocol changes. Requesting user data access via https on local execution")
@Test(expected = Test.None.class)
@Test
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing an unnecessary parameter: Test.None.class is the default value.

@@ -33,36 +33,36 @@ public void testCheckMethod() {
}

@Test
public void testAction() throws Exception {
public void testAction() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing an unnecessary throws clause.

basil added a commit to basil/bom that referenced this pull request Jan 14, 2023
@basil basil marked this pull request as ready for review January 15, 2023 03:51
@basil basil requested a review from a team as a code owner January 15, 2023 03:51
@basil basil requested a review from jtnord January 15, 2023 03:52
Copy link
Member

@jtnord jtnord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good except the potential for a deadlock in the process launching to get the java version

@@ -938,19 +939,19 @@ public static String getMavenModule(String plugin, File pluginPath, MavenRunner
if (absolutePath.endsWith(plugin)) {
return plugin;
}
String module = absolutePath.substring(absolutePath.lastIndexOf(File.separatorChar) + 1, absolutePath.length());
String module = absolutePath.substring(absolutePath.lastIndexOf(File.separatorChar) + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 what on earth was it warning about?

Comment on lines 401 to 403
try {
process.waitFor();
} catch (InterruptedException e) {
throw new IOException("interrupted while getting Java version", e);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we were not waiting for the process to terminate before trying to read its output.

for good reason see above ;-)

readAllBytes will block until the end of stream is reached - (ie the process has terminated, or otherwise closed its output stream) thus we can not have partial data.

the argument splitting fix is still valid.

Comment on lines 417 to 419
try {
process2.waitFor();
} catch (InterruptedException e) {
throw new IOException("interrupted while getting full Java version", e);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see similar comment about this and introducing a blocked state.

@@ -166,7 +169,7 @@ public PomData retrievePomData() throws PluginSourcesUnavailableException {
packaging = StringUtils.trimToNull((String)packagingXPath.evaluate(doc, XPathConstants.STRING));

String parentNode = xpath.evaluate("/project/parent", doc);
if (StringUtils.isNotBlank(parentNode)) {
if (parentNode != null && !parentNode.isBlank()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a common enough idiom here that I wonder if in in hindsight if you had considered introducing a helper class in this module. The two not conditions is not the best for legibility

@basil
Copy link
Member Author

basil commented Jan 17, 2023

All feedback is addressed from my perspective - let me know if there are any other changes you would like

@jtnord jtnord self-requested a review January 18, 2023 13:37
@jtnord
Copy link
Member

jtnord commented Jan 18, 2023

downstream closed source build is passing - this is good to merge from my perspective.

@basil basil merged commit 2e67c6f into master Jan 18, 2023
@basil basil deleted the cleanup branch January 18, 2023 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants