Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 163444 | Differences between
and this patch

Collapse All | Expand All

(-)tests/org/eclipse/jdt/debug/tests/core/ClasspathContainerTests.java (-1 / +1 lines)
Lines 98-104 Link Here
98
		IVMInstall newVM = def.getVMInstallType().findVMInstall(vmId);
98
		IVMInstall newVM = def.getVMInstallType().findVMInstall(vmId);
99
		assertNotNull("Failed to create new VM", newVM);
99
		assertNotNull("Failed to create new VM", newVM);
100
		
100
		
101
		JREContainer container = new JREContainer(newVM, containerPath);
101
		JREContainer container = new JREContainer(newVM, containerPath, getJavaProject());
102
		JREContainerInitializer initializer = new JREContainerInitializer();
102
		JREContainerInitializer initializer = new JREContainerInitializer();
103
		// store the current library settings
103
		// store the current library settings
104
		LibraryLocation[] originalLibs = JavaRuntime.getLibraryLocations(newVM);
104
		LibraryLocation[] originalLibs = JavaRuntime.getLibraryLocations(newVM);
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/SelectSystemLibraryQuickFix.java (-2 / +4 lines)
Lines 12-18 Link Here
12
12
13
13
14
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.InvocationTargetException;
15
import com.ibm.icu.text.MessageFormat;
15
16
import org.eclipse.core.resources.IMarker;
16
import org.eclipse.core.resources.IMarker;
17
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.IPath;
Lines 33-38 Link Here
33
import org.eclipse.jface.operation.IRunnableWithProgress;
33
import org.eclipse.jface.operation.IRunnableWithProgress;
34
import org.eclipse.ui.PlatformUI;
34
import org.eclipse.ui.PlatformUI;
35
35
36
import com.ibm.icu.text.MessageFormat;
37
36
/**
38
/**
37
 * Quick fix to select an alternate JRE for a project. 
39
 * Quick fix to select an alternate JRE for a project. 
38
 */
40
 */
Lines 96-102 Link Here
96
							project.setRawClasspath(classpath, monitor);
98
							project.setRawClasspath(classpath, monitor);
97
							newBinding = newPath;
99
							newBinding = newPath;
98
						}
100
						}
99
					JavaCore.setClasspathContainer(unboundPath, new IJavaProject[] {project}, new IClasspathContainer[] {new JREContainer(vm, newBinding)}, monitor);
101
					JavaCore.setClasspathContainer(unboundPath, new IJavaProject[] {project}, new IClasspathContainer[] {new JREContainer(vm, newBinding, project)}, monitor);
100
					} catch (CoreException e) {
102
					} catch (CoreException e) {
101
						throw new InvocationTargetException(e);
103
						throw new InvocationTargetException(e);
102
					}
104
					}
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/RuntimeClasspathEntryLabelProvider.java (-2 / +3 lines)
Lines 13-19 Link Here
13
13
14
14
15
import java.io.File;
15
import java.io.File;
16
import com.ibm.icu.text.MessageFormat;
17
16
18
import org.eclipse.core.resources.IContainer;
17
import org.eclipse.core.resources.IContainer;
19
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.IResource;
Lines 40-45 Link Here
40
import org.eclipse.swt.graphics.Image;
39
import org.eclipse.swt.graphics.Image;
41
import org.eclipse.ui.model.WorkbenchLabelProvider;
40
import org.eclipse.ui.model.WorkbenchLabelProvider;
42
41
42
import com.ibm.icu.text.MessageFormat;
43
43
/**
44
/**
44
 * Label provider for runtime classpath entries.
45
 * Label provider for runtime classpath entries.
45
 */
46
 */
Lines 186-192 Link Here
186
							if (path.segmentCount() > 0 && path.segment(0).equals(JavaRuntime.JRE_CONTAINER)) {
187
							if (path.segmentCount() > 0 && path.segment(0).equals(JavaRuntime.JRE_CONTAINER)) {
187
								IVMInstall vm = JavaRuntime.getVMInstall(path);
188
								IVMInstall vm = JavaRuntime.getVMInstall(path);
188
								if (vm != null) {
189
								if (vm != null) {
189
									JREContainer container = new JREContainer(vm, path);
190
									JREContainer container = new JREContainer(vm, path, project);
190
									return container.getDescription();
191
									return container.getDescription();
191
								}
192
								}
192
							}
193
							}
