Example usage for org.eclipse.jdt.core IClasspathEntry getPath

List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry getPath.

Prototype

IPath getPath();

Source Link

Document

Returns the path of this classpath entry.

Usage

From source file:com.wt.studio.plugin.platform.actions.MavenClasspathUpdateJob.java

License:Open Source License

private IPath getJREContainerPath(IContainer basedir) throws CoreException {
    IProject project = basedir.getProject();
    if (project != null && project.hasNature(JavaCore.NATURE_ID)) {
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (JavaRuntime.JRE_CONTAINER.equals(entry.getPath().segment(0))) {
                return entry.getPath();
            }//  w w  w .j a v  a2 s .  c om
        }
    }
    return null;
}

From source file:de.devboost.emfcustomize.builder.EMFCustomizeBuilder.java

License:Open Source License

private void adjustFactory(IFile iFile, ResourceSet resourceSet) {
    //adjust factory for generation gap pattern
    IJavaProject javaProject = JavaCore.create(iFile.getProject());
    try {/*  www . j  a  v a2s.  c o  m*/
        for (IClasspathEntry cpEntry : javaProject.getRawClasspath()) {
            if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                //to register newly generated code;
                updateClaspath(new File(
                        iFile.getWorkspace().getRoot().getLocation().toString() + cpEntry.getPath().toString()),
                        "", resourceSet);
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

/**
 * @param javaElement//from   www . j  a va2s. c  o  m
 * @return absolute path of generated bytecode package for given element
 * @throws JavaModelException
 */
private static String getPackageOutputPath(IJavaElement javaElement) throws JavaModelException {
    String dir = ""; //$NON-NLS-1$
    if (javaElement == null) {
        return dir;
    }

    IJavaProject project = javaElement.getJavaProject();

    if (project == null) {
        return dir;
    }
    // default bytecode location
    IPath path = project.getOutputLocation();

    IResource resource = javaElement.getUnderlyingResource();
    if (resource == null) {
        return dir;
    }
    // resolve multiple output locations here
    if (project.exists() && project.getProject().isOpen()) {
        IClasspathEntry entries[] = project.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry classpathEntry = entries[i];
            if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath outputPath = classpathEntry.getOutputLocation();
                if (outputPath != null && classpathEntry.getPath().isPrefixOf(resource.getFullPath())) {
                    path = outputPath;
                    break;
                }
            }
        }
    }

    if (path == null) {
        // check the default location if not already included
        IPath def = project.getOutputLocation();
        if (def != null && def.isPrefixOf(resource.getFullPath())) {
            path = def;
        }
    }

    if (path == null) {
        return dir;
    }

    IWorkspace workspace = ResourcesPlugin.getWorkspace();

    if (!project.getPath().equals(path)) {
        IFolder outputFolder = workspace.getRoot().getFolder(path);
        if (outputFolder != null) {
            // linked resources will be resolved here!
            IPath rawPath = outputFolder.getRawLocation();
            if (rawPath != null) {
                path = rawPath;
            }
        }
    } else {
        path = project.getProject().getLocation();
    }

    // here we should resolve path variables,
    // probably existing at first place of path
    IPathVariableManager pathManager = workspace.getPathVariableManager();
    path = pathManager.resolvePath(path);

    if (path == null) {
        return dir;
    }

    if (isPackageRoot(project, resource)) {
        dir = path.toOSString();
    } else {
        String packPath = EclipseUtils.getJavaPackageName(javaElement).replace(Signature.C_DOT,
                PACKAGE_SEPARATOR);
        dir = path.append(packPath).toOSString();
    }
    return dir;
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

private static void getClassURLs(IJavaProject javaProject, List<URL> urls) {
    IProject project = javaProject.getProject();
    IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();

    IClasspathEntry[] paths = null;//from w w w  .  j  a  va  2s  . c om
    IPath defaultOutputLocation = null;
    try {
        paths = javaProject.getResolvedClasspath(true);
        defaultOutputLocation = javaProject.getOutputLocation();
    } catch (JavaModelException e) {
        // don't show message to user neither log it
        // BytecodeOutlinePlugin.log(e, IStatus.ERROR);
    }
    if (paths != null) {
        IPath projectPath = javaProject.getProject().getLocation();
        for (int i = 0; i < paths.length; ++i) {
            IClasspathEntry cpEntry = paths[i];
            IPath p = null;
            if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                // filter out source container - there are unused for class
                // search - add bytecode output location instead
                p = cpEntry.getOutputLocation();
                if (p == null) {
                    // default output used:
                    p = defaultOutputLocation;
                }
            } else if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                String projName = cpEntry.getPath().toPortableString().substring(1);
                IProject proj = workspaceRoot.getProject(projName);
                IJavaProject projj = JavaCore.create(proj);
                getClassURLs(projj, urls);
                continue;
            } else {
                p = cpEntry.getPath();
            }

            if (p == null) {
                continue;
            }
            if (!p.toFile().exists()) {
                // removeFirstSegments: remove project from relative path
                p = projectPath.append(p.removeFirstSegments(1));
                if (!p.toFile().exists()) {
                    continue;
                }
            }
            try {
                urls.add(p.toFile().toURI().toURL());
            } catch (MalformedURLException e) {
                // don't show message to user
                BytecodeOutlinePlugin.log(e, IStatus.ERROR);
            }
        }
    }
}

