aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-25 03:21:44 (EST)
committerWinston Prakash2011-12-01 20:47:35 (EST)
commit4a2111ef55fe6a4721844d86ea86d493d5c62646 (patch)
tree2f288f8696ee02dd92a45233a448c1260560d361
parent274f5995d42488e08bcf4c3c27ffd1c0e86af4b7 (diff)
downloadorg.eclipse.hudson.core-4a2111ef55fe6a4721844d86ea86d493d5c62646.zip
org.eclipse.hudson.core-4a2111ef55fe6a4721844d86ea86d493d5c62646.tar.gz
org.eclipse.hudson.core-4a2111ef55fe6a4721844d86ea86d493d5c62646.tar.bz2
Job should be saved after changing cascading children
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/matrix/MatrixProject.java2
-rw-r--r--hudson-core/src/main/java/hudson/model/AbstractItem.java3
-rw-r--r--hudson-core/src/main/java/hudson/model/AbstractProject.java4
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java56
-rw-r--r--hudson-core/src/main/java/hudson/util/CascadingUtil.java16
-rw-r--r--hudson-core/src/test/java/hudson/util/CascadingParameterDefinitionPropertiesTest.java2
-rw-r--r--hudson-core/src/test/java/hudson/util/CascadingTriggersTest.java2
-rw-r--r--hudson-core/src/test/java/hudson/util/CascadingUtilTest.java16
8 files changed, 59 insertions, 42 deletions
diff --git a/hudson-core/src/main/java/hudson/matrix/MatrixProject.java b/hudson-core/src/main/java/hudson/matrix/MatrixProject.java
index e2d81ce..47ff46f 100644
--- a/hudson-core/src/main/java/hudson/matrix/MatrixProject.java
+++ b/hudson-core/src/main/java/hudson/matrix/MatrixProject.java
@@ -656,7 +656,7 @@ public class MatrixProject extends BaseBuildableProject<MatrixProject, MatrixBui
}
@Override
- public void setCascadingProjectName(String cascadingProjectName) {
+ public void setCascadingProjectName(String cascadingProjectName) throws IOException {
super.setCascadingProjectName(cascadingProjectName);
try {
rebuildConfigurations();
diff --git a/hudson-core/src/main/java/hudson/model/AbstractItem.java b/hudson-core/src/main/java/hudson/model/AbstractItem.java
index 2cbe055..0bd56c9 100644
--- a/hudson-core/src/main/java/hudson/model/AbstractItem.java
+++ b/hudson-core/src/main/java/hudson/model/AbstractItem.java
@@ -147,8 +147,9 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
*
* @param oldName old item name.
* @param newName new item name.
+ * @throws java.io.IOException if item couldn't be saved.
*/
- protected void performBeforeItemRenaming(String oldName, String newName){
+ protected void performBeforeItemRenaming(String oldName, String newName) throws IOException {
}
/**
diff --git a/hudson-core/src/main/java/hudson/model/AbstractProject.java b/hudson-core/src/main/java/hudson/model/AbstractProject.java
index c2ddeb1..39b9253 100644
--- a/hudson-core/src/main/java/hudson/model/AbstractProject.java
+++ b/hudson-core/src/main/java/hudson/model/AbstractProject.java
@@ -1633,12 +1633,12 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
@Exported
public SCM getScm() {
- return (SCM) getProperty(SCM_PROPERTY_NAME, SCMProjectProperty.class).getValue();
+ return CascadingUtil.getScmProjectProperty(this, SCM_PROPERTY_NAME).getValue();
}
@SuppressWarnings("unchecked")
public void setScm(SCM scm) throws IOException {
- getProperty(SCM_PROPERTY_NAME, SCMProjectProperty.class).setValue(scm);
+ CascadingUtil.getScmProjectProperty(this, SCM_PROPERTY_NAME).setValue(scm);
save();
}
diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java
index f1e0d8a..542b43e 100644
--- a/hudson-core/src/main/java/hudson/model/Job.java
+++ b/hudson-core/src/main/java/hudson/model/Job.java
@@ -297,21 +297,25 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
}
/**
- * Adds cascading child project name.
+ * Adds cascading child project name and saves configuration.
*
* @param cascadingChildName cascading child project name.
+ * @throws java.io.IOException if configuration couldn't be saved.
*/
- public void addCascadingChild(String cascadingChildName) {
+ public void addCascadingChild(String cascadingChildName) throws IOException {
cascadingChildrenNames.add(cascadingChildName);
+ save();
}
/**
- * Remove cascading child project name.
+ * Remove cascading child project name and saves job configuration
*
* @param cascadingChildName cascading child project name.
+ * @throws java.io.IOException if configuration couldn't be saved.
*/
- public void removeCascadingChild(String cascadingChildName) {
+ public void removeCascadingChild(String cascadingChildName) throws IOException {
cascadingChildrenNames.remove(cascadingChildName);
+ save();
}
public boolean hasCascadingChild(String cascadingChildName) {
@@ -319,14 +323,16 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
}
/**
- * Remove cascading child project name.
+ * Remove cascading child project name and saves job configuration
*
* @param oldChildName old child project name.
* @param newChildName new child project name.
+ * @throws java.io.IOException if configuration couldn't be saved.
*/
- public synchronized void renameCascadingChildName(String oldChildName, String newChildName) {
+ public synchronized void renameCascadingChildName(String oldChildName, String newChildName) throws IOException {
cascadingChildrenNames.remove(oldChildName);
cascadingChildrenNames.add(newChildName);
+ save();
}
@Override
@@ -827,7 +833,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
* @inheritDoc
*/
@Override
- protected void performBeforeItemRenaming(String oldName, String newName){
+ protected void performBeforeItemRenaming(String oldName, String newName) throws IOException {
CascadingUtil.renameCascadingChildLinks(cascadingProject, oldName, newName);
CascadingUtil.renameCascadingParentLinks(oldName, newName);
}
@@ -1520,16 +1526,6 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
}
/**
- * Renames cascading project name. For the properties prcessing and children links updating
- * please use {@link #setCascadingProjectName} instead.
- *
- * @param cascadingProjectName new project name.
- */
- public void renameCascadingProjectNameTo(String cascadingProjectName) {
- this.cascadingProjectName = cascadingProjectName;
- }
-
- /**
* Returns cascading project name.
*
* @return cascading project name.
@@ -1538,7 +1534,8 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
return cascadingProjectName;
}
- public synchronized void doUpdateCascadingProject(@QueryParameter(fixEmpty = true) String projectName) {
+ public synchronized void doUpdateCascadingProject(@QueryParameter(fixEmpty = true) String projectName)
+ throws IOException {
setCascadingProjectName(projectName);
}
@@ -1559,12 +1556,13 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
}
/**
- * Sets cascadingProject name.
+ * Sets cascadingProject name and saves project configuration.
*
* @param cascadingProjectName cascadingProject name.
+ * @throws java.io.IOException if configuration couldn't be saved.
*/
@SuppressWarnings("unchecked")
- public synchronized void setCascadingProjectName(String cascadingProjectName) {
+ public synchronized void setCascadingProjectName(String cascadingProjectName) throws IOException {
if (StringUtils.isBlank(cascadingProjectName)) {
clearCascadingProject();
} else if (!StringUtils.equalsIgnoreCase(this.cascadingProjectName, cascadingProjectName)) {
@@ -1580,6 +1578,16 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
}
/**
+ * Renames cascading project name. For the properties prcessing and children links updating
+ * please use {@link #setCascadingProjectName} instead.
+ *
+ * @param cascadingProjectName new project name.
+ */
+ public void renameCascadingProjectNameTo(String cascadingProjectName) {
+ this.cascadingProjectName = cascadingProjectName;
+ }
+
+ /**
* Returns selected ccascading project.
*
* @return cascading project.
@@ -1593,7 +1601,6 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
return cascadingProject;
}
-
/**
* Checks whether current job is inherited from other project.
* @return boolean.
@@ -1603,9 +1610,11 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
}
/**
- * Remove cascading project data and mark all project properties as non-overridden
+ * Removes cascading project data, marks all project properties as non-overridden and saves configuration
+ *
+ * @throws java.io.IOException if configuration couldn't be saved.
*/
- private void clearCascadingProject() {
+ private void clearCascadingProject() throws IOException {
CascadingUtil.unlinkProjectFromCascadingParents(cascadingProject, name);
this.cascadingProject = null;
this.cascadingProjectName = null;
@@ -1614,7 +1623,6 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
}
}
-
public Graph getBuildTimeGraph() {
Graph graph = new Graph(getLastBuild().getTimestamp(), 500, 400);
diff --git a/hudson-core/src/main/java/hudson/util/CascadingUtil.java b/hudson-core/src/main/java/hudson/util/CascadingUtil.java
index d62c590..e98949e 100644
--- a/hudson-core/src/main/java/hudson/util/CascadingUtil.java
+++ b/hudson-core/src/main/java/hudson/util/CascadingUtil.java
@@ -25,6 +25,7 @@ import hudson.model.ParameterDefinition;
import hudson.model.ParametersDefinitionProperty;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
@@ -289,8 +290,10 @@ public class CascadingUtil {
* @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
+ * @throws java.io.IOException if cascading project couldn't be saved.
*/
- public static boolean unlinkProjectFromCascadingParents(Job cascadingProject, String projectToUnlink) {
+ public static boolean unlinkProjectFromCascadingParents(Job cascadingProject, String projectToUnlink)
+ throws IOException {
if (null != cascadingProject && null != projectToUnlink) {
Job job = Functions.getItemByName(Hudson.getInstance().getAllItems(Job.class), projectToUnlink);
Set<String> set = new HashSet<String>(job.getCascadingChildrenNames());
@@ -306,8 +309,10 @@ public class CascadingUtil {
* @param cascadingProject cascading project to start from.
* @param projectsToUnlink projects that should be unlinked.
* @return if project was unlinked
+ * @throws java.io.IOException if cascading project couldn't be saved.
*/
- private static boolean unlinkProjectFromCascadingParents(Job cascadingProject, Set<String> projectsToUnlink) {
+ private static boolean unlinkProjectFromCascadingParents(Job cascadingProject, Set<String> projectsToUnlink)
+ throws IOException {
if (null != cascadingProject && null != projectsToUnlink) {
for (String toUnlink : projectsToUnlink) {
cascadingProject.removeCascadingChild(toUnlink);
@@ -326,8 +331,9 @@ public class CascadingUtil {
*
* @param cascadingProject cascadingProject.
* @param childProjectName the name of child project name.
+ * @throws java.io.IOException if cascading project couldn't be saved.
*/
- public static void linkCascadingProjectsToChild(Job cascadingProject, String childProjectName) {
+ public static void linkCascadingProjectsToChild(Job cascadingProject, String childProjectName) throws IOException {
if (cascadingProject != null) {
cascadingProject.addCascadingChild(childProjectName);
if (cascadingProject.hasCascadingProject()) {
@@ -344,8 +350,10 @@ public class CascadingUtil {
* @param cascadingProject cascading project.
* @param oldName old project name.
* @param newName new project name.
+ * @throws java.io.IOException if cascading project couldn't be saved.
*/
- public static void renameCascadingChildLinks(Job cascadingProject, String oldName, String newName) {
+ public static void renameCascadingChildLinks(Job cascadingProject, String oldName, String newName)
+ throws IOException {
if (cascadingProject != null) {
cascadingProject.renameCascadingChildName(oldName, newName);
if (cascadingProject.hasCascadingProject()) {
diff --git a/hudson-core/src/test/java/hudson/util/CascadingParameterDefinitionPropertiesTest.java b/hudson-core/src/test/java/hudson/util/CascadingParameterDefinitionPropertiesTest.java
index 84a0f95..cc5ec34 100644
--- a/hudson-core/src/test/java/hudson/util/CascadingParameterDefinitionPropertiesTest.java
+++ b/hudson-core/src/test/java/hudson/util/CascadingParameterDefinitionPropertiesTest.java
@@ -52,7 +52,7 @@ public class CascadingParameterDefinitionPropertiesTest {
private CopyOnWriteList<ParametersDefinitionProperty> copyOnWriteList;
@Before
- public void setUp() {
+ public void setUp() throws Exception {
p1 = new FreeStyleProjectMock("p1");
p2 = new FreeStyleProjectMock("p2");
p3 = new FreeStyleProjectMock("p3");
diff --git a/hudson-core/src/test/java/hudson/util/CascadingTriggersTest.java b/hudson-core/src/test/java/hudson/util/CascadingTriggersTest.java
index 4668bbf..bd9e50c 100644
--- a/hudson-core/src/test/java/hudson/util/CascadingTriggersTest.java
+++ b/hudson-core/src/test/java/hudson/util/CascadingTriggersTest.java
@@ -55,7 +55,7 @@ public class CascadingTriggersTest {
private StaplerRequest req;
@Before
- public void setUp() throws ANTLRException {
+ public void setUp() throws Exception {
p1 = new FreeStyleProjectMock("p1");
p2 = new FreeStyleProjectMock("p2");
p3 = new FreeStyleProjectMock("p3");
diff --git a/hudson-core/src/test/java/hudson/util/CascadingUtilTest.java b/hudson-core/src/test/java/hudson/util/CascadingUtilTest.java
index fbf8c9d..7c988aa 100644
--- a/hudson-core/src/test/java/hudson/util/CascadingUtilTest.java
+++ b/hudson-core/src/test/java/hudson/util/CascadingUtilTest.java
@@ -50,7 +50,7 @@ public class CascadingUtilTest {
@Test
@PrepareForTest(Hudson.class)
- public void testUnlinkProjectFromCascadingParents() {
+ public void testUnlinkProjectFromCascadingParents() throws Exception {
//Prepare data
FreeStyleProject project1 = new FreeStyleProjectMock("project1");
FreeStyleProjectMock child1 = new FreeStyleProjectMock("child1");
@@ -94,7 +94,7 @@ public class CascadingUtilTest {
@Test
@PrepareForTest(Hudson.class)
- public void testUnlinkProjectFromCascadingParents2() {
+ public void testUnlinkProjectFromCascadingParents2() throws Exception {
FreeStyleProject project1 = new FreeStyleProjectMock("p1");
FreeStyleProjectMock project2 = new FreeStyleProjectMock("p2");
FreeStyleProjectMock project3 = new FreeStyleProjectMock("p3");
@@ -120,7 +120,7 @@ public class CascadingUtilTest {
}
@Test
- public void testLinkCascadingProjectsToChild() {
+ public void testLinkCascadingProjectsToChild() throws Exception {
FreeStyleProject project1 = new FreeStyleProjectMock("project1");
FreeStyleProjectMock child1 = new FreeStyleProjectMock("child1");
child1.setCascadingProject(project1);
@@ -143,7 +143,7 @@ public class CascadingUtilTest {
@Test
- public void testRenameCascadingChildLinks() {
+ public void testRenameCascadingChildLinks() throws Exception {
String oldName = "oldCascadingProject";
String newName = "newCascadingProject";
FreeStyleProject project1 = new FreeStyleProjectMock("project1");
@@ -165,13 +165,13 @@ public class CascadingUtilTest {
}
@Test
- public void testRenameCascadingChildLinksNullProject() {
+ public void testRenameCascadingChildLinksNullProject() throws Exception {
CascadingUtil.renameCascadingChildLinks(null, "name", "newName");
}
@Test
@PrepareForTest(Hudson.class)
- public void testRenameCascadingParentLinks() {
+ public void testRenameCascadingParentLinks() throws Exception {
String oldName = "oldCascadingProject";
String newName = "newCascadingProject";
List<Job> jobs = new ArrayList<Job>();
@@ -212,7 +212,7 @@ public class CascadingUtilTest {
@Test
@PrepareForTest(Hudson.class)
- public void testGetAllItems() {
+ public void testGetAllItems() throws Exception {
FreeStyleProject project1 = new FreeStyleProjectMock("p1");
FreeStyleProjectMock project2 = new FreeStyleProjectMock("p2");
FreeStyleProjectMock project3 = new FreeStyleProjectMock("p3");
@@ -269,7 +269,7 @@ public class CascadingUtilTest {
@Test
@PrepareForTest(Hudson.class)
- public void testHasCyclicCascadingLink() {
+ public void testHasCyclicCascadingLink() throws Exception {
FreeStyleProject project1 = new FreeStyleProjectMock("p1");
FreeStyleProjectMock project2 = new FreeStyleProjectMock("p2");
FreeStyleProjectMock project3 = new FreeStyleProjectMock("p3");