use of org.netbeans.api.autoupdate.InstallSupport.Installer in project netbeans-rcp-lite by outersky.
the class ModuleOptions method install.
@NbBundle.Messages({ "# {0} - module name", "# {1} - module version", "MSG_Installing=Installing {0}@{1}", "# {0} - paterns", "MSG_InstallNoMatch=Cannot install. No match for {0}." })
private void install(final Env env, String... pattern) throws CommandException {
if (!initialized()) {
refresh(env);
}
Pattern[] pats = findMatcher(env, pattern);
List<UpdateUnit> units = UpdateManager.getDefault().getUpdateUnits();
OperationContainer<InstallSupport> operate = OperationContainer.createForInstall();
for (UpdateUnit uu : units) {
if (uu.getInstalled() != null) {
continue;
}
if (!matches(uu.getCodeName(), pats)) {
continue;
}
if (uu.getAvailableUpdates().isEmpty()) {
continue;
}
UpdateElement ue = uu.getAvailableUpdates().get(0);
env.getOutputStream().println(Bundle.MSG_Installing(uu.getCodeName(), ue.getSpecificationVersion()));
operate.add(ue);
}
final InstallSupport support = operate.getSupport();
if (support == null) {
env.getOutputStream().println(Bundle.MSG_InstallNoMatch(Arrays.asList(pats)));
return;
}
try {
// NOI18N
env.getOutputStream().println("modules=" + operate.listAll().size());
// NOI18N
ProgressHandle downloadHandle = new CLIInternalHandle("downloading-modules", env).createProgressHandle();
downloadHandle.setInitialDelay(0);
final Validator res1 = support.doDownload(downloadHandle, null, false);
Installer res2 = support.doValidate(res1, null);
// NOI18N
ProgressHandle installHandle = new CLIInternalHandle("installing-modules", env).createProgressHandle();
installHandle.setInitialDelay(0);
Restarter res3 = support.doInstall(res2, installHandle);
if (res3 != null) {
support.doRestart(res3, null);
}
} catch (OperationException ex) {
// a hack
if (OperationException.ERROR_TYPE.INSTALL.equals(ex.getErrorType())) {
// probably timeout of loading
env.getErrorStream().println(ex.getLocalizedMessage());
throw (CommandException) new CommandException(34, ex.getMessage()).initCause(ex);
} else {
try {
support.doCancel();
throw (CommandException) new CommandException(32, ex.getMessage()).initCause(ex);
} catch (OperationException ex1) {
throw (CommandException) new CommandException(32, ex1.getMessage()).initCause(ex1);
}
}
}
}
use of org.netbeans.api.autoupdate.InstallSupport.Installer in project netbeans-rcp-lite by outersky.
the class ModuleOptions method updateModules.
@NbBundle.Messages({ "MSG_UpdateNotFound=Updates not found.", "# {0} - pattern", "MSG_UpdateNoMatchPattern=Nothing to update. The pattern {0} has no match among available updates.", "# {0} - module name", "# {1} - installed version", "# {2} - available version", "MSG_Update=Will update {0}@{1} to version {2}", "# {0} - plugin name", "MSG_Download=Downloading {0}" })
private void updateModules(final Env env, String... pattern) throws CommandException {
if (!initialized()) {
refresh(env);
}
Pattern[] pats = findMatcher(env, pattern);
List<UpdateUnit> units = UpdateManager.getDefault().getUpdateUnits(UpdateManager.TYPE.MODULE);
final Collection<String> firstClass = getFirstClassModules();
boolean firstClassHasUpdates = false;
OperationContainer<InstallSupport> operate = OperationContainer.createForUpdate();
if (!firstClass.isEmpty() && pattern.length == 0) {
for (UpdateUnit uu : units) {
if (uu.getInstalled() == null) {
continue;
}
final List<UpdateElement> updates = uu.getAvailableUpdates();
if (updates.isEmpty()) {
continue;
}
if (!firstClass.contains(uu.getCodeName())) {
continue;
}
final UpdateElement ue = updates.get(0);
env.getOutputStream().println(Bundle.MSG_Update(uu.getCodeName(), uu.getInstalled().getSpecificationVersion(), ue.getSpecificationVersion()));
if (operate.canBeAdded(uu, ue)) {
LOG.fine(" ... update " + uu.getInstalled() + " -> " + ue);
firstClassHasUpdates = true;
OperationInfo<InstallSupport> info = operate.add(ue);
if (info != null) {
Set<UpdateElement> requiredElements = info.getRequiredElements();
LOG.fine(" ... add required elements: " + requiredElements);
operate.add(requiredElements);
}
}
}
}
if (!firstClassHasUpdates) {
for (UpdateUnit uu : units) {
if (uu.getInstalled() == null) {
continue;
}
final List<UpdateElement> updates = uu.getAvailableUpdates();
if (updates.isEmpty()) {
continue;
}
if (pattern.length > 0 && !matches(uu.getCodeName(), pats)) {
continue;
}
final UpdateElement ue = updates.get(0);
env.getOutputStream().println(Bundle.MSG_Update(uu.getCodeName(), uu.getInstalled().getSpecificationVersion(), ue.getSpecificationVersion()));
if (operate.canBeAdded(uu, ue)) {
LOG.fine(" ... update " + uu.getInstalled() + " -> " + ue);
OperationInfo<InstallSupport> info = operate.add(ue);
if (info != null) {
Set<UpdateElement> requiredElements = info.getRequiredElements();
LOG.fine(" ... add required elements: " + requiredElements);
operate.add(requiredElements);
}
}
}
}
final InstallSupport support = operate.getSupport();
if (support == null) {
env.getOutputStream().println(pats == null || pats.length == 0 ? Bundle.MSG_UpdateNotFound() : Bundle.MSG_UpdateNoMatchPattern(Arrays.asList(pats)));
// NOI18N
env.getOutputStream().println("updates=0");
return;
}
// NOI18N
env.getOutputStream().println("updates=" + operate.listAll().size());
// NOI18N
ProgressHandle downloadHandle = new CLIInternalHandle("downloading-updates", env).createProgressHandle();
downloadHandle.setInitialDelay(0);
try {
final Validator res1 = support.doDownload(downloadHandle, null, false);
Installer res2 = support.doValidate(res1, null);
// NOI18N
ProgressHandle installHandle = new CLIInternalHandle("installing-updates", env).createProgressHandle();
installHandle.setInitialDelay(0);
Restarter res3 = support.doInstall(res2, installHandle);
if (res3 != null) {
support.doRestart(res3, null);
}
} catch (OperationException ex) {
try {
support.doCancel();
throw (CommandException) new CommandException(33, ex.getMessage()).initCause(ex);
} catch (OperationException ex1) {
throw (CommandException) new CommandException(33, ex1.getMessage()).initCause(ex1);
}
}
}
use of org.netbeans.api.autoupdate.InstallSupport.Installer in project netbeans-rcp-lite by outersky.
the class InstallStep method doDownloadAndVerificationAndInstall.
@SuppressWarnings("null")
private void doDownloadAndVerificationAndInstall() {
OperationContainer<InstallSupport> installContainer = model.getInstallContainer();
final InstallSupport support = installContainer.getSupport();
assert support != null : "Operation failed: OperationSupport cannot be null because OperationContainer " + "contains elements: " + installContainer.listAll() + " and invalid elements " + installContainer.listInvalid() + "\ncontainer: " + installContainer;
assert installContainer.listInvalid().isEmpty() : support + ".listInvalid().isEmpty() but " + installContainer.listInvalid() + " container: " + installContainer;
if (support == null) {
log.log(Level.WARNING, "Operation failed: OperationSupport was null because OperationContainer " + "either does not contain any elements: {0} or contains invalid elements {1}", new Object[] { model.getInstallContainer().listAll(), model.getInstallContainer().listInvalid() });
return;
}
Validator v;
// download
if ((v = handleDownload(support)) != null) {
Installer i;
// verifation
if ((i = handleValidation(v, support)) != null) {
// installation
Restarter r;
if ((r = handleInstall(i, support)) != null) {
presentInstallNeedsRestart(r, support);
} else {
presentInstallDone();
}
}
}
if (!canceled) {
// delay the fire untilt he task completes
org.netbeans.modules.autoupdate.ui.actions.Installer.RP.post(this::fireChange);
}
}
use of org.netbeans.api.autoupdate.InstallSupport.Installer 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