From source file:de.loskutov.eclipse.jdepend.views.TreeObject.java

License:Open Source License

protected String getPackageOutputPath(IJavaElement jElement) throws JavaModelException {
    String dir = ""; //$NON-NLS-1$
    if (jElement == null) {
        return dir;
    }/*from  w w  w. j av a2s  .  c  om*/

    IJavaProject project = jElement.getJavaProject();

    if (project == null) {
        return dir;
    }
    IPath path = project.getOutputLocation();

    IResource resource = jElement.getUnderlyingResource();
    if (resource == null) {
        return dir;
    }
    // resolve multiple output locations here
    if (project.exists() && project.getProject().isOpen()) {
        IClasspathEntry entries[] = project.getRawClasspath();

        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry classpathEntry = entries[i];
            if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath outputPath = classpathEntry.getOutputLocation();
                if (outputPath != null) {
                    // if this source folder contains specified java resource
                    // then take bytecode location from himself
                    if (classpathEntry.getPath().isPrefixOf(resource.getFullPath())) {
                        path = outputPath;
                        break;
                    }
                }
            }
        }
    }

    if (path == null) {
        // check the default location if not already included
        IPath def = project.getOutputLocation();
        if (def != null && def.isPrefixOf(resource.getFullPath())) {
            path = def;
        }
    }

    if (path == null) {
        return dir;
    }

    IWorkspace workspace = ResourcesPlugin.getWorkspace();

    if (!project.getPath().equals(path)) {
        IFolder outputFolder = workspace.getRoot().getFolder(path);
        if (outputFolder != null) {
            // linked resources will be resolved here!
            IPath rawPath = outputFolder.getRawLocation();
            if (rawPath != null) {
                path = rawPath;
            }
        }
    } else {
        path = project.getProject().getLocation();
    }

    if (path == null) {
        return dir;
    }

    // here we should resolve path variables,
    // probably existing at first place of path
    IPathVariableManager pathManager = workspace.getPathVariableManager();
    path = pathManager.resolvePath(path);

    if (path == null) {
        return dir;
    }

    boolean packageRoot = false;
    try {
        packageRoot = isPackageRoot(project, resource);
    } catch (JavaModelException e) {
        // seems to be a bug in 3.3
    }
    if (packageRoot) {
        dir = path.toOSString();
    } else {
        String packPath = getPackageName().replace('.', '/');
        dir = path.append(packPath).toOSString();
    }
    return dir;
}

From source file:de.lynorics.eclipse.jangaroo.m2e.JangarooProjectConfigurator.java

License:Open Source License

private void addSourcePath(IJavaProject javaProject, List<IClasspathEntry> entries, String path)
        throws JavaModelException {
    IPath srcPath = javaProject.getPath().append(path);
    IClasspathEntry srcEntry = JavaCore.newSourceEntry(srcPath, null);
    boolean found = false;
    for (IClasspathEntry entry : entries) {
        if (entry.getPath().makeRelative().toString().equals(srcEntry.getPath().makeRelative().toString())) {
            found = true;//from  w w w . jav  a 2  s.co  m
            break;
        }
    }
    if (!found) {
        entries.add(JavaCore.newSourceEntry(srcEntry.getPath()));
    }
}

From source file:de.lynorics.eclipse.jangaroo.ui.wizard.NewAS3FileWizardPage.java

License:Open Source License

