Search in sources :

Example 11 with OperationException

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

the class InstallManager method checkTargetCluster.

private static File checkTargetCluster(UpdateElementImpl update, String targetCluster, boolean isGlobal, boolean useUserdirAsFallback) throws OperationException {
    if (targetCluster == null || targetCluster.length() == 0) {
        return null;
    }
    File res = null;
    // does have a target cluster?
    for (File cluster : UpdateTracking.clusters(true)) {
        if (targetCluster.equals(cluster.getName())) {
            boolean wasNew = !cluster.exists();
            if (Utilities.canWriteInCluster(cluster)) {
                if (wasNew) {
                    cluster.mkdirs();
                    extendSystemFileSystem(cluster);
                }
                res = cluster;
            } else {
                if (!useUserdirAsFallback && isGlobal) {
                    ERR.log(Level.WARNING, "There is no write permission to write in target cluster " + targetCluster + " for " + update.getUpdateElement());
                    throw new OperationException(OperationException.ERROR_TYPE.WRITE_PERMISSION, update.getCodeName());
                }
                if (countOfWarnings++ < MAX_COUNT_OF_WARNINGS) {
                    ERR.log(Level.WARNING, "There is no write permission to write in target cluster " + targetCluster + " for " + update.getUpdateElement());
                }
                if (countOfWarnings == MAX_COUNT_OF_WARNINGS) {
                    ERR.log(Level.WARNING, "There is no write permission to write in target cluster " + targetCluster + " for more updates or plugins.");
                }
            }
            break;
        }
    }
    return res;
}
Also used : JarFile(java.util.jar.JarFile) File(java.io.File) OperationException(org.netbeans.api.autoupdate.OperationException)

Example 12 with OperationException

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

the class PluginManager method installSingle.

/**
 * Open standard dialog for installing a module including declared dependencies.
 * 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 codenamebase the codenamebase of module to install
 * @param displayName the display name of the module
 * @param alternativeOptions alternative options possibly displayed in error
 *             dialog user may choose if it is not possible to install the plugin;
 *             if chosen the option is return value of this method
 * @return <code>null</code> if the module has been successfully installed
 *             and/or activated, otherwise it returns the options user has
 *             selected in problem dialog, typically {@link NotifyDescriptor#DEFAULT_OPTION}
 *             (on esc), {@link NotifyDescriptor#CANCEL_OPTION} or
 *             any of <code>alternativeOptions</code>.
 * @since 1.35
 * @see #install(java.util.Set, java.lang.Object[])
 */
@CheckForNull
public static Object installSingle(@NonNull String codenamebase, @NonNull String displayName, @NonNull Object... alternativeOptions) {
    Parameters.notNull("cnb", codenamebase);
    Parameters.notNull("displayName", displayName);
    Parameters.notNull("alternativeOptions", alternativeOptions);
    try {
        return new ModuleInstallerSupport(alternativeOptions).installPlugins(displayName, Collections.singleton(codenamebase));
    } catch (OperationException ex) {
        Logger.getLogger(PluginManager.class.getName()).log(Level.WARNING, null, ex);
    }
    return NotifyDescriptor.DEFAULT_OPTION;
}
Also used : ModuleInstallerSupport(org.netbeans.modules.autoupdate.ui.ModuleInstallerSupport) OperationException(org.netbeans.api.autoupdate.OperationException) CheckForNull(org.netbeans.api.annotations.common.CheckForNull)

Example 13 with OperationException

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

the class InstallStep method tryPerformDownload.

