Java Code Examples for org.openide.filesystems.FileUtil#urlForArchiveOrDir()
The following examples show how to use
org.openide.filesystems.FileUtil#urlForArchiveOrDir() .
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: MuxClassPathImplementationTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testFlagsEvents() throws IOException { final File wd = FileUtil.normalizeFile(getWorkDir()); final URL cp1r1 = FileUtil.urlForArchiveOrDir(new File(wd, "cp1_root1")); //NOI18N final URL cp2r1 = FileUtil.urlForArchiveOrDir(new File(wd, "cp2_root1")); //NOI18N final MutableClassPathImpl cpImpl1 = new MutableClassPathImpl(cp1r1); final MutableClassPathImpl cpImpl2 = new MutableClassPathImpl(cp2r1) .add(ClassPath.Flag.INCOMPLETE); final SelectorImpl selector = new SelectorImpl( ClassPathFactory.createClassPath(cpImpl1), ClassPathFactory.createClassPath(cpImpl2)); final ClassPath cp = ClassPathSupport.createMultiplexClassPath(selector); assertEquals(0, cp.getFlags().size()); final MockPropertyChangeListener l = new MockPropertyChangeListener(); cp.addPropertyChangeListener(l); selector.select(1); l.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS, ClassPath.PROP_FLAGS); selector.select(0); l.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS, ClassPath.PROP_FLAGS); cpImpl1.add(ClassPath.Flag.INCOMPLETE); l.assertEvents(ClassPath.PROP_FLAGS); cpImpl1.remove(ClassPath.Flag.INCOMPLETE); l.assertEvents(ClassPath.PROP_FLAGS); selector.select(1); l.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS, ClassPath.PROP_FLAGS); }
Example 2
Source File: Utils.java From netbeans with Apache License 2.0 | 6 votes |
@NonNull public static List<? extends URL> getRuntimeClassPath(@NonNull final File javafxRuntime) { Parameters.notNull("javafxRuntime", javafxRuntime); //NOI18N final List<URL> result = new ArrayList<URL>(); final File lib = new File (javafxRuntime,"lib"); //NOI18N final File[] children = lib.listFiles(new FileFilter() { @Override public boolean accept(@NonNull final File pathname) { return pathname.getName().toLowerCase().endsWith(".jar"); //NOI18N } }); if (children != null) { for (File f : children) { final URL root = FileUtil.urlForArchiveOrDir(f); if (root != null) { result.add(root); } } } return result; }
Example 3
Source File: BinaryForSourceQueryImpl.java From netbeans with Apache License 2.0 | 6 votes |
@Override @NonNull public URL[] getRoots() { String[] names = activeNames; if (names == null) { names = getActivePropertyNames(root); activeNames = names; } if (names == null) { //No more handled by this project, remove from cache. cache.remove(root); return new URL[0]; } final List<URL> urls = new ArrayList<URL>(); for (String propName : names) { String val = eval.getProperty(propName); if (val != null) { final URL url = FileUtil.urlForArchiveOrDir(helper.resolveFile(val)); if (url != null) { urls.add(url); } } } return urls.toArray(new URL[urls.size()]); }
Example 4
Source File: SourceForBinaryImplTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testCompletionWorks_69735() throws Exception { SuiteProject suite = generateSuite("suite"); NbModuleProject project = TestBase.generateSuiteComponent(suite, "module"); File library = new File(getWorkDir(), "test-library-0.1_01.jar"); createJar(library, Collections.<String,String>emptyMap(), new Manifest()); FileObject libraryFO = FileUtil.toFileObject(library); FileObject yyJar = FileUtil.copyFile(libraryFO, FileUtil.toFileObject(getWorkDir()), "yy"); // library wrapper File suiteDir = suite.getProjectDirectoryFile(); File wrapperDirF = new File(new File(getWorkDir(), "suite"), "wrapper"); NbModuleProjectGenerator.createSuiteLibraryModule( wrapperDirF, "yy", // 69735 - the same name as jar "Testing Wrapper (yy)", // display name "org/example/wrapper/resources/Bundle.properties", suiteDir, // suite directory null, new File[] { FileUtil.toFile(yyJar)} ); ApisupportAntUtils.addDependency(project, "yy", null, null, true, null); ProjectManager.getDefault().saveProject(project); URL wrappedJar = FileUtil.urlForArchiveOrDir(new File(wrapperDirF, "release/modules/ext/yy.jar")); assertEquals("no sources for wrapper", 0, SourceForBinaryQuery.findSourceRoots(wrappedJar).getRoots().length); }
Example 5
Source File: JavadocForBinaryImpl.java From netbeans with Apache License 2.0 | 6 votes |
/** * Find Javadoc roots for classpath extensions ("wrapped" JARs) of the project * added by naming convention <tt><jar name>-javadoc(.zip)</tt> * See issue #66275 * @param binaryRoot * @return */ private Result findForCPExt(URL binaryRoot) { URL jar = FileUtil.getArchiveFile(binaryRoot); if (jar == null) return null; // not a class-path-extension File binaryRootF = Utilities.toFile(URI.create(jar.toExternalForm())); // XXX this will only work for modules following regular naming conventions: String n = binaryRootF.getName(); if (!n.endsWith(".jar")) { // NOI18N // ignore return null; } // convention-over-cfg per mkleint's suggestion: <jarname>-javadoc(.zip) folder or ZIP File jFolder = new File(binaryRootF.getParentFile(), n.substring(0, n.length() - ".jar".length()) + "-javadoc"); if (jFolder.isDirectory()) { return new R(new URL[]{FileUtil.urlForArchiveOrDir(jFolder)}); } else { File jZip = new File(jFolder.getAbsolutePath() + ".zip"); if (jZip.isFile()) { return new R(new URL[]{FileUtil.urlForArchiveOrDir(jZip)}); } } return null; }
Example 6
Source File: RepositoryMavenCPProvider.java From netbeans with Apache License 2.0 | 6 votes |
private ClassPathImplementation createCompileCPI(MavenProject project, File binary) { List<PathResourceImplementation> items = new ArrayList<PathResourceImplementation>(); //according to jglick this could be posisble to leave out on compilation CP.. items.add(ClassPathSupport.createResource(FileUtil.urlForArchiveOrDir(binary))); if (project != null) { for (Artifact s : project.getCompileArtifacts()) { File file = s.getFile(); if (file == null) continue; URL u = FileUtil.urlForArchiveOrDir(file); if(u != null) { items.add(ClassPathSupport.createResource(u)); } else { LOG.log(Level.FINE, "Could not retrieve URL for artifact file {0}", new Object[] {file}); // NOI18N } } } return ClassPathSupport.createClassPathImplementation(items); }
Example 7
Source File: JavadocForBinaryImplTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testJavadocForExternalModules() throws Exception { ClassPath.getClassPath(resolveEEP("/suite2/misc-project/src"), ClassPath.COMPILE); File miscJar = resolveEEPFile("/suite2/build/cluster/modules/org-netbeans-examples-modules-misc.jar"); URL[] roots = JavadocForBinaryQuery.findJavadoc(FileUtil.urlForArchiveOrDir(miscJar)).getRoots(); URL[] expectedRoots = new URL[] { FileUtil.urlForArchiveOrDir(file(suite2, "misc-project/build/javadoc/org-netbeans-examples-modules-misc")), // It is inside ${netbeans.home}/.. so read this. urlForJar(apisZip, "org-netbeans-examples-modules-misc/"), }; assertEquals("correct Javadoc roots for misc", urlSet(expectedRoots), urlSet(roots)); ClassPath.getClassPath(resolveEEP("/suite3/dummy-project/src"), ClassPath.COMPILE); File dummyJar = file(suite3, "dummy-project/build/cluster/modules/org-netbeans-examples-modules-dummy.jar"); roots = JavadocForBinaryQuery.findJavadoc(FileUtil.urlForArchiveOrDir(dummyJar)).getRoots(); expectedRoots = new URL[] { FileUtil.urlForArchiveOrDir(file(suite3, "dummy-project/build/javadoc/org-netbeans-examples-modules-dummy")), }; assertEquals("correct Javadoc roots for dummy", urlSet(expectedRoots), urlSet(roots)); }
Example 8
Source File: ClassPathSupport.java From netbeans with Apache License 2.0 | 5 votes |
/** * Convenience method to create a classpath object from a conventional string representation. * @param jvmPath a JVM-style classpath (folder or archive paths separated by {@link File#pathSeparator}) * @return a corresponding classpath object * @throws IllegalArgumentException in case a path entry looks to be invalid * @since org.netbeans.api.java/1 1.15 * @see FileUtil#urlForArchiveOrDir * @see ClassPath#toJVMPath */ public static ClassPath createClassPath(String jvmPath) throws IllegalArgumentException { List<PathResourceImplementation> l = new ArrayList<PathResourceImplementation>(); for (String piece : jvmPath.split(File.pathSeparator)) { File f = FileUtil.normalizeFile(new File(piece)); URL u = FileUtil.urlForArchiveOrDir(f); if (u == null) { throw new IllegalArgumentException("Path entry looks to be invalid: " + piece); // NOI18N } l.add(createResource(u)); } return createClassPath(l); }
Example 9
Source File: GlobalSourceForBinaryImplTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testBehaviourWithNonZipFile() throws Exception { GlobalSourceForBinaryImpl.quiet = true; File nbSrcZip = new File(getWorkDir(), "wrong-nbsrc.zip"); nbSrcZip.createNewFile(); NbPlatform.getDefaultPlatform().addSourceRoot(FileUtil.urlForArchiveOrDir(nbSrcZip)); URL loadersURL = FileUtil.urlForArchiveOrDir(file("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-loaders.jar")); SourceForBinaryQuery.findSourceRoots(loadersURL).getRoots(); }
Example 10
Source File: AndroidClassPathProvider.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private void addJavaLibraryDependencies(List<URL> roots, Map<URL, ArtifactData> libs, JavaLibrary lib) { URL root = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(lib.getJarFile())); if (!roots.contains(root)) { roots.add(root); libs.put(root, new ArtifactData(lib, project)); } for (JavaLibrary childLib : lib.getDependencies()) { addJavaLibraryDependencies(roots, libs, childLib); } }
Example 11
Source File: JavadocForBinaryImplTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testJavadocForNetBeansOrgModules() throws Exception { // Have to load at least one module to get the scan going. ClassPath.getClassPath(nbRoot().getFileObject("classfile/src"), ClassPath.COMPILE); File classfileJar = file("nbbuild/netbeans/" + TestBase.CLUSTER_JAVA + "/modules/org-netbeans-modules-classfile.jar"); URL[] roots = JavadocForBinaryQuery.findJavadoc(FileUtil.urlForArchiveOrDir(classfileJar)).getRoots(); URL[] expectedRoots = { FileUtil.urlForArchiveOrDir(file("nbbuild/build/javadoc/org-netbeans-modules-classfile")), urlForJar(apisZip, "org-netbeans-modules-classfile/"), }; assertEquals("correct Javadoc roots for classfile", urlSet(expectedRoots), urlSet(roots)); }
Example 12
Source File: SourceForBinaryImplTest.java From netbeans with Apache License 2.0 | 5 votes |
private void doTestFindSourceRootForCompiledClasses(String srcPath, String classesPath) throws Exception { File classesF = file(classesPath); File srcF = file(srcPath); FileObject src = FileUtil.toFileObject(srcF); assertNotNull("have " + srcF, src); URL u = FileUtil.urlForArchiveOrDir(classesF); assertEquals("right source root for " + u, Collections.singletonList(src), trimGenerated(Arrays.asList(SourceForBinaryQuery.findSourceRoots(u).getRoots()))); }
Example 13
Source File: GlobalJavadocForBinaryImplTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testFindJavadoc() throws Exception { File nbDocZip = generateNbDocZip(); URL nbDocZipURL = FileUtil.urlForArchiveOrDir(nbDocZip); NbPlatform.getDefaultPlatform().addJavadocRoot(nbDocZipURL); doTestFindJavadoc(Utilities.toURI(file("openide.loaders/src")).toURL(), nbDocZipURL); doTestFindJavadoc(FileUtil.urlForArchiveOrDir(file("nbbuild/netbeans/platform/modules/org-openide-loaders.jar")), nbDocZipURL); }
Example 14
Source File: QuerySupportTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testGetDependentRootsJavaLikeDependenciesProjectsClosed() throws IOException, InterruptedException { final FileObject wd = FileUtil.toFileObject(getWorkDir()); final FileObject src1 = FileUtil.createFolder(wd,"src1"); //NOI18N final URL build1 = FileUtil.urlForArchiveOrDir(new File (getWorkDir(),"build1"));//NOI18N final FileObject src2 = FileUtil.createFolder(wd,"src2"); //NOI18N final URL build2 = FileUtil.urlForArchiveOrDir(new File (getWorkDir(),"build2")); //NOI18N final FileObject src3 = FileUtil.createFolder(wd,"src3"); //NOI18N final URL build3 = FileUtil.urlForArchiveOrDir(new File (getWorkDir(),"build3")); //NOI18N final FileObject src4 = FileUtil.createFolder(wd,"src4"); //NOI18N final URL build4 = FileUtil.urlForArchiveOrDir(new File (getWorkDir(),"build4")); //NOI18N final ClassPath src1Source = ClassPathSupport.createClassPath(src1); final ClassPath src2Source = ClassPathSupport.createClassPath(src2); final ClassPath src2Compile = ClassPathSupport.createClassPath(build1); final ClassPath src3Source = ClassPathSupport.createClassPath(src3); final ClassPath src3Compile = ClassPathSupport.createClassPath(build1); final ClassPath src4Source = ClassPathSupport.createClassPath(src4); final ClassPath src4Compile = ClassPathSupport.createClassPath(build2); final Map<URL,Pair<Boolean,List<FileObject>>> sfbq = new HashMap<URL, Pair<Boolean,List<FileObject>>>(); sfbq.put(build1,Pair.of(true,Collections.singletonList(src1))); sfbq.put(build2,Pair.of(true,Collections.singletonList(src2))); sfbq.put(build3,Pair.of(true,Collections.singletonList(src3))); sfbq.put(build4,Pair.of(true,Collections.singletonList(src4))); SourceForBinaryQueryImpl.register(sfbq); final ClassPath boot = ClassPath.EMPTY; final Map<String,ClassPath> src1cps = new HashMap<String, ClassPath>(); src1cps.put(JavaLikePathRecognizer.BOOT, boot); src1cps.put(JavaLikePathRecognizer.COMPILE, ClassPath.EMPTY); src1cps.put(JavaLikePathRecognizer.SRC, src1Source); final Map<String,ClassPath> src2cps = new HashMap<String, ClassPath>(); src2cps.put(JavaLikePathRecognizer.BOOT, boot); src2cps.put(JavaLikePathRecognizer.COMPILE, src2Compile); src2cps.put(JavaLikePathRecognizer.SRC, src2Source); final Map<String,ClassPath> src3cps = new HashMap<String, ClassPath>(); src3cps.put(JavaLikePathRecognizer.BOOT, boot); src3cps.put(JavaLikePathRecognizer.COMPILE, src3Compile); src3cps.put(JavaLikePathRecognizer.SRC, src3Source); final Map<String,ClassPath> src4cps = new HashMap<String, ClassPath>(); src4cps.put(JavaLikePathRecognizer.BOOT, boot); src4cps.put(JavaLikePathRecognizer.COMPILE, src4Compile); src4cps.put(JavaLikePathRecognizer.SRC, src4Source); final Map<FileObject,Map<String,ClassPath>> cps = new HashMap<FileObject, Map<String, ClassPath>>(); cps.put(src1,src1cps); cps.put(src2,src2cps); cps.put(src3,src3cps); cps.put(src4,src4cps); ClassPathProviderImpl.register(cps); globalPathRegistry_register( JavaLikePathRecognizer.BOOT, new ClassPath[]{ boot }); globalPathRegistry_register( JavaLikePathRecognizer.COMPILE, new ClassPath[]{ src4Compile }); globalPathRegistry_register( JavaLikePathRecognizer.SRC, new ClassPath[]{ src4Source }); RepositoryUpdater.getDefault().waitUntilFinished(RepositoryUpdaterTest.TIME); assertEquals( IndexingController.getDefault().getRootDependencies().keySet().toString(), 3, IndexingController.getDefault().getRootDependencies().size()); assertEquals(new FileObject[] {src4}, QuerySupport.findDependentRoots(src4, true)); assertEquals(new FileObject[] {src4}, QuerySupport.findDependentRoots(src2, true)); assertEquals(new FileObject[] {src4}, QuerySupport.findDependentRoots(src1, true)); assertEquals(new FileObject[] {src4}, QuerySupport.findDependentRoots(src4, false)); assertEquals(new FileObject[] {src2, src4}, QuerySupport.findDependentRoots(src2, false)); assertEquals(new FileObject[] {src1, src2, src4}, QuerySupport.findDependentRoots(src1, false)); }
Example 15
Source File: JavadocForBinaryImplTest.java From netbeans with Apache License 2.0 | 4 votes |
private static URL urlForJar(File jar, String path) throws Exception { return new URL(FileUtil.urlForArchiveOrDir(jar), path); }
Example 16
Source File: JBProperties.java From netbeans with Apache License 2.0 | 4 votes |
private static void addFileToList(List<URL> list, File f) { URL u = FileUtil.urlForArchiveOrDir(f); if (u != null) { list.add(u); } }
Example 17
Source File: MethodInvocationContext.java From netbeans with Apache License 2.0 | 4 votes |
public static URL apiJarURL() { URL jarFile = MethodInvocationContext.class.getProtectionDomain().getCodeSource().getLocation(); return FileUtil.urlForArchiveOrDir(FileUtil.archiveOrDirForURL(jarFile)); }
Example 18
Source File: Classpaths.java From netbeans with Apache License 2.0 | 4 votes |
private URL createClasspathEntry(String text) { File entryFile = helper.resolveFile(text); return FileUtil.urlForArchiveOrDir(entryFile); }
Example 19
Source File: MavenRefactoringElementImplementation.java From netbeans with Apache License 2.0 | 4 votes |
@Override public synchronized FileObject getParentFile() { if (file == null) { try { Artifact a = createArtifact(ref.artifact); File jar = a.getFile(); if (!jar.exists()) { //#236842 try to minimize the cases when we need to let maven resolve and download artifacts jar = RepositoryUtil.downloadArtifact(ref.artifact); // probably a no-op, since local hits must have been indexed } URL jarURL = FileUtil.urlForArchiveOrDir(jar); if (jarURL != null) { SourceForBinaryQuery.Result2 result = SourceForBinaryQuery.findSourceRoots2(jarURL); if (result.preferSources()) { FileObject[] roots = result.getRoots(); for (FileObject root : roots) { file = root.getFileObject(ref.clazz.replace('.', '/') + ".java"); if (file != null) { LOG.log(Level.FINE, "found source file {0}", file); break; } } if (file == null) { if (roots.length > 0) { LOG.log(Level.WARNING, "did not find {0} among {1}", new Object[] {ref.clazz, Arrays.asList(roots)}); } else { LOG.log(Level.FINE, "no source roots for {0}", jar); } } } else { LOG.log(Level.FINE, "ignoring non-preferred sources for {0}", jar); } } else { LOG.log(Level.WARNING, "no URL for {0}", jar); } if (file == null) { if (jar.isFile()) { file = URLMapper.findFileObject(new URL("jar:" + jar.toURI() + "!/" + ref.clazz.replace('.', '/') + ".class")); if (file == null) { LOG.log(Level.WARNING, "did not find {0} in {1}", new Object[] {ref.clazz, jar}); } } else { LOG.log(Level.WARNING, "{0} does not exist", jar); } } } catch (Exception x) { LOG.log(Level.WARNING, null, x); } if (file == null) { file = NO_FILE; } } return file; }
Example 20
Source File: TranslateClassPath.java From netbeans with Apache License 2.0 | 4 votes |
private File[] translateEntry(final String path, boolean disableSources) throws BuildException { final File entryFile = new HackedFile(path); try { final URL entry = FileUtil.urlForArchiveOrDir(entryFile); final SourceForBinaryQuery.Result2 r = SourceForBinaryQuery.findSourceRoots2(entry); boolean appendEntry = false; if (!disableSources && r.preferSources() && r.getRoots().length > 0) { final List<File> translated = new ArrayList<File>(); for (FileObject source : r.getRoots()) { final File sourceFile = FileUtil.toFile(source); if (sourceFile == null) { log("Source URL: " + source.toURL().toExternalForm() + " cannot be translated to file, skipped", Project.MSG_WARN); appendEntry = true; continue; } final Boolean bamiResult = clean ? BuildArtifactMapperImpl.clean(Utilities.toURI(sourceFile).toURL()) : BuildArtifactMapperImpl.ensureBuilt(Utilities.toURI(sourceFile).toURL(), getProject(), true, true); if (bamiResult == null) { appendEntry = true; continue; } if (!bamiResult) { throw new UserCancel(); } for (URL binary : BinaryForSourceQuery.findBinaryRoots(source.toURL()).getRoots()) { final FileObject binaryFO = URLMapper.findFileObject(binary); final File finaryFile = binaryFO != null ? FileUtil.toFile(binaryFO) : null; if (finaryFile != null) { if (moduleOriented && finaryFile.isDirectory() && "jar".equals(entry.getProtocol())) { boolean hasModuleInfo = finaryFile.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return "module-info.class".equals(name); } }).length > 0; if (!hasModuleInfo) { File jarFile = new File(finaryFile.getParentFile(), entryFile.getName()); Jar jarTask = new Jar(); jarTask.setProject(getProject()); jarTask.setDestFile(jarFile); jarTask.setBasedir(finaryFile); jarTask.setExcludes(".netbeans*"); jarTask.execute(); translated.add(jarFile); continue; } } translated.add(finaryFile); } } } if (appendEntry) { translated.add(entryFile); } return translated.toArray(new File[translated.size()]); } else { return new File[] {entryFile}; } } catch (IOException ex) { throw new BuildException(ex); } }