BatchFile.java 2.4 KB
Newer Older
K
kohsuke 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * The MIT License
 * 
 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
 * 
 * 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.
 */
K
kohsuke 已提交
24 25 26
package hudson.tasks;

import hudson.FilePath;
27
import hudson.Extension;
K
kohsuke 已提交
28
import hudson.model.Descriptor;
29
import hudson.model.AbstractProject;
K
kohsuke 已提交
30
import net.sf.json.JSONObject;
K
kohsuke 已提交
31 32 33 34 35 36 37
import org.kohsuke.stapler.StaplerRequest;

/**
 * Executes commands by using Windows batch file.
 *
 * @author Kohsuke Kawaguchi
 */
K
kohsuke 已提交
38
public class BatchFile extends CommandInterpreter {
K
kohsuke 已提交
39
    public BatchFile(String command) {
K
kohsuke 已提交
40
        super(command);
K
kohsuke 已提交
41 42
    }

K
kohsuke 已提交
43 44
    protected String[] buildCommandLine(FilePath script) {
        return new String[] {script.getRemote()};
K
kohsuke 已提交
45 46
    }

K
kohsuke 已提交
47 48 49
    protected String getContents() {
        return command+"\r\nexit %ERRORLEVEL%";
    }
K
kohsuke 已提交
50

K
kohsuke 已提交
51 52
    protected String getFileExtension() {
        return ".bat";
K
kohsuke 已提交
53 54
    }

55
    @Extension
56
    public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
K
kohsuke 已提交
57 58 59 60 61
        public String getHelpFile() {
            return "/help/project-config/batch.html";
        }

        public String getDisplayName() {
K
i18n  
kohsuke 已提交
62
            return Messages.BatchFile_DisplayName();
K
kohsuke 已提交
63 64
        }

K
kohsuke 已提交
65 66
        public Builder newInstance(StaplerRequest req, JSONObject data) {
            return new BatchFile(data.getString("batchFile"));
K
kohsuke 已提交
67
        }
68 69 70 71

        public boolean isApplicable(Class<? extends AbstractProject> jobType) {
            return true;
        }
K
kohsuke 已提交
72 73
    }
}