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;
}
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;
}
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;
}
Aggregations