aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-24 08:43:43 (EST)
committerWinston Prakash2011-12-01 20:47:26 (EST)
commitcd71b16352e845e62873a075fea145e13c667f3e (patch)
treec32da27e2b9a88db8cca8076769135ec5620cbc2
parent77bb9f3ff736edca879f76f4de3567b6ab7fcfc8 (diff)
downloadorg.eclipse.hudson.core-cd71b16352e845e62873a075fea145e13c667f3e.zip
org.eclipse.hudson.core-cd71b16352e845e62873a075fea145e13c667f3e.tar.gz
org.eclipse.hudson.core-cd71b16352e845e62873a075fea145e13c667f3e.tar.bz2
Improve cascadingDescriptorList tag. Improve TriggerProjectProperty
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/util/CascadingUtil.java73
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/TriggerProjectProperty.java5
-rw-r--r--hudson-core/src/main/resources/hudson/triggers/SCMTrigger/config.jelly4
-rw-r--r--hudson-core/src/main/resources/hudson/triggers/TimerTrigger/config.jelly4
-rw-r--r--hudson-core/src/main/resources/lib/hudson/cascadingDescriptorList.jelly61
-rw-r--r--hudson-core/src/main/resources/lib/hudson/project/config-trigger.jelly3
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java1
7 files changed, 82 insertions, 69 deletions
diff --git a/hudson-core/src/main/java/hudson/util/CascadingUtil.java b/hudson-core/src/main/java/hudson/util/CascadingUtil.java
index f0c2947..467988d 100644
--- a/hudson-core/src/main/java/hudson/util/CascadingUtil.java
+++ b/hudson-core/src/main/java/hudson/util/CascadingUtil.java
@@ -401,39 +401,40 @@ public class CascadingUtil {
}
/**
- * Sets trigger for job and all its children if necessary.
- *
- * @param job parentJob
- * @param descriptor trigger descriptor
- * @param key trigger property key
- * @param req stapler request
- * @param json submited json
- * @throws hudson.model.Descriptor.FormException if incorrect parameters
- */
- @SuppressWarnings("unchecked")
- public static void setChildrenTrigger(Job job, TriggerDescriptor descriptor, String key, StaplerRequest req,
- JSONObject json) throws Descriptor.FormException {
- TriggerProjectProperty<Trigger<?>> property = CascadingUtil.getTriggerProjectProperty(job, key);
- if (property.getValue() != null) {
- property.getValue().stop();
- }
- Trigger trigger = null;
- if (json.has(key)) {
- trigger = descriptor.newInstance(req, json.getJSONObject(key));
- trigger.start(job, true);
- }
- property.setValue(trigger);
- Set<String> cascadingChildrenNames = job.getCascadingChildrenNames();
- for (String childName : cascadingChildrenNames) {
- Job childJob = (Job)Hudson.getInstance().getItem(childName);
- if (StringUtils.equals(job.getName(), childJob.getCascadingProjectName())) {
- TriggerProjectProperty childProperty = CascadingUtil.getTriggerProjectProperty(childJob, key);
- if (!childProperty.isOverridden()) {
- setChildrenTrigger(childJob, descriptor, key, req, json);
- } else if (!childProperty.allowOverrideValue(trigger, childProperty.getValue())) {
- childProperty.setOverridden(false);
- }
- }
- }
- }
- }
+ * Sets trigger for job and all its children if necessary.
+ *
+ * @param job parentJob
+ * @param descriptor trigger descriptor
+ * @param key trigger property key
+ * @param req stapler request
+ * @param json submited json
+ * @throws hudson.model.Descriptor.FormException
+ * if incorrect parameters
+ */
+ @SuppressWarnings("unchecked")
+ public static void setChildrenTrigger(Job job, TriggerDescriptor descriptor, String key, StaplerRequest req,
+ JSONObject json) throws Descriptor.FormException {
+ TriggerProjectProperty property = CascadingUtil.getTriggerProjectProperty(job, key);
+ if (property.getValue() != null) {
+ property.getValue().stop();
+ }
+ Trigger trigger = null;
+ if (json.has(key)) {
+ trigger = descriptor.newInstance(req, json.getJSONObject(key));
+ trigger.start(job, true);
+ }
+ property.setValue(trigger);
+ Set<String> cascadingChildrenNames = job.getCascadingChildrenNames();
+ for (String childName : cascadingChildrenNames) {
+ Job childJob = (Job) Hudson.getInstance().getItem(childName);
+ if (StringUtils.equals(job.getName(), childJob.getCascadingProjectName())) {
+ TriggerProjectProperty childProperty = CascadingUtil.getTriggerProjectProperty(childJob, key);
+ if (!childProperty.isOverridden()) {
+ setChildrenTrigger(childJob, descriptor, key, req, json);
+ } else if (!childProperty.allowOverrideValue(trigger, childProperty.getValue())) {
+ childProperty.setOverridden(false);
+ }
+ }
+ }
+ }
+}
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/TriggerProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/TriggerProjectProperty.java
index 8fab530..84e4eb5 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/TriggerProjectProperty.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/TriggerProjectProperty.java
@@ -15,13 +15,14 @@
package org.eclipse.hudson.api.model.project.property;
+import hudson.triggers.Trigger;
import org.eclipse.hudson.api.model.IJob;
/**
* Property for triggers in case of we should use child project trigger
* instead of parent project if they are equals.
*/
-public class TriggerProjectProperty<T> extends ExternalProjectProperty<T> {
+public class TriggerProjectProperty extends BaseProjectProperty<Trigger> {
public TriggerProjectProperty(IJob job) {
super(job);
}
@@ -30,7 +31,7 @@ public class TriggerProjectProperty<T> extends ExternalProjectProperty<T> {
* {@inheritDoc}
*/
@Override
- protected void clearOriginalValue(T originalValue) {
+ protected void clearOriginalValue(Trigger originalValue) {
setOriginalValue(originalValue, false);
}
}
diff --git a/hudson-core/src/main/resources/hudson/triggers/SCMTrigger/config.jelly b/hudson-core/src/main/resources/hudson/triggers/SCMTrigger/config.jelly
index 21e2505..90e1210 100644
--- a/hudson-core/src/main/resources/hudson/triggers/SCMTrigger/config.jelly
+++ b/hudson-core/src/main/resources/hudson/triggers/SCMTrigger/config.jelly
@@ -9,14 +9,14 @@
#
# Contributors:
#
-# Kohsuke Kawaguchi, Anton Kozak
+# Kohsuke Kawaguchi, Anton Kozak, Nikita Levyankov
#
#
#************************************************************************** -->
<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">
- <j:set var="instanceProperty" value="${cu.getExternalProjectProperty(it, descriptor.jsonSafeClassName)}"/>
+ <j:set var="instanceProperty" value="${cu.getBaseProjectProperty(it, descriptor.jsonSafeClassName)}"/>
<j:set var="instance" value="${instanceProperty.getValue()}"/>
<f:entry title="${%Schedule}" help="/descriptor/hudson.triggers.TimerTrigger/help/spec" isPropertyOverridden="${instanceProperty.isOverridden()}">
diff --git a/hudson-core/src/main/resources/hudson/triggers/TimerTrigger/config.jelly b/hudson-core/src/main/resources/hudson/triggers/TimerTrigger/config.jelly
index bf18886..515e762 100644
--- a/hudson-core/src/main/resources/hudson/triggers/TimerTrigger/config.jelly
+++ b/hudson-core/src/main/resources/hudson/triggers/TimerTrigger/config.jelly
@@ -9,14 +9,14 @@
#
# Contributors:
#
-# Kohsuke Kawaguchi, InfraDNA, Inc., Anton Kozak
+# Kohsuke Kawaguchi, InfraDNA, Inc., Anton Kozak, Nikita Levyankov
#
#
#************************************************************************** -->
<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">
- <j:set var="instanceProperty" value="${cu.getExternalProjectProperty(it, descriptor.jsonSafeClassName)}"/>
+ <j:set var="instanceProperty" value="${cu.getBaseProjectProperty(it, descriptor.jsonSafeClassName)}"/>
<j:set var="instance" value="${instanceProperty.getValue()}"/>
<f:entry title="${%Schedule}" field="spec" isPropertyOverridden="${instanceProperty.isOverridden()}">
<f:textarea />
diff --git a/hudson-core/src/main/resources/lib/hudson/cascadingDescriptorList.jelly b/hudson-core/src/main/resources/lib/hudson/cascadingDescriptorList.jelly
index b15b845..3fce557 100644
--- a/hudson-core/src/main/resources/lib/hudson/cascadingDescriptorList.jelly
+++ b/hudson-core/src/main/resources/lib/hudson/cascadingDescriptorList.jelly
@@ -14,30 +14,41 @@
#
#************************************************************************** -->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:f="/lib/form">
- <st:documentation>
- Generates config pages from a list of Descriptors into a section. Tag is based on cascading functionality.
- <st:attribute name="title">
- Human readable title of the section to be rendered in HTML.
- </st:attribute>
- <st:attribute name="descriptors" use="required">
- hudson.model.Descriptor collection whose configuration page is rendered.
- </st:attribute>
- </st:documentation>
+ <st:documentation>
+ Generates config pages from a list of Descriptors into a section. Tag is based on cascading functionality.
+ <st:attribute name="title">
+ Human readable title of the section to be rendered in HTML.
+ </st:attribute>
+ <st:attribute name="descriptors" use="required">
+ hudson.model.Descriptor collection whose configuration page is rendered.
+ </st:attribute>
+ <st:attribute name="projectPropertyClass">
+ ProjectProperty class that will be used for creating project property instance
+ based on hudson.util.CascadingUtil.getProjectProperty method. Default value is
+ org.hudsonci.model.project.property.ExternalProjectProperty.class.
+ </st:attribute>
+ </st:documentation>
- <j:set var="targetType" value="${it.class}"/>
- <j:if test="${!empty(descriptors) or context['org.apache.commons.jelly.body']!=null}">
- <f:section title="${attrs.title}" name="${attrs.name}">
- <d:invokeBody/>
- <j:forEach var="descriptor" items="${descriptors}">
- <j:set var="instanceProperty" value="${cu.getExternalProjectProperty(it, descriptor.jsonSafeClassName)}"/>
- <j:set var="instance" value="${instanceProperty.getValue()}"/>
- <f:optionalBlock name="${descriptor.jsonSafeClassName}" help="${descriptor.helpFile}"
- title="${descriptor.displayName}" checked="${instance!=null}"
- resetUrl="${jobUrl}/resetProjectProperty?propertyName=${descriptor.jsonSafeClassName}"
- isPropertyOverridden="${instanceProperty.isOverridden()}">
- <st:include from="${descriptor}" page="${descriptor.configPage}" optional="true"/>
- </f:optionalBlock>
- </j:forEach>
- </f:section>
- </j:if>
+ <j:set var="targetType" value="${it.class}"/>
+ <j:if test="${attrs.projectPropertyClass==null}">
+ <j:set var="attrs.projectPropertyClass"
+ value="${org.hudsonci.model.project.property.ExternalProjectProperty.class}"/>
+ </j:if>
+ <j:if test="${!empty(descriptors) or context['org.apache.commons.jelly.body']!=null}">
+ <f:section title="${attrs.title}" name="${attrs.name}">
+ <d:invokeBody/>
+ <j:forEach var="descriptor" items="${descriptors}">
+ <j:set var="instanceProperty"
+ value="${cu.getProjectProperty(it, descriptor.jsonSafeClassName, attrs.projectPropertyClass)}"/>
+ <j:set var="instance" value="${instanceProperty.getValue()}"/>
+ <f:optionalBlock name="${descriptor.jsonSafeClassName}" help="${descriptor.helpFile}"
+ title="${descriptor.displayName}" checked="${instance!=null}"
+ resetUrl="${jobUrl}/resetProjectProperty?propertyName=${descriptor.jsonSafeClassName}"
+ isPropertyOverridden="${instanceProperty.isOverridden()}">
+ <st:include from="${descriptor}" page="${descriptor.configPage}" optional="true"/>
+ </f:optionalBlock>
+ </j:forEach>
+ </f:section>
+ </j:if>
</j:jelly>
+
diff --git a/hudson-core/src/main/resources/lib/hudson/project/config-trigger.jelly b/hudson-core/src/main/resources/lib/hudson/project/config-trigger.jelly
index b85885d..25a9565 100644
--- a/hudson-core/src/main/resources/lib/hudson/project/config-trigger.jelly
+++ b/hudson-core/src/main/resources/lib/hudson/project/config-trigger.jelly
@@ -23,7 +23,8 @@
<j:invokeStatic var="triggers" className="hudson.triggers.Trigger" method="for_">
<j:arg value="${it}" type="hudson.model.Item" />
</j:invokeStatic>
- <t:cascadingDescriptorList title="${%Build Triggers}" descriptors="${triggers}">
+ <t:cascadingDescriptorList title="${%Build Triggers}" descriptors="${triggers}"
+ propertyClass="${org.hudsonci.model.project.property.BaseProjectProperty.class}">
<d:invokeBody />
<!-- pseudo-trigger to configure URL to trigger builds remotely. -->
<st:include page="/hudson/model/BuildAuthorizationToken/config.jelly" />
diff --git a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java
index c37d6f8..c847d16 100644
--- a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java
+++ b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java
@@ -712,7 +712,6 @@ public class ProjectPropertyTest {
TriggerProjectProperty property = new TriggerProjectProperty(project);
Trigger originalTrigger = new TimerTrigger("* * * * *");
Trigger cascadingTrigger = new TimerTrigger("* * * * *");
- property.setModified(true);
property.updateOriginalValue(originalTrigger, cascadingTrigger);
//Property isn't overridden because of values equal.
assertFalse(property.isOverridden());