Skip to content
Permalink
Browse files

[JENKINS-35095] Migrate to 2.9 parent pom. Address findbugs issues.

  • Loading branch information
armfergom committed Jun 9, 2016
1 parent a2bf336 commit 4424c200bd8342cacd4fb761e7d133eb2311b546
@@ -5,10 +5,9 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.596.1</version>
<version>2.9</version>
</parent>

<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials-binding</artifactId>
<version>1.8-SNAPSHOT</version>
<packaging>hpi</packaging>
@@ -19,7 +18,9 @@
<url>http://wiki.jenkins-ci.org/display/JENKINS/Credentials+Binding+Plugin</url>
<properties>
<workflow.version>1.7</workflow.version>
</properties>
<jenkins.version>1.596.1</jenkins.version>
<java.level>6</java.level>
</properties>
<licenses>
<license>
<name>MIT</name>
@@ -25,12 +25,15 @@
package org.jenkinsci.plugins.credentialsbinding;

import com.cloudbees.plugins.credentials.common.StandardCredentials;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import java.io.IOException;

import javax.annotation.Nonnull;

import hudson.model.Run;
@@ -110,9 +113,13 @@ public Environment bind(@Nonnull final AbstractBuild build, final Launcher launc
throw new AbstractMethodError("you must override bindSingle");
}
}

private static class UnbinderWrapper implements Unbinder {
private static final long serialVersionUID = 1; // only really serialize if what it wraps is, too

@SuppressFBWarnings(value="SE_BAD_FIELD", justification="Environment is deprecated and will generally be not serializable")
private final Environment e;

UnbinderWrapper(Environment e) {
this.e = e;
}
@@ -126,7 +126,8 @@ public Unbinder getUnbinder() {
if (type().isInstance(cred))
return type().cast(cred);

Descriptor expected = Jenkins.getInstance().getDescriptor(type());

Descriptor expected = Jenkins.getActiveInstance().getDescriptor(type());
throw new CredentialNotFoundException("Credentials '"+credentialsId+"' is of type '"+
cred.getDescriptor().getDisplayName()+"' where '"+
(expected!=null ? expected.getDisplayName() : type().getName())+
@@ -36,6 +36,7 @@
import hudson.model.TaskListener;
import hudson.util.Secret;
import java.io.IOException;
import java.io.ObjectStreamException;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.ArrayList;
@@ -45,6 +46,8 @@
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.codec.Charsets;
import org.jenkinsci.plugins.credentialsbinding.MultiBinding;
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl;
@@ -92,7 +95,7 @@
}
getContext().newBodyInvoker().
withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new Overrider(overrides))).
withContext(BodyInvoker.mergeConsoleLogFilters(getContext().get(ConsoleLogFilter.class), new Filter(overrides.values()))).
withContext(BodyInvoker.mergeConsoleLogFilters(getContext().get(ConsoleLogFilter.class), new Filter(overrides.values(), run.getCharset().name()))).
withCallback(new Callback(unbinders)).
start();
return false;
@@ -130,8 +133,9 @@
private static final long serialVersionUID = 1;

private final Secret pattern;

Filter(Collection<String> secrets) {
private String charsetName;

Filter(Collection<String> secrets, String charsetName) {
StringBuilder b = new StringBuilder();
for (String secret : secrets) {
if (b.length() > 0) {
@@ -140,15 +144,24 @@
b.append(Pattern.quote(secret));
}
pattern = Secret.fromString(b.toString());
this.charsetName = charsetName;
}

// To avoid de-serialization issues with newly added field (charsetName)
private Object readResolve() throws ObjectStreamException {
if (this.charsetName == null) {
this.charsetName = Charsets.UTF_8.name();
}
return this;
}

@Override public OutputStream decorateLogger(AbstractBuild _ignore, final OutputStream logger) throws IOException, InterruptedException {
final Pattern p = Pattern.compile(pattern.getPlainText());
return new LineTransformationOutputStream() {
@Override protected void eol(byte[] b, int len) throws IOException {
Matcher m = p.matcher(new String(b, 0, len));
Matcher m = p.matcher(new String(b, 0, len, charsetName));
if (m.find()) {
logger.write(m.replaceAll("****").getBytes());
logger.write(m.replaceAll("****").getBytes(charsetName));
} else {
// Avoid byte → char → byte conversion unless we are actually doing something.
logger.write(b, 0, len);
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
Allows credentials to be bound to environment variables for use from miscellaneous build steps.
</div>

0 comments on commit 4424c20

Please sign in to comment.