public boolean installLauncherJar()

in src/main/java/org/apache/sling/launchpad/base/shared/Loader.java [163:218]


    public boolean installLauncherJar(URL launcherJar) throws IOException {
        info("Checking launcher JAR in folder " + launchpadHome);
        final File currentLauncherJarFile = getLauncherJarFile();

        // Copy the new launcher jar to a temporary file, and
        // extract bundle version info
        final URLConnection launcherJarConn = launcherJar.openConnection();
        launcherJarConn.setUseCaches(false);
        final File tmp = new File(launchpadHome, "Loader_tmp_" + System.currentTimeMillis() + SharedConstants.LAUNCHER_JAR_REL_PATH);
        spool(launcherJarConn.getInputStream(), tmp);
        final FileBundleVersionInfo newVi = new FileBundleVersionInfo(tmp);
        boolean installNewLauncher = true;

        try {
            if(!newVi.isBundle()) {
                throw new IOException("New launcher jar is not a bundle, cannot get version info:" + launcherJar);
            }

            // Compare versions to decide whether to use the existing or new launcher jar
            if (currentLauncherJarFile.exists()) {
                final FileBundleVersionInfo currentVi = new FileBundleVersionInfo(currentLauncherJarFile);
                if(!currentVi.isBundle()) {
                    throw new IOException("Existing launcher jar is not a bundle, cannot get version info:"
                            + currentLauncherJarFile.getAbsolutePath());
                }

                String info = null;
                if(currentVi.compareTo(newVi) == 0) {
                    info = "up to date";
                    installNewLauncher = false;
                } else if(currentVi.compareTo(newVi) > 0) {
                    info = "more recent than ours";
                    installNewLauncher = false;
                }

                if(info != null) {
                    info("Existing launcher is " + info + ", using it: "
                            + getBundleInfo(currentVi) + " (" + currentLauncherJarFile.getName() + ")");
                }
            }

            if(installNewLauncher) {
                final File f = new File(tmp.getParentFile(), SharedConstants.LAUNCHER_JAR_REL_PATH + "." + System.currentTimeMillis());
                if(!tmp.renameTo(f)) {
                    throw new IOException("Failed to rename " + tmp.getName() + " to " + f.getName());
                }
                info("Installing new launcher: " + launcherJar  + ", " + getBundleInfo(newVi) + " (" + f.getName() + ")");
            }
        } finally {
            if(tmp.exists()) {
                tmp.delete();
            }
        }

        return installNewLauncher;
    }