Skip to content

Commit

Permalink
Specifying encoding to read/write temporary files and changelogs in
Browse files Browse the repository at this point in the history
[FIXED JENKINS-4633] Force changelog encoding during file read
[FIXED JENKINS-14678] Force changelog encoding during file write
  • Loading branch information
mc1arke committed Sep 3, 2012
1 parent da501e9 commit 2f8e49e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/main/java/hudson/scm/AbstractCvs.java
Expand Up @@ -557,7 +557,7 @@ private CvsLog getRemoteLogForModule(final CvsRepository repository, final CvsRe
// can then parse it from here
final File tmpRlogSpill = File.createTempFile("cvs","rlog");
final DeferredFileOutputStream outputStream = new DeferredFileOutputStream(100*1024,tmpRlogSpill);
final PrintStream logStream = new PrintStream(outputStream);
final PrintStream logStream = new PrintStream(outputStream, true, getDescriptor().getChangelogEncoding());

// set a listener with our output stream that we parse the log from
final CVSListener basicListener = new BasicListener(logStream, listener.getLogger());
Expand Down Expand Up @@ -592,12 +592,11 @@ private CvsLog getRemoteLogForModule(final CvsRepository repository, final CvsRe
return new CvsLog() {
@Override
public Reader read() throws IOException {
// TODO: is it really correct that we read this in the platform encoding?
// note that master and slave can have different platform encoding
if (outputStream.isInMemory())
return new InputStreamReader(new ByteArrayInputStream(outputStream.getData()));
return new InputStreamReader(new ByteArrayInputStream(outputStream.getData()), getDescriptor().getChangelogEncoding());
else
return new FileReader(outputStream.getFile());
return new InputStreamReader(new FileInputStream(outputStream.getFile()), getDescriptor().getChangelogEncoding());
}

@Override
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/hudson/scm/CVSChangeLogSet.java
Expand Up @@ -44,6 +44,7 @@
import java.util.Iterator;
import java.util.List;

import jenkins.model.Jenkins;
import org.apache.commons.digester.Digester;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
Expand Down Expand Up @@ -702,11 +703,12 @@ public String toString() {
}

public void toFile(final java.io.File changelogFile) throws IOException {
PrintStream output = new PrintStream(new FileOutputStream(changelogFile));
String encoding = ((CVSSCM.DescriptorImpl)Jenkins.getInstance().getDescriptorOrDie(CVSSCM.class)).getChangelogEncoding();
PrintStream output = new PrintStream(new FileOutputStream(changelogFile), true, encoding);

DateFormat format = new SimpleDateFormat(CHANGE_DATE_FORMATTER_PATTERN);

output.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
output.println("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>");
output.println("<changelog>");

for (CVSChangeLog entry : this) {
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/hudson/scm/CVSSCM.java
Expand Up @@ -29,8 +29,10 @@
import hudson.model.*;
import hudson.scm.cvstagging.LegacyTagAction;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import hudson.util.Secret;
import net.sf.json.JSONObject;
import org.jvnet.localizer.LocaleProvider;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
Expand All @@ -41,6 +43,7 @@
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.util.*;

import static hudson.Util.fixEmptyAndTrim;
Expand Down Expand Up @@ -361,7 +364,9 @@ private class RepositoryBrowser {
private Secret privateKeyPassword = null;
private String knownHostsLocation = System.getProperty("user.home") + "/.ssh/known_hosts";
private CvsAuthentication[] authTokens = new CvsAuthentication[]{};

// we don't provide a way for users to edit this, other than by manually editing their XML config
private String changelogEncoding = "UTF-8";

public DescriptorImpl() {
super(CVSRepositoryBrowser.class);
load();
Expand Down Expand Up @@ -404,6 +409,12 @@ public int getCompressionLevel() {
public CvsAuthentication[] getAuthentication() {
return authTokens;
}

@Override
@Exported
public String getChangelogEncoding() {
return changelogEncoding;
}

@Override
public void load() {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/hudson/scm/CvsProjectset.java
Expand Up @@ -295,6 +295,12 @@ public CvsAuthentication[] getAuthentication() {
return getCvsDescriptor().getAuthentication();
}


@Override
public String getChangelogEncoding() {
return getCvsDescriptor().getChangelogEncoding();
}

}


Expand Down
8 changes: 8 additions & 0 deletions src/main/java/hudson/scm/ICvsDescriptor.java
Expand Up @@ -36,4 +36,12 @@ public interface ICvsDescriptor {
public int getCompressionLevel();

public CvsAuthentication[] getAuthentication();


/**
* Provides the format that the changelog (and any other plugin files)
* should be read and written in.
* @return the encoding selected by the user, defaults to UTF-8
*/
public String getChangelogEncoding();
}

0 comments on commit 2f8e49e

Please sign in to comment.