Skip to content
Permalink
Browse files

Specifying encoding to read/write temporary files and changelogs in

[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 2f8e49edf358d4f01b385a5fad69e1182fa71006
@@ -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());
@@ -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
@@ -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;
@@ -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) {
@@ -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;
@@ -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;
@@ -361,7 +364,9 @@ public DescriptorImpl getDescriptor() {
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();
@@ -404,6 +409,12 @@ public int getCompressionLevel() {
public CvsAuthentication[] getAuthentication() {
return authTokens;
}

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

@Override
public void load() {
@@ -295,6 +295,12 @@ public int getCompressionLevel() {
return getCvsDescriptor().getAuthentication();
}


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

}


@@ -36,4 +36,12 @@
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.
You can’t perform that action at this time.