(-)launching/org/eclipse/jdt/internal/launching/JREContainerInitializer.java (-1 / +1 lines)
Lines 52-58 Link Here
52
				IVMInstall vm = resolveVM(containerPath);
52
				IVMInstall vm = resolveVM(containerPath);
53
				JREContainer container = null;
53
				JREContainer container = null;
54
				if (vm != null) {
54
				if (vm != null) {
55
					container = new JREContainer(vm, containerPath);
55
					container = new JREContainer(vm, containerPath, project);
56
				}
56
				}
57
				JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {container}, null);
57
				JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {container}, null);
58
			}
58
			}
(-)launching/org/eclipse/jdt/internal/launching/JREContainer.java (-10 / +40 lines)
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
	/**
(-)schema/executionEnvironments.exsd (-1 / +39 lines)
Lines 15-20 Link Here
15
         <sequence>
15
         <sequence>
16
            <element ref="environment" minOccurs="0" maxOccurs="unbounded"/>
16
            <element ref="environment" minOccurs="0" maxOccurs="unbounded"/>
17
            <element ref="analyzer" minOccurs="0" maxOccurs="unbounded"/>
17
            <element ref="analyzer" minOccurs="0" maxOccurs="unbounded"/>
18
            <element ref="ruleParticipant" minOccurs="0" maxOccurs="unbounded"/>
18
         </sequence>
19
         </sequence>
19
         <attribute name="point" type="string" use="required">
20
         <attribute name="point" type="string" use="required">
20
            <annotation>
21
            <annotation>
Lines 62-67 Link Here
62
               </appInfo>
63
               </appInfo>
63
            </annotation>
64
            </annotation>
64
         </attribute>
65
         </attribute>
66
         <attribute name="ruleParticipant" type="string">
67
            <annotation>
68
               <documentation>
69
                  the fully qualified name of a Java class that implements &lt;code&gt;org.eclipse.jdt.launching.environments.IAccessRuleParticipant&lt;/code&gt;. When specified, this class is used to create access rules for VM libraries associated with this execution environment during classpath resolution. This participant creates rules first, followed by any &lt;code&gt;ruleParticipants&lt;/code&gt; contributed as elements. This attribute was added in the 3.3 release.
70
               </documentation>
71
               <appInfo>
72
                  <meta.attribute kind="java" basedOn="org.eclipse.jdt.launching.environments.IAccessRuleParticipant"/>
73
               </appInfo>
74
            </annotation>
75
         </attribute>
65
      </complexType>
76
      </complexType>
66
   </element>
77
   </element>
67
78
Lines 87-92 Link Here
87
      </complexType>
98
      </complexType>
88
   </element>
99
   </element>
89
100
101
   <element name="ruleParticipant">
102
      <annotation>
103
         <documentation>
104
            This element was added in the 3.3 release.
105
         </documentation>
106
      </annotation>
107
      <complexType>
108
         <attribute name="id" type="string" use="required">
109
            <annotation>
110
               <documentation>
111
                  a unique identifier for this rule participant
112
               </documentation>
113
            </annotation>
114
         </attribute>
115
         <attribute name="class" type="string" use="required">
116
            <annotation>
117
               <documentation>
118
                  the fully qualified name of a Java class that implements &lt;code&gt;org.eclipse.jdt.launching.environments.IAccessRuleParticipant&lt;/code&gt;. When specified, this class is used to create access rules for VM libraries associated with this execution environment during classpath resolution. This participant creates after any &lt;code&gt;ruleParticipant&lt;/code&gt; contributed as by an execution environment directly.
119
               </documentation>
120
               <appInfo>
121
                  <meta.attribute kind="java" basedOn="org.eclipse.jdt.launching.environments.IAccessRuleParticipant"/>
122
               </appInfo>
123
            </annotation>
124
         </attribute>
125
      </complexType>
126
   </element>
127
90
   <annotation>
128
   <annotation>
91
      <appInfo>
129
      <appInfo>
92
         <meta.section type="since"/>
130
         <meta.section type="since"/>
Lines 122-128 Link Here
122
         <meta.section type="implementation"/>
160
         <meta.section type="implementation"/>
123
      </appInfo>
161
      </appInfo>
124
      <documentation>
162
      <documentation>
125
         PDE (&lt;code&gt;org.eclispe.pde.core&lt;/code&gt;) provides definitions and an analyzer for the following execution environments:
163
         JDT (&lt;code&gt;org.eclispe.jdt.launching&lt;/code&gt;) provides definitions and an analyzer for the following execution environments:
126
&lt;ul&gt;
164
&lt;ul&gt;
127
&lt;li&gt;OSGi/Minimum-1.0&lt;/li&gt;
165
&lt;li&gt;OSGi/Minimum-1.0&lt;/li&gt;
128
&lt;li&gt;OSGi/Minimum-1.1&lt;/li&gt;
166
&lt;li&gt;OSGi/Minimum-1.1&lt;/li&gt;
(-)launching/org/eclipse/jdt/launching/environments/IExecutionEnvironment.java (+17 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.launching.environments;
11
package org.eclipse.jdt.launching.environments;
12
12
13
import org.eclipse.jdt.core.IAccessRule;
14
import org.eclipse.jdt.core.IJavaProject;
13
import org.eclipse.jdt.launching.IVMInstall;
15
import org.eclipse.jdt.launching.IVMInstall;
16
import org.eclipse.jdt.launching.LibraryLocation;
14
17
15
/**
18
/**
16
 * An execution environment describes capabilities of
19
 * An execution environment describes capabilities of
Lines 82-85 Link Here
82
	 *  this environment
85
	 *  this environment
83
	 */
