org.openide.filesystems.URLMapper Java Examples

The following examples show how to use org.openide.filesystems.URLMapper. 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: WildFlyProperties.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private List<URL> selectJars(FileObject file) {
    if (file == null) {
        return Collections.EMPTY_LIST;
    }
    if (file.isData()) {
        if (file.isValid() && FileUtil.isArchiveFile(file)) {
            URL url = URLMapper.findURL(file, URLMapper.EXTERNAL);
            if (url != null) {
                return Collections.singletonList(FileUtil.getArchiveRoot(url));
            }
        }
        return Collections.EMPTY_LIST;
    }
    List<URL> result = new ArrayList<URL>();
    for (FileObject child : file.getChildren()) {
        result.addAll(selectJars(child));
    }
    return result;
}
 
Example #2
Source File: HttpServerURLMapper.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Get an array of FileObjects for this url
 * @param url to wanted FileObjects
 * @return a suitable array of FileObjects, or null
 */
public FileObject[] getFileObjects(URL url) {
    String path = url.getPath();

    // remove the wrapper servlet URI
    String wrapper = httpserverSettings().getWrapperBaseURL ();
    if (path == null || !path.startsWith(wrapper))
        return null;
    path = path.substring(wrapper.length());
    
    // resource name
    if (path.startsWith ("/")) path = path.substring (1); // NOI18N
    if (path.length() == 0) {
        return new FileObject[0];
    }
    // decode path to EXTERNAL/INTERNAL type of URL
    URL u = decodeURL(path);
    if (u == null) {
        return new FileObject[0];
    }
    return URLMapper.findFileObjects(u);
}
 
Example #3
Source File: WindowManagerParserTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private WindowManagerParser createWMParser (String path, String name) {
    URL url;
    url = WindowManagerParserTest.class.getResource(path);
    assertNotNull("url not found.",url);
    
    FileObject [] foArray = URLMapper.findFileObjects(url);
    assertNotNull("Test parent folder not found. Array is null.",foArray);
    assertTrue("Test parent folder not found. Array is empty.",foArray.length > 0);
    
    FileObject parentFolder = foArray[0];
    assertNotNull("Test parent folder not found. ParentFolder is null.",parentFolder);
    
    PersistenceManager.getDefault().setRootModuleFolder(parentFolder);
    PersistenceManager.getDefault().setRootLocalFolder(parentFolder);
    
    WindowManagerParser wmParser = new WindowManagerParser(PersistenceManager.getDefault(),name);
    
    return wmParser;
}
 
Example #4
Source File: LanguageClientImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void publishDiagnostics(PublishDiagnosticsParams pdp) {
    try {
        FileObject file = URLMapper.findFileObject(new URI(pdp.getUri()).toURL());
        EditorCookie ec = file.getLookup().lookup(EditorCookie.class);
        Document doc = ec != null ? ec.getDocument() : null;
        if (doc == null)
            return ; //ignore...
        List<ErrorDescription> diags = pdp.getDiagnostics().stream().map(d -> {
            LazyFixList fixList = allowCodeActions ? new DiagnosticFixList(pdp.getUri(), d) : ErrorDescriptionFactory.lazyListForFixes(Collections.emptyList());
            return ErrorDescriptionFactory.createErrorDescription(severityMap.get(d.getSeverity()), d.getMessage(), fixList, file, Utils.getOffset(doc, d.getRange().getStart()), Utils.getOffset(doc, d.getRange().getEnd()));
        }).collect(Collectors.toList());
        HintsController.setErrors(doc, LanguageClientImpl.class.getName(), diags);
    } catch (URISyntaxException | MalformedURLException ex) {
        LOG.log(Level.FINE, null, ex);
    }
}
 
Example #5
Source File: JavaTypeProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@CheckForNull
public FileObject getRoot() {
    synchronized (this) {
        if (cachedRoot != null) {
            return cachedRoot;
        }
    }
    final URL root = toURL(rootURI);
    final FileObject _tmp = root == null ?
            null :
            URLMapper.findFileObject(root);
    synchronized (this) {
        if (cachedRoot == null) {
            cachedRoot = _tmp;
        }
    }
    return _tmp;
}
 
