summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-21 05:32:13 (EST)
committer Winston Prakash2011-12-01 20:46:47 (EST)
commitf78aa24f8e799ae570410b3b9c30c38d429fc855 (patch)
treeb0f4d787427c32d07614e6915ea19c659e0f9d3a
parentbe01b154cf5c01c48b54e9c75dae321b83173759 (diff)
downloadorg.eclipse.hudson.core-f78aa24f8e799ae570410b3b9c30c38d429fc855.zip
org.eclipse.hudson.core-f78aa24f8e799ae570410b3b9c30c38d429fc855.tar.gz
org.eclipse.hudson.core-f78aa24f8e799ae570410b3b9c30c38d429fc855.tar.bz2
Update FreeStyleProject in order to support parent template while setting and getting custom workspace value
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/FreeStyleProject.java39
-rw-r--r--hudson-core/src/main/java/hudson/model/IFreeStyleProject.java2
-rw-r--r--hudson-core/src/main/java/hudson/model/IProject.java45
-rw-r--r--hudson-core/src/main/java/hudson/model/Project.java2
5 files changed, 90 insertions, 15 deletions
diff --git a/hudson-core/src/main/java/hudson/model/AbstractProject.java b/hudson-core/src/main/java/hudson/model/AbstractProject.java
index 2b985d3..768c766 100644
--- a/hudson-core/src/main/java/hudson/model/AbstractProject.java
+++ b/hudson-core/src/main/java/hudson/model/AbstractProject.java
@@ -1977,10 +1977,19 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
*
* @return template.
*/
- public AbstractProject getTemplate() {
+ @SuppressWarnings({"unchecked"})
+ public P getTemplate() {
if (null == template) {
- template = Hudson.getInstance().getTemplate(this.getClass(), templateName);
+ template = Hudson.getInstance().getTemplate(this.getClass(),templateName);
}
- return template;
+ return (P)template;
}
-}
+
+ /**
+ * Checks whether current project is inherited from other project.
+ * @return boolean.
+ */
+ protected boolean hasParentTemplate() {
+ return null != getTemplate();
+ }
+} \ No newline at end of file
diff --git a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
index af15e55..956b1fa 100644
--- a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
+++ b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
@@ -21,6 +21,7 @@ import hudson.Extension;
import java.io.File;
import java.io.IOException;
+import org.apache.commons.lang3.StringUtils;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
@@ -55,8 +56,12 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
return FreeStyleBuild.class;
}
+
public String getCustomWorkspace() {
- return customWorkspace;
+ if (StringUtils.isNotBlank(customWorkspace)) {
+ return customWorkspace;
+ }
+ return hasParentTemplate()? getTemplate().getCustomWorkspace() : null;
}
/**
@@ -73,22 +78,38 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
*
* <p>
* If this path is relative, it's resolved against {@link Node#getRootPath()} on the node where this workspace
- * is prepared.
+ * is prepared.
*
* @since 1.320
*/
public void setCustomWorkspace(String customWorkspace) throws IOException {
- this.customWorkspace= customWorkspace;
- save();
+ setCustomWorkspace(customWorkspace, true);
+ }
+
+ /**
+ * Sets custom workspace,
+ * @param customWorkspace workspace.
+ * @param forceSave true to force save operation
+ * @throws IOException if any.
+ * @see #save()
+ */
+ private void setCustomWorkspace(String customWorkspace, boolean forceSave) throws IOException{
+ if (!(hasParentTemplate()
+ && StringUtils.equalsIgnoreCase(getTemplate().getCustomWorkspace(), customWorkspace))) {
+ this.customWorkspace = customWorkspace;
+ } else {
+ this.customWorkspace = null;
+ }
+ if (forceSave) {
+ save();
+ }
}
@Override
protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, Descriptor.FormException {
- if(req.hasParameter("customWorkspace"))
- customWorkspace = req.getParameter("customWorkspace.directory");
- else
- customWorkspace = null;
-
+ setCustomWorkspace(
+ req.hasParameter("customWorkspace")? req.getParameter("customWorkspace.directory") : null,
+ false);
super.submit(req, rsp);
}
diff --git a/hudson-core/src/main/java/hudson/model/IFreeStyleProject.java b/hudson-core/src/main/java/hudson/model/IFreeStyleProject.java
index 06795e6..a982527 100644
--- a/hudson-core/src/main/java/hudson/model/IFreeStyleProject.java
+++ b/hudson-core/src/main/java/hudson/model/IFreeStyleProject.java
@@ -21,7 +21,7 @@ package hudson.model;
*
* @author Nikita Levyankov
*/
-public interface IFreeStyleProject extends IAbstractProject {
+public interface IFreeStyleProject extends IProject {
/**
* Returns user-specified workspace directory, or null if it's up to Hudson
diff --git a/hudson-core/src/main/java/hudson/model/IProject.java b/hudson-core/src/main/java/hudson/model/IProject.java
new file mode 100644
index 0000000..4baf249
--- /dev/null
+++ b/hudson-core/src/main/java/hudson/model/IProject.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ *
+ * Copyright (c) 20011 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.model;
+
+import hudson.tasks.BuildWrapper;
+import hudson.tasks.Builder;
+import hudson.tasks.Publisher;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Project interface
+ * <p/>
+ * Date: 9/15/11
+ *
+ * @author Nikita Levyankov
+ */
+public interface IProject extends IAbstractProject {
+ /**
+ * @return list of project {@link Builder}
+ */
+ List<Builder> getBuilders();
+
+ /**
+ * @return map of project {@link BuildWrapper}
+ */
+ Map<Descriptor<BuildWrapper>, BuildWrapper> getBuildWrappers();
+
+ /**
+ * @return map of project {@link Publisher}
+ */
+ Map<Descriptor<Publisher>, Publisher> getPublishers();
+}
diff --git a/hudson-core/src/main/java/hudson/model/Project.java b/hudson-core/src/main/java/hudson/model/Project.java
index 5626aa7..7133c8b 100644
--- a/hudson-core/src/main/java/hudson/model/Project.java
+++ b/hudson-core/src/main/java/hudson/model/Project.java
@@ -48,7 +48,7 @@ import java.util.Set;
* @author Kohsuke Kawaguchi
*/
public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
- extends AbstractProject<P,B> implements SCMedItem, Saveable, ProjectWithMaven, BuildableItemWithBuildWrappers {
+ extends AbstractProject<P,B> implements SCMedItem, Saveable, ProjectWithMaven, BuildableItemWithBuildWrappers, IProject {
/**
* List of active {@link Builder}s configured for this project.