private boolean tryPerformDownload(final InstallSupport support) {
    validator = null;
    JLabel detailLabel = null;
    try {
        ProgressHandle handle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Download_DownloadingPlugins"));
        JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
        JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent(handle);
        detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
        if (runInBackground()) {
            systemHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Download_DownloadingPlugins"), new Cancellable() {

                @Override
                public boolean cancel() {
                    return handleCancel();
                }
            });
            handle = systemHandle;
        } else {
            spareHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Download_DownloadingPlugins"), new Cancellable() {

                @Override
                public boolean cancel() {
                    return handleCancel();
                }
            });
            totalUnits = model.getInstallContainer().listAll().size();
            processedUnits = 0;
            detailLabel.addPropertyChangeListener(TEXT_PROPERTY, new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    assert TEXT_PROPERTY.equals(evt.getPropertyName()) : "Listens onlo on " + TEXT_PROPERTY + " but was " + evt;
                    if (evt.getOldValue() != evt.getNewValue()) {
                        processedUnits++;
                        if (indeterminateProgress && spareHandleStarted) {
                            if (processedUnits < totalUnits - 1) {
                                totalUnits = totalUnits - processedUnits;
                                spareHandle.switchToDeterminate(totalUnits);
                                indeterminateProgress = false;
                            }
                        }
                        if (!indeterminateProgress && spareHandleStarted) {
                            spareHandle.progress(((JLabel) evt.getSource()).getText(), processedUnits < totalUnits - 1 ? processedUnits : totalUnits - 1);
                        }
                    }
                }
            });
        }
        handle.setInitialDelay(0);
        panel.waitAndSetProgressComponents(mainLabel, progressComponent, detailLabel);
        validator = support.doDownload(handle, Utilities.isGlobalInstallation(), userdirAsFallback);
        if (validator == null) {
            handleCancel();
            return true;
        }
        panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(getBundle("InstallStep_Done")));
        if (spareHandle != null && spareHandleStarted) {
            spareHandle.finish();
            spareHandleStarted = false;
        }
    } catch (OperationException ex) {
        log.log(Level.INFO, ex.getMessage(), ex);
        if (OperationException.ERROR_TYPE.PROXY == ex.getErrorType()) {
            if (runInBackground()) {
                handleCancel();
                notifyNetworkProblem(ex);
            } else {
                JButton tryAgain = new JButton();
                // NOI18N
                Mnemonics.setLocalizedText(tryAgain, getBundle("InstallStep_NetworkProblem_Continue"));
                ProblemPanel problem = new ProblemPanel(// NOI18N
                getBundle("InstallStep_NetworkProblem_Text", ex.getLocalizedMessage()), new JButton[] { tryAgain, model.getCancelButton(wd) });
                Object ret = problem.showNetworkProblemDialog();
                if (tryAgain.equals(ret)) {
                    // try again
                    return false;
                } else if (DialogDescriptor.CLOSED_OPTION.equals(ret)) {
                    model.getCancelButton(wd).doClick();
                }
            }
        } else if (OperationException.ERROR_TYPE.WRITE_PERMISSION == ex.getErrorType()) {
            if (runInBackground()) {
                UpdateElement culprit = findCulprit(ex.getMessage());
                handleCancel();
                notifyWritePermissionProblem(ex, culprit);
            } else {
                JButton cancel = new JButton();
                Mnemonics.setLocalizedText(cancel, cancel());
                JButton install = new JButton();
                Mnemonics.setLocalizedText(install, install());
                UpdateElement culprit = findCulprit(ex.getMessage());
                ProblemPanel problem = new ProblemPanel(ex, culprit, false);
                Object ret = problem.showWriteProblemDialog();
                if (install.equals(ret)) {
                    // install anyway
                    userdirAsFallback = true;
                    return false;
                } else {
                    model.getCancelButton(wd).doClick();
                }
            }
        } else {
            // general problem, show more
            String pluginName = detailLabel == null || detailLabel.getText().length() == 0 ? getBundle("InstallStep_DownloadProblem_SomePlugins") : detailLabel.getText();
            String message = getBundle("InstallStep_DownloadProblem", pluginName, ex.getLocalizedMessage());
            Exceptions.attachLocalizedMessage(ex, message);
            log.log(Level.SEVERE, null, ex);
            handleCancel();
        }
    }
    return true;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) Cancellable(org.openide.util.Cancellable) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) ProblemPanel(org.netbeans.modules.autoupdate.ui.ProblemPanel) ProgressHandle(org.netbeans.api.progress.ProgressHandle) OperationException(org.netbeans.api.autoupdate.OperationException)

Aggregations

OperationException (org.netbeans.api.autoupdate.OperationException)13 JLabel (javax.swing.JLabel)6 ProgressHandle (org.netbeans.api.progress.ProgressHandle)6 JComponent (javax.swing.JComponent)5 Restarter (org.netbeans.api.autoupdate.OperationSupport.Restarter)4 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyChangeListener (java.beans.PropertyChangeListener)3 ArrayList (java.util.ArrayList)3 OperationSupport (org.netbeans.api.autoupdate.OperationSupport)3 Dialog (java.awt.Dialog)2 File (java.io.File)2 JarFile (java.util.jar.JarFile)2 JButton (javax.swing.JButton)2 CheckForNull (org.netbeans.api.annotations.common.CheckForNull)2 InstallSupport (org.netbeans.api.autoupdate.InstallSupport)2 UpdateUnit (org.netbeans.api.autoupdate.UpdateUnit)2 ModuleInstallerSupport (org.netbeans.modules.autoupdate.ui.ModuleInstallerSupport)2 ProblemPanel (org.netbeans.modules.autoupdate.ui.ProblemPanel)2 DialogDescriptor (org.openide.DialogDescriptor)2