Example usage for com.google.gwt.eclipse.core.runtime GWTRuntimeContainer CONTAINER_ID

List of usage examples for com.google.gwt.eclipse.core.runtime GWTRuntimeContainer CONTAINER_ID

Introduction

In this page you can find the example usage for com.google.gwt.eclipse.core.runtime GWTRuntimeContainer CONTAINER_ID.

Prototype

String CONTAINER_ID

To view the source code for com.google.gwt.eclipse.core.runtime GWTRuntimeContainer CONTAINER_ID.

Click Source Link

Usage

From source file:com.google.gdt.eclipse.appengine.rpc.wizards.helpers.RpcServiceLayerCreator.java

License:Open Source License

private String getGwtContainerPath(IJavaProject javaProject) throws CoreException {
    IClasspathEntry[] entries = null;//  w w  w .j  a v a 2  s . c o m

    entries = javaProject.getRawClasspath();

    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && entry.getPath().toString().equals("com.google.gwt.eclipse.core.GWT_CONTAINER")) { //$NON-NLS-N$
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            if (container instanceof GWTRuntimeContainer) {
                IPath path = ((GWTRuntimeContainer) container).getSdk().getInstallationPath();
                return path.toString();
            }
        }
    }
    // gwt not on classpath, add to it, set nature
    GWTRuntime gwt = GWTPreferences.getDefaultRuntime();
    IPath containerPath = SdkClasspathContainer.computeContainerPath(GWTRuntimeContainer.CONTAINER_ID, gwt,
            SdkClasspathContainer.Type.DEFAULT);
    if (GaeNature.isGaeProject(javaProject.getProject())) {
        addClasspathContainer(javaProject, containerPath);
        GWTNature.addNatureToProject(javaProject.getProject());
    }
    return gwt.getInstallationPath().toString();
}

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

License:Open Source License

IPath getGWTSdkContainerPath() {
    return getSdkContainerPath(gwtSelectionBlock.getSdkSelection(), GWTRuntimeContainer.CONTAINER_ID);
}

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

License:Open Source License

private void createGWTProject(IProgressMonitor monitor, String packageName, String outDirPath)
          throws MalformedURLException, SdkException, JavaModelException, ClassNotFoundException, CoreException {

      /*/*ww w. ja  va  2s. c  o  m*/
       * The project name will be used as the entry point name. When invoking
       * GWT's WebAppCreator, the entry point name will be passed in as the last
       * component in the module name. The WebAppCreator will use the last
       * component of the module name as the generated Eclipse project name, which
       * gives us the desired effect.
       *
       * FIXME: The project name may not be a valid entry point name. We need to
       * scan the project name token-by-token, and translate its tokens into a
       * valid Java identifier name. Some examples:
       *
       * If the first token in the project name is a lower-case letter, then the
       * translated character should be made upper case.
       *
       * If the first token in the project name is a non-alpha character it should
       * be deleted in the translation.
       */

      final String entryPoint = generateClassName(projectName);
      final String qualifiedModuleName = packageName + "." + entryPoint;

      IPath gwtContainerPath = findContainerPath(GWTRuntimeContainer.CONTAINER_ID);
      assert (gwtContainerPath != null);

      GWTRuntime runtime = GWTPreferences.getSdkManager().findSdkForPath(gwtContainerPath);
      assert (runtime != null);

      // Get a reference to the gwt-dev-<platform>.jar
      File gwtDevJar = runtime.getDevJar();

      // Need to set gwt.devjar property before calling projectCreator and
      // applicationCreator
      System.setProperty("gwt.devjar", gwtDevJar.toString());

      File outDir = new File(outDirPath, projectName);

      IPath startupUrl = new Path(entryPoint + ".html");
      try {
          if (!runtime.containsSCL()) {
              // TODO: Consider using a WebAppProjectCreatorRunner-style solution
              // here.
              URLClassLoader cl = runtime.createClassLoader();
              Class<?> projectCreatorClass = cl.loadClass("com.google.gwt.user.tools.ProjectCreator");
              Method m = projectCreatorClass.getDeclaredMethod("createProject", String.class, String.class,
                      File.class, boolean.class, boolean.class);
              m.setAccessible(true);
              m.invoke(null, projectName, null, outDir, false, false);
              monitor.worked(1);

              Class<?> applicationCreatorClass = cl.loadClass("com.google.gwt.user.tools.ApplicationCreator");
              m = applicationCreatorClass.getDeclaredMethod("createApplication", String.class, File.class,
                      String.class, boolean.class, boolean.class);
              m.setAccessible(true);

              if (!packageName.endsWith("client")) {
                  packageName = packageName + ".client";
              }
              m.invoke(null, packageName + "." + entryPoint, outDir, projectName, false, false);

              startupUrl = new Path(qualifiedModuleName).append(startupUrl);
          } else {
              WebAppProjectCreatorRunner.createProject(qualifiedModuleName, outDir.getAbsolutePath(), runtime,
                      monitor, templateSources, templates);
          }

          reformatJavaFiles(outDir);
          String version = runtime.getVersion();
          if (!SdkUtils.isInternal(version) && SdkUtils.compareVersionStrings(version,
                  WebAppProjectCreatorRunner.GWT_VERSION_WITH_TEMPLATES) <= -1) {
              deleteAllLaunchConfigurations(outDir);
              deleteAllShellScripts(projectName, outDir);
              deleteBuildScript(outDir);
          }
      } catch (NoSuchMethodException e) {
          GdtPlugin.getLogger().logError(e);
          throw new SdkException(
                  "Unable to invoke methods for project creation or application creation. using runtime "
                          + runtime.getName() + " " + e);
      } catch (IllegalAccessException e) {
          throw new SdkException(
                  "Unable to access methods for project creation or application creation. using runtime "
                          + runtime.getName() + " " + e);
      } catch (InvocationTargetException e) {
          // Rethrow exception thrown by creator class
          Throwable cause = e.getCause();
          if (cause != null && cause instanceof Exception) {
              GdtPlugin.getLogger().logError(cause);
          } else {
              GdtPlugin.getLogger().logError(e);
          }

          throw new SdkException(
                  "Exception occured while attempting to create project and application, using runtime  "
                          + runtime.getName() + " " + e);
      }
  }

