use of org.netbeans.api.autoupdate.UpdateElement in project netbeans-rcp-lite by outersky.
the class Utilities method findRequiredUpdateElements.
public static Set<UpdateElement> findRequiredUpdateElements(UpdateElement element, Collection<ModuleInfo> infos, Set<Dependency> brokenDependencies, boolean topAggressive, Collection<UpdateElement> recommended) {
Set<UpdateElement> retval = new HashSet<UpdateElement>();
switch(element.getUpdateUnit().getType()) {
case KIT_MODULE:
case MODULE:
boolean avoidRecommended = recommended != null && !recommended.isEmpty();
ModuleUpdateElementImpl el = (ModuleUpdateElementImpl) Trampoline.API.impl(element);
Set<Dependency> deps = new HashSet<Dependency>(el.getModuleInfo().getDependencies());
Set<ModuleInfo> availableInfos = new HashSet<ModuleInfo>(infos);
maybeAddImplicitHostDependency(element, deps);
int max_counter = el.getType().equals(UpdateManager.TYPE.KIT_MODULE) ? 2 : 1;
int counter = max_counter;
boolean aggressive = topAggressive && counter > 0;
Set<Dependency> all = new HashSet<Dependency>();
for (; ; ) {
Set<Dependency> newones = processDependencies(deps, retval, availableInfos, brokenDependencies, element, aggressive, recommended, avoidRecommended);
newones.removeAll(all);
// issue #247884 Autoupdate should force restart when a new module enables module which is a fragment of other module
for (Dependency dep : deps) {
UpdateUnit uu = toUpdateUnit(dep.getName());
if (uu != null && uu.getInstalled() != null) {
ModuleUpdateElementImpl em = (ModuleUpdateElementImpl) Trampoline.API.impl(uu.getInstalled());
// restart
if (em.getInstallInfo().getUpdateItemImpl().isFragment() && !uu.getInstalled().isEnabled()) {
String fh = em.getInstallInfo().getUpdateItemImpl().getFragmentHost();
Module m = Utilities.toModule(fh);
if (m != null && m.isEnabled()) {
el.getInstallInfo().getUpdateItemImpl().setNeedsRestart(true);
}
}
}
}
if (newones.isEmpty()) {
break;
}
all.addAll(newones);
deps = newones;
}
Set<Dependency> moreBroken = new HashSet<Dependency>();
Set<ModuleInfo> tmp = new HashSet<ModuleInfo>(availableInfos);
Set<UpdateElement> more;
counter = max_counter;
aggressive = topAggressive && counter > 0;
while (retval.addAll(more = handleBackwardCompatability(tmp, moreBroken, aggressive))) {
if (!moreBroken.isEmpty()) {
brokenDependencies.addAll(moreBroken);
break;
}
for (UpdateElement e : more) {
// infos.addAll (Trampoline.API.impl (el).getModuleInfos ());
tmp.add(((ModuleUpdateElementImpl) Trampoline.API.impl(e)).getModuleInfo());
}
aggressive = aggressive && (counter--) > 0;
}
if (!moreBroken.isEmpty()) {
brokenDependencies.addAll(moreBroken);
}
break;
case STANDALONE_MODULE:
case FEATURE:
FeatureUpdateElementImpl feature = (FeatureUpdateElementImpl) Trampoline.API.impl(element);
aggressive = topAggressive;
for (ModuleUpdateElementImpl module : feature.getContainedModuleElements()) {
retval.addAll(findRequiredUpdateElements(module.getUpdateElement(), infos, brokenDependencies, aggressive, recommended));
}
break;
case CUSTOM_HANDLED_COMPONENT:
// XXX
getLogger().log(Level.INFO, "CUSTOM_HANDLED_COMPONENT doesn't care about required elements.");
break;
default:
assert false : "Not implement for type " + element.getUpdateUnit() + " of UpdateElement " + element;
}
return retval;
}
use of org.netbeans.api.autoupdate.UpdateElement 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.UpdateElement in project netbeans-rcp-lite by outersky.
the class UpdateUnitFactory method appendUpdateItems.
Map<String, UpdateUnit> appendUpdateItems(Map<String, UpdateUnit> originalUnits, UpdateProvider provider) {
assert originalUnits != null : "Map of original UnitImpl cannot be null";
boolean trusted = UpdateUnitProviderImpl.loadTrusted(provider);
Map<String, UpdateItem> items;
try {
items = provider.getUpdateItems();
} catch (IOException ioe) {
log.log(Level.INFO, "Cannot read UpdateItem from UpdateProvider " + provider, ioe);
return originalUnits;
}
assert items != null : "UpdateProvider[" + provider.getName() + "] should return non-null items.";
// append updates
for (String simpleItemId : items.keySet()) {
UpdateElement updateEl = null;
try {
// create UpdateItemImpl
UpdateItemImpl itemImpl = Trampoline.SPI.impl(items.get(simpleItemId));
boolean isKitModule = false;
if (itemImpl instanceof ModuleItem) {
ModuleInfo mi = ((ModuleItem) itemImpl).getModuleInfo();
assert mi != null : "ModuleInfo must be found for " + itemImpl;
isKitModule = Utilities.isKitModule(mi);
}
if (itemImpl instanceof InstalledModuleItem) {
if (isKitModule) {
KitModuleUpdateElementImpl impl = new KitModuleUpdateElementImpl((InstalledModuleItem) itemImpl, null);
updateEl = Trampoline.API.createUpdateElement(impl);
} else {
ModuleUpdateElementImpl impl = new ModuleUpdateElementImpl((InstalledModuleItem) itemImpl, null);
updateEl = Trampoline.API.createUpdateElement(impl);
}
} else if (itemImpl instanceof ModuleItem) {
if (isKitModule) {
KitModuleUpdateElementImpl impl = new KitModuleUpdateElementImpl((ModuleItem) itemImpl, provider.getDisplayName());
updateEl = Trampoline.API.createUpdateElement(impl);
} else {
ModuleUpdateElementImpl impl = new ModuleUpdateElementImpl((ModuleItem) itemImpl, provider.getDisplayName());
updateEl = Trampoline.API.createUpdateElement(impl);
}
} else if (itemImpl instanceof LocalizationItem) {
updateEl = Trampoline.API.createUpdateElement(new LocalizationUpdateElementImpl((LocalizationItem) itemImpl, provider.getDisplayName()));
} else if (itemImpl instanceof NativeComponentItem) {
updateEl = Trampoline.API.createUpdateElement(new NativeComponentUpdateElementImpl((NativeComponentItem) itemImpl, provider.getDisplayName()));
} else if (itemImpl instanceof FeatureItem) {
FeatureUpdateElementImpl impl = new FeatureUpdateElementImpl.Agent((FeatureItem) itemImpl, provider.getDisplayName(), UpdateManager.TYPE.FEATURE);
updateEl = Trampoline.API.createUpdateElement(impl);
} else {
assert false : "Unknown type of UpdateElement " + updateEl;
}
} catch (IllegalArgumentException iae) {
log.log(Level.INFO, iae.getLocalizedMessage(), iae);
}
// add element to map
if (updateEl != null) {
Trampoline.API.impl(updateEl).setCatalogTrusted(trusted);
addElement(originalUnits, updateEl, provider);
}
}
return originalUnits;
}
use of org.netbeans.api.autoupdate.UpdateElement in project netbeans-rcp-lite by outersky.
the class UpdateUnitImpl method identifyLocalizationUpdates.
private List<UpdateElement> identifyLocalizationUpdates(UpdateElement installed, List<UpdateElement> updates) {
// XXX: handle identifyLocalizationUpdates
List<UpdateElement> res = null;
// check if potentinally updates exist
if (updates != null && !updates.isEmpty()) {
// check if a module is already installed
if (installed == null) {
return updates;
} else {
// compare installed with optionallly update
String moduleId = installed.getCodeName();
List<UpdateElement> realUpdates = new ArrayList<UpdateElement>();
for (UpdateElement update : updates) {
if (update.getSpecificationVersion().compareTo(installed.getSpecificationVersion()) > 0) {
err.log(Level.FINE, "Module " + moduleId + "[" + installed.getSpecificationVersion() + "] has update " + moduleId + "[" + update.getSpecificationVersion() + "]");
realUpdates.add(update);
}
}
if (!realUpdates.isEmpty()) {
res = realUpdates;
}
}
}
return res;
}
use of org.netbeans.api.autoupdate.UpdateElement in project netbeans-rcp-lite by outersky.
the class ModuleUpdateUnitImpl method getVisibleAncestor.
@Override
public UpdateUnit getVisibleAncestor() {
if (visibleAncestor == null) {
assert getInstalled() != null : this + " is installed";
ModuleUpdateElementImpl installedImpl = (ModuleUpdateElementImpl) Trampoline.API.impl(getInstalled());
TreeSet<Module> visible = new TreeSet<Module>(new Comparator<Module>() {
@Override
public int compare(Module o1, Module o2) {
return o1.getCodeNameBase().compareTo(o2.getCodeNameBase());
}
});
Set<Module> seen = new HashSet<Module>();
for (ModuleInfo mi : installedImpl.getModuleInfos()) {
visible.addAll(findVisibleAncestor(Utilities.toModule(mi), seen));
}
String cat = installedImpl.getCategory();
String installationCluster = installedImpl.getInstallationCluster();
if (BROAD_CATEGORY.contains(cat)) {
cat = null;
}
UpdateUnit shot = null;
UpdateUnit spare = null;
UpdateUnit strike = null;
for (Module visMod : visible) {
visibleAncestor = Utilities.toUpdateUnit(visMod);
UpdateElementImpl visibleImpl = Trampoline.API.impl(visibleAncestor.getInstalled());
String visTargetCluster = null;
String visCat = null;
if (visibleImpl != null && visibleImpl instanceof ModuleUpdateElementImpl) {
visTargetCluster = ((ModuleUpdateElementImpl) visibleImpl).getInstallationCluster();
visCat = visibleImpl.getCategory();
}
if (installationCluster != null && installationCluster.equals(visTargetCluster)) {
spare = visibleAncestor;
} else if (visCat != null && visCat.equals(cat)) {
strike = visibleAncestor;
break;
} else if (shot == null) {
shot = visibleAncestor;
}
}
visibleAncestor = strike != null ? strike : spare != null ? spare : shot;
// if it's still unknown - try visible representative in given cluster
if (visibleAncestor == null && installationCluster != null) {
for (UpdateElement visEl : UpdateManagerImpl.getInstance().getInstalledKits(installationCluster)) {
visibleAncestor = visEl.getUpdateUnit();
if (installedImpl.getRawCategory().equals(visEl.getCategory())) {
visibleAncestor = visEl.getUpdateUnit();
break;
}
}
}
}
return visibleAncestor;
}
Aggregations