JDKInstaller.java 23.9 KB
Newer Older
K
kohsuke 已提交
1 2 3
/*
 * The MIT License
 *
4
 * Copyright (c) 2009-2010, Sun Microsystems, Inc.
K
kohsuke 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * 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.AbortException;
import hudson.Extension;
import hudson.FilePath;
29
import hudson.ProxyConfiguration;
K
kohsuke 已提交
30
import hudson.Util;
31
import hudson.Launcher;
32
import jenkins.model.Jenkins;
K
kohsuke 已提交
33 34
import hudson.util.FormValidation;
import hudson.util.ArgumentListBuilder;
35
import hudson.util.IOException2;
K
kohsuke 已提交
36 37 38
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.model.DownloadService.Downloadable;
39
import hudson.model.JDK;
K
kohsuke 已提交
40 41
import static hudson.tools.JDKInstaller.Preference.*;
import hudson.remoting.Callable;
K
kohsuke 已提交
42
import org.jvnet.robust_http_client.RetryableHttpStream;
K
kohsuke 已提交
43 44 45
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.apache.commons.io.IOUtils;
46 47 48 49 50
import org.apache.commons.io.output.NullWriter;
import org.w3c.tidy.Tidy;
import org.dom4j.io.DOMReader;
import org.dom4j.Document;
import org.dom4j.Element;
K
kohsuke 已提交
51 52

import java.io.ByteArrayInputStream;
K
kohsuke 已提交
53 54
import java.io.File;
import java.io.FileOutputStream;
K
kohsuke 已提交
55 56 57 58
import java.io.IOException;
import java.io.PrintStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
59
import java.io.PrintWriter;
60
import java.io.InputStream;
K
kohsuke 已提交
61
import java.net.URL;
62 63
import java.net.HttpURLConnection;
import java.net.URLEncoder;
K
kohsuke 已提交
64 65 66 67
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Arrays;
68
import java.util.Iterator;
K
kohsuke 已提交
69 70 71 72 73 74 75 76 77 78
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.sf.json.JSONObject;

/**
 * Install JDKs from java.sun.com.
 *
 * @author Kohsuke Kawaguchi
79
 * @since 1.305
K
kohsuke 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
 */
public class JDKInstaller extends ToolInstaller {
    /**
     * The release ID that Sun assigns to each JDK, such as "jdk-6u13-oth-JPR@CDS-CDS_Developer"
     *
     * <p>
     * This ID can be seen in the "ProductRef" query parameter of the download page, like
     * https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=jdk-6u13-oth-JPR@CDS-CDS_Developer
     */
    public final String id;

    /**
     * We require that the user accepts the license by clicking a checkbox, to make up for the part
     * that we auto-accept cds.sun.com license click through.
     */
    public final boolean acceptLicense;

    @DataBoundConstructor
    public JDKInstaller(String id, boolean acceptLicense) {
        super(null);
        this.id = id;
        this.acceptLicense = acceptLicense;
    }

    public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
105
        FilePath expectedLocation = preferredLocation(tool, node);
K
kohsuke 已提交
106 107 108
        PrintStream out = log.getLogger();
        try {
            if(!acceptLicense) {
109
                out.println(Messages.JDKInstaller_UnableToInstallUntilLicenseAccepted());
K
kohsuke 已提交
110 111 112 113
                return expectedLocation;
            }
            // already installed?
            FilePath marker = expectedLocation.child(".installedByHudson");
114
            if (marker.exists() && marker.readToString().equals(id)) {
K
kohsuke 已提交
115
                return expectedLocation;
116 117
            }
            expectedLocation.deleteRecursive();
K
kohsuke 已提交
118 119 120 121 122 123
            expectedLocation.mkdirs();

            Platform p = Platform.of(node);
            URL url = locate(log, p, CPU.of(node));

            out.println("Downloading "+url);
124
            FilePath file = expectedLocation.child(p.bundleFileName);
K
kohsuke 已提交
125 126
            file.copyFrom(url);

127 128
            // JDK6u13 on Windows doesn't like path representation like "/tmp/foo", so make it a strict platform native format by doing 'absolutize'
            install(node.createLauncher(log), p, new FilePathFileSystem(node), log, expectedLocation.absolutize().getRemote(), file.getRemote());
K
kohsuke 已提交
129 130 131

            // successfully installed
            file.delete();
132
            marker.write(id, null);
K
kohsuke 已提交
133 134 135 136 137 138 139 140 141

        } catch (DetectionFailedException e) {
            out.println("JDK installation skipped: "+e.getMessage());
        }

