Java Code Examples for org.openide.filesystems.FileUtil#getArchiveFile()

The following examples show how to use org.openide.filesystems.FileUtil#getArchiveFile() . 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: WebAppParseSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private URL findExternalURL(FileObject fo) {
    // PENDING - URLMapper.EXTERNAL does not seem to be working now, so using this workaround
    File f = FileUtil.toFile(fo);
    if ((f != null)/* && (f.isDirectory())*/) {
        try {
            return f.toURI().toURL();
        } catch (MalformedURLException e) {
            LOG.log(Level.INFO, null, e);
        }
    }
    // fallback
    URL u = URLMapper.findURL(fo,  URLMapper.EXTERNAL);
    URL archiveFile = FileUtil.getArchiveFile(u);
    if (archiveFile != null) {
        return archiveFile;
    }
    return u;
}
 
Example 2
Source File: AppClientModuleProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public File[] getRequiredLibraries() {
    ProjectSourcesClassPathProvider cppImpl = project.getLookup().lookup(ProjectSourcesClassPathProvider.class);
    // do not use COMPILE classpath here because it contains dependencies
    // with *provided* scope which should not be deployed
    ClassPath cp = cppImpl.getProjectSourcesClassPath(ClassPath.EXECUTE);
    List<File> files = new ArrayList<File>();
    for (FileObject fo : cp.getRoots()) {
        fo = FileUtil.getArchiveFile(fo);
        if (fo == null) {
            continue;
        }
        files.add(FileUtil.toFile(fo));
    }
    return files.toArray(new File[files.size()]);
}
 
Example 3
Source File: Customizer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@org.netbeans.api.annotations.common.SuppressWarnings(value="DMI_BLOCKING_METHODS_ON_URL", justification="File URLs only")
public Object getElementAt(int index) {
    java.util.List list = this.getData();
    URL url = (URL)list.get(index);
    if ("jar".equals(url.getProtocol())) {      //NOI18N
        URL fileURL = FileUtil.getArchiveFile (url);
        if (FileUtil.getArchiveRoot(fileURL).equals(url)) {
            // really the root
            url = fileURL;
        } else {
            // some subdir, just show it as is
            return url.toExternalForm();
        }
    }
    if ("file".equals(url.getProtocol())) { // NOI18N
        File f = new File (URI.create(url.toExternalForm()));
        return f.getAbsolutePath();
    }
    else {
        return url.toExternalForm();
    }
}
 
Example 4
Source File: CustomizerSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the element at the specified position in this list.
 *
 * @param index The element position in the list.
 *
 * @return The element at the specified position in this list.
 */
public Object getElementAt(int index) {
    URL url = data.get(index);
    if ("jar".equals(url.getProtocol())) { // NOI18N
        URL fileURL = FileUtil.getArchiveFile(url);
        if (FileUtil.getArchiveRoot(fileURL).equals(url)) {
            // really the root
            url = fileURL;
        } else {
            // some subdir, just show it as is
            return url.toExternalForm();
        }
    }
    if ("file".equals(url.getProtocol())) { // NOI18N
        File f = new File(URI.create(url.toExternalForm()));
        return f.getAbsolutePath();
    }
    else {
        return url.toExternalForm();
    }
}
 
Example 5
Source File: JShellEnvironment.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String addRoots(String prev, ClassPath cp) {
    FileObject[] roots = cp.getRoots();
    StringBuilder sb = new StringBuilder(prev);
    
    for (FileObject r : roots) {
        FileObject ar = FileUtil.getArchiveFile(r);
        if (ar == null) {
            ar = r;
        }
        File f = FileUtil.toFile(ar);
        if (f != null) {
            if (sb.length() > 0) {
                sb.append(File.pathSeparatorChar);
            }
            sb.append(f.getPath());
        }
    }
    return sb.toString();
}
 
