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:in.cypal.studio.gwt.core.facet.InstallDelegate.java

License:Apache License

public static void addServletLibToWebInf(IProject project, IProgressMonitor monitor) {

    monitor = Util.getNonNullMonitor(monitor);

    try {/*from   w ww.  j a  v  a 2  s. c o  m*/
        monitor.beginTask("", 1);

        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] oldClasspath = javaProject.getRawClasspath();
        IClasspathEntry[] newClasspath = new IClasspathEntry[oldClasspath.length + 1];
        System.arraycopy(oldClasspath, 0, newClasspath, 0, oldClasspath.length);
        IClasspathEntry gwtServletJarEntry = JavaCore.newVariableEntry(Util.getGwtServletLibPath(), null, null);
        IClasspathAttribute attr = JavaCore.newClasspathAttribute("org.eclipse.jst.component.dependency",
                "/WEB-INF/lib");
        gwtServletJarEntry = JavaCore.newVariableEntry(gwtServletJarEntry.getPath(), null, null,
                new IAccessRule[0], new IClasspathAttribute[] { attr }, false);
        newClasspath[oldClasspath.length] = gwtServletJarEntry;
        javaProject.setRawClasspath(newClasspath, monitor);

    } catch (JavaModelException e) {
        // the jar is already in the classpath.
        Activator.logException(e);
    } finally {
        monitor.done();
    }
}

From source file:in.cypal.studio.gwt.core.facet.UpgradeDelegate.java

License:Apache License

private void removeGWTEntries(IProject project, IProgressMonitor monitor) throws JavaModelException {

    monitor = Util.getNonNullMonitor(monitor);
    monitor.beginTask("Removing old entries...", 2);
    try {// ww  w. jav a  2s .  c  om

        IJavaProject javaProject = JavaCore.create(project);
        List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();

        IClasspathEntry[] oldClasspath = javaProject.getRawClasspath();
        for (IClasspathEntry classpathEntry : oldClasspath) {
            if (!classpathEntry.getPath().lastSegment().startsWith("gwt"))
                classpathEntries.add(classpathEntry);
        }
        javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
                new SubProgressMonitor(monitor, 1));

        IPath webContent = ComponentCore.createComponent(project).getRootFolder().getProjectRelativePath();
        IFile theLink = project.getFile(webContent.append("WEB-INF").append("lib").append("gwt-servlet.jar"));
        theLink.delete(true, new SubProgressMonitor(monitor, 1));

    } catch (CoreException e) {
        Activator.logException(e);
    } finally {
        monitor.done();
    }
}

From source file:in.cypal.studio.gwt.ui.wizards.GwtRuntimeContainerPage.java

License:Apache License

public void setSelection(IClasspathEntry containerEntry) {
    if (containerEntry != null)
        gwtRuntimeVersion = containerEntry.getPath().lastSegment();
    else//from ww  w .  jav a 2s. c o m
        gwtRuntimeVersion = Constants.GWT_RUNTIME_WORKSPACE_DEFAULT;
}

From source file:in.software.analytics.parichayana.core.internal.builder.ParichayanaBuilder.java

License:Open Source License

private IProject[] getRequiredProjects(boolean includeBinaryPrerequisites) {
    JavaProject javaProject = (JavaProject) JavaCore.create(this.project);
    IWorkspaceRoot workspaceRoot = this.project.getWorkspace().getRoot();
    if (javaProject == null || workspaceRoot == null) {
        return ZERO_PROJECT;
    }//from  ww w. j  ava2s  .  co m

    List<IProject> projects = new ArrayList<IProject>();
    ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
    try {
        IClasspathEntry[] entries = javaProject.getExpandedClasspath();
        for (int i = 0, l = entries.length; i < l; i++) {
            IClasspathEntry entry = entries[i];
            IPath path = entry.getPath();
            IProject p = null;
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_PROJECT:
                p = workspaceRoot.getProject(path.lastSegment()); // missing projects are considered too
                if (((ClasspathEntry) entry).isOptional() && !JavaProject.hasJavaNature(p)) // except if entry is optional
                    p = null;
                break;
            case IClasspathEntry.CPE_LIBRARY:
                if (includeBinaryPrerequisites && path.segmentCount() > 0) {
                    // some binary resources on the class path can come from projects that are not included in the project references
                    IResource resource = workspaceRoot.findMember(path.segment(0));
                    if (resource instanceof IProject) {
                        p = (IProject) resource;
                    } else {
                        resource = externalFoldersManager.getFolder(path);
                        if (resource != null)
                            p = resource.getProject();
                    }
                }
            }
            if (p != null && !projects.contains(p))
                projects.add(p);
        }
    } catch (JavaModelException e) {
        return ZERO_PROJECT;
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
}

From source file:io.sarl.eclipse.tests.buildpath.SARLClasspathContainerTest.java

License:Apache License

private static boolean isReferenceLibrary(String reference, IClasspathEntry entry) {
    IPath path = entry.getPath();
    String str = path.lastSegment();
    if ("classes".equals(str)) {
        str = path.segment(path.segmentCount() - 3);
        return str.equals(reference);
    }// ww w  .  j  a v  a2 s.c om
    return str.startsWith(reference + "_");
}

