Search in sources :

Example 1 with SpecificationVersion

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

the class ArtificialFeaturesProvider method createFeatureItem.

public static FeatureItem createFeatureItem(String codeName, Set<ModuleUpdateElementImpl> modules, Set<FeatureUpdateElementImpl> features, UpdateElementImpl original, String additionalDescription) {
    Set<String> containsModulesOrFeatures = new HashSet<String>();
    String versionN = "";
    for (ModuleUpdateElementImpl impl : modules) {
        ModuleInfo info = impl.getModuleInfo();
        containsModulesOrFeatures.add(info.getCodeName() + " > " + info.getSpecificationVersion());
        SpecificationVersion spec = info.getSpecificationVersion();
        versionN = addVersion(versionN, spec);
    }
    for (FeatureUpdateElementImpl impl : features) {
        containsModulesOrFeatures.add(impl.getCodeName() + " > " + impl.getSpecificationVersion());
        SpecificationVersion spec = impl.getSpecificationVersion();
        versionN = addVersion(versionN, spec);
    }
    String description = original == null || original.getDescription() == null || original.getDescription().length() == 0 ? "" : original.getDescription();
    description = additionalDescription == null || additionalDescription.length() == 0 ? description : description + additionalDescription;
    String displayName = original == null || original.getDisplayName() == null || original.getDisplayName().length() == 0 ? codeName : original.getDisplayName();
    String version = original == null || original.getSpecificationVersion() == null ? versionN : original.getSpecificationVersion().toString();
    return new FeatureItem(codeName, version, containsModulesOrFeatures, displayName, description, null);
}
Also used : SpecificationVersion(org.openide.modules.SpecificationVersion) FeatureUpdateElementImpl(org.netbeans.modules.autoupdate.services.FeatureUpdateElementImpl) ModuleInfo(org.openide.modules.ModuleInfo) HashSet(java.util.HashSet) ModuleUpdateElementImpl(org.netbeans.modules.autoupdate.services.ModuleUpdateElementImpl)

Example 2 with SpecificationVersion

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

the class DependencyChecker method checkDependencyModule.

private static boolean checkDependencyModule(Dependency dep, ModuleInfo module, boolean allowEqual) {
    boolean ok = false;
    if (dep.getName().equals(module.getCodeNameBase()) || dep.getName().equals(module.getCodeName())) {
        if (dep.getComparison() == Dependency.COMPARE_ANY) {
            ok = true;
        } else if (dep.getComparison() == Dependency.COMPARE_SPEC) {
            if (module.getSpecificationVersion() == null) {
                ok = false;
            } else if (new SpecificationVersion(dep.getVersion()).compareTo(module.getSpecificationVersion()) > 0) {
                ok = false;
            } else if (allowEqual && new SpecificationVersion(dep.getVersion()).compareTo(module.getSpecificationVersion()) == 0) {
                ok = true;
            } else {
                ok = true;
            }
        } else {
            // COMPARE_IMPL
            if (module.getImplementationVersion() == null) {
                ok = false;
            } else if (!module.getImplementationVersion().equals(dep.getVersion())) {
                ok = false;
            } else if (dep.getName().indexOf('/') == -1 || module.getCodeName().indexOf('/') != -1) {
                // COMPARE_IMPL with implicit release version specified - see Issue #177737
                if (dep.getName().equals(module.getCodeName())) {
                    // release version specified in both dependency and module codename, and the same - since different release versions are handled separately
                    ok = true;
                } else {
                    ok = false;
                }
            } else {
                ok = true;
            }
        }
    } else {
        // NOI18N
        int dash = dep.getName().indexOf('-');
        if (dash != -1) {
            // Ranged major release version, cf. #19714.
            // NOI18N
            int slash = dep.getName().indexOf('/');
            String cnb = dep.getName().substring(0, slash);
            int relMin = Integer.parseInt(dep.getName().substring(slash + 1, dash));
            int relMax = Integer.parseInt(dep.getName().substring(dash + 1));
            if (cnb.equals(module.getCodeNameBase()) && relMin <= module.getCodeNameRelease() && relMax >= module.getCodeNameRelease()) {
                if (dep.getComparison() == Dependency.COMPARE_ANY) {
                    ok = true;
                } else {
                    // COMPARE_SPEC; COMPARE_IMPL not allowed here
                    if (module.getCodeNameRelease() > relMin) {
                        // Great, skip the spec version.
                        ok = true;
                    } else {
                        // As usual.
                        if (module.getSpecificationVersion() == null) {
                            ok = false;
                        } else if (new SpecificationVersion(dep.getVersion()).compareTo(module.getSpecificationVersion()) > 0) {
                            ok = false;
                        } else if (allowEqual && new SpecificationVersion(dep.getVersion()).compareTo(module.getSpecificationVersion()) > 0) {
                            ok = true;
                        } else {
                            ok = true;
                        }
                    }
                }
            }
        } else if (dep.getName().indexOf('/') != -1) {
            // NOI18N
            // MAJOR RELEASE
            // NOI18N
            String cnb = dep.getName().substring(0, dep.getName().indexOf('/'));
            if (cnb.equals(module.getCodeNameBase())) {
                err.log(Level.FINE, "Unmatched major versions. Dependency " + dep + " doesn't match with module " + module);
                ok = false;
            }
        }
    }
    return ok;
}
Also used : SpecificationVersion(org.openide.modules.SpecificationVersion)

