提交 f7ce7ccb 编写于 作者: K kohsuke

added upstream pseudo trigger to the matrix project.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3825 71c3de6d-444a-0410-be80-ed276b4c234a
上级 c8f5881d
......@@ -3,6 +3,7 @@ package hudson.model;
import hudson.FeedAdapter;
import hudson.FilePath;
import hudson.Launcher;
import hudson.tasks.BuildTrigger;
import hudson.maven.MavenModule;
import hudson.model.Descriptor.FormException;
import hudson.model.Fingerprint.RangeSet;
......@@ -32,6 +33,9 @@ import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Vector;
import java.util.Set;
import java.util.Collections;
import java.util.HashSet;
/**
* Base implementation of {@link Job}s that build software.
......@@ -220,7 +224,54 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
else
return super.getIconColor();
}
@Override
public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
super.doConfigSubmit(req,rsp);
Set<AbstractProject> upstream = Collections.emptySet();
if(req.getParameter("pseudoUpstreamTrigger")!=null) {
upstream = new HashSet<AbstractProject>(Items.fromNameList(req.getParameter("upstreamProjects"),AbstractProject.class));
}
// dependency setting might have been changed by the user, so rebuild.
Hudson.getInstance().rebuildDependencyGraph();
// reflect the submission of the pseudo 'upstream build trriger'.
// this needs to be done after we release the lock on 'this',
// or otherwise we could dead-lock
for (Project p : Hudson.getInstance().getProjects()) {
boolean isUpstream = upstream.contains(p);
synchronized(p) {
List<AbstractProject> newChildProjects = new ArrayList<AbstractProject>(p.getDownstreamProjects());
if(isUpstream) {
if(!newChildProjects.contains(this))
newChildProjects.add(this);
} else {
newChildProjects.remove(this);
}
if(newChildProjects.isEmpty()) {
p.removePublisher(BuildTrigger.DESCRIPTOR);
} else {
BuildTrigger existing = (BuildTrigger)p.getPublisher(BuildTrigger.DESCRIPTOR);
if(existing!=null && existing.hasSame(newChildProjects))
continue; // no need to touch
p.addPublisher(new BuildTrigger(newChildProjects,
existing==null?Result.SUCCESS:existing.getThreshold()));
}
}
}
// notify the queue as the project might be now tied to different node
Hudson.getInstance().getQueue().scheduleMaintenance();
// this is to reflect the upstream build adjustments done above
Hudson.getInstance().rebuildDependencyGraph();
}
/**
* Schedules a build of this project.
*
......
......@@ -14,12 +14,8 @@ import org.kohsuke.stapler.StaplerResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
/**
......@@ -81,14 +77,14 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
/**
* Adds a new {@link BuildStep} to this {@link Project} and saves the configuration.
*/
private void addPublisher(Publisher buildStep) throws IOException {
public void addPublisher(Publisher buildStep) throws IOException {
addToList(buildStep,publishers);
}
/**
* Removes a publisher from this project, if it's active.
*/
private void removePublisher(Descriptor<Publisher> descriptor) throws IOException {
public void removePublisher(Descriptor<Publisher> descriptor) throws IOException {
removeFromList(descriptor, publishers);
}
......@@ -140,53 +136,6 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
updateTransientActions();
}
@Override
public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
super.doConfigSubmit(req,rsp);
Set<AbstractProject> upstream = Collections.emptySet();
if(req.getParameter("pseudoUpstreamTrigger")!=null) {
upstream = new HashSet<AbstractProject>(Items.fromNameList(req.getParameter("upstreamProjects"),AbstractProject.class));
}
// dependency setting might have been changed by the user, so rebuild.
Hudson.getInstance().rebuildDependencyGraph();
// reflect the submission of the pseudo 'upstream build trriger'.
// this needs to be done after we release the lock on 'this',
// or otherwise we could dead-lock
for (Project p : Hudson.getInstance().getProjects()) {
boolean isUpstream = upstream.contains(p);
synchronized(p) {
List<AbstractProject> newChildProjects = new ArrayList<AbstractProject>(p.getDownstreamProjects());
if(isUpstream) {
if(!newChildProjects.contains(this))
newChildProjects.add(this);
} else {
newChildProjects.remove(this);
}
if(newChildProjects.isEmpty()) {
p.removePublisher(BuildTrigger.DESCRIPTOR);
} else {
BuildTrigger existing = (BuildTrigger)p.getPublisher(BuildTrigger.DESCRIPTOR);
if(existing!=null && existing.hasSame(newChildProjects))
continue; // no need to touch
p.addPublisher(new BuildTrigger(newChildProjects,
existing==null?Result.SUCCESS:existing.getThreshold()));
}
}
}
// notify the queue as the project might be now tied to different node
Hudson.getInstance().getQueue().scheduleMaintenance();
// this is to reflect the upstream build adjustments done above
Hudson.getInstance().rebuildDependencyGraph();
}
private void updateTransientActions() {
synchronized(transientActions) {
transientActions.clear();
......
......@@ -9,7 +9,9 @@
</f:advanced>
</f:section>
<p:config-scm/>
<p:config-trigger/>
<p:config-trigger>
<p:config-upstream-pseudo-trigger />
</p:config-trigger>
<f:section title="Configuration Matrix">
<!-- JDK config -->
......
......@@ -5,19 +5,7 @@
<st:include page="configure-common.jelly" />
<p:config-trigger>
<!-- pseudo-trigger to list upstream projects. -->
<j:set var="up" value="${it.upstreamProjects}" />
<f:optionalBlock name="pseudoUpstreamTrigger"
help="/help/project-config/upstream.html"
title="Build after other projects are built"
checked="${!empty(up)}">
<f:entry title="Projects names"
description="Multiple projects can be specified like 'abc, def'">
<input class="setting-input validated" name="upstreamProjects"
checkUrl="'${rootURL}/publisher/BuildTrigger/check?value='+escape(this.value)"
type="text" value="${h.getProjectListString(up)}"/>
</f:entry>
</f:optionalBlock>
<p:config-upstream-pseudo-trigger />
</p:config-trigger>
<p:config-buildWrappers />
......
<!--
Present the pseudo "upstream project trigger". Used inside <p:config-trigger>
"it" is assumed to be a Project object.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<!-- pseudo-trigger to list upstream projects. -->
<j:set var="up" value="${it.upstreamProjects}" />
<f:optionalBlock name="pseudoUpstreamTrigger"
help="/help/project-config/upstream.html"
title="Build after other projects are built"
checked="${!empty(up)}">
<f:entry title="Projects names"
description="Multiple projects can be specified like 'abc, def'">
<input class="setting-input validated" name="upstreamProjects"
checkUrl="'${rootURL}/publisher/BuildTrigger/check?value='+escape(this.value)"
type="text" value="${h.getProjectListString(up)}"/>
</f:entry>
</f:optionalBlock>
</j:jelly>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册