        return expectedLocation;
    }

    /**
142 143 144 145 146 147 148 149 150 151 152 153 154 155
     * Performs the JDK installation to a system, provided that the bundle was already downloaded.
     *
     * @param launcher
     *      Used to launch processes on the system.
     * @param p
     *      Platform of the system. This determines how the bundle is installed.
     * @param fs
     *      Abstraction of the file system manipulation on this system.
     * @param log
     *      Where the output from the installation will be written.
     * @param expectedLocation
     *      Path to install JDK to. Must be absolute and in the native file system notation.
     * @param jdkBundle
     *      Path to the installed JDK bundle. (The bundle to download can be determined by {@link #locate(TaskListener, Platform, CPU)} call.)
K
kohsuke 已提交
156
     */
157 158 159 160
    public void install(Launcher launcher, Platform p, FileSystem fs, TaskListener log, String expectedLocation, String jdkBundle) throws IOException, InterruptedException {
        PrintStream out = log.getLogger();

        out.println("Installing "+ jdkBundle);
K
kohsuke 已提交
161 162 163
        switch (p) {
        case LINUX:
        case SOLARIS:
164
            fs.chmod(jdkBundle,0755);
165 166 167 168 169
            int exit = launcher.launch().cmds(jdkBundle, "-noregister")
                    .stdin(new ByteArrayInputStream("yes".getBytes())).stdout(out)
                    .pwd(new FilePath(launcher.getChannel(), expectedLocation)).join();
            if (exit != 0)
                throw new AbortException(Messages.JDKInstaller_FailedToInstallJDK(exit));
170 171 172 173 174 175 176 177 178 179 180 181

            // JDK creates its own sub-directory, so pull them up
            List<String> paths = fs.listSubDirectories(expectedLocation);
            for (Iterator<String> itr = paths.iterator(); itr.hasNext();) {
                String s =  itr.next();
                if (!s.matches("j(2s)?dk.*"))
                    itr.remove();
            }
            if(paths.size()!=1)
                throw new AbortException("Failed to find the extracted JDKs: "+paths);

            // remove the intermediate directory
182
            fs.pullUp(expectedLocation+'/'+paths.get(0),expectedLocation);
183
            break;
K
kohsuke 已提交
184
        case WINDOWS:
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
            /*
                Windows silent installation is full of bad know-how.

                On Windows, command line argument to a process at the OS level is a single string,
                not a string array like POSIX. When we pass arguments as string array, JRE eventually
                turn it into a single string with adding quotes to "the right place". Unfortunately,
                with the strange argument layout of InstallShield (like /v/qn" INSTALLDIR=foobar"),
                it appears that the escaping done by JRE gets in the way, and prevents the installation.
                Presumably because of this, my attempt to use /q/vn" INSTALLDIR=foo" didn't work with JDK5.

                I tried to locate exactly how InstallShield parses the arguments (and why it uses
                awkward option like /qn, but couldn't find any. Instead, experiments revealed that
                "/q/vn ARG ARG ARG" works just as well. This is presumably due to the Visual C++ runtime library
                (which does single string -> string array conversion to invoke the main method in most Win32 process),
                and this consistently worked on JDK5 and JDK4.

                Some of the official documentations are available at
                - http://java.sun.com/j2se/1.5.0/sdksilent.html
                - http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/silent.html
             */
            String logFile = jdkBundle+".install.log";

            ArgumentListBuilder args = new ArgumentListBuilder();
            args.add(jdkBundle);
            args.add("/s");
            // according to http://community.acresso.com/showthread.php?t=83301, \" is the trick to quote values with whitespaces.
            // Oh Windows, oh windows, why do you have to be so difficult?
            args.add("/v/qn REBOOT=Suppress INSTALLDIR=\\\""+ expectedLocation +"\\\" /L \\\""+logFile+"\\\"");

K
kohsuke 已提交
214 215 216 217
            int r = launcher.launch().cmds(args).stdout(out)
                    .pwd(new FilePath(launcher.getChannel(), expectedLocation)).join();
            if (r != 0) {
                out.println(Messages.JDKInstaller_FailedToInstallJDK(r));
218 219 220 221 222 223 224 225 226 227 228 229 230
                // log file is in UTF-16
                InputStreamReader in = new InputStreamReader(fs.read(logFile), "UTF-16");
                try {
                    IOUtils.copy(in,new OutputStreamWriter(out));
                } finally {
                    in.close();
                }
                throw new AbortException();
            }

            fs.delete(logFile);

            break;
K
kohsuke 已提交
231 232 233 234
        }
    }

    /**
235 236
     * Abstraction of the file system to perform JDK installation.
     * Consider {@link FilePathFileSystem} as the canonical documentation of the contract.
K
kohsuke 已提交
237
     */
