Java Code Examples for org.openide.modules.InstalledFileLocator#getDefault()

The following examples show how to use org.openide.modules.InstalledFileLocator#getDefault() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AntBridge.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Get a map from enabled module code name bases to class loaders containing
 * JARs from ant/nblib/*.jar.
 */
private static Map<String,ClassLoader> createCustomDefClassLoaders(ClassLoader main) throws IOException {
    Map<String,ClassLoader> m = new HashMap<String,ClassLoader>();
    ModuleInfo[] modules = miscListener.getEnabledModules();
    InstalledFileLocator ifl = InstalledFileLocator.getDefault();
    for (ModuleInfo module : modules) {
        String cnb = module.getCodeNameBase();
        String cnbDashes = cnb.replace('.', '-');
        File lib = ifl.locate("ant/nblib/" + cnbDashes + ".jar", cnb, false); // NOI18N
        if (lib == null) {
            if (main.getResource(cnb.replace('.', '/') + "/antlib.xml") != null) { // NOI18N
                // Run-in-classpath mode.
                m.put(cnb, main);
            }
            continue;
        }
        ClassLoader l = createAuxClassLoader(lib, main, module.getClassLoader());
        m.put(cnb, l);
    }
    return m;
}
 
Example 2
Source File: LocaleVariants.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Find a path such that InstalledFileLocator.getDefault().locate(path, null, false)
 * yields the given file. Only guaranteed to work in case the logical path is a suffix of
 * the file's absolute path (after converting path separators); otherwise there is no
 * general way to invert locate(...) so this heuristic may fail. However for the IFL
 * implementation used in a plain NB installation (i.e.
 * org.netbeans.core.modules.InstalledFileLocatorImpl), this condition will in fact hold.
 * @return the inverse of locate(...), or null if there is no such path
 * @see "#34069"
 */
private static String findLogicalPath(File f, String codeNameBase) {
    InstalledFileLocator l = InstalledFileLocator.getDefault();
    String path = f.getName();
    File parent = f.getParentFile();
    while (parent != null) {
        File probe = l.locate(path, codeNameBase, false);
        //System.err.println("Util.fLP: f=" + f + " parent=" + parent + " probe=" + probe + " f.equals(probe)=" + f.equals(probe));
        if (f.equals(probe)) {
            return path;
        }
        path = parent.getName() + '/' + path;
        parent = parent.getParentFile();
    }
    return null;
}
 
Example 3
Source File: ParserLoader.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Bootstrapping method.
 * @return ParserLoader or null if library can not be located
 */
public static synchronized ParserLoader getInstance() {
                    
    if (instance != null) return instance;
    
    try {
        InstalledFileLocator installedFileLocator = InstalledFileLocator.getDefault();

        URL xer2url = installedFileLocator.locate(XERCES_ARCHIVE, CODENAME_BASE, false).toURL(); // NOI18N
        if ( Util.THIS.isLoggable() ) Util.THIS.debug ("Isolated library URL=" + xer2url); // NOI18N

        // The isolating classloader itself (not parent) must also see&load interface
        // implementation class because all subsequent classes must be loaded by the
        // isolating classloader (not its parent that does not see isolated jar)
        URL module = installedFileLocator.locate(MODULE_ARCHIVE, CODENAME_BASE, false).toURL(); // NOI18N
        if ( Util.THIS.isLoggable() ) Util.THIS.debug ("Isolated module URL=" + module); // NOI18N

        instance = new ParserLoader(new URL[] {xer2url, module});

    } catch (MalformedURLException ex) {
        if ( Util.THIS.isLoggable() )  Util.THIS.debug (ex);
    }
           
    return instance;
}
 
Example 4
Source File: TomcatInstallUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Return the CATALINA_HOME directory of the bundled Tomcat
 *
 * @return the CATALINA_HOME directory of the bundled Tomcat, <code>null</code>
 *         if the CATALINA_HOME directory does not exist which should never happen.
 */