86
	 */
84
	public void setDefaultVM(IVMInstall vm);
87
	public void setDefaultVM(IVMInstall vm);
88
	
89
	/**
90
	 * Returns a collection of access rules to be applied to the specified VM
91
	 * libraries for this execution environment in the context of the given project.
92
	 * An array of access rules is returned for each library specified by
93
	 * <code>libraries</code>, possibly empty.
94
	 * 
95
	 * @param vm the vm that access rules are requested for
96
	 * @param libraries the libraries that access rules are requested for 
97
	 * @param project the project the access rules are requested for or <code>null</code> if none
98
	 * @return a collection of arrays of access rules - one array per library
99
	 * @since 3.3
100
	 */
101
	public IAccessRule[][] getAccessRules(IVMInstall vm, LibraryLocation[] libraries, IJavaProject project);
85
}
102
}
(-)launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironment.java (-3 / +52 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.launching.environments;
11
package org.eclipse.jdt.internal.launching.environments;
12
12
13
import com.ibm.icu.text.MessageFormat;
14
import java.util.ArrayList;
13
import java.util.ArrayList;
15
import java.util.HashSet;
14
import java.util.HashSet;
16
import java.util.List;
15
import java.util.List;
Lines 20-25 Link Here
20
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.core.runtime.IConfigurationElement;
21
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.NullProgressMonitor;
21
import org.eclipse.core.runtime.NullProgressMonitor;
22
import org.eclipse.jdt.core.IAccessRule;
23
import org.eclipse.jdt.core.IClasspathContainer;
23
import org.eclipse.jdt.core.IClasspathContainer;
24
import org.eclipse.jdt.core.IClasspathEntry;
24
import org.eclipse.jdt.core.IClasspathEntry;
25
import org.eclipse.jdt.core.IJavaModel;
25
import org.eclipse.jdt.core.IJavaModel;
Lines 29-36 Link Here
29
import org.eclipse.jdt.internal.launching.LaunchingPlugin;
29
import org.eclipse.jdt.internal.launching.LaunchingPlugin;
30
import org.eclipse.jdt.launching.IVMInstall;
30
import org.eclipse.jdt.launching.IVMInstall;
31
import org.eclipse.jdt.launching.JavaRuntime;
31
import org.eclipse.jdt.launching.JavaRuntime;
32
import org.eclipse.jdt.launching.LibraryLocation;
33
import org.eclipse.jdt.launching.environments.IAccessRuleParticipant;
32
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
34
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
33
35
36
import com.ibm.icu.text.MessageFormat;
37
34
/**
38
/**
35
 * A contributed execution environment.
39
 * A contributed execution environment.
36
 * 
40
 * 
Lines 41-52 Link Here
41
	private IConfigurationElement fElement;
45
	private IConfigurationElement fElement;
42
	
46
	
43
	/**
47
	/**
44
	 * Set of compatible vms - just the strictly compatible ones
48
	 * Environment specific rule participant or <code>null</code> if none.
49
	 */
50
	private IAccessRuleParticipant fRuleParticipant;
51
	
52
	/**
53
	 * Set of compatible vm's - just the strictly compatible ones
45
	 */
54
	 */
46
	private Set fStrictlyCompatible = new HashSet();
55
	private Set fStrictlyCompatible = new HashSet();
47
	
56
	
48
	/** 
57
	/** 
49
	 * All compatible vms
58
	 * All compatible vm's
50
	 */
59
	 */
51
	private List fCompatibleVMs = new ArrayList();
60
	private List fCompatibleVMs = new ArrayList();
52
	
61
	
Lines 57-62 Link Here
57
	
66
	
58
	ExecutionEnvironment(IConfigurationElement element) {
67
	ExecutionEnvironment(IConfigurationElement element) {
59
		fElement = element;
68
		fElement = element;
69
		String attribute = fElement.getAttribute(EnvironmentsManager.RULE_PARTICIPANT_ELEMENT);
70
		if (attribute != null) {
71
			fRuleParticipant = new AccessRuleParticipant(fElement);
72
		}
60
	}
73
	}
61
	
74
	
62
	private void init() {
75
	private void init() {
Lines 171-174 Link Here
171
	void initDefaultVM(IVMInstall vm) {
184
	void initDefaultVM(IVMInstall vm) {
172
		fDefault = vm;
185
		fDefault = vm;
173
	}
186
	}
187
188
	/* (non-Javadoc)
189
	 * @see org.eclipse.jdt.launching.environments.IExecutionEnvironment#getAccessRules(org.eclipse.jdt.launching.IVMInstall, org.eclipse.jdt.launching.LibraryLocation[], org.eclipse.jdt.core.IJavaProject)
190
	 */
191
	public IAccessRule[][] getAccessRules(IVMInstall vm, LibraryLocation[] libraries, IJavaProject project) {
192
		List[] libLists = new List[libraries.length]; // array of lists of access rules
193
		for (int i = 0; i < libLists.length; i++) {
194
			libLists[i] = new ArrayList();
195
		}
196
		// check primary provider first
197
		if (fRuleParticipant != null) {
198
			processParticipant(fRuleParticipant, libLists, vm, libraries, project);
199
		}
200
		// check other participants
201
		IAccessRuleParticipant[] participants = EnvironmentsManager.getDefault().getAccessRuleParticipants();
202
		for (int i = 0; i < participants.length; i++) {
203
			processParticipant(participants[i], libLists, vm, libraries, project);
204
		}
205
		IAccessRule[][] allRules = new IAccessRule[libraries.length][];
206
		for (int i = 0; i < libLists.length; i++) {
207
			allRules[i] = (IAccessRule[]) libLists[i].toArray(new IAccessRule[libLists[i].size()]);
208
		}
209
		return allRules;
210
	}
211
	
212
	private void processParticipant(IAccessRuleParticipant participant, List[] collect, IVMInstall vm, LibraryLocation[] libraries, IJavaProject project) {
213
		// TODO: use safe runnables
214
		IAccessRule[][] accessRules = participant.getAccessRules(this, vm, libraries, project);
215
		for (int i = 0; i < accessRules.length; i++) {
216
			IAccessRule[] libRules = accessRules[i];
217
			List list = collect[i];
218
			for (int j = 0; j < libRules.length; j++) {
219
				list.add(libRules[j]);
220
			}
221
		}
222
	}
174
}
223
}
(-)launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java (-3 / +44 lines)
Lines 12-18 Link Here
12
12
13
import java.io.ByteArrayInputStream;
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
14
import java.io.IOException;
15
import com.ibm.icu.text.MessageFormat;
16
import java.util.ArrayList;
15
import java.util.ArrayList;
17
import java.util.Collection;
16
import java.util.Collection;
18
import java.util.HashMap;
17
import java.util.HashMap;
Lines 38-43 Link Here
38
import org.eclipse.jdt.launching.PropertyChangeEvent;
37
import org.eclipse.jdt.launching.PropertyChangeEvent;
39
import org.eclipse.jdt.launching.VMStandin;
38
import org.eclipse.jdt.launching.VMStandin;
40
import org.eclipse.jdt.launching.environments.CompatibleEnvironment;
39
import org.eclipse.jdt.launching.environments.CompatibleEnvironment;
40
import org.eclipse.jdt.launching.environments.IAccessRuleParticipant;
41
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
41
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
42
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
42
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
43
import org.w3c.dom.Document;
43
import org.w3c.dom.Document;
Lines 46-51 Link Here
46
import org.w3c.dom.NodeList;
46
import org.w3c.dom.NodeList;
47
import org.xml.sax.SAXException;
47
import org.xml.sax.SAXException;
48
48
49
import com.ibm.icu.text.MessageFormat;
50
49
/**
51
/**
50
 * Utility class for execution environments.
52
 * Utility class for execution environments.
51
 * 
53
 * 
Lines 53-58 Link Here
53
 */
55
 */
54
public class EnvironmentsManager implements IExecutionEnvironmentsManager, IVMInstallChangedListener, IPropertyChangeListener {
56
public class EnvironmentsManager implements IExecutionEnvironmentsManager, IVMInstallChangedListener, IPropertyChangeListener {
55
57
58
	/**
59
	 * Extension configuration element name.
60
	 */
61
	private static final String ANALYZER_ELEMENT = "analyzer"; //$NON-NLS-1$
62
63
	/**
64
	 * Extension configuration element name.
65
	 */
66
	static final String ENVIRONMENT_ELEMENT = "environment"; //$NON-NLS-1$
67
	
68
	/**
69
	 * Extension configuration element name.
70
	 */
71
	static final String RULE_PARTICIPANT_ELEMENT = "ruleParticipant"; //$NON-NLS-1$	
72
56
	private static EnvironmentsManager fgManager = null;
73
	private static EnvironmentsManager fgManager = null;
57
	
74
	
58
	/**
75
	/**
Lines 66-71 Link Here
66
	private List fEnvironments = null;
83
	private List fEnvironments = null;
67
	
84
	
68
	/**
85
	/**
86
	 * List of access rule participants
87
	 */
88
	private List fRuleParticipants = null;
89
	
90
	/**
69
	 * Map of environments keyed by id
91
	 * Map of environments keyed by id
70
	 */
92
	 */
71
	private Map fEnvironmentsMap = null;
93
	private Map fEnvironmentsMap = null;
Lines 133-138 Link Here
133
		return (IExecutionEnvironment[]) fEnvironments.toArray(new IExecutionEnvironment[fEnvironments.size()]);
155
		return (IExecutionEnvironment[]) fEnvironments.toArray(new IExecutionEnvironment[fEnvironments.size()]);
134
	}
156
	}
135
	
157
	
158
	/**
159
	 * Returns all access rule participants that are not specific to an execution environment.
160
	 * 
161
	 * @return all access rule participants that are not specific to an execution environment.
162
	 * @since 3.3
163
	 */
164
	public synchronized IAccessRuleParticipant[] getAccessRuleParticipants() {
165
		initializeExtensions();
166
		return (IAccessRuleParticipant[]) fRuleParticipants.toArray(new IAccessRuleParticipant[fRuleParticipants.size()]);
167
	}
168
	
136
	/* (non-Javadoc)
169
	/* (non-Javadoc)
137
	 * @see org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager#getEnvironment(java.lang.String)
170
	 * @see org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager#getEnvironment(java.lang.String)
138
	 */
171
	 */
Lines 157-168 Link Here
157
			IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(LaunchingPlugin.ID_PLUGIN, JavaRuntime.EXTENSION_POINT_EXECUTION_ENVIRONMENTS);
190
			IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(LaunchingPlugin.ID_PLUGIN, JavaRuntime.EXTENSION_POINT_EXECUTION_ENVIRONMENTS);
158
			IConfigurationElement[] configs= extensionPoint.getConfigurationElements();
191
			IConfigurationElement[] configs= extensionPoint.getConfigurationElements();
159
			fEnvironments = new ArrayList();
192
			fEnvironments = new ArrayList();
193
			fRuleParticipants = new ArrayList();
160
			fEnvironmentsMap = new HashMap(configs.length);
194
			fEnvironmentsMap = new HashMap(configs.length);
161
			fAnalyzers = new HashMap(configs.length);
195
			fAnalyzers = new HashMap(configs.length);
162
			for (int i = 0; i < configs.length; i++) {
196
			for (int i = 0; i < configs.length; i++) {
163
				IConfigurationElement element = configs[i];
197
				IConfigurationElement element = configs[i];
164
				String name = element.getName();
198
				String name = element.getName();
165
				if (name.equals("environment")) { //$NON-NLS-1$
199
				if (name.equals(ENVIRONMENT_ELEMENT)) {
166
					String id = element.getAttribute("id"); //$NON-NLS-1$
200
					String id = element.getAttribute("id"); //$NON-NLS-1$
167
					if (id == null) {
201
					if (id == null) {
168
						LaunchingPlugin.log(MessageFormat.format("Execution environment must specify \"id\" attribute. Contributed by {0}.", new String[]{element.getContributor().getName()})); //$NON-NLS-1$
202
						LaunchingPlugin.log(MessageFormat.format("Execution environment must specify \"id\" attribute. Contributed by {0}.", new String[]{element.getContributor().getName()})); //$NON-NLS-1$
Lines 171-183 Link Here
171
						fEnvironments.add(env);
205
						fEnvironments.add(env);
172
						fEnvironmentsMap.put(id, env);
206
						fEnvironmentsMap.put(id, env);
173
					}
207
					}
174
				} else if (name.equals("analyzer")) { //$NON-NLS-1$
208
				} else if (name.equals(ANALYZER_ELEMENT)) {
175
					String id = element.getAttribute("id"); //$NON-NLS-1$
209
					String id = element.getAttribute("id"); //$NON-NLS-1$
176
					if (id == null) {
210
					if (id == null) {
177
						LaunchingPlugin.log(MessageFormat.format("Execution environment analyzer must specify \"id\" attribute. Contributed by {0}", new String[]{element.getContributor().getName()})); //$NON-NLS-1$
211
						LaunchingPlugin.log(MessageFormat.format("Execution environment analyzer must specify \"id\" attribute. Contributed by {0}", new String[]{element.getContributor().getName()})); //$NON-NLS-1$
178
					} else {
212
					} else {
179
						fAnalyzers.put(id, new Analyzer(element));
213
						fAnalyzers.put(id, new Analyzer(element));
180
					}
214
					}
215
				} else if (name.equals(RULE_PARTICIPANT_ELEMENT)) {
216
					String id = element.getAttribute("id"); //$NON-NLS-1$
217
					if (id == null) {
218
						LaunchingPlugin.log(MessageFormat.format("Execution environment rule participant must specify \"id\" attribute. Contributed by {0}", new String[]{element.getContributor().getName()})); //$NON-NLS-1$
219
					} else {
220
						fRuleParticipants.add(new AccessRuleParticipant(element));
221
					}
181
				}
222
				}
182
			}
223
			}
183
		}
