Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 eeeab34
Show file tree
Hide file tree
Showing 25 changed files with 236 additions and 177 deletions.
13 changes: 9 additions & 4 deletions pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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 -->
Expand Down Expand Up @@ -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>
Expand Down
Expand Up @@ -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}.
Expand All @@ -39,7 +39,7 @@ public abstract class BuildEnvironmentMapperDescriptor extends Descriptor<BuildE
*
* @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);
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -85,14 +84,11 @@ public List<ToolInstallation> getToolInstallations(@NonNull BuildEnvironment env
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;
}
}
}
Expand All @@ -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;
}
}
}
Expand Down
Expand Up @@ -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;

Expand All @@ -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.
Expand Down Expand Up @@ -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);
}
}

/**
Expand All @@ -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);
}
}

Expand All @@ -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);
}

}
Expand Down Expand Up @@ -155,14 +159,14 @@ public Set<String> getPaths(String path) throws PathNotFoundException, IOExcepti
}
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}
*/
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()));
}

/**
Expand Down
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Expand Up @@ -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.
*
Expand Down Expand Up @@ -67,13 +67,13 @@ public List<ExecutionEnvironment> environments(@NonNull List<ExecutionEnvironmen
*/
@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;
}
Expand Down
Expand Up @@ -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()),
Expand Down
Expand Up @@ -25,6 +25,7 @@

import hudson.AbortException;
import hudson.EnvVars;
import hudson.ExtensionList;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()));
}

}
Expand Down
Expand Up @@ -238,7 +238,11 @@ protected Class<LiterateEnvironmentBuild> getBuildClass() {
*/
@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) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit eeeab34

Please sign in to comment.