Search in sources :

Example 36 with IProject

use of org.eclipse.core.resources.IProject in project che by eclipse.

the class QualifiedNameFinder method createScope.

private static TextSearchScope createScope(String filePatterns, IProject root) {
    HashSet<IProject> res = new HashSet<IProject>();
    res.add(root);
    addReferencingProjects(root, res);
    IResource[] resArr = res.toArray(new IResource[res.size()]);
    Pattern filePattern = getFilePattern(filePatterns);
    return TextSearchScope.newSearchScope(resArr, filePattern, false);
}
Also used : Pattern(java.util.regex.Pattern) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 37 with IProject

use of org.eclipse.core.resources.IProject in project generator by mybatis.

the class RunGeneratorThread method getJavaProject.

private IJavaProject getJavaProject() {
    IJavaProject answer = null;
    IProject project = inputFile.getProject();
    try {
        if (project.hasNature(JavaCore.NATURE_ID)) {
            answer = JavaCore.create(project);
        }
    } catch (CoreException e) {
        // ignore - something is wrong
        ;
    }
    return answer;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject)

Example 38 with IProject

use of org.eclipse.core.resources.IProject 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 39 with IProject

use of org.eclipse.core.resources.IProject in project che by eclipse.

the class JavaProjectHelper method addClassFolder.

/**
     * Creates and adds a class folder to the class path.
     * @param jproject The parent project
     * @param containerName
     * @param sourceAttachPath The source attachment path
     * @param sourceAttachRoot The source attachment root path
     * @return The handle of the created root
     * @throws CoreException
     */
public static IPackageFragmentRoot addClassFolder(IJavaProject jproject, String containerName, IPath sourceAttachPath, IPath sourceAttachRoot) throws CoreException {
    IProject project = jproject.getProject();
    IContainer container = null;
    if (containerName == null || containerName.length() == 0) {
        container = project;
    } else {
        IFolder folder = project.getFolder(containerName);
        if (!folder.exists()) {
            CoreUtility.createFolder(folder, false, true, null);
        }
        container = folder;
    }
    IClasspathEntry cpe = JavaCore.newLibraryEntry(container.getFullPath(), sourceAttachPath, sourceAttachRoot);
    addToClasspath(jproject, cpe);
    return jproject.getPackageFragmentRoot(container);
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IContainer(org.eclipse.core.resources.IContainer) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 40 with IProject

use of org.eclipse.core.resources.IProject in project che by eclipse.

the class JavaSearchScope method packageFragmentRoot.

/**
     * @see AbstractJavaSearchScope#packageFragmentRoot(String, int, String)
     */
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPath) {
    int index = -1;
    boolean isJarFile = jarSeparatorIndex != -1;
    if (isJarFile) {
        // internal or external jar (case 3, 4, or 5)
        String relativePath = resourcePathString.substring(jarSeparatorIndex + 1);
        index = indexOf(jarPath, relativePath);
    } else {
        // resource in workspace (case 1 or 2)
        index = indexOf(resourcePathString);
    }
    if (index >= 0) {
        int idx = this.projectIndexes[index];
        String projectPath = idx == -1 ? null : (String) this.projectPaths.get(idx);
        if (projectPath != null) {
            IJavaProject project = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject(projectPath));
            if (isJarFile) {
                IResource resource = JavaModel.getWorkspaceTarget(new Path(jarPath));
                if (resource != null)
                    return project.getPackageFragmentRoot(resource);
                return project.getPackageFragmentRoot(jarPath);
            }
            Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[index] + '/' + this.relativePaths[index]));
            if (target != null) {
                if (target instanceof IProject) {
                    return project.getPackageFragmentRoot((IProject) target);
                }
                IJavaElement element = JavaModelManager.create((IResource) target, project);
                return (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
            }
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

IProject (org.eclipse.core.resources.IProject)2658 IFile (org.eclipse.core.resources.IFile)642 CoreException (org.eclipse.core.runtime.CoreException)598 Test (org.junit.Test)483 IPath (org.eclipse.core.runtime.IPath)408 IFolder (org.eclipse.core.resources.IFolder)339 IResource (org.eclipse.core.resources.IResource)305 File (java.io.File)279 ArrayList (java.util.ArrayList)270 Path (org.eclipse.core.runtime.Path)268 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)259 IOException (java.io.IOException)201 IJavaProject (org.eclipse.jdt.core.IJavaProject)193 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)186 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)175 IProjectDescription (org.eclipse.core.resources.IProjectDescription)161 IWorkspace (org.eclipse.core.resources.IWorkspace)138 IStatus (org.eclipse.core.runtime.IStatus)124 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)116 List (java.util.List)109