summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-23 04:00:51 (EST)
committer Winston Prakash2011-12-01 20:47:07 (EST)
commitd6b9d181f486f51a5c6e88217c56ffa647cfbcd4 (patch)
tree6fd0517b46b0b062c38a1f2a1871e32daba29f5c
parentc67ded557dce6e75f51ae06400fb6da7a916bf86 (diff)
downloadorg.eclipse.hudson.core-d6b9d181f486f51a5c6e88217c56ffa647cfbcd4.zip
org.eclipse.hudson.core-d6b9d181f486f51a5c6e88217c56ffa647cfbcd4.tar.gz
org.eclipse.hudson.core-d6b9d181f486f51a5c6e88217c56ffa647cfbcd4.tar.bz2
Added test which verifies old matrix configuration loading.
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/matrix/MatrixProject.java43
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java13
-rw-r--r--hudson-core/src/test/java/hudson/matrix/LegacyMatrixConfigurationTest.java87
-rw-r--r--hudson-core/src/test/resources/hudson/matrix/config.xml53
4 files changed, 177 insertions, 19 deletions
diff --git a/hudson-core/src/main/java/hudson/matrix/MatrixProject.java b/hudson-core/src/main/java/hudson/matrix/MatrixProject.java
index 0c5427d..75ebfac 100644
--- a/hudson-core/src/main/java/hudson/matrix/MatrixProject.java
+++ b/hudson-core/src/main/java/hudson/matrix/MatrixProject.java
@@ -471,23 +471,25 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i
* Rebuilds the {@link #configurations} list and {@link #activeConfigurations}.
*/
void rebuildConfigurations() throws IOException {
- {
- // backward compatibility check to see if there's any data in the old structure
- // if so, bring them to the newer structure.
- File[] oldDirs = getConfigurationsDir().listFiles(new FileFilter() {
- public boolean accept(File child) {
- return child.isDirectory() && !child.getName().startsWith("axis-");
- }
- });
- if(oldDirs!=null) {
- // rename the old directory to the new one
- for (File dir : oldDirs) {
- try {
- Combination c = Combination.fromString(dir.getName());
- dir.renameTo(getRootDirFor(c));
- } catch (IllegalArgumentException e) {
- // it's not a configuration dir. Just ignore.
- }
+ // for the tests
+ if(!isAllowSave()){
+ return;
+ }
+ // backward compatibility check to see if there's any data in the old structure
+ // if so, bring them to the newer structure.
+ File[] oldDirs = getConfigurationsDir().listFiles(new FileFilter() {
+ public boolean accept(File child) {
+ return child.isDirectory() && !child.getName().startsWith("axis-");
+ }
+ });
+ if (oldDirs != null) {
+ // rename the old directory to the new one
+ for (File dir : oldDirs) {
+ try {
+ Combination c = Combination.fromString(dir.getName());
+ dir.renameTo(getRootDirFor(c));
+ } catch (IllegalArgumentException e) {
+ // it's not a configuration dir. Just ignore.
}
}
}
@@ -747,5 +749,12 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i
this.cascadingProject = cascadingProject;
}
+ /**
+ * @inheritDoc
+ */
+ protected void setAllowSave(Boolean allowSave) {
+ super.setAllowSave(allowSave);
+ }
+
private static final Logger LOGGER = Logger.getLogger(MatrixProject.class.getName());
}
diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java
index 6ac14ab..d3105d9 100644
--- a/hudson-core/src/main/java/hudson/model/Job.java
+++ b/hudson-core/src/main/java/hudson/model/Job.java
@@ -198,6 +198,15 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
this.allowSave.set(allowSave);
}
+ /**
+ * Returns true if save operation for config is permitted.
+ *
+ * @return true if save operation for config is permitted.
+ */
+ protected Boolean isAllowSave() {
+ return allowSave.get();
+ }
+
protected Job(ItemGroup parent, String name) {
super(parent, name);
}
@@ -279,7 +288,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
if (null == allowSave) {
initAllowSave();
}
- if (allowSave.get()) {
+ if (isAllowSave()) {
super.save();
holdOffBuildUntilSave = false;
}
@@ -351,7 +360,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
/**
* Initialize project properties if null.
*/
- protected final void initProjectProperties() {
+ public final void initProjectProperties() {
if (null == jobProperties) {
jobProperties = new ConcurrentHashMap<String, IProjectProperty>();
}
diff --git a/hudson-core/src/test/java/hudson/matrix/LegacyMatrixConfigurationTest.java b/hudson-core/src/test/java/hudson/matrix/LegacyMatrixConfigurationTest.java
new file mode 100644
index 0000000..c54945c
--- /dev/null
+++ b/hudson-core/src/test/java/hudson/matrix/LegacyMatrixConfigurationTest.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ *
+ * 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:
+ *
+ * Anton Kozak
+ *
+ *
+ *******************************************************************************/
+package hudson.matrix;
+
+import hudson.model.AbstractProject;
+import hudson.model.Hudson;
+import hudson.model.Items;
+import hudson.model.Result;
+import hudson.tasks.LogRotator;
+import java.io.File;
+import java.net.URISyntaxException;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import static junit.framework.Assert.*;
+
+/**
+ * Test to verify legacy matrix project configuration loading.
+ * <p/>
+ * Date: 10/06/11
+ *
+ * @author Anton Kozak
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({Hudson.class})
+public class LegacyMatrixConfigurationTest {
+
+ private File config;
+
+ @Before
+ public void setUp() throws URISyntaxException {
+ config = new File(MatrixProject.class.getResource("/hudson/matrix").toURI());
+ }
+
+ /**
+ * Tests unmarshalls MatrixProject configuration and checks whether properties are loaded correctly.
+ *
+ * @throws Exception if any.
+ */
+ @Test
+ public void testLoadLegacyMatrixProject() throws Exception {
+ MatrixProject project = (MatrixProject) Items.getConfigFile(config).read();
+ project.setAllowSave(false);
+ project.initProjectProperties();
+ project.buildProjectProperties();
+ assertEquals("/tmp/1", project.getProperty(AbstractProject.CUSTOM_WORKSPACE_PROPERTY_NAME).getValue());
+ assertEquals(new Integer(7), project.getIntegerProperty(AbstractProject.QUIET_PERIOD_PROPERTY_NAME).getValue());
+
+ assertTrue(project.getBooleanProperty(MatrixProject.RUN_SEQUENTIALLY_PROPERTY_NAME).getValue());
+ assertEquals("!(label==\"win\" && DB==\"oracle\")",
+ project.getProperty(MatrixProject.COMBINATION_FILTER_PROPERTY_NAME).getValue());
+ assertEquals("label==\"unix\" && DB==\"mysql\"",
+ project.getProperty(MatrixProject.TOUCH_STONE_COMBINATION_FILTER_PROPERTY_NAME).getValue());
+ assertEquals(Result.SUCCESS,
+ project.getResultProperty(MatrixProject.TOUCH_STONE_RESULT_CONDITION_PROPERTY_NAME).getValue());
+ assertEquals(new LogRotator(7, 7, 7, 7),
+ project.getLogRotatorProjectProperty(MatrixProject.LOG_ROTATOR_PROPERTY_NAME).getValue());
+ AxisList axes = project.getAxesListProjectProperty(MatrixProject.AXES_PROPERTY_NAME).getValue();
+ assertEquals(2, axes.size());
+ assertEquals("DB", axes.get(0).getName());
+ assertEquals(2, axes.get(0).getValues().size());
+ assertEquals("oracle", axes.get(0).getValues().get(0));
+ assertEquals("mysql", axes.get(0).getValues().get(1));
+ assertEquals("label", axes.get(1).getName());
+ assertEquals(2, axes.get(1).getValues().size());
+ assertEquals("unix", axes.get(1).getValues().get(0));
+ assertEquals("win", axes.get(1).getValues().get(1));
+ //TODO add matrix configuration verification
+
+ }
+}
diff --git a/hudson-core/src/test/resources/hudson/matrix/config.xml b/hudson-core/src/test/resources/hudson/matrix/config.xml
new file mode 100644
index 0000000..cf72028
--- /dev/null
+++ b/hudson-core/src/test/resources/hudson/matrix/config.xml
@@ -0,0 +1,53 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<matrix-project>
+ <actions/>
+ <description></description>
+ <logRotator>
+ <daysToKeep>7</daysToKeep>
+ <numToKeep>7</numToKeep>
+ <artifactDaysToKeep>7</artifactDaysToKeep>
+ <artifactNumToKeep>7</artifactNumToKeep>
+ </logRotator>
+ <keepDependencies>false</keepDependencies>
+ <creationTime>1317889840582</creationTime>
+ <properties/>
+ <scm class="hudson.scm.NullSCM"/>
+ <quietPeriod>7</quietPeriod>
+ <scmCheckoutRetryCount>7</scmCheckoutRetryCount>
+ <advancedAffinityChooser>false</advancedAffinityChooser>
+ <canRoam>true</canRoam>
+ <disabled>false</disabled>
+ <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
+ <blockBuildWhenUpstreamBuilding>true</blockBuildWhenUpstreamBuilding>
+ <triggers class="vector"/>
+ <concurrentBuild>false</concurrentBuild>
+ <cleanWorkspaceRequired>false</cleanWorkspaceRequired>
+ <axes>
+ <hudson.matrix.TextAxis>
+ <name>DB</name>
+ <values>
+ <string>oracle</string>
+ <string>mysql</string>
+ </values>
+ </hudson.matrix.TextAxis>
+ <hudson.matrix.LabelAxis>
+ <name>label</name>
+ <values>
+ <string>unix</string>
+ <string>win</string>
+ </values>
+ </hudson.matrix.LabelAxis>
+ </axes>
+ <combinationFilter>!(label==&quot;win&quot; &amp;&amp; DB==&quot;oracle&quot;)</combinationFilter>
+ <builders/>
+ <publishers/>
+ <buildWrappers/>
+ <runSequentially>true</runSequentially>
+ <touchStoneCombinationFilter>label==&quot;unix&quot; &amp;&amp; DB==&quot;mysql&quot;</touchStoneCombinationFilter>
+ <touchStoneResultCondition>
+ <name>SUCCESS</name>
+ <ordinal>0</ordinal>
+ <color>BLUE</color>
+ </touchStoneResultCondition>
+ <customWorkspace>/tmp/1</customWorkspace>
+</matrix-project> \ No newline at end of file