Skip to content

Commit

Permalink
Merge pull request #17 from oleg-nenashev/JENKINS-48944-jep-200
Browse files Browse the repository at this point in the history
[JENKINS-48944] - Prevent serialization of PrintStream to the disk
  • Loading branch information
oleg-nenashev committed Jan 16, 2018
2 parents 5a576c4 + bd2e04b commit 182b5ae
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Jenkinsfile
@@ -0,0 +1,2 @@
// Build the plugin using https://github.com/jenkins-infra/pipeline-library
buildPlugin()
16 changes: 12 additions & 4 deletions pom.xml
Expand Up @@ -3,14 +3,22 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.609</version>
<version>3.2</version>
</parent>

<artifactId>build-name-setter</artifactId>
<version>1.6.8-SNAPSHOT</version>
<packaging>hpi</packaging>

<url>http://wiki.jenkins-ci.org/display/JENKINS/Build+Name+Setter+Plugin</url>
<properties>
<jenkins.version>1.625.3</jenkins.version>
<java.level>7</java.level>
<!-- TODO: remove once FindBugs issues are fixed -->
<findbugs.failOnError>false</findbugs.failOnError>
</properties>


<url>http://wiki.jenkins.io/display/JENKINS/Build+Name+Setter+Plugin</url>

<licenses>
<license>
Expand Down Expand Up @@ -55,14 +63,14 @@
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

Expand Down
31 changes: 24 additions & 7 deletions src/main/java/org/jenkinsci/plugins/EnvironmentVarSetter.java
Expand Up @@ -9,15 +9,21 @@
import java.io.PrintStream;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Created by Leo on 4/20/2016.
* Helper to work with environment variables.
*/
public class EnvironmentVarSetter implements EnvironmentContributingAction {
private PrintStream log;

@CheckForNull
private transient PrintStream log;
private final Map<String, String> envVars = new ConcurrentHashMap<String, String>();

private static final Logger LOGGER = Logger.getLogger(EnvironmentVarSetter.class.getName());

public static final String buildDisplayNameVar = "BUILD_DISPLAY_NAME";

public EnvironmentVarSetter(@CheckForNull String key, @CheckForNull String value, @CheckForNull PrintStream logger) {
Expand Down Expand Up @@ -45,28 +51,39 @@ public void setVar(@CheckForNull String key, @CheckForNull String value) {
}

if (envVars.containsKey(key)) {
log.println(
"Variable with name '" + key + "' already exists, current value: '" + envVars.get(key) +
"', new value: '" + value + "'");
log("Variable with name '%s' already exists, current value: '%s', new value: '%s'",
key, envVars.get(key), value);
}
else {
log.println("Create new variable " + key + "=" + value);
log("Create new variable %s=%s", key, value);
}

envVars.put(key, value);
}

public String getVar(String key) {
if (envVars.containsKey(key)) {
log.println("Get var: " + key + "=" + envVars.get(key));
log("Get var: %s=%s", key, envVars.get(key));
return envVars.get(key);
}
else {
log.println("Var '" + key + "' doesn't exist");
log("Var '%s' doesn't exist", key);
return "";
}
}

private void log(String format, Object ... args) {
if (log == null && !LOGGER.isLoggable(Level.FINE)) { // not loggable
return;
}

String message = String.format(format, args);
LOGGER.fine(message);
if (log != null) {
log.println(message);
}
}

@Override
public void buildEnvVars(AbstractBuild<?, ?> abstractBuild, EnvVars envVars) {
envVars.putAll(this.envVars);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/index.jelly
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
This plug-in sets the display name of a build to something other than #1, #2, #3, ...
</div>
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="${%Build Name}" field="template">
Expand Down
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
Normally, builds are named by their sequential numbers, but you can change that here by
setting what name new build gets. This field can contain the following macros:
Expand Down
@@ -1,4 +1,5 @@
<!--suppress XmlUnusedNamespaceDeclaration -->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:optionalBlock
Expand Down
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
This field could contain relative path to the file
with build name from the build workspace.
Expand Down
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
Normally build name consists of [file content]+[macro],<br/>
this option reverses the order i.e. [macro]+[file content].
Expand Down
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
This field can contain the following macros:<br/>
<help xmlns="/lib/token-macro"/>
Expand Down

0 comments on commit 182b5ae

Please sign in to comment.