Example usage for org.eclipse.jdt.core IPackageFragmentRoot getResource

List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getResource

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragmentRoot getResource.

Prototype

IResource getResource();

Source Link

Document

Returns the innermost resource enclosing this element.

Usage

From source file:org.jetbrains.kotlin.core.utils.ProjectUtils.java

License:Apache License

@NotNull
private static List<File> getFileByEntry(@NotNull IClasspathEntry entry, @NotNull IJavaProject javaProject) {
    List<File> files = Lists.newArrayList();

    IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(entry);
    if (packageFragmentRoots.length > 0) {
        for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) {
            IResource resource = packageFragmentRoot.getResource();
            if (resource != null) {
                files.add(resource.getLocation().toFile());
            } else { // This can be if resource is external
                files.add(packageFragmentRoot.getPath().toFile());
            }//ww w .j  a va 2 s. c o  m
        }
    } else {
        File file = entry.getPath().toFile();
        if (file.exists()) {
            files.add(file);
        }
    }

    return files;
}

From source file:org.key_project.util.jdt.JDTUtil.java

License:Open Source License

/**
 * Returns the {@link IResource}s of the given {@link IClasspathEntry}.
 * @param javaProject The actual {@link IJavaProject} that provides the {@link IClasspathEntry}.
 * @param entry The given {@link IClasspathEntry}.
 * @param alreadyHandledProjects The already handled {@link IProject} that don't need to be analysed again.
 * @return The found {@link IResource}s.
 * @throws JavaModelException /*from   w  ww.  j ava  2 s . co  m*/
 */
private static List<IResource> getResourceFor(IJavaProject javaProject, IClasspathEntry entry, int expectedKind,
        Set<IProject> alreadyHandledProjects) throws JavaModelException {
    if (entry != null) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                || entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            List<IResource> result = new LinkedList<IResource>();
            IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry);
            for (IPackageFragmentRoot root : roots) {
                if (root.getKind() == expectedKind) {
                    if (root.getResource() != null) {
                        if (root.getResource().getLocationURI() != null) {
                            result.add(root.getResource());
                        }
                    } else if (root.getPath() != null) {
                        IResource resource = ResourcesPlugin.getWorkspace().getRoot()
                                .findMember(root.getPath());
                        if (resource != null && resource.exists()) {
                            result.add(resource);
                        }
                    }
                }
            }
            return result; // Ignore containers
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            Assert.isNotNull(entry.getPath());
            IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
            Assert.isTrue(project instanceof IProject);
            if (!alreadyHandledProjects.contains(project)) {
                return getSourceResources((IProject) project, alreadyHandledProjects);
            } else {
                return null; // Project was already analyzed, no need to do it again.
            }
        } else {
            Assert.isTrue(false, "Unknown content kind \"" + entry.getContentKind()
                    + "\" of class path entry \"" + entry + "\".");
            return null;
        }
    } else {
        return null;
    }
}

From source file:org.key_project.util.jdt.JDTUtil.java

License:Open Source License

/**
 * Returns the locations of the given {@link IClasspathEntry}.
 * @param javaProject The actual {@link IJavaProject} that provides the {@link IClasspathEntry}.
 * @param entry The given {@link IClasspathEntry}.
 * @param alreadyHandledProjects The already handled {@link IProject} that don't need to be analysed again.
 * @return The found locations./*from  w  w  w .  j a v a 2  s .co  m*/
 * @throws JavaModelException 
 */
private static List<File> getLocationFor(IJavaProject javaProject, IClasspathEntry entry, int expectedKind,
        Set<IProject> alreadyHandledProjects) throws JavaModelException {
    if (entry != null) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                || entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            List<File> result = new LinkedList<File>();
            IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry);
            for (IPackageFragmentRoot root : roots) {
                if (root.getKind() == expectedKind) {
                    if (root.getResource() != null) {
                        if (root.getResource().getLocationURI() != null) {
                            result.add(ResourceUtil.getLocation(root.getResource()));
                        }
                    } else if (root.getPath() != null) {
                        File location = new File(root.getPath().toString());
                        if (location.exists()) {
                            result.add(location);
                        }
                    }
                }
            }
            return result; // Ignore containers
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            Assert.isNotNull(entry.getPath());
            IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
            Assert.isTrue(project instanceof IProject);
            if (!alreadyHandledProjects.contains(project)) {
                return getSourceLocations((IProject) project, alreadyHandledProjects);
            } else {
                return null; // Project was already analyzed, no need to do it again.
            }
        } else {
            Assert.isTrue(false, "Unknown content kind \"" + entry.getContentKind()
                    + "\" of class path entry \"" + entry + "\".");
            return null;
        }
    } else {
        return null;
    }
}

