Example usage for org.eclipse.jdt.core IJavaProject getProject

List of usage examples for org.eclipse.jdt.core IJavaProject getProject

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getProject.

Prototype

IProject getProject();

Source Link

Document

Returns the IProject on which this IJavaProject was created.

Usage

From source file:com.google.gdt.eclipse.core.ui.JavaProjectSelectionDialog.java

License:Open Source License

/**
 * Opens the dialog for the user to choose a Java project.
 * //from www .  j ava  2s  .  c o  m
 * @param shell the parent shell
 * @param initialSelection the initially-selected project, or
 *          <code>null</code>
 * @param requiredNatures the natures that chosen project must have, or
 *          <code>null</code>
 * @return the selected project, or <code>null</code> if the dialog was
 *         canceled
 */
public static IJavaProject chooseProject(Shell shell, IJavaProject initialSelection,
        Set<String> requiredNatures) {
    // Start with all the Java projects in the workspace
    List<IJavaProject> javaProjects = new ArrayList<IJavaProject>();
    try {
        javaProjects.addAll(
                Arrays.asList(JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects()));
    } catch (JavaModelException e) {
        CorePluginLog.logError(e);
    }

    // Filter the list to only show projects with the specified nature
    if (requiredNatures != null) {
        Iterator<IJavaProject> iter = javaProjects.iterator();
        while (iter.hasNext()) {
            IJavaProject javaProject = iter.next();
            for (String requiredNature : requiredNatures) {
                try {
                    if (!NatureUtils.hasNature(javaProject.getProject(), requiredNature)) {
                        iter.remove();
                        break;
                    }
                } catch (CoreException e) {
                    CorePluginLog.logError(e);
                }
            }
        }
    }

    ElementListSelectionDialog dialog = new JavaProjectSelectionDialog(shell, javaProjects, initialSelection);

    if (dialog.open() == Window.OK) {
        return (IJavaProject) dialog.getFirstResult();
    }
    return null;
}

From source file:com.google.gdt.eclipse.core.validators.AbstractProjectValidator.java

License:Open Source License

protected static void addInvalidSdkMarker(String problemMarkerID, IJavaProject javaProject, Sdk sdk,
        String sdkTypeName, String detailedErrorMessage) throws CoreException {
    MarkerUtilities.createQuickFixMarker(problemMarkerID, ProjectStructureOrSdkProblemType.INVALID_SDK, null,
            javaProject.getProject(), sdkTypeName, sdk.getName(), detailedErrorMessage);
}

From source file:com.google.gdt.eclipse.core.validators.AbstractProjectValidator.java

License:Open Source License

protected static void addNoSdkMarker(String problemMarkerID, IJavaProject javaProject, String sdkTypeName)
        throws CoreException {
    MarkerUtilities.createQuickFixMarker(problemMarkerID, ProjectStructureOrSdkProblemType.NO_SDK, sdkTypeName,
            javaProject.getProject(), javaProject.getElementName(), sdkTypeName);
}

From source file:com.google.gdt.eclipse.core.validators.WebAppProjectValidator.java

License:Open Source License

private boolean validateBuildClasspath(IJavaProject javaProject) throws CoreException {
    IPath webInfLibFolderLocation = null;

    IFolder webInfLibFolder = WebAppUtilities.getWebInfOut(getProject()).getFolder("lib");

    if (webInfLibFolder.exists()) {
        webInfLibFolderLocation = webInfLibFolder.getLocation();
    }/*from   www .j  av a 2  s  .  c  o  m*/

    IClasspathEntry[] rawClasspaths = javaProject.getRawClasspath();
    boolean isOk = true;
    List<IPath> excludedJars = WebAppProjectProperties.getJarsExcludedFromWebInfLib(javaProject.getProject());

    for (IClasspathEntry rawClasspath : rawClasspaths) {
        rawClasspath = JavaCore.getResolvedClasspathEntry(rawClasspath);
        if (rawClasspath.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IPath entryPath = ResourceUtils.resolveToAbsoluteFileSystemPath(rawClasspath.getPath());
            if (excludedJars.contains(entryPath)) {
                continue;
            }

            if (webInfLibFolderLocation == null || !webInfLibFolderLocation.isPrefixOf(entryPath)) {
                MarkerUtilities.createQuickFixMarker(PROBLEM_MARKER_ID,
                        ProjectStructureOrSdkProblemType.JAR_OUTSIDE_WEBINF_LIB, entryPath.toPortableString(),
                        javaProject.getProject(), entryPath.toOSString());
                isOk = false;
            }
        }
    }

    return isOk;
}

