Search in sources :

Example 36 with AbortException

use of hudson.AbortException in project hudson-2.x by hudson.

the class InstallToolCommand method install.

/**
 * Performs an installation.
 */
private int install(ToolInstallation t, BuildIDs id, AbstractProject p) throws IOException, InterruptedException {
    Run b = p.getBuildByNumber(Integer.parseInt(id.number));
    if (b == null)
        throw new AbortException("No such build: " + id.number);
    Executor exec = b.getExecutor();
    if (exec == null)
        throw new AbortException(b.getFullDisplayName() + " is not building");
    Node node = exec.getOwner().getNode();
    if (t instanceof NodeSpecific) {
        NodeSpecific n = (NodeSpecific) t;
        t = (ToolInstallation) n.forNode(node, new StreamTaskListener(stderr));
    }
    if (t instanceof EnvironmentSpecific) {
        EnvironmentSpecific e = (EnvironmentSpecific) t;
        t = (ToolInstallation) e.forEnvironment(EnvVars.getRemote(channel));
    }
    stdout.println(t.getHome());
    return 0;
}
Also used : Executor(hudson.model.Executor) EnvironmentSpecific(hudson.model.EnvironmentSpecific) StreamTaskListener(hudson.util.StreamTaskListener) Node(hudson.model.Node) NodeSpecific(hudson.slaves.NodeSpecific) Run(hudson.model.Run) AbortException(hudson.AbortException)

Example 37 with AbortException

use of hudson.AbortException in project hudson-2.x by hudson.

the class JDKInstaller method locateStage1.

// dom4j doesn't do generics, apparently... should probably switch to XOM
@SuppressWarnings("unchecked")
private HttpURLConnection locateStage1(Platform platform, CPU cpu) throws IOException {
    URL url = new URL("https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=" + id);
    String cookie;
    Element form;
    try {
        HttpURLConnection con = (HttpURLConnection) ProxyConfiguration.open(url);
        cookie = con.getHeaderField("Set-Cookie");
        LOGGER.fine("Cookie=" + cookie);
        Tidy tidy = new Tidy();
        tidy.setErrout(new PrintWriter(new NullWriter()));
        DOMReader domReader = new DOMReader();
        Document dom = domReader.read(tidy.parseDOM(con.getInputStream(), null));
        form = null;
        for (Element e : (List<Element>) dom.selectNodes("//form")) {
            String action = e.attributeValue("action");
            LOGGER.fine("Found form:" + action);
            if (action.contains("ViewFilteredProducts")) {
                form = e;
                break;
            }
        }
    } catch (IOException e) {
        throw new IOException2("Failed to access " + url, e);
    }
    url = new URL(form.attributeValue("action"));
    try {
        HttpURLConnection con = (HttpURLConnection) ProxyConfiguration.open(url);
        con.setRequestMethod("POST");
        con.setDoOutput(true);
        con.setRequestProperty("Cookie", cookie);
        con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        PrintStream os = new PrintStream(con.getOutputStream());
        // select platform
        String primary = null, secondary = null;
        Element p = (Element) form.selectSingleNode(".//select[@id='dnld_platform']");
        for (Element opt : (List<Element>) p.elements("option")) {
            String value = opt.attributeValue("value");
            String vcap = value.toUpperCase(Locale.ENGLISH);
            if (!platform.is(vcap))
                continue;
            switch(cpu.accept(vcap)) {
                case PRIMARY:
                    primary = value;
                    break;
                case SECONDARY:
                    secondary = value;
                    break;
                case UNACCEPTABLE:
                    break;
            }
        }
        if (primary == null)
            primary = secondary;
        if (primary == null)
            throw new AbortException("Couldn't find the right download for " + platform + " and " + cpu + " combination");
        os.print(p.attributeValue("name") + '=' + primary);
        LOGGER.fine("Platform choice:" + primary);
        // select language
        Element l = (Element) form.selectSingleNode(".//select[@id='dnld_language']");
        if (l != null) {
            os.print("&" + l.attributeValue("name") + "=" + l.element("option").attributeValue("value"));
        }
        // the rest
        for (Element e : (List<Element>) form.selectNodes(".//input")) {
            os.print('&');
            os.print(e.attributeValue("name"));
            os.print('=');
            String value = e.attributeValue("value");
            if (value == null)
                // assume this is a checkbox
                os.print("on");
            else
                os.print(URLEncoder.encode(value, "UTF-8"));
        }
        os.close();
        return con;
    } catch (IOException e) {
        throw new IOException2("Failed to access " + url, e);
    }
}
Also used : PrintStream(java.io.PrintStream) Element(org.dom4j.Element) IOException(java.io.IOException) Document(org.dom4j.Document) Tidy(org.w3c.tidy.Tidy) URL(java.net.URL) NullWriter(org.apache.commons.io.output.NullWriter) DOMReader(org.dom4j.io.DOMReader) HttpURLConnection(java.net.HttpURLConnection) ArrayList(java.util.ArrayList) List(java.util.List) IOException2(hudson.util.IOException2) PrintWriter(java.io.PrintWriter) AbortException(hudson.AbortException)

Aggregations

AbortException (hudson.AbortException)37 IOException (java.io.IOException)13 FilePath (hudson.FilePath)11 EnvVars (hudson.EnvVars)5 ArrayList (java.util.ArrayList)5 Node (hudson.model.Node)4 ArgumentListBuilder (hudson.util.ArgumentListBuilder)4 Launcher (hudson.Launcher)3 Computer (hudson.model.Computer)3 Run (hudson.model.Run)3 WorkspaceList (hudson.slaves.WorkspaceList)3 ServletException (javax.servlet.ServletException)3 StandardCredentials (com.cloudbees.plugins.credentials.common.StandardCredentials)2 AbstractBuild (hudson.model.AbstractBuild)2 ParameterDefinition (hudson.model.ParameterDefinition)2 ParameterValue (hudson.model.ParameterValue)2 PollingResult (hudson.scm.PollingResult)2 SCMRevisionState (hudson.scm.SCMRevisionState)2 File (java.io.File)2 Authentication (org.acegisecurity.Authentication)2