diff --git a/core/src/main/java/hudson/tools/AbstractCommandInstaller.java b/core/src/main/java/hudson/tools/AbstractCommandInstaller.java new file mode 100644 index 0000000000000000000000000000000000000000..24d54b4073eef1867b17e4f06d549f47da80049d --- /dev/null +++ b/core/src/main/java/hudson/tools/AbstractCommandInstaller.java @@ -0,0 +1,119 @@ +/* + * The MIT License + * + * Copyright 2009-2014 Sun Microsystems and contributors + * + * 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 hudson.tools; + +import hudson.FilePath; +import hudson.model.Node; +import hudson.model.TaskListener; +import hudson.util.FormValidation; +import java.io.IOException; +import org.kohsuke.stapler.QueryParameter; + +/** + * A generic script-based installer. + * @since TODO: define a version + * @see BatchCommandInstaller + * @see CommandInstaller + * @author Oleg Nenashev + * + */ +public abstract class AbstractCommandInstaller extends ToolInstaller { + + /** + * Command to execute, similar to {@link CommandInterpreter#command}. + */ + private final String command; + private final String toolHome; + + public AbstractCommandInstaller(String label, String command, String toolHome) { + super(label); + this.command = fixCrLf(command); + this.toolHome = toolHome; + } + + public String getCommand() { + return command; + } + + public String getToolHome() { + return toolHome; + } + + public abstract String getCommandFileExtension(); + + /** + * Retrieves a call for remote script caller. + */ + public abstract String[] getCommandCall(FilePath script); + + @Override + public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { + FilePath dir = preferredLocation(tool, node); + // XXX support Windows batch scripts, Unix scripts with interpreter line, etc. (see CommandInterpreter subclasses) + FilePath script = dir.createTextTempFile("hudson", getCommandFileExtension(), command); + try { + String cmd[] = getCommandCall(script); + int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(dir).join(); + if (r != 0) { + throw new IOException("Command returned status " + r); + } + } finally { + script.delete(); + } + return dir.child(getToolHome()); + } + + /** + * Fix CR/LF and always make it Unix style. + */ + //TODO: replace by a Windows style + private static String fixCrLf(String s) { + // eliminate CR + int idx; + while ((idx = s.indexOf("\r\n")) != -1) { + s = s.substring(0, idx) + s.substring(idx + 1); + } + return s; + } + + public static abstract class Descriptor + extends ToolInstallerDescriptor { + + public FormValidation doCheckCommand(@QueryParameter String value) { + if (value.length() > 0) { + return FormValidation.ok(); + } else { + return FormValidation.error(Messages.CommandInstaller_no_command()); + } + } + + public FormValidation doCheckToolHome(@QueryParameter String value) { + if (value.length() > 0) { + return FormValidation.ok(); + } else { + return FormValidation.error(Messages.CommandInstaller_no_command()); + } + } + } +} diff --git a/core/src/main/java/hudson/tools/BatchCommandInstaller.java b/core/src/main/java/hudson/tools/BatchCommandInstaller.java new file mode 100644 index 0000000000000000000000000000000000000000..415dbb700f08442979fefbf6ecbd2f2dc88d73ad --- /dev/null +++ b/core/src/main/java/hudson/tools/BatchCommandInstaller.java @@ -0,0 +1,62 @@ +/* + * The MIT License + * + * Copyright (c) 2013, Oleg Nenashev + * + * 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 hudson.tools; + +import hudson.Extension; +import hudson.FilePath; +import org.kohsuke.stapler.DataBoundConstructor; + +/** + * Installs tool via script execution of Batch script. + * Inspired by "Command installer" from the Jenkins core. + * @since 0.1 + */ +public class BatchCommandInstaller extends AbstractCommandInstaller { + + @DataBoundConstructor + public BatchCommandInstaller(String label, String command, String toolHome) { + super(label, command, toolHome); + } + + @Override + public String getCommandFileExtension() { + return ".bat"; + } + + @Override + public String[] getCommandCall(FilePath script) { + String[] cmd = {"cmd", "/c", "call", script.getRemote()}; + return cmd; + } + + @Extension + public static class DescriptorImpl extends Descriptor { + + @Override + public String getDisplayName() { + return Messages.BatchCommandInstaller_DescriptorImpl_displayName(); + } + } +} diff --git a/core/src/main/java/hudson/tools/CommandInstaller.java b/core/src/main/java/hudson/tools/CommandInstaller.java index bbcc18d6bb59e7257f02a70b8e8f415f993bd779..b02137f0f5d08785f7a819a99054aec7c4374059 100644 --- a/core/src/main/java/hudson/tools/CommandInstaller.java +++ b/core/src/main/java/hudson/tools/CommandInstaller.java @@ -26,95 +26,36 @@ package hudson.tools; import hudson.Extension; import hudson.FilePath; -import hudson.model.Node; -import hudson.model.TaskListener; -import hudson.tasks.CommandInterpreter; -import hudson.util.FormValidation; -import java.io.IOException; import org.kohsuke.stapler.DataBoundConstructor; -import org.kohsuke.stapler.QueryParameter; /** * Installs a tool by running an arbitrary shell command. * @since 1.305 */ -public class CommandInstaller extends ToolInstaller { - - /** - * Command to execute, similar to {@link CommandInterpreter#command}. - */ - private final String command; - - /** - * Resulting tool home directory. - */ - private final String toolHome; +public class CommandInstaller extends AbstractCommandInstaller { @DataBoundConstructor public CommandInstaller(String label, String command, String toolHome) { - super(label); - this.command = fixCrLf(command); - this.toolHome = toolHome; - } - - /** - * Fix CR/LF and always make it Unix style. - */ - private static String fixCrLf(String s) { - // eliminate CR - int idx; - while((idx=s.indexOf("\r\n"))!=-1) - s = s.substring(0,idx)+s.substring(idx+1); - return s; - } - - public String getCommand() { - return command; + super(label, command, toolHome); } - public String getToolHome() { - return toolHome; + @Override + public String getCommandFileExtension() { + return ".sh"; } - public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { - FilePath dir = preferredLocation(tool, node); - // TODO support Windows batch scripts, Unix scripts with interpreter line, etc. (see CommandInterpreter subclasses) - FilePath script = dir.createTextTempFile("hudson", ".sh", command); - try { - String[] cmd = {"sh", "-e", script.getRemote()}; - int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(dir).join(); - if (r != 0) { - throw new IOException("Command returned status " + r); - } - } finally { - script.delete(); - } - return dir.child(toolHome); + @Override + public String[] getCommandCall(FilePath script) { + String[] cmd = {"sh", "-e", script.getRemote()}; + return cmd; } @Extension - public static class DescriptorImpl extends ToolInstallerDescriptor { + public static class DescriptorImpl extends Descriptor { + @Override public String getDisplayName() { return Messages.CommandInstaller_DescriptorImpl_displayName(); } - - public FormValidation doCheckCommand(@QueryParameter String value) { - if (value.length() > 0) { - return FormValidation.ok(); - } else { - return FormValidation.error(Messages.CommandInstaller_no_command()); - } - } - - public FormValidation doCheckToolHome(@QueryParameter String value) { - if (value.length() > 0) { - return FormValidation.ok(); - } else { - return FormValidation.error(Messages.CommandInstaller_no_toolHome()); - } - } - } - } diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/config.jelly b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/config.jelly similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/config.jelly rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/config.jelly diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/config_da.properties b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_da.properties similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/config_da.properties rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_da.properties diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/config_de.properties b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_de.properties similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/config_de.properties rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_de.properties diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/config_es.properties b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_es.properties similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/config_es.properties rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_es.properties diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/config_fr.properties b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_fr.properties similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/config_fr.properties rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_fr.properties diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/config_ja.properties b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_ja.properties similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/config_ja.properties rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_ja.properties diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/config_nl.properties b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_nl.properties similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/config_nl.properties rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_nl.properties diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/config_pt_BR.properties b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_pt_BR.properties similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/config_pt_BR.properties rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_pt_BR.properties diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/config_ru.properties b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_ru.properties similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/config_ru.properties rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_ru.properties diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/config_zh_CN.properties b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_zh_CN.properties similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/config_zh_CN.properties rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_zh_CN.properties diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/config_zh_TW.properties b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_zh_TW.properties similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/config_zh_TW.properties rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/config_zh_TW.properties diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help-command.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-command.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help-command.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-command.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help-command_de.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-command_de.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help-command_de.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-command_de.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help-command_ja.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-command_ja.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help-command_ja.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-command_ja.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help-command_zh_CN.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-command_zh_CN.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help-command_zh_CN.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-command_zh_CN.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help-command_zh_TW.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-command_zh_TW.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help-command_zh_TW.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-command_zh_TW.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help-toolHome.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-toolHome.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help-toolHome.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-toolHome.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help-toolHome_de.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-toolHome_de.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help-toolHome_de.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-toolHome_de.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help-toolHome_zh_CN.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-toolHome_zh_CN.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help-toolHome_zh_CN.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-toolHome_zh_CN.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help-toolHome_zh_TW.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-toolHome_zh_TW.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help-toolHome_zh_TW.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help-toolHome_zh_TW.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help_de.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help_de.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help_de.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help_de.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help_ja.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help_ja.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help_ja.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help_ja.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help_zh_CN.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help_zh_CN.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help_zh_CN.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help_zh_CN.html diff --git a/core/src/main/resources/hudson/tools/CommandInstaller/help_zh_TW.html b/core/src/main/resources/hudson/tools/AbstractCommandInstaller/help_zh_TW.html similarity index 100% rename from core/src/main/resources/hudson/tools/CommandInstaller/help_zh_TW.html rename to core/src/main/resources/hudson/tools/AbstractCommandInstaller/help_zh_TW.html diff --git a/core/src/main/resources/hudson/tools/Messages.properties b/core/src/main/resources/hudson/tools/Messages.properties index 7cfad94889e2ee0a412b39b5e7f2c76f1434ff5a..a00ad9a24c00733783d72181385cc0f4b48157f3 100644 --- a/core/src/main/resources/hudson/tools/Messages.properties +++ b/core/src/main/resources/hudson/tools/Messages.properties @@ -21,9 +21,10 @@ # THE SOFTWARE. ToolLocationNodeProperty.displayName=Tool Locations -CommandInstaller.DescriptorImpl.displayName=Run Command +CommandInstaller.DescriptorImpl.displayName=Run Shell Command CommandInstaller.no_command=Must provide a command to run. CommandInstaller.no_toolHome=Must provide a tool home directory. +BatchCommandInstaller.DescriptorImpl.displayName=Run Batch Command JDKInstaller.FailedToInstallJDK=Failed to install JDK. Exit code={0} JDKInstaller.RequireOracleAccount=Installing JDK requires Oracle account. Please enter your username/password JDKInstaller.UnableToInstallUntilLicenseAccepted=Unable to auto-install JDK until the license is accepted.