forked from bap2000/jenkins-flexible-publish-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-19146] Make work with BuildTrigger.
- Loading branch information
Showing
6 changed files
with
252 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/main/java/org/jenkins_ci/plugins/flexible_publish/ConditionalDependencyGraphWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2013 IKEDA Yasuyuki | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.jenkins_ci.plugins.flexible_publish; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.jenkins_ci.plugins.run_condition.RunCondition; | ||
|
||
import hudson.model.AbstractProject; | ||
import hudson.model.DependencyGraph; | ||
|
||
/** | ||
* Wraps {@link DependencyGraph} and append {@link RunCondition} to {@link Dependency}. | ||
* | ||
* Methods other than addDependency are just calling methods of wrapped {@link DependencyGraph} | ||
*/ | ||
public class ConditionalDependencyGraphWrapper extends DependencyGraph | ||
{ | ||
private DependencyGraph graph; | ||
private RunCondition condition; | ||
|
||
public ConditionalDependencyGraphWrapper(DependencyGraph graph, RunCondition condition) { | ||
this.graph = graph; | ||
this.condition = condition; | ||
} | ||
|
||
/** | ||
* Add dependency. {@link RunCondition} will be attached. | ||
* | ||
* @see hudson.model.DependencyGraph#addDependency(hudson.model.DependencyGraph.Dependency) | ||
*/ | ||
@Override | ||
public void addDependency(Dependency dep) { | ||
graph.addDependency(new ConditionalDependencyWrapper(dep, condition)); | ||
} | ||
|
||
@Override | ||
public void build() { | ||
graph.build(); | ||
} | ||
|
||
@Override | ||
public int compare(AbstractProject o1, AbstractProject o2) { | ||
return graph.compare(o1, o2); | ||
} | ||
|
||
@Override | ||
public <T> T getComputationalData(Class<T> key) { | ||
return graph.getComputationalData(key); | ||
} | ||
|
||
@Override | ||
public List<AbstractProject> getDownstream(AbstractProject p) { | ||
return graph.getDownstream(p); | ||
} | ||
|
||
@Override | ||
public List<Dependency> getDownstreamDependencies(AbstractProject p) { | ||
return graph.getDownstreamDependencies(p); | ||
} | ||
|
||
@Override | ||
public Set<AbstractProject> getTransitiveDownstream(AbstractProject src) { | ||
return graph.getTransitiveDownstream(src); | ||
} | ||
|
||
@Override | ||
public Set<AbstractProject> getTransitiveUpstream(AbstractProject src) { | ||
return graph.getTransitiveUpstream(src); | ||
} | ||
|
||
@Override | ||
public List<AbstractProject> getUpstream(AbstractProject p) { | ||
return graph.getUpstream(p); | ||
} | ||
|
||
@Override | ||
public List<Dependency> getUpstreamDependencies(AbstractProject p) { | ||
return graph.getUpstreamDependencies(p); | ||
} | ||
|
||
@Override | ||
public boolean hasIndirectDependencies(AbstractProject src, AbstractProject dst) { | ||
return graph.hasIndirectDependencies(src, dst); | ||
} | ||
|
||
@Override | ||
public <T> void putComputationalData(Class<T> key, T value) { | ||
graph.putComputationalData(key, value); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
src/main/java/org/jenkins_ci/plugins/flexible_publish/ConditionalDependencyWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2013 IKEDA Yasuyuki | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.jenkins_ci.plugins.flexible_publish; | ||
|
||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import org.jenkins_ci.plugins.run_condition.RunCondition; | ||
|
||
import hudson.model.DependencyGraph.Dependency; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Action; | ||
import hudson.model.BuildListener; | ||
import hudson.model.StreamBuildListener; | ||
import hudson.model.TaskListener; | ||
import hudson.util.NullStream; | ||
|
||
/** | ||
* Wraps {@link Dependency} and evaluates {@link RunCondition} when the dependency is triggered. | ||
*/ | ||
public class ConditionalDependencyWrapper extends Dependency { | ||
private static Logger LOGGER = Logger.getLogger(ConditionalDependencyWrapper.class.getName()); | ||
private Dependency dep; | ||
private RunCondition condition; | ||
|
||
public ConditionalDependencyWrapper(Dependency dep, RunCondition condition) { | ||
super(dep.getUpstreamProject(), dep.getDownstreamProject()); | ||
this.dep = dep; | ||
this.condition = condition; | ||
} | ||
|
||
/** | ||
* Determines whether the downstream project should be launched. | ||
* | ||
* {@link RunCondition} is evaluated. | ||
* | ||
* @see hudson.model.DependencyGraph.Dependency#shouldTriggerBuild(hudson.model.AbstractBuild, hudson.model.TaskListener, java.util.List) | ||
*/ | ||
@Override | ||
public boolean shouldTriggerBuild(AbstractBuild build, | ||
TaskListener listener, List<Action> actions) { | ||
BuildListener buildListener = null; | ||
if (listener instanceof BuildListener) { | ||
buildListener = (BuildListener)listener; | ||
} else { | ||
// Usually listener is instance of BuildListener, | ||
// So there may be no case entering this path. | ||
// If there's that case, BuildLister wrapping TaskListener should be written. | ||
LOGGER.warning("There is no BuildListener, and logs from RunCondition won't be recorded."); | ||
buildListener = new StreamBuildListener(new NullStream()); | ||
} | ||
|
||
try { | ||
if (condition.runPerform(build, buildListener)) { | ||
return dep.shouldTriggerBuild(build, listener, actions); | ||
} else { | ||
return false; | ||
} | ||
} catch (Exception e) { | ||
LOGGER.log(Level.SEVERE, "Failed to evaluate condition", e); | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
|
||
ConditionalDependencyWrapper d = (ConditionalDependencyWrapper)obj; | ||
|
||
return dep.equals(d.dep) && condition.equals(d.condition); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return dep.hashCode() * 23 + condition.hashCode(); | ||
} | ||
|
||
@Override | ||
public AbstractProject getDownstreamProject() { | ||
return dep.getDownstreamProject(); | ||
} | ||
|
||
@Override | ||
public AbstractProject getUpstreamProject() { | ||
return dep.getUpstreamProject(); | ||
} | ||
|
||
@Override | ||
public boolean pointsItself() { | ||
return dep.pointsItself(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters