Search in sources :

Example 1 with OperationInfo

use of org.netbeans.api.autoupdate.OperationContainer.OperationInfo in project netbeans-rcp-lite by outersky.

the class AvailableTableModel method getDownloadSize.

@SuppressWarnings("unchecked")
@Override
public int getDownloadSize() {
    int res = 0;
    assert container != null || containerCustom != null : "OperationContainer found when asking for download size.";
    Set<OperationInfo> infos = new HashSet<OperationInfo>();
    infos.addAll(container.listAll());
    infos.addAll(containerCustom.listAll());
    Set<UpdateElement> elements = new HashSet<UpdateElement>();
    for (OperationInfo info : infos) {
        elements.add(info.getUpdateElement());
        elements.addAll(info.getRequiredElements());
    }
    for (UpdateElement el : elements) {
        res += el.getDownloadSize();
    }
    return res;
}
Also used : OperationInfo(org.netbeans.api.autoupdate.OperationContainer.OperationInfo) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) HashSet(java.util.HashSet)

Example 2 with OperationInfo

use of org.netbeans.api.autoupdate.OperationContainer.OperationInfo in project netbeans-rcp-lite by outersky.

the class InstallSupportImpl method doInstall.

@SuppressWarnings("ThrowableResultIgnored")
public Boolean doInstall(final Installer installer, final ProgressHandle progress, /*or null*/
final boolean forceInstall) throws OperationException {
    assert installer != null;
    Callable<Boolean> installCallable = new Callable<Boolean>() {

        @Override
        @SuppressWarnings("SleepWhileInLoop")
        public Boolean call() throws Exception {
            synchronized (LOCK) {
                assert currentStep != STEP.FINISHED : currentStep + " != STEP.FINISHED";
                if (currentStep == STEP.CANCEL)
                    return false;
                currentStep = STEP.INSTALLATION;
            }
            assert support.getContainer().listInvalid().isEmpty() : support + ".listInvalid().isEmpty() but " + support.getContainer().listInvalid();
            // do trust of so far untrusted certificates
            addTrustedCertificates();
            affectedModuleImpls = new HashSet<ModuleUpdateElementImpl>();
            affectedFeatureImpls = new HashSet<FeatureUpdateElementImpl>();
            if (progress != null)
                progress.start();
            for (OperationInfo info : infos) {
                UpdateElementImpl toUpdateImpl = Trampoline.API.impl(info.getUpdateElement());
                switch(toUpdateImpl.getType()) {
                    case KIT_MODULE:
                    case MODULE:
                        affectedModuleImpls.add((ModuleUpdateElementImpl) toUpdateImpl);
                        break;
                    case STANDALONE_MODULE:
                    case FEATURE:
                        affectedFeatureImpls.add((FeatureUpdateElementImpl) toUpdateImpl);
                        affectedModuleImpls.addAll(((FeatureUpdateElementImpl) toUpdateImpl).getContainedModuleElements());
                        break;
                    default:
                        // XXX: what other types
                        assert false : "Unsupported type " + toUpdateImpl;
                }
            }
            boolean needsRestart = false;
            File targetCluster;
            List<UpdaterInfo> updaterFiles = new ArrayList<UpdaterInfo>();
            for (ModuleUpdateElementImpl moduleImpl : affectedModuleImpls) {
                synchronized (LOCK) {
                    if (currentStep == STEP.CANCEL) {
                        if (progress != null)
                            progress.finish();
                        return false;
                    }
                }
                // skip installed element
                if (Utilities.isElementInstalled(moduleImpl.getUpdateElement())) {
                    continue;
                }
                // find target dir
                UpdateElement installed = moduleImpl.getUpdateUnit().getInstalled();
                targetCluster = getTargetCluster(installed, moduleImpl, isGlobal, useUserdirAsFallback);
                URL source = moduleImpl.getInstallInfo().getDistribution();
                LOG.log(Level.FINE, "Source URL for " + moduleImpl.getCodeName() + " is " + source);
                File dest = getDestination(targetCluster, moduleImpl.getCodeName(), source, 0);
                assert dest != null : "Destination file exists for " + moduleImpl + " in " + targetCluster;
                JarFile jf = new JarFile(dest);
                try {
                    for (JarEntry entry : Collections.list(jf.entries())) {
                        if (ModuleUpdater.AUTOUPDATE_UPDATER_JAR_PATH.equals(entry.toString()) || entry.toString().matches(ModuleUpdater.AUTOUPDATE_UPDATER_JAR_LOCALE_PATTERN)) {
                            LOG.log(Level.INFO, entry.toString() + " is being installed from " + moduleImpl.getCodeName());
                            updaterFiles.add(new UpdaterInfo(entry, dest, targetCluster));
                            needsRestart = true;
                        }
                    }
                } finally {
                    jf.close();
                }
                needsRestart |= needsRestart(installed != null, moduleImpl, dest);
            }
            try {
                // store source of installed files
                Utilities.writeAdditionalInformation(getElement2Clusters());
                for (int i = 0; i < updaterFiles.size(); i++) {
                    UpdaterInfo info = updaterFiles.get(i);
                    try {
                        Utilities.writeUpdateOfUpdaterJar(info.getUpdaterJarEntry(), info.getZipFileWithUpdater(), info.getUpdaterTargetCluster());
                    } catch (IOException ex) {
                        LOG.log(Level.INFO, "Cannot open or close jar file {0}", info.getZipFileWithUpdater());
                    }
                }
                if (!needsRestart || forceInstall) {
                    synchronized (LOCK) {
                        if (currentStep == STEP.CANCEL) {
                            if (progress != null)
                                progress.finish();
                            return false;
                        }
                    }
                    if (progress != null)
                        progress.switchToDeterminate(affectedModuleImpls.size());
                    final Set<File> files;
                    synchronized (downloadedFiles) {
                        files = new HashSet<File>(downloadedFiles);
                    }
                    if (!files.isEmpty()) {
                        try {
                            FileUtil.runAtomicAction(new Runnable() {

                                @Override
                                public void run() {
                                    try {
                                        UpdaterInternal.update(files, new RefreshModulesListener(progress), NbBundle.getBranding());
                                    } catch (InterruptedException ie) {
                                        LOG.log(Level.INFO, ie.getMessage(), ie);
                                    }
                                }
                            });
                            for (ModuleUpdateElementImpl impl : affectedModuleImpls) {
                                int rerunWaitCount = 0;
                                Module module = Utilities.toModule(impl.getCodeName(), impl.getSpecificationVersion());
                                for (; rerunWaitCount < 100 && module == null; rerunWaitCount++) {
                                    LOG.log(Level.FINE, "Waiting for {0}@{1} #{2}", new Object[] { impl.getCodeName(), impl.getSpecificationVersion(), rerunWaitCount });
                                    Thread.sleep(100);
                                    module = Utilities.toModule(impl.getCodeName(), impl.getSpecificationVersion());
                                }
                                if (rerunWaitCount == 100) {
                                    LOG.log(Level.INFO, "Timeout waiting for loading module {0}@{1}", new Object[] { impl.getCodeName(), impl.getSpecificationVersion() });
                                    afterInstall();
                                    synchronized (downloadedFiles) {
                                        downloadedFiles.clear();
                                    }
                                    throw new OperationException(OperationException.ERROR_TYPE.INSTALL, // NOI18N
                                    NbBundle.getMessage(// NOI18N
                                    InstallSupportImpl.class, // NOI18N
                                    "InstallSupportImpl_TurnOnTimeout", impl.getUpdateElement()));
                                }
                            }
                        } catch (InterruptedException ie) {
                            LOG.log(Level.INFO, ie.getMessage(), ie);
                        }
                    }
                    afterInstall();
                    synchronized (downloadedFiles) {
                        downloadedFiles.clear();
                    }
                }
            } finally {
                // end progress
                if (progress != null) {
                    progress.progress("");
                    progress.finish();
                }
            }
            return needsRestart && !forceInstall ? Boolean.TRUE : Boolean.FALSE;
        }
    };
    boolean retval = false;
    try {
        runningTask = getExecutionService().submit(installCallable);
        retval = runningTask.get();
    } catch (CancellationException ex) {
        // NOI18N
        LOG.log(Level.FINE, "InstallSupport.doInstall was cancelled", ex);
        return false;
    } catch (InterruptedException iex) {
        LOG.log(Level.INFO, iex.getLocalizedMessage(), iex);
    } catch (ExecutionException iex) {
        if (iex.getCause() instanceof OperationException) {
            throw (OperationException) iex.getCause();
        } else {
            LOG.log(Level.INFO, iex.getLocalizedMessage(), iex);
        }
    } finally {
        if (!retval) {
            getElement2Clusters().clear();
        }
    }
    return retval;
}
Also used : OperationInfo(org.netbeans.api.autoupdate.OperationContainer.OperationInfo) URL(java.net.URL) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) Module(org.netbeans.Module) JarFile(java.util.jar.JarFile)

Example 3 with OperationInfo

use of org.netbeans.api.autoupdate.OperationContainer.OperationInfo in project netbeans-rcp-lite by outersky.

the class InstallSupportImpl method doValidate.

@SuppressWarnings("ThrowableResultIgnored")
public boolean doValidate(final Validator validator, final ProgressHandle progress) throws /*or null*/
OperationException {
    assert validator != null;
    Callable<Boolean> validationCallable = new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            synchronized (LOCK) {
                assert currentStep != STEP.FINISHED;
                if (currentStep == STEP.CANCEL)
                    return false;
                currentStep = STEP.VALIDATION;
            }
            final OperationContainer<InstallSupport> container = support.getContainer();
            assert container.listInvalid().isEmpty() : support + ".listInvalid().isEmpty() but " + container.listInvalid() + "\ncontainer: " + container;
            // start progress
            if (progress != null) {
                progress.start(wasDownloaded);
            }
            int aggregateVerified = 0;
            try {
                for (OperationInfo info : infos) {
                    if (cancelled())
                        return false;
                    UpdateElementImpl toUpdateImpl = Trampoline.API.impl(info.getUpdateElement());
                    boolean hasCustom = toUpdateImpl.getInstallInfo().getCustomInstaller() != null;
                    if (hasCustom) {
                        // XXX: validation of custom installed
                        assert false : "InstallSupportImpl cannot support CustomInstaller!";
                    } else {
                        aggregateVerified += doValidate(info, progress, aggregateVerified);
                    }
                }
            } finally {
                // end progress
                if (progress != null) {
                    progress.progress("");
                    progress.finish();
                }
            }
            return true;
        }
    };
    boolean retval = false;
    try {
        runningTask = getExecutionService().submit(validationCallable);
        retval = runningTask.get();
    } catch (CancellationException ex) {
        // NOI18N
        LOG.log(Level.FINE, "InstallSupport.doValidate was cancelled", ex);
        return false;
    } catch (InterruptedException iex) {
        if (iex.getCause() instanceof OperationException) {
            throw (OperationException) iex.getCause();
        }
        Exceptions.printStackTrace(iex);
    } catch (ExecutionException iex) {
        if (iex.getCause() instanceof SecurityException) {
            throw new OperationException(OperationException.ERROR_TYPE.MODIFIED, iex.getLocalizedMessage());
        } else {
            if (iex.getCause() instanceof OperationException) {
                throw (OperationException) iex.getCause();
            }
            Exceptions.printStackTrace(iex);
        }
    }
    return retval;
}
Also used : OperationInfo(org.netbeans.api.autoupdate.OperationContainer.OperationInfo)

Example 4 with OperationInfo

use of org.netbeans.api.autoupdate.OperationContainer.OperationInfo in project netbeans-rcp-lite by outersky.

the class InstallUnitWizardModel method getBaseContainerImpl.

private OperationContainer<InstallSupport> getBaseContainerImpl() {
    if (updateContainer != null) {
        return updateContainer;
    }
    OperationContainer<InstallSupport> c = null;
    switch(getOperation()) {
        case INSTALL:
            c = Containers.forAvailable();
            break;
        case UPDATE:
            c = Containers.forUpdate();
            break;
        case LOCAL_DOWNLOAD:
            OperationContainer<InstallSupport> forUpdateNbms = Containers.forUpdateNbms();
            OperationContainer<InstallSupport> forAvailableNbms = Containers.forAvailableNbms();
            if (forUpdateNbms.listAll().isEmpty()) {
                c = forAvailableNbms;
            } else {
                c = forUpdateNbms;
                for (OperationInfo i : forAvailableNbms.listAll()) {
                    c.add(i.getUpdateElement());
                }
                assert forAvailableNbms.listInvalid().isEmpty() : "Containers.forAvailableNbms().listInvalid() should be empty but " + forAvailableNbms.listInvalid();
                forAvailableNbms.removeAll();
            }
            updateContainer = c;
            break;
    }
    return c;
}
Also used : OperationInfo(org.netbeans.api.autoupdate.OperationContainer.OperationInfo)

