use of org.netbeans.api.autoupdate.UpdateUnit in project constellation by constellation-app.
the class DeveloperOptionsPanel method masterResetButtonActionPerformed.
// </editor-fold>//GEN-END:initComponents
private void masterResetButtonActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_masterResetButtonActionPerformed
Collection<UpdateElement> toUninstall = new ArrayList<>();
for (UpdateUnit unit : UpdateManager.getDefault().getUpdateUnits()) {
String codeName = unit.getCodeName();
if (!"au.gov.asd.tac.constellation.autoupdate".equals(codeName) && !codeName.startsWith("org.netbeans.") && !codeName.startsWith("org.openide.") && !codeName.startsWith("org.jdesktop.")) {
UpdateElement element = unit.getInstalled();
if (element != null) {
toUninstall.add(element);
}
}
}
OperationContainer<OperationSupport> operationContainer = OperationContainer.createForUninstall();
operationContainer.add(toUninstall);
OperationSupport operationSupport = operationContainer.getSupport();
try {
operationSupport.doOperation(null);
} catch (final OperationException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
use of org.netbeans.api.autoupdate.UpdateUnit in project netbeans-rcp-lite by outersky.
the class Utilities method handleDependency.
public static Collection<UpdateElement> handleDependency(UpdateElement el, Dependency dep, Collection<ModuleInfo> availableInfos, Set<Dependency> brokenDependencies, boolean beAggressive) {
Collection<UpdateElement> requested = new HashSet<UpdateElement>();
switch(dep.getType()) {
case Dependency.TYPE_JAVA:
if (!DependencyChecker.matchDependencyJava(dep)) {
brokenDependencies.add(dep);
}
break;
case Dependency.TYPE_PACKAGE:
if (!DependencyChecker.matchPackageDependency(dep)) {
brokenDependencies.add(dep);
}
break;
case Dependency.TYPE_MODULE:
Collection<UpdateUnit> reqUnits = DependencyAggregator.getRequested(dep);
assert reqUnits == null || reqUnits.isEmpty() || reqUnits.size() == 1 : dep + " returns null, empty or only once module, but returns " + reqUnits;
boolean matched = false;
UpdateUnit u = reqUnits == null || reqUnits.isEmpty() ? null : reqUnits.iterator().next();
if (u != null) {
boolean aggressive = beAggressive;
if (aggressive && (isFirstClassModule(el) || u.getType() == UpdateManager.TYPE.KIT_MODULE)) {
aggressive = false;
}
// if new module update is available, promote it even though installed one suites all the dependendencies
if (u.getInstalled() != null) {
UpdateElementImpl reqElImpl = Trampoline.API.impl(u.getInstalled());
matched = DependencyChecker.checkDependencyModule(dep, ((ModuleUpdateElementImpl) reqElImpl).getModuleInfo());
}
if (!matched) {
for (ModuleInfo m : availableInfos) {
if (DependencyChecker.checkDependencyModule(dep, m)) {
matched = true;
break;
}
}
}
if (aggressive || !matched) {
UpdateElement reqEl = u.getAvailableUpdates().isEmpty() ? null : u.getAvailableUpdates().get(0);
if (reqEl != null) {
UpdateElementImpl reqElImpl = Trampoline.API.impl(reqEl);
ModuleUpdateElementImpl reqModuleImpl = (ModuleUpdateElementImpl) reqElImpl;
ModuleInfo info = reqModuleImpl.getModuleInfo();
if (DependencyChecker.checkDependencyModule(dep, info)) {
if (!availableInfos.contains(info)) {
requested.add(reqEl);
matched = true;
}
}
}
}
} else {
for (ModuleInfo m : availableInfos) {
if (DependencyChecker.checkDependencyModule(dep, m)) {
matched = true;
break;
}
}
}
if (!matched) {
brokenDependencies.add(dep);
}
break;
case Dependency.TYPE_REQUIRES:
case Dependency.TYPE_NEEDS:
case Dependency.TYPE_RECOMMENDS:
if (DummyModuleInfo.TOKEN_MODULE_FORMAT1.equals(dep.getName()) || DummyModuleInfo.TOKEN_MODULE_FORMAT2.equals(dep.getName())) {
// these tokens you can ignore here
break;
}
Collection<UpdateUnit> requestedUnits = DependencyAggregator.getRequested(dep);
boolean passed = false;
if (requestedUnits == null || requestedUnits.isEmpty()) {
// look on availableInfos as well
for (ModuleInfo m : availableInfos) {
if (Arrays.asList(m.getProvides()).contains(dep.getName())) {
passed = true;
break;
}
}
} else {
passed = true;
for (UpdateUnit uu : requestedUnits) {
if (!uu.getAvailableUpdates().isEmpty()) {
requested.add(uu.getAvailableUpdates().get(0));
}
}
}
if (!passed && Dependency.TYPE_RECOMMENDS != dep.getType()) {
brokenDependencies.add(dep);
}
break;
}
return requested;
}
use of org.netbeans.api.autoupdate.UpdateUnit in project netbeans-rcp-lite by outersky.
the class Utilities method handleBackwardCompatability4ModuleInfo.
private static Set<UpdateElement> handleBackwardCompatability4ModuleInfo(ModuleInfo mi, Set<ModuleInfo> forInstall, Set<Dependency> brokenDependencies, boolean aggressive) {
if (cachedInfo2RequestedReference != null && cachedInfo2RequestedReference.get() != null) {
Set<UpdateElement> requested = cachedInfo2RequestedReference.get().get(mi);
if (requested != null) {
return requested;
}
}
UpdateUnit u = UpdateManagerImpl.getInstance().getUpdateUnit(mi.getCodeNameBase());
Set<UpdateElement> moreRequested = new HashSet<UpdateElement>();
// invalid codenamebase (in unit tests)
if (u == null) {
return moreRequested;
}
// not installed, not need to handle backward compatability
UpdateElement i = u.getInstalled();
if (i == null) {
return moreRequested;
}
// Dependency.TYPE_MODULE
Collection<Dependency> dependencies = new HashSet<Dependency>();
dependencies.addAll(Dependency.create(Dependency.TYPE_MODULE, mi.getCodeName()));
SortedSet<String> newTokens = new TreeSet<String>(Arrays.asList(mi.getProvides()));
SortedSet<String> oldTokens = new TreeSet<String>(Arrays.asList(((ModuleUpdateElementImpl) Trampoline.API.impl(i)).getModuleInfo().getProvides()));
oldTokens.removeAll(newTokens);
// handle diff
for (String tok : oldTokens) {
// don't care about provider of platform dependency here
if (tok.startsWith("org.openide.modules.os") || tok.startsWith("org.openide.modules.jre")) {
// NOI18N
continue;
}
dependencies.addAll(Dependency.create(Dependency.TYPE_REQUIRES, tok));
dependencies.addAll(Dependency.create(Dependency.TYPE_NEEDS, tok));
}
for (Dependency d : dependencies) {
DependencyAggregator deco = DependencyAggregator.getAggregator(d);
int type = d.getType();
String name = d.getName();
Collection<ModuleInfo> dependings = deco.getDependening();
synchronized (dependings) {
for (ModuleInfo depMI : dependings) {
Module depM = getModuleInstance(depMI.getCodeNameBase(), depMI.getSpecificationVersion());
if (depM == null) {
continue;
}
if (!depM.getProblems().isEmpty()) {
// skip this module because it has own problems already
continue;
}
for (Dependency toTry : depM.getDependencies()) {
// check only relevant deps
if (type == toTry.getType() && name.equals(toTry.getName()) && !DependencyChecker.checkDependencyModule(toTry, mi)) {
UpdateUnit tryUU = UpdateManagerImpl.getInstance().getUpdateUnit(depM.getCodeNameBase());
if (!tryUU.getAvailableUpdates().isEmpty()) {
UpdateElement tryUE = tryUU.getAvailableUpdates().get(0);
ModuleInfo tryUpdated = ((ModuleUpdateElementImpl) Trampoline.API.impl(tryUE)).getModuleInfo();
Set<Dependency> deps = new HashSet<Dependency>(tryUpdated.getDependencies());
Set<ModuleInfo> availableInfos = new HashSet<ModuleInfo>(forInstall);
Set<Dependency> newones;
maybeAddImplicitHostDependency(tryUE, deps);
while (!(newones = processDependencies(deps, moreRequested, availableInfos, brokenDependencies, tryUE, aggressive, null, false)).isEmpty()) {
deps = newones;
}
moreRequested.add(tryUE);
}
}
}
}
}
}
if (cachedInfo2RequestedReference == null || cachedInfo2RequestedReference.get() == null) {
cachedInfo2RequestedReference = new WeakReference<Map<ModuleInfo, Set<UpdateElement>>>(new HashMap<ModuleInfo, Set<UpdateElement>>());
}
cachedInfo2RequestedReference.get().put(mi, moreRequested);
return moreRequested;
}
use of org.netbeans.api.autoupdate.UpdateUnit in project netbeans-rcp-lite by outersky.
the class Utilities method getBrokenDependencies.
static Set<String> getBrokenDependencies(UpdateElement element, List<ModuleInfo> infos) {
assert element != null : "UpdateElement cannot be null";
Set<Dependency> brokenDependencies = new HashSet<Dependency>();
// create init collection of brokenDependencies
Utilities.findRequiredUpdateElements(element, infos, brokenDependencies, false, new HashSet<UpdateElement>());
// backward compatibility
for (ModuleInfo mi : infos) {
UpdateUnit u = UpdateManagerImpl.getInstance().getUpdateUnit(mi.getCodeNameBase());
// invalid codenamebase (in unit tests)
if (u == null) {
continue;
}
// not installed, not need to handle backward compatability
UpdateElement i = u.getInstalled();
if (i == null) {
continue;
}
// maybe newer version is processed as a update
if (!u.getAvailableUpdates().isEmpty()) {
UpdateElement ue = u.getAvailableUpdates().get(0);
ModuleInfo newerMI = ((ModuleUpdateElementImpl) Trampoline.API.impl(ue)).getModuleInfo();
if (infos.contains(newerMI)) {
continue;
}
}
// Dependency.TYPE_MODULE
for (Dependency d : Dependency.create(Dependency.TYPE_MODULE, mi.getCodeName())) {
DependencyAggregator deco = DependencyAggregator.getAggregator(d);
Collection<ModuleInfo> dependings = deco.getDependening();
synchronized (dependings) {
for (ModuleInfo depMI : dependings) {
// Module depM = Utilities.toModule (depMI);
Module depM = getModuleInstance(depMI.getCodeNameBase(), depMI.getSpecificationVersion());
if (depM == null) {
continue;
}
if (!depM.getProblems().isEmpty()) {
// skip this module because it has own problems already
continue;
}
for (Dependency toTry : depM.getDependencies()) {
// check only relevant deps
if (deco.equals(DependencyAggregator.getAggregator(toTry)) && !DependencyChecker.checkDependencyModule(toTry, mi)) {
brokenDependencies.add(toTry);
}
}
}
}
}
// Dependency.TYPE_REQUIRES
// Dependency.TYPE_NEEDS
SortedSet<String> newTokens = new TreeSet<String>(Arrays.asList(mi.getProvides()));
SortedSet<String> oldTokens = new TreeSet<String>(Arrays.asList(((ModuleUpdateElementImpl) Trampoline.API.impl(i)).getModuleInfo().getProvides()));
oldTokens.removeAll(newTokens);
// handle diff
for (String tok : oldTokens) {
Collection<Dependency> deps = new HashSet<Dependency>(Dependency.create(Dependency.TYPE_REQUIRES, tok));
deps.addAll(Dependency.create(Dependency.TYPE_NEEDS, tok));
for (Dependency d : deps) {
DependencyAggregator deco = DependencyAggregator.getAggregator(d);
Collection<ModuleInfo> dependings = deco.getDependening();
synchronized (dependings) {
for (ModuleInfo depMI : dependings) {
// Module depM = Utilities.toModule (depMI);
Module depM = getModuleInstance(depMI.getCodeNameBase(), depMI.getSpecificationVersion());
if (depM == null) {
continue;
}
if (!depM.getProblems().isEmpty()) {
// skip this module because it has own problems already
continue;
}
for (Dependency toTry : depM.getDependencies()) {
// check only relevant deps
if (deco.equals(DependencyAggregator.getAggregator(toTry))) {
brokenDependencies.add(toTry);
}
}
}
}
}
}
}
Set<String> retval = new HashSet<String>(brokenDependencies.size());
for (Dependency dep : brokenDependencies) {
retval.add(dep.toString());
}
return retval;
}
use of org.netbeans.api.autoupdate.UpdateUnit in project netbeans-rcp-lite by outersky.
the class UpdateUnitFactory method getUpdateUnits.
public Map<String, UpdateUnit> getUpdateUnits() {
// TODO: this call should be forced not to be called from AWT
// assert !SwingUtilities.isEventDispatchThread();
// NOI18N
resetRunTime("Measuring of UpdateUnitFactory.getUpdateUnits()");
List<UpdateUnitProvider> updates = UpdateUnitProviderImpl.getUpdateUnitProviders(true);
try {
InstalledModuleProvider.getDefault().getUpdateItems();
} catch (Exception x) {
x.printStackTrace();
}
reportRunTime("Get all installed modules.");
// append installed units
Map<String, UpdateUnit> mappedImpl = appendUpdateItems(new HashMap<String, UpdateUnit>(), InstalledModuleProvider.getDefault());
reportRunTime("Append installed units.");
for (UpdateUnitProvider up : updates) {
UpdateUnitProviderImpl impl = Trampoline.API.impl(up);
// append units from provider
mappedImpl = appendUpdateItems(mappedImpl, impl.getUpdateProvider());
reportRunTime("AppendUpdateItems for " + impl.getUpdateProvider().getDisplayName());
}
return mappedImpl;
}
Aggregations