Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add inner class to ExportParametersBuilder
Annonymous inner class that implements FileCallable uses external
final String. This might be an issue regarding serialization on
remote.

This patch adds new inner class that implements FileCallable to
keep such string.

Issue: JENKINS-38917
  • Loading branch information
rinrinne committed Oct 13, 2016
1 parent 4d64841 commit cef03bf
Showing 1 changed file with 35 additions and 15 deletions.
Expand Up @@ -43,6 +43,7 @@
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
Expand Down Expand Up @@ -128,23 +129,10 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

Serializer serializer = SerializerFactory.createSerializer(fileFormat);
if (serializer != null) {
final String buf = serializer.serialize(env);
String buf = serializer.serialize(env);
if (buf != null) {
try {
paramFile.act(new FilePath.FileCallable<Void>() {
private static final long serialVersionUID = 1;
@Override
public Void invoke(File file, VirtualChannel channel) throws IOException, InterruptedException {
if (file.exists()) {
file.delete();
}
BufferedWriter bw = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(file), CharEncoding.UTF_8));
bw.write(buf);
bw.close();
return null;
}
});
paramFile.act(new ParametersExporter(buf));
listener.getLogger().println("Stored the below parameters into " + paramFile.getRemote());
for (String key : env.keySet()) {
listener.getLogger().println(key);
Expand All @@ -164,6 +152,38 @@ public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
}

/**
* A class to export parameters to a file.
*
* @author rinrinne (rinrin.ne@gmail.com)
*/
private static final class ParametersExporter implements FileCallable<Void> {

private static final long serialVersionUID = 1;
private final String buffer;

/**
* Constructor.
*
* @param parameters the string that contanins parameters.
*/
public ParametersExporter(String parameters) {
this.buffer = parameters;
}

@Override
public Void invoke(File file, VirtualChannel channel) throws IOException, InterruptedException {
if (file.exists()) {
file.delete();
}
BufferedWriter bw = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(file), CharEncoding.UTF_8));
bw.write(buffer);
bw.close();
return null;
}
}

/**
* A implementation of Descliptor.
*
Expand Down

0 comments on commit cef03bf

Please sign in to comment.