|
Lines 12-18
Link Here
|
| 12 |
|
12 |
|
| 13 |
|
13 |
|
| 14 |
import java.net.URL; |
14 |
import java.net.URL; |
| 15 |
import com.ibm.icu.text.MessageFormat; |
|
|
| 16 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
| 17 |
import java.util.HashMap; |
16 |
import java.util.HashMap; |
| 18 |
import java.util.List; |
17 |
import java.util.List; |
|
Lines 23-34
Link Here
|
| 23 |
import org.eclipse.jdt.core.IClasspathAttribute; |
22 |
import org.eclipse.jdt.core.IClasspathAttribute; |
| 24 |
import org.eclipse.jdt.core.IClasspathContainer; |
23 |
import org.eclipse.jdt.core.IClasspathContainer; |
| 25 |
import org.eclipse.jdt.core.IClasspathEntry; |
24 |
import org.eclipse.jdt.core.IClasspathEntry; |
|
|
25 |
import org.eclipse.jdt.core.IJavaProject; |
| 26 |
import org.eclipse.jdt.core.JavaCore; |
26 |
import org.eclipse.jdt.core.JavaCore; |
| 27 |
import org.eclipse.jdt.launching.IVMInstall; |
27 |
import org.eclipse.jdt.launching.IVMInstall; |
| 28 |
import org.eclipse.jdt.launching.IVMInstallChangedListener; |
28 |
import org.eclipse.jdt.launching.IVMInstallChangedListener; |
| 29 |
import org.eclipse.jdt.launching.JavaRuntime; |
29 |
import org.eclipse.jdt.launching.JavaRuntime; |
| 30 |
import org.eclipse.jdt.launching.LibraryLocation; |
30 |
import org.eclipse.jdt.launching.LibraryLocation; |
| 31 |
import org.eclipse.jdt.launching.PropertyChangeEvent; |
31 |
import org.eclipse.jdt.launching.PropertyChangeEvent; |
|
|
32 |
import org.eclipse.jdt.launching.environments.IExecutionEnvironment; |
| 33 |
|
| 34 |
import com.ibm.icu.text.MessageFormat; |
| 32 |
|
35 |
|
| 33 |
/** |
36 |
/** |
| 34 |
* JRE Container - resolves a classpath container variable to a JRE |
37 |
* JRE Container - resolves a classpath container variable to a JRE |
|
Lines 46-51
Link Here
|
| 46 |
private IPath fPath = null; |
49 |
private IPath fPath = null; |
| 47 |
|
50 |
|
| 48 |
/** |
51 |
/** |
|
|
52 |
* The project this container is for |
| 53 |
*/ |
| 54 |
private IJavaProject fProject = null; |
| 55 |
|
| 56 |
/** |
| 49 |
* Cache of classpath entries per VM install. Cleared when a VM changes. |
57 |
* Cache of classpath entries per VM install. Cleared when a VM changes. |
| 50 |
*/ |
58 |
*/ |
| 51 |
private static Map fgClasspathEntries = null; |
59 |
private static Map fgClasspathEntries = null; |
|
Lines 53-64
Link Here
|
| 53 |
private static IAccessRule[] EMPTY_RULES = new IAccessRule[0]; |
61 |
private static IAccessRule[] EMPTY_RULES = new IAccessRule[0]; |
| 54 |
|
62 |
|
| 55 |
/** |
63 |
/** |
| 56 |
* Returns the classpath entries associated with the given VM. |
64 |
* Returns the classpath entries associated with the given VM |
|
|
65 |
* in the context of the given path and project. |
| 57 |
* |
66 |
* |
| 58 |
* @param vm |
67 |
* @param vm |
|
|
68 |
* @param containerPath the container path resolution is for |
| 69 |
* @param project project the resolution is for |
| 59 |
* @return classpath entries |
70 |
* @return classpath entries |
| 60 |
*/ |
71 |
*/ |
| 61 |
private static IClasspathEntry[] getClasspathEntries(IVMInstall vm) { |
72 |
private static IClasspathEntry[] getClasspathEntries(IVMInstall vm, IPath containerPath, IJavaProject project) { |
| 62 |
if (fgClasspathEntries == null) { |
73 |
if (fgClasspathEntries == null) { |
| 63 |
fgClasspathEntries = new HashMap(10); |
74 |
fgClasspathEntries = new HashMap(10); |
| 64 |
// add a listener to clear cached value when a VM changes or is removed |
75 |
// add a listener to clear cached value when a VM changes or is removed |
|
Lines 83-107
Link Here
|
| 83 |
} |
94 |
} |
| 84 |
IClasspathEntry[] entries = (IClasspathEntry[])fgClasspathEntries.get(vm); |
95 |
IClasspathEntry[] entries = (IClasspathEntry[])fgClasspathEntries.get(vm); |
| 85 |
if (entries == null) { |
96 |
if (entries == null) { |
| 86 |
entries = computeClasspathEntries(vm); |
97 |
entries = computeClasspathEntries(vm, containerPath, project); |
| 87 |
fgClasspathEntries.put(vm, entries); |
98 |
fgClasspathEntries.put(vm, entries); |
| 88 |
} |
99 |
} |
| 89 |
return entries; |
100 |
return entries; |
| 90 |
} |
101 |
} |
| 91 |
|
102 |
|
| 92 |
/** |
103 |
/** |
| 93 |
* Computes the classpath entries associated with a VM - one entry per library. |
104 |
* Computes the classpath entries associated with a VM - one entry per library |
|
|
105 |
* in the context of the given path and project. |
| 94 |
* |
106 |
* |
| 95 |
* @param vm |
107 |
* @param vm |
|
|
108 |
* @param containerPath the container path the resolution is for |
| 109 |
* @param project the project the resolution is for. |
| 96 |
* @return classpath entries |
110 |
* @return classpath entries |
| 97 |
*/ |
111 |
*/ |
| 98 |
private static IClasspathEntry[] computeClasspathEntries(IVMInstall vm) { |
112 |
private static IClasspathEntry[] computeClasspathEntries(IVMInstall vm, IPath containerPath, IJavaProject project) { |
| 99 |
LibraryLocation[] libs = vm.getLibraryLocations(); |
113 |
LibraryLocation[] libs = vm.getLibraryLocations(); |
| 100 |
boolean overrideJavaDoc = false; |
114 |
boolean overrideJavaDoc = false; |
| 101 |
if (libs == null) { |
115 |
if (libs == null) { |
| 102 |
libs = JavaRuntime.getLibraryLocations(vm); |
116 |
libs = JavaRuntime.getLibraryLocations(vm); |
| 103 |
overrideJavaDoc = true; |
117 |
overrideJavaDoc = true; |
| 104 |
} |
118 |
} |
|
|
119 |
String id = JavaRuntime.getExecutionEnvironmentId(containerPath); |
| 120 |
IAccessRule[][] rules = null; |
| 121 |
if (id != null) { |
| 122 |
// compute access rules for execution environment |
| 123 |
IExecutionEnvironment environment = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(id); |
| 124 |
if (environment != null) { |
| 125 |
rules = environment.getAccessRules(vm, libs, project); |
| 126 |
} |
| 127 |
} |
| 105 |
List entries = new ArrayList(libs.length); |
128 |
List entries = new ArrayList(libs.length); |
| 106 |
for (int i = 0; i < libs.length; i++) { |
129 |
for (int i = 0; i < libs.length; i++) { |
| 107 |
if (!libs[i].getSystemLibraryPath().isEmpty()) { |
130 |
if (!libs[i].getSystemLibraryPath().isEmpty()) { |
|
Lines 123-150
Link Here
|
| 123 |
} else { |
146 |
} else { |
| 124 |
attributes = new IClasspathAttribute[]{JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadocLocation.toExternalForm())}; |
147 |
attributes = new IClasspathAttribute[]{JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadocLocation.toExternalForm())}; |
| 125 |
} |
148 |
} |
| 126 |
entries.add(JavaCore.newLibraryEntry(libs[i].getSystemLibraryPath(), sourcePath, rootPath, EMPTY_RULES, attributes, false)); |
149 |
IAccessRule[] libRules = null; |
|
|
150 |
if (rules != null) { |
| 151 |
libRules = rules[i]; |
| 152 |
} else { |
| 153 |
libRules = EMPTY_RULES; |
| 154 |
} |
| 155 |
entries.add(JavaCore.newLibraryEntry(libs[i].getSystemLibraryPath(), sourcePath, rootPath, libRules, attributes, false)); |
| 127 |
} |
156 |
} |
| 128 |
} |
157 |
} |
| 129 |
return (IClasspathEntry[])entries.toArray(new IClasspathEntry[entries.size()]); |
158 |
return (IClasspathEntry[])entries.toArray(new IClasspathEntry[entries.size()]); |
| 130 |
} |
159 |
} |
| 131 |
|
160 |
|
| 132 |
/** |
161 |
/** |
| 133 |
* Constructs a JRE classpath conatiner on the given VM install |
162 |
* Constructs a JRE classpath container on the given VM install |
| 134 |
* |
163 |
* |
| 135 |
* @param vm vm install - cannot be <code>null</code> |
164 |
* @param vm vm install - cannot be <code>null</code> |
| 136 |
* @param path container path used to resolve this JRE |
165 |
* @param path container path used to resolve this JRE |
| 137 |
*/ |
166 |
*/ |
| 138 |
public JREContainer(IVMInstall vm, IPath path) { |
167 |
public JREContainer(IVMInstall vm, IPath path, IJavaProject project) { |
| 139 |
fVMInstall = vm; |
168 |
fVMInstall = vm; |
| 140 |
fPath = path; |
169 |
fPath = path; |
|
|
170 |
fProject = project; |
| 141 |
} |
171 |
} |
| 142 |
|
172 |
|
| 143 |
/** |
173 |
/** |
| 144 |
* @see IClasspathContainer#getClasspathEntries() |
174 |
* @see IClasspathContainer#getClasspathEntries() |
| 145 |
*/ |
175 |
*/ |
| 146 |
public IClasspathEntry[] getClasspathEntries() { |
176 |
public IClasspathEntry[] getClasspathEntries() { |
| 147 |
return getClasspathEntries(fVMInstall); |
177 |
return getClasspathEntries(fVMInstall, getPath(), fProject); |
| 148 |
} |
178 |
} |
| 149 |
|
179 |
|
| 150 |
/** |
180 |
/** |