Skip to content

Commit

Permalink
Added Job DSL support. Implements JENKINS-30261
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Lacour authored and MadsNielsen committed Sep 14, 2015
1 parent f2b26e1 commit 3d7b860
Show file tree
Hide file tree
Showing 6 changed files with 456 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Expand Up @@ -424,6 +424,13 @@
<version>1.0</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>job-dsl</artifactId>
<version>1.38</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>net.praqma</groupId>
<artifactId>praqmajutils</artifactId>
Expand Down
206 changes: 206 additions & 0 deletions src/main/java/net/praqma/hudson/scm/ClearCaseUcmJobDslContext.java
@@ -0,0 +1,206 @@
package net.praqma.hudson.scm;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javaposse.jobdsl.dsl.Context;
import static javaposse.jobdsl.dsl.Preconditions.checkArgument;
import static javaposse.jobdsl.plugin.ContextExtensionPoint.executeInContext;
import net.praqma.hudson.scm.pollingmode.PollChildMode;
import net.praqma.hudson.scm.pollingmode.PollRebaseMode;
import net.praqma.hudson.scm.pollingmode.PollSelfMode;
import net.praqma.hudson.scm.pollingmode.PollSiblingMode;
import net.praqma.hudson.scm.pollingmode.PollSubscribeMode;
import net.praqma.hudson.scm.pollingmode.PollingMode;