From source file:com.google.gwt.eclipse.testing.GwtMavenTestingUtilities.java

/**
 * Convert the standard Java project to a Maven project. This will remove the Default GWT sdk and
 * instead use a GWT Maven sdk distribution. Using the Maven classpath container will allow for
 * adding a specific GWT version easily.
 *
 * TODO Embue the WebAppCreator factory or create a Maven web app factory with Maven creation
 * options.//from  w w  w .  j a va 2 s.  c om
 */
public static void createMavenProject(IProject project, String withGwtSdkVersion) throws Exception {
    // Remove the default GWT sdk container from classpath, instead use Maven
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entriesWithGwtContainer = javaProject.getRawClasspath();
    IClasspathEntry[] entriesWithOutGwtContainer = new IClasspathEntry[entriesWithGwtContainer.length - 1];
    int b = 0;
    for (int a = 0; a < entriesWithGwtContainer.length; a++) {
        String path = entriesWithGwtContainer[a].getPath().toString();
        if (!path.contains(GWTRuntimeContainer.CONTAINER_ID)) {
            entriesWithOutGwtContainer[b] = entriesWithGwtContainer[a];
            b++;
        }
    }
    // Removing the GWT SDK classpath entry from project
    javaProject.setRawClasspath(entriesWithOutGwtContainer, new NullProgressMonitor());
    JobsUtilities.waitForIdle();

    // Provide a pom.xml for a bare-bones configuration to convert standard project to Maven nature
    URL url = GwtTestingPlugin.getDefault().getBundle().getResource("resources/pom.xml");
    InputStream pomxmlStream = url.openStream();
    pomxmlStream = changeGwtSdkVersionInPom(pomxmlStream, withGwtSdkVersion);
    ResourceUtils.createFile(project.getFullPath().append("pom.xml"), pomxmlStream);

    // Turn on the Maven nature
    NatureUtils.addNature(project, MAVEN2_NATURE_ID);
    JobsUtilities.waitForIdle();

    // Maven update project will add the Maven dependencies to the classpath
    IProjectConfigurationManager projectConfig = MavenPlugin.getProjectConfigurationManager();
    projectConfig.updateProjectConfiguration(project, new NullProgressMonitor());
    JobsUtilities.waitForIdle();
}