Search in sources :

Example 1 with Module

use of org.netbeans.Module 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;
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) DummyModuleInfo(org.netbeans.modules.autoupdate.updateprovider.DummyModuleInfo) Module(org.netbeans.Module)

Example 2 with Module

use of org.netbeans.Module in project netbeans-rcp-lite by outersky.

the class Utilities method filterDependingOnOtherProvider.

private static Set<Module> filterDependingOnOtherProvider(Module m, Set<Module> modules) {
    Set<Module> alive = new HashSet<Module>();
    for (String token : m.getProvides()) {
        for (Module depM : modules) {
            for (Dependency dep : depM.getDependencies()) {
                if (dep.getType() == Dependency.TYPE_REQUIRES || dep.getType() == Dependency.TYPE_NEEDS) {
                    if (token.equals(dep.getName())) {
                        // check other installed providers
                        assert UpdateManagerImpl.getInstance().getInstalledProviders(token).contains(m) : "Provides of token " + token + " " + UpdateManagerImpl.getInstance().getInstalledProviders(token) + " contains " + m;
                        if (UpdateManagerImpl.getInstance().getInstalledProviders(token).size() > 1) {
                            alive.add(depM);
                        }
                    }
                }
            }
        }
    }
    modules.removeAll(alive);
    return modules;
}
Also used : Module(org.netbeans.Module)

Example 3 with Module

use of org.netbeans.Module in project netbeans-rcp-lite by outersky.

the class Utilities method getModuleInstance.

private static Module getModuleInstance(String codeNameBase, SpecificationVersion specificationVersion) {
    ModuleInfo mi = ModuleCache.getInstance().find(codeNameBase);
    if (mi instanceof Module) {
        Module m = (Module) mi;
        if (specificationVersion == null) {
            err.log(Level.FINE, "no module {0} for null version", m);
            return m;
        } else {
            SpecificationVersion version = m.getSpecificationVersion();
            if (version == null) {
                err.log(Level.FINER, "No version for {0}", m);
                return null;
            }
            final int res = version.compareTo(specificationVersion);
            err.log(Level.FINER, "Comparing versions: {0}.compareTo({1}) = {2}", new Object[] { version, specificationVersion, res });
            return res >= 0 ? m : null;
        }
    }
    return null;
}
Also used : DummyModuleInfo(org.netbeans.modules.autoupdate.updateprovider.DummyModuleInfo) Module(org.netbeans.Module)

Example 4 with Module

use of org.netbeans.Module 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;
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) ModuleInfo(org.openide.modules.ModuleInfo) TreeSet(java.util.TreeSet) Module(org.netbeans.Module) HashSet(java.util.HashSet)

Example 5 with Module

use of org.netbeans.Module in project netbeans-rcp-lite by outersky.

the class JaveleonModuleReloader method setupClassLoaderForJaveleonModule.

private void setupClassLoaderForJaveleonModule(ModuleManager mgr, JaveleonModule javeleonModule) throws InvalidException {
    try {
        // Calculate the parents to initialize the classloader with.
        Dependency[] dependencies = javeleonModule.getDependenciesArray();
        Set<Module> parents = new HashSet<Module>(dependencies.length * 4 / 3 + 1);
        for (Dependency dep : dependencies) {
            if (dep.getType() != Dependency.TYPE_MODULE) {
                // But you cannot automatically access classes from it.
                continue;
            }
            String name = (String) Util.parseCodeName(dep.getName())[0];
            Module parent = mgr.get(name);
            // Should not happen:
            if (parent == null) {
                // NOI18N
                throw new IOException("Parent " + name + " not found!");
            }
            parents.add(parent);
        }
        javeleonModule.classLoaderUp(parents);
    // classLoader.append(new ClassLoader[]{javeleonModule.getClassLoader()});
    } catch (IOException ioe) {
        InvalidException ie = new InvalidException(javeleonModule, ioe.toString());
        ie.initCause(ioe);
        throw ie;
    }
}
Also used : InvalidException(org.netbeans.InvalidException) Dependency(org.openide.modules.Dependency) IOException(java.io.IOException) JaveleonModule(org.netbeans.JaveleonModule) Module(org.netbeans.Module) HashSet(java.util.HashSet)

Aggregations

Module (org.netbeans.Module)43 HashSet (java.util.HashSet)12 IOException (java.io.IOException)10 File (java.io.File)9 InvalidException (org.netbeans.InvalidException)9 Dependency (org.openide.modules.Dependency)9 JaveleonModule (org.netbeans.JaveleonModule)6 ArrayList (java.util.ArrayList)5 JarFile (java.util.jar.JarFile)5 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)5 SpecificationVersion (org.openide.modules.SpecificationVersion)5 URL (java.net.URL)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4 TreeSet (java.util.TreeSet)4 UpdateUnit (org.netbeans.api.autoupdate.UpdateUnit)4 DummyModuleInfo (org.netbeans.modules.autoupdate.updateprovider.DummyModuleInfo)4 TreeMap (java.util.TreeMap)3 ModuleInfo (org.openide.modules.ModuleInfo)3 Collection (java.util.Collection)2