| author | akozak | 2011-11-24 03:00:56 (EST) |
|---|---|---|
| committer | Winston Prakash | 2011-12-01 20:47:22 (EST) |
| commit | 9cbca09410d45519eed483132085a75c828a91d1 (patch) (side-by-side diff) | |
| tree | a0e6d2d3c90b6e29f4525e637e4e26ecbdc038ce | |
| parent | b2db1d15a757b8f9d1c58ebcc619ec97839d019a (diff) | |
| download | org.eclipse.hudson.core-9cbca09410d45519eed483132085a75c828a91d1.zip org.eclipse.hudson.core-9cbca09410d45519eed483132085a75c828a91d1.tar.gz org.eclipse.hudson.core-9cbca09410d45519eed483132085a75c828a91d1.tar.bz2 | |
Introduce CascadingUtil class. Move cascading logic to utils. Improve FreeStyleProjectMock
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
7 files changed, 403 insertions, 129 deletions
diff --git a/hudson-core/src/main/java/hudson/Functions.java b/hudson-core/src/main/java/hudson/Functions.java index ea17615..fc83914 100644 --- a/hudson-core/src/main/java/hudson/Functions.java +++ b/hudson-core/src/main/java/hudson/Functions.java @@ -59,6 +59,7 @@ import hudson.tasks.BuildWrappers; import hudson.tasks.Builder; import hudson.tasks.Publisher; import hudson.util.Area; +import hudson.util.CascadingUtil; import hudson.util.Iterators; import hudson.scm.SCM; import hudson.scm.SCMDescriptor; @@ -1372,31 +1373,21 @@ public class Functions { return templates.iterator().hasNext() ? templates.iterator().next() : null; } + /** + * @see CascadingUtil#getCascadingParents(Class, hudson.model.Job) + */ + //TODO remove this method after 2.2.0 Beta release. Use direct call to CascadingUtil public static <T extends Item> List<Job> getAllItems(Class<T> type, Job currentJob) { - List<T> allItems = Hudson.getInstance().getAllItems(type); - List<Job> result = new ArrayList<Job>(allItems.size()); - for (T item : allItems) { - Job job = (Job) item; - if (!hasCyclicCascadingLink(job, currentJob.getCascadingChildrenNames())) { - result.add(job); - } - } - return result; + return CascadingUtil.getCascadingParents(type, currentJob); } + + /** + * @see CascadingUtil#hasCyclicCascadingLink(hudson.model.Job, java.util.Set) + */ + //TODO remove this method after 2.2.0 Beta release. Use direct call to CascadingUtil protected static boolean hasCyclicCascadingLink(Job cascadingCandidate, Set<String> cascadingChildren) { - if (null != cascadingCandidate && CollectionUtils.isNotEmpty(cascadingChildren)) { - if (cascadingChildren.contains(cascadingCandidate.getName())) { - return true; - } - for (String childName : cascadingChildren) { - Job job = getItemByName(Hudson.getInstance().getAllItems(Job.class), childName); - if (hasCyclicCascadingLink(cascadingCandidate, job.getCascadingChildrenNames())) { - return true; - } - } - } - return false; + return CascadingUtil.hasCyclicCascadingLink(cascadingCandidate, cascadingChildren); } /** @@ -1405,16 +1396,11 @@ public class Functions { * @param cascadingProject cascading project to start from. * @param projectToUnlink project that should be unlinked. * @return true if project was unlinked, false - if cascadingProject or projectToUnlink is Null + * @see CascadingUtil#unlinkProjectFromCascadingParents(hudson.model.Job, java.lang.String) */ + //TODO remove this method after 2.2.0 Beta release. Use direct call to CascadingUtil public static boolean unlinkProjectFromCascadingParents(Job cascadingProject, String projectToUnlink) { - if (null != cascadingProject && null != projectToUnlink) { - cascadingProject.removeCascadingChild(projectToUnlink); - if (cascadingProject.hasCascadingProject()) { - unlinkProjectFromCascadingParents(cascadingProject.getCascadingProject(), projectToUnlink); - } - return true; - } - return false; + return CascadingUtil.unlinkProjectFromCascadingParents(cascadingProject, projectToUnlink); } /** @@ -1423,14 +1409,11 @@ public class Functions { * * @param cascadingProject cascadingProject. * @param childProjectName the name of child project name. + * @see CascadingUtil#linkCascadingProjectsToChild(hudson.model.Job, java.lang.String) */ - public static void linkCascadingProjectsToChild(Job cascadingProject, String childProjectName){ - if(cascadingProject != null){ - cascadingProject.addCascadingChild(childProjectName); - if(cascadingProject.hasCascadingProject()){ - linkCascadingProjectsToChild(cascadingProject.getCascadingProject(), childProjectName); - } - } + //TODO remove this method after 2.2.0 Beta release. Use direct call to CascadingUtil + public static void linkCascadingProjectsToChild(Job cascadingProject, String childProjectName) { + CascadingUtil.linkCascadingProjectsToChild(cascadingProject, childProjectName); } /** @@ -1441,15 +1424,11 @@ public class Functions { * @param cascadingProject cascading project. * @param oldName old project name. * @param newName new project name. + * @see CascadingUtil#renameCascadingChildLinks(hudson.model.Job, java.lang.String, java.lang.String) */ - @SuppressWarnings("unchecked") - public static void renameCascadingChildLinks(Job cascadingProject, String oldName, String newName){ - if(cascadingProject != null){ - cascadingProject.renameCascadingChildName(oldName, newName); - if(cascadingProject.hasCascadingProject()){ - renameCascadingChildLinks(cascadingProject.getCascadingProject(), oldName, newName); - } - } + //TODO remove this method after 2.2.0 Beta release. Use direct call to CascadingUtil + public static void renameCascadingChildLinks(Job cascadingProject, String oldName, String newName) { + CascadingUtil.renameCascadingChildLinks(cascadingProject, oldName, newName); } /** @@ -1458,19 +1437,10 @@ public class Functions { * * @param oldName old project name. * @param newName new project name. - + * @see CascadingUtil#renameCascadingParentLinks(java.lang.String, java.lang.String) */ - @SuppressWarnings("unchecked") - public static void renameCascadingParentLinks(final String oldName, final String newName){ - if (StringUtils.isBlank(newName)|| StringUtils.isBlank(oldName)) { - return; - } - for (Job job : Hudson.getInstance().getAllItems(Job.class)) { - if(oldName.equals(job.getCascadingProjectName())){ - job.renameCascadingProjectNameTo(newName); - } - - } + //TODO remove this method after 2.2.0 Beta release. Use direct call to CascadingUtil + public static void renameCascadingParentLinks(final String oldName, final String newName) { + CascadingUtil.renameCascadingParentLinks(oldName, newName); } } - diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java index 752fa93..e3f160e 100644 --- a/hudson-core/src/main/java/hudson/model/Job.java +++ b/hudson-core/src/main/java/hudson/model/Job.java @@ -18,7 +18,9 @@ package hudson.model; import hudson.Functions; +import hudson.util.CascadingUtil; import java.util.concurrent.CopyOnWriteArraySet; +import org.apache.commons.collections.MapUtils; import org.eclipse.hudson.api.model.project.property.AxisListProjectProperty; import org.eclipse.hudson.api.model.project.property.BaseProjectProperty; import org.eclipse.hudson.api.model.project.property.BooleanProjectProperty; @@ -177,7 +179,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R /** * The name of the cascadingProject. */ - private String cascadingProjectName; + String cascadingProjectName; /** * The list with the names of children cascading projects. Required to avoid cyclic references and @@ -229,8 +231,14 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R * @param key key. * @param property property instance. */ - protected void putJobProperty(String key, IProjectProperty property) { - jobProperties.put(key, property); + public void putProjectProperty(String key, IProjectProperty property) { + if (null != key && null != property) { + jobProperties.put(key, property); + } + } + + public Map<String, IProjectProperty> getProjectProperties() { + return MapUtils.unmodifiableMap(jobProperties); } /** @@ -253,74 +261,57 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R * Returns job property by specified key. * * @param key key. - * @return {@link org.eclipse.hudson.api.model.IProjectProperty} instance or null. + * @return {@link org.hudsonci.api.model.IProjectProperty} instance or null. */ public IProjectProperty getProperty(String key){ - return getProperty(key, null); + return CascadingUtil.getProjectProperty(this, key); } - //TODO relocate it to functions /** * {@inheritDoc} */ public IProjectProperty getProperty(String key, Class clazz) { - IProjectProperty t = jobProperties.get(key); - if (null == t && null != clazz) { - try { - t = (IProjectProperty) clazz.getConstructor(IJob.class).newInstance(this); - t.setKey(key); - putJobProperty(key, t); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - } - return t; + return CascadingUtil.getProjectProperty(this, key, clazz); } public StringProjectProperty getStringProperty(String key) { - return (StringProjectProperty) getProperty(key, StringProjectProperty.class); + return CascadingUtil.getStringProjectProperty(this, key); } public BaseProjectProperty getBaseProjectProperty(String key) { - return (BaseProjectProperty) getProperty(key, BaseProjectProperty.class); + return CascadingUtil.getBaseProjectProperty(this, key); } public ExternalProjectProperty getExternalProjectProperty(String key) { - return (ExternalProjectProperty) getProperty(key, ExternalProjectProperty.class); + return CascadingUtil.getExternalProjectProperty(this, key); } public ResultProjectProperty getResultProperty(String key) { - return (ResultProjectProperty) getProperty(key, ResultProjectProperty.class); + return CascadingUtil.getResultProjectProperty(this, key); } - public BooleanProjectProperty getBooleanProperty(String key){ - return (BooleanProjectProperty) getProperty(key, BooleanProjectProperty.class); + public BooleanProjectProperty getBooleanProperty(String key) { + return CascadingUtil.getBooleanProjectProperty(this, key); } public IntegerProjectProperty getIntegerProperty(String key) { - return (IntegerProjectProperty) getProperty(key, IntegerProjectProperty.class); + return CascadingUtil.getIntegerProjectProperty(this, key); } public LogRotatorProjectProperty getLogRotatorProjectProperty(String key) { - return (LogRotatorProjectProperty) getProperty(key, LogRotatorProjectProperty.class); + return CascadingUtil.getLogRotatorProjectProperty(this, key); } - public AxisListProjectProperty getAxesListProjectProperty(String key) { - return (AxisListProjectProperty) getProperty(key, AxisListProjectProperty.class); + public DescribableListProjectProperty getDescribableListProjectProperty(String key) { + return CascadingUtil.getDescribableListProjectProperty(this, key); } - public DescribableListProjectProperty getDescribableListProjectProperty(String key) { - return (DescribableListProjectProperty) getProperty(key, DescribableListProjectProperty.class); + public AxisListProjectProperty getAxesListProjectProperty(String key) { + return CascadingUtil.getAxesListProjectProperty(this, key); } public SCMProjectProperty getScmProjectProperty(String key) { - return (SCMProjectProperty) getProperty(key, SCMProjectProperty.class); + return CascadingUtil.getScmProjectProperty(this, key); } /** @@ -522,7 +513,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R // should we block until the build is cancelled? } } - //TODO delete cascading project + Functions.unlinkProjectFromCascadingParents(getCascadingProject(), name); super.performDelete(); } @@ -621,7 +612,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R * Returns the log rotator for this job, or null if none. */ public LogRotator getLogRotator() { - return (LogRotator) getProperty(LOG_ROTATOR_PROPERTY_NAME, LogRotatorProjectProperty.class).getValue(); + return CascadingUtil.getLogRotatorProjectProperty(this, LOG_ROTATOR_PROPERTY_NAME).getValue(); } /** @@ -631,7 +622,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R */ @SuppressWarnings("unchecked") public void setLogRotator(LogRotator logRotator) { - getProperty(LOG_ROTATOR_PROPERTY_NAME, LogRotatorProjectProperty.class).setValue(logRotator); + CascadingUtil.getLogRotatorProjectProperty(this, LOG_ROTATOR_PROPERTY_NAME).setValue(logRotator); } diff --git a/hudson-core/src/main/java/hudson/util/CascadingUtil.java b/hudson-core/src/main/java/hudson/util/CascadingUtil.java new file mode 100644 index 0000000..efaa764 --- a/dev/null +++ b/hudson-core/src/main/java/hudson/util/CascadingUtil.java @@ -0,0 +1,337 @@ +/******************************************************************************* + * + * Copyright (c) 2011 Oracle Corporation. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * + * Nikita Levyankov + * + *******************************************************************************/ +package hudson.util; + +import hudson.Functions; +import hudson.model.Hudson; +import hudson.model.Item; +import hudson.model.Job; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.hudson.api.model.IJob; +import org.eclipse.hudson.api.model.IProjectProperty; +import org.eclipse.hudson.api.model.project.property.AxisListProjectProperty; +import org.eclipse.hudson.api.model.project.property.BaseProjectProperty; +import org.eclipse.hudson.api.model.project.property.BooleanProjectProperty; +import org.eclipse.hudson.api.model.project.property.DescribableListProjectProperty; +import org.eclipse.hudson.api.model.project.property.ExternalProjectProperty; +import org.eclipse.hudson.api.model.project.property.IntegerProjectProperty; +import org.eclipse.hudson.api.model.project.property.LogRotatorProjectProperty; +import org.eclipse.hudson.api.model.project.property.ResultProjectProperty; +import org.eclipse.hudson.api.model.project.property.SCMProjectProperty; +import org.eclipse.hudson.api.model.project.property.StringProjectProperty; + +/** + * Utility class for cascading functionality. + * <p/> + * Date: 10/25/11 + * + * @author Nikita Levyankov + */ +public class CascadingUtil { + + /** + * Returns job property by specified key. + * + * @param currentJob job that should be analyzed. + * @param key key. + * @return {@link import org.eclipse.hudson.api.model.IProjectProperty} instance or null. + * @throws NullPointerException if currentJob is null. + */ + public static IProjectProperty getProjectProperty(Job currentJob, String key) { + return getProjectProperty(currentJob, key, null); + } + + /** + * Returns StringProjectProperty by specified key. If property doesn't exists, it will be initialized and added to + * current job. + * + * @param currentJob job that should be analyzed. + * @param key key. + * @return {@link org.eclipse.hudson.api.model.project.property.StringProjectProperty} instance. + * @throws NullPointerException if currentJob is null. + */ + public static StringProjectProperty getStringProjectProperty(Job currentJob, String key) { + return getProjectProperty(currentJob, key, StringProjectProperty.class); + } + + /** + * Returns BaseProjectProperty by specified key. If property doesn't exists, it will be initialized and added to + * current job. + * + * @param currentJob job that should be analyzed. + * @param key key. + * @return {@link org.eclipse.hudson.api.model.project.property.BaseProjectProperty} instance. + * @throws NullPointerException if currentJob is null. + */ + public static BaseProjectProperty getBaseProjectProperty(Job currentJob, String key) { + return getProjectProperty(currentJob, key, BaseProjectProperty.class); + } + + /** + * Returns ExternalProjectProperty by specified key. If property doesn't exists, it will be initialized and added to + * current job. + * + * @param currentJob job that should be analyzed. + * @param key key. + * @return {@link org.eclipse.hudson.api.model.project.property.ExternalProjectProperty} instance. + * @throws NullPointerException if currentJob is null. + */ + public static ExternalProjectProperty getExternalProjectProperty(Job currentJob, String key) { + return getProjectProperty(currentJob, key, ExternalProjectProperty.class); + } + + /** + * Returns ResultProjectProperty by specified key. If property doesn't exists, it will be initialized and added to + * current job. + * + * @param currentJob job that should be analyzed. + * @param key key. + * @return {@link org.eclipse.hudson.api.model.project.property.ResultProjectProperty} instance. + * @throws NullPointerException if currentJob is null. + */ + public static ResultProjectProperty getResultProjectProperty(Job currentJob, String key) { + return getProjectProperty(currentJob, key, ResultProjectProperty.class); + } + + /** + * Returns BooleanProjectProperty by specified key. If property doesn't exists, it will be initialized and added to + * current job. + * + * @param currentJob job that should be analyzed. + * @param key key. + * @return {@link org.eclipse.hudson.api.model.project.property.BooleanProjectProperty} instance. + * @throws NullPointerException if currentJob is null. + */ + public static BooleanProjectProperty getBooleanProjectProperty(Job currentJob, String key) { + return getProjectProperty(currentJob, key, BooleanProjectProperty.class); + } + + /** + * Returns IntegerProjectProperty by specified key. If property doesn't exists, it will be initialized and added to + * current job. + * + * @param currentJob job that should be analyzed. + * @param key key. + * @return {@link org.eclipse.hudson.api.model.project.property.IntegerProjectProperty} instance. + * @throws NullPointerException if currentJob is null. + */ + public static IntegerProjectProperty getIntegerProjectProperty(Job currentJob, String key) { + return getProjectProperty(currentJob, key, IntegerProjectProperty.class); + } + + /** + * Returns LogRotatorProjectProperty by specified key. If property doesn't exists, it will be initialized and added + * to current job. + * + * @param currentJob job that should be analyzed. + * @param key key. + * @return {@link org.eclipse.hudson.api.model.project.property.LogRotatorProjectProperty} instance. + * @throws NullPointerException if currentJob is null. + */ + public static LogRotatorProjectProperty getLogRotatorProjectProperty(Job currentJob, String key) { + return getProjectProperty(currentJob, key, LogRotatorProjectProperty.class); + } + + /** + * Returns DescribableListProjectProperty by specified key. If property doesn't exists, it will be initialized and + * added to current job. + * + * @param currentJob job that should be analyzed. + * @param key key. + * @return {@link org.eclipse.hudson.api.model.project.property.DescribableListProjectProperty} instance. + * @throws NullPointerException if currentJob is null. + */ + public static DescribableListProjectProperty getDescribableListProjectProperty(Job currentJob, String key) { + return getProjectProperty(currentJob, key, DescribableListProjectProperty.class); + } + + /** + * Returns AxisListProjectProperty by specified key. If property doesn't exists, it will be initialized and added to + * current job. + * + * @param currentJob job that should be analyzed. + * @param key key. + * @return {@link org.eclipse.hudson.api.model.project.property.AxisListProjectProperty} instance. + * @throws NullPointerException if currentJob is null. + */ + public static AxisListProjectProperty getAxesListProjectProperty(Job currentJob, String key) { + return getProjectProperty(currentJob, key, AxisListProjectProperty.class); + } + + /** + * Returns SCMProjectProperty by specified key. If property doesn't exists, it will be initialized and added to + * current job. + * + * @param currentJob job that should be analyzed. + * @param key key. + * @return {@link org.eclipse.hudson.api.model.project.property.SCMProjectProperty} instance. + * @throws NullPointerException if currentJob is null. + */ + public static SCMProjectProperty getScmProjectProperty(Job currentJob, String key) { + return getProjectProperty(currentJob, key, SCMProjectProperty.class); + } + + /** + * Returns project property by specified key. + * + * @param currentJob job that should be analyzed. + * @param key key. + * @param clazz required property class. + * If class is not null and property was not found, property of given class will be created. + * @return {@link org.eclipse.hudson.api.model.IProjectProperty} instance or null. + * @throws NullPointerException if currentJob is null. + */ + @SuppressWarnings("unchecked") + public static <T extends IProjectProperty> T getProjectProperty(Job currentJob, String key, Class<T> clazz) { + IProjectProperty t = (IProjectProperty) currentJob.getProjectProperties().get(key); + if (null == t && null != clazz) { + try { + t = clazz.getConstructor(IJob.class).newInstance(currentJob); + t.setKey(key); + currentJob.putProjectProperty(key, t); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + } + return (T) t; + } + + /** + * Checks whether cascadingCandidate project can produce cycle cascading dependencies. + * + * @param cascadingCandidate candidate. + * @param cascadingChildren children of given job. + * @return false - if cyclic cascading dependency is not possible, true - otherwise. + */ + @SuppressWarnings("unchecked") + public static boolean hasCyclicCascadingLink(Job cascadingCandidate, Set<String> cascadingChildren) { + if (null != cascadingCandidate && CollectionUtils.isNotEmpty(cascadingChildren)) { + if (cascadingChildren.contains(cascadingCandidate.getName())) { + return true; + } + for (String childName : cascadingChildren) { + Job job = Functions.getItemByName(Hudson.getInstance().getAllItems(Job.class), childName); + if (hasCyclicCascadingLink(cascadingCandidate, job.getCascadingChildrenNames())) { + return true; + } + } + } + return false; + } + + /** + * Recursively unlink specified project from cascading hierarchy. + * + * @param cascadingProject cascading project to start from. + * @param projectToUnlink project that should be unlinked. + * @return true if project was unlinked, false - if cascadingProject or projectToUnlink is Null + */ + public static boolean unlinkProjectFromCascadingParents(Job cascadingProject, String projectToUnlink) { + if (null != cascadingProject && null != projectToUnlink) { + cascadingProject.removeCascadingChild(projectToUnlink); + if (cascadingProject.hasCascadingProject()) { + unlinkProjectFromCascadingParents(cascadingProject.getCascadingProject(), projectToUnlink); + } + return true; + } + return false; + } + + /** + * Links cascading project to children project. Method updates all parent cascading projects starting + * from the specified cascadingProject. + * + * @param cascadingProject cascadingProject. + * @param childProjectName the name of child project name. + */ + public static void linkCascadingProjectsToChild(Job cascadingProject, String childProjectName) { + if (cascadingProject != null) { + cascadingProject.addCascadingChild(childProjectName); + if (cascadingProject.hasCascadingProject()) { + linkCascadingProjectsToChild(cascadingProject.getCascadingProject(), childProjectName); + } + } + } + + /** + * Updates the name of the project in all children cascading references. + * If this project uses some cascading parent, the name of this project will be renamed in the cascading children + * collection of the cascading parent project. + * + * @param cascadingProject cascading project. + * @param oldName old project name. + * @param newName new project name. + */ + public static void renameCascadingChildLinks(Job cascadingProject, String oldName, String newName) { + if (cascadingProject != null) { + cascadingProject.renameCascadingChildName(oldName, newName); + if (cascadingProject.hasCascadingProject()) { + renameCascadingChildLinks(cascadingProject.getCascadingProject(), oldName, newName); + } + } + } + + /** + * Updates the name of the project in all parent cascading references. + * If this project is used as cascading parent, it's name will be renamed in all children projects. + * + * @param oldName old project name. + * @param newName new project name. + */ + public static void renameCascadingParentLinks(final String oldName, final String newName) { + if (StringUtils.isBlank(newName) || StringUtils.isBlank(oldName)) { + return; + } + for (Job job : Hudson.getInstance().getAllItems(Job.class)) { + if (oldName.equals(job.getCascadingProjectName())) { + job.renameCascadingProjectNameTo(newName); + } + } + } + + /** + * Returns possible cascading parents for current job, which are filtered by type and checked for avoidness cyclic + * dependency + * + * @param type project type. + * @param currentJob current job instance + * @param <T> Item + * @return list of cascading parents. + */ + @SuppressWarnings("unchecked") + public static <T extends Item> List<Job> getCascadingParents(Class<T> type, Job currentJob) { + List<T> allItems = Hudson.getInstance().getAllItems(type); + List<Job> result = new ArrayList<Job>(allItems.size()); + for (T item : allItems) { + Job job = (Job) item; + if (!hasCyclicCascadingLink(job, currentJob.getCascadingChildrenNames())) { + result.add(job); + } + } + return result; + } + +} diff --git a/hudson-core/src/main/resources/hudson/model/AbstractProject/deleteConfirmationPanel.jelly b/hudson-core/src/main/resources/hudson/model/AbstractProject/deleteConfirmationPanel.jelly index e2367b5..9b669c1 100644 --- a/hudson-core/src/main/resources/hudson/model/AbstractProject/deleteConfirmationPanel.jelly +++ b/hudson-core/src/main/resources/hudson/model/AbstractProject/deleteConfirmationPanel.jelly @@ -20,6 +20,7 @@ jQuery.ajax({ url: "${rootUrl}/${it.url}api/json", dataType: 'json', + cache: false, success: function(data) { jQuery('#confirmDialog').show(); jQuery('#childrenList').hide(); diff --git a/hudson-core/src/test/java/hudson/matrix/CombinationTest.java b/hudson-core/src/test/java/hudson/matrix/CombinationTest.java index fcbe46f..ea69a20 100644 --- a/hudson-core/src/test/java/hudson/matrix/CombinationTest.java +++ b/hudson-core/src/test/java/hudson/matrix/CombinationTest.java @@ -16,19 +16,21 @@ package hudson.matrix; -import junit.framework.TestCase; - import java.util.Map; import java.util.HashMap; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; /** * @author Kohsuke Kawaguchi */ -public class CombinationTest extends TestCase { +public class CombinationTest{ AxisList axes = new AxisList( new Axis("a","X","x"), new Axis("b","Y","y")); + @Test @SuppressWarnings({"RedundantStringConstructorCall"}) public void testEval() { Map<String,String> r = new HashMap<String, String>(); diff --git a/hudson-core/src/test/java/hudson/model/FreeStyleProjectMock.java b/hudson-core/src/test/java/hudson/model/FreeStyleProjectMock.java index 222ea73..c6f0d4d 100644 --- a/hudson-core/src/test/java/hudson/model/FreeStyleProjectMock.java +++ b/hudson-core/src/test/java/hudson/model/FreeStyleProjectMock.java @@ -15,8 +15,6 @@ package hudson.model; -import org.eclipse.hudson.api.model.IProjectProperty; - /** * Mock class for FreeStyleProject * <p/> @@ -26,13 +24,6 @@ import org.eclipse.hudson.api.model.IProjectProperty; */ public class FreeStyleProjectMock extends FreeStyleProject { - //TODO find better solution - /** - * The name of the cascadingProject. - */ - private String cascadingProjectName; - - public FreeStyleProjectMock(String name) { super((ItemGroup) null, name); setAllowSave(false); @@ -51,22 +42,4 @@ public class FreeStyleProjectMock extends FreeStyleProject { this.cascadingProject = cascadingProject; this.cascadingProjectName = cascadingProject != null ? cascadingProject.getName() : null; } - - public String getCascadingProjectName() { - return cascadingProjectName; - } - - public void renameCascadingProjectNameTo(String cascadingProjectName) { - this.cascadingProjectName = cascadingProjectName; - } - - /** - * Increase visibility for testing, - * - * @param key key. - * @param property property instance. - */ - public void putJobProperty(String key, IProjectProperty property) { - super.putJobProperty(key, property); - } } 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 3307c2d..53ec7f0 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 @@ -402,7 +402,7 @@ public class ProjectPropertyTest { BaseProjectProperty parentProperty = new BaseProjectProperty(parent); parentProperty.setKey(propertyKey); parentProperty.setValue(parentValue); - parent.putJobProperty(propertyKey, parentProperty); + parent.putProjectProperty(propertyKey, parentProperty); project.setCascadingProject(parent); property = new BaseProjectProperty(project); property.setKey(propertyKey); @@ -505,7 +505,7 @@ public class ProjectPropertyTest { BaseProjectProperty parentProperty = new BaseProjectProperty(parent); parentProperty.setKey(propertyKey); parentProperty.setValue(parentValue); - parent.putJobProperty(propertyKey, parentProperty); + parent.putProjectProperty(propertyKey, parentProperty); project.setCascadingProject(parent); //If value set to null, need to check whether default value is equals to cascading @@ -549,7 +549,7 @@ public class ProjectPropertyTest { IntegerProjectProperty parentProperty = new IntegerProjectProperty(parent); parentProperty.setKey(propertyKey); parentProperty.setValue(propertyValue); - parent.putJobProperty(propertyKey, parentProperty); + parent.putProjectProperty(propertyKey, parentProperty); project.setCascadingProject(parent); property = new IntegerProjectProperty(project); |