Example 6
Source File: Hk2PluginProperties.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Return string representation of the specified URL. */
private static String urlToString(URL url) {
    if ("jar".equals(url.getProtocol())) { // NOI18N

        URL fileURL = FileUtil.getArchiveFile(url);
        if (FileUtil.getArchiveRoot(fileURL).equals(url)) {
            // really the root
            url = fileURL;
        } else {
            // some subdir, just show it as is
            return url.toExternalForm();
        }
    }
    if ("file".equals(url.getProtocol())) { // NOI18N

        File f = new File(URI.create(url.toExternalForm()));
        return f.getAbsolutePath();
    } else {
        return url.toExternalForm();
    }
}
 
Example 7
Source File: PlatformNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private List<SourceGroup> getKeys() {
    JavaPlatform platform = ((PlatformNode)this.getNode()).pp.getPlatform();
    if (platform == null) {
        return Collections.emptyList();
    }
    //Todo: Should listen on returned classpath, but now the bootstrap libraries are read only
    FileObject[] roots = platform.getBootstrapLibraries().getRoots();
    List<SourceGroup> result = new ArrayList<SourceGroup>(roots.length);
    for (int i=0; i<roots.length; i++) {
            FileObject file;
            Icon icon;
            if ("jar".equals(roots[i].toURL().getProtocol())) { //NOI18N
                file = FileUtil.getArchiveFile(roots[i]);
                icon = ImageUtilities.loadImageIcon(ARCHIVE_ICON, false);
            } else {
                file = roots[i];
                icon = null;
            }
            if (file.isValid()) {
                result.add(new LibrariesSourceGroup(roots[i], file.getNameExt(), icon, icon));
            }
    }
    return result;
}
 
Example 8
Source File: CustomizerSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Return string representation of the specified URL. */
private static String urlToString(URL url) {
    if ("jar".equals(url.getProtocol())) { // NOI18N
        URL fileURL = FileUtil.getArchiveFile(url);
        if (FileUtil.getArchiveRoot(fileURL).equals(url)) {
            // really the root
            url = fileURL;
        } else {
            // some subdir, just show it as is
            return url.toExternalForm();
        }
    }
    if ("file".equals(url.getProtocol())) { // NOI18N
        File f = new File(URI.create(url.toExternalForm()));
        return f.getAbsolutePath();
    }
    else {
        return url.toExternalForm();
    }
}
 
Example 9
Source File: CreatedModifiedFilesProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * returns archive name or temporarily null cause there is no zip support
 * for file protocol
 */
private static String addArchiveToCopy(CreatedModifiedFiles fileSupport, NewLibraryDescriptor.DataModel data, URL originalURL, String pathPrefix) {
    String retval = null;

    URL archivURL = FileUtil.getArchiveFile(originalURL);
    if (archivURL != null && FileUtil.isArchiveFile(archivURL)) {
        FileObject archiv = URLMapper.findFileObject(archivURL);
        if (archiv == null) {
            // #129617: broken library entry, just skip it.
            return null;
        }
        retval = archiv.getNameExt();
        fileSupport.add(fileSupport.createFile(pathPrefix + retval, archiv));
    } else {
        if ("file".equals(originalURL.getProtocol())) {//NOI18N
            FileObject folderToZip;
            folderToZip = URLMapper.findFileObject(originalURL);
            if (folderToZip != null) {
                retval = data.getLibraryName() + "-" + folderToZip.getName() + ".zip"; // NOI18N
                pathPrefix += retval;
                fileSupport.add(new ZipAndCopyOperation(data.getProject(),
                        folderToZip, pathPrefix));
            }
        }
    }
    return retval;
}
 
Example 10
Source File: ClassPathProviderImplTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean classPathEntriesContainJar(List entries, String name) {
    for (Iterator i = entries.iterator(); i.hasNext();) {
        ClassPath.Entry e = (ClassPath.Entry)i.next();
        URL jar = FileUtil.getArchiveFile(e.getURL());
        if (jar != null && name.equals(new File(URI.create(jar.toExternalForm())).getName())) {
            return true;
        }
    }
    return false;
}
 
Example 11
Source File: SpringUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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()])));
}
 