Example 3 with SpecificationVersion

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

the class PersistenceManager method findModule.

/**
 * Searches for module with given code name and specification version.
 * @param codeNameBase unique string base name of the module
 * (without release number)
 * @param spec string form of specification version of the module, null if
 * not important
 * @param strRelease release number of the module or null if not important
 *
 * @return module info of found module or null if module not found
 * (not installed).
 * @deprecated will be replaced by similar method in Modules Open APIs in
 * future releases
 */
@Deprecated
static final ModuleInfo findModule(String codeNameBase, String strRelease, String strSpec) {
    SpecificationVersion spec = null;
    int release = -1;
    if (strRelease != null) {
        try {
            release = Integer.parseInt(strRelease);
        } catch (NumberFormatException nfe) {
            LOG.log(Level.INFO, null, nfe);
        }
    }
    if (strSpec != null) {
        spec = new SpecificationVersion(strSpec);
    }
    Lookup.Result<ModuleInfo> modulesResult = Lookup.getDefault().lookup(new Lookup.Template<ModuleInfo>(ModuleInfo.class));
    for (ModuleInfo curInfo : modulesResult.allInstances()) {
        // spec numbers, if present
        if (curInfo.getCodeNameBase().equals(codeNameBase)) {
            if (((release < 0) && (spec == null)) || (curInfo.getCodeNameRelease() >= release)) {
                return curInfo;
            } else if ((release < 0) || (curInfo.getCodeNameRelease() == release)) {
                if (spec == null) {
                    return curInfo;
                } else {
                    if ((curInfo.getSpecificationVersion() != null) && (curInfo.getSpecificationVersion().compareTo(spec) >= 0)) {
                        return curInfo;
                    }
                }
            }
        }
    }
    return null;
}
Also used : SpecificationVersion(org.openide.modules.SpecificationVersion) ModuleInfo(org.openide.modules.ModuleInfo) Lookup(org.openide.util.Lookup)

Example 4 with SpecificationVersion

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

the class OperationDescriptionStep method getPresentationName.

