Ejemplo n.º 1
0
  public static void addServletLibToWebInf(IProject project, IProgressMonitor monitor) {

    monitor = Util.getNonNullMonitor(monitor);

    try {
      monitor.beginTask("", 1);

      IJavaProject javaProject = JavaCore.create(project);
      IClasspathEntry[] oldClasspath = javaProject.getRawClasspath();
      IClasspathEntry[] newClasspath = new IClasspathEntry[oldClasspath.length + 1];
      System.arraycopy(oldClasspath, 0, newClasspath, 0, oldClasspath.length);
      IClasspathEntry gwtServletJarEntry =
          JavaCore.newVariableEntry(Util.getGwtServletLibPath(), null, null);
      IClasspathAttribute attr =
          JavaCore.newClasspathAttribute("org.eclipse.jst.component.dependency", "/WEB-INF/lib");
      gwtServletJarEntry =
          JavaCore.newVariableEntry(
              gwtServletJarEntry.getPath(),
              null,
              null,
              new IAccessRule[0],
              new IClasspathAttribute[] {attr},
              false);
      newClasspath[oldClasspath.length] = gwtServletJarEntry;
      javaProject.setRawClasspath(newClasspath, monitor);

    } catch (JavaModelException e) {
      // the jar is already in the classpath.
      Activator.logException(e);
    } finally {
      monitor.done();
    }
  }
Ejemplo n.º 2
0
  public static void addUserLibToClassPath(IProject project, IProgressMonitor monitor) {

    monitor = Util.getNonNullMonitor(monitor);
    try {

      IJavaProject javaProject = JavaCore.create(project);
      IClasspathEntry[] oldClasspath = javaProject.getRawClasspath();
      IClasspathEntry[] newClasspath = new IClasspathEntry[oldClasspath.length + 1];
      System.arraycopy(oldClasspath, 0, newClasspath, 0, oldClasspath.length);
      IClasspathEntry gwtuserJarEntry =
          JavaCore.newVariableEntry(Util.getGwtUserLibPath(), null, null);
      gwtuserJarEntry =
          JavaCore.newVariableEntry(
              gwtuserJarEntry.getPath(),
              null,
              null,
              new IAccessRule[0],
              new IClasspathAttribute[0],
              false);
      newClasspath[oldClasspath.length] = gwtuserJarEntry;
      javaProject.setRawClasspath(newClasspath, monitor);

    } catch (CoreException e) {
      // the jar is already in the classpath.
      Activator.logException(e);
    } finally {
      monitor.done();
    }
  }
Ejemplo n.º 3
0
  public void execute(
      IProject project, IProjectFacetVersion facetVersion, Object config, IProgressMonitor monitor)
      throws CoreException {

    monitor = Util.getNonNullMonitor(monitor);

    try {

      monitor.beginTask("", 3);

      addNature(project, new SubProgressMonitor(monitor, 1));
      addUserLibToClassPath(project, new SubProgressMonitor(monitor, 1));
      addServletLibToWebInf(project, new SubProgressMonitor(monitor, 1));

    } catch (CoreException e) {
      monitor.setCanceled(true);
      Activator.logException(e);
    } finally {
      monitor.done();
    }
  }
Ejemplo n.º 4
0
  private void addNature(IProject project, IProgressMonitor monitor) throws CoreException {

    monitor = Util.getNonNullMonitor(monitor);

    try {

      monitor.beginTask("", 1);

      IProjectDescription description = project.getDescription();
      String[] prevNatures = description.getNatureIds();
      String[] newNatures = new String[prevNatures.length + 1];
      System.arraycopy(prevNatures, 0, newNatures, 1, prevNatures.length);
      newNatures[0] = Constants.NATURE_ID;
      description.setNatureIds(newNatures);

      project.setDescription(description, IResource.FORCE, null);

    } finally {
      monitor.done();
    }
  }