public static List<IPath> getProjectSourceDirectories(IProject project) {
    List<IPath> paths = new ArrayList<IPath>();
    try {/*from  w w  w  . j  a v  a  2 s .  c  o m*/
        if (project.isOpen() && project.getNature(JangarooProjectHelper.NATURE_ID) != null) {
            IJavaProject javaProject = JavaCore.create(project);
            IClasspathEntry[] classpathEntries = null;
            classpathEntries = javaProject.getResolvedClasspath(true);
            for (int i = 0; i < classpathEntries.length; i++) {
                IClasspathEntry entry = classpathEntries[i];
                if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                    paths.add(entry.getPath());
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return paths;
}

From source file:de.ovgu.featureide.aspectj.AspectJComposer.java

License:Open Source License

/**
 * Set the unselected aspect files to be excluded
 * @param e The ClasspathEntry to set//from  w  ww  . j  a  v a 2s . c om
 * @return The set entry
 */
private IClasspathEntry setSourceEntry(IClasspathEntry e) {
    IPath[] excludedAspects = new IPath[unSelectedFeatures.size()];
    int i = 0;
    for (String f : unSelectedFeatures) {
        excludedAspects[i++] = new Path(f.replaceAll("_", "/") + ".aj");
    }
    return new ClasspathEntry(e.getContentKind(), e.getEntryKind(), e.getPath(), e.getInclusionPatterns(),
            excludedAspects, e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(),
            e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes());
}

From source file:de.ovgu.featureide.core.mpl.job.MPLRenameExternalJob.java

License:Open Source License

private static IPath setJavaBuildPath(JavaProject javaProject, IPath path, int index) {
    try {//w  ww. j  a  v a  2 s .  co  m
        final IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath();

        if (index >= 0) {
            final IClasspathEntry e = classpathEntrys[index];
            if (!e.getPath().equals(path)) {
                final IPath formerSourcePath = e.getPath();
                classpathEntrys[index] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), path,
                        e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(),
                        e.combineAccessRules(), e.getExtraAttributes());
                javaProject.setRawClasspath(classpathEntrys, null);
                return formerSourcePath;
            }
        } else {
            final IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length + 1];
            System.arraycopy(classpathEntrys, 0, newEntrys, 0, classpathEntrys.length);
            newEntrys[newEntrys.length - 1] = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE,
                    IClasspathEntry.CPE_SOURCE, path, new IPath[0], new IPath[0], null, null, null, false, null,
                    false, new IClasspathAttribute[0]);
            javaProject.setRawClasspath(newEntrys, null);
        }
    } catch (JavaModelException e) {
        MPLPlugin.getDefault().logError(e);
    }

    return null;
}

From source file:de.ovgu.featureide.featurehouse.FeatureHouseComposer.java

License:Open Source License

/**
 * Sets the Java build path to the folder at the build folder, named like the current configuration.
 * @param buildPath The name of the current configuration
 *///www  .java 2  s. c  o  m
private void setJavaBuildPath(String buildPath) {
    try {
        JavaProject javaProject = new JavaProject(featureProject.getProject(), null);
        IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath();

        int i = 0;
        for (IClasspathEntry e : classpathEntrys) {
            if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath path = featureProject.getBuildFolder().getFolder(buildPath).getFullPath();

                /** return if nothing has to be changed **/
                if (e.getPath().equals(path)) {
                    return;
                }

                /** change the actual source entry to the new build path **/
                ClasspathEntry changedEntry = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), path,
                        e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(),
                        e.combineAccessRules(), e.getExtraAttributes());
                classpathEntrys[i] = changedEntry;
                javaProject.setRawClasspath(classpathEntrys, null);
                return;
            }
            i++;
        }

        /** case: there is no source entry at the class path
         *       add the source entry to the classpath **/
        IFolder folder = featureProject.getBuildFolder().getFolder(buildPath);
        ClasspathEntry sourceEntry = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE,
                IClasspathEntry.CPE_SOURCE, folder.getFullPath(), new IPath[0], new IPath[0], null, null, null,
                false, null, false, new IClasspathAttribute[0]);
        IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length + 1];
        System.arraycopy(classpathEntrys, 0, newEntrys, 0, classpathEntrys.length);
        newEntrys[newEntrys.length - 1] = sourceEntry;
        javaProject.setRawClasspath(newEntrys, null);
    } catch (JavaModelException e) {
        FeatureHouseCorePlugin.getDefault().logError(e);
    }
}