Skip to content

Commit

Permalink
Merge branch 'master' into JENKINS-40370
Browse files Browse the repository at this point in the history
Conflicts:
	pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/AbstractModelDefTest.java
  • Loading branch information
abayer committed Jan 5, 2017
2 parents b6ff288 + a323f49 commit 96a34ed
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 22 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List; import java.util.List;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.apache.commons.lang.StringEscapeUtils;
import org.jenkinsci.plugins.pipeline.modeldefinition.validator.ModelValidator; import org.jenkinsci.plugins.pipeline.modeldefinition.validator.ModelValidator;


/** /**
Expand Down Expand Up @@ -112,7 +113,10 @@ public String toGroovy() {
result.append(','); result.append(',');
} }
result.append('\n'); result.append('\n');
result.append(branch.getName()).append(": {\n").append(branch.toGroovy()).append("\n}"); result.append('"' + StringEscapeUtils.escapeJava(branch.getName()) + '"')
.append(": {\n")
.append(branch.toGroovy())
.append("\n}");
} }
if (failFast != null && failFast) { if (failFast != null && failFast) {
result.append(",\nfailFast: true"); result.append(",\nfailFast: true");
Expand Down
36 changes: 20 additions & 16 deletions pipeline-model-definition/pom.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -74,27 +74,27 @@
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId> <groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId> <artifactId>workflow-cps</artifactId>
<version>2.21</version> <version>2.23</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId> <groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId> <artifactId>workflow-api</artifactId>
<version>2.7</version> <version>2.8</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId> <groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId> <artifactId>workflow-job</artifactId>
<version>2.8</version> <version>2.9</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId> <groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-multibranch</artifactId> <artifactId>workflow-multibranch</artifactId>
<version>2.9</version> <version>2.9.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId> <groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-scm-step</artifactId> <artifactId>workflow-scm-step</artifactId>
<version>2.2</version> <version>2.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId> <groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down Expand Up @@ -129,7 +129,12 @@
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId> <groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId> <artifactId>workflow-support</artifactId>
<version>2.10</version> <version>2.11</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>1.3</version>
</dependency> </dependency>


<!-- JSON schema stuff --> <!-- JSON schema stuff -->
Expand All @@ -144,7 +149,13 @@
<version>2.2.3</version> <version>2.2.3</version>
</dependency> </dependency>


<!-- TEST deps --> <!-- TEST deps -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps-global-lib</artifactId>
<version>2.5</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins</groupId> <groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId> <artifactId>git</artifactId>
Expand All @@ -165,13 +176,6 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>


<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps-global-lib</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>

<dependency> <dependency>
<groupId>org.jenkins-ci.plugins</groupId> <groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-graph-analysis</artifactId> <artifactId>pipeline-graph-analysis</artifactId>
Expand Down Expand Up @@ -203,14 +207,14 @@
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId> <groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-scm-step</artifactId> <artifactId>workflow-scm-step</artifactId>
<version>2.2</version> <version>2.3</version>
<classifier>tests</classifier> <classifier>tests</classifier>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId> <groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId> <artifactId>workflow-support</artifactId>
<version>2.10</version> <version>2.11</version>
<classifier>tests</classifier> <classifier>tests</classifier>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/ */
package org.jenkinsci.plugins.pipeline.modeldefinition.parser package org.jenkinsci.plugins.pipeline.modeldefinition.parser


import com.cloudbees.groovy.cps.NonCPS
import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule
Expand All @@ -35,11 +36,13 @@ import org.codehaus.groovy.control.CompilationFailedException
import org.codehaus.groovy.control.CompilationUnit import org.codehaus.groovy.control.CompilationUnit
import org.codehaus.groovy.control.CompilerConfiguration import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.SourceUnit import org.codehaus.groovy.control.SourceUnit
import org.codehaus.groovy.control.customizers.ImportCustomizer
import org.jenkinsci.plugins.pipeline.modeldefinition.ASTSchema import org.jenkinsci.plugins.pipeline.modeldefinition.ASTSchema
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTPipelineDef import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTPipelineDef
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTStep import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTStep
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution
import org.jenkinsci.plugins.workflow.cps.CpsScript import org.jenkinsci.plugins.workflow.cps.CpsScript
import org.jenkinsci.plugins.workflow.cps.GroovyShellDecorator