public static File getBundledHome() {
    FileObject fo = FileUtil.getConfigFile(TomcatProperties.BUNDLED_TOMCAT_SETTING);
    if (fo != null) {
        InstalledFileLocator ifl = InstalledFileLocator.getDefault();
        return ifl.locate(fo.getAttribute("bundled_home").toString(), null, false); // NOI18N
    }
    return null;
}
 
Example 5
Source File: WebInspectorJNIBinding.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private WebInspectorJNIBinding() {
    this.writeLock = new Object();
    this.readLock = new Object();
    
    final InstalledFileLocator locator = InstalledFileLocator.getDefault();
    System.load(locator.locate("bin/libplist.1.dylib", CODE_BASE, false).getPath());
    System.load(locator.locate("bin/libimobiledevice.4.dylib", CODE_BASE, false).getPath());
    System.load(locator.locate("bin/libusbmuxd.2.dylib", CODE_BASE, false).getPath());
    System.load(locator.locate("bin/libiDeviceNativeBinding.dylib", CODE_BASE, false).getPath());
}
 
Example 6
Source File: StandardModule.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Look up a native library as described in modules documentation.
 * @see http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#jni
 */
protected @Override String findLibrary(String libname) {
    InstalledFileLocator ifl = InstalledFileLocator.getDefault();
    String arch = System.getProperty("os.arch"); // NOI18N
    String system = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); // NOI18N
    String mapped = System.mapLibraryName(libname);
    File lib;

    lib = ifl.locate("modules/lib/" + mapped, getCodeNameBase(), false); // NOI18N
    if (lib != null) {
        CL_LOG.log(Level.FINE, "found {0}", lib);
        return lib.getAbsolutePath();
    }

    lib = ifl.locate("modules/lib/" + arch + "/" + mapped, getCodeNameBase(), false); // NOI18N
    if (lib != null) {
        CL_LOG.log(Level.FINE, "found {0}", lib);
        return lib.getAbsolutePath();
    }

    lib = ifl.locate("modules/lib/" + arch + "/" + system + "/" + mapped, getCodeNameBase(), false); // NOI18N
    if (lib != null) {
        CL_LOG.log(Level.FINE, "found {0}", lib);
        return lib.getAbsolutePath();
    }
    
    if( BaseUtilities.isMac() ) {
        String jniMapped = mapped.replaceFirst("\\.dylib$",".jnilib");
        lib = ifl.locate("modules/lib/" + jniMapped, getCodeNameBase(), false); // NOI18N
        if (lib != null) {
            CL_LOG.log(Level.FINE, "found {0}", lib);
            return lib.getAbsolutePath();
        }

        lib = ifl.locate("modules/lib/" + arch + "/" + jniMapped, getCodeNameBase(), false); // NOI18N
        if (lib != null) {
            CL_LOG.log(Level.FINE, "found {0}", lib);
            return lib.getAbsolutePath();
        }

        lib = ifl.locate("modules/lib/" + arch + "/" + system + "/" + jniMapped, getCodeNameBase(), false); // NOI18N
        if (lib != null) {
            CL_LOG.log(Level.FINE, "found {0}", lib);
            return lib.getAbsolutePath();
        }
        CL_LOG.log(Level.FINE, "found nothing like modules/lib/{0}/{1}/{2}", new Object[] {arch, system, jniMapped});
    }

    CL_LOG.log(Level.FINE, "found nothing like modules/lib/{0}/{1}/{2}", new Object[] {arch, system, mapped});
    return null;
}
 
Example 7
Source File: InstalledFileLocatorProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static InstalledFileLocator getDefault() {
    return InstalledFileLocator.getDefault();
}
 
Example 8
Source File: MemoryHistogramProvider.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private String getAgentPath() {
    InstalledFileLocator loc = InstalledFileLocator.getDefault();
    File jar = loc.locate(AGENT_PATH, "org.graalvm.visualvm.sampler.truffle", false);   // NOI18N

    return jar.getAbsolutePath();
}
 
Example 9
Source File: ThreadInfoProvider.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private String getAgentPath() {
    InstalledFileLocator loc = InstalledFileLocator.getDefault();
    File jar = loc.locate(AGENT_PATH, "org.graalvm.visualvm.sampler.truffle", false);   // NOI18N

    return jar.getAbsolutePath();
}