private static String getPresentationName(String dep) {
    String presentationName = null;
    boolean isPending = false;
    String reason = null;
    if (dep != null && dep.startsWith("module")) {
        // NOI18N
        String codeName = dep.substring(6).trim();
        // NOI18N
        int end = codeName.indexOf('/');
        String releaseVersion = null;
        if (end == -1) {
            // NOI18N
            end = codeName.indexOf(' ');
        } else {
            int spaceIndex = codeName.indexOf(' ');
            int index = (spaceIndex != -1) ? spaceIndex : codeName.length();
            releaseVersion = codeName.substring(end + 1, index).trim();
        }
        if (end != -1) {
            codeName = codeName.substring(0, end);
        }
        int greater = dep.indexOf('>');
        int equals = dep.indexOf('=');
        int idx = Math.max(greater, equals);
        String version = null;
        if (idx > 0) {
            version = dep.substring(idx + 2).trim();
        }
        UpdateElement other = null;
        for (UpdateUnit u : UpdateManager.getDefault().getUpdateUnits(UpdateManager.TYPE.MODULE)) {
            if (codeName.equals(u.getCodeName())) {
                if (u.getInstalled() != null) {
                    other = u.getInstalled();
                } else if (u.getAvailableUpdates().size() > 0) {
                    other = u.getAvailableUpdates().get(0);
                }
                if (u != null) {
                    isPending = u.isPending();
                }
                break;
            }
        }
        if (idx == -1) {
            // COMPARE_ANY
            // The module named {0} was needed and not found.
            reason = getBundle("OperationDescriptionStep_BrokenModuleNameDep", other == null ? codeName : other.getDisplayName());
        } else if (greater > 0) {
            // COMPARE_SPEC
            if (version != null && other != null && version.equals(other.getSpecificationVersion())) {
                // The module {0} would also need to be installed.
                reason = getBundle("OperationDescriptionStep_BrokenModuleDep", other.getDisplayName());
            } else if (version != null) {
                if (other != null) {
                    // The module {0} was requested in version >= {1} but only {2} was found.
                    int compare = new SpecificationVersion(other.getSpecificationVersion()).compareTo(new SpecificationVersion(version));
                    if (releaseVersion != null && (equals > 0 ? (compare >= 0) : (compare > 0))) {
                        reason = getBundle("OperationDescriptionStep_BrokenModuleReleaseVersionDep", other.getDisplayName(), version, releaseVersion, other.getSpecificationVersion());
                    } else {
                        reason = getBundle("OperationDescriptionStep_BrokenModuleVersionDep", other.getDisplayName(), version, other.getSpecificationVersion());
                    }
                } else {
                    // The module {0} was requested in version >= {1}.
                    reason = getBundle("OperationDescriptionStep_BrokenModuleOnlyVersionDep", codeName, version);
                }
            } else {
                // The module {0} would also need to be installed.
                reason = getBundle("OperationDescriptionStep_BrokenModuleDep", other == null ? codeName : other.getDisplayName());
            }
        } else if (equals > 0) {
            // The module {0} was requested in implementation version "{1}".
            if (version != null) {
                reason = getBundle("OperationDescriptionStep_BrokenModuleImplDep", other == null ? codeName : other.getDisplayName(), version);
            } else {
                reason = getBundle("OperationDescriptionStep_BrokenModuleDep", other == null ? codeName : other.getDisplayName());
            }
        }
        if (isPending) {
            presentationName = getBundle(// NOI18N
            "OperationDescriptionStep_BrokenPendingModuleDepInit", // NOI18N
            other == null ? codeName : other.getDisplayName(), reason);
        } else {
            presentationName = getBundle(// NOI18N
            "OperationDescriptionStep_BrokenModuleDepInit", // NOI18N
            other == null ? codeName : other.getDisplayName(), reason);
        }
    } else if (dep != null && (dep.toLowerCase().startsWith("requires") || dep.toLowerCase().startsWith("needs"))) {
        // NOI18N
        // No module providing the capability {0} could be found.
        String token = dep.substring(dep.indexOf(' ') + 1);
        presentationName = getBundle("OperationDescriptionStep_BrokenRequireDepInit", token, getBundle("OperationDescriptionStep_BrokenRequiresDep", token));
    } else if (dep != null && dep.toLowerCase().startsWith("java")) {
        // NOI18N
        presentationName = getBundle("OperationDescriptionStep_BrokenJavaDepInit", dep, getBundle("OperationDescriptionStep_PluginBrokesJavaDependency", dep, Dependency.JAVA_SPEC));
    } else if (dep != null && dep.toLowerCase().startsWith("package")) {
        // NOI18N
        presentationName = getBundle("OperationDescriptionStep_BrokenPackageDepInit");
    }
    return presentationName == null ? dep : presentationName;
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) SpecificationVersion(org.openide.modules.SpecificationVersion)

Example 5 with SpecificationVersion

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

the class NbLoaderPool method readPool.

/**
 * Reads loader from the input stream.
 * @param ois object input stream to read from
 */