Example 5 with OperationInfo

use of org.netbeans.api.autoupdate.OperationContainer.OperationInfo in project netbeans-rcp-lite by outersky.

the class PluginManager method openInstallWizard.

/**
 * Open standard dialog for installing set of modules. Shows it to the user,
 * asks for confirmation, license acceptance, etc. The whole operation requires
 * AWT dispatch thread access (to show the dialog) and blocks
 * (until the user clicks through), so either call from AWT dispatch thread
 * directly, or be sure you hold no locks and block no progress of other
 * threads to avoid deadlocks.
 *
 * @param container the container with list of modules for install
 * @param runInBackground if <code>true</code> then installation run in the background after license acceptance
 */
public static void openInstallWizard(OperationContainer<InstallSupport> container, boolean runInBackground) {
    if (container == null) {
        // NOI18N
        throw new IllegalArgumentException("OperationContainer cannot be null.");
    }
    List<OperationContainer.OperationInfo<InstallSupport>> all = container.listAll();
    if (all.isEmpty()) {
        // NOI18N
        throw new IllegalArgumentException("OperationContainer cannot be empty.");
    }
    List<OperationContainer.OperationInfo<InstallSupport>> invalid = container.listInvalid();
    if (!invalid.isEmpty()) {
        // NOI18N
        throw new IllegalArgumentException("OperationContainer cannot contain invalid elements but " + invalid);
    }
    OperationInfo<InstallSupport> info = all.get(0);
    OperationType doOperation = info.getUpdateUnit().getInstalled() == null ? OperationType.INSTALL : OperationType.UPDATE;
    new InstallUnitWizard().invokeWizard(new InstallUnitWizardModel(doOperation, container), true, runInBackground);
}
Also used : OperationInfo(org.netbeans.api.autoupdate.OperationContainer.OperationInfo) InstallSupport(org.netbeans.api.autoupdate.InstallSupport) InstallUnitWizard(org.netbeans.modules.autoupdate.ui.wizards.InstallUnitWizard) OperationType(org.netbeans.modules.autoupdate.ui.wizards.OperationWizardModel.OperationType) InstallUnitWizardModel(org.netbeans.modules.autoupdate.ui.wizards.InstallUnitWizardModel)

Aggregations

OperationInfo (org.netbeans.api.autoupdate.OperationContainer.OperationInfo)9 HashSet (java.util.HashSet)3 InstallSupport (org.netbeans.api.autoupdate.InstallSupport)2 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)2 InstallUnitWizard (org.netbeans.modules.autoupdate.ui.wizards.InstallUnitWizard)2 InstallUnitWizardModel (org.netbeans.modules.autoupdate.ui.wizards.InstallUnitWizardModel)2 OperationType (org.netbeans.modules.autoupdate.ui.wizards.OperationWizardModel.OperationType)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 Module (org.netbeans.Module)1 Dependency (org.openide.modules.Dependency)1 ModuleInfo (org.openide.modules.ModuleInfo)1