diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 319b9e6abd..b017964202 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -57,27 +57,25 @@ import java.util.logging.Logger; /** * Base implementation of {@link Job}s that build software. - * - * For now this is primarily the common part of {@link Project} and - * {@link MavenModule}. - * + * + * For now this is primarily the common part of {@link Project} and {@link MavenModule}. + * * @author Kohsuke Kawaguchi * @see AbstractBuild */ -public abstract class AbstractProject
, R extends AbstractBuild
> - extends Job
implements BuildableItem { +public abstract class AbstractProject
,R extends AbstractBuild
> extends Job
implements BuildableItem {
/**
- * {@link SCM} associated with the project. To allow derived classes to link
- * {@link SCM} config to elsewhere, access to this variable should always go
- * through {@link #getScm()}.
+ * {@link SCM} associated with the project.
+ * To allow derived classes to link {@link SCM} config to elsewhere,
+ * access to this variable should always go through {@link #getScm()}.
*/
private volatile SCM scm = new NullSCM();
/**
* All the builds keyed by their build number.
*/
- protected transient/* almost final */RunMap , R extends
private volatile Integer quietPeriod = null;
/**
- * If this project is configured to be only built on a certain label, this
- * value will be set to that label.
- *
- * For historical reasons, this is called 'assignedNode'. Also for a
- * historical reason, null to indicate the affinity with the master node.
- *
+ * If this project is configured to be only built on a certain label,
+ * this value will be set to that label.
+ *
+ * For historical reasons, this is called 'assignedNode'. Also for
+ * a historical reason, null to indicate the affinity
+ * with the master node.
+ *
* @see #canRoam
*/
private String assignedNode;
/**
* True if this project can be built on any node.
- *
+ *
*
- * This somewhat ugly flag combination is so that we can migrate existing
- * Hudson installations nicely.
+ * This somewhat ugly flag combination is so that we can migrate
+ * existing Hudson installations nicely.
*/
private volatile boolean canRoam;
@@ -110,13 +109,13 @@ public abstract class AbstractProject , R extends
protected volatile boolean disabled;
/**
- * Identifies {@link JDK} to be used. Null if no explicit configuration is
- * required.
- *
+ * Identifies {@link JDK} to be used.
+ * Null if no explicit configuration is required.
+ *
*
- * Can't store {@link JDK} directly because {@link Hudson} and
- * {@link Project} are saved independently.
- *
+ * Can't store {@link JDK} directly because {@link Hudson} and {@link Project}
+ * are saved independently.
+ *
* @see Hudson#getJDK(String)
*/
private volatile String jdk;
@@ -135,46 +134,42 @@ public abstract class AbstractProject , R extends
/**
* {@link Action}s contributed from subsidiary objects associated with
- * {@link AbstractProject}, such as from triggers, builders, publishers,
- * etc.
- *
- * We don't want to persist them separately, and these actions come and go
- * as configuration change, so it's kept separate.
+ * {@link AbstractProject}, such as from triggers, builders, publishers, etc.
+ *
+ * We don't want to persist them separately, and these actions
+ * come and go as configuration change, so it's kept separate.
*/
- protected transient/* final */List , R extends
// prevent a new build while a delete operation is in progress
makeDisabled(true);
FilePath ws = getWorkspace();
- if (ws != null)
- getScm().processWorkspaceBeforeDeletion(this, ws, getLastBuiltOn());
+ if(ws!=null)
+ getScm().processWorkspaceBeforeDeletion(this, ws,getLastBuiltOn());
super.performDelete();
}
/**
- * If this project is configured to be always built on this node, return
- * that {@link Node}. Otherwise null.
+ * If this project is configured to be always built on this node,
+ * return that {@link Node}. Otherwise null.
*/
public Label getAssignedLabel() {
- if (canRoam)
+ if(canRoam)
return null;
- if (assignedNode == null)
+ if(assignedNode==null)
return Hudson.getInstance().getSelfLabel();
return Hudson.getInstance().getLabel(assignedNode);
}
/**
- * Get the term used in the UI to represent this kind of
- * {@link AbstractProject}. Must start with a capital letter.
+ * Get the term used in the UI to represent this kind of {@link AbstractProject}.
+ * Must start with a capital letter.
*/
@Override
public String getPronoun() {
@@ -211,21 +206,21 @@ public abstract class AbstractProject , R extends
/**
* Gets the directory where the module is checked out.
- *
- * @return null if the workspace is on a slave that's not connected.
+ *
+ * @return
+ * null if the workspace is on a slave that's not connected.
*/
public abstract FilePath getWorkspace();
/**
* Returns the root directory of the checked-out module.
*
- * This is usually where pom.xml, build.xml and so on
- * exists.
+ * This is usually where pom.xml, build.xml
+ * and so on exists.
*/
public FilePath getModuleRoot() {
FilePath ws = getWorkspace();
- if (ws == null)
- return null;
+ if(ws==null) return null;
return getScm().getModuleRoot(ws);
}
@@ -234,7 +229,6 @@ public abstract class AbstractProject , R extends
*
* Some SCMs support checking out multiple modules into the same workspace.
* In these cases, the returned array will have a length greater than one.
- *
* @return The roots of all modules checked out from the SCM.
*/
public FilePath[] getModuleRoots() {
@@ -242,13 +236,12 @@ public abstract class AbstractProject , R extends
}
public int getQuietPeriod() {
- return quietPeriod != null ? quietPeriod : Hudson.getInstance()
- .getQuietPeriod();
+ return quietPeriod!=null ? quietPeriod : Hudson.getInstance().getQuietPeriod();
}
// ugly name because of EL
public boolean getHasCustomQuietPeriod() {
- return quietPeriod != null;
+ return quietPeriod!=null;
}
public final boolean isBuildable() {
@@ -256,8 +249,8 @@ public abstract class AbstractProject , R extends
}
/**
- * Used in sidepanel.jelly to decide whether to display the
- * config/delete/build links.
+ * Used in sidepanel.jelly to decide whether to display
+ * the config/delete/build links.
*/
public boolean isConfigurable() {
return true;
@@ -271,41 +264,39 @@ public abstract class AbstractProject , R extends
* Marks the build as disabled.
*/
public void makeDisabled(boolean b) throws IOException {
- if (disabled == b)
- return; // noop
+ if(disabled==b) return; // noop
this.disabled = b;
save();
}
@Override
public BallColor getIconColor() {
- if (isDisabled())
+ if(isDisabled())
return BallColor.DISABLED;
else
return super.getIconColor();
}
protected void updateTransientActions() {
- synchronized (transientActions) {
+ synchronized(transientActions) {
transientActions.clear();
for (JobProperty super P> p : properties) {
- Action a = p.getJobAction((P) this);
- if (a != null)
+ Action a = p.getJobAction((P)this);
+ if(a!=null)
transientActions.add(a);
}
}
}
/**
- * Returns the live list of all {@link Publisher}s configured for this
- * project.
- *
+ * Returns the live list of all {@link Publisher}s configured for this project.
+ *
*
- * This method couldn't be called getPublishers() because existing
- * methods in sub-classes return different inconsistent types.
+ * This method couldn't be called getPublishers() because existing methods
+ * in sub-classes return different inconsistent types.
*/
- public abstract DescribableList , R extends
List , R extends
// this needs to be done after we release the lock on 'this',
// or otherwise we could dead-lock
- for (AbstractProject, ?> p : Hudson.getInstance().getAllItems(
- AbstractProject.class)) {
+ for (AbstractProject,?> p : Hudson.getInstance().getAllItems(AbstractProject.class)) {
boolean isUpstream = upstream.contains(p);
- synchronized (p) {
- // does 'p' include us in its BuildTrigger?
- DescribableList , R extends
/**
* Schedules a build of this project.
- *
- * @return true if the project is actually added to the queue. false if the
- * queue contained it and therefore the add() was noop
+ *
+ * @return
+ * true if the project is actually added to the queue.
+ * false if the queue contained it and therefore the add()
+ * was noop
*/
public boolean scheduleBuild() {
return scheduleBuild(getQuietPeriod());
}
public boolean scheduleBuild(int quietPeriod) {
- if (isDisabled())
- return false;
-
- AbstractBuild, ?> lastBuild = getLastBuild();
-
- ParametersAction paramsAction = lastBuild == null ? null : lastBuild
- .getAction(ParametersAction.class);
- if (paramsAction == null)
- return Hudson.getInstance().getQueue().add(this, quietPeriod);
- else
- return Hudson.getInstance().getQueue().add(
- new ParameterizedProjectTask(this, paramsAction
- .getParameters()), quietPeriod);
+ if(isDisabled()) return false;
+ return Hudson.getInstance().getQueue().add(this,quietPeriod);
}
/**
- * Schedules a build of this project, and returns a {@link Future} object to
- * wait for the completion of the build.
+ * Schedules a build of this project, and returns a {@link Future} object
+ * to wait for the completion of the build.
*/
public Future , R extends
* Schedules a polling of this project.
*/
public boolean schedulePolling() {
- if (isDisabled())
- return false;
+ if(isDisabled()) return false;
SCMTrigger scmt = getTrigger(SCMTrigger.class);
- if (scmt == null)
- return false;
+ if(scmt==null) return false;
scmt.run();
return true;
}
@@ -471,7 +437,7 @@ public abstract class AbstractProject , R extends
*/
public boolean isBuilding() {
R b = getLastBuild();
- return b != null && b.isBuilding();
+ return b!=null && b.isBuilding();
}
/**
@@ -511,8 +477,7 @@ public abstract class AbstractProject , R extends
*/
protected R newBuild() throws IOException {
try {
- R lastBuild = getBuildClass().getConstructor(getClass())
- .newInstance(this);
+ R lastBuild = getBuildClass().getConstructor(getClass()).newInstance(this);
builds.put(lastBuild);
return lastBuild;
} catch (InstantiationException e) {
@@ -526,15 +491,11 @@ public abstract class AbstractProject , R extends
}
}
- private IOException handleInvocationTargetException(
- InvocationTargetException e) {
+ private IOException handleInvocationTargetException(InvocationTargetException e) {
Throwable t = e.getTargetException();
- if (t instanceof Error)
- throw (Error) t;
- if (t instanceof RuntimeException)
- throw (RuntimeException) t;
- if (t instanceof IOException)
- return (IOException) t;
+ if(t instanceof Error) throw (Error)t;
+ if(t instanceof RuntimeException) throw (RuntimeException)t;
+ if(t instanceof IOException) return (IOException)t;
throw new Error(t);
}
@@ -543,8 +504,7 @@ public abstract class AbstractProject , R extends
*/
protected R loadBuild(File dir) throws IOException {
try {
- return getBuildClass().getConstructor(getClass(), File.class)
- .newInstance(this, dir);
+ return getBuildClass().getConstructor(getClass(),File.class).newInstance(this,dir);
} catch (InstantiationException e) {
throw new Error(e);
} catch (IllegalAccessException e) {
@@ -558,31 +518,31 @@ public abstract class AbstractProject , R extends
/**
* {@inheritDoc}
- *
+ *
*
* Note that this method returns a read-only view of {@link Action}s.
- * {@link BuildStep}s and others who want to add a project action should do
- * so by implementing {@link BuildStep#getProjectAction(AbstractProject)}.
+ * {@link BuildStep}s and others who want to add a project action
+ * should do so by implementing {@link BuildStep#getProjectAction(AbstractProject)}.
*/
public synchronized List , R extends
/**
* {@inheritDoc}
- *
+ *
*
- * A project must be blocked if its own previous build is in progress, but
- * derived classes can also check other conditions.
+ * A project must be blocked if its own previous build is in progress,
+ * but derived classes can also check other conditions.
*/
public boolean isBuildBlocked() {
return isBuilding();
@@ -602,21 +562,19 @@ public abstract class AbstractProject , R extends
public String getWhyBlocked() {
AbstractBuild, ?> build = getLastBuild();
Executor e = build.getExecutor();
- String eta = "";
- if (e != null)
+ String eta="";
+ if(e!=null)
eta = Messages.AbstractProject_ETA(e.getEstimatedRemainingTime());
int lbn = build.getNumber();
- return Messages.AbstractProject_BuildInProgress(lbn, eta);
+ return Messages.AbstractProject_BuildInProgress(lbn,eta);
}
public final long getEstimatedDuration() {
AbstractBuild b = getLastSuccessfulBuild();
- if (b == null)
- return -1;
+ if(b==null) return -1;
long duration = b.getDuration();
- if (duration == 0)
- return -1;
+ if(duration==0) return -1;
return duration;
}
@@ -637,7 +595,7 @@ public abstract class AbstractProject , R extends
* Gets the {@link Resource} that represents the workspace of this project.
*/
public Resource getWorkspaceResource() {
- return new Resource(getFullDisplayName() + " workspace");
+ return new Resource(getFullDisplayName()+" workspace");
}
/**
@@ -645,8 +603,7 @@ public abstract class AbstractProject , R extends
*/
public ResourceList getResourceList() {
final Set , R extends
}
/**
- * Set of child resource activities of the build of this project (override
- * in child projects).
- *
- * @return The set of child resource activities of the build of this
- * project.
+ * Set of child resource activities of the build of this project (override in child projects).
+ * @return The set of child resource activities of the build of this project.
*/
protected Set
- * The caller is responsible for coordinating the mutual exclusion between a
- * build and polling, as both touches the workspace.
+ * The caller is responsible for coordinating the mutual exclusion between
+ * a build and polling, as both touches the workspace.
*/
- public boolean pollSCMChanges(TaskListener listener) {
+ public boolean pollSCMChanges( TaskListener listener ) {
SCM scm = getScm();
- if (scm == null) {
+ if(scm==null) {
listener.getLogger().println(Messages.AbstractProject_NoSCM());
return false;
}
- if (isDisabled()) {
+ if(isDisabled()) {
listener.getLogger().println(Messages.AbstractProject_Disabled());
return false;
}
try {
FilePath workspace = getWorkspace();
- if (scm.requiresWorkspaceForPolling()
- && (workspace == null || !workspace.exists())) {
+ if (scm.requiresWorkspaceForPolling() && (workspace == null || !workspace.exists())) {
// workspace offline. build now, or nothing will ever be built
Label label = getAssignedLabel();
if (label != null && label.isSelfLabel()) {
- // if the build is fixed on a node, then attempting a build
- // will do us
+ // if the build is fixed on a node, then attempting a build will do us
// no good. We should just wait for the slave to come back.
- listener.getLogger().println(
- Messages.AbstractProject_NoWorkspace());
+ listener.getLogger().println(Messages.AbstractProject_NoWorkspace());
return false;
}
if (workspace == null)
- listener.getLogger().println(
- Messages.AbstractProject_WorkspaceOffline());
+ listener.getLogger().println(Messages.AbstractProject_WorkspaceOffline());
else
- listener.getLogger().println(
- Messages.AbstractProject_NoWorkspace());
- listener.getLogger().println(
- Messages.AbstractProject_NewBuildForWorkspace());
+ listener.getLogger().println(Messages.AbstractProject_NoWorkspace());
+ listener.getLogger().println(Messages.AbstractProject_NewBuildForWorkspace());
return true;
}
- Launcher launcher = workspace != null ? workspace
- .createLauncher(listener) : null;
+ Launcher launcher = workspace != null ? workspace.createLauncher(listener) : null;
LOGGER.fine("Polling SCM changes of " + getName());
return scm.pollChanges(this, launcher, workspace, listener);
} catch (AbortException e) {
@@ -741,21 +686,19 @@ public abstract class AbstractProject , R extends
e.printStackTrace(listener.fatalError(e.getMessage()));
return false;
} catch (InterruptedException e) {
- e.printStackTrace(listener.fatalError(Messages
- .AbstractProject_PollingABorted()));
+ e.printStackTrace(listener.fatalError(Messages.AbstractProject_PollingABorted()));
return false;
}
}
/**
* Returns true if this user has made a commit to this project.
- *
+ *
* @since 1.191
*/
public boolean hasParticipant(User user) {
- for (R build = getLastBuild(); build != null; build = build
- .getPreviousBuild())
- if (build.hasParticipant(user))
+ for( R build = getLastBuild(); build!=null; build=build.getPreviousBuild())
+ if(build.hasParticipant(user))
return true;
return false;
}
@@ -772,19 +715,19 @@ public abstract class AbstractProject , R extends
* Adds a new {@link Trigger} to this {@link Project} if not active yet.
*/
public void addTrigger(Trigger> trigger) throws IOException {
- addToList(trigger, triggers);
+ addToList(trigger,triggers);
}
public void removeTrigger(TriggerDescriptor trigger) throws IOException {
- removeFromList(trigger, triggers);
+ removeFromList(trigger,triggers);
}
- protected final synchronized , R extends
}
}
- public synchronized Map , R extends
}
/**
- * Returns only those upstream projects that defines {@link BuildTrigger} to
- * this project. This is a subset of {@link #getUpstreamProjects()}
- *
- * @return A List of upstream projects that has a {@link BuildTrigger} to
- * this project.
+ * Returns only those upstream projects that defines {@link BuildTrigger} to this project.
+ * This is a subset of {@link #getUpstreamProjects()}
+ *
+ * @return A List of upstream projects that has a {@link BuildTrigger} to this project.
*/
public final List , R extends
/**
* Helper method for getDownstreamRelationship.
- *
- * For each given build, find the build number range of the given project
- * and put that into the map.
+ *
+ * For each given build, find the build number range of the given project and put that into the map.
*/
- private void checkAndRecord(AbstractProject that,
- TreeMap , R extends
/**
* Builds the dependency graph.
- *
* @see DependencyGraph
*/
protected abstract void buildDependencyGraph(DependencyGraph graph);
protected SearchIndexBuilder makeSearchIndex() {
SearchIndexBuilder sib = super.makeSearchIndex();
- if (isBuildable() && Hudson.isAdmin())
- sib.add("build", "build");
+ if(isBuildable() && Hudson.isAdmin())
+ sib.add("build","build");
return sib;
}
@Override
protected HistoryWidget createHistoryWidget() {
- return new BuildHistoryWidget , R extends
/**
* Schedules a new SCM polling command.
*/
- public void doPolling(StaplerRequest req, StaplerResponse rsp)
- throws IOException, ServletException {
+ public void doPolling( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
BuildAuthorizationToken.checkPermission(this, authToken, req, rsp);
schedulePolling();
rsp.forwardToPreviousPage(req);
@@ -1008,8 +936,7 @@ public abstract class AbstractProject , R extends
/**
* Cancels a scheduled build.
*/
- public void doCancelQueue(StaplerRequest req, StaplerResponse rsp)
- throws IOException, ServletException {
+ public void doCancelQueue( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
checkPermission(BUILD);
Hudson.getInstance().getQueue().cancel(this);
@@ -1017,25 +944,24 @@ public abstract class AbstractProject , R extends
}
@Override
- protected void submit(StaplerRequest req, StaplerResponse rsp)
- throws IOException, ServletException, FormException {
- super.submit(req, rsp);
+ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
+ super.submit(req,rsp);
- disabled = req.getParameter("disable") != null;
+ disabled = req.getParameter("disable")!=null;
jdk = req.getParameter("jdk");
- if (req.getParameter("hasCustomQuietPeriod") != null) {
+ if(req.getParameter("hasCustomQuietPeriod")!=null) {
quietPeriod = Integer.parseInt(req.getParameter("quiet_period"));
} else {
quietPeriod = null;
}
- if (req.getParameter("hasSlaveAffinity") != null) {
+ if(req.getParameter("hasSlaveAffinity")!=null) {
canRoam = false;
assignedNode = req.getParameter("slave");
- if (assignedNode != null) {
- if (Hudson.getInstance().getLabel(assignedNode).isEmpty())
- assignedNode = null; // no such label
+ if(assignedNode !=null) {
+ if(Hudson.getInstance().getLabel(assignedNode).isEmpty())
+ assignedNode = null; // no such label
}
} else {
canRoam = true;
@@ -1048,25 +974,22 @@ public abstract class AbstractProject , R extends
for (Trigger t : triggers)
t.stop();
- triggers = buildDescribable(req, Triggers.getApplicableTriggers(this),
- "trigger");
+ triggers = buildDescribable(req, Triggers.getApplicableTriggers(this), "trigger");
for (Trigger t : triggers)
- t.start(this, true);
+ t.start(this,true);
updateTransientActions();
}
- protected final , R extends
/**
* Serves the workspace files.
*/
- public void doWs(StaplerRequest req, StaplerResponse rsp)
- throws IOException, ServletException, InterruptedException {
+ public void doWs( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, InterruptedException {
checkPermission(AbstractProject.WORKSPACE);
FilePath ws = getWorkspace();
if ((ws == null) || (!ws.exists())) {
// if there's no workspace, report a nice error message
- req.getView(this, "noWorkspace.jelly").forward(req, rsp);
+ req.getView(this,"noWorkspace.jelly").forward(req,rsp);
} else {
- new DirectoryBrowserSupport(this, getDisplayName() + " workspace")
- .serveFile(req, rsp, ws, "folder.gif", true);
+ new DirectoryBrowserSupport(this,getDisplayName()+" workspace").serveFile(req, rsp, ws, "folder.gif", true);
}
}
/**
* Wipes out the workspace.
*/
- public void doDoWipeOutWorkspace(StaplerResponse rsp) throws IOException,
- InterruptedException {
+ public void doDoWipeOutWorkspace(StaplerResponse rsp) throws IOException, InterruptedException {
checkPermission(AbstractProject.BUILD);
getWorkspace().deleteRecursive();
rsp.sendRedirect2(".");
@@ -1102,8 +1022,7 @@ public abstract class AbstractProject , R extends
/**
* RSS feed for changes in this project.
*/
- public void doRssChangelog(StaplerRequest req, StaplerResponse rsp)
- throws IOException, ServletException {
+ public void doRssChangelog( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
class FeedItem {
ChangeLogSet.Entry e;
int idx;
@@ -1113,73 +1032,70 @@ public abstract class AbstractProject , R extends
this.idx = idx;
}
- AbstractBuild, ?> getBuild() {
+ AbstractBuild,?> getBuild() {
return e.getParent().build;
}
}
List