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

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

Introduction

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

Prototype

int getEntryKind();

Source Link

Document

Returns the kind of this classpath entry.

Usage

From source file:org.eclipse.che.plugin.java.server.rest.ClasspathService.java

License:Open Source License

private List<ClasspathEntryDto> convertClasspathEntriesToDTO(IJavaProject javaProject,
        IClasspathEntry[] entries) throws JavaModelException {
    List<ClasspathEntryDto> entriesDTO = new ArrayList<>(entries.length);
    for (IClasspathEntry entry : entries) {
        ClasspathEntryDto entryDTO = DtoFactory.getInstance().createDto(ClasspathEntryDto.class);
        entryDTO.withEntryKind(entry.getEntryKind()).withPath(entry.getPath().toOSString());
        if (IClasspathEntry.CPE_CONTAINER == entry.getEntryKind()) {

            IClasspathEntry[] subEntries = JavaCore.getClasspathContainer(entry.getPath(), javaProject)
                    .getClasspathEntries();

            entryDTO.withExpandedEntries(convertClasspathEntriesToDTO(javaProject, subEntries));
        }//from ww w.  j a va 2s .co  m
        entriesDTO.add(entryDTO);
    }

    return entriesDTO;
}

From source file:org.eclipse.che.plugin.java.testing.AbstractJavaTestRunner.java

License:Open Source License

protected String getOutputDirectory(IJavaProject javaProject) {
    String path = workspacePath + javaProject.getPath() + TEST_OUTPUT_FOLDER;
    try {//from   w ww .java2s  .co  m
        IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry iClasspathEntry : resolvedClasspath) {
            if (iClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath outputLocation = iClasspathEntry.getOutputLocation();
                if (outputLocation == null) {
                    continue;
                }
                return workspacePath + outputLocation.removeLastSegments(1).append(TEST_OUTPUT_FOLDER);
            }
        }
    } catch (JavaModelException e) {
        return path;
    }
    return path;
}

From source file:org.eclipse.che.plugin.java.testing.ProjectClasspathProvider.java

License:Open Source License

/**
 * Builds classpath for the java project.
 *
 * @param javaProject java project//from  w  w w .  j  a  v  a  2s .co  m
 * @return set of resources which are included to the classpath
 */
public Set<String> getProjectClassPath(IJavaProject javaProject) {
    try {
        IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(false);
        Set<String> result = new HashSet<>();
        for (IClasspathEntry classpathEntry : resolvedClasspath) {
            switch (classpathEntry.getEntryKind()) {
            case IClasspathEntry.CPE_LIBRARY:
                IPath path = classpathEntry.getPath();
                result.add(path.toOSString());
                break;

            case IClasspathEntry.CPE_SOURCE:
                IPath outputLocation = classpathEntry.getOutputLocation();
                if (outputLocation != null) {
                    result.add(workspacePath + outputLocation.toOSString());
                }
                break;

            case IClasspathEntry.CPE_PROJECT:
                IPath projectPath = classpathEntry.getPath();
                JavaModel javaModel = JavaModelManager.getJavaModelManager().getJavaModel();
                IJavaProject project = javaModel.getJavaProject(projectPath.toOSString());
                result.addAll(getProjectClassPath(project));
                break;
            }
        }
        return result;
    } catch (JavaModelException e) {
        LOG.debug(e.getMessage(), e);
    }

    return Collections.emptySet();
}

From source file:org.eclipse.che.plugin.java.testing.ProjectClasspathProviderTest.java

License:Open Source License

@Test
public void classpathProviderShouldProvideClasspathPaths() throws Exception {
    IClasspathEntry classpathEntry = mock(IClasspathEntry.class);
    when(classpathEntry.getEntryKind()).thenReturn(IClasspathEntry.CPE_SOURCE);
    IPath path = new Path("/testProject/target/classes");
    when(classpathEntry.getOutputLocation()).thenReturn(path);

    IClasspathEntry[] entries = new IClasspathEntry[] { classpathEntry };
    when(javaProject.getResolvedClasspath(false)).thenReturn(entries);

    Set<String> classPath = classpathProvider.getProjectClassPath(javaProject);
    assertThat(classPath).isNotNull().isNotEmpty().contains(PROJECTS_PATH + "/testProject/target/classes");
}