public class ClearCaseUcmJobDslContext implements Context {

String loadModules = "All";
Map<String, String> loadModulesOptions = new HashMap<String, String>() {
{
put("ALL", "All");
put("MODIFIABLE", "Modifiable");
}
};

public void loadModules(String value) {
value = value.toUpperCase();
checkArgument(loadModulesOptions.containsKey(value), "loadModules must be one of: " + loadModulesOptions.keySet().toString());
loadModules = loadModulesOptions.get(value);
}

boolean ignoreUnmodifiableChanges = false;

public void ignoreUnmodifiableChanges() {
ignoreUnmodifiableChanges = true;
}

public void ignoreUnmodifiableChanges(boolean value) {
ignoreUnmodifiableChanges = value;
}

boolean trimmedChangeset = false;

public void trimmedChangeset() {
trimmedChangeset = true;
}

public void trimmedChangeset(boolean value) {
trimmedChangeset = value;
}

boolean removeViewPrivateFiles = true;

public void removeViewPrivateFiles() {
removeViewPrivateFiles = true;
}

public void removeViewPrivateFiles(boolean value) {
removeViewPrivateFiles = value;
}

String buildProject = null;

public void buildProject(String value) {
buildProject = value;
}

boolean setDescription = true;

public void setDescription() {
setDescription = true;
}

public void setDescription(boolean value) {
setDescription = value;
}

boolean makeTag = false;

public void makeTag() {
makeTag = true;
}

public void makeTag(boolean value) {
makeTag = value;
}

boolean recommendBaseline = false;

public void recommendBaseline() {
recommendBaseline = true;
}

public void recommendBaseline(boolean value) {
recommendBaseline = value;
}

boolean forceDeliver = false;

public void forceDeliver() {
forceDeliver = true;
}

public void forceDeliver(boolean value) {
forceDeliver = value;
}

String nameTemplate = "[project]_[date]_[time]";

public void nameTemplate(String value) {
nameTemplate = value;
}

String treatUnstableAsSuccessful = "successful";

public void treatUnstableAsSuccessful() {
treatUnstableAsSuccessful = "successful";
}

public void treatUnstableAsSuccessful(boolean value) {
if (value) {
treatUnstableAsSuccessful = "successful";
} else {
treatUnstableAsSuccessful = "failed";
}
}

PollingMode pollingMode = new PollChildMode("INITIAL");
Set<String> pollingModes = new HashSet<String>() {
{
add("CHILD");
add("REBASE");
add("SELF");
add("SIBLING");
add("SUBSCRIBE");
}
};
Set<String> promotionLevels = new HashSet<String>() {
{
add("ANY");
add("INITIAL");
add("BUILT");
add("TESTED");
add("RELEASED");
add("REJECTED");
}
};

public void pollingMode(String mode, String component, Runnable closure) {
mode = mode.toUpperCase();
checkArgument(pollingModes.contains(mode), "pollingMode must be one of: " + pollingModes.toString());

String promotionLevel;
if (mode.equals("SELF")) {
promotionLevel = "ANY";
} else {
promotionLevel = "INITIAL";
}

pollingMode(mode, component, promotionLevel, closure);
}

public void pollingMode(String mode, String component, String promotionLevel, Runnable closure) {
mode = mode.toUpperCase();
checkArgument(pollingModes.contains(mode), "pollingMode must be one of: " + pollingModes.toString());

promotionLevel = promotionLevel.toUpperCase();
checkArgument(promotionLevels.contains(promotionLevel), "promotionLevel must be one of: " + promotionLevels.toString());

PollingModeJobDslContext context = new PollingModeJobDslContext(promotionLevel);
executeInContext(closure, context);

if (mode.equals("CHILD")) {
PollChildMode pollChildMode = new PollChildMode(context.promotionLevel);
pollChildMode.setComponent(component);
pollChildMode.setCreateBaseline(context.createBaseline);
pollChildMode.setNewest(context.useNewest);
pollingMode = pollChildMode;
} else if (mode.equals("REBASE")) {
PollRebaseMode pollRebaseMode = new PollRebaseMode(context.promotionLevel);
pollRebaseMode.setComponent(component);
pollRebaseMode.setCreateBaseline(context.createBaseline);
pollRebaseMode.setExcludeList(context.excludeList);
pollingMode = pollRebaseMode;
} else if (mode.equals("SELF")) {
PollSelfMode pollSelfMode = new PollSelfMode(context.promotionLevel);
pollSelfMode.setComponent(component);
pollSelfMode.setNewest(context.useNewest);
pollingMode = pollSelfMode;
} else if (mode.equals("SIBLING")) {
PollSiblingMode pollSiblingMode = new PollSiblingMode(context.promotionLevel);
pollSiblingMode.setComponent(component);
pollSiblingMode.setCreateBaseline(context.createBaseline);
pollSiblingMode.setUseHyperLinkForPolling(context.hyperlinkPolling);
pollSiblingMode.setNewest(context.useNewest);
pollingMode = pollSiblingMode;
} else if (mode.equals("SUBSCRIBE")) {
PollSubscribeMode pollSubscribeMode = new PollSubscribeMode(context.promotionLevel, context.components, context.jobs);
pollSubscribeMode.setComponent(component);
pollSubscribeMode.setCascadePromotion(context.cascadePromotion);
pollSubscribeMode.setNewest(context.useNewest);
pollingMode = pollSubscribeMode;
}
}
}
103 changes: 103 additions & 0 deletions src/main/java/net/praqma/hudson/scm/ClearCaseUcmJobDslExtension.java
@@ -0,0 +1,103 @@
package net.praqma.hudson.scm;

import hudson.Extension;
import hudson.scm.SCM;
import javaposse.jobdsl.dsl.RequiresPlugin;
import javaposse.jobdsl.dsl.helpers.ScmContext;
import javaposse.jobdsl.plugin.ContextExtensionPoint;
import javaposse.jobdsl.plugin.DslExtensionMethod;