Example #6
Source File: HtmlCatalog.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public String getSystemID(String publicId) {
    if (publicId == null){
        return null;
    }
    for(ReaderProvider provider : providers) {
        FileObject systemIdFile = provider.getSystemId(publicId);
        if(systemIdFile != null) {
            URL url = URLMapper.findURL(systemIdFile, URLMapper.INTERNAL);
            if(url != null) {
                return url.toExternalForm();
            }
        }
    }

    return null;
}
 
Example #7
Source File: SourceAnalyzerFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@CheckForNull
private static String getResourceName (@NullAllowed final CompilationUnitTree cu) {
    if (cu instanceof JCTree.JCCompilationUnit) {
        JavaFileObject jfo = ((JCTree.JCCompilationUnit)cu).sourcefile;
        if (jfo != null) {
            URI uri = jfo.toUri();
            if (uri != null && uri.isAbsolute()) {
                try {
                    FileObject fo = URLMapper.findFileObject(uri.toURL());
                    if (fo != null) {
                        ClassPath cp = ClassPath.getClassPath(fo,ClassPath.SOURCE);
                        if (cp != null) {
                            return cp.getResourceName(fo,'.',false);
                        }
                    }
                } catch (MalformedURLException e) {
                    Exceptions.printStackTrace(e);
                }
            }
        }
    }
    return null;
}
 
Example #8
Source File: JavadocForBinaryQueryImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private URL getNormalizedURL (URL url) {
    //URL is already nornalized, return it
    if (isNormalizedURL(url)) {
        return url;
    }
    //Todo: Should listen on the LibrariesManager and cleanup cache
    // in this case the search can use the cache onle and can be faster
    // from O(n) to O(ln(n))
    URL normalizedURL = normalizedURLCache.get(url);
    if (normalizedURL == null) {
        FileObject fo = URLMapper.findFileObject(url);
        if (fo != null) {
            normalizedURL = fo.toURL();
            this.normalizedURLCache.put (url, normalizedURL);
        }
    }
    return normalizedURL;
}
 
Example #9
Source File: OpenProjectListTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Map<Project,Set<String>> close(Project[] projects, boolean notifyUI) {
    
    for (int i = 0; i < projects.length; i++) {
        Set<String> projectOpenFiles = urls4project.get(projects [i]);
        if (projectOpenFiles != null) {
            projectOpenFiles.retainAll (openFiles);
            urls4project.put (projects [i], projectOpenFiles);
            for (String url : projectOpenFiles) {
                FileObject fo = null;
                try {
                    fo = URLMapper.findFileObject (new URL (url));
                    openFiles.remove (fo.toURL ().toExternalForm ());
                } catch (MalformedURLException mue) {
                    fail ("MalformedURLException in " + url);
                }
            }
        }
    }
    
    return urls4project;
}
 
Example #10
Source File: DebuggerTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Line getLine(int line, String remoteFileName, SessionId id) {
    Breakpoint[] breakpoints = DebuggerManager.getDebuggerManager().getBreakpoints();
    for (Breakpoint breakpoint : breakpoints) {
        if (breakpoint instanceof TestLineBreakpoint) {
            TestLineBreakpoint lineBreakpoint = (TestLineBreakpoint) breakpoint;
            Line lineObj = lineBreakpoint.getLine();
            Lookup lkp = lineObj.getLookup();
            FileObject fo = lkp.lookup(FileObject.class);
            try {
                URL remoteURL = new URL(remoteFileName);
                FileObject remoteFo = URLMapper.findFileObject(remoteURL);
                if (remoteFo == fo && line == lineObj.getLineNumber() + 1) {
                    return lineObj;
                }
            } catch (MalformedURLException ex) {
                break;
            }
        }
    }
    return super.getLine(line, remoteFileName, id);
}
 
Example #11
Source File: JavaCustomIndexer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static CompileTuple createTuple(Context context, JavaParsingContext javaContext, Indexable indexable) {
    File root = null;
    if (!context.checkForEditorModifications() && "file".equals(indexable.getURL().getProtocol()) && (root = FileUtil.toFile(context.getRoot())) != null) { //NOI18N
        try {
            return new CompileTuple(
                FileObjects.fileFileObject(
                    indexable,
                    root,
                    javaContext.getJavaFileFilter(),
                    javaContext.getEncoding()),
                indexable);
        } catch (Exception ex) {
            //pass
        }
    }
    FileObject fo = URLMapper.findFileObject(indexable.getURL());
    return fo != null ? new CompileTuple(FileObjects.sourceFileObject(fo, context.getRoot()), indexable) : null;
}
 
