Skip to content
Permalink
Browse files

Merge branch 'master' into JENKINS-40370

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 96a34eda839c2436181a9f9889662256d187970f
@@ -4,6 +4,7 @@
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringEscapeUtils;
import org.jenkinsci.plugins.pipeline.modeldefinition.validator.ModelValidator;

/**
@@ -112,7 +113,10 @@ public String toGroovy() {
result.append(',');
}
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) {
result.append(",\nfailFast: true");
@@ -74,27 +74,27 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.21</version>
<version>2.23</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.7</version>
<version>2.8</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.8</version>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-multibranch</artifactId>
<version>2.9</version>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-scm-step</artifactId>
<version>2.2</version>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
@@ -129,7 +129,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<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>

<!-- JSON schema stuff -->
@@ -144,7 +149,13 @@
<version>2.2.3</version>
</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>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
@@ -165,13 +176,6 @@
<scope>test</scope>
</dependency>

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

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

import com.cloudbees.groovy.cps.NonCPS
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule
@@ -35,11 +36,13 @@ import org.codehaus.groovy.control.CompilationFailedException
import org.codehaus.groovy.control.CompilationUnit
import org.codehaus.groovy.control.CompilerConfiguration
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.ast.ModelASTPipelineDef
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTStep
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution
import org.jenkinsci.plugins.workflow.cps.CpsScript
import org.jenkinsci.plugins.workflow.cps.GroovyShellDecorator

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

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
* {@link ModelASTPipelineDef}
@@ -140,7 +157,7 @@ public class Converter {

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

import com.cloudbees.groovy.cps.NonCPS;
import hudson.Extension;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.classgen.GeneratorContext;
@@ -8,6 +9,7 @@
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.SourceUnit;
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.workflow.cps.CpsFlowExecution;
import org.jenkinsci.plugins.workflow.cps.GroovyShellDecorator;
@@ -23,6 +25,12 @@
public class GroovyShellDecoratorImpl extends GroovyShellDecorator {
@Override
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) {
@Override
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException {
@@ -134,7 +134,9 @@ public void setUp() throws Exception {
"skippedWhen",
"parallelPipelineWithFailFast",
"whenBranch",
"whenEnv"
"whenEnv",
"parallelPipelineWithSpaceInBranch",
"parallelPipelineQuoteEscaping"
);

public static Iterable<Object[]> configsWithErrors() {
@@ -26,6 +26,7 @@
import com.google.common.base.Predicate;
import hudson.model.Result;
import hudson.model.Slave;
import jenkins.plugins.git.GitSCMSource;
import org.jenkinsci.plugins.pipeline.modeldefinition.actions.ExecutionModelAction;
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTBranch;
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTScriptBlock;
@@ -40,13 +41,17 @@
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner;
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.StatusAndTiming;
import org.junit.BeforeClass;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;

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

import static org.junit.Assert.assertEquals;
@@ -160,6 +165,20 @@ public void parallelPipeline() throws Exception {
.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
public void parallelPipelineWithFailFast() throws Exception {
expect("parallelPipelineWithFailFast")
@@ -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")
@Test
public void booleanParamBuildStep() throws Exception {
@@ -396,5 +432,4 @@ public void booleanParamBuildStep() throws Exception {
.logContains("[Pipeline] { (promote)", "Scheduling project")
.go();
}

}
@@ -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"
}
}}
@@ -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"
}
}}

0 comments on commit 96a34ed

Please sign in to comment.
You can’t perform that action at this time.