Skip to content

Commit

Permalink
Merge pull request #41 from jenkinsci/findbugs
Browse files Browse the repository at this point in the history
Fixing findbugs warnings after plugin pom upgrade
  • Loading branch information
rsandell authored Feb 14, 2018
2 parents 1551e88 + 8dcdb86 commit 088fc7c
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
buildPlugin(findbugs: [run: true, archive:true])
buildPlugin(findbugs: [run: true, archive:true, unstableTotalAll: "0"])
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,34 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.5</version>
<configuration>
<!-- The excludeFilterFile profile in plugin-pom doesn't seem to take effect. So redundant configuration to fix.-->
<excludeFilterFile>src/findbugs/excludesFilter.xml</excludeFilterFile>
<failOnError>${findbugs.failOnError}</failOnError>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>false</findbugsXmlOutput>
<effort>${findbugs.effort}</effort>
<threshold>${findbugs.threshold}</threshold>
</configuration>
<executions>
<execution>
<id>findbugs</id>
<goals>
<goal>check</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

<scm>
<connection>scm:git:git://github.com/jenkinsci/pipeline-utility-steps-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/pipeline-utility-steps-plugin.git</developerConnection>
Expand Down
5 changes: 4 additions & 1 deletion src/findbugs/excludesFilter.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Package name="org.jenkinsci.plugins.pipeline.utility.steps.shaded"/>
<Package name="~org\.jenkinsci\.plugins\.pipeline\.utility\.steps\.shaded.*"/>
</Match>
<Match>
<Class name="~.*\.Messages"/>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* @author Robert Sandell &lt;rsandell@cloudbees.com&gt;.
*/
public class ReadPropertiesStepExecution extends AbstractFileOrTextStepExecution<Map<String, Object>> {
private static final long serialVersionUID = 1L;

private transient ReadPropertiesStep step;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.model.TaskListener;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.pipeline.utility.steps.shaded.org.yaml.snakeyaml.DumperOptions;
import org.jenkinsci.plugins.pipeline.utility.steps.shaded.org.yaml.snakeyaml.Yaml;
import org.jenkinsci.plugins.workflow.steps.*;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.io.*;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.FileAlreadyExistsException;
import java.util.*;

Expand All @@ -51,6 +53,7 @@ public class WriteYamlStep extends Step {

private String file;
private Object data;
private String charset;

@DataBoundConstructor
public WriteYamlStep(@Nonnull String file, @Nonnull Object data) {
Expand Down Expand Up @@ -84,6 +87,21 @@ public Object getData() {
return data;
}

public String getCharset() {
return charset;
}

/**
* The charset encoding to use when writing the file. Defaults to UTF-8.
* @param charset the charset
* @see Charset
* @see Charset#forName(String)
*/
@DataBoundSetter
public void setCharset(String charset) {
this.charset = charset;
}

private boolean isValidObjectType(Object obj) {
if ((obj instanceof Boolean) || (obj instanceof Character) ||
(obj instanceof Number) || (obj instanceof String) ||
Expand Down Expand Up @@ -139,6 +157,7 @@ public String getDisplayName() {
}

public static class Execution extends SynchronousNonBlockingStepExecution<Void> {
private static final long serialVersionUID = 1L;

private transient WriteYamlStep step;

Expand All @@ -163,7 +182,15 @@ protected Void run () throws Exception {
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);

try (OutputStreamWriter writer = new OutputStreamWriter(path.write())) {
Charset cs;

if (StringUtils.isEmpty(step.getCharset())) {
cs = Charset.forName("UTF-8"); //If it doesn't exist then something is broken in the jvm
} else {
cs = Charset.forName(step.getCharset()); //Will throw stuff directly to the user
}

try (OutputStreamWriter writer = new OutputStreamWriter(path.write(), cs)) {
yaml.dump (step.getData(), writer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package org.jenkinsci.plugins.pipeline.utility.steps.conf.mf;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.FilePath;
import hudson.model.TaskListener;
import org.jenkinsci.plugins.pipeline.utility.steps.AbstractFileOrTextStep;
Expand All @@ -50,6 +51,7 @@
* @author Robert Sandell &lt;rsandell@cloudbees.com&gt;.
*/
public class ReadManifestStepExecution extends AbstractFileOrTextStepExecution<SimpleManifest> {
private static final long serialVersionUID = 1L;

private transient ReadManifestStep step;

Expand All @@ -75,6 +77,7 @@ private SimpleManifest parseText(String text) throws IOException {
return new SimpleManifest(manifest);
}

@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE", justification = "I don't understand what/where it is.")
private SimpleManifest parseFile(String file) throws IOException, InterruptedException {
TaskListener listener = getContext().get(TaskListener.class);
FilePath path = ws.child(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected String run() throws Exception {
return filePath.act(new ComputeSha1());
}

private class ComputeSha1 extends MasterToSlaveFileCallable<String> {
private static class ComputeSha1 extends MasterToSlaveFileCallable<String> {
@Override
public String invoke(File file, VirtualChannel virtualChannel) throws IOException, InterruptedException {
if (file.exists() && file.isFile()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* @author Robert Sandell &lt;rsandell@cloudbees.com&gt;.
*/
public class FindFilesStepExecution extends SynchronousNonBlockingStepExecution<FileWrapper[]> {
private static final long serialVersionUID = 1L;

@Inject
private transient FindFilesStep step;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public OutputStream decorateLogger(Run build, final OutputStream logger) throws
private static OutputStream append(FilePath fp) throws IOException, InterruptedException {
if (fp.getChannel() == null) {
File f = new File(fp.getRemote()).getAbsoluteFile();
f.getParentFile().mkdirs();
if (!f.getParentFile().exists() && !f.getParentFile().mkdirs()) {
throw new IOException("Failed to create directory " + f.getParentFile());
}
try {
return Files.newOutputStream(f.toPath(), StandardOpenOption.CREATE, StandardOpenOption.APPEND/*, StandardOpenOption.DSYNC*/);
} catch (InvalidPathException e) {
Expand All @@ -120,7 +122,9 @@ private static OutputStream append(FilePath fp) throws IOException, InterruptedE
@Override
public OutputStream invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
f = f.getAbsoluteFile();
f.getParentFile().mkdirs();
if (!f.getParentFile().exists() && !f.getParentFile().mkdirs()) {
throw new IOException("Failed to create directory " + f.getParentFile());
}
try {
return new RemoteOutputStream(Files.newOutputStream(f.toPath(), StandardOpenOption.CREATE, StandardOpenOption.APPEND/*, StandardOpenOption.DSYNC*/));
} catch (InvalidPathException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public FormValidation doCheckFile(@QueryParameter String value) {
* The execution of {@link TouchStep}.
*/
public static class ExecutionImpl extends SynchronousNonBlockingStepExecution<FileWrapper> {
private static final long serialVersionUID = 1L;

private transient TouchStep step;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public Set<? extends Class<?>> getRequiredContext() {
public static class Execution extends SynchronousStepExecution<List<String>> {

private static final long serialVersionUID = 1L;
private transient final String label;
private transient final boolean includeOffline;
private final String label;
private final boolean includeOffline;

Execution(String label, boolean includeOffline, StepContext context) {
super(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* @author Nikolas Falco
*/
public class ReadJSONStepExecution extends AbstractFileOrTextStepExecution<JSON> {
private static final long serialVersionUID = 1L;

private transient ReadJSONStep step;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* @author Nikolas Falco
*/
public class WriteJSONStepExecution extends SynchronousNonBlockingStepExecution<Void> {
private static final long serialVersionUID = 1L;

private transient WriteJSONStep step;

Expand All @@ -71,7 +72,7 @@ protected Void run() throws Exception {
throw new FileNotFoundException(Messages.JSONStepExecution_fileIsDirectory(path.getRemote()));
}

try (OutputStreamWriter writer = new OutputStreamWriter(path.write())) {
try (OutputStreamWriter writer = new OutputStreamWriter(path.write(), "UTF-8")) {
if (step.getPretty() > 0) {
writer.write(step.getJson().toString(step.getPretty()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public String getDisplayName() {
}

public static class Execution extends SynchronousNonBlockingStepExecution<Model> {
private static final long serialVersionUID = 1L;

private transient ReadMavenPomStep step;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public String getDisplayName() {
}

public static class Execution extends SynchronousNonBlockingStepExecution<Void> {
private static final long serialVersionUID = 1L;

private transient WriteMavenPomStep step;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
* @author Robert Sandell &lt;rsandell@cloudbees.com&gt;.
*/
public class UnZipStepExecution extends SynchronousNonBlockingStepExecution<Object> {
private static final long serialVersionUID = 1L;

private transient UnZipStep step;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* @author Robert Sandell &lt;rsandell@cloudbees.com&gt;.
*/
public class ZipStepExecution extends SynchronousNonBlockingStepExecution<Void> {
private static final long serialVersionUID = 1L;

private transient ZipStep step;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
<f:textbox />
</f:entry>

<f:entry title="${%text.title}" field="text" description="${%text.description}">
<f:entry title="${%text.title}" field="data" description="${%text.description}">
<f:textbox />
</f:entry>
<f:entry title="${%charset.title}" field="charset" description="${%charset.description}">
<f:textbox />
</f:entry>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
file.title=File
file.description=File to save as YAML
text.title=Data
text.description=Object to serialize to YAML. Must be Boolean, Character, Number, String, URL, Calendar, Date, UUID, null or a Collection/Map of them.
text.description=Object to serialize to YAML. Must be Boolean, Character, Number, String, URL, Calendar, Date, UUID, null or a Collection/Map of them.
charset.title=Charset
charset.description=(Optional) What charset to use when writing the file. Default: UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@
<code>data</code>:
A Mandatory Object containing the data to be serialized.
</li>
<li>
<code>charset</code>:
Optionally specify the charset to use when writing the file. Defaults to UTF-8 if nothing else is specified.
What charsets that are available depends on your Jenkins master system.
The java specification tells us though that at least the following should be available:
<ul>
<li>US-ASCII</li>
<li>ISO-8859-1</li>
<li>UTF-8</li>
<li>UTF-16BE</li>
<li>UTF-16LE</li>
<li>UTF-16</li>
</ul>
</li>
</ul>
<p>
<strong>Examples:</strong><br/>
Expand Down

0 comments on commit 088fc7c

Please sign in to comment.