Permalink
Browse files

Job should be saved after changing cascading children

  • Loading branch information...
1 parent 1ed110a commit 3a941939bc4912aede0e635068a20e86eb522662 @8nevil8 8nevil8 committed Nov 18, 2011
@@ -662,7 +662,7 @@ void setCascadingProject(MatrixProject cascadingProject) {
}
@Override
- public void setCascadingProjectName(String cascadingProjectName) {
+ public void setCascadingProjectName(String cascadingProjectName) throws IOException {
super.setCascadingProjectName(cascadingProjectName);
try {
rebuildConfigurations();
@@ -155,8 +155,9 @@ protected void doSetName(String name) {
*
* @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 {
}
/**
@@ -103,7 +103,6 @@
import org.apache.commons.lang3.math.NumberUtils;
import org.hudsonci.api.model.IAbstractProject;
import org.hudsonci.model.project.property.IntegerProjectProperty;
-import org.hudsonci.model.project.property.SCMProjectProperty;
import org.hudsonci.model.project.property.TriggerProjectProperty;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
@@ -116,8 +115,7 @@
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
-import static hudson.scm.PollingResult.BUILD_NOW;
-import static hudson.scm.PollingResult.NO_CHANGES;
+import static hudson.scm.PollingResult.*;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
/**
@@ -1647,12 +1645,12 @@ public boolean hasParticipant(User user) {
@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();
}
@@ -308,36 +308,42 @@ public IProjectProperty getProperty(String key, Class clazz) {
}
/**
- * 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) {
return null != cascadingChildName && cascadingChildrenNames.contains(cascadingChildName);
}
/**
- * 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
@@ -834,7 +840,7 @@ public String getNextKey(String key) {
* @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);
}
@@ -1641,7 +1647,8 @@ public String getCascadingProjectName() {
return cascadingProjectName;
}
- public synchronized void doUpdateCascadingProject(@QueryParameter(fixEmpty = true) String projectName) {
+ public synchronized void doUpdateCascadingProject(@QueryParameter(fixEmpty = true) String projectName)
+ throws IOException {
setCascadingProjectName(projectName);
}
@@ -1662,12 +1669,13 @@ public synchronized void doModifyCascadingProperty(@QueryParameter(fixEmpty = tr
}
/**
- * 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)) {
@@ -1715,9 +1723,11 @@ public boolean hasCascadingProject() {
}
/**
- * 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;
@@ -34,6 +34,7 @@
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;
@@ -298,8 +299,10 @@ public static boolean hasCyclicCascadingLink(Job cascadingCandidate, Set<String>
* @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());
@@ -315,8 +318,10 @@ public static boolean unlinkProjectFromCascadingParents(Job cascadingProject, St
* @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);
@@ -335,8 +340,9 @@ private static boolean unlinkProjectFromCascadingParents(Job cascadingProject, S
*
* @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()) {
@@ -353,8 +359,10 @@ public static void linkCascadingProjectsToChild(Job cascadingProject, String chi
* @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()) {
@@ -60,7 +60,7 @@
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");
@@ -23,7 +23,6 @@
*/
package hudson.util;
-import antlr.ANTLRException;
import hudson.model.FreeStyleProjectMock;
import hudson.model.Hudson;
import hudson.triggers.TimerTrigger;
@@ -63,7 +62,7 @@
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");
@@ -63,7 +63,7 @@
@Test
@PrepareForTest(Hudson.class)
- public void testUnlinkProjectFromCascadingParents() {
+ public void testUnlinkProjectFromCascadingParents() throws Exception {
//Prepare data
FreeStyleProject project1 = new FreeStyleProjectMock("project1");
FreeStyleProjectMock child1 = new FreeStyleProjectMock("child1");
@@ -107,7 +107,7 @@ public void testUnlinkProjectFromCascadingParents() {
@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");
@@ -133,7 +133,7 @@ public void testUnlinkProjectFromCascadingParents2() {
}
@Test
- public void testLinkCascadingProjectsToChild() {
+ public void testLinkCascadingProjectsToChild() throws Exception {
FreeStyleProject project1 = new FreeStyleProjectMock("project1");
FreeStyleProjectMock child1 = new FreeStyleProjectMock("child1");
child1.setCascadingProject(project1);
@@ -156,7 +156,7 @@ public void testLinkCascadingProjectsToChild() {
@Test
- public void testRenameCascadingChildLinks() {
+ public void testRenameCascadingChildLinks() throws Exception {
String oldName = "oldCascadingProject";
String newName = "newCascadingProject";
FreeStyleProject project1 = new FreeStyleProjectMock("project1");
@@ -178,13 +178,13 @@ public void testRenameCascadingChildLinks() {
}
@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>();
@@ -225,7 +225,7 @@ public void testRenameCascadingParentLinksNullName2() {
@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");
@@ -282,7 +282,7 @@ public void testGetAllItems() {
@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");

0 comments on commit 3a94193

Please sign in to comment.