From source file:io.sarl.eclipse.wizards.newfile.NewSarlFileWizardPage.java

License:Apache License

private static IPath determinePackageName(IPath path) {
    if (path != null) {
        final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
        try {/*from ww w .j  a  va2  s .  c o  m*/
            if (project != null && project.hasNature(JavaCore.NATURE_ID)) {
                final IJavaProject javaProject = JavaCore.create(project);
                for (final IClasspathEntry entry : javaProject.getRawClasspath()) {
                    if (entry.getPath().isPrefixOf(path)) {
                        return path.removeFirstSegments(entry.getPath().segmentCount());
                    }
                }
            }
        } catch (Exception e) {
            // Ignore the exceptions since they are not useful (hopefully)
        }
    }
    return null;
}

From source file:io.sarl.eclipse.wizards.newproject.BuildSettingWizardPage.java

License:Apache License

private void buildNewBuildPath(IProject project, OutParameter<IClasspathEntry[]> classpath,
        OutParameter<IPath> outputLocation, IProgressMonitor monitor) throws CoreException {
    final List<IClasspathEntry> cpEntries = new ArrayList<>();
    final IWorkspaceRoot root = project.getWorkspace().getRoot();

    final Collection<IClasspathEntry> originalEntries = SARLProjectConfigurator
            .getDefaultSourceClassPathEntries(new Path(this.firstPage.getProjectName()).makeAbsolute());
    final SubMonitor subMonitor = SubMonitor.convert(monitor, originalEntries.size() + 1);
    for (final IClasspathEntry sourceClasspathEntry : originalEntries) {
        final IPath path = sourceClasspathEntry.getPath();
        if (path.segmentCount() > 1) {
            final IFolder folder = root.getFolder(path);
            CoreUtility.createFolder(folder, true, true, subMonitor.newChild(1));
        }/*from  w w w  . ja  va  2  s.  c  o  m*/
        cpEntries.add(sourceClasspathEntry);
    }

    this.firstPage.putDefaultClasspathEntriesIn(cpEntries);

    final IClasspathEntry[] entries = cpEntries.toArray(new IClasspathEntry[cpEntries.size()]);

    final IPath outLocation = this.firstPage.getOutputLocation();
    if (outLocation.segmentCount() > 1) {
        final IFolder folder = root.getFolder(outLocation);
        CoreUtility.createDerivedFolder(folder, true, true, subMonitor.newChild(1));
    }

    if (classpath != null) {
        classpath.set(entries);
    }
    if (outputLocation != null) {
        outputLocation.set(outLocation);
    }
}

From source file:io.sarl.eclipse.wizards.newproject.NewSarlProjectWizard.java

License:Apache License

private static boolean hasSourcePath(IJavaProject javaProject, IPath path) {
    if (path != null) {
        final IPath pathInProject = javaProject.getProject().getFullPath().append(path);
        try {//  ww  w .ja v a  2 s  .  c om
            for (final IClasspathEntry entry : javaProject.getRawClasspath()) {
                if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                        && pathInProject.equals(entry.getPath())) {
                    return true;
                }
            }
        } catch (Throwable exception) {
            //
        }
    }
    return false;
}

From source file:io.sarl.eclipse.wizards.newproject.NewSarlProjectWizard.java

License:Apache License

private static String buildInvalidOutputPathMessageFragment(IJavaProject javaProject) {
    final StringBuilder sourceFolders = new StringBuilder();
    try {//w  ww  .j a  v a  2 s  . com
        for (final IClasspathEntry entry : javaProject.getRawClasspath()) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                sourceFolders.append("\t"); //$NON-NLS-1$
                sourceFolders.append(entry.getPath().toOSString());
                sourceFolders.append("\n"); //$NON-NLS-1$
            }
        }
    } catch (Throwable exception) {
        //
    }
    return sourceFolders.toString();
}

From source file:io.sarl.m2e.MavenProjectSREProviderFactory.java

License:Apache License

@Override
public ProjectSREProvider getProjectSREProvider(IProject project) {
    try {//from   w  w  w.  j av  a 2s  .  c om
        if (project.hasNature(IMavenConstants.NATURE_ID) && project.hasNature(JavaCore.NATURE_ID)
                && project.hasNature(SARLEclipseConfig.NATURE_ID)) {
            final IMavenProjectFacade facade = MavenPluginActivator.getDefault().getMavenProjectManager()
                    .getProject(project);
            if (facade == null) {
                return null;
            }
            final IJavaProject javaProject = JavaCore.create(project);
            final IClasspathEntry[] classpath = javaProject.getResolvedClasspath(true);
            if (classpath == null) {
                return null;
            }
            for (final IClasspathEntry dep : classpath) {
                final IPath depPath = dep.getPath();
                if (SARLRuntime.isPackedSRE(depPath)) {
                    return new MavenProjectSREProvider(
                            facade.getArtifactKey().toString() + ":" + depPath.lastSegment(), //$NON-NLS-1$
                            depPath);
                }
            }
        }
    } catch (CoreException e) {
        SARLMavenEclipsePlugin.getDefault().log(e);
    }
    return null;
}