public static boolean isClasspathRoot(FileObject fo) { return fo.equals(ClassPath.getClassPath(fo, ClassPath.SOURCE).findOwnerRoot(fo)); }
public static FileObject getClassPathRoot(FileObject fileObject) { return ClassPath.getClassPath(fileObject, ClassPath.SOURCE).findOwnerRoot(fileObject); }
public static ActionManager getActionManager(FileObject fileInProject) { if(ams == null) { ams = Collections.synchronizedMap(new HashMap<Project,ActionManager>()); } Project proj = getProject(fileInProject); ActionManager am = ams.get(proj); if(am == null && canHaveActions(fileInProject)) { synchronized(ActionManager.class) { if (ams.get(proj) == null) { ClassPath cp = ClassPath.getClassPath(fileInProject, ClassPath.SOURCE); FileObject root = cp.findOwnerRoot(fileInProject); am = new ActionManager(proj, root); ams.put(proj,am); } } } return am; }
private static String getGroovyPath(String url) { FileObject fo = getFileObjectFromUrl(url); String relativePath = url; if (fo != null) { ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE); if (cp == null) { LOGGER.log(Level.FINE, "No classpath for {0}", url); return null; } FileObject root = cp.findOwnerRoot(fo); if (root == null) { return null; } relativePath = FileUtil.getRelativePath(root, fo); } return relativePath; } }
private static String findApplicationClass(FileObject fileInProject) { if (isFrameworkLibAvailable(fileInProject)) { ClassPath cp = ClassPath.getClassPath(fileInProject, ClassPath.SOURCE); return scanFolderForApplication(cp.findOwnerRoot(fileInProject)); } else { return null; } }
private ClassPath[] findClassPathOrNull(FileObject file, String type, Library lib) { if (lib.getType().equals(J2SELibraryTypeProvider.LIBRARY_TYPE)) { List<URL> resources = lib.getContent(J2SELibraryTypeProvider.VOLUME_TYPE_SRC); ClassPath sourcePath = ClassPathSupport.createClassPath(resources.toArray(new URL[resources.size()])); FileObject root = sourcePath.findOwnerRoot(file); if (root != null) { setLastUsedLibrary(root, lib); if (ClassPath.SOURCE.equals(type)) { return new ClassPath[] {sourcePath}; } else if (ClassPath.COMPILE.equals(type)) { resources = lib.getContent(J2SELibraryTypeProvider.VOLUME_TYPE_CLASSPATH); return new ClassPath[] {ClassPathSupport.createClassPath(resources.toArray(new URL[resources.size()]))}; } else if (ClassPath.BOOT.equals(type)) { return new ClassPath[] {ScalaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries()}; } else { return new ClassPath[] {null}; } } } return null; }
private String findVersion(FileObject classpathRoot) { ClassPath cp = ClassPath.getClassPath(classpathRoot, ClassPath.COMPILE); if (cp == null) { return null; } String classRelativePath = SpringUtilities.SPRING_CLASS_NAME.replace('.', '/') + ".class"; //NOI18N try { FileObject resource = cp.findResource(classRelativePath); //NOI18N if (resource==null) { return null; } FileObject ownerRoot = cp.findOwnerRoot(resource); if (ownerRoot !=null) { //NOI18N if (ownerRoot.getFileSystem() instanceof JarFileSystem) { JarFileSystem jarFileSystem = (JarFileSystem) ownerRoot.getFileSystem(); return SpringUtilities.getImplementationVersion(jarFileSystem); } } } catch (FileStateInvalidException e) { Exceptions.printStackTrace(e); } return null; } }
/** * Will find * Copied from JUnit module implementation in 4.1 and modified */ public static FileObject findTestForFile(final FileObject selectedFO) { if ((selectedFO == null) || !selectedFO.getExt().equalsIgnoreCase("java")) { return null; // NOI18N } ClassPath cp = ClassPath.getClassPath(selectedFO, ClassPath.SOURCE); if (cp == null) { return null; } FileObject packageRoot = cp.findOwnerRoot(selectedFO); if (packageRoot == null) { return null; // not a file in the source dirs - e.g. generated class in web app } URL[] testRoots = UnitTestForSourceQuery.findUnitTests(packageRoot); FileObject fileToOpen = null; for (int j = 0; j < testRoots.length; j++) { fileToOpen = findUnitTestInTestRoot(cp, selectedFO, testRoots[j]); if (fileToOpen != null) { return fileToOpen; } } return null; }
static File getCurrentSourceRoot() { FileObject fo = EditorContextDispatcher.getDefault().getMostRecentFile(); if (fo == null) { return null; } ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE); if (cp == null) { return null; } fo = cp.findOwnerRoot(fo); if (fo == null) { return null; } return FileUtil.toFile(fo); }
private static String getLibraryVersion(Library library, String className) { List<URL> urls = library.getContent("classpath"); // NOI18N ClassPath cp = createClassPath(urls); try { FileObject resource = cp.findResource(className.replace('.', '/') + ".class"); //NOI18N if (resource==null) { return null; } FileObject ownerRoot = cp.findOwnerRoot(resource); if (ownerRoot !=null) { //NOI18N if (ownerRoot.getFileSystem() instanceof JarFileSystem) { JarFileSystem jarFileSystem = (JarFileSystem) ownerRoot.getFileSystem(); return getImplementationVersion(jarFileSystem); } } } catch (FileStateInvalidException e) { Exceptions.printStackTrace(e); } return null; }
static File getCurrentSourceRoot() { FileObject fo = EditorContextDispatcher.getDefault().getMostRecentFile(); if (fo == null) { return null; } ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE); if (cp == null) { return null; } fo = cp.findOwnerRoot(fo); if (fo == null) { return null; } return FileUtil.toFile(fo); }
"No classpath was found for folder: {0}", // NOI18N FileUtil.getFileDisplayName(targetFO)); } else if (cp.findOwnerRoot(targetFO) == null) { LOG.log( Level.WARNING,
private String classToSourceURL (FileObject fo, Log logger) { try { ClassPath cp = ClassPath.getClassPath (fo, ClassPath.EXECUTE); FileObject root = cp.findOwnerRoot (fo); String resourceName = cp.getResourceName (fo, '/', false); if (resourceName == null) { logger.info("Can not find classpath resource for "+fo+", skipping..."); return null; } int i = resourceName.indexOf ('$'); if (i > 0) resourceName = resourceName.substring (0, i); FileObject[] sRoots = SourceForBinaryQuery.findSourceRoots (root.getURL ()).getRoots (); ClassPath sourcePath = ClassPathSupport.createClassPath (sRoots); FileObject rfo = sourcePath.findResource (resourceName + ".java"); if (rfo == null) return null; return rfo.getURL ().toExternalForm (); } catch (FileStateInvalidException ex) { ex.printStackTrace (); return null; } }
public String getSourceLevel(org.openide.filesystems.FileObject javaFile) { Library ll = this.isLastUsed (javaFile); if (ll != null) { return getSourceLevel (ll); } for (LibraryManager mgr : LibraryManager.getOpenManagers()) { for (Library lib : mgr.getLibraries()) { if (!lib.getType().equals(J2SELibraryTypeProvider.LIBRARY_TYPE)) { continue; } List<URL> sourceRoots = lib.getContent(J2SELibraryTypeProvider.VOLUME_TYPE_SRC); if (sourceRoots.isEmpty()) { continue; } ClassPath cp = ClassPathSupport.createClassPath(sourceRoots.toArray(new URL[sourceRoots.size()])); FileObject root = cp.findOwnerRoot(javaFile); if (root != null) { setLastUsedRoot(root, lib); return getSourceLevel(lib); } } } return null; }
final FileObject root = classPath.findOwnerRoot(folder); final String prefix = FileUtil.getRelativePath(root, folder.getParent()).replace('/','.'); final String oldName = buildName(prefix, folder.getName());
@Override public void commit() { if (!refElement.isEnabled()) { return; } // This is supposed to run before the original package is renamed. // The package is renamed after "transactions", then form updates // are run. ClassPath cp = ClassPath.getClassPath(resFolder.getPrimaryFile(), ClassPath.SOURCE); FileObject srcRoot = cp.findOwnerRoot(resFolder.getPrimaryFile()); String newName = refactoring.getNewName().replace('.', '/'); try { // the new package folder is not there yet DataFolder targetFolder = DataFolder.findFolder( FileUtil.createFolder(srcRoot, newName)); resFolder.move(targetFolder); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
/** * @return html file with the same name as applet */ private static FileObject generateHtml(FileObject appletFile, FileObject buildDir, FileObject classesDir) throws IOException { FileObject htmlFile = buildDir.getFileObject(appletFile.getName(), HTML_EXT); if (htmlFile == null) { htmlFile = buildDir.createData(appletFile.getName(), HTML_EXT); } FileLock lock = htmlFile.lock(); PrintWriter writer = null; try { writer = new PrintWriter(htmlFile.getOutputStream(lock)); ClassPath cp = ClassPath.getClassPath(appletFile, ClassPath.EXECUTE); ClassPath sp = ClassPath.getClassPath(appletFile, ClassPath.SOURCE); String path = FileUtil.getRelativePath(sp.findOwnerRoot(appletFile), appletFile); path = path.substring(0, path.length()-5); String codebase = FileUtil.getRelativePath(buildDir, classesDir); if (codebase == null) { codebase = classesDir.getURL().toString(); } fillInFile(writer, path + "." + CLASS_EXT, "codebase=\"" + codebase + "\""); // NOI18N } finally { lock.releaseLock(); if (writer != null) writer.close(); } return htmlFile; }
String path = FileUtil.getRelativePath(sp.findOwnerRoot(appletFile), appletFile); path = path.substring(0, path.length() - 5); fillInFile(writer, path + "." + CLASS_EXT, "codebase=\"" + classesDir.getURL() + "\""); // NOI18N
public static ClasspathInfo getClasspathInfoFor(FileObject ... files) { assert files.length >0; Set<URL> dependentRoots = new HashSet(); for (FileObject fo: files) { Project p = null; if (fo!=null) p=FileOwnerQuery.getOwner(fo); if (p!=null) { URL sourceRoot = URLMapper.findURL(ClassPath.getClassPath(fo, ClassPath.SOURCE).findOwnerRoot(fo), URLMapper.INTERNAL); dependentRoots.addAll(SourceUtils.getDependentRoots(sourceRoot)); for (SourceGroup root:ProjectUtils.getSources(p).getSourceGroups("java")) { dependentRoots.add(URLMapper.findURL(root.getRootFolder(), URLMapper.INTERNAL)); } } else { for(ClassPath cp: GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) { for (FileObject root:cp.getRoots()) { dependentRoots.add(URLMapper.findURL(root, URLMapper.INTERNAL)); } } } } ClassPath rcp = ClassPathSupport.createClassPath(dependentRoots.toArray(new URL[dependentRoots.size()])); // ClassPath nullPath = ClassPathSupport.createClassPath(new FileObject[0]); ClassPath boot = ClassPath.getClassPath(files[0], ClassPath.BOOT); ClassPath compile = ClassPath.getClassPath(files[0], ClassPath.COMPILE); ClasspathInfo cpInfo = ClasspathInfo.create(boot, compile, rcp); return cpInfo; }
@Override public void rollback() { if (!refElement.isEnabled()) { return; } // This is suposed to run after the package is renamed back. ClassPath cp = ClassPath.getClassPath(resFolder.getPrimaryFile(), ClassPath.SOURCE); FileObject srcRoot = cp.findOwnerRoot(resFolder.getPrimaryFile()); FileObject pkgFolder = resFolder.getPrimaryFile().getParent(); try { DataFolder targetFolder = DataFolder.findFolder( FileUtil.createFolder(srcRoot, oldPkgName.replace('.', '/'))); resFolder.move(targetFolder); // remove the package folder if it is empty after moving resources if (pkgFolder != null && pkgFolder.isValid() && pkgFolder.getChildren().length == 0) { pkgFolder.delete(); } } catch (Exception ex) { Exceptions.printStackTrace(ex); } } }