Skip to content
Permalink
Browse files
Merge pull request #6 from jenkinsci/multibranch-workflow-JENKINS-26129
[JENKINS-26129] Adapting to upstream changes
  • Loading branch information
jglick committed Jul 27, 2015
2 parents 1f7e685 + 068fba8 commit eeeab34f131ebfd5aac1622dbd36948975839bc6
Showing with 236 additions and 177 deletions.
  1. +9 −4 pom.xml
  2. +4 −4 src/main/java/org/cloudbees/literate/jenkins/BuildEnvironmentMapperDescriptor.java
  3. +11 −18 src/main/java/org/cloudbees/literate/jenkins/DefaultBuildEnvironmentMapper.java
  4. +10 −6 src/main/java/org/cloudbees/literate/jenkins/FilePathRepository.java
  5. +7 −6 src/main/java/org/cloudbees/literate/jenkins/LiterateBranchBuild.java
  6. +11 −2 src/main/java/org/cloudbees/literate/jenkins/LiterateBranchProject.java
  7. +7 −7 src/main/java/org/cloudbees/literate/jenkins/LiterateBranchProperty.java
  8. +5 −2 src/main/java/org/cloudbees/literate/jenkins/LiterateBuilder.java
  9. +8 −6 src/main/java/org/cloudbees/literate/jenkins/LiterateEnvironmentBuild.java
  10. +11 −6 src/main/java/org/cloudbees/literate/jenkins/LiterateEnvironmentProject.java
  11. +9 −11 src/main/java/org/cloudbees/literate/jenkins/LiterateMultibranchProject.java
  12. +1 −2 src/main/java/org/cloudbees/literate/jenkins/MigrateFreeStyleAction.java
  13. +8 −40 src/main/java/org/cloudbees/literate/jenkins/ParametersDefinitionBranchProperty.java
  14. +5 −1 src/main/java/org/cloudbees/literate/jenkins/ParentLiterateBranchBuildAction.java
  15. +8 −8 src/main/java/org/cloudbees/literate/jenkins/promotions/PromotionBranchProperty.java
  16. +13 −4 src/main/java/org/cloudbees/literate/jenkins/promotions/PromotionBuild.java
  17. +10 −5 src/main/java/org/cloudbees/literate/jenkins/promotions/PromotionProject.java
  18. +5 −1 src/main/java/org/cloudbees/literate/jenkins/promotions/PromotionTargetAction.java
  19. +24 −8 src/main/java/org/cloudbees/literate/jenkins/promotions/PromotionTrigger.java
  20. +1 −1 src/main/java/org/cloudbees/literate/jenkins/publishers/Agent.java
  21. +1 −1 src/main/java/org/cloudbees/literate/jenkins/publishers/ArtifactsAgent.java
  22. +3 −4 src/main/java/org/cloudbees/literate/jenkins/publishers/DefaultXmlAgent.java
  23. +1 −1 src/main/java/org/cloudbees/literate/jenkins/publishers/JUnitReportAgent.java
  24. +0 −29 src/main/resources/org/cloudbees/literate/jenkins/ParametersDefinitionBranchProperty/config.jelly
  25. +64 −0 src/test/java/org/cloudbees/literate/jenkins/ParametersDefinitionBranchPropertyTest.java
13 pom.xml
@@ -29,7 +29,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.509.4</version>
<version>1.580.3</version> <!-- to match branch-api -->
</parent>

<artifactId>literate</artifactId>
@@ -102,7 +102,7 @@
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.9</version>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.literate</groupId>
@@ -118,7 +118,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>branch-api</artifactId>
<version>0.2-beta-2</version>
<version>0.2-beta-4</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit</artifactId>
<version>1.6</version>
</dependency>
<!-- jenkins dependencies -->
<!-- test dependencies -->
@@ -176,7 +181,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<version>3.0.1</version>
<configuration>
<excludeFilterFile>src/findbugs/excludesFilter.xml</excludeFilterFile>
<failOnError>${maven.findbugs.failure.strict}</failOnError>
@@ -23,9 +23,9 @@
*/
package org.cloudbees.literate.jenkins;

import hudson.DescriptorExtensionList;
import hudson.ExtensionList;
import hudson.model.Descriptor;
import jenkins.model.Jenkins;
import java.util.List;

