Search in sources :

Example 81 with IProject

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

the class GeneratorLaunchShortcut method getJavaProjectNameFromResource.

/**
     * This will return null if there isn't a JavaProject associated with this
     * resource.
     * 
     * @param resource
     * @return the JavaProject name if there is one
     */
public static String getJavaProjectNameFromResource(IResource resource) {
    String name = null;
    IProject project = resource.getProject();
    try {
        if (project != null && project.exists() && project.hasNature(JavaCore.NATURE_ID)) {
            // add the JavaProject name to the launch - this will add it to the
            // classpath of the launch automatically
            IJavaProject javaProject = JavaCore.create(project);
            name = javaProject.getElementName();
        }
    } catch (CoreException e) {
    // just ignore it - no ultimate harm done if we can't find the Java project
    }
    return name;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject)

Example 82 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 83 with IProject

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

the class EclipseShellCallback method getJavaProject.

private IJavaProject getJavaProject(String javaProjectName) throws ShellException {
    IJavaProject javaProject = projects.get(javaProjectName);
    if (javaProject == null) {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IProject project = root.getProject(javaProjectName);
        if (project.exists()) {
            boolean isJavaProject;
            try {
                isJavaProject = project.hasNature(JavaCore.NATURE_ID);
            } catch (CoreException e) {
                throw new ShellException(e.getStatus().getMessage(), e);
            }
            if (isJavaProject) {
                javaProject = JavaCore.create(project);
            } else {
                StringBuffer sb = new StringBuffer();
                sb.append("Project ");
                sb.append(javaProjectName);
                sb.append(" is not a Java project");
                throw new ShellException(sb.toString());
            }
        } else {
            StringBuffer sb = new StringBuffer();
            sb.append("Project ");
            sb.append(javaProjectName);
            sb.append(" does not exist");
            throw new ShellException(sb.toString());
        }
        projects.put(javaProjectName, javaProject);
    }
    return javaProject;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) ShellException(org.mybatis.generator.exception.ShellException) IProject(org.eclipse.core.resources.IProject)

Example 84 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 85 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)

Aggregations

IProject (org.eclipse.core.resources.IProject)665 CoreException (org.eclipse.core.runtime.CoreException)157 IFile (org.eclipse.core.resources.IFile)142 Test (org.junit.Test)130 IResource (org.eclipse.core.resources.IResource)112 IPath (org.eclipse.core.runtime.IPath)98 IFolder (org.eclipse.core.resources.IFolder)77 File (java.io.File)73 IOException (java.io.IOException)70 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)70 Path (org.eclipse.core.runtime.Path)70 IJavaProject (org.eclipse.jdt.core.IJavaProject)68 ArrayList (java.util.ArrayList)67 IWorkspace (org.eclipse.core.resources.IWorkspace)55 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)48 ByteArrayInputStream (java.io.ByteArrayInputStream)45 ProjectAdapter (org.apache.sling.ide.test.impl.helpers.ProjectAdapter)45 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)41 IProjectDescription (org.eclipse.core.resources.IProjectDescription)38 IStatus (org.eclipse.core.runtime.IStatus)35