Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into JENKINS-37778
Browse files Browse the repository at this point in the history
 Conflicts:
	pipeline-model-definition/pom.xml
	pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Root.groovy
	pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Stage.groovy
  • Loading branch information
rsandell committed Nov 7, 2016
2 parents 1617729 + eee41f8 commit 7e5cbd4
Show file tree
Hide file tree
Showing 30 changed files with 299 additions and 162 deletions.
2 changes: 1 addition & 1 deletion pipeline-model-declarative-agent/pom.xml
Expand Up @@ -42,7 +42,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.18</version>
<version>2.21</version>
</dependency>
</dependencies>

Expand Down
Expand Up @@ -26,7 +26,6 @@

import hudson.ExtensionPoint;
import hudson.model.AbstractDescribableImpl;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.jenkinsci.plugins.workflow.cps.CpsScript;
import org.jenkinsci.plugins.workflow.cps.CpsThread;

Expand All @@ -47,13 +46,13 @@ public abstract class DeclarativeAgent extends AbstractDescribableImpl<Declarati
* @throws Exception if the script source cannot be loaded or we're called from outside a CpsThread.
*/
@SuppressWarnings("unchecked")
@Whitelisted
public DeclarativeAgentScript getScript(CpsScript cpsScript) throws Exception {
CpsThread c = CpsThread.current();
if (c == null)
throw new IllegalStateException("Expected to be called from CpsThread");

return (DeclarativeAgentScript) cpsScript.getClass().getClassLoader()
return (DeclarativeAgentScript) cpsScript.getClass()
.getClassLoader()
.loadClass(getDescriptor().getDeclarativeAgentScriptClass())
.getConstructor(CpsScript.class, DeclarativeAgent.class)
.newInstance(cpsScript, this);
Expand Down
Expand Up @@ -25,12 +25,15 @@

import hudson.ExtensionList;
import hudson.model.Descriptor;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.jenkinsci.plugins.structs.SymbolLookup;
import org.jenkinsci.plugins.structs.describable.DescribableModel;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand All @@ -43,7 +46,7 @@
public abstract class DeclarativeAgentDescriptor extends Descriptor<DeclarativeAgent> {

/**
* The name for this agent type. Should match the {@code Symbol} on the class.
* The name for this agent type. Defaults to the first string in the {@code Symbol} on the class.
*
* @return The name.
*/
Expand All @@ -57,7 +60,8 @@ public abstract class DeclarativeAgentDescriptor extends Descriptor<DeclarativeA
}

/**
* The full package and class name for the {@link DeclarativeAgentScript} class corresponding to this.
* The full package and class name for the {@link DeclarativeAgentScript} class corresponding to this. Defaults to
* the {@link DeclarativeAgent} class name with "Script" appended to the end.
*
* @return The class name, defaulting to the {@link DeclarativeAgent} {@link #clazz} class name with "Script" appended.
*/
Expand Down Expand Up @@ -86,6 +90,11 @@ public DeclarativeAgent newInstance() throws Exception {
return clazz.newInstance();
}

/**
* Get all {@link DeclarativeAgentDescriptor}s.
*
* @return a list of all {@link DeclarativeAgentDescriptor}s registered.`
*/
public static ExtensionList<DeclarativeAgentDescriptor> all() {
return ExtensionList.lookup(DeclarativeAgentDescriptor.class);
}
Expand Down Expand Up @@ -129,8 +138,7 @@ public static Map<String,DescribableModel> zeroArgModels() {
* @param name The name for the descriptor to look up
* @return The corresponding descriptor or null if not found.
*/
@Whitelisted
public static @CheckForNull DeclarativeAgentDescriptor byName(@Nonnull String name) {
public static @Nullable DeclarativeAgentDescriptor byName(@Nonnull String name) {
return (DeclarativeAgentDescriptor) SymbolLookup.get().findDescriptor(DeclarativeAgent.class, name);
}

Expand All @@ -142,9 +150,8 @@ public static Map<String,DescribableModel> zeroArgModels() {
* @return The instantiated {@link DeclarativeAgent} instance, or null if the name isn't found.
* @throws Exception
*/
@Whitelisted
public static @CheckForNull DeclarativeAgent instanceForName(@Nonnull String name,
Map<String,Object> arguments) throws Exception {
public static @Nullable DeclarativeAgent instanceForName(@Nonnull String name,
Map<String,Object> arguments) throws Exception {
DeclarativeAgentDescriptor descriptor = byName(name);

if (descriptor != null) {
Expand All @@ -162,7 +169,6 @@ public static Map<String,DescribableModel> zeroArgModels() {
* @return The instantiated {@link DeclarativeAgent} instance.
* @throws Exception
*/
@Whitelisted
public static @Nonnull DeclarativeAgent instanceForDescriptor(@Nonnull DeclarativeAgentDescriptor descriptor,
Map<String,Object> arguments) throws Exception {
if (zeroArgModels().keySet().contains(descriptor.getName())) {
Expand Down
21 changes: 8 additions & 13 deletions pipeline-model-definition/pom.xml
Expand Up @@ -64,17 +64,17 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.18</version>
<version>2.21</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.6</version>
<version>2.8</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-multibranch</artifactId>
<version>2.8</version>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand All @@ -84,12 +84,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.1</version>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.4</version>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -99,18 +99,13 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>docker-workflow</artifactId>
<version>1.8</version>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>1.22</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials-binding</artifactId>
Expand Down Expand Up @@ -153,7 +148,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps-global-lib</artifactId>
<version>2.3</version>
<version>2.4</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -181,7 +176,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>2.2</version>
<version>2.10</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
Expand Up @@ -31,15 +31,13 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
import hudson.ExtensionList
import hudson.model.Describable
import hudson.model.Descriptor
import hudson.triggers.TriggerDescriptor
import org.apache.commons.codec.digest.DigestUtils
import org.jenkinsci.plugins.pipeline.modeldefinition.actions.ExecutionModelAction
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTPipelineDef
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTStages
import org.jenkinsci.plugins.pipeline.modeldefinition.model.MethodsToList
import org.jenkinsci.plugins.pipeline.modeldefinition.parser.Converter
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
import org.jenkinsci.plugins.structs.SymbolLookup
import org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable
import org.jenkinsci.plugins.workflow.cps.CpsScript
import org.jenkinsci.plugins.workflow.job.WorkflowRun

Expand All @@ -66,7 +64,6 @@ public class Utils {
* we'll get the actual name from actualFieldName(...)
* @return True if the field exists and is of the given type.
*/
@Whitelisted
public static boolean isFieldA(Class fieldType, Class actualClass, String fieldName) {
def actualFieldName = actualFieldName(actualClass, fieldName)
def realFieldType = actualClass.metaClass.getMetaProperty(actualFieldName)?.type
Expand All @@ -85,7 +82,6 @@ public class Utils {
* @param fieldName The original field name, which could need to be pluralized.
* @return The real field name, pluralized if necessary, or null if not found.
*/
@Whitelisted
public static String actualFieldName(Class actualClass, String fieldName) {
if (actualClass.metaClass.getMetaProperty(fieldName) != null) {
return fieldName
Expand All @@ -103,7 +99,6 @@ public class Utils {
* @param fieldName The field name we're looking for, which could get pluralized.
* @return The class of the field in the inspected class, or the class contained in the list or map.
*/
@Whitelisted
public static Class actualFieldType(Class actualClass, String fieldName) {
def actualFieldName = actualFieldName(actualClass, fieldName)
if (actualFieldName == null) {
Expand Down Expand Up @@ -131,7 +126,6 @@ public class Utils {
* @param c A class.
* @return The parameterized type argument for the class, if it's a {@link MethodsToList} class. Null otherwise.
*/
@Whitelisted
public static Class<Describable> getMethodsToListType(Class c) {
Class retClass
c.genericInterfaces.each { Type t ->
Expand All @@ -152,7 +146,6 @@ public class Utils {
* @param o The object to check
* @return True if the object is an instance of the class, false otherwise
*/
@Whitelisted
public static boolean instanceOfWrapper(Class c, Object o) {
return c.isInstance(o)
}
Expand All @@ -164,17 +157,10 @@ public class Utils {
* @param o The class to check
* @return True if o can be assigned to c, false otherwise
*/
@Whitelisted
public static boolean assignableFromWrapper(Class c, Class o) {
return c.isAssignableFrom(o)
}

@Whitelisted
public static Object[] toObjectArray(List<Object> origList) {
return origList.toArray()
}

@Whitelisted
public static boolean hasScmContext(CpsScript script) {
try {
// Just rely on SCMVar's own context-checking (via CpsScript) rather than brewing our own.
Expand All @@ -186,7 +172,6 @@ public class Utils {
}
}

@Whitelisted
static void attachExecutionModel(CpsScript script) {
WorkflowRun r = script.$build()
ModelASTPipelineDef model = Converter.parseFromCpsScript(script)
Expand All @@ -198,6 +183,10 @@ public class Utils {
r.addAction(new ExecutionModelAction(stages))
}

public static String stringToSHA1(String s) {
return DigestUtils.sha1Hex(s)
}

/**
* Creates and sets the loading for a cache of {@link Describable}s descending from the given descriptor type.
*
Expand Down
Expand Up @@ -25,7 +25,6 @@ package org.jenkinsci.plugins.pipeline.modeldefinition.model

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings

import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
import org.jenkinsci.plugins.workflow.job.WorkflowRun
import org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper

Expand All @@ -41,7 +40,6 @@ public abstract class AbstractBuildConditionResponder<T extends AbstractBuildCon


@Override
@Whitelisted
public void modelFromMap(Map<String,Object> inMap) {

inMap.each { conditionName, conditionClosure ->
Expand All @@ -54,8 +52,6 @@ public abstract class AbstractBuildConditionResponder<T extends AbstractBuildCon
}
}


@Whitelisted
public List<Closure> satisfiedConditions(Object runWrapperObj) {
RunWrapper runWrapper = (RunWrapper)runWrapperObj
WorkflowRun run = (WorkflowRun)runWrapper.getRawBuild()
Expand Down
Expand Up @@ -29,7 +29,6 @@ import groovy.transform.ToString
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgent
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.None
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted


/**
Expand All @@ -42,18 +41,15 @@ import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
@EqualsAndHashCode
@SuppressFBWarnings(value="SE_NO_SERIALVERSIONID")
public class Agent implements Serializable {
@Whitelisted
Map<String,String> arguments = [:]

@Whitelisted
public Agent(Map<String,String> args) {
this.arguments.putAll(args)
}

/**
* Special constructor for the no-additional-arguments agent types, i.e., none and any
*/
@Whitelisted
public Agent(String s) {
this.arguments.put(s, "true")
}
Expand All @@ -63,7 +59,6 @@ public class Agent implements Serializable {
*
* @return The instantiated declarative agent or null if not found.
*/
@Whitelisted
public DeclarativeAgent getDeclarativeAgent() {
DeclarativeAgentDescriptor foundDescriptor = DeclarativeAgentDescriptor.all().find { d ->
arguments.containsKey(d.getName())
Expand All @@ -76,7 +71,6 @@ public class Agent implements Serializable {
}
}

@Whitelisted
public boolean hasAgent() {
DeclarativeAgent a = getDeclarativeAgent()
return a != null && !None.class.isInstance(a)
Expand Down
Expand Up @@ -32,9 +32,6 @@ import groovy.transform.ToString
import hudson.model.JobProperty
import hudson.model.JobPropertyDescriptor
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
import org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable
import org.jenkinsci.plugins.workflow.cps.CpsScript

import javax.annotation.Nonnull

Expand Down Expand Up @@ -72,7 +69,6 @@ public class JobProperties implements Serializable, MethodsToList<JobProperty> {
*
* @return A map of valid property type keys to their actual type IDs.
*/
@Whitelisted
public static Map<String,String> getAllowedPropertyTypes() {
return propertyTypeCache.get(CACHE_KEY)
}
Expand All @@ -83,7 +79,6 @@ public class JobProperties implements Serializable, MethodsToList<JobProperty> {
* @param key The key to look up.
* @return The type ID for that key, if it's in the property types cache.
*/
@Whitelisted
public static String typeForKey(@Nonnull String key) {
return getAllowedPropertyTypes().get(key)
}
Expand Down

0 comments on commit 7e5cbd4

Please sign in to comment.