Example usage for com.google.gwt.eclipse.core.nature GWTNature NATURE_ID

List of usage examples for com.google.gwt.eclipse.core.nature GWTNature NATURE_ID

Introduction

In this page you can find the example usage for com.google.gwt.eclipse.core.nature GWTNature NATURE_ID.

Prototype

String NATURE_ID

To view the source code for com.google.gwt.eclipse.core.nature GWTNature NATURE_ID.

Click Source Link

Usage

From source file:com.google.gdt.eclipse.appengine.rpc.validators.JavaCompilationParticipant.java

License:Open Source License

@Override
public boolean isActive(IJavaProject project) {
    try {/*from   ww w  . j av  a 2  s . c om*/
        boolean active = project.exists() && (project.getProject().hasNature(GaeNature.NATURE_ID)
                || project.getProject().hasNature(GWTNature.NATURE_ID));
        return active;
    } catch (CoreException e) {
        AppEngineRPCPlugin.log(e);
        return false;
    }
}

From source file:com.google.gdt.eclipse.maven.configurators.AbstracMavenProjectConfigurator.java

License:Open Source License

/**
 * Searches the Maven pom.xml for the given project nature.
 *
 * @param mavenProject a description of the Maven project
 * @param natureId the nature to check//from w w w .j  av a 2  s. com
 * @return {@code true} if the project
 */