Example #12
Source File: J2SEPlatformJavadocForBinaryQueryTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testQuery() throws Exception {
    JavaPlatform platform = JavaPlatform.getDefault();
    ClassPath cp = platform.getBootstrapLibraries();
    FileObject pfo = cp.getRoots()[0];
    URL u = URLMapper.findURL(pfo, URLMapper.EXTERNAL);
    URL urls[] = JavadocForBinaryQuery.findJavadoc(u).getRoots();
    assertEquals(1, urls.length);
    assertTrue(urls[0].toString(), urls[0].toString().startsWith("https://docs.oracle.com/"));

    List<URL> l = new ArrayList<URL>();
    File javadocFile = getBaseDir();
    File api = new File (javadocFile,"api");
    File index = new File (api,"index-files");
    FileUtil.toFileObject(index);
    index.mkdirs();
    l.add(Utilities.toURI(javadocFile).toURL());
    J2SEPlatformImpl platformImpl = (J2SEPlatformImpl)platform;
    platformImpl.setJavadocFolders(l);
    urls = JavadocForBinaryQuery.findJavadoc(u).getRoots();
    assertEquals(1, urls.length);
    assertEquals(Utilities.toURI(api).toURL(), urls[0]);
}
 
Example #13
Source File: GlobalSourceForBinaryImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testListeningToNbPlatform() throws Exception {
    NbPlatform.getDefaultPlatform(); // initBuildProperties
    File nbSrcZip = generateNbSrcZip("");
    URL loadersURL = FileUtil.urlForArchiveOrDir(file("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-loaders.jar"));
    SourceForBinaryQuery.Result res = SourceForBinaryQuery.findSourceRoots(loadersURL);
    assertNotNull("got result", res);
    ResultChangeListener resultCL = new ResultChangeListener();
    res.addChangeListener(resultCL);
    assertFalse("not changed yet", resultCL.changed);
    assertEquals("non source root", 0, res.getRoots().length);
    NbPlatform.getDefaultPlatform().addSourceRoot(FileUtil.urlForArchiveOrDir(nbSrcZip));
    assertTrue("changed yet", resultCL.changed);
    assertEquals("one source root", 1, res.getRoots().length);
    URL loadersSrcURL = new URL(FileUtil.urlForArchiveOrDir(nbSrcZip), "openide/loaders/src/");
    assertRoot(loadersURL, URLMapper.findFileObject(loadersSrcURL));
}
 
Example #14
Source File: CopyClassesUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Problem setParameters(boolean checkOnly) {
    if (panel == null) {
        return null;
    }
    URL url = URLMapper.findURL(panel.getRootFolder(), URLMapper.EXTERNAL);
    try {
        refactoring.setTarget(Lookups.singleton(new URL(url.toExternalForm() + panel.getPackageName().replace('.', '/')))); // NOI18N
    } catch (MalformedURLException ex) {
        Exceptions.printStackTrace(ex);
    }
    if (checkOnly) {
        return refactoring.fastCheckParameters();
    } else {
        return refactoring.checkParameters();
    }
}
 
Example #15
Source File: ProfileSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected final void validateBinaryRoot(
        @NonNull final URL root,
        @NonNull final ViolationCollector collector) {
    final FileObject rootFo = URLMapper.findFileObject(root);
    if (rootFo == null) {
        return;
    }
    final Enumeration<? extends FileObject> children = rootFo.getChildren(true);
    while (children.hasMoreElements()) {
        if (context.isCancelled()) {
            break;
        }
        final FileObject fo = children.nextElement();
        if (isImportant(fo)) {
            validateBinaryFile(fo, collector);
        }
    }
}
 
