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

The following examples show how to use org.openide.filesystems.FileUtil#isArchiveArtifact() . 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: ModuleClassPaths.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Collection<? extends URL> filterArtefact(
        final boolean archive,
        @NonNull final URL... urls) {
    final Collection<URL> res = new ArrayList<>(urls.length);
    for (URL url : urls) {
        if ((archive && FileUtil.isArchiveArtifact(url)) ||
            (!archive && !FileUtil.isArchiveArtifact(url))) {
            res.add(url);
            break;
        }
    }
    if (res.isEmpty()) {
        Collections.addAll(res, urls);
    }
    return res;
}
 
Example 2
Source File: ClassPathProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean apply(@NonNull final URL url) {
    final URL aurl = FileUtil.isArchiveArtifact(url) ?
            FileUtil.getArchiveFile(url) :
            url;
    if (Optional.ofNullable(includeProp)
            .map((p) -> getDir(p))
            .map((fo) -> Objects.equals(fo.toURL(),aurl))
            .orElse(Boolean.FALSE)) {
        return Boolean.TRUE;
    }            
    if(Optional.ofNullable(excludeProp)
            .map((p) -> getDir(p))
            .map((fo) -> Objects.equals(fo.toURL(),aurl))
            .orElse(Boolean.FALSE)) {
        return Boolean.FALSE;
    }
    return null;
}
 
Example 3
Source File: MultiModuleSourceForBinaryQueryImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Result findSourceRoots2(@NonNull 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);
            if (res == null) {
                res = createResult(artefact, archive, testModules, testBinaryProperties);
            }
            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 4
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 5
Source File: ProjectRunnerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static URL[] removeArchives(@NonNull final URL... orig) {
    final List<URL> res = new ArrayList<>(orig.length);
    for (URL url : orig) {
        if (!FileUtil.isArchiveArtifact(url)) {
            res.add(url);
        }
    }
    return res.isEmpty() ?
            orig :
            res.toArray(new URL[res.size()]);
}
 
Example 6
Source File: ShellProjectUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static FileObject findProjectRoots(Project project, List<URL> urls) {
    if (project == null) {
        return null;
    }
    FileObject ret = null;
    Set<URL> knownURLs = new HashSet<>();
    for (SourceGroup sg : org.netbeans.api.project.ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
        if (org.netbeans.modules.jshell.project.ShellProjectUtils.isNormalRoot(sg)) {
            if (urls != null) {
                URL u = URLMapper.findURL(sg.getRootFolder(), URLMapper.INTERNAL);
                BinaryForSourceQuery.Result r = BinaryForSourceQuery.findBinaryRoots(u);
                for (URL ru : r.getRoots()) {
                    // ignore JARs, prefer output folder:
                    if (FileUtil.isArchiveArtifact(ru)) {
                        continue;
                    }
                    if (knownURLs.add(ru)) {
                        urls.add(ru);
                    }
                }
            }
            if (ret == null) {
                ret = sg.getRootFolder();
            }
        }
    }
    return ret;
}
 
Example 7
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;
}