From source file:org.eclipse.che.plugin.java.testing.ProjectClasspathProviderTest.java

License:Open Source License

@Test
public void classpathProviderShouldProvideClasspathPathsWithExternalDependencies() throws Exception {
    IClasspathEntry classpathEntry = mock(IClasspathEntry.class);
    when(classpathEntry.getEntryKind()).thenReturn(IClasspathEntry.CPE_SOURCE);
    IPath path = new Path("/testProject/target/classes");
    when(classpathEntry.getOutputLocation()).thenReturn(path);

    IClasspathEntry jarClasspathEntry = mock(IClasspathEntry.class);
    when(jarClasspathEntry.getEntryKind()).thenReturn(IClasspathEntry.CPE_LIBRARY);
    IPath jarPath = new Path("/absolute/path/to/jar.file");
    when(jarClasspathEntry.getPath()).thenReturn(jarPath);

    IClasspathEntry[] entries = new IClasspathEntry[] { classpathEntry, jarClasspathEntry };
    when(javaProject.getResolvedClasspath(false)).thenReturn(entries);

    Set<String> classPath = classpathProvider.getProjectClassPath(javaProject);

    assertThat(classPath).isNotNull().isNotEmpty().contains(PROJECTS_PATH + "/testProject/target/classes",
            "/absolute/path/to/jar.file");
}

From source file:org.eclipse.che.plugin.java.testing.ProjectClasspathProviderTest.java

License:Open Source License

private IClasspathEntry mockClasspathEntry(int kind, String path, String outputPath) {
    IClasspathEntry result = mock(IClasspathEntry.class);
    when(result.getEntryKind()).thenReturn(kind);
    when(result.getPath()).thenReturn(new Path(path));
    if (outputPath != null) {
        when(result.getOutputLocation()).thenReturn(new Path(outputPath));
    }/*  w w  w. ja v a 2s  . c o  m*/
    return result;
}

From source file:org.eclipse.che.plugin.maven.server.classpath.OutputPathTest.java

License:Open Source License

@Test
public void testSourceClasspathEntryShouldHaveOutputLocationPath() throws Exception {
    String pom = "<groupId>test</groupId>" + "<artifactId>testOutputLocation</artifactId>"
            + "<version>42</version>" + "<dependencies>" + "    <dependency>"
            + "        <groupId>junit</groupId>" + "        <artifactId>junit</artifactId>"
            + "        <version>4.12</version>" + "    </dependency>" + "</dependencies>";
    createTestProject("test", pom);

    IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
    mavenWorkspace.update(Collections.singletonList(test));
    mavenWorkspace.waitForUpdate();//from  w w w  .  java2  s .  c  o  m

    JavaProject javaProject = (JavaProject) JavaCore.create(test);
    IClasspathEntry[] classpath = javaProject.getResolvedClasspath();
    IClasspathEntry srcMainJava = null;
    for (IClasspathEntry entry : classpath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                && entry.getPath().toOSString().endsWith("src/main/java")) {
            srcMainJava = entry;
            break;
        }
    }

    assertThat(srcMainJava).isNotNull();
    assertThat(srcMainJava.getOutputLocation()).isNotNull();
    assertThat(srcMainJava.getOutputLocation().toOSString()).endsWith("target/classes");
}

From source file:org.eclipse.che.plugin.maven.server.classpath.OutputPathTest.java

License:Open Source License

