use of org.netbeans.api.autoupdate.OperationException in project netbeans-rcp-lite by outersky.
the class ModuleInstallerSupport method installPlugins.
public Object installPlugins(final String displayName, Set<String> cnbs) throws OperationException {
Collection<UpdateUnit> units = findModules(cnbs);
if (units == null) {
final String searchMessage = displayName != null ? searching_handle_single(displayName) : searching_handle();
final String resolveTitle = displayName != null ? resolve_title_single(displayName) : resolve_title();
final ProgressHandle handle = ProgressHandleFactory.createHandle(searchMessage);
initButtons();
final DialogDescriptor searching = new DialogDescriptor(searchingPanel(new JLabel(searchMessage), ProgressHandleFactory.createProgressComponent(handle)), resolveTitle, true, null);
handle.setInitialDelay(0);
handle.start();
searching.setOptions(new Object[] { NotifyDescriptor.CANCEL_OPTION });
searching.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
final Dialog dlg = DialogDisplayer.getDefault().createDialog(searching);
RP.post(new Runnable() {
@Override
public void run() {
// May be first start, when no update lists have yet been downloaded.
try {
for (UpdateUnitProvider p : UpdateUnitProviderFactory.getDefault().getUpdateUnitProviders(true)) {
p.refresh(handle, true);
}
// close searching
dlg.dispose();
} catch (IOException ex) {
LOG.log(Level.FINE, ex.getMessage(), ex);
if (!dlg.isVisible()) {
LOG.fine("dialog not visible => do nothing");
return;
}
DialogDescriptor networkProblem = new DialogDescriptor(// message
problemPanel(resolveTitle, networkproblem_message()), // title
networkproblem_header(), // modal
true, null);
networkProblem.setOptions(new Object[] { tryAgain, proxySettings, NotifyDescriptor.CANCEL_OPTION });
networkProblem.setAdditionalOptions(closingOptions);
networkProblem.setClosingOptions(fullClosingOptions);
networkProblem.setMessageType(NotifyDescriptor.WARNING_MESSAGE);
Dialog networkProblemDialog = DialogDisplayer.getDefault().createDialog(networkProblem);
networkProblemDialog.setVisible(true);
Object answer = networkProblem.getValue();
if (NotifyDescriptor.CANCEL_OPTION.equals(answer) || Arrays.asList(closingOptions).contains(answer) || answer.equals(NotifyDescriptor.DEFAULT_OPTION)) /* escape */
{
LOG.fine("cancel network problem dialog");
searching.setValue(answer);
dlg.dispose();
} else if (tryAgain.equals(answer)) {
LOG.fine("try again searching");
RP.post(this);
} else {
assert false : "Unknown " + answer;
}
}
}
});
dlg.setVisible(true);
handle.finish();
if (NotifyDescriptor.CANCEL_OPTION.equals(searching.getValue()) || searching.getValue().equals(NotifyDescriptor.DEFAULT_OPTION)) /* escape */
{
LOG.log(Level.FINE, "user canceled searching for {0}", cnbs);
return showNoDownloadDialog(displayName, cnbs);
} else if (Arrays.asList(closingOptions).contains(searching.getValue())) {
return searching.getValue();
}
units = findModules(cnbs);
if (units == null) {
LOG.log(Level.FINE, "could not find {0} on any update site", cnbs);
return showNoDownloadDialog(displayName, cnbs);
}
}
List<UpdateUnit> toHandle = new ArrayList<UpdateUnit>(units);
OperationContainer<OperationSupport> oc = null;
for (Iterator<UpdateUnit> it = toHandle.iterator(); it.hasNext(); ) {
UpdateUnit unit = it.next();
// check if module installed
if (unit.getInstalled() != null) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine(unit.getInstalled() + " already installed. Is active? " + unit.getInstalled().isEnabled());
}
if (unit.getInstalled().isEnabled()) {
it.remove();
continue;
} else {
if (oc == null) {
oc = OperationContainer.createForEnable();
}
if (!oc.canBeAdded(unit, unit.getInstalled())) {
throw new OperationException(OperationException.ERROR_TYPE.ENABLE, "could not add " + unit.getInstalled() + " for activation");
}
for (UpdateElement req : oc.add(unit.getInstalled()).getRequiredElements()) {
oc.add(req);
}
it.remove();
continue;
}
}
}
if (oc != null) {
ProgressHandle activeHandle = ProgressHandleFactory.createHandle(displayName != null ? active_handle_single(displayName) : active_handle());
Restarter restarter = oc.getSupport().doOperation(activeHandle);
assert restarter == null : "No Restater need to make units active";
}
if (toHandle.isEmpty()) {
return null;
}
OperationContainer<InstallSupport> ocInstall = OperationContainer.createForInstall();
for (Iterator<UpdateUnit> it = toHandle.iterator(); it.hasNext(); ) {
UpdateUnit unit = it.next();
List<UpdateElement> updates = unit.getAvailableUpdates();
if (updates.isEmpty()) {
throw new OperationException(OperationException.ERROR_TYPE.INSTALL, "no updates for " + unit);
}
UpdateElement element = updates.get(0);
if (!ocInstall.canBeAdded(unit, element)) {
throw new OperationException(OperationException.ERROR_TYPE.INSTALL, "could not add " + element + " to updates");
}
for (UpdateElement req : ocInstall.add(element).getRequiredElements()) {
ocInstall.add(req);
}
it.remove();
}
assert toHandle.isEmpty() : "These unit were not handled " + toHandle;
if (!PluginManager.openInstallWizard(ocInstall)) {
LOG.fine("user canceled PM");
return showNoDownloadDialog(displayName, cnbs);
}
return null;
}
use of org.netbeans.api.autoupdate.OperationException in project netbeans-rcp-lite by outersky.
the class InstallManager method getInstallDir.
// can be null for fixed modules
private static File getInstallDir(UpdateElement installed, UpdateElementImpl update, boolean isGlobal, boolean useUserdirAsFallback) throws OperationException {
File res = null;
UpdateElementImpl i = Trampoline.API.impl(installed);
assert i instanceof ModuleUpdateElementImpl : "Impl of " + installed + " instanceof ModuleUpdateElementImpl";
Module m = Utilities.toModule(((ModuleUpdateElementImpl) i).getModuleInfo());
File jarFile = m == null ? null : m.getJarFile();
if (jarFile == null) {
// only fixed module cannot be located
ERR.log(Level.FINE, "No install dir for " + installed + " (It's ok for fixed). Is fixed? " + Trampoline.API.impl(installed).isFixed());
String targetCluster = update.getInstallInfo().getTargetCluster();
if (targetCluster != null) {
for (File cluster : UpdateTracking.clusters(false)) {
if (targetCluster.equals(cluster.getName())) {
res = cluster;
break;
}
}
}
if (res == null) {
// go to platform if no cluster is known
res = UpdateTracking.getPlatformDir();
}
} else {
for (File cluster : UpdateTracking.clusters(true)) {
cluster = FileUtil.normalizeFile(cluster);
if (isParentOf(cluster, jarFile)) {
res = cluster;
break;
}
}
}
if (res == null || !Utilities.canWriteInCluster(res)) {
if (!useUserdirAsFallback && isGlobal) {
ERR.log(Level.WARNING, "There is no write permission to write in target cluster " + res + " for " + update.getUpdateElement());
throw new OperationException(OperationException.ERROR_TYPE.WRITE_PERMISSION, update.getCodeName());
}
// go to userdir if no writable cluster is known
if (countOfWarnings++ < MAX_COUNT_OF_WARNINGS) {
ERR.log(Level.WARNING, "There is no write permission to write in target cluster " + res + " for " + update.getUpdateElement());
}
if (countOfWarnings == MAX_COUNT_OF_WARNINGS) {
ERR.log(Level.WARNING, "There is no write permission to write in target cluster " + res + " for more updates or plugins.");
}
res = UpdateTracking.getUserDir();
}
ERR.log(Level.FINEST, "Install dir of " + installed + " is " + res);
return res;
}
use of org.netbeans.api.autoupdate.OperationException in project netbeans-rcp-lite by outersky.
the class InstallStep method storeSettings.
@Override
public void storeSettings(WizardDescriptor wd) {
assert !WizardDescriptor.PREVIOUS_OPTION.equals(wd.getValue()) : "Cannot invoke Back in this case.";
if (wasStored) {
return;
}
this.wasStored = true;
InstallSupport support = model.getBaseContainer().getSupport();
if (WizardDescriptor.CANCEL_OPTION.equals(wd.getValue()) || WizardDescriptor.CLOSED_OPTION.equals(wd.getValue())) {
try {
model.doCleanup(true);
} catch (OperationException x) {
Logger.getLogger(InstallStep.class.getName()).log(Level.INFO, x.getMessage(), x);
}
} else if (restarter != null) {
if (support == null) {
assert model.getInstallContainer().listAll() == null : "storeSettings failed. OperationSupport is null because OperationContainer " + "contains no elements: " + model.getInstallContainer().listAll();
return;
}
if (panel.restartNow()) {
resetLastCheckWhenUpdatingFirstClassModules(model.getAllUpdateElements());
handleLazyUnits(clearLazyUnits, false);
try {
support.doRestart(restarter, null);
} catch (OperationException x) {
log.log(Level.INFO, x.getMessage(), x);
}
} else {
resetLastCheckWhenUpdatingFirstClassModules(model.getAllUpdateElements());
support.doRestartLater(restarter);
handleLazyUnits(clearLazyUnits, true);
try {
model.doCleanup(false);
} catch (OperationException x) {
log.log(Level.INFO, x.getMessage(), x);
}
// NOI18N
notifyInstallRestartNeeded(support, restarter);
}
} else {
try {
model.doCleanup(!WizardDescriptor.FINISH_OPTION.equals(wd.getValue()));
} catch (OperationException x) {
log.log(Level.INFO, x.getMessage(), x);
}
}
}
use of org.netbeans.api.autoupdate.OperationException in project netbeans-rcp-lite by outersky.
the class InstallStep method handleInstall.
private Restarter handleInstall(Installer i, final InstallSupport support) {
if (canceled) {
log.fine("Quit handleInstall() because an previous installation was canceled.");
return null;
}
installException = null;
component.setHeadAndContent(getBundle(HEAD_INSTALL), getBundle(CONTENT_INSTALL));
model.modifyOptionsForDisabledCancel(wd);
ProgressHandle handle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Install_InstallingPlugins"));
JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent(handle);
JLabel detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
if (runInBackground()) {
systemHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Install_InstallingPlugins"));
handle = systemHandle;
} else {
spareHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Install_InstallingPlugins"));
totalUnits = model.getInstallContainer().listAll().size();
processedUnits = 0;
if (indeterminateProgress) {
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) {
spareHandle.progress(((JLabel) evt.getSource()).getText(), processedUnits < totalUnits - 1 ? processedUnits : totalUnits - 1);
}
}
}
});
}
}
handle.setInitialDelay(0);
panel.waitAndSetProgressComponents(mainLabel, progressComponent, detailLabel);
Restarter r = null;
boolean success = false;
try {
r = support.doInstall(i, handle);
success = true;
} catch (OperationException ex) {
log.log(Level.INFO, ex.getMessage(), ex);
panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(getBundle("InstallStep_Unsuccessful", ex.getLocalizedMessage())));
installException = ex;
}
if (success) {
panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(getBundle("InstallStep_Done")));
}
if (spareHandle != null && spareHandleStarted) {
spareHandle.finish();
}
return r;
}
use of org.netbeans.api.autoupdate.OperationException in project netbeans-rcp-lite by outersky.
the class InstallStep method handleValidation.
private Installer handleValidation(Validator v, final InstallSupport support) {
if (canceled) {
log.fine("Quit handleValidation() because an previous installation was canceled.");
return null;
}
component.setHeadAndContent(getBundle(HEAD_VERIFY), getBundle(CONTENT_VERIFY));
ProgressHandle handle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Validate_ValidatingPlugins"));
JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
JLabel mainLabel = ProgressHandleFactory.createMainLabelComponent(handle);
JLabel detailLabel = ProgressHandleFactory.createDetailLabelComponent(handle);
if (runInBackground()) {
systemHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Validate_ValidatingPlugins"), new Cancellable() {
@Override
public boolean cancel() {
handleCancel();
return true;
}
});
handle = systemHandle;
} else {
spareHandle = ProgressHandleFactory.createHandle(getBundle("InstallStep_Validate_ValidatingPlugins"), new Cancellable() {
@Override
public boolean cancel() {
handleCancel();
return true;
}
});
totalUnits = model.getInstallContainer().listAll().size();
processedUnits = 0;
if (indeterminateProgress) {
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) {
spareHandle.progress(((JLabel) evt.getSource()).getText(), processedUnits < totalUnits - 1 ? processedUnits : totalUnits - 1);
}
}
}
});
}
}
handle.setInitialDelay(0);
panel.waitAndSetProgressComponents(mainLabel, progressComponent, detailLabel);
if (spareHandle != null && spareHandleStarted) {
spareHandle.finish();
}
Installer tmpInst;
try {
tmpInst = support.doValidate(v, handle);
if (tmpInst == null)
return null;
} catch (OperationException ex) {
log.log(Level.INFO, ex.getMessage(), ex);
ProblemPanel problem = new ProblemPanel(ex, detailLabel.getText(), false);
if (ex.getErrorType() == OperationException.ERROR_TYPE.MODIFIED) {
problem.showModifiedProblemDialog(detailLabel.getText());
} else {
problem.showNetworkProblemDialog();
}
handleCancel();
return null;
}
final Installer inst = tmpInst;
List<UpdateElement> signedVerified = new ArrayList<UpdateElement>();
List<UpdateElement> signedUnverified = new ArrayList<UpdateElement>();
List<UpdateElement> unsigned = new ArrayList<UpdateElement>();
List<UpdateElement> modified = new ArrayList<UpdateElement>();
int trustedCount = 0;
Map<Object, String> certs = new HashMap<>();
for (UpdateElement el : model.getAllUpdateElements()) {
boolean writeCert = false;
if (support.isContentModified(inst, el)) {
modified.add(el);
continue;
} else if (support.isTrusted(inst, el)) {
trustedCount++;
continue;
} else if (support.isSignedVerified(inst, el)) {
signedVerified.add(el);
writeCert = true;
} else if (support.isSignedUnverified(inst, el)) {
signedUnverified.add(el);
writeCert = true;
} else {
unsigned.add(el);
}
if (writeCert) {
String cert = support.getCertificate(inst, el);
if (cert != null && cert.length() > 0) {
certs.put(el.getDisplayName(), cert);
}
}
}
if (signedVerified.size() > 0 || signedUnverified.size() > 0 || unsigned.size() > 0 || modified.size() > 0 && !runInBackground()) {
int total = trustedCount + signedVerified.size() + signedUnverified.size() + unsigned.size();
final ValidationWarningPanel p = new ValidationWarningPanel(signedVerified, signedUnverified, unsigned, modified, total);
final boolean verifyCertificate = (!signedVerified.isEmpty() || !signedUnverified.isEmpty()) && !certs.isEmpty();
JButton[] options;
JButton[] closeOptions;
final JButton cancel = model.getCancelButton(wd);
DialogDescriptor dd = new DialogDescriptor(p, verifyCertificate ? getBundle("ValidationWarningPanel_VerifyCertificate_Title") : getBundle("ValidationWarningPanel_Title"));
JButton canContinue = new JButton();
canContinue.setDefaultCapable(false);
if (modified.isEmpty()) {
final JButton showDetails = new JButton();
Mnemonics.setLocalizedText(showDetails, getBundle("ValidationWarningPanel_ShowDetailsButton"));
final Map<Object, String> certsMap = certs;
showDetails.setEnabled(false);
p.addSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (e.getNewLeadSelectionPath().getPathCount() == 3 && certsMap.containsKey(p.getSelectedNode())) {
showDetails.setEnabled(true);
} else {
showDetails.setEnabled(false);
}
}
});
showDetails.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (showDetails.equals(e.getSource())) {
Object node = p.getSelectedNode();
if (certsMap.containsKey(node)) {
JTextArea ta = new JTextArea(certsMap.get(node));
ta.setEditable(false);
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(ta));
}
}
}
});
Mnemonics.setLocalizedText(canContinue, getBundle("ValidationWarningPanel_ContinueButton"));
if (verifyCertificate) {
dd.setAdditionalOptions(new JButton[] { showDetails });
}
options = new JButton[] { canContinue, cancel };
closeOptions = new JButton[] { canContinue, cancel };
} else {
options = new JButton[] { cancel };
closeOptions = new JButton[] { cancel };
}
dd.setOptions(options);
dd.setClosingOptions(closeOptions);
dd.setMessageType(NotifyDescriptor.WARNING_MESSAGE);
final Dialog dlg = DialogDisplayer.getDefault().createDialog(dd);
JDialog jdlg = (JDialog) dlg;
jdlg.getRootPane().setDefaultButton(cancel);
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
dlg.setVisible(true);
}
});
} catch (InterruptedException ex) {
log.log(Level.INFO, ex.getLocalizedMessage(), ex);
return null;
} catch (InvocationTargetException ex) {
log.log(Level.INFO, ex.getLocalizedMessage(), ex);
return null;
}
if (!canContinue.equals(dd.getValue())) {
if (!cancel.equals(dd.getValue())) {
cancel.doClick();
}
return null;
}
assert canContinue.equals(dd.getValue());
}
panel.waitAndSetProgressComponents(mainLabel, progressComponent, new JLabel(getBundle("InstallStep_Done")));
return inst;
}
Aggregations