/*
job {
scm {
clearCaseUCM (String stream) {
loadModules (String loadModules) // loadModules can be: 'ALL', 'MODIFIABLE'. Defaults to 'ALL'
nameTemplate (String nameTemplate) // Defaults to '[project]_[date]_[time]'
recommendBaseline (boolean recommend = true) // Defaults to false
makeTag (boolean makeTag = true) // Defaults to false
setDescription (boolean setDescription = true) // Defaults to true
treatUnstableAsSuccessful (boolean success = true) // Defaults to true
forceDeliver (boolean forceDeliver = true) // Defaults to false
removeViewPrivateFiles (boolean remove = true) // Defaults to true
trimmedChangeset (boolean trim = true) // Defaults to false
ignoreUnmodifiableChanges (boolean ignore = true) // Defaults to false
buildProject (String project)
pollingMode(String mode, String component) { //mode can be: 'CHILD','REBASE','SELF','SIBLING','SUBSCRIBE'. Defaults to 'CHILD'.
pollingMode(String mode, String component, String promotionLevel){ //promotionLevel can be: 'ANY','INITIAL','BUILT','TESTED','RELEASED','REJECTED'. Defaults to lowest available.
//Applicable: All
promotionLevel (String promotionLevel) //promotionLevel can be: 'ANY','INITIAL','BUILT','TESTED','RELEASED','REJECTED'.
//Applicable: CHILD, REBASE, SIBLING
createBaseline (boolean create = true) // Defaults to true
//Applicable: REBASE
excludeList (String excludeList)
//Applicable: SIBLING
hyperlinkPolling (String polling = true) // Defaults to false
//Applicable: SUBSCRIBE, SELF, CHILD, SIBLING
useNewest (boolean useNewest = true) // Defaults to false
//Applicable: SUBSCRIBE
cascadePromotion (boolean cascade = true) // Defaults to true
components {
component (String selection)
}
jobs {
job (String name, String ignores = null)
}
}
}
}
}
}
job('cc_gen') {
scm {
clearCaseUCM (/dev@\foo_bar/) {
loadModules 'ALL'
nameTemplate '[project]_[date]_[time]'
recommendBaseline false
makeTag false
setDescription true
treatUnstableAsSuccessful true
forceDeliver false
removeViewPrivateFiles true
trimmedChangeset false
ignoreUnmodifiableChanges false
pollingMode('CHILD', /sys@\foo_bar/, 'TESTED'){
createBaseline true
}
}
}
}
*/

@Extension(optional = true)
public class ClearCaseUcmJobDslExtension extends ContextExtensionPoint {
@RequiresPlugin(id = "clearcase-ucm-plugin", minimumVersion = "1.6.4")
@DslExtensionMethod(context = ScmContext.class)
public Object clearCaseUCM(String stream, Runnable closure){
ClearCaseUcmJobDslContext context = new ClearCaseUcmJobDslContext();
executeInContext(closure, context);

SCM scm = new CCUCMScm(context.loadModules,
false,
context.pollingMode,
stream,
context.treatUnstableAsSuccessful,
context.nameTemplate,
context.forceDeliver,
context.recommendBaseline,
context.makeTag,
context.setDescription,
context.buildProject,
context.removeViewPrivateFiles,
context.trimmedChangeset,
context.ignoreUnmodifiableChanges);
return scm;
}
}
14 changes: 14 additions & 0 deletions src/main/java/net/praqma/hudson/scm/ComponentsJobDslContext.java
@@ -0,0 +1,14 @@
package net.praqma.hudson.scm;

import java.util.ArrayList;
import java.util.List;
import javaposse.jobdsl.dsl.Context;
import net.praqma.hudson.scm.pollingmode.ComponentSelectionCriteriaRequirement;

class ComponentsJobDslContext implements Context{
List<ComponentSelectionCriteriaRequirement> components = new ArrayList<ComponentSelectionCriteriaRequirement>();

public void component(String selection){
components.add(new ComponentSelectionCriteriaRequirement(selection));
}
}
18 changes: 18 additions & 0 deletions src/main/java/net/praqma/hudson/scm/JobsJobDslContext.java
@@ -0,0 +1,18 @@
package net.praqma.hudson.scm;

import java.util.ArrayList;
import java.util.List;
import javaposse.jobdsl.dsl.Context;
import net.praqma.hudson.scm.pollingmode.JobNameRequirement;

class JobsJobDslContext implements Context {
List<JobNameRequirement> jobs = new ArrayList<JobNameRequirement>();

public void job(String name) {
jobs.add(new JobNameRequirement(name, null));
}

public void job(String name, String ignores) {
jobs.add(new JobNameRequirement(name, ignores));
}
}

0 comments on commit 3d7b860

Please sign in to comment.