K
kohsuke 已提交
238
    public interface FileSystem {
239 240 241 242 243 244 245 246 247 248
        void delete(String file) throws IOException, InterruptedException;
        void chmod(String file,int mode) throws IOException, InterruptedException;
        InputStream read(String file) throws IOException;
        /**
         * List sub-directories of the given directory and just return the file name portion.
         */
        List<String> listSubDirectories(String dir) throws IOException, InterruptedException;
        void pullUp(String from, String to) throws IOException, InterruptedException;
    }

249
    /*package*/ static final class FilePathFileSystem implements FileSystem {
250 251
        private final Node node;

252
        FilePathFileSystem(Node node) {
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
            this.node = node;
        }

        public void delete(String file) throws IOException, InterruptedException {
            $(file).delete();
        }

        public void chmod(String file, int mode) throws IOException, InterruptedException {
            $(file).chmod(mode);
        }

        public InputStream read(String file) throws IOException {
            return $(file).read();
        }

        public List<String> listSubDirectories(String dir) throws IOException, InterruptedException {
            List<String> r = new ArrayList<String>();
            for( FilePath f : $(dir).listDirectories())
                r.add(f.getName());
            return r;
        }

        public void pullUp(String from, String to) throws IOException, InterruptedException {
            $(from).moveAllChildrenTo($(to));
        }

        private FilePath $(String file) {
            return node.createPath(file);
K
kohsuke 已提交
281
        }
282
    }
K
kohsuke 已提交
283

K
kohsuke 已提交
284 285 286 287
    /**
     * This is where we locally cache this JDK.
     */
    private File getLocalCacheFile(Platform platform, CPU cpu) {
288
        return new File(Jenkins.getInstance().getRootDir(),"cache/jdks/"+platform+"/"+cpu+"/"+id);
K
kohsuke 已提交
289 290
    }

K
kohsuke 已提交
291 292 293
    /**
     * Performs a license click through and obtains the one-time URL for downloading bits.
     */
294
    public URL locate(TaskListener log, Platform platform, CPU cpu) throws IOException {
K
kohsuke 已提交
295 296 297
        File cache = getLocalCacheFile(platform, cpu);
        if (cache.exists()) return cache.toURL();

298 299
        HttpURLConnection con = locateStage1(platform, cpu);
        String page = IOUtils.toString(con.getInputStream());
K
kohsuke 已提交
300 301 302 303 304 305 306 307
        URL src = locateStage2(log, page);

        // download to a temporary file and rename it in to handle concurrency and failure correctly,
        File tmp = new File(cache.getPath()+".tmp");
        tmp.getParentFile().mkdirs();
        try {
            FileOutputStream out = new FileOutputStream(tmp);
            try {
308 309 310
                IOUtils.copy(new RetryableHttpStream(src) {
                    @Override
                    protected HttpURLConnection connect() throws IOException {
311 312 313
                        HttpURLConnection con = (HttpURLConnection) ProxyConfiguration.open(url);
                        con.setReadTimeout(60*1000);    // don't block forever, but don't let the slow client fail with false positives either
                        return con;
314 315
                    }
                }, out);
K
kohsuke 已提交
316 317 318 319 320 321 322 323 324
            } finally {
                out.close();
            }

            tmp.renameTo(cache);
            return cache.toURL();
        } finally {
            tmp.delete();
        }
325 326
    }

327
    @SuppressWarnings("unchecked") // dom4j doesn't do generics, apparently... should probably switch to XOM
328 329
    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);
330 331 332
        String cookie;
        Element form;
        try {
333
            HttpURLConnection con = (HttpURLConnection) ProxyConfiguration.open(url);
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
            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;
                }
350
            }
351 352
        } catch (IOException e) {
            throw new IOException2("Failed to access "+url,e);
353 354
        }