From source file:org.limy.eclipse.qalab.ant.UmlgraphCreator.java

License:Open Source License

/**
 * @param targetEl//from   w  ww. j  a  va2s . c o  m
 * @param env
 * @param targetProject
 * @return Element???? true
 * @throws CoreException 
 */
private boolean createJavadocElement(XmlElement targetEl, LimyQalabEnvironment env, IProject targetProject)
        throws CoreException {

    XmlElement javadocEl = createElement(targetEl, "javadoc");

    IJavaProject javaProject = JavaCore.create(targetProject);
    IPreferenceStore store = env.getStore();

    IPackageFragmentRoot[] roots = javaProject.getAllPackageFragmentRoots();

    // v?WFNg\?[XfBNg
    boolean isEmpty = true;
    for (IPackageFragmentRoot root : roots) {
        if (root.getKind() == IPackageFragmentRoot.K_SOURCE && root.getJavaProject().equals(javaProject)) {

            IResource rootDir = root.getResource();
            if (((IContainer) rootDir).members().length > 0) {
                isEmpty = false;
            }
            XmlElement fileEl = createElement(javadocEl, "fileset", "dir", rootDir.getLocation().toString());
            fileEl.setAttribute("includes", "**/*.java");
            fileEl.setAttribute("excludes", "**/*Test.java");
        }
    }

    // \?[Xt@C??javadocvf?
    if (isEmpty) {
        targetEl.removeChild(javadocEl);
        return false;
    }

    javadocEl.setAttribute("destDir", "${dest.dir}/javadoc/" + targetProject.getName());

    javadocEl.setAttribute("Encoding", "${src.encoding}");
    javadocEl.setAttribute("classpathref", "all.classpath");
    javadocEl.setAttribute("private", "false");
    javadocEl.setAttribute("packagenames", "*");
    javadocEl.setAttribute("useexternalfile", "yes");

    XmlElement docletEl = createElement(javadocEl, "doclet");
    docletEl.setAttribute("name", "gr.spinellis.umlgraph.doclet.UmlGraph");
    docletEl.setAttribute("path", LimyQalabPluginUtils.getResourcePath("lib/UmlGraph.jar"));

    addParam(docletEl, "-collpackages", "java.util.*");
    if (store.getBoolean(LimyQalabConstants.UMLGRAPH_INFERREL)) {
        addParam(docletEl, "-inferrel", null);
    }
    if (store.getBoolean(LimyQalabConstants.UMLGRAPH_HORIZONTAL)) {
        addParam(docletEl, "-horizontal", null);
    }

    String resources = env.getStore().getString(LimyQalabConstants.EXCLUDE_JDEPENDS);
    String[] excludes = resources.split("\n");
    for (String exclude : excludes) {
        // ?K\\L java.* => ^java\..*
        // org.apache.* => ^org\.apache\..*
        if (exclude.length() > 0) {
            addParam(docletEl, "-hide", "^" + exclude.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*"));
        }
    }
    return true;
}

From source file:org.limy.eclipse.qalab.common.LimyQalabJavaUtils.java

License:Open Source License

/**
 * PackageFragmentRoot?pX?B/*from w  w w.ja v a2 s . co m*/
 * @param fragment PackageFragmentRoot
 * @return
 * @throws CoreException 
 */
public static String getExternalLocation(IPackageFragmentRoot fragment) throws CoreException {

    String location = null;
    if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) {
        // v?WFNgQ?v?WFNg\?[XfBNg
        IPath outputLocation = fragment.getRawClasspathEntry().getOutputLocation();
        if (outputLocation != null) {
            // \?[XpXL?o?w??
            location = LimyQalabUtils.createFullPath(fragment.getJavaProject(), outputLocation);
        } else {
            // \?[XpXL?o?w???Av?WFNgftHg?o?gp
            location = LimyQalabUtils.createFullPath(fragment.getJavaProject(),
                    fragment.getJavaProject().getOutputLocation());
        }
    } else {
        // v?WFNgclasspathQ?v?WFNgExportCu
        IResource resource = fragment.getResource();
        if (resource != null) {
            location = resource.getLocation().toString();
        } else {
            // Variablewjart@Cresource = null 
            IPath path = fragment.getRawClasspathEntry().getPath();
            if (!path.toString().startsWith("org.eclipse.jdt.launching.JRE_CONTAINER")) {
                // JREOJARt@C?iVariablew?jNXpX
                location = fragment.getPath().toString();
            }
        }
    }
    return location;
}