From source file:com.google.gdt.eclipse.core.WebAppUtilities.java

License:Open Source License

/**
 * Sets the project's default output directory to the WAR output directory's
 * WEB-INF/classes folder. If the WAR output directory does not have a WEB-INF
 * directory, this method returns without doing anything.
 *
 * @throws CoreException if there's a problem setting the output directory
 *//*  ww w .  java  2  s  . c o m*/
public static void setOutputLocationToWebInfClasses(IJavaProject javaProject, IProgressMonitor monitor)
        throws CoreException {
    IProject project = javaProject.getProject();

    IFolder webInfOut = getWebInfOut(project);
    if (!webInfOut.exists()) {
        // If the project has no output <WAR>/WEB-INF directory, don't touch the
        // output location
        return;
    }

    IPath oldOutputPath = javaProject.getOutputLocation();
    IPath outputPath = webInfOut.getFullPath().append("classes");

    if (!outputPath.equals(oldOutputPath)) {
        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

        // Remove old output location and contents
        IFolder oldOutputFolder = workspaceRoot.getFolder(oldOutputPath);
        if (oldOutputFolder.exists()) {
            try {
                removeOldClassfiles(oldOutputFolder);
            } catch (Exception e) {
                CorePluginLog.logError(e);
            }
        }

        // Create the new output location if necessary
        IFolder outputFolder = workspaceRoot.getFolder(outputPath);
        if (!outputFolder.exists()) {
            // TODO: Could move recreate this in a utilities class
            CoreUtility.createDerivedFolder(outputFolder, true, true, null);
        }

        javaProject.setOutputLocation(outputPath, monitor);
    }
}

From source file:com.google.gdt.eclipse.designer.core.util.UtilsTest.java

License:Open Source License

/**
 * Test for {@link Utils#isGWTProject(IJavaProject)} and {@link Utils#isGWTProject(IProject)}.
 *//*from   www  .j a  v a 2s  . c om*/
public void test_isGWTProject() throws Exception {
    IJavaProject javaProject = Utils.getJavaProject("TestProject");
    assertTrue(Utils.isGWTProject(javaProject));
    assertTrue(Utils.isGWTProject(javaProject.getProject()));
}

From source file:com.google.gdt.eclipse.designer.core.util.UtilsTest.java

License:Open Source License

/**
 * Test for {@link Utils#isGWTProject(IJavaProject)} and {@link Utils#isGWTProject(IProject)}.
 *//*  w w w . j a  v  a  2 s. c  o  m*/
public void test_isGWTProject_newProject() throws Exception {
    TestProject newProject = new TestProject("newProject");
    try {
        IJavaProject javaProject = newProject.getJavaProject();
        IProject project = javaProject.getProject();
        // initially not GWT project
        assertFalse(Utils.isGWTProject(javaProject));
        assertFalse(Utils.isGWTProject(project));
        // convert into GWT project
        GTestUtils.configure(newProject);
        assertTrue(Utils.isGWTProject(javaProject));
        assertTrue(Utils.isGWTProject(project));
        // remove GWT nature, still GWT project
        ProjectUtils.removeNature(project, Constants.NATURE_ID);
        assertTrue(Utils.isGWTProject(javaProject));
        assertTrue(Utils.isGWTProject(project));
    } finally {
        newProject.dispose();
    }
}

From source file:com.google.gdt.eclipse.designer.hosted.tdt.HostedModeSupport.java

License:Open Source License

public static String getTemporaryDirectoryName(IJavaProject javaProject) {
    String logDir = javaProject.getProject().getLocation().toOSString() + File.separator + ".gwt";
    File logDirFile = new File(logDir);
    logDirFile.mkdirs();/*from w w w.ja va  2s  .c om*/
    return logDir;
}

From source file:com.google.gdt.eclipse.designer.model.web.WebUtils.java

License:Open Source License

/**
 * @return the name of "web" folder.//from ww w. j  a  v  a2s  . c o m
 */
public static String getWebFolderName(IJavaProject javaProject) {
    IProject project = javaProject.getProject();
    return getWebFolderName(project);
}

From source file:com.google.gdt.eclipse.designer.model.web.WebUtils.java

License:Open Source License

/**
 * @return the "web" folder./*from  w  ww. j  a  va  2 s .  c o m*/
 */
public static IFolder getWebFolder(IJavaProject javaProject) {
    IProject project = javaProject.getProject();
    return getWebFolder(project);
}