protected boolean hasProjectNature(MavenProject mavenProject, String natureId) {
    if (natureId == GWTNature.NATURE_ID || getGwtMavenPlugin(mavenProject) != null) {
        return true;
    }
    // The use of the maven-eclipse-plugin is deprecated. The following code is
    // only for backward compatibility.
    Plugin plugin = getEclipsePlugin(mavenProject);
    if (plugin != null) {
        Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
        if (configuration != null) {
            Xpp3Dom additionalBuildCommands = configuration.getChild("additionalProjectnatures");
            if (additionalBuildCommands != null) {
                for (Xpp3Dom projectNature : additionalBuildCommands.getChildren("projectnature")) {
                    if (projectNature != null && natureId.equals(projectNature.getValue())) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}

From source file:com.google.gdt.eclipse.maven.configurators.MavenProjectConfigurator.java

License:Open Source License

@Override
protected void doConfigure(final MavenProject mavenProject, IProject project,
        ProjectConfigurationRequest unused, final IProgressMonitor monitor) throws CoreException {
    Activator.log("MavenProjectConfigurator.doConfigure() invoked");

    // configure the GWT Nature
    boolean hasGwtNature = configureNature(project, mavenProject, GWTNature.NATURE_ID, true,
            new NatureCallback() {
                @Override//from ww w .  j  a  v  a2s  . c  o m
                protected void beforeAddingNature() {
                    configureGwtProject(mavenProject, monitor);
                }
            }, monitor);

    // retrieve gwt-maven-plugin configuration if it exists
    Plugin gwtMavenPlugin = getGwtMavenPlugin(mavenProject);
    Xpp3Dom mavenConfig = gwtMavenPlugin == null ? null : (Xpp3Dom) gwtMavenPlugin.getConfiguration();

    // Persist GWT nature settings
    if (!hasGwtNature) {
        Activator.log(
                "MavenProjectConfigurator: Skipping Maven configuration because GWT nature is false. hasGWTNature="
                        + hasGwtNature);
        // Exit no maven plugin found
        return;
    }

    try {
        persistGwtNatureSettings(project, mavenProject, mavenConfig);
    } catch (BackingStoreException exception) {
        Activator.logError("MavenProjectConfigurator: Problem configuring maven project.", exception);
    }
}

From source file:com.google.gdt.eclipse.maven.e35.configurators.AbstractGoogleProjectConfigurator.java

License:Open Source License

/**
 * Searches the Maven pom.xml for the given project nature.
 *//*from  w ww  . ja  v  a  2 s.co  m*/
protected boolean hasProjectNature(MavenProject mavenProject, IProject project, String natureId) {
    if ((natureId == GWTNature.NATURE_ID) && (getGwtMavenPlugin(mavenProject) != null)) {
        return true;
    }
    if ((natureId == GaeNature.NATURE_ID) && (getGaeMavenPlugin(mavenProject) != null)) {
        return true;
    }
    // The use of the maven-eclipse-plugin is deprecated. The following code is
    // only for backward compatibility.
    Plugin plugin = getEclipsePlugin(mavenProject);
    if (plugin != null) {
        Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
        if (configuration != null) {
            Xpp3Dom additionalBuildCommands = configuration.getChild("additionalProjectnatures");
            if (additionalBuildCommands != null) {
                for (Xpp3Dom projectNature : additionalBuildCommands.getChildren("projectnature")) {
                    if (projectNature != null && natureId.equals(projectNature.getValue())) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}

From source file:com.google.gdt.eclipse.maven.e35.configurators.GoogleProjectConfigurator.java

License:Open Source License

@Override
protected void doConfigure(final MavenProject mavenProject, IProject project,
        ProjectConfigurationRequest request, final IProgressMonitor monitor) throws CoreException {

    final IMaven maven = MavenPlugin.getDefault().getMaven();

    boolean configureGaeNatureSuccess = configureNature(project, mavenProject, GaeNature.NATURE_ID, true,
            new NatureCallbackAdapter() {

                @Override/*from w  ww .  ja v a 2  s .  c om*/
                public void beforeAddingNature() {
                    try {
                        DefaultMavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
                        executionRequest.setBaseDirectory(mavenProject.getBasedir());
                        executionRequest.setLocalRepository(maven.getLocalRepository());
                        executionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories());
                        executionRequest
                                .setPluginArtifactRepositories(mavenProject.getPluginArtifactRepositories());
                        executionRequest.setPom(mavenProject.getFile());
                        executionRequest.setGoals(GAE_UNPACK_GOAL);

                        MavenExecutionResult result = maven.execute(executionRequest, monitor);
                        if (result.hasExceptions()) {
                            Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
                                    "Error configuring project", result.getExceptions().get(0)));
                        }
                    } catch (CoreException e) {
                        Activator.getDefault().getLog().log(
                                new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error configuring project", e));
                    }
                }
            }, monitor);

    boolean configureGWTNatureSuccess = configureNature(project, mavenProject, GWTNature.NATURE_ID, true,
            new NatureCallbackAdapter() {

                @Override
                public void beforeAddingNature() {

                    // Get the GWT version from the project pom
                    String gwtVersion = null;
                    List<Dependency> dependencies = mavenProject.getDependencies();
                    for (Dependency dependency : dependencies) {
                        if (GWTMavenRuntime.MAVEN_GWT_GROUP_ID.equals(dependency.getGroupId())
                                && (GWTMavenRuntime.MAVEN_GWT_USER_ARTIFACT_ID
                                        .equals(dependency.getArtifactId())
                                        || GWTMavenRuntime.MAVEN_GWT_SERVLET_ARTIFACT_ID
                                                .equals(dependency.getArtifactId()))) {
                            gwtVersion = dependency.getVersion();
                            break;
                        }
                    }

                    // Check that the pom.xml has GWT dependencies
                    if (!StringUtilities.isEmpty(gwtVersion)) {
                        try {
                            /*
                             * Download and install the gwt-dev.jar into the local
                             * repository.
                             */
                            maven.resolve(GWTMavenRuntime.MAVEN_GWT_GROUP_ID,
                                    GWTMavenRuntime.MAVEN_GWT_DEV_JAR_ARTIFACT_ID, gwtVersion, "jar", null,
                                    mavenProject.getRemoteArtifactRepositories(), monitor);
                        } catch (CoreException e) {
                            Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
                                    "Error configuring project", e));
                        }
                    }
                }
            }, monitor);

    if (configureGWTNatureSuccess || configureGaeNatureSuccess) {
        try {
            // Add GWT Web Application configuration parameters
            WebAppProjectProperties.setWarSrcDir(project, new Path("src/main/webapp"));
            WebAppProjectProperties.setWarSrcDirIsOutput(project, false);

            String artifactId = mavenProject.getArtifactId();
            String version = mavenProject.getVersion();
            IPath location = (project.getRawLocation() != null ? project.getRawLocation()
                    : project.getLocation());
            if (location != null && artifactId != null && version != null) {
                WebAppProjectProperties.setLastUsedWarOutLocation(project,
                        location.append("target").append(artifactId + "-" + version));
            }
        } catch (BackingStoreException be) {
            Activator.getDefault().getLog()
                    .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error configuring project", be));
        }
    }
}

From source file:com.google.gdt.eclipse.suite.GdtPlugin.java

License:Open Source License

private static void rebuildGoogleProjectIfPluginVersionChanged(IProject project) {
    try {//from w ww.  ja v a2  s .  co  m
        // We're only worried about Google projects
        if (NatureUtils.hasNature(project, GWTNature.NATURE_ID)
                || NatureUtils.hasNature(project, GaeNature.NATURE_ID)) {
            // Find the last plugin version that know the project was built with
            Version lastForcedRebuildAt = GdtPreferences.getVersionForLastForcedRebuild(project);
            Version currentPluginVersion = GdtPlugin.getVersion();

            if (!lastForcedRebuildAt.equals(currentPluginVersion)) {
                GdtPreferences.setVersionForLastForcedRebuild(project, currentPluginVersion);

                BuilderUtilities.scheduleRebuild(project);
                CorePluginLog.logInfo("Scheduled rebuild of project " + project.getName()
                        + " because of plugin update (current version: " + currentPluginVersion.toString()
                        + ")");
            }
        }
    } catch (CoreException e) {
        CorePluginLog.logError(e);
    }
}

From source file:com.google.gdt.eclipse.suite.launch.ui.WebAppMainTab.java

License:Open Source License

/**
 * Returns <code>true</code> if the project exists and it uses GWT or GAE.
 *//* www.ja v  a  2 s. c om*/
private boolean isValidProject(String projectName) {
    if (projectName.length() == 0) {
        setErrorMessage("Project was not specified");
        return false;
    }

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IStatus status = workspace.validateName(projectName, IResource.PROJECT);
    if (status.isOK()) {
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        if (!project.exists()) {
            setErrorMessage(MessageFormat.format(LauncherMessages.JavaMainTab_20, projectName));
            return false;
        }

        if (!project.isOpen()) {
            setErrorMessage(MessageFormat.format(LauncherMessages.JavaMainTab_21, projectName));
            return false;
        }

        boolean isGwtOrGaeProject;
        try {
            isGwtOrGaeProject = NatureUtils.hasNature(project, GWTNature.NATURE_ID)
                    || NatureUtils.hasNature(project, GaeNature.NATURE_ID);
        } catch (CoreException e) {
            GdtPlugin.getLogger().logError(e);
            isGwtOrGaeProject = false;
        }

        if (!isGwtOrGaeProject) {
            setErrorMessage("Project does not use GWT or GAE");
            return false;
        }
    } else {
        setErrorMessage(MessageFormat.format(LauncherMessages.JavaMainTab_19, status.getMessage()));
        return false;
    }

    return true;
}

From source file:com.google.gdt.eclipse.suite.preferences.ui.ErrorsWarningsPage.java

License:Open Source License

@Override
public boolean performOk() {
    updateWorkingCopyFromCombos();//from w ww  . j av  a 2  s . c  o  m

    if (!GdtProblemSeverities.getInstance().equals(problemSeveritiesWorkingCopy)) {
        MessageDialog dialog = new MessageDialog(getShell(), "Errors/Warnings Settings Changed", null,
                "The Google Error/Warning settings have changed.  A full rebuild "
                        + "of all GWT/App Engine projects is required for changes to "
                        + "take effect.  Do the full build now?",
                MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                        IDialogConstants.CANCEL_LABEL },
                2); // Cancel is default
        int result = dialog.open();

        if (result == 2) { // Cancel
            return false;
        } else {
            updateWorkspaceSeveritySettingsFromWorkingCopy();

            if (result == 0) { // Yes
                BuilderUtilities.scheduleRebuildAll(GWTNature.NATURE_ID, GaeNature.NATURE_ID);
            }
        }
    }
    return true;
}

From source file:com.google.gdt.eclipse.suite.ProjectMigrator.java

License:Open Source License

/**
 * Migrates the given project if there is some migration that needs to be
 * done. This method ensures no exceptions escape.
 *//*from  w  w  w  .  j ava 2 s .c  om*/
private void safelyMigrateIfVersionChanged(IProject project) {
    try {
        if (NatureUtils.hasNature(project, GWTNature.NATURE_ID)
                || NatureUtils.hasNature(project, GaeNature.NATURE_ID)) {
            int projectVersion = GdtPreferences.getProjectMigratorVersion(project);
            if (projectVersion != CURRENT_VERSION) {
                migrateProject(project, projectVersion);
            }
        }
    } catch (Throwable e) {
        GdtPlugin.getLogger().logError(e, "Skipping project migrator for project " + project.getName());
    }
}

From source file:com.google.gdt.eclipse.suite.wizards.NewWebAppProjectWizard.java

License:Open Source License

@Override
protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
    try {/*from w  w  w  .  ja  v  a 2s  .  co  m*/
        IWebAppProjectCreator wapc = ProjectUtilities.createWebAppProjectCreator();

        wapc.setProjectName(projectName);
        wapc.setPackageName(packageName);
        wapc.setLocationURI(locationURI);
        wapc.setGenerateEmptyProject(isGenerateEmptyProject);
        wapc.setAppsMarketplaceSupported(isAppsMarketplaceSupported);

        if (useGae) {
            wapc.addContainerPath(gaeSdkContainerPath);
            wapc.addNature(GaeNature.NATURE_ID);
            wapc.setIsGaeSdkFromEclipseDefault(gaeSdkIsEclipseDefault);
        }

        if (useGWT) {
            wapc.addContainerPath(gwtSdkContainerPath);
            wapc.addNature(GWTNature.NATURE_ID);
        }

        wapc.create(monitor);

    } catch (MalformedURLException e) {
        throw new CoreException(new Status(IStatus.ERROR, GdtPlugin.PLUGIN_ID, e.getMessage(), e));
    } catch (UnsupportedEncodingException e) {
        throw new CoreException(new Status(IStatus.ERROR, GdtPlugin.PLUGIN_ID, e.getMessage(), e));
    } catch (SdkException e) {
        throw new CoreException(new Status(IStatus.ERROR, GdtPlugin.PLUGIN_ID, e.getMessage(), e));
    } catch (ClassNotFoundException e) {
        throw new CoreException(new Status(IStatus.ERROR, GdtPlugin.PLUGIN_ID, e.getMessage(), e));
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, GdtPlugin.PLUGIN_ID, e.getMessage(), e));
    } catch (BackingStoreException e) {
        throw new CoreException(new Status(IStatus.ERROR, GdtPlugin.PLUGIN_ID, e.getMessage(), e));
    }
}