### Eclipse Workspace Patch 1.0 #P org.eclipse.pde.core Index: src/org/eclipse/pde/internal/core/ClasspathComputer.java =================================================================== RCS file: src/org/eclipse/pde/internal/core/ClasspathComputer.java diff -N src/org/eclipse/pde/internal/core/ClasspathComputer.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/internal/core/ClasspathComputer.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,339 @@ +/******************************************************************************* + * Copyright (c) 2005, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.core; + +import java.util.*; +import org.eclipse.core.resources.*; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.*; +import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.jdt.launching.environments.IExecutionEnvironment; +import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; +import org.eclipse.osgi.service.resolver.BundleDescription; +import org.eclipse.pde.core.build.*; +import org.eclipse.pde.core.plugin.IPluginLibrary; +import org.eclipse.pde.core.plugin.IPluginModelBase; +import org.eclipse.pde.internal.core.build.WorkspaceBuildModel; +import org.eclipse.pde.internal.core.util.CoreUtility; +import org.eclipse.team.core.RepositoryProvider; + +public class ClasspathComputer { + + private static Hashtable fSeverityTable = null; + private static final int SEVERITY_ERROR = 3; + private static final int SEVERITY_WARNING = 2; + private static final int SEVERITY_IGNORE = 1; + + public static void setClasspath(IProject project, IPluginModelBase model) throws CoreException { + IClasspathEntry[] entries = getClasspath(project, model, false); + JavaCore.create(project).setRawClasspath(entries, null); + } + + 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 JRE and set compliance options + String ee = getExecutionEnvironment(model.getBundleDescription()); + result.add(createEntryUsingPreviousEntry(javaProject, ee, PDECore.JRE_CONTAINER_PATH)); + setComplianceOptions(JavaCore.create(project), ExecutionEnvironmentAnalyzer.getCompliance(ee)); + + // add pde container + result.add(createEntryUsingPreviousEntry(javaProject, ee, PDECore.REQUIRED_PLUGINS_CONTAINER_PATH)); + + // add own libraries/source + addSourceAndLibraries(project, model, build, clear, result); + + IClasspathEntry[] entries = (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); + IJavaModelStatus validation = JavaConventions.validateClasspath(javaProject, entries, javaProject.getOutputLocation()); + if (!validation.isOK()) { + PDECore.logErrorMessage(validation.getMessage()); + throw new CoreException(validation); + } + return (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); + } + + public static void addSourceAndLibraries(IProject project, IPluginModelBase model, IBuild build, boolean clear, ArrayList result) throws CoreException { + + HashSet paths = new HashSet(); + + // keep existing source folders + if (!clear) { + IClasspathEntry[] entries = JavaCore.create(project).getRawClasspath(); + for (int i = 0; i < entries.length; i++) { + IClasspathEntry entry = entries[i]; + if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { + if (paths.add(entry.getPath())) + result.add(entry); + } + } + } + + IClasspathAttribute[] attrs = getClasspathAttributes(project, model); + IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); + for (int i = 0; i < libraries.length; i++) { + IBuildEntry buildEntry = build == null ? null : build.getEntry("source." + libraries[i].getName()); //$NON-NLS-1$ + if (buildEntry != null) { + addSourceFolder(buildEntry, project, paths, result); + } else { + if (libraries[i].getName().equals(".")) //$NON-NLS-1$ + addJARdPlugin(project, ClasspathUtilCore.getFilename(model), attrs, result); + else + addLibraryEntry(project, libraries[i], attrs, result); + } + } + if (libraries.length == 0) { + if (build != null) { + IBuildEntry buildEntry = build == null ? null : build.getEntry("source.."); //$NON-NLS-1$ + if (buildEntry != null) { + addSourceFolder(buildEntry, project, paths, result); + } + } else if (ClasspathUtilCore.hasBundleStructure(model)) { + addJARdPlugin(project, ClasspathUtilCore.getFilename(model), attrs, result); + } + } + } + + private static IClasspathAttribute[] getClasspathAttributes(IProject project, IPluginModelBase model) { + IClasspathAttribute[] attributes = new IClasspathAttribute[0]; + if (!RepositoryProvider.isShared(project)) { + JavadocLocationManager manager = PDECore.getDefault().getJavadocLocationManager(); + String javadoc = manager.getJavadocLocation(model); + if (javadoc != null) { + attributes = new IClasspathAttribute[] {JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadoc)}; + } + } + return attributes; + } + + private static void addSourceFolder(IBuildEntry buildEntry, IProject project, HashSet paths, ArrayList result) throws CoreException { + String[] folders = buildEntry.getTokens(); + for (int j = 0; j < folders.length; j++) { + String folder = folders[j]; + IPath path = project.getFullPath().append(folder); + if (paths.add(path)) { + if (project.findMember(folder) == null) { + CoreUtility.createFolder(project.getFolder(folder)); + } else { + IPackageFragmentRoot root = JavaCore.create(project).getPackageFragmentRoot(path.toString()); + if (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY) { + result.add(root.getRawClasspathEntry()); + continue; + } + } + result.add(JavaCore.newSourceEntry(path)); + } + } + } + + protected static IBuild getBuild(IProject project) throws CoreException { + IFile buildFile = project.getFile("build.properties"); //$NON-NLS-1$ + IBuildModel buildModel = null; + if (buildFile.exists()) { + buildModel = new WorkspaceBuildModel(buildFile); + buildModel.load(); + } + return (buildModel != null) ? buildModel.getBuild() : null; + } + + private static void addLibraryEntry(IProject project, IPluginLibrary library, IClasspathAttribute[] attrs, ArrayList result) throws JavaModelException { + String name = ClasspathUtilCore.expandLibraryName(library.getName()); + IResource jarFile = project.findMember(name); + if (jarFile == null) + return; + + IPackageFragmentRoot root = JavaCore.create(project).getPackageFragmentRoot(jarFile); + if (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY) { + IClasspathEntry oldEntry = root.getRawClasspathEntry(); + if (oldEntry.getSourceAttachmentPath() != null && !result.contains(oldEntry)) { + result.add(oldEntry); + return; + } + } + + IClasspathEntry entry = createClasspathEntry(project, jarFile, name, attrs, library.isExported()); + if (!result.contains(entry)) + result.add(entry); + } + + private static void addJARdPlugin(IProject project, String filename, IClasspathAttribute[] attrs, ArrayList result) { + String name = ClasspathUtilCore.expandLibraryName(filename); + IResource jarFile = project.findMember(name); + if (jarFile != null) { + IClasspathEntry entry = createClasspathEntry(project, jarFile, filename, attrs, true); + if (!result.contains(entry)) + result.add(entry); + } + } + + private static IClasspathEntry createClasspathEntry(IProject project, IResource library, String fileName, IClasspathAttribute[] attrs, boolean isExported) { + String sourceZipName = ClasspathUtilCore.getSourceZipName(fileName); + IResource resource = project.findMember(sourceZipName); + // if zip file does not exist, see if a directory with the source does. This in necessary how we import source for individual source bundles. + if (resource == null && sourceZipName.endsWith(".zip")) { //$NON-NLS-1$ + resource = project.findMember(sourceZipName.substring(0, sourceZipName.length() - 4)); + if (resource == null) + // if we can't find the the source for a library, then try to find the common source location set up to share source from one jar to all libraries. + // see PluginImportOperation.linkSourceArchives + resource = project.getFile(project.getName() + "src.zip"); //$NON-NLS-1$ + } + IPath srcAttachment = resource != null ? resource.getFullPath() : library.getFullPath(); + return JavaCore.newLibraryEntry(library.getFullPath(), srcAttachment, null, new IAccessRule[0], attrs, isExported); + } + + private static String getExecutionEnvironment(BundleDescription bundleDescription) { + if (bundleDescription != null) { + String[] envs = bundleDescription.getExecutionEnvironments(); + if (envs.length > 0) + return envs[0]; + } + return null; + } + + public static void setComplianceOptions(IJavaProject project, String compliance) { + Map map = project.getOptions(false); + if (compliance == null) { + if (map.size() > 0) { + map.remove(JavaCore.COMPILER_COMPLIANCE); + map.remove(JavaCore.COMPILER_SOURCE); + map.remove(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM); + map.remove(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER); + map.remove(JavaCore.COMPILER_PB_ENUM_IDENTIFIER); + } else { + return; + } + } else if (JavaCore.VERSION_1_6.equals(compliance)) { + map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6); + map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6); + map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6); + map.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); + map.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); + } else if (JavaCore.VERSION_1_5.equals(compliance)) { + map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + map.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); + map.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); + } else if (JavaCore.VERSION_1_4.equals(compliance)) { + map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + updateSeverityComplianceOption(map, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.WARNING); + updateSeverityComplianceOption(map, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.WARNING); + } else if (JavaCore.VERSION_1_3.equals(compliance)) { + map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_3); + map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_1); + updateSeverityComplianceOption(map, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.IGNORE); + updateSeverityComplianceOption(map, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.IGNORE); + } + project.setOptions(map); + } + + private static void updateSeverityComplianceOption(Map map, String key, String value) { + Integer current_value = null; + Integer new_value = null; + String current_string_value = null; + int current_int_value = 0; + int new_int_value = 0; + // Initialize the severity table (only once) + if (fSeverityTable == null) { + fSeverityTable = new Hashtable(SEVERITY_ERROR); + fSeverityTable.put(JavaCore.IGNORE, new Integer(SEVERITY_IGNORE)); + fSeverityTable.put(JavaCore.WARNING, new Integer(SEVERITY_WARNING)); + fSeverityTable.put(JavaCore.ERROR, new Integer(SEVERITY_ERROR)); + } + // Get the current severity + current_string_value = (String) map.get(key); + if (current_string_value != null) { + current_value = (Integer) fSeverityTable.get(current_string_value); + if (current_value != null) { + current_int_value = current_value.intValue(); + } + } + // Get the new severity + new_value = (Integer) fSeverityTable.get(value); + if (new_value != null) { + new_int_value = new_value.intValue(); + } + // If the current severity is not higher than the new severity, replace it + if (new_int_value > current_int_value) { + map.put(key, value); + } + } + + /** + * 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 classpath entries + * @param ee id of the execution environment to create an entry for + * @param path id of the container 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 createEntryUsingPreviousEntry(IJavaProject javaProject, String ee, IPath path) throws CoreException { + IClasspathEntry[] entries = javaProject.getRawClasspath(); + for (int i = 0; i < entries.length; i++) { + if (entries[i].getPath().equals(path)) { + if (path.equals(PDECore.JRE_CONTAINER_PATH)) + return JavaCore.newContainerEntry(getEEPath(ee), entries[i].getAccessRules(), entries[i].getExtraAttributes(), entries[i].isExported()); + + return JavaCore.newContainerEntry(path, entries[i].getAccessRules(), entries[i].getExtraAttributes(), entries[i].isExported()); + } + } + + if (path.equals(PDECore.JRE_CONTAINER_PATH)) + return createJREEntry(ee); + + return JavaCore.newContainerEntry(path); + } + + /** + * 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(); + IExecutionEnvironment env = manager.getEnvironment(ee); + if (env != null) + path = JavaRuntime.newJREContainerPath(env); + } + if (path == null) { + path = JavaRuntime.newDefaultJREContainerPath(); + } + 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); + } + +} #P org.eclipse.pde.ui Index: src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java,v retrieving revision 1.21 diff -u -r1.21 ExecutionEnvironmentSection.java --- src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java 16 Jan 2008 17:07:47 -0000 1.21 +++ src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java 26 Feb 2008 20:42:12 -0000 @@ -24,6 +24,7 @@ import org.eclipse.pde.core.IModelChangedEvent; import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.PluginRegistry; +import org.eclipse.pde.internal.core.ClasspathComputer; import org.eclipse.pde.internal.core.ibundle.*; import org.eclipse.pde.internal.core.text.bundle.*; import org.eclipse.pde.internal.ui.*; @@ -33,7 +34,6 @@ import org.eclipse.pde.internal.ui.parts.EditableTablePart; import org.eclipse.pde.internal.ui.parts.TablePart; import org.eclipse.pde.internal.ui.preferences.PDEPreferencesUtil; -import org.eclipse.pde.internal.ui.wizards.plugin.ClasspathComputer; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; Index: src/org/eclipse/pde/internal/ui/wizards/plugin/ClasspathComputer.java =================================================================== RCS file: src/org/eclipse/pde/internal/ui/wizards/plugin/ClasspathComputer.java diff -N src/org/eclipse/pde/internal/ui/wizards/plugin/ClasspathComputer.java --- src/org/eclipse/pde/internal/ui/wizards/plugin/ClasspathComputer.java 11 Feb 2008 16:12:33 -0000 1.21 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,340 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.internal.ui.wizards.plugin; - -import java.util.*; -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jdt.core.*; -import org.eclipse.jdt.launching.JavaRuntime; -import org.eclipse.jdt.launching.environments.IExecutionEnvironment; -import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; -import org.eclipse.osgi.service.resolver.BundleDescription; -import org.eclipse.pde.core.build.*; -import org.eclipse.pde.core.plugin.IPluginLibrary; -import org.eclipse.pde.core.plugin.IPluginModelBase; -import org.eclipse.pde.internal.core.*; -import org.eclipse.pde.internal.core.build.WorkspaceBuildModel; -import org.eclipse.pde.internal.core.util.CoreUtility; -import org.eclipse.team.core.RepositoryProvider; - -public class ClasspathComputer { - - private static Hashtable fSeverityTable = null; - private static final int SEVERITY_ERROR = 3; - private static final int SEVERITY_WARNING = 2; - private static final int SEVERITY_IGNORE = 1; - - public static void setClasspath(IProject project, IPluginModelBase model) throws CoreException { - IClasspathEntry[] entries = getClasspath(project, model, false); - JavaCore.create(project).setRawClasspath(entries, null); - } - - 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 JRE and set compliance options - String ee = getExecutionEnvironment(model.getBundleDescription()); - result.add(createEntryUsingPreviousEntry(javaProject, ee, PDECore.JRE_CONTAINER_PATH)); - setComplianceOptions(JavaCore.create(project), ExecutionEnvironmentAnalyzer.getCompliance(ee)); - - // add pde container - result.add(createEntryUsingPreviousEntry(javaProject, ee, PDECore.REQUIRED_PLUGINS_CONTAINER_PATH)); - - // add own libraries/source - addSourceAndLibraries(project, model, build, clear, result); - - IClasspathEntry[] entries = (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); - IJavaModelStatus validation = JavaConventions.validateClasspath(javaProject, entries, javaProject.getOutputLocation()); - if (!validation.isOK()) { - PDECore.logErrorMessage(validation.getMessage()); - throw new CoreException(validation); - } - return (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); - } - - public static void addSourceAndLibraries(IProject project, IPluginModelBase model, IBuild build, boolean clear, ArrayList result) throws CoreException { - - HashSet paths = new HashSet(); - - // keep existing source folders - if (!clear) { - IClasspathEntry[] entries = JavaCore.create(project).getRawClasspath(); - for (int i = 0; i < entries.length; i++) { - IClasspathEntry entry = entries[i]; - if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { - if (paths.add(entry.getPath())) - result.add(entry); - } - } - } - - IClasspathAttribute[] attrs = getClasspathAttributes(project, model); - IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); - for (int i = 0; i < libraries.length; i++) { - IBuildEntry buildEntry = build == null ? null : build.getEntry("source." + libraries[i].getName()); //$NON-NLS-1$ - if (buildEntry != null) { - addSourceFolder(buildEntry, project, paths, result); - } else { - if (libraries[i].getName().equals(".")) //$NON-NLS-1$ - addJARdPlugin(project, ClasspathUtilCore.getFilename(model), attrs, result); - else - addLibraryEntry(project, libraries[i], attrs, result); - } - } - if (libraries.length == 0) { - if (build != null) { - IBuildEntry buildEntry = build == null ? null : build.getEntry("source.."); //$NON-NLS-1$ - if (buildEntry != null) { - addSourceFolder(buildEntry, project, paths, result); - } - } else if (ClasspathUtilCore.hasBundleStructure(model)) { - addJARdPlugin(project, ClasspathUtilCore.getFilename(model), attrs, result); - } - } - } - - private static IClasspathAttribute[] getClasspathAttributes(IProject project, IPluginModelBase model) { - IClasspathAttribute[] attributes = new IClasspathAttribute[0]; - if (!RepositoryProvider.isShared(project)) { - JavadocLocationManager manager = PDECore.getDefault().getJavadocLocationManager(); - String javadoc = manager.getJavadocLocation(model); - if (javadoc != null) { - attributes = new IClasspathAttribute[] {JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadoc)}; - } - } - return attributes; - } - - private static void addSourceFolder(IBuildEntry buildEntry, IProject project, HashSet paths, ArrayList result) throws CoreException { - String[] folders = buildEntry.getTokens(); - for (int j = 0; j < folders.length; j++) { - String folder = folders[j]; - IPath path = project.getFullPath().append(folder); - if (paths.add(path)) { - if (project.findMember(folder) == null) { - CoreUtility.createFolder(project.getFolder(folder)); - } else { - IPackageFragmentRoot root = JavaCore.create(project).getPackageFragmentRoot(path.toString()); - if (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY) { - result.add(root.getRawClasspathEntry()); - continue; - } - } - result.add(JavaCore.newSourceEntry(path)); - } - } - } - - protected static IBuild getBuild(IProject project) throws CoreException { - IFile buildFile = project.getFile("build.properties"); //$NON-NLS-1$ - IBuildModel buildModel = null; - if (buildFile.exists()) { - buildModel = new WorkspaceBuildModel(buildFile); - buildModel.load(); - } - return (buildModel != null) ? buildModel.getBuild() : null; - } - - private static void addLibraryEntry(IProject project, IPluginLibrary library, IClasspathAttribute[] attrs, ArrayList result) throws JavaModelException { - String name = ClasspathUtilCore.expandLibraryName(library.getName()); - IResource jarFile = project.findMember(name); - if (jarFile == null) - return; - - IPackageFragmentRoot root = JavaCore.create(project).getPackageFragmentRoot(jarFile); - if (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY) { - IClasspathEntry oldEntry = root.getRawClasspathEntry(); - if (oldEntry.getSourceAttachmentPath() != null && !result.contains(oldEntry)) { - result.add(oldEntry); - return; - } - } - - IClasspathEntry entry = createClasspathEntry(project, jarFile, name, attrs, library.isExported()); - if (!result.contains(entry)) - result.add(entry); - } - - private static void addJARdPlugin(IProject project, String filename, IClasspathAttribute[] attrs, ArrayList result) { - String name = ClasspathUtilCore.expandLibraryName(filename); - IResource jarFile = project.findMember(name); - if (jarFile != null) { - IClasspathEntry entry = createClasspathEntry(project, jarFile, filename, attrs, true); - if (!result.contains(entry)) - result.add(entry); - } - } - - private static IClasspathEntry createClasspathEntry(IProject project, IResource library, String fileName, IClasspathAttribute[] attrs, boolean isExported) { - String sourceZipName = ClasspathUtilCore.getSourceZipName(fileName); - IResource resource = project.findMember(sourceZipName); - // if zip file does not exist, see if a directory with the source does. This in necessary how we import source for individual source bundles. - if (resource == null && sourceZipName.endsWith(".zip")) { //$NON-NLS-1$ - resource = project.findMember(sourceZipName.substring(0, sourceZipName.length() - 4)); - if (resource == null) - // if we can't find the the source for a library, then try to find the common source location set up to share source from one jar to all libraries. - // see PluginImportOperation.linkSourceArchives - resource = project.getFile(project.getName() + "src.zip"); //$NON-NLS-1$ - } - IPath srcAttachment = resource != null ? resource.getFullPath() : library.getFullPath(); - return JavaCore.newLibraryEntry(library.getFullPath(), srcAttachment, null, new IAccessRule[0], attrs, isExported); - } - - private static String getExecutionEnvironment(BundleDescription bundleDescription) { - if (bundleDescription != null) { - String[] envs = bundleDescription.getExecutionEnvironments(); - if (envs.length > 0) - return envs[0]; - } - return null; - } - - public static void setComplianceOptions(IJavaProject project, String compliance) { - Map map = project.getOptions(false); - if (compliance == null) { - if (map.size() > 0) { - map.remove(JavaCore.COMPILER_COMPLIANCE); - map.remove(JavaCore.COMPILER_SOURCE); - map.remove(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM); - map.remove(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER); - map.remove(JavaCore.COMPILER_PB_ENUM_IDENTIFIER); - } else { - return; - } - } else if (JavaCore.VERSION_1_6.equals(compliance)) { - map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6); - map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6); - map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6); - map.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); - map.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); - } else if (JavaCore.VERSION_1_5.equals(compliance)) { - map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); - map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); - map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); - map.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); - map.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); - } else if (JavaCore.VERSION_1_4.equals(compliance)) { - map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); - map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); - map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); - updateSeverityComplianceOption(map, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.WARNING); - updateSeverityComplianceOption(map, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.WARNING); - } else if (JavaCore.VERSION_1_3.equals(compliance)) { - map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_3); - map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); - map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_1); - updateSeverityComplianceOption(map, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.IGNORE); - updateSeverityComplianceOption(map, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.IGNORE); - } - project.setOptions(map); - } - - private static void updateSeverityComplianceOption(Map map, String key, String value) { - Integer current_value = null; - Integer new_value = null; - String current_string_value = null; - int current_int_value = 0; - int new_int_value = 0; - // Initialize the severity table (only once) - if (fSeverityTable == null) { - fSeverityTable = new Hashtable(SEVERITY_ERROR); - fSeverityTable.put(JavaCore.IGNORE, new Integer(SEVERITY_IGNORE)); - fSeverityTable.put(JavaCore.WARNING, new Integer(SEVERITY_WARNING)); - fSeverityTable.put(JavaCore.ERROR, new Integer(SEVERITY_ERROR)); - } - // Get the current severity - current_string_value = (String) map.get(key); - if (current_string_value != null) { - current_value = (Integer) fSeverityTable.get(current_string_value); - if (current_value != null) { - current_int_value = current_value.intValue(); - } - } - // Get the new severity - new_value = (Integer) fSeverityTable.get(value); - if (new_value != null) { - new_int_value = new_value.intValue(); - } - // If the current severity is not higher than the new severity, replace it - if (new_int_value > current_int_value) { - map.put(key, value); - } - } - - /** - * 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 classpath entries - * @param ee id of the execution environment to create an entry for - * @param path id of the container 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 createEntryUsingPreviousEntry(IJavaProject javaProject, String ee, IPath path) throws CoreException { - IClasspathEntry[] entries = javaProject.getRawClasspath(); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getPath().equals(path)) { - if (path.equals(PDECore.JRE_CONTAINER_PATH)) - return JavaCore.newContainerEntry(getEEPath(ee), entries[i].getAccessRules(), entries[i].getExtraAttributes(), entries[i].isExported()); - - return JavaCore.newContainerEntry(path, entries[i].getAccessRules(), entries[i].getExtraAttributes(), entries[i].isExported()); - } - } - - if (path.equals(PDECore.JRE_CONTAINER_PATH)) - return createJREEntry(ee); - - return JavaCore.newContainerEntry(path); - } - - /** - * 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(); - IExecutionEnvironment env = manager.getEnvironment(ee); - if (env != null) - path = JavaRuntime.newJREContainerPath(env); - } - if (path == null) { - path = JavaRuntime.newDefaultJREContainerPath(); - } - 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); - } - -} Index: src/org/eclipse/pde/internal/ui/wizards/tools/UpdateClasspathJob.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/UpdateClasspathJob.java,v retrieving revision 1.14 diff -u -r1.14 UpdateClasspathJob.java --- src/org/eclipse/pde/internal/ui/wizards/tools/UpdateClasspathJob.java 16 Jan 2008 17:08:24 -0000 1.14 +++ src/org/eclipse/pde/internal/ui/wizards/tools/UpdateClasspathJob.java 26 Feb 2008 20:42:13 -0000 @@ -15,9 +15,9 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jdt.core.JavaCore; import org.eclipse.pde.core.plugin.IPluginModelBase; +import org.eclipse.pde.internal.core.ClasspathComputer; import org.eclipse.pde.internal.core.builders.PDEMarkerFactory; import org.eclipse.pde.internal.ui.*; -import org.eclipse.pde.internal.ui.wizards.plugin.ClasspathComputer; public class UpdateClasspathJob extends Job { IPluginModelBase[] fModels; Index: src/org/eclipse/pde/internal/ui/wizards/tools/ConvertProjectToPluginOperation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/ConvertProjectToPluginOperation.java,v retrieving revision 1.2 diff -u -r1.2 ConvertProjectToPluginOperation.java --- src/org/eclipse/pde/internal/ui/wizards/tools/ConvertProjectToPluginOperation.java 16 Jan 2008 17:08:24 -0000 1.2 +++ src/org/eclipse/pde/internal/ui/wizards/tools/ConvertProjectToPluginOperation.java 26 Feb 2008 20:42:13 -0000 @@ -21,8 +21,7 @@ import org.eclipse.pde.core.build.IBuild; import org.eclipse.pde.core.build.IBuildEntry; import org.eclipse.pde.core.plugin.*; -import org.eclipse.pde.internal.core.ICoreConstants; -import org.eclipse.pde.internal.core.TargetPlatformHelper; +import org.eclipse.pde.internal.core.*; import org.eclipse.pde.internal.core.build.WorkspaceBuildModel; import org.eclipse.pde.internal.core.bundle.WorkspaceBundlePluginModel; import org.eclipse.pde.internal.core.ibundle.IBundle; @@ -34,7 +33,6 @@ import org.eclipse.pde.internal.ui.PDEUIMessages; import org.eclipse.pde.internal.ui.util.ModelModification; import org.eclipse.pde.internal.ui.util.PDEModelUtility; -import org.eclipse.pde.internal.ui.wizards.plugin.ClasspathComputer; import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.osgi.framework.Constants; Index: src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportOperation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportOperation.java,v retrieving revision 1.117 diff -u -r1.117 PluginImportOperation.java --- src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportOperation.java 5 Feb 2008 15:19:12 -0000 1.117 +++ src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportOperation.java 26 Feb 2008 20:42:13 -0000 @@ -38,7 +38,6 @@ import org.eclipse.pde.internal.core.util.CoreUtility; import org.eclipse.pde.internal.ui.PDEPlugin; import org.eclipse.pde.internal.ui.PDEUIMessages; -import org.eclipse.pde.internal.ui.wizards.plugin.ClasspathComputer; import org.eclipse.swt.widgets.Display; import org.eclipse.team.core.RepositoryProvider; import org.eclipse.team.core.TeamException; Index: src/org/eclipse/pde/internal/ui/correction/UpdateClasspathResolution.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/UpdateClasspathResolution.java,v retrieving revision 1.4 diff -u -r1.4 UpdateClasspathResolution.java --- src/org/eclipse/pde/internal/ui/correction/UpdateClasspathResolution.java 8 Jun 2007 16:48:00 -0000 1.4 +++ src/org/eclipse/pde/internal/ui/correction/UpdateClasspathResolution.java 26 Feb 2008 20:42:11 -0000 @@ -16,8 +16,8 @@ import org.eclipse.pde.core.IBaseModel; import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.PluginRegistry; +import org.eclipse.pde.internal.core.ClasspathComputer; import org.eclipse.pde.internal.ui.PDEUIMessages; -import org.eclipse.pde.internal.ui.wizards.plugin.ClasspathComputer; public class UpdateClasspathResolution extends AbstractPDEMarkerResolution { Index: src/org/eclipse/pde/internal/ui/wizards/RequiredPluginsContainerPage.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/RequiredPluginsContainerPage.java,v retrieving revision 1.34 diff -u -r1.34 RequiredPluginsContainerPage.java --- src/org/eclipse/pde/internal/ui/wizards/RequiredPluginsContainerPage.java 16 Jan 2008 17:08:18 -0000 1.34 +++ src/org/eclipse/pde/internal/ui/wizards/RequiredPluginsContainerPage.java 26 Feb 2008 20:42:12 -0000 @@ -20,10 +20,10 @@ import org.eclipse.jface.wizard.WizardPage; import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.PluginRegistry; +import org.eclipse.pde.internal.core.ClasspathComputer; import org.eclipse.pde.internal.core.RequiredPluginsClasspathContainer; import org.eclipse.pde.internal.ui.*; import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; -import org.eclipse.pde.internal.ui.wizards.plugin.ClasspathComputer; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData;