Search in sources :

Example 1 with Dependency

use of org.openide.modules.Dependency in project netbeans-rcp-lite by outersky.

the class ModuleManager method clearProblemCache.

private void clearProblemCache(Map<Module, Set<Union2<Dependency, InvalidException>>> mP) {
    Iterator<Map.Entry<Module, Set<Union2<Dependency, InvalidException>>>> it = mP.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<Module, Set<Union2<Dependency, InvalidException>>> entry = it.next();
        Module m = entry.getKey();
        if (!m.isEnabled()) {
            Set<Union2<Dependency, InvalidException>> s = entry.getValue();
            if (s != null) {
                boolean clear = false;
                for (Union2<Dependency, InvalidException> problem : s) {
                    if (problem.hasSecond()) {
                        // Hard problem, skip this one.
                        continue;
                    }
                    Dependency dep = problem.first();
                    if (dep.getType() != Dependency.TYPE_MODULE && dep.getType() != Dependency.TYPE_REQUIRES && dep.getType() != Dependency.TYPE_NEEDS && dep.getType() != Dependency.TYPE_RECOMMENDS) {
                        // Also a hard problem.
                        continue;
                    }
                    // Some soft problems found, i.e. module deps. Clear them all.
                    // #76917: Even clear any hard problems.
                    clear = true;
                    break;
                }
                if (clear || s.isEmpty()) {
                    // leave alone only if all hard problems
                    it.remove();
                    firer.change(new ChangeFirer.Change(m, Module.PROP_PROBLEMS, null, null));
                }
            }
        // if we never computed anything, make no change now
        }
    // enabled modules are definitely OK, no change there
    }
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Union2(org.openide.util.Union2) Dependency(org.openide.modules.Dependency) Map(java.util.Map) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap)

Example 2 with Dependency

use of org.openide.modules.Dependency in project netbeans-rcp-lite by outersky.

the class ModuleManager method maybeAddToEnableList.