Example #16
Source File: LineDelegate.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public FileObject getFileObject() {
    if (line instanceof FutureLine) {
        URL url = getURL();
        FileObject fo = URLMapper.findFileObject(url);
        if (fo != null) {
            try {
                DataObject dobj = DataObject.find(fo);
                LineCookie lineCookie = dobj.getLookup().lookup(LineCookie.class);
                if (lineCookie == null) {
                    return null;
                }
                Line l = lineCookie.getLineSet().getCurrent(getLineNumber() - 1);
                setLine(l);
            } catch (DataObjectNotFoundException ex) {
            }
        }
        return fo;
    } else {
        return line.getLookup().lookup(FileObject.class);
    }
}
 
Example #17
Source File: BinaryForSourceQuery.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public URL[] getRoots() {
    FileObject fo = URLMapper.findFileObject(sourceRoot);
    if (fo == null) {
        return new URL[0];
    }
    ClassPath exec = ClassPath.getClassPath(fo, ClassPath.EXECUTE);
    if (exec == null) {
        return new URL[0];
    }           
    Set<URL> result = new HashSet<>();
    for (ClassPath.Entry e : exec.entries()) {
        final URL eurl = e.getURL();
        FileObject[] roots = SourceForBinaryQuery.findSourceRoots(eurl).getRoots();
        for (FileObject root : roots) {
                if (sourceRoot.equals (root.toURL())) {
                    result.add (eurl);
                }
        }
    }
    return result.toArray(new URL[result.size()]);
}
 
Example #18
Source File: JBJ2eePlatformFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isBundled(String classFqn) {
    j2eePlatform.getLibraries();
    for (LibraryImplementation lib : j2eePlatform.getLibraries()) {
        List<URL> urls = lib.getContent(J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH);
        for (URL url: urls) {
            FileObject root = URLMapper.findFileObject(url);
            if ( FileUtil.isArchiveFile(root)){
                root = FileUtil.getArchiveRoot(root);
            }
            String path = classFqn.replace('.', '/')+".class"; //NOI18N
            if ( root.getFileObject(path )!= null ) {
                return true;
            }
        }
    }
    
    return false;
}
 
Example #19
Source File: IdeJaxRsSupportImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isBundled( String classFqn ) {
    Library restapiLibrary = LibraryManager.getDefault().getLibrary(RESTAPI_LIBRARY);
    List<URL> urls = restapiLibrary.getContent("classpath");            // NOI18N
    for( URL url : urls ){
        FileObject root = URLMapper.findFileObject(url);
        if ( FileUtil.isArchiveFile(root)){
            root = FileUtil.getArchiveRoot(root);
        }
        String classFileObject = classFqn.replace('.', '/')+".class";   // NOI18N
        if ( root.getFileObject(classFileObject) != null ){
            return true;
        }
    }
    return false;
}
 
Example #20
Source File: ModuleNamesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public FileObject[] getRoots() {
    final Pair<URL,URL> current = root;
    if (current != null && bin.equals(current.second())) {
        final URL src = current.first();
        final FileObject srcFo = URLMapper.findFileObject(src);
        if (srcFo != null) {
            return new FileObject[] {srcFo};
        }
    }
    return new FileObject[0];
}
 
Example #21
Source File: BreakpointsReader.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private FileObject getFileObject(String url) {
    FileObject file;
    try {
        file = URLMapper.findFileObject(new URL(url));
    } catch (MalformedURLException e) {
        return null;
    }
    return file;
}
 
Example #22
Source File: RefactoringUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static FileObject getRootFileObject(URL url) throws IOException {
    FileObject result = URLMapper.findFileObject(url);
    File f;
    try {
        f = result != null ? null : FileUtil.normalizeFile(Utilities.toFile(url.toURI())); //NOI18N
    } catch (URISyntaxException ex) {
        throw new IOException(ex);
    }
    while (result == null && f != null) {
        result = FileUtil.toFileObject(f);
        f = f.getParentFile();
    }
    return result;
}
 
