public @Override File locate(String rp, String cnb, boolean l) { InstalledFileLocator[] ifls = getInstances(); for (int i = 0; i < ifls.length; i++) { File f = ifls[i].locate(rp, cnb, l); if (f != null) { return f; } } return null; } public @Override Set<File> locateAll(String relativePath, String codeNameBase, boolean localized) {
/** Get a localized display name, if available. * As a fallback provides the code name (base). * Convenience method only. */ public String getDisplayName() { String dn = (String) getLocalizedAttribute("OpenIDE-Module-Name"); // NOI18N if (dn != null) { return dn; } return getCodeNameBase(); }
/** The identification of the build version. Usually build number. * If no specific build version is provided then this method delegates to {@link #getImplementationVersion}. * * @return textual identification of build version or the value for implementation version * @since 4.18 */ public String getBuildVersion() { String bld = (String) getAttribute("OpenIDE-Module-Build-Version"); // NOI18N return (bld == null) ? getImplementationVersion() : bld; }
new SpecificationVersion(version); } catch (NumberFormatException nfe) { throw new IllegalArgumentException(nfe.toString()); checkCodeName(name, true); checkCodeName(name.substring(0, idx), false); checkCodeName(name.substring(idx + 1, name.length() - 1), false); } else { checkCodeName(name, false); checkCodeName(name, false); } else if (type == Dependency.TYPE_NEEDS) { if (comparison != Dependency.COMPARE_ANY) { checkCodeName(name, false); } else if (type == Dependency.TYPE_RECOMMENDS) { if (comparison != Dependency.COMPARE_ANY) { checkCodeName(name, false); } else { throw new IllegalArgumentException("unknown type"); // NOI18N Dependency nue = new Dependency(type, name, comparison, version); DependencyKey key = new DependencyKey(nue);
/** Try to make a specification version from a string. * Deal with errors gracefully and try to recover something from it. * E.g. "1.4.0beta" is technically erroneous; correct to "1.4.0". */ private static SpecificationVersion makeSpec(String vers) { if (vers != null) { try { return new SpecificationVersion(vers); } catch (NumberFormatException nfe) { System.err.println("WARNING: invalid specification version: " + vers); // NOI18N } do { vers = vers.substring(0, vers.length() - 1); try { return new SpecificationVersion(vers); } catch (NumberFormatException nfe) { // ignore } } while (vers.length() > 0); } // Nothing decent in it at all; use zero. return new SpecificationVersion("0"); // NOI18N }
/** * @deprecated Use {@link #restored} instead. */ @Deprecated public void installed() { restored(); }
/** * Locates the NetBeans cache directory. * This may be used to store pure performance caches - files which could be safely deleted, * since they would be automatically recreated on demand. * Each module is responsible for using sufficiently unique filenames within this directory. * {@code $userdir/var/cache/} is used as a default when {@link #getUserDirectory} is configured. * As a final fallback, a location in the system temporary directory will be returned. * @return a directory location (never null but need not yet exist) * @see #getCacheSubdirectory * @see #getCacheSubfile */ public static synchronized /*@NonNull*/ File getCacheDirectory() { Places places = Lookup.getDefault().lookup(Places.class); if (places != null) { File cache = places.findCacheDirectory(); if (cache != null) { return cache; } } File userdir = getUserDirectory(); if (userdir != null) { return new File(new File(userdir, "var"), "cache"); } return new File(System.getProperty("java.io.tmpdir"), "nbcache"); }
@OnStop public static class Reporter implements Runnable { @Override public void run() { if (!extensionsToInclude.isEmpty()) { for (FileStatistics fileStatistics : instances.values()) { fileStatistics.report(); } } } }
/** * Convenience method to get a particular subdirectory within {@link #getCacheDirectory}. * The directory will be created if it does not yet exist (but a warning logged if permissions do not allow this). * @param path a subdirectory path such as {@code stuff} or {@code mymodule/stuff} ({@code /} permitted even on Windows) * @return a directory of that name within the general cache directory */ public static /*@NonNull*/ File getCacheSubdirectory(String path) { File d = new File(getCacheDirectory(), path); if (!d.isDirectory() && !d.mkdirs()) { LOG.log(Level.WARNING, "could not create {0}", d); } return d; }
/** The implementation version, or null. * Convenience method only. */ public String getImplementationVersion() { return (String) getAttribute("OpenIDE-Module-Implementation-Version"); // NOI18N }
/** Parse from string. Must be Dewey-decimal. */ public SpecificationVersion(String version) throws NumberFormatException { synchronized (parseCache) { int[] d = parseCache.get(version); if (d == null) { d = parse(version); parseCache.put(version.intern(), d); } digits = d; } }
public @Override ModuleInfo ownerOf(Class<?> clazz) { for (ModuleInfo module : Lookup.getDefault().lookupAll(ModuleInfo.class)) { if (module.owns(clazz)) { return module; } } return null; }
public @Override Set<File> locateAll(String relativePath, String codeNameBase, boolean localized) { Set<File> result = null; for (InstalledFileLocator ifl : getInstances()) { Set<File> added = ifl.locateAll(relativePath, codeNameBase, localized); // avoid allocating extra lists, under the assumption there is only one result: if (!added.isEmpty()) { if (result == null) { result = added; } else { result = new LinkedHashSet<File>(result); result.addAll(added); } } } return result != null ? result : Collections.<File>emptySet(); } };
/** * Gets the singleton set of modules. * An implementation of this service should be registered by the module system. * The fallback implementation implements {@link #ownerOf} using a linear search. * @return the default instance */ public static Modules getDefault() { Modules impl = Lookup.getDefault().lookup(Modules.class); if (impl == null) { impl = new Trivial(); } return impl; }
/** * Locates the NetBeans user directory. * This may be used to persist valuable files for which the system filesystem * ({@code FileUtil.getConfigFile}) is inappropriate due its being virtual. * Each module is responsible for using sufficiently unique filenames within this directory. * The system property {@link #USER_DIR_PROP} is used for compatibility. * @return a directory location (need not yet exist), or null if unconfigured */ public static synchronized /*@CheckForNull*/ File getUserDirectory() { Places places = Lookup.getDefault().lookup(Places.class); if (places != null) { return places.findUserDirectory(); } String p = System.getProperty("netbeans.user"); return p != null ? new File(p) : null; }
/** * Similar to {@link #locate} but can return multiple results. * The default implementation returns a list with zero or one elements according to {@link #locate}. * @param relativePath a path from install root * @param codeNameBase name of the supplying module or null * @param localized true to perform a localized/branded search * @return a (possibly empty) set of files * @since org.openide.modules 7.15 */ public Set<File> locateAll(String relativePath, String codeNameBase, boolean localized) { File f = locate(relativePath, codeNameBase, localized); return f != null ? Collections.singleton(f) : Collections.<File>emptySet(); }
/** * @deprecated Use {@link #restored} instead. */ @Deprecated public void updated(int release, String specVersion) { restored(); }
@OnStop public static final class ModuleStop implements Runnable { @Override public void run() { close(); } }
/** * Convenience method to get a particular file within {@link #getCacheDirectory}. * The parent directory will be created if it does not yet exist (but a warning logged if permissions do not allow this); * the file itself will not be automatically created. * @param path a file path such as {@code stuff.ser} or {@code mymodule/stuff.ser} ({@code /} permitted even on Windows) * @return a file of that name within the general cache directory */ public static /*@NonNull*/ File getCacheSubfile(String path) { File f = new File(getCacheDirectory(), path); File d = f.getParentFile(); if (!d.isDirectory() && !d.mkdirs()) { LOG.log(Level.WARNING, "could not create {0}", d); } return f; }