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; } }
@Override public Map<String, ?> attributesFor(DataObject template, DataFolder target, String name) { FileObject templateFO = template.getPrimaryFile(); if (!JFXProjectProperties.FXML_EXTENSION.equals(templateFO.getExt()) || templateFO.isFolder()) { return null; Map<String,Object> result = new HashMap<String,Object>(); ClassPath cp = ClassPath.getClassPath(targetFO, ClassPath.SOURCE); if (cp == null) { LOG.log( Level.WARNING, "No classpath was found for folder: {0}", // NOI18N FileUtil.getFileDisplayName(targetFO)); } else if (cp.findOwnerRoot(targetFO) == null) { LOG.log( Level.WARNING, "Folder {0} is not on its classpath: {1}", // NOI18N new Object[] { FileUtil.getFileDisplayName(targetFO), cp.toString(ClassPath.PathConversionMode.PRINT) }); result.put("package", cp.getResourceName(targetFO, '.', false)); // NOI18N
private static boolean isAptBuildGeneratedFolder(@NonNull final FileObject root) { final ClassPath scp = ClassPath.getClassPath(root, ClassPath.SOURCE); if (scp != null) { for (FileObject srcRoot : scp.getRoots()) { if (root.toURL().equals( AnnotationProcessingQuery.getAnnotationProcessingOptions(srcRoot).sourceOutputDirectory())) { return true; } } } return false; }
public static String getPackageName(FileObject folder) { return ClassPath.getClassPath( folder, ClassPath.SOURCE) .getResourceName(folder, '.', false); }
public static FileObject getClassPathRoot(FileObject fileObject) { return ClassPath.getClassPath(fileObject, ClassPath.SOURCE).findOwnerRoot(fileObject); }
private static String getPackageName(FileObject folder) { assert folder.isFolder() : "argument must be folder"; return ClassPath.getClassPath( folder, ClassPath.SOURCE) .getResourceName(folder, '.', false); }
for (ClassPath.Entry entry : platform.getBootstrapLibraries().entries()) { if (entry.getURL().equals (binaryRoot)) { res = new Result(platform); this.cache.put (binaryRoot, res); for (ClassPath.Entry entry : platform.getStandardLibraries().entries()) { if (entry.getURL().equals (binaryRoot)) { res = new Result(platform); this.cache.put (binaryRoot, res); String binaryRootS = binaryRoot.toExternalForm(); if (binaryRootS.startsWith(JAR_FILE)) { String srcZipS = null; URL srcZip = FileUtil.getArchiveRoot(new URL(srcZipS)); FileObject fo = URLMapper.findFileObject(srcZip); if (fo != null) { Exceptions.printStackTrace(mue);
/** * @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; }
void setSources (ClassPath sources) { String srcPath = null; if (sources.entries().size()>0) { URL folderRoot = ((ClassPath.Entry)sources.entries().get(0)).getURL(); if ("jar".equals(folderRoot.getProtocol())) { //NOI18N folderRoot = FileUtil.getArchiveFile (folderRoot); } srcPath = new File(URI.create(folderRoot.toExternalForm())).getAbsolutePath(); } setSources (srcPath); }
try { if (targetURL != null) { f = FileUtil.normalizeFile(new File(targetURL.toURI())); Exceptions.printStackTrace(ex); f = f.getParentFile(); FileObject targetFolder = (f != null) ? FileUtil.toFileObject(f) : null; if (targetFolder != null && targetFolder.isFolder()) { ClassPath cp = ClassPath.getClassPath(targetFolder, ClassPath.SOURCE); if (cp != null) { String pkg = cp.getResourceName(targetFolder, '.', false); StringBuilder buf = new StringBuilder(); if (pkg != null) {
private static boolean equals(ClassPath cp1, ClassPath cp2) { if (cp1.entries().size() != cp2.entries().size()) { return false; } for (int i = 0; i < cp1.entries().size(); i++) { try { if (!cp1.entries().get(i).getURL().toURI() .equals(cp2.entries().get(i).getURL().toURI())) { return false; } } catch (URISyntaxException e) { if ( !cp1.entries().get(i).equals(cp2.entries().get(i)) ){ return false; } } } return true; }
private File getClassFolderForApt(final String baseName) { String[] parentName = splitParentName(baseName); for (ClassPath.Entry entry : this.apt.entries()) { FileObject root = entry.getRoot(); if (root != null) { FileObject parentFile = root.getFileObject(parentName[0]); if (parentFile != null) { if (parentFile.getFileObject(parentName[1], FileObjects.JAVA) != null) { final URL classFolder = AptCacheForSourceQuery.getClassFolder(entry.getURL()); if (classFolder != null) { try { return BaseUtilities.toFile(classFolder.toURI()); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } } } } } } return null; }
@Override protected void index(Iterable<? extends Indexable> files, Context context) { final URL rootURL = context.getRootURI(); if (FileUtil.getArchiveFile(rootURL) != null) { return; final ClassPath srcPath = ClassPath.getClassPath(context.getRoot(), ClassPath.SOURCE); for (Indexable i : files) { if (javaMimeTypes.contains(i.getMimeType())) final FileObject resource = srcPath.findResource(i.getRelativePath()); if (resource == null) { LOG.log( context.getRoot() }); } else if (FileUtil.isParentOf(context.getRoot(), resource)) { updated.add(BaseUtilities.toFile(url.toURI())); Exceptions.printStackTrace(ex); File sourceRootFile = BaseUtilities.toFile(context.getRootURI().toURI()); Exceptions.printStackTrace(ex);
private File getClassFolderForApt(final @NonNull URL surl) { for (ClassPath.Entry entry : apt.entries()) { if (FileObjects.isParentOf(entry.getURL(), surl)) { final URL classFolder = AptCacheForSourceQuery.getClassFolder(entry.getURL()); if (classFolder != null) { try { return BaseUtilities.toFile(classFolder.toURI()); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } } } } return null; }
@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); } } }
if (cancel.get()) return; nonRecursiveRoots.add(f.getFolder()); for (FileObject c : f.getFolder().getChildren()) { if (!c.isData()) continue; toFormat.add(c); if (nonRecursiveRoots.contains(d.getPrimaryFile())) continue; addRecursivelly(d.getPrimaryFile(), toFormat, sourceIds, null, null, cancel); for (FileObject root : sCP.getRoots()) { if (cancel.get()) return; Project owner = FileOwnerQuery.getOwner(root); if (cancel.get()) break ; try { DataObject d = DataObject.find(current); EditorCookie ec = d.getLookup().lookup(EditorCookie.class); handle.progress(Bundle.LBL_Formatting(FileUtil.getFileDisplayName(current))); uqe.confirmed(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } finally { handle.progress(++done);
FileObject templateFO = FileUtil.getConfigFile("Templates/UnitTests/junit-custom.xml"); //NOI18N FileObject tmpDir = FileUtil.toFileObject(new File(System.getProperty("java.io.tmpdir")).getCanonicalFile()); FileObject targetFO = tmpDir.createFolder("junit-custom-" + id); //NOI18N props.put("work.dir", testSession.getProject().getProjectDirectory().getPath()); //NOI18N ClassPath cp = ClassPath.getClassPath(someTestFO, ClassPath.EXECUTE); props.put("classpath", cp != null ? cp.toString(ClassPath.PathConversionMode.FAIL) : "");//NOI18N Project p = testSession.getProject(); String platformId = null; props.put("platform.java", platform.findTool("java").getPath());//NOI18N } else { Exceptions.printStackTrace(ex); } catch (IllegalArgumentException ex) { Exceptions.printStackTrace(ex);
throw new IllegalArgumentException ("fileObject == null"); //NOI18N JavaSource js = ref != null ? ref.get() : null; if (js == null) { mimeType = mimeType == null ? FileUtil.getMIMEType(fileObject, supportedMIMETypes) : mimeType; if (ClassParser.MIME_TYPE.equals(mimeType) || FileObjects.CLASS.equals(fileObject.getExt())) { ClassPath bootPath = ClassPath.getClassPath(fileObject, ClassPath.BOOT); if (bootPath == null) { ClassPath compilePath = ClassPath.getClassPath(fileObject, ClassPath.COMPILE); if (compilePath == null) { compilePath = ClassPathSupport.createClassPath(new URL[0]); ClassPath srcPath = ClassPath.getClassPath(fileObject, ClassPath.SOURCE); if (srcPath == null) { srcPath = ClassPathSupport.createClassPath(new URL[0]); ClassPath execPath = ClassPath.getClassPath(fileObject, ClassPath.EXECUTE); if (execPath != null) { bootPath = ClassPathSupport.createProxyClassPath(execPath, bootPath); final ClasspathInfo info = ClasspathInfo.create(bootPath, compilePath, srcPath); FileObject root = ClassPathSupport.createProxyClassPath( ClassPathSupport.createClassPath(CachingArchiveProvider.getDefault().ctSymRootsFor(bootPath)), bootPath, compilePath, srcPath).findOwnerRoot(fileObject);
refHelper.copyLibrary(LibraryManager.getDefault().getLibrary("CopyLibs")); // NOI18N } catch (IOException ex) { Exceptions.printStackTrace(ex); findResource("org/netbeans/modules/java/j2seproject/copylibstask/CopyFiles.class") == null; // NOI18N if (!version61) { return; refHelper.getProjectLibraryManager().removeLibrary(lib); } catch (IOException ex) { Exceptions.printStackTrace(ex); FileObject parent = null; for (URL u : roots) { URL u2 = FileUtil.getArchiveFile(u); if (u2 != null) { u = u2; if (fo != null) { if (parent == null) { parent = fo.getParent(); fo.delete(); if (parent != null && parent.getChildren().length == 0 && parent.getNameExt().equals("CopyLibs")) { // NOI18N parent.delete(); Exceptions.printStackTrace(ex);