private static List<String> appendLaunchClasspath(
     List<String> l,
     String projectName,
     ILaunchConfiguration config,
     IClasspathEntry[] adding,
     IJavaProject jp,
     int high) {
   initJefHome();
   Set<IClasspathEntry> set = new HashSet<IClasspathEntry>();
   try {
     if (l == null) {
       l = new ArrayList<String>();
       l.add(JavaRuntime.computeJREEntry(jp).getMemento());
       l.add(
           String.format(
               "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n<runtimeClasspathEntry id=\"org.eclipse.jdt.launching.classpathentry.defaultClasspath\">\r\n<memento exportedEntriesOnly=\"false\" project=\"%s\"/></runtimeClasspathEntry>\r\n",
               projectName));
     } else {
       for (String s : l) {
         Document doc = XMLUtils.loadDocumentByString(s);
         if (doc.getDocumentElement().hasAttribute("type")) {
           IRuntimeClasspathEntry rcp =
               new org.eclipse.jdt.internal.launching.RuntimeClasspathEntry(
                   doc.getDocumentElement());
           set.add(rcp.getClasspathEntry());
         }
       }
     }
     int i = 0;
     for (IClasspathEntry cp : adding) {
       if (!set.contains(cp)) {
         IRuntimeClasspathEntry rcp =
             new org.eclipse.jdt.internal.launching.RuntimeClasspathEntry(cp);
         if (i < high) {
           rcp.setClasspathProperty(2);
         } else {
           rcp.setClasspathProperty(3);
         }
         l.add(rcp.getMemento());
         set.add(cp);
         i++;
       }
     }
   } catch (CoreException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (SAXException e) {
     e.printStackTrace();
   }
   return l;
 }
  private void addJreClasspath() {
    try {
      IRuntimeClasspathEntry computeJREEntry = JavaRuntime.computeJREEntry(javaProject);
      if (computeJREEntry == null) {
        return;
      }

      IRuntimeClasspathEntry[] jreEntries =
          JavaRuntime.resolveRuntimeClasspathEntry(computeJREEntry, javaProject);

      if (jreEntries.length != 0) {
        for (IRuntimeClasspathEntry jreEntry : jreEntries) {
          addToClasspath(jreEntry.getClasspathEntry().getPath().toFile());
        }

        return;
      }
    } catch (JavaModelException e) {
      KotlinLogger.logAndThrow(e);
    } catch (CoreException e) {
      KotlinLogger.logAndThrow(e);
    }
  }
  protected void computeRuntimeClassPath() throws CoreException {
    runtimeDependencies = new ArrayList<String>();

    IRuntimeClasspathEntry[] unresolved =
        JavaRuntime.computeUnresolvedRuntimeClasspath(javaProject);
    IRuntimeClasspathEntry jreEntry = JavaRuntime.computeJREEntry(javaProject);
    List<IRuntimeClasspathEntry> resolved = new ArrayList<IRuntimeClasspathEntry>();

    // Resolve all runtime entries, and skip the jre entry
    for (IRuntimeClasspathEntry rcEntry : unresolved) {

      if (rcEntry.equals(jreEntry)) {
        continue;
      } else {
        IRuntimeClasspathEntry[] entries =
            JavaRuntime.resolveRuntimeClasspathEntry(rcEntry, javaProject);

        if (entries != null) {
          resolved.addAll(Arrays.asList(entries));
        }
      }
    }

    // Separate dependency entries like archives from other runtime entries
    List<IRuntimeClasspathEntry> toSeparate = new ArrayList<IRuntimeClasspathEntry>(resolved);

    for (IRuntimeClasspathEntry entry : resolved) {

      String entryLocation = entry.getLocation();
      if (isAccessibleFile(entryLocation)) {
        toSeparate.remove(entry);
        runtimeDependencies.add(entry.getLocation());
      }
    }
    resolved = toSeparate;

    if (shouldSkipTestSources()) {
      // The special case to consider is if both the test source and non
      // test source have the same output location
      // if that is the case, the runtime entry associated with that
      // output location CANNOT be skipped. The only time
      // the test source entry can be skipped is if the output location
      // for that entry is NOT also used by a non test source entry
      Collection<String> testSourceOutputLocations = getTestSourceOutputLocations();
      Collection<String> nonTestSourceOutputLocations = getNonTestSourceOutputLocations();
      List<IRuntimeClasspathEntry> nonTestEntries = new ArrayList<IRuntimeClasspathEntry>(resolved);
      for (IRuntimeClasspathEntry entry : resolved) {

        String entryLocation = entry.getLocation();
        if (testSourceOutputLocations.contains(entryLocation)
            && !nonTestSourceOutputLocations.contains(entryLocation)) {
          nonTestEntries.remove(entry);
        }
      }
      resolved = nonTestEntries;
    }

    Set<String> resolvedEntryLocations = new HashSet<String>(resolved.size());
    for (IRuntimeClasspathEntry entry : resolved) {
      resolvedEntryLocations.add(entry.getLocation());
    }

    runtimeSource = new ArrayList<String>(resolvedEntryLocations);
  }
예제 #4
0
  /**
   * Creates a classpath to be added to a a launch configuration for running the Jetty server. The
   * appropriate Jetty, servlet, and EDT plug-ins will be added to the classpath, as well as
   * ensuring any Java projects on the EGL build path are included in the classpath if they aren't
   * already. Finally, classpath contributions from {@link
   * AbstractTestServerContribution#getClasspathAdditions(TestServerConfiguration)} will be appended
   * at the end, so long as the contributions are valid.
   *
   * @param config The test server configuration.
   * @param classpath A list that will receive the new entries.
   * @throws CoreException
   */
  public static void buildClasspath(TestServerConfiguration config, List<String> classpath)
      throws CoreException {
    IProject project = config.getProject();
    String entry;

    // The project's JRE (not required for execution, but required for source lookup).
    try {
      IRuntimeClasspathEntry jreEntry = JavaRuntime.computeJREEntry(JavaCore.create(project));
      if (jreEntry != null) {
        classpath.add(jreEntry.getMemento());
      }
    } catch (CoreException ce) {
      TestServerPlugin.getDefault().log(ce);
    }

    if (testServerBaseEntries == null) {
      testServerBaseEntries = new ArrayList<String>(20);

      // Add all org.eclipse.jetty.* plug-ins.
      Bundle[] bundles = TestServerPlugin.getDefault().getBundle().getBundleContext().getBundles();
      for (Bundle bundle : bundles) {
        if (bundle.getSymbolicName().startsWith("org.eclipse.jetty.")) { // $NON-NLS-1$
          entry = getClasspathEntry(bundle);
          if (entry != null) {
            testServerBaseEntries.add(entry);
          }
        }
      }

      entry = getClasspathEntry("javax.servlet"); // $NON-NLS-1$
      if (entry != null) {
        testServerBaseEntries.add(entry);
      }

      entry = getClasspathEntry("org.eclipse.edt.ide.testserver"); // $NON-NLS-1$
      if (entry != null) {
        testServerBaseEntries.add(entry);
      }
    }

    classpath.addAll(testServerBaseEntries);

    // The main project.
    classpath.add(getWorkspaceProjectClasspathEntry(project.getName()));

    // Add any contributed classpath entries.
    for (AbstractTestServerContribution contrib : TestServerPlugin.getContributions()) {
      String[] extraClasspath = contrib.getClasspathAdditions(config);
      if (extraClasspath != null && extraClasspath.length > 0) {
        for (String next : extraClasspath) {
          if (!classpath.contains(next)) {
            // Validate the entry; bad entries will prevent the process from launching.
            if (classpathEntryIsValid(next, project)) {
              classpath.add(next);
            } else {
              TestServerPlugin.getDefault()
                  .logWarning(NLS.bind(TestServerMessages.InvalidClasspathEntry, next));
            }
          }
        }
      }
    }
  }