From e65f893b1bc0608ef57095c71eb0517c5353bda1 Mon Sep 17 00:00:00 2001 From: Christoph Kutzinski Date: Tue, 12 Apr 2011 23:05:12 +0200 Subject: [PATCH] [JENKINS-8848] allow custom workspaces for maven jobs --- .../main/java/hudson/matrix/MatrixBuild.java | 11 ----- .../java/hudson/matrix/MatrixProject.java | 33 -------------- .../main/java/hudson/model/AbstractBuild.java | 5 +++ .../java/hudson/model/AbstractProject.java | 38 ++++++++++++++++ .../java/hudson/model/FreeStyleBuild.java | 11 ----- .../java/hudson/model/FreeStyleProject.java | 43 ------------------- .../MavenModuleSet/configure-entries.jelly | 5 ++- .../help/project-config/custom-workspace.html | 3 +- .../project-config/custom-workspace_de.html | 5 +-- .../project-config/custom-workspace_fr.html | 3 +- .../project-config/custom-workspace_tr.html | 3 +- 11 files changed, 51 insertions(+), 109 deletions(-) diff --git a/core/src/main/java/hudson/matrix/MatrixBuild.java b/core/src/main/java/hudson/matrix/MatrixBuild.java index 27376ec61451..60f867597549 100644 --- a/core/src/main/java/hudson/matrix/MatrixBuild.java +++ b/core/src/main/java/hudson/matrix/MatrixBuild.java @@ -323,17 +323,6 @@ public void post2(BuildListener listener) throws Exception { for (MatrixAggregator a : aggregators) a.endBuild(); } - - @Override - protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws IOException, InterruptedException { - String customWorkspace = getProject().getCustomWorkspace(); - if (customWorkspace != null) { - // we allow custom workspaces to be concurrently used between jobs. - return Lease.createDummyLease(n.getRootPath().child(getEnvironment(listener).expand(customWorkspace))); - } - return super.decideWorkspace(n,wsl); - } - } /** diff --git a/core/src/main/java/hudson/matrix/MatrixProject.java b/core/src/main/java/hudson/matrix/MatrixProject.java index 7735423a011d..859b4ba4fea1 100644 --- a/core/src/main/java/hudson/matrix/MatrixProject.java +++ b/core/src/main/java/hudson/matrix/MatrixProject.java @@ -143,11 +143,6 @@ public class MatrixProject extends AbstractProject im */ private Result touchStoneResultCondition; - /** - * See {@link #setCustomWorkspace(String)}. - */ - private String customWorkspace; - public MatrixProject(String name) { this(Hudson.getInstance(), name); } @@ -229,28 +224,6 @@ public void setTouchStoneResultCondition(Result touchStoneResultCondition) { this.touchStoneResultCondition = touchStoneResultCondition; } - public String getCustomWorkspace() { - return customWorkspace; - } - - /** - * User-specified workspace directory, or null if it's up to Hudson. - * - *

- * Normally a matrix project uses the workspace location assigned by its parent container, - * but sometimes people have builds that have hard-coded paths. - * - *

- * This is not {@link File} because it may have to hold a path representation on another OS. - * - *

- * If this path is relative, it's resolved against {@link Node#getRootPath()} on the node where this workspace - * is prepared. - */ - public void setCustomWorkspace(String customWorkspace) throws IOException { - this.customWorkspace= customWorkspace; - } - @Override protected List createTransientActions() { List r = super.createTransientActions(); @@ -594,12 +567,6 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio this.touchStoneCombinationFilter = null; } - if(req.hasParameter("customWorkspace")) { - customWorkspace = req.getParameter("customWorkspace.directory"); - } else { - customWorkspace = null; - } - // parse system axes DescribableList newAxes = new DescribableList(this); newAxes.rebuildHetero(req, json, Axis.all(),"axis"); diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index 9f0171e34704..0c00c5d23ca3 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -394,6 +394,11 @@ protected final Node getCurrentNode() { * Passed in for the convenience. The returned path must be registered to this object. */ protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { + String customWorkspace = getProject().getCustomWorkspace(); + if (customWorkspace != null) { + // we allow custom workspaces to be concurrently used between jobs. + return Lease.createDummyLease(n.getRootPath().child(getEnvironment(listener).expand(customWorkspace))); + } // TODO: this cast is indicative of abstraction problem return wsl.allocate(n.getWorkspaceFor((TopLevelItem)getProject())); } diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index a5e1a3f889cf..96bd82723635 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -219,6 +219,13 @@ public abstract class AbstractProject

,R extends A private boolean concurrentBuild; + /** + * See {@link #setCustomWorkspace(String)}. + * + * @since xxx + */ + private String customWorkspace; + protected AbstractProject(ItemGroup parent, String name) { super(parent,name); @@ -1629,6 +1636,12 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio blockBuildWhenDownstreamBuilding = req.getParameter("blockBuildWhenDownstreamBuilding")!=null; blockBuildWhenUpstreamBuilding = req.getParameter("blockBuildWhenUpstreamBuilding")!=null; + if(req.hasParameter("customWorkspace")) { + customWorkspace = req.getParameter("customWorkspace.directory"); + } else { + customWorkspace = null; + } + if(req.getParameter("hasSlaveAffinity")!=null) { assignedNode = Util.fixEmptyAndTrim(req.getParameter("_.assignedLabelString")); } else { @@ -1942,4 +1955,29 @@ public static AbstractProject resolveForCLI( throw new CmdLineException(null,Messages.AbstractItem_NoSuchJobExists(name,AbstractProject.findNearest(name).getFullName())); return item; } + + public String getCustomWorkspace() { + return customWorkspace; + } + + /** + * User-specified workspace directory, or null if it's up to Jenkins. + * + *

+ * Normally a project uses the workspace location assigned by its parent container, + * but sometimes people have builds that have hard-coded paths. + * + *

+ * This is not {@link File} because it may have to hold a path representation on another OS. + * + *

+ * If this path is relative, it's resolved against {@link Node#getRootPath()} on the node where this workspace + * is prepared. + * + * @since XXX + */ + public void setCustomWorkspace(String customWorkspace) throws IOException { + this.customWorkspace= customWorkspace; + save(); + } } diff --git a/core/src/main/java/hudson/model/FreeStyleBuild.java b/core/src/main/java/hudson/model/FreeStyleBuild.java index fdec9c0b15c3..896274add934 100644 --- a/core/src/main/java/hudson/model/FreeStyleBuild.java +++ b/core/src/main/java/hudson/model/FreeStyleBuild.java @@ -45,15 +45,4 @@ public FreeStyleBuild(FreeStyleProject project, File buildDir) throws IOExceptio public void run() { run(new RunnerImpl()); } - - protected class RunnerImpl extends Build.RunnerImpl { - @Override - protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws IOException, InterruptedException { - String customWorkspace = getProject().getCustomWorkspace(); - if (customWorkspace != null) - // we allow custom workspaces to be concurrently used between jobs. - return Lease.createDummyLease(n.getRootPath().child(getEnvironment(listener).expand(customWorkspace))); - return super.decideWorkspace(n,wsl); - } - } } diff --git a/core/src/main/java/hudson/model/FreeStyleProject.java b/core/src/main/java/hudson/model/FreeStyleProject.java index e6c08b069daa..76c4f527f8e0 100644 --- a/core/src/main/java/hudson/model/FreeStyleProject.java +++ b/core/src/main/java/hudson/model/FreeStyleProject.java @@ -39,12 +39,6 @@ * @author Kohsuke Kawaguchi */ public class FreeStyleProject extends Project implements TopLevelItem { - /** - * See {@link #setCustomWorkspace(String)}. - * - * @since 1.216 - */ - private String customWorkspace; /** * @deprecated as of 1.390 @@ -62,43 +56,6 @@ protected Class getBuildClass() { return FreeStyleBuild.class; } - public String getCustomWorkspace() { - return customWorkspace; - } - - /** - * User-specified workspace directory, or null if it's up to Hudson. - * - *

- * Normally a free-style project uses the workspace location assigned by its parent container, - * but sometimes people have builds that have hard-coded paths (which can be only built in - * certain locations. see http://www.nabble.com/Customize-Workspace-directory-tt17194310.html for - * one such discussion.) - * - *

- * This is not {@link File} because it may have to hold a path representation on another OS. - * - *

- * If this path is relative, it's resolved against {@link Node#getRootPath()} on the node where this workspace - * is prepared. - * - * @since 1.320 - */ - public void setCustomWorkspace(String customWorkspace) throws IOException { - this.customWorkspace= customWorkspace; - 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; - - super.submit(req, rsp); - } - public DescriptorImpl getDescriptor() { return DESCRIPTOR; } diff --git a/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries.jelly b/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries.jelly index ae31a6f3c204..f862a217666a 100644 --- a/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries.jelly +++ b/maven-plugin/src/main/resources/hudson/maven/MavenModuleSet/configure-entries.jelly @@ -92,7 +92,8 @@ THE SOFTWARE. + checked="${it.isProcessPlugins()}" /> + @@ -114,4 +115,4 @@ THE SOFTWARE. - \ No newline at end of file + diff --git a/war/src/main/webapp/help/project-config/custom-workspace.html b/war/src/main/webapp/help/project-config/custom-workspace.html index d2664a5a65fa..1587ac510eb8 100644 --- a/war/src/main/webapp/help/project-config/custom-workspace.html +++ b/war/src/main/webapp/help/project-config/custom-workspace.html @@ -6,11 +6,10 @@

Once such situation is where paths are hard-coded and the code needs to be built on a specific location. - (and you can find one such discussion here.) While there's no doubt that such a build is not ideal, this option allows you to get going in such a situation.

- Another situation where this is useful is when you are using the free-style project type not to perform + Another situation where this is useful is when you are using the project type not to perform a software build, but execution of a certain batch task, perhaps as a cron replacement. In such case, you can use this option to map the relevant directory as the workspace, so that people can look at files through the Jenkins web UI, and you can kick relevant commands more easily. diff --git a/war/src/main/webapp/help/project-config/custom-workspace_de.html b/war/src/main/webapp/help/project-config/custom-workspace_de.html index 5ee073bb3fbb..52eca21a786f 100644 --- a/war/src/main/webapp/help/project-config/custom-workspace_de.html +++ b/war/src/main/webapp/help/project-config/custom-workspace_de.html @@ -7,12 +7,11 @@

In einer solchen Situation verwenden Sie beispielsweise "festverdrahtete" Dateipfade und - der Code muß daher an einer bestimmten Stelle im Dateisystem gebaut werden - (mehr dazu). + der Code muß daher an einer bestimmten Stelle im Dateisystem gebaut werden. Zweifellos ist dies kein Idealfall eines Builds, aber diese Option erlaubt es Ihnen, auch in einer solchen Situation weiterzukommmen.

- In einer anderen Situation verwenden Sie ein "Free-Style"-Projekt nicht um einen + In einer anderen Situation verwenden Sie ein Projekt nicht um einen Software-Build auszuführen, sondern um eine Batch-Aufgabe auszuführen, z.B. als Cron-Ersatz. In diesem Fall können Sie diese Option verwenden, um ein relevantes Verzeichnis als Arbeitsverzeichnis einzustellen, so daß Anwender Dateien in diesem Verzeichnis über diff --git a/war/src/main/webapp/help/project-config/custom-workspace_fr.html b/war/src/main/webapp/help/project-config/custom-workspace_fr.html index 005287db4736..f8617263d8ef 100644 --- a/war/src/main/webapp/help/project-config/custom-workspace_fr.html +++ b/war/src/main/webapp/help/project-config/custom-workspace_fr.html @@ -7,8 +7,7 @@

Un exemple d'une telle situation est quand les chemins sont codés en dur et que le code a besoin - d'être construit à partir d'un emplacement spécifique (voir la discussion - ici). + d'être construit à partir d'un emplacement spécifique. Il est certain qu'une telle configuration de build est déconseillée, mais cette option vous permet néanmoins d'avencer dans ces circonstances. diff --git a/war/src/main/webapp/help/project-config/custom-workspace_tr.html b/war/src/main/webapp/help/project-config/custom-workspace_tr.html index 27b7783b7adb..e3476f1d70b6 100644 --- a/war/src/main/webapp/help/project-config/custom-workspace_tr.html +++ b/war/src/main/webapp/help/project-config/custom-workspace_tr.html @@ -6,11 +6,10 @@

Once such situation is where paths are hard-coded and the code needs to be built on a specific location. - (and you can find one such discussion here.) While there's no doubt that such a build is not ideal, this option allows you to get going in such a situation.

- Another situation where this is useful is when you are using the free-style project type not to perform + Another situation where this is useful is when you are using the project type not to perform a software build, but execution of a certain batch task, perhaps as a cron replacement. In such case, you can use this option to map the relevant directory as the workspace, so that people can look at files through the Jenkins web UI, and you can kick relevant commands more easily.