Example #23
Source File: MavenSettings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static @CheckForNull String getCommandLineMavenVersion(File mavenHome) {
    File[] jars = new File(mavenHome, "lib").listFiles(new FilenameFilter() { // NOI18N
        public @Override boolean accept(File dir, String name) {
            return name.endsWith(".jar"); // NOI18N
        }
    });
    if (jars == null) {
        return null;
    }
    for (File jar : jars) {
        try {
            // Prefer to use this rather than raw ZipFile since URLMapper since ArchiveURLMapper will cache JARs:
            FileObject entry = URLMapper.findFileObject(new URL(FileUtil.urlForArchiveOrDir(jar), "META-INF/maven/org.apache.maven/maven-core/pom.properties")); // NOI18N
            if (entry != null) {
                InputStream is = entry.getInputStream();
                try {
                    Properties properties = new Properties();
                    properties.load(is);
                    return properties.getProperty("version"); // NOI18N
                } finally {
                    is.close();
                }
            }
        } catch (IOException x) {
            // ignore for now
        }
    }
    return null;
}
 
Example #24
Source File: APIIsSelfContainedTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private FileObject[] prepareClasspath() {
    FileObject javaSourceJar = URLMapper.findFileObject(JavaSource.class.getProtectionDomain().getCodeSource().getLocation());
    FileObject root = javaSourceJar.getParent().getParent().getParent();
    
    return new FileObject[] {
        FileUtil.getArchiveRoot(root.getFileObject("java/modules/org-netbeans-modules-java-source.jar")),
    };
}
 
Example #25
Source File: AddConnectionWizard.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize panels representing individual wizard's steps and sets
 * various properties for them influencing wizard appearance.
 */
private WizardDescriptor.Panel<AddConnectionWizard>[] getPanels() {
    if (panels == null) {
        if (jdbcDriver != null) {
            URL[] jars = jdbcDriver.getURLs();
            if (jars != null && jars.length > 0) {
                    FileObject jarFO = URLMapper.findFileObject(jars[0]);
                    if (jarFO != null && jarFO.isValid()) {
                        this.allPrivilegedFileNames.add(jarFO.getNameExt());
                        this.increase = true;
                    }
            }
        }
        driverPanel = new ChoosingDriverPanel(jdbcDriver);
        panels = new Panel[] {
            driverPanel,
            new ConnectionPanel(),
            new ChoosingSchemaPanel(),
            new ChoosingConnectionNamePanel()
        };
        steps = new String[panels.length];
        steps = new String[] {
            NbBundle.getMessage(AddConnectionWizard.class, "ChoosingDriverUI.Name"), // NOI18N
            NbBundle.getMessage(AddConnectionWizard.class, "ConnectionPanel.Name"), // NOI18N
            NbBundle.getMessage(AddConnectionWizard.class, "ChoosingSchemaPanel.Name"), // NOI18N
            NbBundle.getMessage(AddConnectionWizard.class, "ChooseConnectionNamePanel.Name"), // NOI18N
        };
    }
    return panels;
}
 
Example #26
Source File: WLDriverDeployer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Returns a list of jdbc drivers that need to be deployed. */
private List<FileObject> jdbcDriversToDeploy(Set<Datasource> datasources) {
    List<FileObject> jdbcDriverFiles = new ArrayList<FileObject>();
    Collection<File> driverCP = getJDBCDriverClasspath();
    for (Datasource datasource : datasources) {
        String className = datasource.getDriverClassName();
        boolean exists = false;
        try {
            exists = ClasspathUtil.containsClass(driverCP, className);
        } catch (IOException e) {
            LOGGER.log(Level.INFO, null, e);
        }
        if (!exists) {
            for (DatabaseConnection databaseConnection : DatasourceHelper.findDatabaseConnections(datasource)) {
                JDBCDriver[] jdbcDrivers;
                JDBCDriver connDriver = databaseConnection.getJDBCDriver();
                if (connDriver != null) {
                    jdbcDrivers = new JDBCDriver[] {connDriver};
                } else {
                    // old fashioned way - fallback
                    String driverClass = databaseConnection.getDriverClass();
                    jdbcDrivers = JDBCDriverManager.getDefault().getDrivers(driverClass);
                }
                for (JDBCDriver jdbcDriver : jdbcDrivers) {
                    for (URL url : jdbcDriver.getURLs()) {
                        FileObject file = URLMapper.findFileObject(url);
                        if (file != null) {
                            jdbcDriverFiles.add(file);
                        }
                    }
                }
            }
        }
    }
    return jdbcDriverFiles;
}
 