/**
* The {@link Descriptor} for {@link BuildEnvironmentMapper}.
@@ -39,7 +39,7 @@
*
* @return all the {@link BuildEnvironmentMapperDescriptor} instances.
*/
public static DescriptorExtensionList<BuildEnvironmentMapper, BuildEnvironmentMapperDescriptor> all() {
return Jenkins.getInstance().getDescriptorList(BuildEnvironmentMapper.class);
public static List<BuildEnvironmentMapperDescriptor> all() {
return ExtensionList.lookup(BuildEnvironmentMapperDescriptor.class);
}
}
@@ -50,12 +50,11 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.EnvVars;
import hudson.Extension;
import hudson.model.Descriptor;
import hudson.ExtensionList;
import hudson.model.Label;
import hudson.model.labels.LabelAtom;
import hudson.tools.ToolDescriptor;
import hudson.tools.ToolInstallation;
import jenkins.model.Jenkins;

import java.util.ArrayList;
import java.util.List;
@@ -85,14 +84,11 @@ public void buildEnvVars(@NonNull BuildEnvironment environment, EnvVars envVars)
List<ToolInstallation> result = new ArrayList<ToolInstallation>();
for (String component : environment.getComponents()) {
descriptors:
for (Descriptor<ToolInstallation> d : Jenkins.getInstance().getDescriptorList(ToolInstallation.class)) {
if (d instanceof ToolDescriptor) {
final ToolDescriptor descriptor = (ToolDescriptor) d;
for (ToolInstallation t : descriptor.getInstallations()) {
if (component.equalsIgnoreCase(t.getName())) {
result.add(t);
break descriptors;
}
for (ToolDescriptor descriptor : ExtensionList.lookup(ToolDescriptor.class)) {
for (ToolInstallation t : descriptor.getInstallations()) {
if (component.equalsIgnoreCase(t.getName())) {
result.add(t);
break descriptors;
}
}
}
@@ -110,14 +106,11 @@ public Label getLabel(@NonNull BuildEnvironment environment) {
if(component.contains("=")) continue;
boolean isToolInstallation = false;
descriptors:
for (Descriptor<ToolInstallation> d : Jenkins.getInstance().getDescriptorList(ToolInstallation.class)) {
if (d instanceof ToolDescriptor) {
final ToolDescriptor descriptor = (ToolDescriptor) d;
for (ToolInstallation t : descriptor.getInstallations()) {
if (component.equalsIgnoreCase(t.getName())) {
isToolInstallation = true;
break descriptors;
}
for (ToolDescriptor descriptor : ExtensionList.lookup(ToolDescriptor.class)) {
for (ToolInstallation t : descriptor.getInstallations()) {
if (component.equalsIgnoreCase(t.getName())) {
isToolInstallation = true;
break descriptors;
}
}
}
@@ -25,7 +25,6 @@

import hudson.FilePath;
import hudson.remoting.VirtualChannel;
import hudson.util.IOException2;
import org.cloudbees.literate.api.v1.vfs.PathNotFoundException;
import org.cloudbees.literate.api.v1.vfs.ProjectRepository;

@@ -34,6 +33,7 @@
import java.io.InputStream;
import java.util.Set;
import java.util.TreeSet;
import jenkins.MasterToSlaveFileCallable;

/**
* A {@link ProjectRepository} that is accessed using Jenkins' remoting {@link FilePath} interface.
@@ -90,7 +90,11 @@ private FilePath resolve(String path) throws PathNotFoundException {
* {@inheritDoc}
*/
public InputStream get(String filePath) throws PathNotFoundException, IOException {
return resolve(filePath).read();
try {
return resolve(filePath).read();
} catch (InterruptedException x) {
throw new IOException(x);
}
}

/**
@@ -100,7 +104,7 @@ public boolean isDirectory(String path) throws IOException {
try {
return resolve(path).isDirectory();
} catch (InterruptedException e) {
throw new IOException2(e);
throw new IOException(e);
}
}

@@ -111,7 +115,7 @@ public boolean isFile(String path) throws IOException {
try {
return resolve(path).act(new IsFile());
} catch (InterruptedException e) {
throw new IOException2(e);
throw new IOException(e);
}

}
@@ -155,14 +159,14 @@ public boolean isFile(String path) throws IOException {
}
return result;
} catch (InterruptedException e) {
throw new IOException2(e);
throw new IOException(e);
}
}

/**
* Remote closure to test if something is a file.
*/
private static class IsFile implements FilePath.FileCallable<Boolean> {
private static class IsFile extends MasterToSlaveFileCallable<Boolean> {
/**
* {@inheritDoc}
*/
@@ -44,7 +44,6 @@
import hudson.util.HttpResponses;
import hudson.util.IOUtils;
import jenkins.branch.BranchProperty;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.cloudbees.literate.api.v1.ExecutionEnvironment;
import org.cloudbees.literate.api.v1.Parameter;
@@ -335,7 +334,7 @@ protected Result doRun(final BuildListener listener) throws Exception, RunnerAbo
return r;
} finally {
// if the build was aborted in the middle, cancel all the child builds
Queue q = Jenkins.getInstance().getQueue();
Queue q = Queue.getInstance();
synchronized (q) {// avoid micro-locking on Queue#cancel
final int n = getNumber();
for (LiterateEnvironmentProject c : configurations) {
@@ -394,10 +393,12 @@ protected void post2(BuildListener listener) throws Exception {
@Override
protected WorkspaceList.Lease decideWorkspace(Node n, WorkspaceList wsl)
throws InterruptedException, IOException {
// TODO: this cast is indicative of abstraction problem
LiterateBranchProject project = (LiterateBranchProject) getProject();
return wsl.allocate(n.getWorkspaceFor(project.getParent())
.child(project.getBranch().getName()));
LiterateBranchProject project = getProject();
FilePath workspace = n.getWorkspaceFor(project.getParent());
if (workspace == null) {
throw new IOException("offline node " + n);
}
return wsl.allocate(workspace.child(project.getBranch().getName()));
}

/**
@@ -229,7 +229,11 @@ public synchronized SCM getScm() {
@Override
@NonNull
public SCMCheckoutStrategy getScmCheckoutStrategy() {
return Jenkins.getInstance().getDescriptorByType(SCMCheckoutStrategyImpl.DescriptorImpl.class).getInstance();
Jenkins j = Jenkins.getInstance();
if (j == null) {
throw new IllegalStateException("Jenkins has not started, or is shutting down"); // TODO 1.590+ getActiveInstance
}
return j.getDescriptorByType(SCMCheckoutStrategyImpl.DescriptorImpl.class).getInstance();
}

/**
@@ -640,8 +644,13 @@ private void calcPollingBaseline(AbstractBuild build, Launcher launcher, TaskLis
* {@inheritDoc}
*/
// TODO - Hack - child items of an item group that is a view container must to implement TopLevelItem
@Override
public TopLevelItemDescriptor getDescriptor() {
return (TopLevelItemDescriptor) Jenkins.getInstance().getDescriptorOrDie(LiterateBranchProject.class);
Jenkins j = Jenkins.getInstance();
if (j == null) {
throw new IllegalStateException("Jenkins has not started, or is shutting down"); // TODO 1.590+ getActiveInstance
}
return (TopLevelItemDescriptor) j.getDescriptorOrDie(LiterateBranchProject.class);
}

/**
@@ -25,15 +25,15 @@

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Job;
import hudson.model.Run;
import java.util.List;
import jenkins.branch.BranchProperty;
import jenkins.branch.JobDecorator;
import jenkins.branch.ProjectDecorator;
import org.cloudbees.literate.api.v1.ExecutionEnvironment;
import org.cloudbees.literate.api.v1.ProjectModelRequest;

import java.util.List;

/**
* A {@link BranchProperty} that is specifically for {@link LiterateMultibranchProject}s.
*
@@ -67,13 +67,13 @@ public void projectModelRequest(@NonNull ProjectModelRequest.Builder requestBuil
*/
@SuppressWarnings("unchecked")
@Override
public final <P extends AbstractProject<P, B>, B extends AbstractBuild<P, B>> ProjectDecorator<P, B> decorator(
public final <P extends Job<P, B>, B extends Run<P, B>> JobDecorator<P, B> jobDecorator(
Class<P> jobType) {
if (LiterateBranchProject.class.isAssignableFrom(jobType)) {
return (ProjectDecorator<P, B>) branchDecorator();
return (ProjectDecorator) branchDecorator();
}
if (LiterateEnvironmentProject.class.isAssignableFrom(jobType)) {
return (ProjectDecorator<P, B>) environmentDecorator();
return (ProjectDecorator) environmentDecorator();
}
return null;
}
@@ -185,8 +185,11 @@ public static boolean perform(AbstractBuild<?, ?> build, Launcher launcher, Buil
args.set(0, args.get(0).substring(2)); // trim off "#!"
commandLine = args.toArray(new String[args.size()]);
} else {
Shell.DescriptorImpl shellDescriptor =
Jenkins.getInstance().getDescriptorByType(Shell.DescriptorImpl.class);
Jenkins j = Jenkins.getInstance();
if (j == null) {
throw new IllegalStateException("Jenkins has not started, or is shutting down"); // TODO 1.590+ getActiveInstance
}
Shell.DescriptorImpl shellDescriptor = j.getDescriptorByType(Shell.DescriptorImpl.class);
commandLine =
new String[]{
shellDescriptor.getShellOrDefault(ws.getChannel()),
@@ -25,6 +25,7 @@

import hudson.AbortException;
import hudson.EnvVars;
import hudson.ExtensionList;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
@@ -38,7 +39,6 @@
import hudson.slaves.WorkspaceList;
import hudson.tasks.Publisher;
import hudson.tools.ToolInstallation;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.cloudbees.literate.api.v1.ExecutionEnvironment;
import org.cloudbees.literate.api.v1.ProjectModel;
@@ -202,7 +202,7 @@ protected Result doRun(final BuildListener listener) throws Exception, RunnerAbo
ProjectModel model = projectModelAction.getModel();
Map<Class<? extends Publisher>, List<Agent<? extends Publisher>>> agents = new LinkedHashMap<Class<?
extends Publisher>, List<Agent<? extends Publisher>>>();
for (Agent agent : Jenkins.getInstance().getExtensionList(Agent.class)) {
for (Agent agent : ExtensionList.lookup(Agent.class)) {
Class clazz = agent.getPublisherClass();
List<Agent<? extends Publisher>> list = agents.get(clazz);
if (list == null) {
@@ -329,10 +329,12 @@ protected void post2(BuildListener listener) throws Exception {
@Override
protected WorkspaceList.Lease decideWorkspace(Node n, WorkspaceList wsl)
throws InterruptedException, IOException {
// TODO: this cast is indicative of abstraction problem
LiterateEnvironmentProject project = (LiterateEnvironmentProject) getProject();
return wsl.allocate(n.getWorkspaceFor(project.getParent().getParent())
.child(project.getParent().getBranch().getName() + "-" + project.getEnvironment().getName()));
LiterateEnvironmentProject project = getProject();
FilePath workspace = n.getWorkspaceFor(project.getParent().getParent());
if (workspace == null) {
throw new IOException("offline node " + n);
}
return wsl.allocate(workspace.child(project.getParent().getBranch().getName() + "-" + project.getEnvironment().getName()));
}

}
@@ -238,7 +238,11 @@ public boolean isConfigurable() {
*/
@Override
protected synchronized LiterateEnvironmentBuild newBuild() throws IOException {
List<Action> actions = Executor.currentExecutor().getCurrentWorkUnit().context.actions;
Executor exec = Executor.currentExecutor();
if (exec == null) {
throw new IOException("not on an executor thread");
}
List<Action> actions = exec.getCurrentWorkUnit().context.actions;
LiterateBranchBuild lb = getParent().getLastBuild();
for (Action a : actions) {
if (a instanceof ParentLiterateBranchBuildAction) {
@@ -470,11 +474,12 @@ public boolean scheduleBuild(ParametersAction parameters) {
return scheduleBuild(parameters, new Cause.LegacyCodeCause());
}

/**
* @param parameters Can be null.
*/
public boolean scheduleBuild(ParametersAction parameters, Cause c) {
return Jenkins.getInstance().getQueue()
public boolean scheduleBuild(@CheckForNull ParametersAction parameters, Cause c) {
Jenkins j = Jenkins.getInstance();
if (j == null) {
return false;
}
return j.getQueue()
.schedule(this, getQuietPeriod(), parameters, new CauseAction(c),
new ParentLiterateBranchBuildAction()) != null;
}

0 comments on commit eeeab34

Please sign in to comment.