355 356
        url = new URL(form.attributeValue("action"));
        try {
357
            HttpURLConnection con = (HttpURLConnection) ProxyConfiguration.open(url);
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
            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;
                }
K
kohsuke 已提交
376
            }
377 378
            if(primary==null)   primary=secondary;
            if(primary==null)
K
kohsuke 已提交
379
            throw new AbortException("Couldn't find the right download for "+platform+" and "+ cpu +" combination");
380 381
            os.print(p.attributeValue("name")+'='+primary);
            LOGGER.fine("Platform choice:"+primary);
382

383 384 385 386 387
            // select language
            Element l = (Element)form.selectSingleNode(".//select[@id='dnld_language']");
            if (l != null) {
                os.print("&"+l.attributeValue("name")+"="+l.element("option").attributeValue("value"));
            }
388

389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
            // 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)
                    os.print("on"); // assume this is a checkbox
                else
                    os.print(URLEncoder.encode(value,"UTF-8"));
            }
            os.close();
            return con;
        } catch (IOException e) {
            throw new IOException2("Failed to access "+url,e);
404 405
        }
    }
K
kohsuke 已提交
406

407
    private URL locateStage2(TaskListener log, String page) throws IOException {
408 409 410 411 412
        Pattern HREF = Pattern.compile("<a href=\"(http://cds.sun.com/[^\"]+/VerifyItem-Start[^\"]+)\"");
        Matcher m = HREF.matcher(page);
        // this page contains a missing --> that confuses dom4j/jtidy

        log.getLogger().println("Choosing the download bundle");
K
kohsuke 已提交
413 414 415 416
        List<String> urls = new ArrayList<String>();

        while(m.find()) {
            String url = m.group(1);
417 418
            LOGGER.fine("Considering a download link:"+ url);

K
kohsuke 已提交
419 420 421 422 423 424 425 426
            // still more options to choose from.
            // avoid rpm bundles, and avoid tar.Z bundle
            if(url.contains("rpm"))  continue;
            if(url.contains("tar.Z"))  continue;
            // sparcv9 bundle is add-on to the sparc bundle, so just download 32bit sparc bundle, even on 64bit system
            if(url.contains("sparcv9"))  continue;

            urls.add(url);
427
            LOGGER.fine("Found a download candidate: "+ url);
K
kohsuke 已提交
428 429
        }

430 431 432 433
        if (urls.isEmpty()) {
            throw new IOException("found no matches in: " + page);
        }

K
kohsuke 已提交
434 435 436 437 438 439 440 441 442 443 444 445
        // prefer the first match because sometimes "optional downloads" follow the main bundle
        return new URL(urls.get(0));
    }

    public enum Preference {
        PRIMARY, SECONDARY, UNACCEPTABLE
    }

    /**
     * Supported platform.
     */
    public enum Platform {
446 447 448 449 450 451 452 453 454 455
        LINUX("jdk.sh"), SOLARIS("jdk.sh"), WINDOWS("jdk.exe");

        /**
         * Choose the file name suitable for the downloaded JDK bundle.
         */
        public final String bundleFileName;

        Platform(String bundleFileName) {
            this.bundleFileName = bundleFileName;
        }
K
kohsuke 已提交
456 457 458 459 460 461 462 463 464

        public boolean is(String line) {
            return line.contains(name());
        }

        /**
         * Determines the platform of the given node.
         */
        public static Platform of(Node n) throws IOException,InterruptedException,DetectionFailedException {
K
kohsuke 已提交
465
            return n.getChannel().call(new Callable<Platform,DetectionFailedException>() {
K
kohsuke 已提交
466 467 468 469 470 471 472
                public Platform call() throws DetectionFailedException {
                    return current();
                }
            });
        }

        public static Platform current() throws DetectionFailedException {
473
            String arch = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
K
kohsuke 已提交
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
            if(arch.contains("linux"))  return LINUX;
            if(arch.contains("windows"))   return WINDOWS;
            if(arch.contains("sun") || arch.contains("solaris"))    return SOLARIS;
            throw new DetectionFailedException("Unknown CPU name: "+arch);
        }
    }

    /**
     * CPU type.
     */
    public enum CPU {
        i386, amd64, Sparc, Itanium;

        /**
         * In JDK5u3, I see platform like "Linux AMD64", while JDK6u3 refers to "Linux x64", so
         * just use "64" for locating bits.
         */
        public Preference accept(String line) {
            switch (this) {
            // these two guys are totally incompatible with everything else, so no fallback
            case Sparc:     return must(line.contains("SPARC"));
            case Itanium:   return must(line.contains("ITANIUM"));

            // 64bit Solaris, Linux, and Windows can all run 32bit executable, so fall back to 32bit if 64bit bundle is not found
            case amd64:
                if(line.contains("64"))     return PRIMARY;
                if(line.contains("SPARC") || line.contains("ITANIUM"))  return UNACCEPTABLE;
                return SECONDARY;
            case i386:
                if(line.contains("64") || line.contains("SPARC") || line.contains("ITANIUM"))     return UNACCEPTABLE;
                return PRIMARY;
            }
            return UNACCEPTABLE;
        }

        private static Preference must(boolean b) {
             return b ? PRIMARY : UNACCEPTABLE;
        }

        /**
         * Determines the CPU of the given node.
         */
        public static CPU of(Node n) throws IOException,InterruptedException, DetectionFailedException {
K
kohsuke 已提交
517
            return n.getChannel().call(new Callable<CPU,DetectionFailedException>() {
K
kohsuke 已提交
518 519 520 521 522 523 524 525 526 527 528 529
                public CPU call() throws DetectionFailedException {
                    return current();
                }
            });
        }

        /**
         * Determines the CPU of the current JVM.
         *
         * http://lopica.sourceforge.net/os.html was useful in writing this code.
         */
        public static CPU current() throws DetectionFailedException {
530
            String arch = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
K
kohsuke 已提交
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
            if(arch.contains("sparc"))  return Sparc;
            if(arch.contains("ia64"))   return Itanium;
            if(arch.contains("amd64") || arch.contains("86_64"))    return amd64;
            if(arch.contains("86"))    return i386;
            throw new DetectionFailedException("Unknown CPU architecture: "+arch);
        }
    }

    /**
     * Indicates the failure to detect the OS or CPU.
     */
    private static final class DetectionFailedException extends Exception {
        private DetectionFailedException(String message) {
            super(message);
        }
    }

    public static final class JDKFamilyList {
        public JDKFamily[] jdks = new JDKFamily[0];
    }

    public static final class JDKFamily {
        public String name;
        public InstallableJDK[] list;
    }

    public static final class InstallableJDK {
        public String name;
        /**
         * Product code.
         */
        public String id;
    }

    @Extension
    public static final class DescriptorImpl extends ToolInstallerDescriptor<JDKInstaller> {
        public String getDisplayName() {
S
sogabe 已提交
568
            return Messages.JDKInstaller_DescriptorImpl_displayName();
K
kohsuke 已提交
569 570
        }

571 572 573 574 575
        @Override
        public boolean isApplicable(Class<? extends ToolInstallation> toolType) {
            return toolType==JDK.class;
        }

K
kohsuke 已提交
576 577
        public FormValidation doCheckId(@QueryParameter String value) {
            if (Util.fixEmpty(value) == null) {
S
sogabe 已提交
578
                return FormValidation.error(Messages.JDKInstaller_DescriptorImpl_doCheckId()); // improve message
K
kohsuke 已提交
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
            } else {
                // XXX further checks? 
                return FormValidation.ok();
            }
        }

        /**
         * List of installable JDKs.
         * @return never null.
         */
        public List<JDKFamily> getInstallableJDKs() throws IOException {
            return Arrays.asList(JDKList.all().get(JDKList.class).toList().jdks);
        }

        public FormValidation doCheckAcceptLicense(@QueryParameter boolean value) {
            if (value) {
                return FormValidation.ok();
            } else {
S
sogabe 已提交
597
                return FormValidation.error(Messages.JDKInstaller_DescriptorImpl_doCheckAcceptLicense()); 
K
kohsuke 已提交
598 599 600 601 602 603 604 605 606 607
            }
        }
    }

    /**
     * JDK list.
     */
    @Extension
    public static final class JDKList extends Downloadable {
        public JDKList() {
608
            super(JDKInstaller.class);
K
kohsuke 已提交
609 610 611 612 613 614 615 616 617 618 619
        }

        public JDKFamilyList toList() throws IOException {
            JSONObject d = getData();
            if(d==null) return new JDKFamilyList();
            return (JDKFamilyList)JSONObject.toBean(d,JDKFamilyList.class);
        }
    }

    private static final Logger LOGGER = Logger.getLogger(JDKInstaller.class.getName());
}