Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JEP-200] Save charset names, not actual Charset objects #2

Merged
merged 4 commits into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
buildPlugin()
41 changes: 20 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.399</version>
<version>3.2</version>
<relativePath />
</parent>

<artifactId>project-description-setter</artifactId>
Expand All @@ -40,7 +41,8 @@
<url>http://wiki.jenkins-ci.org/display/JENKINS/Project+Description+Setter+Plugin</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jenkins.version>1.625.3</jenkins.version>
<java.level>7</java.level>
</properties>

<licenses>
Expand All @@ -64,6 +66,11 @@
<artifactId>token-macro</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.0</version>
</dependency>
</dependencies>

<scm>
Expand All @@ -77,25 +84,17 @@
<url>http://issues.jenkins-ci.org/</url>
</issueManagement>

<distributionManagement>
<repositories>
<repository>
<id>maven.jenkins-ci.org</id>
<url>http://maven.jenkins-ci.org:8081/content/repositories/releases/</url>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</distributionManagement>

<build>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<version>1.67</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>

</project>


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

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import hudson.matrix.MatrixRun;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Hudson;
import hudson.tasks.BuildWrapper;
import org.apache.commons.io.IOUtils;
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
Expand All @@ -46,22 +45,25 @@
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.nio.charset.Charset;
import jenkins.model.Jenkins;

public class DescriptionSetterWrapper extends BuildWrapper implements MatrixAggregatable {

final Charset charset;
@Deprecated
transient Charset charset;
String charsetName;
final String projectDescriptionFilename;
final boolean disableTokens;

@DataBoundConstructor
public DescriptionSetterWrapper(final String charset, final String projectDescriptionFilename, final boolean disableTokens) {
this.charset = Charset.forName(charset);
this.charsetName = charset;
this.projectDescriptionFilename = projectDescriptionFilename;
this.disableTokens = disableTokens;
}

public String getCharset() {
return charset.displayName();
return charsetName;
}

public String getProjectDescriptionFilename() {
Expand All @@ -72,6 +74,13 @@ public boolean isDisableTokens() {
return disableTokens;
}

private Object readResolve() {
if (charset != null) {
charsetName = charset.name();
}
return this;
}

@Override
public Environment setUp(final AbstractBuild build, final Launcher launcher, final BuildListener listener)
throws IOException, InterruptedException {
Expand Down Expand Up @@ -108,7 +117,11 @@ private String getContentsIfAvailable(final AbstractBuild build, final BuildList
final String trimmed = Util.fixEmptyAndTrim(fileName);
if (trimmed == null) return null;
final String expandedFilename = expand(build, listener, fileName);
final FilePath projectDescriptionFile = build.getWorkspace().child(expandedFilename);
FilePath workspace = build.getWorkspace();
if (workspace == null) {
return null;
}
final FilePath projectDescriptionFile = workspace.child(expandedFilename);
if (!projectDescriptionFile.exists()) {
listener.getLogger().println(Messages.console_noFile(expandedFilename));
return null;
Expand All @@ -134,10 +147,10 @@ private String readFile(final FilePath projectDescriptionFile) {
StringWriter writer = null;
try {
in = projectDescriptionFile.read();
reader = new InputStreamReader(new BufferedInputStream(in), charset);
reader = new InputStreamReader(new BufferedInputStream(in), Charset.forName(charsetName));
writer = new StringWriter();
IOUtils.copy(reader, writer);
} catch (IOException ioe) {
} catch (IOException | InterruptedException ioe) {
IOUtils.closeQuietly(reader);
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(writer);
Expand All @@ -151,7 +164,7 @@ private String readFile(final FilePath projectDescriptionFile) {

@Override
public DescriptionSetterWrapperDescriptor getDescriptor() {
return Hudson.getInstance().getDescriptorByType(DescriptionSetterWrapperDescriptor.class);
return Jenkins.getActiveInstance().getDescriptorByType(DescriptionSetterWrapperDescriptor.class);
}

}