Example 12
Source File: AndroidPlatformInfo.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    String begin = "<html>";
    String end = "</html>";
    if (!userRecord) {
        begin += "<b>";
        end = "</b>" + end;
    }
    URL tmp = url;
    if ("jar".equals(tmp.getProtocol())) {      //NOI18N
        URL fileURL = FileUtil.getArchiveFile(tmp);
        if (FileUtil.getArchiveRoot(fileURL).equals(tmp)) {
            // really the root
            tmp = fileURL;
        } else {
            // some subdir, just show it as is
            FileObject fo = URLMapper.findFileObject(tmp);
            if (fo == null || !fo.isValid()) {
                begin += "<font color=#DF0101>";
                end = "</font>" + end;
            }
            return begin + tmp.toExternalForm() + end;
        }
    }
    if ("file".equals(tmp.getProtocol())) {
        File f = Utilities.toFile(URI.create(tmp.toExternalForm()));
        if (!f.exists()) {
            begin += "<font color=#DF0101>";
            end = "</font>" + end;
        }
        return begin + f.getAbsolutePath() + end;
    } else {
        return begin + tmp.toExternalForm() + end;
    }
}
 
Example 13
Source File: WLJpa2SwitchSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public boolean isEnabled() {
    if (dm != null) {
        return dm.getJ2eePlatformImpl().isJpa2Available();
    } else {
        List<URL> classpath = WLJ2eePlatformFactory.getWLSClassPath(serverRoot,
                WLPluginProperties.getMiddlewareHome(serverRoot), null);
        for (URL url : classpath) {
            URL file = FileUtil.getArchiveFile(url);
            if (file != null && JPA_JAR_1_PATTERN.matcher(file.getFile()).matches()) {
                return true;
            }
        }
        return false;
    }
}
 
Example 14
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static Set<Severity> disableErrors(FileObject file) {
    if (file.getAttribute(DISABLE_ERRORS) != null) {
        return EnumSet.allOf(Severity.class);
    }
    if (!file.canWrite() && FileUtil.getArchiveFile(file) != null) {
        return EnumSet.allOf(Severity.class);
    }

    return EnumSet.noneOf(Severity.class);
}
 
Example 15
Source File: FileOwnerQuery.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Find the project, if any, which "owns" the given URI.
 * @param uri the URI to the file (generally on disk); must be absolute and not opaque (though {@code jar}-protocol URIs are unwrapped as a convenience)
 * @return a project which contains it, or null if there is no known project containing it
 * @throws IllegalArgumentException if the URI is relative or opaque
 */
public static Project getOwner(URI uri) {
    try {
        URL url = uri.toURL();
        if (FileUtil.isArchiveArtifact(url)) {
            url = FileUtil.getArchiveFile(url);
            if (url != null) {
                uri = url.toURI();
            }
        }
    } catch (MalformedURLException | URISyntaxException e) {
        LOG.log(Level.INFO, null, e);
    }
    if (!uri.isAbsolute() || uri.isOpaque()) {
        throw new IllegalArgumentException("Bad URI: " + uri); // NOI18N
    }
    for (FileOwnerQueryImplementation q : getInstances()) {
        Project p = q.getOwner(uri);
        if (p != null) {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.log(Level.FINE, "getOwner({0}) -> {1} from {2}", new Object[] {uri, p, q});
            }
            return p == UNOWNED ? null : p;
        }
    }
    LOG.log(Level.FINE, "getOwner({0}) -> nil", uri);
    return null;
}
 
