Skip to content

Commit

Permalink
Merge pull request #38 from dbut023/jenkins-27094-writefile-encoding
Browse files Browse the repository at this point in the history
[JENKINS-27094] writeFile encoding parameter
  • Loading branch information
jglick committed May 30, 2017
2 parents b1b29f6 + e41ef60 commit 37d4589
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Expand Up @@ -91,7 +91,7 @@ public static final class Execution extends SynchronousNonBlockingStepExecution<
}

@Override protected Void run() throws Exception {
getContext().get(FilePath.class).child(step.file).write(step.text, /* TODO consider specifying encoding */ null);
getContext().get(FilePath.class).child(step.file).write(step.text, step.encoding);
return null;
}

Expand Down
Expand Up @@ -31,6 +31,7 @@
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

public class ReadWriteFileStepTest {
Expand Down Expand Up @@ -67,4 +68,36 @@ public void shouldTestFileExistsStep() throws Exception
r.assertLogContains("test2.txt - FileExists: true", run);
r.assertBuildStatusSuccess(run);
}

@Issue(("JENKINS-27094"))
@Test
public void readAndwriteFileUsesCorrectEncoding() throws Exception
{
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" def text = 'HELLO'\n" +
" writeFile file: 'f1', text: text, encoding: 'utf-32le'\n" +
" def text2 = readFile file: 'f1', encoding: 'utf-32le'\n" +
" echo text2\n" +
"}"));
r.assertLogContains("HELLO", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}




@Issue(("JENKINS-27094"))
@Test
public void testKnownCharsetRoundtrip() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" def text = 'HELLO'\n" +
" writeFile file: 'f1', text: '¤', encoding: 'iso-8859-1'\n" +
" def text2 = readFile file: 'f1', encoding: 'iso-8859-15'\n" +
" echo text2\n" +
"}"));
r.assertLogContains("€", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}
}

0 comments on commit 37d4589

Please sign in to comment.