aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-23 07:35:07 (EST)
committerWinston Prakash2011-12-01 20:47:09 (EST)
commitaae099e94baf4721bc3f696095eda5b5b8d051dc (patch)
tree9b8500544ffe5ceba75c4f0145c25d5512bf0170
parent3dd864ca5c598cae487969671e0f3a3403ce3de7 (diff)
downloadorg.eclipse.hudson.core-aae099e94baf4721bc3f696095eda5b5b8d051dc.zip
org.eclipse.hudson.core-aae099e94baf4721bc3f696095eda5b5b8d051dc.tar.gz
org.eclipse.hudson.core-aae099e94baf4721bc3f696095eda5b5b8d051dc.tar.bz2
Added cascading for project SCM.
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/AbstractProject.java17
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java6
-rw-r--r--hudson-core/src/main/java/hudson/scm/NullSCM.java13
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/SCMProjectProperty.java38
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java87
-rw-r--r--hudson-core/src/test/resources/hudson/scm/NullScmTest.java96
6 files changed, 253 insertions, 4 deletions
diff --git a/hudson-core/src/main/java/hudson/model/AbstractProject.java b/hudson-core/src/main/java/hudson/model/AbstractProject.java
index e61b772..f25ee0f 100644
--- a/hudson-core/src/main/java/hudson/model/AbstractProject.java
+++ b/hudson-core/src/main/java/hudson/model/AbstractProject.java
@@ -94,6 +94,7 @@ import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.eclipse.hudson.api.model.IAbstractProject;
+import org.eclipse.hudson.api.model.project.property.SCMProjectProperty;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.stapler.ForwardToView;
@@ -132,13 +133,18 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
public static final String BUILDERS_PROPERTY_NAME = "builders";
public static final String BUILD_WRAPPERS_PROPERTY_NAME = "buildWrappers";
public static final String PUBLISHERS_PROPERTY_NAME = "publishers";
+ public static final String SCM_PROPERTY_NAME = "scm";
/**
* {@link SCM} associated with the project.
* To allow derived classes to link {@link SCM} config to elsewhere,
* access to this variable should always go through {@link #getScm()}.
+ * @deprecated as of 2.2.0
+ * don't use this field directly, logic was moved to {@link org.hudsonci.api.model.IProjectProperty}.
+ * Use getter/setter for accessing to this field.
*/
+ @Deprecated
private volatile SCM scm = new NullSCM();
/**
@@ -358,6 +364,10 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
setJDK(jdk);
jdk = null;
}
+ if (null == getProperty(SCM_PROPERTY_NAME)) {
+ setScm(scm);
+ scm = null;
+ }
}
@Override
@@ -1526,12 +1536,13 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
@Exported
public SCM getScm() {
- return scm;
+ return (SCM) getProperty(SCM_PROPERTY_NAME, SCMProjectProperty.class).getValue();
}
+ @SuppressWarnings("unchecked")
public void setScm(SCM scm) throws IOException {
- this.scm = scm;
- save();
+ getProperty(SCM_PROPERTY_NAME, SCMProjectProperty.class).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 d3105d9..f44b5ed 100644
--- a/hudson-core/src/main/java/hudson/model/Job.java
+++ b/hudson-core/src/main/java/hudson/model/Job.java
@@ -24,6 +24,7 @@ import org.eclipse.hudson.api.model.project.property.DescribableListProjectPrope
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;
import hudson.util.graph.GraphSeries;
import hudson.widgets.Widget;
@@ -232,6 +233,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
return getProperty(key, null);
}
+ //TODO relocate it to functions
/**
* {@inheritDoc}
*/
@@ -283,6 +285,10 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
return (DescribableListProjectProperty) getProperty(key, DescribableListProjectProperty.class);
}
+ public SCMProjectProperty getScmProjectProperty(String key) {
+ return (SCMProjectProperty) getProperty(key, SCMProjectProperty.class);
+ }
+
@Override
public synchronized void save() throws IOException {
if (null == allowSave) {
diff --git a/hudson-core/src/main/java/hudson/scm/NullSCM.java b/hudson-core/src/main/java/hudson/scm/NullSCM.java
index b89558e..a85d638 100644
--- a/hudson-core/src/main/java/hudson/scm/NullSCM.java
+++ b/hudson-core/src/main/java/hudson/scm/NullSCM.java
@@ -66,4 +66,17 @@ public class NullSCM extends SCM {
return new NullSCM();
}
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ return !(o == null || getClass() != o.getClass());
+ }
+
+ @Override
+ public int hashCode() {
+ return 56;
+ }
}
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/SCMProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/SCMProjectProperty.java
new file mode 100644
index 0000000..f2bdbea
--- /dev/null
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/SCMProjectProperty.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ *
+ * 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 org.eclipse.hudson.api.model.project.property;
+import hudson.scm.NullSCM;
+import hudson.scm.SCM;
+import org.eclipse.hudson.api.model.IJob;
+
+
+/**
+ * Represents {@link SCM} property.
+ * <p/>
+ * Date: 10/11/11
+ *
+ * @author Anton Kozak
+ */
+public class SCMProjectProperty extends BaseProjectProperty<SCM> {
+
+ public SCMProjectProperty(IJob job) {
+ super(job);
+ }
+
+ @Override
+ public SCM getDefaultValue() {
+ return new NullSCM();
+ }
+}
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 b57c33c..292f5c6 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
@@ -15,13 +15,25 @@
package org.eclipse.hudson.api.model.project.property;
+import hudson.FilePath;
+import hudson.Launcher;
import hudson.matrix.Axis;
import hudson.matrix.AxisList;
+import hudson.model.AbstractBuild;
+import hudson.model.AbstractProject;
+import hudson.model.BuildListener;
import hudson.model.FreeStyleProjectMock;
+import hudson.model.TaskListener;
+import hudson.scm.ChangeLogParser;
+import hudson.scm.NullSCM;
+import hudson.scm.PollingResult;
+import hudson.scm.SCM;
+import hudson.scm.SCMRevisionState;
import hudson.tasks.JavadocArchiver;
import hudson.tasks.LogRotator;
import hudson.tasks.Shell;
import hudson.util.DescribableList;
+import java.io.File;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
@@ -118,6 +130,16 @@ public class ProjectPropertyTest {
}
}
+ @Test
+ public void testSCMProjectPropertyConstructor() {
+ try {
+ new SCMProjectProperty(null);
+ fail("Null should be handled by ProjectProperty constructor.");
+ } catch (Exception e) {
+ assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
+ }
+ }
+
/**
* Checks prepareValue method.
*/
@@ -177,6 +199,15 @@ public class ProjectPropertyTest {
assertEquals(value, property.prepareValue(value));
}
+ @Test
+ public void testSCMProjectPropertyPrepareValue() {
+ //Boolean property acts as BaseProperty
+ BaseProjectProperty property = new SCMProjectProperty(project);
+ assertNull(property.prepareValue(null));
+ SCM value = new NullSCM();
+ assertEquals(value, property.prepareValue(value));
+ }
+
/**
* Verify getDefaultValue method.
*/
@@ -222,6 +253,12 @@ public class ProjectPropertyTest {
assertNotNull(property.getDefaultValue());
}
+ @Test
+ public void testScmtProjectPropertyGetDefaultValue() {
+ BaseProjectProperty property = new SCMProjectProperty(project);
+ assertEquals(new NullSCM(), property.getDefaultValue());
+ }
+
/**
* Verify allowOverrideValue method.
*/
@@ -312,6 +349,15 @@ public class ProjectPropertyTest {
assertTrue(property.allowOverrideValue(new AxisList().add(new Axis("DB", "mysql")), new AxisList()));
}
+ @Test
+ public void testSCMProjectPropertyAllowOverrideValue() {
+ BaseProjectProperty property = new SCMProjectProperty(project);
+ assertFalse(property.allowOverrideValue(null, null));
+ assertTrue(property.allowOverrideValue(new NullSCM(), null));
+ assertTrue(property.allowOverrideValue(null, new NullSCM()));
+ assertTrue(property.allowOverrideValue(new NullSCM(), new FakeSCM()));
+ }
+
/**
* Verify getCascadingValue method.
*/
@@ -405,6 +451,15 @@ public class ProjectPropertyTest {
assertEquals(value, property.getOriginalValue());
}
+ @Test
+ public void testScmProjectPropertyGetOriginalValue() {
+ SCM value = new NullSCM();
+ BaseProjectProperty property = new SCMProjectProperty(project);
+ property.setKey(propertyKey);
+ property.setValue(value);
+ assertEquals(value, property.getOriginalValue());
+ }
+
/**
* Verify setValue method.
*/
@@ -551,4 +606,34 @@ public class ProjectPropertyTest {
property.setOverridden(false);
assertFalse(property.isOverridden());
}
-}
+
+ private class FakeSCM extends SCM {
+ @Override
+ public SCMRevisionState calcRevisionsFromBuild(AbstractBuild<?, ?> build, Launcher launcher,
+ TaskListener listener)
+ throws IOException, InterruptedException {
+ return null;
+ }
+
+ @Override
+ protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project, Launcher launcher,
+ FilePath workspace, TaskListener listener,
+ SCMRevisionState baseline)
+ throws IOException, InterruptedException {
+ return null;
+ }
+
+ @Override
+ public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath workspace,
+ BuildListener listener,
+ File changelogFile) throws IOException, InterruptedException {
+ return false;
+ }
+
+ @Override
+ public ChangeLogParser createChangeLogParser() {
+ return null;
+ }
+ }
+
+} \ No newline at end of file
diff --git a/hudson-core/src/test/resources/hudson/scm/NullScmTest.java b/hudson-core/src/test/resources/hudson/scm/NullScmTest.java
new file mode 100644
index 0000000..3609ec5
--- /dev/null
+++ b/hudson-core/src/test/resources/hudson/scm/NullScmTest.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ *
+ * 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.scm;
+
+import hudson.FilePath;
+import hudson.Launcher;
+import hudson.model.AbstractBuild;
+import hudson.model.AbstractProject;
+import hudson.model.BuildListener;
+import hudson.model.TaskListener;
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test to verify {@link NullSCM}
+ */
+@RunWith(Parameterized.class)
+public class NullScmTest {
+ private SCM scm1;
+ private SCM scm2;
+ private boolean expectedResult;
+
+ public NullScmTest(SCM scm1, SCM scm2, boolean expectedResult) {
+ this.scm1 = scm1;
+ this.scm2 = scm2;
+ this.expectedResult = expectedResult;
+ }
+
+ @Parameterized.Parameters
+ public static Collection generateData() {
+ return Arrays.asList(new Object[][]{
+ {new NullSCM(), new NullSCM(), true},
+ {new NullSCM(), null, false},
+ {new NullSCM(), new FakeSCM(), false}
+ });
+
+ }
+
+ @Test
+ public void testEquals() {
+ assertEquals(expectedResult, scm1.equals(scm2));
+ }
+
+ @Test
+ public void testHashCode() {
+ assertEquals(expectedResult, scm1.hashCode() == (scm2 == null? 0: scm2).hashCode());
+ }
+
+ private static class FakeSCM extends SCM {
+ @Override
+ public SCMRevisionState calcRevisionsFromBuild(AbstractBuild<?, ?> build, Launcher launcher,
+ TaskListener listener)
+ throws IOException, InterruptedException {
+ return null;
+ }
+
+ @Override
+ protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project, Launcher launcher,
+ FilePath workspace, TaskListener listener,
+ SCMRevisionState baseline)
+ throws IOException, InterruptedException {
+ return null;
+ }
+
+ @Override
+ public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath workspace,
+ BuildListener listener,
+ File changelogFile) throws IOException, InterruptedException {
+ return false;
+ }
+
+ @Override
+ public ChangeLogParser createChangeLogParser() {
+ return null;
+ }
+ }
+}