From source file:org.openlegacy.ide.eclipse.util.JavaUtils.java

License:Open Source License

public static String convertSourceFolderToString(IPackageFragmentRoot sourceFolder) {

    String projectName = sourceFolder.getJavaProject().getProject().getName();

    return projectName + File.separator + sourceFolder.getResource().getProjectRelativePath();
}

From source file:org.seasar.resource.synchronizer.servlet.SrcLocationServlet.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//from   ww w. j  a va  2 s . c o m
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    response.setStatus(HttpServletResponse.SC_OK);
    PrintWriter w = response.getWriter();
    try {
        for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
            String s = e.nextElement().toString();
            IProject project = root.getProject(s);
            if (project != null && project.exists()) {
                IJavaProject javap = JavaCore.create(project);
                for (IPackageFragmentRoot pfr : javap.getPackageFragmentRoots()) {
                    if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE) {
                        String p = pfr.getResource().getLocation().toString();
                        w.println(p);
                    }
                }
            }
        }
    } catch (CoreException e) {
        Activator.log(e);
    } finally {
        if (w != null) {
            w.close();
        }
    }
}

From source file:org.seasar.s2daoplugin.cache.deployment.deployer.ComponentAutoRegisterDeployer.java

License:Apache License

private boolean isJar(IPackageFragmentRoot root) {
    return root != null && root.isArchive() && "jar".equalsIgnoreCase(root.getResource().getFileExtension());
}

From source file:org.seasar.s2daoplugin.cache.deployment.deployer.JarComponentAutoRegisterDeployer.java

License:Apache License

protected void doDeploy(IHandler handler) throws CoreException {
    if (referenceClass == null) {
        return;//from   w w w  .j  a v  a  2 s.  c o  m
    }
    IPackageFragmentRoot jar = JavaProjectUtil.findPackageFragmentRoot(referenceClass.getType());
    if (!jar.isArchive()) {
        return;
    }
    IContainer base = jar.getResource().getParent();
    IResource[] archives = archives = base.members();
    IJavaProject project = jar.getJavaProject();
    for (int i = 0; i < archives.length; i++) {
        if (!"jar".equalsIgnoreCase(archives[i].getFileExtension())) {
            continue;
        }
        jar = project.getPackageFragmentRoot(archives[i].getFullPath().toString());
        if (!jar.exists()) {
            continue;
        }
        if (isAppliedJar(jar)) {
            handler.processPackageFragmentRoot(jar);
        }
    }
}

From source file:org.springframework.ide.eclipse.beans.ui.properties.NonJavaResourceContentProvider.java

License:Open Source License

private Object[] getNonJavaResources(IPackageFragment fragment) throws JavaModelException {
    Object[] nonJavaResources = fragment.getNonJavaResources();
    IPackageFragmentRoot root = (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
    if (root != null && root.getKind() == IPackageFragmentRoot.K_BINARY) {
        for (int i = 0; i < nonJavaResources.length; i++) {
            Object resource = nonJavaResources[i];
            if (resource instanceof IFile) {
                nonJavaResources[i] = resource;
            } else if (resource instanceof IStorage && root.getResource() instanceof IFile) {
                IStorage storage = (IStorage) resource;
                nonJavaResources[i] = new ZipEntryStorage((IFile) root.getResource(),
                        storage.getFullPath().toString());
            }// w w  w  .j  av  a 2 s.  c  om
        }
    }
    return nonJavaResources;
}