@Test
public void testSourceClasspathEntryShouldHaveCustomOutputLocationPath() throws Exception {
    String pom = "<groupId>test</groupId>" + "<artifactId>testOutputLocation</artifactId>"
            + "<version>42</version>" + "<dependencies>" + "    <dependency>"
            + "        <groupId>junit</groupId>" + "        <artifactId>junit</artifactId>"
            + "        <version>4.12</version>" + "    </dependency>" + "</dependencies>" + "<build>"
            + "  <outputDirectory>bin/classes</outputDirectory>" + "</build>";

    createTestProject("test", pom);

    IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
    mavenWorkspace.update(Collections.singletonList(test));
    mavenWorkspace.waitForUpdate();/*  w ww.j a v a  2  s . c o m*/

    JavaProject javaProject = (JavaProject) JavaCore.create(test);
    IClasspathEntry[] classpath = javaProject.getResolvedClasspath();
    IClasspathEntry srcMainJava = null;
    for (IClasspathEntry entry : classpath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                && entry.getPath().toOSString().endsWith("src/main/java")) {
            srcMainJava = entry;
            break;
        }
    }

    assertThat(srcMainJava).isNotNull();
    assertThat(srcMainJava.getOutputLocation()).isNotNull();
    assertThat(srcMainJava.getOutputLocation().toOSString()).endsWith("bin/classes");
}

From source file:org.eclipse.che.plugin.maven.server.classpath.OutputPathTest.java

License:Open Source License

@Test
public void testTestSourceClasspathEntryShouldHaveOutputLocationPath() throws Exception {
    String pom = "<groupId>test</groupId>" + "<artifactId>testOutputLocation</artifactId>"
            + "<version>42</version>" + "<dependencies>" + "    <dependency>"
            + "        <groupId>junit</groupId>" + "        <artifactId>junit</artifactId>"
            + "        <version>4.12</version>" + "    </dependency>" + "</dependencies>";
    createTestProject("test", pom);

    IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
    mavenWorkspace.update(Collections.singletonList(test));
    mavenWorkspace.waitForUpdate();// w  ww. j  a  v  a 2  s . c  o  m

    JavaProject javaProject = (JavaProject) JavaCore.create(test);
    IClasspathEntry[] classpath = javaProject.getResolvedClasspath();
    IClasspathEntry srcMainJava = null;
    for (IClasspathEntry entry : classpath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                && entry.getPath().toOSString().endsWith("src/test/java")) {
            srcMainJava = entry;
            break;
        }
    }

    assertThat(srcMainJava).isNotNull();
    assertThat(srcMainJava.getOutputLocation()).isNotNull();
    assertThat(srcMainJava.getOutputLocation().toOSString()).endsWith("target/test-classes");
}

From source file:org.eclipse.che.plugin.maven.server.classpath.OutputPathTest.java

License:Open Source License

@Test
public void testTestSourceClasspathEntryShouldHaveCustomOutputLocationPath() throws Exception {
    String pom = "<groupId>test</groupId>" + "<artifactId>testOutputLocation</artifactId>"
            + "<version>42</version>" + "<dependencies>" + "    <dependency>"
            + "        <groupId>junit</groupId>" + "        <artifactId>junit</artifactId>"
            + "        <version>4.12</version>" + "    </dependency>" + "</dependencies>" + "<build>"
            + "  <testOutputDirectory>test/test-classes</testOutputDirectory>" + "</build>";

    createTestProject("test", pom);

    IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
    mavenWorkspace.update(Collections.singletonList(test));
    mavenWorkspace.waitForUpdate();/*from  ww w  .j  a  va2  s  .  c o m*/

    JavaProject javaProject = (JavaProject) JavaCore.create(test);
    IClasspathEntry[] classpath = javaProject.getResolvedClasspath();
    IClasspathEntry srcMainJava = null;
    for (IClasspathEntry entry : classpath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                && entry.getPath().toOSString().endsWith("src/test/java")) {
            srcMainJava = entry;
            break;
        }
    }

    assertThat(srcMainJava).isNotNull();
    assertThat(srcMainJava.getOutputLocation()).isNotNull();
    assertThat(srcMainJava.getOutputLocation().toOSString()).endsWith("test/test-classes");
}