import java.security.CodeSource import java.security.CodeSource
import java.security.cert.Certificate import java.security.cert.Certificate
Expand Down Expand Up @@ -92,7 +95,7 @@ public class Converter {
*/ */
public static ModelASTPipelineDef urlToPipelineDef(URL src) { public static ModelASTPipelineDef urlToPipelineDef(URL src) {
CompilationUnit cu = new CompilationUnit( CompilationUnit cu = new CompilationUnit(
CompilerConfiguration.DEFAULT, makeCompilerConfiguration(),
new CodeSource(src, new Certificate[0]), new CodeSource(src, new Certificate[0]),
new GroovyClassLoader()); new GroovyClassLoader());
cu.addSource(src); cu.addSource(src);
Expand All @@ -108,14 +111,28 @@ public class Converter {
*/ */
public static ModelASTPipelineDef scriptToPipelineDef(String script) { public static ModelASTPipelineDef scriptToPipelineDef(String script) {
CompilationUnit cu = new CompilationUnit( CompilationUnit cu = new CompilationUnit(
CompilerConfiguration.DEFAULT, makeCompilerConfiguration(),
new CodeSource(new URL("file", "", DEFAULT_CODE_BASE), (Certificate[]) null), new CodeSource(new URL("file", "", DEFAULT_CODE_BASE), (Certificate[]) null),
new GroovyClassLoader()) new GroovyClassLoader())
cu.addSource(PIPELINE_SCRIPT_NAME, script) cu.addSource(PIPELINE_SCRIPT_NAME, script)


return compilationUnitToPipelineDef(cu) return compilationUnitToPipelineDef(cu)
} }


private static CompilerConfiguration makeCompilerConfiguration() {
CompilerConfiguration cc = new CompilerConfiguration();

ImportCustomizer ic = new ImportCustomizer();
ic.addStarImports(NonCPS.class.getPackage().getName());
ic.addStarImports("hudson.model","jenkins.model");
for (GroovyShellDecorator d : GroovyShellDecorator.all()) {
d.customizeImports(null, ic);
}

cc.addCompilationCustomizers(ic);

return cc;
}
/** /**
* Takes a {@link CompilationUnit}, copmiles it with the {@link ModelParser} injected, and returns the resulting * Takes a {@link CompilationUnit}, copmiles it with the {@link ModelParser} injected, and returns the resulting
* {@link ModelASTPipelineDef} * {@link ModelASTPipelineDef}
Expand All @@ -140,7 +157,7 @@ public class Converter {


public static List<ModelASTStep> scriptToPlainSteps(String script) { public static List<ModelASTStep> scriptToPlainSteps(String script) {
CompilationUnit cu = new CompilationUnit( CompilationUnit cu = new CompilationUnit(
CompilerConfiguration.DEFAULT, makeCompilerConfiguration(),
new CodeSource(new URL("file", "", DEFAULT_CODE_BASE), (Certificate[]) null), new CodeSource(new URL("file", "", DEFAULT_CODE_BASE), (Certificate[]) null),
new GroovyClassLoader()) new GroovyClassLoader())
cu.addSource(PIPELINE_SCRIPT_NAME, script) cu.addSource(PIPELINE_SCRIPT_NAME, script)
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.pipeline.modeldefinition.parser; package org.jenkinsci.plugins.pipeline.modeldefinition.parser;


import com.cloudbees.groovy.cps.NonCPS;
import hudson.Extension; import hudson.Extension;
import org.codehaus.groovy.ast.ClassNode; import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.classgen.GeneratorContext; import org.codehaus.groovy.classgen.GeneratorContext;
Expand All @@ -8,6 +9,7 @@
import org.codehaus.groovy.control.CompilerConfiguration; import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.SourceUnit; import org.codehaus.groovy.control.SourceUnit;
import org.codehaus.groovy.control.customizers.CompilationCustomizer; import org.codehaus.groovy.control.customizers.CompilationCustomizer;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.jenkinsci.plugins.pipeline.modeldefinition.parser.ModelParser; import org.jenkinsci.plugins.pipeline.modeldefinition.parser.ModelParser;
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution; import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
import org.jenkinsci.plugins.workflow.cps.GroovyShellDecorator; import org.jenkinsci.plugins.workflow.cps.GroovyShellDecorator;
Expand All @@ -23,6 +25,12 @@
public class GroovyShellDecoratorImpl extends GroovyShellDecorator { public class GroovyShellDecoratorImpl extends GroovyShellDecorator {
@Override @Override
public void configureCompiler(@CheckForNull CpsFlowExecution context, CompilerConfiguration cc) { public void configureCompiler(@CheckForNull CpsFlowExecution context, CompilerConfiguration cc) {
ImportCustomizer ic = new ImportCustomizer();
ic.addStarImports(NonCPS.class.getPackage().getName());
ic.addStarImports("hudson.model","jenkins.model");
this.customizeImports(context, ic);
cc.addCompilationCustomizers(ic);

cc.addCompilationCustomizers(new CompilationCustomizer(CompilePhase.CANONICALIZATION) { cc.addCompilationCustomizers(new CompilationCustomizer(CompilePhase.CANONICALIZATION) {
@Override @Override
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ public void setUp() throws Exception {
"skippedWhen", "skippedWhen",
"parallelPipelineWithFailFast", "parallelPipelineWithFailFast",
"whenBranch", "whenBranch",
"whenEnv" "whenEnv",
"parallelPipelineWithSpaceInBranch",
"parallelPipelineQuoteEscaping"
); );


public static Iterable<Object[]> configsWithErrors() { public static Iterable<Object[]> configsWithErrors() {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import hudson.model.Result; import hudson.model.Result;
import hudson.model.Slave; import hudson.model.Slave;
import jenkins.plugins.git.GitSCMSource;
import org.jenkinsci.plugins.pipeline.modeldefinition.actions.ExecutionModelAction; import org.jenkinsci.plugins.pipeline.modeldefinition.actions.ExecutionModelAction;
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTBranch; import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTBranch;
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTScriptBlock; import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTScriptBlock;
Expand All @@ -40,13 +41,17 @@
import org.jenkinsci.plugins.workflow.graph.FlowNode; import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner; import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner;
import org.jenkinsci.plugins.workflow.job.WorkflowRun; import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.libs.GlobalLibraries;
import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration;
import org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever;
import org.jenkinsci.plugins.workflow.pipelinegraphanalysis.GenericStatus; import org.jenkinsci.plugins.workflow.pipelinegraphanalysis.GenericStatus;
import org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StatusAndTiming; import org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StatusAndTiming;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.Issue;


import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -160,6 +165,20 @@ public void parallelPipeline() throws Exception {
.go(); .go();
} }


@Test
public void parallelPipelineQuoteEscaping() throws Exception {
expect("parallelPipelineQuoteEscaping")
.logContains("[Pipeline] { (foo)", "[first] { (Branch: first)", "[\"second\"] { (Branch: \"second\")")
.go();
}

@Test
public void parallelPipelineWithSpaceInBranch() throws Exception {
expect("parallelPipelineWithSpaceInBranch")
.logContains("[Pipeline] { (foo)", "[first one] { (Branch: first one)", "[second one] { (Branch: second one)")
.go();
}

@Test @Test
public void parallelPipelineWithFailFast() throws Exception { public void parallelPipelineWithFailFast() throws Exception {
expect("parallelPipelineWithFailFast") expect("parallelPipelineWithFailFast")
Expand Down Expand Up @@ -388,6 +407,23 @@ public boolean apply(FlowNode input) {
}; };
} }


@Issue("JENKINS-40642")
@Test
public void libraryAnnotation() throws Exception {
otherRepo.init();
otherRepo.write("vars/myecho.groovy", "def call() {echo 'something special'}");
otherRepo.write("vars/myecho.txt", "Says something very special!");
otherRepo.git("add", "vars");
otherRepo.git("commit", "--message=init");
GlobalLibraries.get().setLibraries(Collections.singletonList(
new LibraryConfiguration("echo-utils",
new SCMSourceRetriever(new GitSCMSource(null, otherRepo.toString(), "", "*", "", true)))));

expect("libraryAnnotation")
.logContains("something special")
.go();
}

@Issue("JENKINS-40188") @Issue("JENKINS-40188")
@Test @Test
public void booleanParamBuildStep() throws Exception { public void booleanParamBuildStep() throws Exception {
Expand All @@ -396,5 +432,4 @@ public void booleanParamBuildStep() throws Exception {
.logContains("[Pipeline] { (promote)", "Scheduling project") .logContains("[Pipeline] { (promote)", "Scheduling project")
.go(); .go();
} }

} }
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,31 @@
{"pipeline": {
"stages": [ {
"name": "foo",
"branches": [
{
"name": "first",
"steps": [ {
"name": "echo",
"arguments": {
"isLiteral": true,
"value": "First branch"
}
}]
},
{
"name": "\"second\"",
"steps": [ {
"name": "echo",
"arguments": {
"isLiteral": true,
"value": "Second branch"
}
}]
}
]
}],
"agent": {
"isLiteral": true,
"value": "none"
}
}}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,31 @@
{"pipeline": {
"stages": [ {
"name": "foo",
"branches": [
{
"name": "first one",
"steps": [ {
"name": "echo",
"arguments": {
"isLiteral": true,
"value": "First branch"
}
}]
},
{
"name": "second one",
"steps": [ {
"name": "echo",
"arguments": {
"isLiteral": true,
"value": "Second branch"
}
}]
}
]
}],
"agent": {
"isLiteral": true,
"value": "none"
}
}}
Loading

0 comments on commit 96a34ed

Please sign in to comment.