Search in sources :

Example 1 with FileStateInvalidException

use of org.openide.filesystems.FileStateInvalidException in project enclojure by EricThorsen.

the class SourcePathProviderImpl method getRoot.

/**
 * Returns source root for given ClassPath root as String, or <code>null</code>.
 */
private static String getRoot(FileObject fileObject) {
    File f = null;
    String path = "";
    try {
        if (fileObject.getFileSystem() instanceof JarFileSystem) {
            f = ((JarFileSystem) fileObject.getFileSystem()).getJarFile();
            if (!fileObject.isRoot()) {
                path = "!/" + fileObject.getPath();
            }
        } else {
            f = FileUtil.toFile(fileObject);
        }
    } catch (FileStateInvalidException ex) {
    }
    if (f != null) {
        return f.getAbsolutePath() + path;
    } else {
        return null;
    }
}
Also used : JarFileSystem(org.openide.filesystems.JarFileSystem) FileStateInvalidException(org.openide.filesystems.FileStateInvalidException) File(java.io.File)

Example 2 with FileStateInvalidException

use of org.openide.filesystems.FileStateInvalidException in project enclojure by EricThorsen.

the class SourcePathProviderImpl method getAllURLs.

/**
 * Translates a relative path to all possible URLs.
 * Uses GlobalPathRegistry if global == true.
 *
 * @param relativePath a relative path (java/lang/Thread.java)
 * @param global true if global path should be used
 * @return url
 */
public String[] getAllURLs(String relativePath, boolean global) {
    if (verbose) {
        System.out.println("SPPI: getURL " + relativePath + " global " + global);
    }
    List<FileObject> fos;
    relativePath = normalize(relativePath);
    if (originalSourcePath == null) {
        fos = new ArrayList<FileObject>();
        for (ClassPath cp : GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) {
            fos.addAll(cp.findAllResources(relativePath));
        }
    } else {
        synchronized (this) {
            if (!global) {
                fos = smartSteppingSourcePath.findAllResources(relativePath);
                if (verbose) {
                    System.out.println("SPPI:   fos " + fos);
                }
            } else {
                fos = originalSourcePath.findAllResources(relativePath);
                if (verbose) {
                    System.out.println("SPPI:   fos " + fos);
                }
            }
        }
    }
    List<String> urls = new ArrayList<String>(fos.size());
    for (FileObject fo : fos) {
        try {
            urls.add(fo.getURL().toString());
        } catch (FileStateInvalidException e) {
            if (verbose) {
                System.out.println("SPPI:   FileStateInvalidException for " + fo);
            // skip it
            }
        }
    }
    return urls.toArray(new String[0]);
}
Also used : ClassPath(org.netbeans.api.java.classpath.ClassPath) FileStateInvalidException(org.openide.filesystems.FileStateInvalidException) FileObject(org.openide.filesystems.FileObject)

Example 3 with FileStateInvalidException

use of org.openide.filesystems.FileStateInvalidException in project enclojure by EricThorsen.

the class SourcePathProviderImpl method getURL.

/**
 * Translates a relative path ("java/lang/Thread.java") to url
 * ("file:///C:/Sources/java/lang/Thread.java"). Uses GlobalPathRegistry
 * if global == true.
 *
 * @param relativePath a relative path (java/lang/Thread.java)
 * @param global true if global path should be used
 * @return url or <code>null</code>
 */
public String getURL(String relativePath, boolean global) {
    if (verbose) {
        System.out.println("SPPI: getURL " + relativePath + " global " + global);
    // ET I seem to get explicit paths here for clojure files?
    }
    String cf = checkClojureFile(relativePath);
    if (cf != null) {
        return cf;
    }
    FileObject fo;
    try {
        LOG.log(Level.ALL, " SourcePathProviderImpl::getURL - " + relativePath);
        if (originalSourcePath == null) {
            fo = GlobalPathRegistry.getDefault().findResource(relativePath);
        } else {
            synchronized (this) {
                if (!global) {
                    fo = smartSteppingSourcePath.findResource(relativePath);
                    if (verbose) {
                        System.out.println("SPPI:   fo " + fo);
                    }
                } else {
                    fo = originalSourcePath.findResource(relativePath);
                    if (verbose) {
                        System.out.println("SPPI:   fo " + fo);
                    }
                }
            }
        }
        if (fo == null) {
            LOG.log(Level.ALL, " SourcePathProviderImpl::getURL - NO GO for: " + relativePath);
            return null;
        }
        return fo.getURL().toString();
    } catch (FileStateInvalidException e) {
        if (verbose) {
            System.out.println("SPPI:   FileStateInvalidException");
        }
        return null;
    }
}
Also used : FileStateInvalidException(org.openide.filesystems.FileStateInvalidException) FileObject(org.openide.filesystems.FileObject)

Aggregations

FileStateInvalidException (org.openide.filesystems.FileStateInvalidException)3 FileObject (org.openide.filesystems.FileObject)2 File (java.io.File)1 ClassPath (org.netbeans.api.java.classpath.ClassPath)1 JarFileSystem (org.openide.filesystems.JarFileSystem)1