Example #27
Source File: WhiteListIndexerPlugin.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public JavaIndexerPlugin create(final URL root, final FileObject cacheFolder) {
    try {
        File whiteListDir = roots2whiteListDirs.get(root);
        if (whiteListDir == null) {
            //First time
            final FileObject whiteListFolder = FileUtil.createFolder(cacheFolder, WHITE_LIST_INDEX);
            whiteListDir = FileUtil.toFile(whiteListFolder);
            if (whiteListDir == null) {
                return null;
            }
        }
        final FileObject rootFo = URLMapper.findFileObject(root);
        if (rootFo == null) {
            delete(whiteListDir);
            return null;
        } else {
            final WhiteListQuery.WhiteList wl = WhiteListQuery.getWhiteList(rootFo);
            if (wl == null) {
                return null;
            }
            return new WhiteListIndexerPlugin(
                root,
                wl,
                whiteListDir);
        }
    } catch (IOException ioe) {
        Exceptions.printStackTrace(ioe);
        return null;
    }
}
 
Example #28
Source File: SourcePrefetcherTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDeadlock208663() throws Exception {
    CompileTuple ct = files.iterator().next();
    final FileObject fo = URLMapper.findFileObject(ct.indexable.getURL());
    final FileLock lck = fo.lock();
    try {
        final OutputStream out = new BufferedOutputStream(fo.getOutputStream(lck));
        try {
            for (int i = 0; i<101; i++) {
                out.write('a');
            }
        } finally {
            out.close();
        }
    } finally {
        lck.releaseLock();
    }
    
    JavaIndexerWorker.TEST_DO_PREFETCH = true;
    JavaIndexerWorker.BUFFER_SIZE = 100;
    final LogHandler handler = new LogHandler();
    handler.expect("Using concurrent iterator, {0} workers");    //NOI18N
    final Logger log = Logger.getLogger(JavaIndexerWorker.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SourcePrefetcher pf = SourcePrefetcher.create(files, SuspendSupport.NOP);
        assertTrue(handler.isFound());
        final Deque<CompileTuple> got = new ArrayDeque<CompileTuple>(FILE_COUNT);
        while (pf.hasNext()) {
            ct = pf.next();
            assertNotNull(getCache(ct.jfo));
            got.offer(ct);
            pf.remove();
            assertNull(getCache(ct.jfo));
        }
        assertCollectionsEqual(files,got);
    } finally {
        log.removeHandler(handler);
    }
}
 
Example #29
Source File: BinaryUsagesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testMixed() throws Exception {
    FileObject fo = URLMapper.findFileObject(src.toURL());
    IndexingManager.getDefault().refreshIndexAndWait(src.toURL(), null, true);
    final ClasspathInfo cpInfo = ClasspathInfo.create(src);
    final Collection<? extends FileObject> res = cpInfo.getClassIndex().getResources(
            ElementHandleAccessor.getInstance().create(ElementKind.CLASS, "org.me.Foo"),    //NOI18N
            EnumSet.allOf(ClassIndex.SearchKind.class),
            EnumSet.of(ClassIndex.SearchScope.SOURCE),
            EnumSet.of(ClassIndex.ResourceType.SOURCE));
    assertEquals(1, res.size());
    assertEquals(java, res.iterator().next());

}
 
Example #30
Source File: DriverClassLoader.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public DriverClassLoader(JDBCDriver driver) {
    super(new URL[] {});
    
    // Go through the URLs, and if any of them have the nbinst: protocol,
    // convert these to full-path URLs usable by the classloader
    URL[] urls = driver.getURLs();
    
    for ( URL url : urls ) {
        if ("nbinst".equals(url.getProtocol())) { // NOI18N
            // try to get a file: URL for the nbinst: URL
            FileObject fo = URLMapper.findFileObject(url);
            if (fo == null) {
                LOGGER.log(Level.WARNING, 
                    "Unable to find file object for driver url " + url);
                continue;
            }
            
            URL localURL = URLMapper.findURL(fo, URLMapper.EXTERNAL);
            if (localURL == null) {
                LOGGER.log(Level.WARNING, 
                    "Unable to get file url for nbinst url " + url);
                continue;
            }
            
            super.addURL(localURL);
        } else {
            super.addURL(url);
        }
    }                                       
}