1 package hudson.tasks; 2 3 import hudson.FilePath; 4 import hudson.model.Descriptor; 5 import static hudson.model.Hudson.isWindows; 6 import org.kohsuke.stapler.StaplerRequest; 7 8 import java.util.Map ; 9 10 15 public class Shell extends CommandInterpreter { 16 public Shell(String command) { 17 super(fixCrLf(command)); 18 } 19 20 23 private static String fixCrLf(String s) { 24 int idx; 26 while((idx=s.indexOf("\r\n"))!=-1) 27 s = s.substring(0,idx)+s.substring(idx+1); 28 29 return s; 40 } 41 42 protected String [] buildCommandLine(FilePath script) { 43 return new String [] { DESCRIPTOR.getShell(),"-xe",script.getRemote()}; 44 } 45 46 protected String getContents() { 47 return fixCrLf(command); 48 } 49 50 protected String getFileExtension() { 51 return ".sh"; 52 } 53 54 public Descriptor<Builder> getDescriptor() { 55 return DESCRIPTOR; 56 } 57 58 public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl(); 59 60 public static final class DescriptorImpl extends Descriptor<Builder> { 61 64 private String shell; 65 66 private DescriptorImpl() { 67 super(Shell.class); 68 load(); 69 } 70 71 72 protected void convert(Map <String , Object > oldPropertyBag) { 73 shell = (String )oldPropertyBag.get("shell"); 74 } 75 76 public String getShell() { 77 if(shell==null) 78 return isWindows()?"sh":"/bin/sh"; 79 return shell; 80 } 81 82 public void setShell(String shell) { 83 this.shell = shell; 84 save(); 85 } 86 87 public String getHelpFile() { 88 return "/help/project-config/shell.html"; 89 } 90 91 public String getDisplayName() { 92 return "Execute shell"; 93 } 94 95 public Builder newInstance(StaplerRequest req) { 96 return new Shell(req.getParameter("shell")); 97 } 98 99 public boolean configure( StaplerRequest req ) { 100 setShell(req.getParameter("shell")); 101 return true; 102 } 103 } 104 } 105 | Popular Tags |