当前位置: 首页>>代码示例>>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;未经允许,请勿转载。