### Eclipse Workspace Patch 1.0 #P org.eclipse.pde.ui Index: src/org/eclipse/pde/internal/ui/wizards/plugin/ClasspathComputer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/ClasspathComputer.java,v retrieving revision 1.15 diff -u -r1.15 ClasspathComputer.java --- src/org/eclipse/pde/internal/ui/wizards/plugin/ClasspathComputer.java 8 Jun 2007 16:37:10 -0000 1.15 +++ src/org/eclipse/pde/internal/ui/wizards/plugin/ClasspathComputer.java 28 Sep 2007 17:06:41 -0000 @@ -59,24 +59,22 @@ } public static IClasspathEntry[] getClasspath(IProject project, IPluginModelBase model, boolean clear) throws CoreException { - + IJavaProject javaProject = JavaCore.create(project); ArrayList result = new ArrayList(); - IBuild build = getBuild(project); // add own libraries/source addSourceAndLibraries(project, model, build, clear, result); - + // add JRE and set compliance options String ee = getExecutionEnvironment(model.getBundleDescription()); - result.add(createJREEntry(ee)); + result.add(createJREEntryUsingPreviousEntry(javaProject, ee)); setComplianceOptions(JavaCore.create(project), ExecutionEnvironmentAnalyzer.getCompliance(ee)); // add pde container result.add(createContainerEntry()); IClasspathEntry[] entries = (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); - IJavaProject javaProject = JavaCore.create(project); IJavaModelStatus validation = JavaConventions.validateClasspath( javaProject, @@ -295,8 +293,46 @@ } } + /** + * Returns a new classpath container entry for the given execution environment. If the given java project + * has an existing JRE/EE classpath entry, the access rules, extra attributes and isExported settings of + * the existing entry will be added to the new execution entry. + * + * @param javaProject project to check for existing JRE/EE classpath entries + * @param ee id of the execution environment to create an entry for + * @return new classpath container entry + * @throws CoreException if there is a problem accessing the classpath entries of the project + */ + public static IClasspathEntry createJREEntryUsingPreviousEntry(IJavaProject javaProject, String ee) throws CoreException { + IClasspathEntry existingEntry = null; + IClasspathEntry[] entries = javaProject.getRawClasspath(); + for (int i = 0; i < entries.length; i++) { + if (entries[i].getPath().segment(0).equals(JavaRuntime.JRE_CONTAINER)){ + existingEntry = entries[i]; + break; + } + } + if (existingEntry == null){ + return createJREEntry(ee); + } + return JavaCore.newContainerEntry(getEEPath(ee), existingEntry.getAccessRules(), existingEntry.getExtraAttributes(), existingEntry.isExported()); + } + /** + * Returns a classpath container entry for the given execution environment. + * @param ee id of the execution environment + * @return classpath container entry + */ public static IClasspathEntry createJREEntry(String ee) { + return JavaCore.newContainerEntry(getEEPath(ee)); + } + + /** + * Returns the JRE container path for the execution environment with the given id. + * @param ee execution environment id + * @return JRE container path for the execution environment + */ + private static IPath getEEPath(String ee){ IPath path = null; if (ee != null) { IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); @@ -304,11 +340,15 @@ if (env != null) path = JavaRuntime.newJREContainerPath(env); } - if (path == null) + if (path == null){ path = JavaRuntime.newDefaultJREContainerPath(); - return JavaCore.newContainerEntry(path); + } + return path; } + /** + * @return a new classpath container entry for a required plugin container + */ public static IClasspathEntry createContainerEntry() { return JavaCore.newContainerEntry(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH); }