Search in sources :

Example 56 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class ClasspathBuilderTest method rawClasspathShouldBeContained3Arguments.

@Test
public void rawClasspathShouldBeContained3Arguments() throws Exception {
    createTestProject();
    library.add("/lib");
    sourceFolders.add("/src");
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("/project");
    IJavaProject iJavaProject = JavaCore.create(project);
    classpathBuilder.generateClasspath(iJavaProject, sourceFolders, library);
    List<IClasspathEntry> classpathEntries = Arrays.asList(iJavaProject.getRawClasspath());
    assertThat(classpathEntries).onProperty("path").containsOnly(new Path(JREContainerInitializer.JRE_CONTAINER), new Path("/project/src"), new Path(root + "/project/lib/a.jar"));
}
Also used : Path(org.eclipse.core.runtime.Path) IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IProject(org.eclipse.core.resources.IProject) Test(org.testng.annotations.Test) BaseTest(org.eclipse.che.plugin.java.plain.server.BaseTest)

Example 57 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class JavaProjectHelper method delete.

/**
     * Removes an IJavaElement's resource. Retries if deletion failed (e.g. because the indexer
     * still locks the file).
     *
     * @param elem the element to delete
     * @throws CoreException if operation failed
     * @see #ASSERT_NO_MIXED_LINE_DELIMIERS
     */
public static void delete(final IJavaElement elem) throws CoreException {
    //			MixedLineDelimiterDetector.assertNoMixedLineDelimiters(elem);
    if (elem instanceof JavaProject) {
        ((JavaProject) elem).close();
        JavaModelManager.getJavaModelManager().removePerProjectInfo((JavaProject) elem, true);
    }
    JavaModelManager.getJavaModelManager().resetTemporaryCache();
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            //				performDummySearch();
            if (elem instanceof IJavaProject) {
                IJavaProject jproject = (IJavaProject) elem;
                jproject.setRawClasspath(new IClasspathEntry[0], jproject.getProject().getFullPath(), null);
            }
            delete(elem.getResource());
        }
    };
    ResourcesPlugin.getWorkspace().run(runnable, null);
//		emptyDisplayLoop();
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject)

Example 58 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class ProjectTestSetup method createAndInitializeProject.

protected IJavaProject createAndInitializeProject() throws CoreException {
    IJavaProject javaProject = JavaProjectHelper.createJavaProject(PROJECT_NAME, "bin");
    javaProject.setRawClasspath(getDefaultClasspath(), null);
    TestOptions.initializeProjectOptions(javaProject);
    return javaProject;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject)

Example 59 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class ClasspathUpdaterService method updateClasspath.

/**
     * Updates the information about classpath.
     *
     * @param projectPath
     *         path to the current project
     * @param entries
     *         list of classpath entries which need to set
     * @throws JavaModelException
     *         if JavaModel has a failure
     * @throws ServerException
     *         if some server error
     * @throws ForbiddenException
     *         if operation is forbidden
     * @throws ConflictException
     *         if update operation causes conflicts
     * @throws NotFoundException
     *         if Project with specified path doesn't exist in workspace
     * @throws IOException
     */
@POST
@Consumes(MediaType.APPLICATION_JSON)
public void updateClasspath(@QueryParam("projectpath") String projectPath, List<ClasspathEntryDto> entries) throws JavaModelException, ServerException, ForbiddenException, ConflictException, NotFoundException, IOException {
    IJavaProject javaProject = model.getJavaProject(projectPath);
    javaProject.setRawClasspath(createModifiedEntry(entries), javaProject.getOutputLocation(), new NullProgressMonitor());
    updateProjectConfig(projectPath);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 60 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class PlainJavaProjectGeneratorTest method projectShouldBeCreatedWithDefaultContent.

@Test
public void projectShouldBeCreatedWithDefaultContent() throws Exception {
    attributes = new HashMap<>();
    options = new HashMap<>();
    PlainJavaProjectGenerator generator = new PlainJavaProjectGenerator(vfsProvider, classpathBuilder);
    generator.onCreateProject(Path.of("project"), attributes, options);
    IJavaProject project = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProject("project");
    assertTrue(project.exists());
    verify(classpathBuilder).generateClasspath(project, singletonList(DEFAULT_SOURCE_FOLDER_VALUE), singletonList(DEFAULT_LIBRARY_FOLDER_VALUE));
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) BaseTest(org.eclipse.che.plugin.java.plain.server.BaseTest) Test(org.testng.annotations.Test)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)743 IProject (org.eclipse.core.resources.IProject)178 IFile (org.eclipse.core.resources.IFile)149 Test (org.junit.Test)146 CoreException (org.eclipse.core.runtime.CoreException)127 JavaModelException (org.eclipse.jdt.core.JavaModelException)124 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)123 IPath (org.eclipse.core.runtime.IPath)110 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)103 ArrayList (java.util.ArrayList)87 IFolder (org.eclipse.core.resources.IFolder)78 IResource (org.eclipse.core.resources.IResource)75 IJavaElement (org.eclipse.jdt.core.IJavaElement)63 IType (org.eclipse.jdt.core.IType)63 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)62 Path (org.eclipse.core.runtime.Path)57 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)56 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)47 StringInputStream (org.eclipse.xtext.util.StringInputStream)39 HashMap (java.util.HashMap)38