當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUtil.getArchiveRoot方法代碼示例

本文整理匯總了Java中org.openide.filesystems.FileUtil.getArchiveRoot方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtil.getArchiveRoot方法的具體用法?Java FileUtil.getArchiveRoot怎麽用?Java FileUtil.getArchiveRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openide.filesystems.FileUtil的用法示例。


在下文中一共展示了FileUtil.getArchiveRoot方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: registerLibrary

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:JavadocForBinaryQueryLibraryImplTest.java

示例2: createBootPath

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private ClassPath createBootPath () {
    try {
        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 = Utilities.toURI(f).toURL();
            if (FileUtil.isArchiveFile(url)) {
                url = FileUtil.getArchiveRoot(url);
            }
            roots.add (url);
        }
        return ClassPathSupport.createClassPath(roots.toArray(new URL[roots.size()]));
    } catch (MalformedURLException ex) {}
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:JavaSourceTaskFactoryTest.java

示例3: getBootClassPath

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private static synchronized ClassPath getBootClassPath() {
    if (bootClassPath == null) {
        String cp = System.getProperty("sun.boot.class.path");
        List<URL> urls = new ArrayList<>();
        String[] paths = cp.split(Pattern.quote(System.getProperty("path.separator")));
        for (String path : paths) {
            File f = new File(path);

            if (!f.canRead())
                continue;

            FileObject fo = FileUtil.toFileObject(f);
            if (FileUtil.isArchiveFile(fo)) {
                fo = FileUtil.getArchiveRoot(fo);
            }
            if (fo != null) {
                urls.add(fo.toURL());
            }
        }
        bootClassPath = ClassPathSupport.createClassPath((URL[])urls.toArray(new URL[0]));
    }
    return bootClassPath;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:TestJavaPlatformProviderImpl.java

示例4: scanJarForPackageNames

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
/**
 * Scans a given jar file for all packages which contains at least one
 * .class file. Found entries are in the form of a regular java package
 * (x.y.z).
 * 
 * @param jarFile jar file to be scanned
 * @param packages a set into which found packages will be added
 */
public static void scanJarForPackageNames(final Set<String> packages, final File jarFile) {
    FileObject jarFileFO = FileUtil.toFileObject(jarFile);
    if (jarFileFO == null) {
        // Broken classpath entry, perhaps.
        return;
    }
    FileObject root = FileUtil.getArchiveRoot(jarFileFO);
    if (root == null) {
        // Not really a JAR?
        return;
    }
    Set<FileObject> pkgs = new HashSet<FileObject>();
    scanForPackages(pkgs, root, "class"); // NOI18N
    for (FileObject pkg : pkgs) {
        if (root.equals(pkg)) { // default package #71532
            continue;
        }
        String pkgS = pkg.getPath().replace('/', '.');
        if (isValidJavaFQN(pkgS))
            packages.add(pkgS);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:ApisupportAntUtils.java

示例5: testAddRoots

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public void testAddRoots() throws Exception {
    NbModuleProject prj = TestBase.generateStandaloneModule(getWorkDir(), "module");
    FileObject src = prj.getSourceDirectory();
    FileObject jar = TestFileUtils.writeZipFile(FileUtil.toFileObject(getWorkDir()), "a.jar", "entry:contents");
    URL root = FileUtil.getArchiveRoot(jar.toURL());
    assertTrue(ProjectClassPathModifier.addRoots(new URL[] {root}, src, ClassPath.COMPILE));
    assertFalse(ProjectClassPathModifier.addRoots(new URL[] {root}, src, ClassPath.COMPILE));
    FileObject releaseModulesExt = prj.getProjectDirectory().getFileObject("release/modules/ext");
    assertNotNull(releaseModulesExt);
    assertNotNull(releaseModulesExt.getFileObject("a.jar"));
    jar = TestFileUtils.writeZipFile(releaseModulesExt, "b.jar", "entry2:contents");
    root = FileUtil.getArchiveRoot(jar.toURL());
    assertTrue(ProjectClassPathModifier.addRoots(new URL[] {root}, src, ClassPath.COMPILE));
    assertFalse(ProjectClassPathModifier.addRoots(new URL[] {root}, src, ClassPath.COMPILE));
    assertEquals(2, releaseModulesExt.getChildren().length);
    String projectXml = prj.getProjectDirectory().getFileObject("nbproject/project.xml").toURL().toString();
    InputSource input = new InputSource(projectXml);
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(nbmNamespaceContext());
    assertEquals(projectXml, "ext/a.jar", xpath.evaluate("//nbm:class-path-extension[1]/nbm:runtime-relative-path", input));
    assertEquals(projectXml, "release/modules/ext/a.jar", xpath.evaluate("//nbm:class-path-extension[1]/nbm:binary-origin", input));
    assertEquals(projectXml, "ext/b.jar", xpath.evaluate("//nbm:class-path-extension[2]/nbm:runtime-relative-path", input));
    assertEquals(projectXml, "release/modules/ext/b.jar", xpath.evaluate("//nbm:class-path-extension[2]/nbm:binary-origin", input));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:ModuleProjectClassPathExtenderTest.java

示例6: testResources

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public void testResources() throws Exception { // #208816
    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 res = FileUtil.createFolder(d, "src/main/resources");
    FileObject tres = FileUtil.createFolder(d, "src/test/resources");
    CharSequence log = Log.enable(BinaryForSourceQuery.class.getName(), Level.FINE);
    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(res.toURL()).getRoots()));
    assertEquals(Arrays.asList(new URL(d.toURL(), "target/test-classes/"), url0), Arrays.asList(BinaryForSourceQuery.findBinaryRoots(tres.toURL()).getRoots()));
    String logS = log.toString();
    assertFalse(logS, logS.contains("-> nil"));
    assertTrue(logS, logS.contains("ProjectBinaryForSourceQuery"));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:MavenBinaryForSourceQueryImplTest.java

示例7: createBootPath

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private static ClassPath createBootPath () throws IOException {
    String bootPath = System.getProperty ("sun.boot.class.path");   //NOI18N
    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 = Utilities.toURI(f).toURL();
        if (FileUtil.isArchiveFile(url)) {
            url = FileUtil.getArchiveRoot(url);
        }
        roots.add (url);
    }
    return ClassPathSupport.createClassPath(roots.toArray(new URL[roots.size()]));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:ElementHandleTest.java

示例8: createBootPath

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private ClassPath createBootPath () throws MalformedURLException {
    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 = org.openide.util.Utilities.toURI(f).toURL();
        if (FileUtil.isArchiveFile(url)) {
            url = FileUtil.getArchiveRoot(url);
        }
        roots.add (url);
    }
    return ClassPathSupport.createClassPath(roots.toArray(new URL[roots.size()]));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:JavaSourceTest.java

示例9: testAddRemoveRoot

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public void testAddRemoveRoot () throws Exception {
    final FileObject rootFolder = this.scratch.createFolder("Root");
    final FileObject jarFile = TestFileUtils.writeZipFile(scratch, "archive.jar", "Test.properties:");
    final FileObject jarRoot = FileUtil.getArchiveRoot(jarFile);
    ProjectClassPathModifier.addRoots (new URL[] {rootFolder.toURL()}, this.src, ClassPath.COMPILE);
    String cp = this.eval.getProperty("javac.classpath");
    assertNotNull (cp);
    String[] cpRoots = PropertyUtils.tokenizePath (cp);
    assertNotNull (cpRoots);
    assertEquals(1,cpRoots.length);
    assertEquals(rootFolder,this.helper.resolveFileObject(cpRoots[0]));
    ProjectClassPathModifier.removeRoots (new URL[] {rootFolder.toURL()},this.src, ClassPath.COMPILE);
    cp = this.eval.getProperty("javac.classpath");
    assertNotNull (cp);
    cpRoots = PropertyUtils.tokenizePath (cp);
    assertNotNull (cpRoots);
    assertEquals(0,cpRoots.length);
    ProjectClassPathModifier.addRoots(new URL[] {jarRoot.toURL()},this.test,ClassPath.EXECUTE);
    cp = this.eval.getProperty("run.test.classpath");
    assertNotNull (cp);
    cpRoots = PropertyUtils.tokenizePath (cp);
    assertNotNull (cpRoots);
    assertEquals(5,cpRoots.length);
    assertEquals(this.helper.resolveFileObject(cpRoots[4]),jarFile);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:J2SEProjectClassPathModifierTest.java

示例10: createClassPath

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private static ClassPath createClassPath(List<URL> roots) {
    List<URL> jarRootURLs = new ArrayList<URL>();
    for (URL url : roots) {
        // Workaround for #126307: ClassPath roots should be JAR root URL, not file URLs.
        if (FileUtil.getArchiveFile(url) == null) {
            // Not an archive root URL.
            url = FileUtil.getArchiveRoot(url);
        }
        jarRootURLs.add(url);
    }
    return ClassPathSupport.createClassPath((jarRootURLs.toArray(new URL[jarRootURLs.size()])));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:SpringUtilities.java

示例11: translateURL

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private static URL translateURL(URL u) {
    if (FileUtil.isArchiveFile(u)) {
        return FileUtil.getArchiveRoot(u);
    } else {
        return u;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:ClassSourceResolver.java

示例12: setUp

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@Override
public void setUp() throws IOException, PropertyVetoException {

    // create projects
    projects.add(createProject("projectDir1"));
    projects.add(createProject("projectDir2"));

    List l = new LinkedList<DataObject>();
    clearWorkDir();
    FileObject root = FileUtil.toFileObject(getWorkDir());
    FileObject test1 = root.createFolder("test1");
    FileObject test2 = root.createFolder("test2");
    FileObject test1a = test1.createFolder("A");
    FileObject test1aTestClassJava = test1a.createData("TestClass.java");
    FileObject test2DataTxt = test2.createData("data.txt");
    createZipFile(test2);
    DataObject shadowFile = createShadowFile(test2DataTxt);

    FileObject archiveZip = test2.getFileObject("archive.zip");
    assertTrue(FileUtil.isArchiveFile(archiveZip));
    FileObject archiveRoot = FileUtil.getArchiveRoot(archiveZip);
    assertNotNull(archiveRoot);
    FileObject test2ArchiveZipBTxt = archiveRoot.getFileObject("b.txt");

    // test1/A/TestClass.java
    l.add(DataObject.find(test1aTestClassJava));
    // test2/data.txt
    l.add(DataObject.find(test2DataTxt));
    // test2/archive.zip:b.txt
    l.add(DataObject.find(test2ArchiveZipBTxt));
    // /testDataShadows/testShadowFile -> test2/data.txt
    l.add(shadowFile);
    dataObjects = l;
    List<Lookup.Provider> context = new LinkedList<Lookup.Provider>();
    context.addAll(projects);
    context.addAll(dataObjects);
    action = new CopyPathToClipboardAction(context);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:CopyPathToClipboardActionTest.java

示例13: getJavadocJarRoot

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private URL[] getJavadocJarRoot(File file) {
    try {
        if (file.exists()) {
            FileObject fo = FileUtil.toFileObject(file);
            if (!FileUtil.isArchiveFile(fo)) {
                //#124175  ignore any jar files that are not jar files (like when downloaded file is actually an error html page).
                Logger.getLogger(RepositoryForBinaryQueryImpl.class.getName()).log(Level.INFO, "javadoc in repository is not really a JAR: {0}", file);
                return new URL[0];
            }
            //try detecting the source path root, in case the source jar has the sources not in root.
            Date date = (Date) fo.getAttribute(ATTR_STAMP);
            String path = (String) fo.getAttribute(ATTR_PATH);
            if (date == null || fo.lastModified().after(date)) {
                path = checkPath(FileUtil.getArchiveRoot(fo), fo);
            }

            URL[] url;
            if (path != null) {
                url = new URL[1];
                URL root = FileUtil.getArchiveRoot(Utilities.toURI(file).toURL());
                if (!path.endsWith("/")) { //NOI18N
                    path = path + "/"; //NOI18N
                }
                url[0] = new URL(root, path);
            } else {
                 url = new URL[1];
                url[0] = FileUtil.getArchiveRoot(Utilities.toURI(file).toURL());
            }
            return url;
        }
    } catch (MalformedURLException exc) {
        ErrorManager.getDefault().notify(exc);
    }
    return new URL[0];
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:36,代碼來源:RepositoryForBinaryQueryImpl.java

示例14: addToProjectClassPath

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@Override
public Boolean addToProjectClassPath(FileObject projectArtifact, String classPathType) throws IOException, UnsupportedOperationException {
    URL u = jar.toURI().toURL();
    FileObject jarFile = FileUtil.toFileObject(jar);
    if (jarFile == null) {
        return Boolean.FALSE; // Issue 147451
    }
    if (FileUtil.isArchiveFile(jarFile)) {
        u = FileUtil.getArchiveRoot(u);
    }
    return Boolean.valueOf(ProjectClassPathModifier.addRoots(new URL[] {u}, projectArtifact, classPathType));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:ClassSourceResolver.java

示例15: getFxSources

import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private static List<URI> getFxSources(@NonNull final File javaHome) {
    try {
        final File f = new File (javaHome, FX_SOURCES);
        if (f.exists() && f.canRead()) {
            final URL url = FileUtil.getArchiveRoot(Utilities.toURI(f).toURL());
            final URI uri = url.toURI();
            return Collections.singletonList (uri);
        }
    } catch (MalformedURLException | URISyntaxException e) {
        Exceptions.printStackTrace(e);
    }
    return Collections.emptyList();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:JavaFxDefaultSourcesImpl.java


注:本文中的org.openide.filesystems.FileUtil.getArchiveRoot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。