Skip to content

Commit

Permalink
Merge pull request jenkinsci#22 from sghill-rewrite/refactor/moderniz…
Browse files Browse the repository at this point in the history
…e-java-8

Modernize to latest versions supported by Java 8
  • Loading branch information
olivergondza authored Aug 16, 2023
2 parents 94b7423 + ee86398 commit 0049361
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
17 changes: 13 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.18</version>
<version>4.51</version>
<relativePath />
</parent>
<groupId>io.jenkins.plugins</groupId>
Expand All @@ -16,8 +16,7 @@
<changelist>-SNAPSHOT</changelist>

<!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to run. -->
<jenkins.version>2.277.1</jenkins.version>
<java.level>8</java.level>
<jenkins.version>2.346.3</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
</properties>
<name>Jenkins description setter plugin</name>
Expand All @@ -42,6 +41,17 @@
<developerConnection>scm:git:[email protected]:jenkinsci/description-setter-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/description-setter-plugin</url>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.346.x</artifactId>
<version>1763.v092b_8980a_f5e</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<repositories>
<repository>
Expand All @@ -61,7 +71,6 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.descriptionsetter;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.Launcher;
import hudson.Util;
Expand Down Expand Up @@ -59,8 +60,11 @@ public boolean isApplicable(Class<? extends AbstractProject> jobType) {
}

@Override
public Builder newInstance(StaplerRequest req, JSONObject formData)
public Builder newInstance(StaplerRequest req, @NonNull JSONObject formData)
throws FormException {
if (req == null) {
return null;
}
return req.bindJSON(DescriptionSetterBuilder.class, formData);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import hudson.model.StringParameterValue;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -61,10 +59,9 @@ public static boolean setDescription(AbstractBuild<?, ?> build,
BuildListener listener, String regexp, String description, boolean appendMode)
throws InterruptedException {
try {
Matcher matcher;
String result = null;

matcher = parseLog(build.getLogFile(), regexp);
Matcher matcher = parseLog(build, regexp);
if (matcher != null) {
result = getExpandedDescription(matcher, description);
result = build.getEnvironment(listener).expand(result);
Expand Down Expand Up @@ -106,8 +103,8 @@ private static void setEnvironmentVariable(String result, AbstractBuild<?, ?> bu
build.addAction(new ParametersAction(params));
}

private static Matcher parseLog(File logFile, String regexp)
throws IOException, InterruptedException {
private static Matcher parseLog(AbstractBuild<?, ?> build, String regexp)
throws IOException {

if (regexp == null) {
return null;
Expand All @@ -116,19 +113,13 @@ private static Matcher parseLog(File logFile, String regexp)
// Assume default encoding and text files
String line;
Pattern pattern = Pattern.compile(regexp);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(logFile));
try (BufferedReader reader = new BufferedReader(build.getLogReader())) {
while ((line = reader.readLine()) != null) {
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
return matcher;
}
}
} finally {
if (reader != null) {
reader.close();
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.descriptionsetter;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.Launcher;
import hudson.Util;
Expand Down Expand Up @@ -67,8 +68,10 @@ public BuildStepMonitor getRequiredMonitorService() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
BuildListener listener) throws InterruptedException {

Result result = build.getResult();
boolean useUnstable = (regexpForFailed != null || descriptionForFailed != null)
&& build.getResult().isWorseThan(Result.UNSTABLE);
&& result != null
&& result.isWorseThan(Result.UNSTABLE);
return DescriptionSetterHelper.setDescription(build, listener,
useUnstable ? regexpForFailed : regexp,
useUnstable ? descriptionForFailed : description,
Expand Down Expand Up @@ -103,8 +106,11 @@ public boolean isApplicable(Class<? extends AbstractProject> jobType) {
}

@Override
public Publisher newInstance(StaplerRequest req, JSONObject formData)
public Publisher newInstance(StaplerRequest req, @NonNull JSONObject formData)
throws FormException {
if (req == null) {
return null;
}
return req.bindJSON(DescriptionSetterPublisher.class, formData);
}

Expand Down

0 comments on commit 0049361

Please sign in to comment.