private static synchronized void readPool(ObjectInputStream ois, NbLoaderPool pool) throws IOException, ClassNotFoundException {
    /*installBefores = (Map)*/
    ois.readObject();
    /*installAfters = (Map)*/
    ois.readObject();
    HashSet<Class> classes = new HashSet<Class>();
    LinkedList<DataLoader> l = new LinkedList<DataLoader>();
    Iterator<? extends ModuleInfo> mit = Lookup.getDefault().lookupAll(ModuleInfo.class).iterator();
    Map<String, ModuleInfo> modules = new HashMap<String, ModuleInfo>();
    while (mit.hasNext()) {
        ModuleInfo m = mit.next();
        modules.put(m.getCodeNameBase(), m);
    }
    for (; ; ) {
        Object o1 = ois.readObject();
        if (o1 == null) {
            if (err.isLoggable(Level.FINE))
                err.fine("reading null");
            break;
        }
        NbMarshalledObject obj;
        if (o1 instanceof String) {
            String name = (String) o1;
            if (name.length() > 0 && name.charAt(0) == '=') {
                // NOI18N
                // #27190: unmodified loader, just here for the ordering.
                String cname = name.substring(1);
                DataLoader dl = names2Loaders.get(cname);
                if (dl != null) {
                    if (err.isLoggable(Level.FINE))
                        err.fine("reading unmodified " + cname);
                    l.add(dl);
                    classes.add(dl.getClass());
                } else {
                    // No such known loaded - presumably disabled module.
                    if (err.isLoggable(Level.FINE))
                        err.fine("skipping unmodified nonexistent " + cname);
                }
                continue;
            }
            // Module information.
            int rel = ois.readInt();
            String spec = (String) ois.readObject();
            obj = (NbMarshalledObject) ois.readObject();
            ModuleInfo m = modules.get(name);
            if (m == null) {
                if (err.isLoggable(Level.FINE))
                    err.fine("No known module " + name + ", skipping loader");
                continue;
            }
            if (!m.isEnabled()) {
                if (err.isLoggable(Level.FINE))
                    err.fine("Module " + name + " is disabled, skipping loader");
                continue;
            }
            if (m.getCodeNameRelease() < rel) {
                if (err.isLoggable(Level.FINE))
                    err.fine("Module " + name + " is too old (major vers.), skipping loader");
                continue;
            }
            if (spec != null) {
                SpecificationVersion v = m.getSpecificationVersion();
                if (v == null || v.compareTo(new SpecificationVersion(spec)) < 0) {
                    if (err.isLoggable(Level.FINE))
                        err.fine("Module " + name + " is too old (spec. vers.), skipping loader");
                    continue;
                }
            }
            if (err.isLoggable(Level.FINE))
                err.fine("Module " + name + " is OK, will try to restore loader");
        } else {
            // Loader with no known module, or backward compatibility.
            obj = (NbMarshalledObject) o1;
        }
        Exception t = null;
        try {
            DataLoader loader = (DataLoader) obj.get();
            if (loader == null) {
                // issue 38658)
                continue;
            }
            Class<?> clazz = loader.getClass();
            if (err.isLoggable(Level.FINE))
                err.fine("reading modified " + clazz.getName());
            l.add(loader);
            classes.add(clazz);
        } catch (IOException ex) {
            t = ex;
        } catch (ClassNotFoundException ex) {
            t = ex;
        }
    }
    // Read system loaders. But not into any particular order.
    for (; ; ) {
        NbMarshalledObject obj = (NbMarshalledObject) ois.readObject();
        if (obj == null) {
            if (err.isLoggable(Level.FINE))
                err.fine("reading null");
            break;
        }
        Exception t = null;
        try {
            // Just reads its shared state, nothing more.
            DataLoader loader = (DataLoader) obj.get();
            if (err.isLoggable(Level.FINE))
                err.fine("reading " + loader.getClass().getName());
        } catch (IOException ex) {
            t = ex;
        } catch (ClassNotFoundException ex) {
            t = ex;
        }
    }
    if (err.isLoggable(Level.FINE))
        err.fine("done reading");
    // Explanation: modules are permitted to restoreDefault () before
    // the loader pool is de-externalized. This means that all loader manifest
    // sections will add a default-instance entry to the pool at startup
    // time. Later, when the pool is restored, this may reorder existing ones,
    // as well as change properties. But if any loader is missing (typically
    // due to failed deserialization), it will nonetheless be added to the end
    // now (and the pool resorted just in case).
    Iterator it = loaders.iterator();
    while (it.hasNext()) {
        DataLoader loader = (DataLoader) it.next();
        if (!classes.contains(loader.getClass())) {
            l.add(loader);
        }
    }
    // NOI18N
    if (l.size() > new HashSet<DataLoader>(l).size())
        throw new IllegalStateException("Duplicates in " + l);
    loaders = l;
    // Always "resort": if the existing order was in fact compatible with the
    // current install-befores/afters, then this is no op (besides firing an
    // update event). Cf. #29671.
    resort(pool);
}
Also used : SpecificationVersion(org.openide.modules.SpecificationVersion) HashMap(java.util.HashMap) IOException(java.io.IOException) LinkedList(java.util.LinkedList) IOException(java.io.IOException) DataLoader(org.openide.loaders.DataLoader) ModuleInfo(org.openide.modules.ModuleInfo) NbMarshalledObject(org.openide.util.io.NbMarshalledObject) Iterator(java.util.Iterator) FileObject(org.openide.filesystems.FileObject) NbMarshalledObject(org.openide.util.io.NbMarshalledObject) HashSet(java.util.HashSet)

Aggregations

SpecificationVersion (org.openide.modules.SpecificationVersion)19 ModuleInfo (org.openide.modules.ModuleInfo)7 Module (org.netbeans.Module)5 Dependency (org.openide.modules.Dependency)5 HashSet (java.util.HashSet)4 ArrayList (java.util.ArrayList)3 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 DataLoader (org.openide.loaders.DataLoader)2 NbMarshalledObject (org.openide.util.io.NbMarshalledObject)2 File (java.io.File)1 Comparator (java.util.Comparator)1 Enumeration (java.util.Enumeration)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 StringTokenizer (java.util.StringTokenizer)1 TreeSet (java.util.TreeSet)1