Skip to content

Commit

Permalink
Merge pull request #14 from jglick/shortParameterName
Browse files Browse the repository at this point in the history
Pad short parameter names before using File.createTempFile
  • Loading branch information
jglick authored Jan 30, 2021
2 parents 4ce1cff + b09b18f commit 0ae16ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.StaplerResponse;

Expand Down Expand Up @@ -72,7 +73,7 @@ public void close() throws IOException {

protected FilePath createTempFile(@NonNull Run<?,?> build, @NonNull FilePath tempDir, @NonNull EnvVars env, @NonNull Launcher launcher, @NonNull TaskListener listener) throws IOException, InterruptedException {
assert Util.isOverridden(AbstractFileParameterValue.class, getClass(), "open", Run.class);
FilePath f = tempDir.createTempFile(name, null);
FilePath f = tempDir.createTempFile(StringUtils.rightPad(name, 3, 'x'), null);
try (InputStream is = open(build)) {
f.copyFrom(is);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,18 @@ public class FileParameterWrapperTest {
r.assertLogContains("loaded 'UPLOADED CONTENT HERE'", b);
}

@Test public void shortParameterName() throws Exception {
r.createSlave("remote", null, null);
WorkflowJob p = r.createProject(WorkflowJob.class, "p");
p.addProperty(new ParametersDefinitionProperty(new Base64FileParameterDefinition("F")));
p.setDefinition(new CpsFlowDefinition("node('remote') {withFileParameter('F') {echo(/loaded '${readFile(F).toUpperCase(Locale.ROOT)}' from $F/)}}", true));
assertThat(new CLICommandInvoker(r, "build").
withStdin(new ByteArrayInputStream("uploaded content here".getBytes())).
invokeWithArgs("-f", "-p", "F=", "p"),
CLICommandInvoker.Matcher.succeeded());
WorkflowRun b = p.getBuildByNumber(1);
assertNotNull(b);
r.assertLogContains("loaded 'UPLOADED CONTENT HERE' from ", b);
}

}

0 comments on commit 0ae16ce

Please sign in to comment.