224
		}
(-)launching/org/eclipse/jdt/internal/launching/environments/AccessRuleParticipant.java (+86 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.launching.environments;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IConfigurationElement;
15
import org.eclipse.jdt.core.IAccessRule;
16
import org.eclipse.jdt.core.IJavaProject;
17
import org.eclipse.jdt.internal.launching.LaunchingPlugin;
18
import org.eclipse.jdt.launching.IVMInstall;
19
import org.eclipse.jdt.launching.LibraryLocation;
20
import org.eclipse.jdt.launching.environments.IAccessRuleParticipant;
21
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
22
23
/**
24
 * Proxy to an access rule participant for an execution environment.
25
 * 
26
 * @since 3.3
27
 */
28
class AccessRuleParticipant implements IAccessRuleParticipant {
29
30
	private IConfigurationElement fElement;
31
	
32
	private IAccessRuleParticipant fDelegate;
33
	
34
	/**
35
	 * Constructs a proxy to a rule participant contributed with the 
36
	 * given configuration element. The element may be an
37
	 * <code>executionEnvironment</code> element or a <code>ruleParticipant</code>
38
	 * extension.
39
	 * 
40
	 * @param element
41
	 */
42
	AccessRuleParticipant(IConfigurationElement element) {
43
		fElement = element;
44
	}
45
	
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.jdt.launching.environments.IAccessRuleParticipant#getAccessRules(org.eclipse.jdt.launching.environments.IExecutionEnvironment, org.eclipse.jdt.launching.IVMInstall, org.eclipse.jdt.launching.LibraryLocation[], org.eclipse.jdt.core.IJavaProject)
48
	 */
49
	public IAccessRule[][] getAccessRules(IExecutionEnvironment environment, IVMInstall vm, LibraryLocation[] libraries, IJavaProject project) {
50
		try {
51
			return getDelegate().getAccessRules(environment, vm, libraries, project);
52
		} catch (CoreException e) {
53
			LaunchingPlugin.log(e.getStatus());
54
		}
55
		IAccessRule[][] rules = new IAccessRule[libraries.length][];
56
		for (int i = 0; i < rules.length; i++) {
57
			rules[i] = new IAccessRule[0];
58
		}
59
		return rules;
60
	}
61
	
62
	private IAccessRuleParticipant getDelegate() throws CoreException {
63
		if (fDelegate == null) {
64
			if (fElement.getName().equals(EnvironmentsManager.ENVIRONMENT_ELEMENT)) {
65
				fDelegate = (IAccessRuleParticipant) fElement.createExecutableExtension(EnvironmentsManager.RULE_PARTICIPANT_ELEMENT);
66
			} else {
67
				fDelegate = (IAccessRuleParticipant) fElement.createExecutableExtension("class"); //$NON-NLS-1$
68
			}
69
		}
70
		return fDelegate;
71
	}
72
	
73
	/**
74
	 * Returns the id of this participant.
75
	 * 
76
	 * @return participant id
77
	 */
78
	String getId() {
79
		if (fElement.getName().equals(EnvironmentsManager.ENVIRONMENT_ELEMENT)) {
80
			return fElement.getAttribute(EnvironmentsManager.RULE_PARTICIPANT_ELEMENT);
81
		} else {
82
			return fElement.getAttribute("id");
83
		}
84
	}
85
86
}
(-)launching/org/eclipse/jdt/launching/environments/IAccessRuleParticipant.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.launching.environments;
12
13
import org.eclipse.jdt.core.IAccessRule;
14
import org.eclipse.jdt.core.IJavaProject;
15
import org.eclipse.jdt.launching.IVMInstall;
16
import org.eclipse.jdt.launching.LibraryLocation;
17
18
/**
19
 * Builds access rules for an execution environment. Contributed with
20
 * an execution environment extension.
21
 * <p>
22
 * Client contributing an access rule participant may implement this interface.
23
 * </p>
24
 * @since 3.3
25
 */
26
public interface IAccessRuleParticipant {
27
28
	/**
29
	 * Returns a collection of access rules to be applied to the specified VM
30
	 * libraries and execution environment in the context of the given project.
31
	 * An array of access rules is returned for each library specified by
32
	 * <code>libraries</code>, possibly empty.
33
	 * 
34
	 * @param environment the environment that access rules are requested for
35
	 * @param vm the vm that access rules are requested for
36
	 * @param libraries the libraries that access rules are requested for 
37
	 * @param project the project the access rules are requested for or <code>null</code> if none
38
	 * @return a collection of arrays of access rules - one array per library
39
	 * @since 3.3
40
	 */
41
	public IAccessRule[][] getAccessRules(IExecutionEnvironment environment, IVMInstall vm, LibraryLocation[] libraries, IJavaProject project);
42
}

Return to bug 163444