From 60d5f78fc9860c8b668ea20f20b1988594c33cf6 Mon Sep 17 00:00:00 2001 From: Jacob Gardner Date: Wed, 4 Sep 2013 13:36:46 -0500 Subject: [PATCH 1/2] Add parameterless rebuild option for projects. --- .../sonyericsson/rebuild/RebuildAction.java | 24 ++++++- .../sonyericsson/rebuild/RebuildSettings.java | 69 +++++++++++++++++++ .../rebuild/RebuildSettings/config.jelly | 34 +++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/sonyericsson/rebuild/RebuildSettings.java create mode 100644 src/main/resources/com/sonyericsson/rebuild/RebuildSettings/config.jelly diff --git a/src/main/java/com/sonyericsson/rebuild/RebuildAction.java b/src/main/java/com/sonyericsson/rebuild/RebuildAction.java index 3f89b99..06a6de8 100644 --- a/src/main/java/com/sonyericsson/rebuild/RebuildAction.java +++ b/src/main/java/com/sonyericsson/rebuild/RebuildAction.java @@ -181,13 +181,35 @@ public void doIndex(StaplerRequest request, StaplerResponse response) throws if (currentBuild != null) { ParametersAction paramAction = currentBuild.getAction(ParametersAction.class); if (paramAction != null) { - response.sendRedirect(PARAMETERIZED_URL); + RebuildSettings settings = (RebuildSettings)getProject().getProperty(RebuildSettings.class); + + if(settings.getAuto_rebuild()) { + parameterizedRebuild(currentBuild, response); + } else { + response.sendRedirect(PARAMETERIZED_URL); + } } else { nonParameterizedRebuild(currentBuild, response); } } } + public void parameterizedRebuild(AbstractBuild currentBuild, StaplerResponse response) throws IOException { + AbstractProject project = getProject(); + if (project == null) { + return; + } + project.checkPermission(AbstractProject.BUILD); + if (isRebuildAvailable()) { + + List actions = copyBuildCausesAndAddUserCause(currentBuild); + ParametersAction action = currentBuild.getAction(ParametersAction.class); + actions.add(action); + + Hudson.getInstance().getQueue().schedule(build.getProject(), 0, actions); + response.sendRedirect("../../"); + } + } /** * Call this method while rebuilding * non parameterized build. . diff --git a/src/main/java/com/sonyericsson/rebuild/RebuildSettings.java b/src/main/java/com/sonyericsson/rebuild/RebuildSettings.java new file mode 100644 index 0000000..888476d --- /dev/null +++ b/src/main/java/com/sonyericsson/rebuild/RebuildSettings.java @@ -0,0 +1,69 @@ +/* + * The MIT License + * + * Copyright 2013 gardnerj. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.sonyericsson.rebuild; + +import hudson.Extension; +import hudson.model.Job; +import hudson.model.JobProperty; +import hudson.model.JobPropertyDescriptor; +import net.sf.json.JSONObject; +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.StaplerRequest; + +/** + * + * @author gardnerj + */ +public class RebuildSettings extends JobProperty> { + + public boolean auto_rebuild; + + @DataBoundConstructor + public RebuildSettings(boolean auto_rebuild) { + this.auto_rebuild = auto_rebuild; + } + + public boolean getAuto_rebuild() { + return auto_rebuild; + } + + @Extension + public final static class DescriptorImpl extends JobPropertyDescriptor { + @Override + public String getDisplayName() { + return "Rebuild Settings"; + } + + @Override + public boolean isApplicable(Class jobType) { + return true; + } + + @Override + public JobProperty newInstance(StaplerRequest req, JSONObject formdata ) { + RebuildSettings prop = req.bindJSON(RebuildSettings.class, formdata); + return prop; + } + } +} diff --git a/src/main/resources/com/sonyericsson/rebuild/RebuildSettings/config.jelly b/src/main/resources/com/sonyericsson/rebuild/RebuildSettings/config.jelly new file mode 100644 index 0000000..04f1846 --- /dev/null +++ b/src/main/resources/com/sonyericsson/rebuild/RebuildSettings/config.jelly @@ -0,0 +1,34 @@ + + + + + + + + + + + + From 1e798a286dd8e5bb8f72638052931f35b09c9647 Mon Sep 17 00:00:00 2001 From: Jacob Gardner Date: Wed, 4 Sep 2013 14:13:44 -0500 Subject: [PATCH 2/2] Fix null-pointer exception. --- src/main/java/com/sonyericsson/rebuild/RebuildAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonyericsson/rebuild/RebuildAction.java b/src/main/java/com/sonyericsson/rebuild/RebuildAction.java index 06a6de8..503589c 100644 --- a/src/main/java/com/sonyericsson/rebuild/RebuildAction.java +++ b/src/main/java/com/sonyericsson/rebuild/RebuildAction.java @@ -183,7 +183,7 @@ public void doIndex(StaplerRequest request, StaplerResponse response) throws if (paramAction != null) { RebuildSettings settings = (RebuildSettings)getProject().getProperty(RebuildSettings.class); - if(settings.getAuto_rebuild()) { + if(settings != null && settings.getAuto_rebuild()) { parameterizedRebuild(currentBuild, response); } else { response.sendRedirect(PARAMETERIZED_URL);