From 219a4cb1578ea955d87eb5e45896ea53db4debf2 Mon Sep 17 00:00:00 2001 From: Vojtech Juranek Date: Thu, 2 Jun 2011 15:59:45 +0200 Subject: [PATCH 1/2] Possible fix for JENKINS-9806, fix empty customWorkspace -if empry, replace it by null (i.e. no custom workspace) --- .../java/hudson/model/AbstractProject.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index cf01c0e9ea27..5845900e6252 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -1655,7 +1655,7 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio blockBuildWhenUpstreamBuilding = req.getParameter("blockBuildWhenUpstreamBuilding")!=null; if(req.hasParameter("customWorkspace")) { - customWorkspace = req.getParameter("customWorkspace.directory"); + customWorkspace = fixEmpty(req.getParameter("customWorkspace.directory")); } else { customWorkspace = null; } @@ -1995,7 +1995,23 @@ public String getCustomWorkspace() { * @since 1.410 */ public void setCustomWorkspace(String customWorkspace) throws IOException { - this.customWorkspace= customWorkspace; + this.customWorkspace= fixEmpty(customWorkspace); save(); } + + /** + * Replace customWorkspace by null if customWorkspace is empty string. This should prevent user to + * delete JENKIS_HOME accidentally, see JENKINS-9806 for details. If user wants to set up + * JENKINS_HOME as a workspace for some reason, he can use "." to do so. + * + * @param customWorkspace + * @return customWorkspace if it's not empty string, null otherwise + */ + private String fixEmpty(String customWorkspace){ + if(customWorkspace!=null && customWorkspace.trim().equals("")){ + return null; + } + return customWorkspace; + } + } From 19bf3661b7784e9908df041a475864908373f05b Mon Sep 17 00:00:00 2001 From: Vojtech Juranek Date: Sun, 5 Jun 2011 19:11:27 +0200 Subject: [PATCH 2/2] Add warning for user and replaced fixEmpty() by standad Util.fixEmptyAndTrim() --- .../java/hudson/model/AbstractProject.java | 28 ++++++++----------- .../project/config-customWorkspace.jelly | 2 +- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 5845900e6252..a3017411262c 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -1655,7 +1655,9 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio blockBuildWhenUpstreamBuilding = req.getParameter("blockBuildWhenUpstreamBuilding")!=null; if(req.hasParameter("customWorkspace")) { - customWorkspace = fixEmpty(req.getParameter("customWorkspace.directory")); + customWorkspace = Util.fixEmptyAndTrim(req.getParameter("customWorkspace.directory")); + if(customWorkspace==null) + throw new FormException("Custom workspace is empty", "customWorkspace"); } else { customWorkspace = null; } @@ -1860,6 +1862,13 @@ public FormValidation doCheckAssignedLabelString(@QueryParameter String value) { return FormValidation.ok(); } + public FormValidation doCheckCustomWorkspace(@QueryParameter String customWorkspace){ + if(Util.fixEmptyAndTrim(customWorkspace)==null) + return FormValidation.error("Custom workspace is empty"); + else + return FormValidation.ok(); + } + public AutoCompletionCandidates doAutoCompleteUpstreamProjects(@QueryParameter String value) { AutoCompletionCandidates candidates = new AutoCompletionCandidates(); List jobs = Hudson.getInstance().getItems(Job.class); @@ -1995,23 +2004,8 @@ public String getCustomWorkspace() { * @since 1.410 */ public void setCustomWorkspace(String customWorkspace) throws IOException { - this.customWorkspace= fixEmpty(customWorkspace); + this.customWorkspace= Util.fixEmptyAndTrim(customWorkspace); save(); } - /** - * Replace customWorkspace by null if customWorkspace is empty string. This should prevent user to - * delete JENKIS_HOME accidentally, see JENKINS-9806 for details. If user wants to set up - * JENKINS_HOME as a workspace for some reason, he can use "." to do so. - * - * @param customWorkspace - * @return customWorkspace if it's not empty string, null otherwise - */ - private String fixEmpty(String customWorkspace){ - if(customWorkspace!=null && customWorkspace.trim().equals("")){ - return null; - } - return customWorkspace; - } - } diff --git a/core/src/main/resources/lib/hudson/project/config-customWorkspace.jelly b/core/src/main/resources/lib/hudson/project/config-customWorkspace.jelly index e60a9d83e750..ab4e1cb19eb2 100644 --- a/core/src/main/resources/lib/hudson/project/config-customWorkspace.jelly +++ b/core/src/main/resources/lib/hudson/project/config-customWorkspace.jelly @@ -27,7 +27,7 @@ THE SOFTWARE. - +