private void maybeAddToEnableList(Set<Module> willEnable, Set<Module> mightEnable, Module m, boolean okToFail) {
    if (!missingDependencies(m).isEmpty()) {
        if (!okToFail) {
            Util.err.warning("Module " + m + " had unexpected problems: " + missingDependencies(m) + " (willEnable: " + willEnable + " mightEnable: " + mightEnable + ")");
        }
        // Cannot satisfy its dependencies, exclude it.
        return;
    }
    if (!willEnable.add(m)) {
        // Already there, done.
        return;
    }
    // need to register fragments eagerly, so they are available during
    // dependency sort
    Module host = attachModuleFragment(m);
    if (host != null && !host.isEnabled()) {
        maybeAddToEnableList(willEnable, mightEnable, host, okToFail);
    }
    // or already enabled.
    for (Dependency dep : m.getDependenciesArray()) {
        if (dep.getType() == Dependency.TYPE_MODULE) {
            String codeNameBase = (String) Util.parseCodeName(dep.getName())[0];
            Module other = get(codeNameBase);
            // NOI18N
            if (other == null)
                throw new IllegalStateException("Should have found module: " + codeNameBase);
            if (!other.isEnabled()) {
                maybeAddToEnableList(willEnable, mightEnable, other, false);
            }
        } else if (dep.getType() == Dependency.TYPE_REQUIRES || dep.getType() == Dependency.TYPE_NEEDS || dep.getType() == Dependency.TYPE_RECOMMENDS) {
            Set<Module> providers = getProvidersOf().get(dep.getName());
            if (providers == null) {
                assert dep.getType() == Dependency.TYPE_RECOMMENDS : "Should have found a provider of " + dep;
                continue;
            }
            // First check if >= 1 is already enabled or will be soon. If so, great.
            boolean foundOne = false;
            for (Module other : providers) {
                if (other.isEnabled() || (other.getProblems().isEmpty() && mightEnable.contains(other))) {
                    foundOne = true;
                    break;
                }
            }
            if (foundOne) {
                // OK, we are satisfied.
                continue;
            }
            // All disabled. So add them all to the enable list.
            for (Module other : providers) {
                // It is OK if one of them fails.
                maybeAddToEnableList(willEnable, mightEnable, other, true);
                // But we still check to ensure that at least one did not!
                if (!foundOne && willEnable.contains(other)) {
                    foundOne = true;
                // and continue with the others, try to add them too...
                }
            }
            // Logic is that missingDependencies(m) should contain dep in this case.
            assert foundOne || dep.getType() == Dependency.TYPE_RECOMMENDS : "Should have found a nonproblematic provider of " + dep + " among " + providers + " with willEnable=" + willEnable + " mightEnable=" + mightEnable;
        }
    // else some other kind of dependency that does not concern us
    }
    Collection<Module> frags = getAttachedFragments(m);
    for (Module fragMod : frags) {
        if (!fragMod.isEnabled()) {
            maybeAddToEnableList(willEnable, mightEnable, fragMod, fragMod.isEager());
        }
    }
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Dependency(org.openide.modules.Dependency)

Example 3 with Dependency

use of org.openide.modules.Dependency in project netbeans-rcp-lite by outersky.

the class ModuleManager method calculateParents.

private final Set<Module> calculateParents(Module m) throws NumberFormatException, IOException {
    // Calculate the parents to initialize the classloader with.
    Dependency[] dependencies = m.getDependenciesArray();
    Set<Module> res = new HashSet<Module>(dependencies.length * 4 / 3 + 1);
    for (int i = 0; i < dependencies.length; i++) {
        Dependency dep = dependencies[i];
        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 = get(name);
        // Should not happen:
        if (parent == null) {
            // NOI18N
            throw new IOException("Parent " + name + " not found!");
        }
        res.add(parent);
    }
    // dependencies of fragment modules should be injected into the main module.
    Collection<Module> fragments = getAttachedFragments(m);
    if (!fragments.isEmpty()) {
        for (Module frag : fragments) {
            Set<Module> mods = calculateParents(frag);
            mods.remove(m);
            res.addAll(mods);
        }
    }
    return res;
}
Also used : Dependency(org.openide.modules.Dependency) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 4 with Dependency

use of org.openide.modules.Dependency in project netbeans-rcp-lite by outersky.

the class ModuleData method initDeps.

/**
 * Initializes dependencies of this module
 *
 * @param knownDeps Set<Dependency> of this module known from different
 * source, can be null
 * @param attr attributes in manifest to parse if knownDeps is null
 */
private Dependency[] initDeps(Module forModule, Set<?> knownDeps, Attributes attr) throws IllegalStateException, IllegalArgumentException {
    if (knownDeps != null) {
        return knownDeps.toArray(new Dependency[knownDeps.size()]);
    }
    // deps
    Set<Dependency> deps = new HashSet<Dependency>(20);
    // First convert IDE/1 -> org.openide/1, so we never have to deal with
    // "IDE deps" internally:
    @SuppressWarnings(value = "deprecation") Set<Dependency> // NOI18N
    openideDeps = Dependency.create(Dependency.TYPE_IDE, attr.getValue("OpenIDE-Module-IDE-Dependencies"));
    if (!openideDeps.isEmpty()) {
        // If empty, leave it that way; NbInstaller will add it anyway.
        Dependency d = openideDeps.iterator().next();
        String name = d.getName();
        if (!name.startsWith("IDE/")) {
            // NOI18N
            throw new IllegalStateException("Weird IDE dep: " + name);
        }
        // NOI18N
        deps.addAll(Dependency.create(Dependency.TYPE_MODULE, "org.openide/" + name.substring(4) + " > " + d.getVersion()));
        if (deps.size() != 1) {
            // NOI18N
            throw new IllegalStateException("Should be singleton: " + deps);
        }
        // NOI18N
        Util.err.log(Level.WARNING, "the module {0} uses OpenIDE-Module-IDE-Dependencies which is deprecated. See http://openide.netbeans.org/proposals/arch/modularize.html", codeNameBase);
    }
    // NOI18N
    deps.addAll(Dependency.create(Dependency.TYPE_JAVA, attr.getValue("OpenIDE-Module-Java-Dependencies")));
    // NOI18N
    deps.addAll(Dependency.create(Dependency.TYPE_MODULE, attr.getValue("OpenIDE-Module-Module-Dependencies")));
    // NOI18N
    String pkgdeps = attr.getValue("OpenIDE-Module-Package-Dependencies");
    if (pkgdeps != null) {
        // XXX: Util.err.log(ErrorManager.WARNING, "Warning: module " + codeNameBase + " uses the OpenIDE-Module-Package-Dependencies
        // manifest attribute, which is now deprecated: XXX URL TBD");
        // NOI18N
        deps.addAll(Dependency.create(Dependency.TYPE_PACKAGE, pkgdeps));
    }
    // NOI18N
    deps.addAll(Dependency.create(Dependency.TYPE_REQUIRES, attr.getValue("OpenIDE-Module-Requires")));
    // NOI18N
    deps.addAll(Dependency.create(Dependency.TYPE_NEEDS, attr.getValue("OpenIDE-Module-Needs")));
    // NOI18N
    deps.addAll(Dependency.create(Dependency.TYPE_RECOMMENDS, attr.getValue("OpenIDE-Module-Recommends")));
    forModule.refineDependencies(deps);
    return deps.toArray(new Dependency[deps.size()]);
}
Also used : Dependency(org.openide.modules.Dependency) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 5 with Dependency

use of org.openide.modules.Dependency in project netbeans-rcp-lite by outersky.

the class UpdateUnitFactory method addElement.

private void addElement(Map<String, UpdateUnit> impls, UpdateElement element, UpdateProvider provider) {
    // find if corresponding element exists
    UpdateUnit unit = impls.get(element.getCodeName());
    // XXX: it's should be moved in UI what should filter all elements w/ broken dependencies
    // #101515: Plugin Manager must filter updates by platform dependency
    boolean passed = false;
    UpdateElementImpl elImpl = Trampoline.API.impl(element);
    if (elImpl instanceof ModuleUpdateElementImpl && elImpl.getModuleInfos() != null && elImpl.getModuleInfos().size() == 1) {
        for (Dependency d : elImpl.getModuleInfos().get(0).getDependencies()) {
            if (Dependency.TYPE_REQUIRES == d.getType()) {
                // log.log (Level.FINEST, "Dependency: NAME: " + d.getName () + ", TYPE: " + d.getType () + ": " + d.toString ());
                if (d.getName().startsWith("org.openide.modules.os")) {
                    // NOI18N
                    for (ModuleInfo info : InstalledModuleProvider.getInstalledModules().values()) {
                        if (Arrays.asList(info.getProvides()).contains(d.getName())) {
                            log.log(Level.FINEST, element + " which requires OS " + d + " succeed.");
                            passed = true;
                            break;
                        }
                    }
                    if (!passed) {
                        log.log(Level.FINE, element + " which requires OS " + d + " fails.");
                        return;
                    }
                }
            }
        }
    }
    UpdateUnitImpl unitImpl = null;
    if (unit == null) {
        switch(elImpl.getType()) {
            case MODULE:
                unitImpl = new ModuleUpdateUnitImpl(element.getCodeName());
                break;
            case KIT_MODULE:
                unitImpl = new KitModuleUpdateUnitImpl(element.getCodeName());
                break;
            case STANDALONE_MODULE:
            case FEATURE:
                unitImpl = new FeatureUpdateUnitImpl(element.getCodeName(), elImpl.getType());
                break;
            case CUSTOM_HANDLED_COMPONENT:
                unitImpl = new NativeComponentUpdateUnitImpl(element.getCodeName());
                break;
            case LOCALIZATION:
                unitImpl = new LocalizationUpdateUnitImpl(element.getCodeName());
                break;
            default:
                assert false : "Unsupported for type " + elImpl.getType();
        }
        unit = Trampoline.API.createUpdateUnit(unitImpl);
        impls.put(unit.getCodeName(), unit);
    } else {
        unitImpl = Trampoline.API.impl(unit);
    }
    if (provider == InstalledUpdateProvider.getDefault()) {
        if (unitImpl.getInstalled() == null) {
            unitImpl.setInstalled(element);
        }
    } else if (provider instanceof BackupUpdateProvider) {
        unitImpl.setBackup(element);
    } else {
        // suppose common UpdateProvider
        unitImpl.addUpdate(element);
    }
    // set UpdateUnit into element
    elImpl.setUpdateUnit(unit);
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) Dependency(org.openide.modules.Dependency) ModuleInfo(org.openide.modules.ModuleInfo) BackupUpdateProvider(org.netbeans.modules.autoupdate.updateprovider.BackupUpdateProvider)

Aggregations

Dependency (org.openide.modules.Dependency)27 HashSet (java.util.HashSet)16 Module (org.netbeans.Module)9 TreeSet (java.util.TreeSet)8 Set (java.util.Set)7 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 SpecificationVersion (org.openide.modules.SpecificationVersion)5 HashMap (java.util.HashMap)4 InvalidException (org.netbeans.InvalidException)4 File (java.io.File)3 LinkedHashSet (java.util.LinkedHashSet)3 JarFile (java.util.jar.JarFile)3 ModuleInfo (org.openide.modules.ModuleInfo)3 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 StringTokenizer (java.util.StringTokenizer)2 TreeMap (java.util.TreeMap)2 Union2 (org.openide.util.Union2)2 Collection (java.util.Collection)1