Example 16
Source File: PlatformNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<SourceGroup> getKeys () {
    final FileObject[] roots = ((PlatformNode)this.getNode()).pp.getBootstrapLibraries();
    if (roots.length == 0) {
        return Collections.<SourceGroup>emptyList();
    }
    final List<SourceGroup> result = new ArrayList<>(roots.length);
    for (FileObject root : roots) {
            FileObject file;
            Icon icon;
            Icon openedIcon;
            switch (root.toURL().getProtocol()) {
                case "jar":
                    file = FileUtil.getArchiveFile (root);
                    icon = openedIcon = ImageUtilities.loadImageIcon(ARCHIVE_ICON, false);
                    break;
                case "nbjrt":
                    file = root;
                    icon = openedIcon = ImageUtilities.loadImageIcon(MODULE_ICON, false);
                    break;
                default:
                    file = root;
                    icon = openedIcon = null;
            }
            if (file.isValid()) {
                result.add (new LibrariesSourceGroup(root,file.getNameExt(),icon, openedIcon));
            }
    }
    return result;
}
 
Example 17
Source File: SourceForBinaryQueryImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the given URL is file based, it is already
 * resolved either into file URL or jar URL with file path.
 * @param URL url
 * @return true if  the URL is normal
 */
private static boolean isNormalizedURL (URL url) {
    if ("jar".equals(url.getProtocol())) { //NOI18N
        url = FileUtil.getArchiveFile(url);
    }
    return "file".equals(url.getProtocol());    //NOI18N
}
 
Example 18
Source File: MultiModuleJavadocForBinaryQueryImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public JavadocForBinaryQuery.Result findJavadoc(URL binaryRoot) {
    boolean archive = false;
    if (FileUtil.isArchiveArtifact(binaryRoot)) {
        binaryRoot = FileUtil.getArchiveFile(binaryRoot);
        archive = true;
    }
    R res = null;
    try {
        URI artefact = binaryRoot.toURI();
        res = cache.get(artefact);
        if (res == null) {
            res = createResult(artefact, archive, modules, binaryProperties);
            R prev = cache.get(artefact);
            if (prev != null) {
                res = prev;
            } else if (res != null) {
                prev = cache.putIfAbsent(artefact, res);
                if (prev != null) {
                    res = prev;
                }
            }
        }
    } catch (URISyntaxException e) {
        LOG.log(
                Level.WARNING,
                "Invalid URI: {0}", //NOI18N
                binaryRoot.toExternalForm());
    }
    return res;
}
 
Example 19
Source File: JavadocForBinaryQueryImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the given URL is file based, it is already
 * resolved either into file URL or jar URL with file path.
 * @param URL url
 * @return true if  the URL is normal
 */
private static boolean isNormalizedURL (URL url) {
    if ("jar".equals(url.getProtocol())) { //NOI18N
        url = FileUtil.getArchiveFile(url);
    }
    return "file".equals(url.getProtocol());    //NOI18N
}
 
Example 20
Source File: DetectPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NonNull
private static String urlsToString(@NonNull final List<URL> path) {
    final StringBuilder result = new StringBuilder();
    for (final URL jdocRoot : path) {
        try {
            final String extUrl = jdocRoot.toExternalForm(); 
            URL url = FileUtil.getArchiveFile(jdocRoot);
            String relative;
            String userName;
            if (url == null) {
                url = jdocRoot;
                relative = "";  //NOI18N
            } else {                
                int index = extUrl.lastIndexOf(INNER_SEPARATOR);
                relative = index < 0 ? "" : extUrl.substring(index+INNER_SEPARATOR.length());    //NOI18N
            }
            final String protocol = url.getProtocol();
            if (Util.PROTO_FILE.equals(protocol)) {
                final String absolutePath = Utilities.toFile(url.toURI()).getAbsolutePath();
                final StringBuilder sb = new StringBuilder(absolutePath.length() + INNER_SEPARATOR.length() + relative.length());
                sb.append(absolutePath);
                if (!relative.isEmpty()) {
                    sb.append(INNER_SEPARATOR);
                    sb.append(relative);
                }
                userName = sb.toString();
            } else if (Util.isRemoteProtocol(protocol)) {
                userName = extUrl;
            } else {
                //Other protocols are unsupported
                continue;
            }
            if (result.length() > 0) {
                result.append(PATH_SEPARATOR);
            }
            result.append(userName);
        } catch (URISyntaxException e) {
            Exceptions.printStackTrace(e);
        }
    }
    return result.toString();
}