Java Code Examples for org.openide.filesystems.FileUtil#getArchiveRoot()
The following examples show how to use
org.openide.filesystems.FileUtil#getArchiveRoot() .
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: GradleSourceForRepository.java From netbeans with Apache License 2.0 | 6 votes |
@Override public FileObject[] getRoots() { FileObject[] ret = new FileObject[0]; FileObject fo = FileUtil.toFileObject(root); if (fo != null) { if (FileUtil.isArchiveFile(fo)) { FileObject arch = FileUtil.getArchiveRoot(fo); if (arch != null) { ret = new FileObject[]{arch}; } } else { ret = new FileObject[]{fo}; } } return ret; }
Example 2
Source File: SourceForBinaryQueryTest.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected void setUp() throws Exception { this.clearWorkDir(); super.setUp(); File wd = this.getWorkDir(); FileObject wdfo = FileUtil.toFileObject(wd); br1 = wdfo.createFolder("bin1"); br2 = wdfo.createFolder("bin2"); sr1 = wdfo.createFolder("src1"); File zf = new File (wd,"src2.zip"); ZipOutputStream zos = new ZipOutputStream (new FileOutputStream (zf)); zos.putNextEntry(new ZipEntry("foo.java")); zos.closeEntry(); zos.close(); sr2 = FileUtil.getArchiveRoot(FileUtil.toFileObject(zf)); map.put(br1.toURL(), Collections.singletonList(sr1)); map.put(br2.toURL(), Collections.singletonList(sr2)); }
Example 3
Source File: TemplateManager.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
public static List<Template> findTemplates(String subFolder) { List<Template> tmp = new ArrayList<>(); URL location = AndroidTemplateLocator.class.getProtectionDomain().getCodeSource().getLocation(); FileObject fo = URLMapper.findFileObject(location); FileObject archiveFile = FileUtil.getArchiveRoot(fo); if (archiveFile == null && fo.isRoot()) { archiveFile = fo; } FileObject rootDir = archiveFile.getFileObject("/android/studio/imports/templates/" + subFolder); Enumeration<? extends FileObject> children = rootDir.getChildren(true); while (children.hasMoreElements()) { FileObject nextElement = children.nextElement(); if ("template.xml".equalsIgnoreCase(nextElement.getNameExt())) { Template template = new Template(nextElement); TemplateMetadata metadata = template.getMetadata(); tmp.add(template); } } return tmp; }
Example 4
Source File: CssHelpResolver.java From netbeans with Apache License 2.0 | 6 votes |
public static synchronized URL getHelpZIPURL() { if (HELP_ZIP_URL == null) { File f = InstalledFileLocator.getDefault().locate(HELP_LOCATION, null, false); //NoI18N if (f != null) { try { URL urll = f.toURI().toURL(); //toURI should escape the illegal characters like spaces HELP_ZIP_URL = FileUtil.getArchiveRoot(urll); } catch (java.net.MalformedURLException e) { ErrorManager.getDefault().notify(e); } } else { Logger.getLogger(CssHelpResolver.class.getSimpleName()) .info("Cannot locate the css documentation file " + HELP_LOCATION ); //NOI18N } } return HELP_ZIP_URL; }
Example 5
Source File: CachingFileManagerTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testGetFileForInputWithCachingArchive() throws Exception { final File wd = getWorkDir(); final File archiveFile = new File (wd, "src.zip"); final ZipOutputStream out = new ZipOutputStream(new FileOutputStream(archiveFile)); try { out.putNextEntry(new ZipEntry("org/me/resources/test.txt")); out.write("test".getBytes()); } finally { out.close(); } final URL archiveRoot = FileUtil.getArchiveRoot(Utilities.toURI(archiveFile).toURL()); final URI expectedURI = new URL (archiveRoot.toExternalForm()+"org/me/resources/test.txt").toURI(); doTestGetFileForInput(ClassPathSupport.createClassPath(archiveRoot), Arrays.asList( Pair.<Pair<String,String>,URI>of(Pair.<String,String>of("","org/me/resources/test.txt"), expectedURI), Pair.<Pair<String,String>,URI>of(Pair.<String,String>of("org.me","resources/test.txt"), expectedURI), Pair.<Pair<String,String>,URI>of(Pair.<String,String>of("org.me","resources/doesnotexist.txt"), null) )); }
Example 6
Source File: JBJ2eePlatformFactory.java From netbeans with Apache License 2.0 | 6 votes |
private static boolean containsService(LibraryImplementation library, String serviceName, String serviceImplName) { List roots = library.getContent(J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH); for (Iterator it = roots.iterator(); it.hasNext();) { URL rootUrl = (URL) it.next(); FileObject root = URLMapper.findFileObject(rootUrl); if (root != null && "jar".equals(rootUrl.getProtocol())) { //NOI18N FileObject archiveRoot = FileUtil.getArchiveRoot(FileUtil.getArchiveFile(root)); String serviceRelativePath = "META-INF/services/" + serviceName; //NOI18N FileObject serviceFO = archiveRoot.getFileObject(serviceRelativePath); if (serviceFO != null && containsService(serviceFO, serviceName, serviceImplName)) { return true; } } } return false; }
Example 7
Source File: ClassPathProviderImpl.java From netbeans with Apache License 2.0 | 6 votes |
public ClassPath findClassPath(FileObject file, String type) { if(ClassPath.SOURCE.equals(type)){ return this.classPath; } if (ClassPath.COMPILE.equals(type)){ try { URL eclipselinkJarUrl = Class.forName("javax.persistence.EntityManager").getProtectionDomain().getCodeSource().getLocation(); URL[] urls = new URL[]{FileUtil.getArchiveRoot(eclipselinkJarUrl)}; return ClassPathSupport.createClassPath(urls); } catch (Exception ex) { throw new RuntimeException(ex); } } if (ClassPath.BOOT.equals(type)){ return JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries(); } return null; }
Example 8
Source File: ELTestBase.java From netbeans with Apache License 2.0 | 6 votes |
/** * Creates boot {@link ClassPath} for platform the test is running on, * it uses the sun.boot.class.path property to find out the boot path roots. * @return ClassPath * @throws java.io.IOException when boot path property contains non valid path */ public static ClassPath createBootClassPath() throws IOException { String bootPath = System.getProperty("sun.boot.class.path"); String[] paths = bootPath.split(File.pathSeparator); List<URL> roots = new ArrayList<URL>(paths.length); for (String path : paths) { File f = new File(path); if (!f.exists()) { continue; } URL url = f.toURI().toURL(); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); } roots.add(url); // System.out.println(url); } // System.out.println("-----------"); return ClassPathSupport.createClassPath(roots.toArray(new URL[roots.size()])); }
Example 9
Source File: MavenBinaryForSourceQueryImplTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testGeneratedSources() throws Exception { // #187595 TestFileUtils.writeFile(d, "pom.xml", "<project xmlns='http://maven.apache.org/POM/4.0.0'>" + "<modelVersion>4.0.0</modelVersion>" + "<groupId>grp</groupId>" + "<artifactId>art</artifactId>" + "<packaging>jar</packaging>" + "<version>0</version>" + "</project>"); FileObject src = FileUtil.createFolder(d, "src/main/java"); FileObject gsrc = FileUtil.createFolder(d, "target/generated-sources/xjc"); gsrc.createData("Whatever.class"); FileObject tsrc = FileUtil.createFolder(d, "src/test/java"); FileObject gtsrc = FileUtil.createFolder(d, "target/generated-test-sources/jaxb"); gtsrc.createData("Whatever.class"); File repo = EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile(); File art0 = new File(repo, "grp/art/0/art-0.jar"); URL url0 = FileUtil.getArchiveRoot(art0.toURI().toURL()); assertEquals(Arrays.asList(new URL(d.toURL(), "target/classes/"), url0), Arrays.asList(BinaryForSourceQuery.findBinaryRoots(src.toURL()).getRoots())); assertEquals(Arrays.asList(new URL(d.toURL(), "target/classes/"), url0), Arrays.asList(BinaryForSourceQuery.findBinaryRoots(gsrc.toURL()).getRoots())); assertEquals(Arrays.asList(new URL(d.toURL(), "target/test-classes/"), url0), Arrays.asList(BinaryForSourceQuery.findBinaryRoots(tsrc.toURL()).getRoots())); assertEquals(Arrays.asList(new URL(d.toURL(), "target/test-classes/"), url0), Arrays.asList(BinaryForSourceQuery.findBinaryRoots(gtsrc.toURL()).getRoots())); }
Example 10
Source File: J2eePlatformTestNode.java From netbeans with Apache License 2.0 | 6 votes |
private List<SourceGroup> getKeys () { List<SourceGroup> result; J2eePlatform j2eePlatform = ((J2eePlatformTestNode)this.getNode()).getPlatform(); if (j2eePlatform != null && j2eePlatform.isToolSupported(J2eePlatform.TOOL_EMBEDDABLE_EJB)) { File[] classpathEntries = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_EMBEDDABLE_EJB); result = new ArrayList<SourceGroup>(classpathEntries.length); for (int i = 0; i < classpathEntries.length; i++) { FileObject file = FileUtil.toFileObject(classpathEntries[i]); if (file != null) { FileObject archiveFile = FileUtil.getArchiveRoot(file); if (archiveFile != null) { result.add(ProjectUISupport.createLibrariesSourceGroup(archiveFile, file.getNameExt(), icon, icon)); } } } } else { result = Collections.<SourceGroup>emptyList(); } return result; }
Example 11
Source File: SourceForBinaryQueryLibraryImplTest.java From netbeans with Apache License 2.0 | 6 votes |
private void registerLibrary(final String libName, final File cp, final File src) throws Exception { DefaultLibraryImplementation lib; lib = new DefaultLibraryImplementation("j2se", new String[]{"classpath", "src"}); lib.setName(libName); List<URL> l = new ArrayList<URL>(); URL u = Utilities.toURI(cp).toURL(); if (cp.getPath().endsWith(".jar")) { u = FileUtil.getArchiveRoot(u); } l.add(u); lib.setContent("classpath", l); if (src != null) { l = new ArrayList<URL>(); u = Utilities.toURI(src).toURL(); if (src.getPath().endsWith(".jar")) { u = FileUtil.getArchiveRoot(u); } l.add(u); lib.setContent("src", l); } TestLibraryProviderImpl prov = TestLibraryProviderImpl.getDefault(); prov.addLibrary(lib); }
Example 12
Source File: JavadocForBinaryQueryLibraryImplTest.java From netbeans with Apache License 2.0 | 6 votes |
private void registerLibrary(final String libName, final File cp, final File javadoc) throws Exception { DefaultLibraryImplementation lib; lib = new DefaultLibraryImplementation("j2se", new String[]{"classpath", "javadoc"}); lib.setName(libName); List<URL> l = new ArrayList<URL>(); URL u = Utilities.toURI(cp).toURL(); if (cp.getPath().endsWith(".jar")) { u = FileUtil.getArchiveRoot(u); } l.add(u); lib.setContent("classpath", l); l = new ArrayList<URL>(); u = Utilities.toURI(javadoc).toURL(); if (javadoc.getPath().endsWith(".jar")) { u = FileUtil.getArchiveRoot(u); } l.add(u); lib.setContent("javadoc", l); TestLibraryProviderImpl prov = TestLibraryProviderImpl.getDefault(); prov.addLibrary(lib); }
Example 13
Source File: RepositoryForBinaryQueryImpl.java From netbeans with Apache License 2.0 | 5 votes |
@Override public synchronized URL[] getRoots() { URL[] toRet; checkCurrentProject(); Project prj = currentProject; if (prj != null) { toRet = new URL[0]; } else { URL root = FileUtil.isArchiveFile(binary) ? FileUtil.getArchiveRoot(binary) : binary; File[] f = SourceJavadocByHash.find(root, true); if (f != null) { List<URL> accum = new ArrayList<URL>(); for (File ff : f) { URL[] url = getJavadocJarRoot(ff); if (url != null) { accum.addAll(Arrays.asList(url)); } } toRet = accum.toArray(new URL[0]); } else if (javadocJarFile != null && javadocJarFile.exists()) { toRet = getJavadocJarRoot(javadocJarFile); } else if (fallbackJavadocJarFile != null && fallbackJavadocJarFile.exists()) { toRet = getJavadocJarRoot(fallbackJavadocJarFile); } else { toRet = checkShadedMultiJars(); } } if (!Arrays.equals(cached, toRet)) { //how to figure otherwise that something changed, possibly multiple people hold the result instance // and one asks the roots, later we get event from outside, but then the cached value already updated.. RP.post(new Runnable() { @Override public void run() { support.fireChange(); } }); } cached = toRet; return toRet; }
Example 14
Source File: ConfigurationsNode.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { File javadoc = GradleArtifactStore.getDefault().getJavadoc(FileUtil.toFile(mainJar)); FileObject fo = FileUtil.toFileObject(javadoc); if (fo != null) { FileObject arch = FileUtil.getArchiveRoot(fo); if (arch != null) { FileObject index = arch.getFileObject("index.html"); //NOI18N if (index != null) { URL indexUrl = index.toURL(); HtmlBrowser.URLDisplayer.getDefault().showURL(indexUrl); } } } }
Example 15
Source File: MultiModuleClassPathProviderTest.java From netbeans with Apache License 2.0 | 5 votes |
private static FileObject createJar( @NonNull final FileObject folder, @NonNull final String name) throws IOException { final FileObject f = FileUtil.createData(folder, name); try (final ZipOutputStream out = new ZipOutputStream(f.getOutputStream())) { //write something } return FileUtil.getArchiveRoot(f); }
Example 16
Source File: PerfJavacIntefaceGCTest.java From netbeans with Apache License 2.0 | 5 votes |
protected void setUp() throws Exception { clearWorkDir(); workDir = getWorkDir(); TestUtil.copyFiles( workDir, TestUtil.RT_JAR, "jdk/JTable.java" ); rtJar = new File( workDir, TestUtil.RT_JAR ); URL url = FileUtil.getArchiveRoot (Utilities.toURI(rtJar).toURL()); this.bootPath = ClassPathSupport.createClassPath (new URL[] {url}); this.classPath = ClassPathSupport.createClassPath(new URL[0]); }
Example 17
Source File: ClasspathInfoTest.java From netbeans with Apache License 2.0 | 5 votes |
protected void setUp() throws Exception { this.clearWorkDir(); File workDir = getWorkDir(); File cacheFolder = new File (workDir, "cache"); //NOI18N cacheFolder.mkdirs(); IndexUtil.setCacheFolder(cacheFolder); rtJar = FileUtil.normalizeFile(TestUtil.createRT_JAR(workDir)); URL url = FileUtil.getArchiveRoot (Utilities.toURI(rtJar).toURL()); this.bootPath = ClassPathSupport.createClassPath (new URL[] {url}); this.classPath = ClassPathSupport.createClassPath(new URL[0]); }
Example 18
Source File: TextDocumentServiceImpl.java From netbeans with Apache License 2.0 | 5 votes |
public static FileObject fromUri(String uri) throws MalformedURLException { File cacheDir = Places.getCacheSubfile("java-server"); URI uriUri = URI.create(uri); URI relative = cacheDir.toURI().relativize(uriUri); if (relative != null && new File(cacheDir, relative.toString()).canRead()) { String segmentAndPath = relative.toString(); int slash = segmentAndPath.indexOf('/'); String segment = segmentAndPath.substring(0, slash); String path = segmentAndPath.substring(slash + 1); File segments = new File(cacheDir, "segments"); Properties props = new Properties(); try (InputStream in = new FileInputStream(segments)) { props.load(in); String archiveUri = props.getProperty(segment); FileObject archive = URLMapper.findFileObject(URI.create(archiveUri).toURL()); archive = archive != null ? FileUtil.getArchiveRoot(archive) : null; FileObject file = archive != null ? archive.getFileObject(path) : null; if (file != null) { return file; } } catch (IOException ex) { Exceptions.printStackTrace(ex); } } return URLMapper.findFileObject(URI.create(uri).toURL()); }
Example 19
Source File: GradleSourceForRepository.java From netbeans with Apache License 2.0 | 5 votes |
@Override public URL[] getRoots() { URL[] ret = new URL[0]; FileObject fo = FileUtil.toFileObject(root); if (fo != null) { FileObject arch = FileUtil.getArchiveRoot(fo); if (arch != null) { ret = new URL[]{arch.toURL()}; } } return ret; }
Example 20
Source File: RepositoryForBinaryQueryImplTest.java From netbeans with Apache License 2.0 | 4 votes |
@Test public void testFindSources() throws IOException { File repo = EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile(); File parent = new File(repo, "nbtest/testprj/1.0"); RepositoryForBinaryQueryImpl query = new RepositoryForBinaryQueryImpl(); // find nothing File artifact = new File(parent, "testprj-1.0.jar"); TestFileUtils.writeZipFile(artifact, "META-INF/MANIFEST.MF:Version:1.0"); URL artifactRoot = FileUtil.getArchiveRoot(artifact.toURI().toURL()); SourceForBinaryQuery.Result result = query.findSourceRoots(artifactRoot); assertNotNull(result); assertEquals(0, result.getRoots().length); // find regular sources File sources = new File(parent, "testprj-1.0-sources.jar"); TestFileUtils.writeZipFile(sources, "META-INF/MANIFEST.MF:Version:1.0"); URL sourcesRoot = FileUtil.getArchiveRoot(sources.toURI().toURL()); result = query.findSourceRoots(artifactRoot); assertEquals(1, result.getRoots().length); assertEquals(sourcesRoot, result.getRoots()[0].toURL()); // classifier attachments should fall back to the regular sources File attachment = new File(parent, "testprj-1.0-attachment.jar"); TestFileUtils.writeZipFile(attachment, "META-INF/MANIFEST.MF:Version:1.0"); URL attachmentRoot = FileUtil.getArchiveRoot(attachment.toURI().toURL()); result = query.findSourceRoots(attachmentRoot); assertEquals(1, result.getRoots().length); assertEquals(sourcesRoot, result.getRoots()[0].toURL()); // classifier attachments should find their own sources File attachmentSources = new File(parent, "testprj-1.0-attachment-sources.jar"); TestFileUtils.writeZipFile(attachmentSources, "META-INF/MANIFEST.MF:Version:1.0"); URL attachmentSourcesRoot = FileUtil.getArchiveRoot(attachmentSources.toURI().toURL()); result = query.findSourceRoots(attachmentRoot); assertEquals(1, result.getRoots().length); assertEquals(attachmentSourcesRoot, result.getRoots()[0].toURL()); // result reacts to filesystem changes org.codehaus.plexus.util.FileUtils.forceDelete(attachmentSources); assertEquals(1, result.getRoots().length); assertEquals(sourcesRoot, result.getRoots()[0].toURL()); org.codehaus.plexus.util.FileUtils.forceDelete(sources); assertEquals(0, result.getRoots().length); TestFileUtils.writeZipFile(sources, "META-INF/MANIFEST.MF:Version:1.0"); assertEquals(1, result.getRoots().length); assertEquals(sourcesRoot, result.getRoots()[0].toURL()); }