View | Details | Raw Unified | Return to bug 256910 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/ui/tests/target/TargetDefinitionTests.java (-340 / +681 lines)
Lines 1-340 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.ui.tests.target;
11
package org.eclipse.pde.ui.tests.target;
12
12
13
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService;
14
14
15
import org.eclipse.pde.internal.core.target.provisional.ITargetHandle;
15
import org.eclipse.pde.internal.core.target.provisional.LoadTargetDefinitionJob;
16
16
17
import org.eclipse.core.resources.IFile;
17
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
18
18
19
import org.eclipse.core.resources.ResourcesPlugin;
19
import java.io.*;
20
20
import java.net.URL;
21
import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService;
21
import java.util.*;
22
22
import java.util.zip.ZipEntry;
23
import java.io.*;
23
import java.util.zip.ZipFile;
24
import java.net.URL;
24
import junit.framework.TestCase;
25
import java.util.*;
25
import org.eclipse.core.resources.IFile;
26
import java.util.zip.ZipEntry;
26
import org.eclipse.core.resources.ResourcesPlugin;
27
import java.util.zip.ZipFile;
27
import org.eclipse.core.runtime.*;
28
import junit.framework.TestCase;
28
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
29
import org.eclipse.core.runtime.*;
29
import org.eclipse.pde.core.plugin.IPluginModelBase;
30
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
30
import org.eclipse.pde.core.plugin.TargetPlatform;
31
import org.eclipse.pde.core.plugin.TargetPlatform;
31
import org.eclipse.pde.internal.core.*;
32
import org.eclipse.pde.internal.core.*;
32
import org.eclipse.pde.internal.core.target.provisional.*;
33
import org.eclipse.pde.internal.core.target.provisional.*;
33
import org.eclipse.pde.internal.ui.tests.macro.MacroPlugin;
34
import org.eclipse.pde.internal.ui.tests.macro.MacroPlugin;
34
import org.osgi.framework.ServiceReference;
35
import org.osgi.framework.ServiceReference;
35
36
36
/**
37
/**
37
 * Tests for target definitions.
38
 * Tests for target definitions.
38
 * 
39
 * 
39
 * @since 3.5 
40
 * @since 3.5 
40
 */
41
 */
41
public class TargetDefinitionTests extends TestCase {
42
public class TargetDefinitionTests extends TestCase {
42
	
43
	
43
	/**
44
	/**
44
	 * Retrieves all bundles (source and code) in the given target definition
45
	 * Retrieves all bundles (source and code) in the given target definition
45
	 * returning them as a set of URLs.
46
	 * returning them as a set of URLs.
46
	 * 
47
	 * 
47
	 * @param target target definition
48
	 * @param target target definition
48
	 * @return all bundle URLs
49
	 * @return all bundle URLs
49
	 */
50
	 */
50
	protected Set getAllBundleURLs(ITargetDefinition target) throws Exception {
51
	protected Set getAllBundleURLs(ITargetDefinition target) throws Exception {
51
		BundleInfo[] code = target.resolveBundles(null);
52
		BundleInfo[] code = target.resolveBundles(null);
52
		BundleInfo[] source = target.resolveSourceBundles(null);
53
		BundleInfo[] source = target.resolveSourceBundles(null);
53
		Set urls = new HashSet(code.length + source.length);
54
		Set urls = new HashSet(code.length + source.length);
54
		for (int i = 0; i < code.length; i++) {
55
		for (int i = 0; i < code.length; i++) {
55
			urls.add(new File(code[i].getLocation()).toURL());
56
			urls.add(new File(code[i].getLocation()).toURL());
56
		}
57
		}
57
		for (int i = 0; i < source.length; i++) {
58
		for (int i = 0; i < source.length; i++) {
58
			urls.add(new File(source[i].getLocation()).toURL());
59
			urls.add(new File(source[i].getLocation()).toURL());
59
		}
60
		}
60
		return urls;
61
		return urls;
61
	}
62
	}
62
	
63
	
63
	/**
64
	/**
64
	 * Extracts the classic plug-ins archive, if not already done, and returns a path to the
65
	 * Extracts the classic plug-ins archive, if not already done, and returns a path to the
65
	 * root directory containing the plug-ins.
66
	 * root directory containing the plug-ins.
66
	 * 
67
	 * 
67
	 * @return path to the plug-ins directory
68
	 * @return path to the plug-ins directory
68
	 * @throws Exception
69
	 * @throws Exception
69
	 */
70
	 */
70
	protected IPath extractClassicPlugins() throws Exception {
71
	protected IPath extractClassicPlugins() throws Exception {
71
		// extract the 3.0.2 skeleton
72
		// extract the 3.0.2 skeleton
72
		IPath stateLocation = MacroPlugin.getDefault().getStateLocation();
73
		IPath stateLocation = MacroPlugin.getDefault().getStateLocation();
73
		IPath location = stateLocation.append("classic-plugins");
74
		IPath location = stateLocation.append("classic-plugins");
74
		if (location.toFile().exists()) {
75
		if (location.toFile().exists()) {
75
			return location;
76
			return location;
76
		}
77
		}
77
		URL zipURL = MacroPlugin.getBundleContext().getBundle().getEntry("/tests/targets/classic-plugins.zip");
78
		URL zipURL = MacroPlugin.getBundleContext().getBundle().getEntry("/tests/targets/classic-plugins.zip");
78
		Path zipPath = new Path(new File(FileLocator.toFileURL(zipURL).getFile()).getAbsolutePath());
79
		Path zipPath = new Path(new File(FileLocator.toFileURL(zipURL).getFile()).getAbsolutePath());
79
		ZipFile zipFile = new ZipFile(zipPath.toFile());
80
		ZipFile zipFile = new ZipFile(zipPath.toFile());
80
		Enumeration entries = zipFile.entries();
81
		Enumeration entries = zipFile.entries();
81
		while (entries.hasMoreElements()) {
82
		while (entries.hasMoreElements()) {
82
			ZipEntry entry = (ZipEntry) entries.nextElement();
83
			ZipEntry entry = (ZipEntry) entries.nextElement();
83
			if (!entry.isDirectory()) {
84
			if (!entry.isDirectory()) {
84
				IPath entryPath = stateLocation.append(entry.getName());
85
				IPath entryPath = stateLocation.append(entry.getName());
85
				File dir = entryPath.removeLastSegments(1).toFile();
86
				File dir = entryPath.removeLastSegments(1).toFile();
86
				dir.mkdirs();
87
				dir.mkdirs();
87
				File file = entryPath.toFile();
88
				File file = entryPath.toFile();
88
				file.createNewFile();
89
				file.createNewFile();
89
				InputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry));
90
				InputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry));
90
				byte[] bytes = getInputStreamAsByteArray(inputStream, -1);
91
				byte[] bytes = getInputStreamAsByteArray(inputStream, -1);
91
				inputStream.close();
92
				inputStream.close();
92
				BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
93
				BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
93
				outputStream.write(bytes);
94
				outputStream.write(bytes);
94
				outputStream.close();
95
				outputStream.close();
95
			}
96
			}
96
		}
97
		}
97
		zipFile.close();
98
		zipFile.close();
98
		return location;
99
		return location;
99
	}
100
	}
100
	
101
	
101
	/**
102
	/**
102
	 * Returns the target platform service or <code>null</code> if none
103
	 * Returns the target platform service or <code>null</code> if none
103
	 * 
104
	 * 
104
	 * @return target platform service
105
	 * @return target platform service
105
	 */
106
	 */
106
	protected ITargetPlatformService getTargetService() {
107
	protected ITargetPlatformService getTargetService() {
107
		ServiceReference reference = MacroPlugin.getBundleContext().getServiceReference(ITargetPlatformService.class.getName());
108
		ServiceReference reference = MacroPlugin.getBundleContext().getServiceReference(ITargetPlatformService.class.getName());
108
		assertNotNull("Missing target platform service", reference);
109
		assertNotNull("Missing target platform service", reference);
109
		if (reference == null)
110
		if (reference == null)
110
			return null;
111
			return null;
111
		return (ITargetPlatformService) MacroPlugin.getBundleContext().getService(reference);
112
		return (ITargetPlatformService) MacroPlugin.getBundleContext().getService(reference);
112
	}
113
	}
113
	
114
114
	/**
115
	/**
115
	 * Returns a default target platform that takes target weaving into account
116
	 * Tests that a target definition equivalent to the default target platform
116
	 * if in a second instance of Eclipse. This allows the target platfrom to be 
117
	 * contains the same bundles as the default target platform (this is an 
117
	 * reset after changing it in a test.
118
	 * explicit location with no target weaving).
118
	 * 
119
	 * 
119
	 * @return default settings for target platform
120
	 * @throws Exception
120
	 */
121
	 */
121
	protected ITargetDefinition getDefaultTargetPlatorm() {
122
	public void testDefaultTargetPlatform() throws Exception {
122
		ITargetDefinition definition = getTargetService().newTarget();
123
		// the new way
123
		IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(),
124
		ITargetDefinition definition = getTargetService().newTarget();
124
				new File(Platform.getConfigurationLocation().getURL().getFile()).getAbsolutePath());
125
		IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation());
125
		definition.setBundleContainers(new IBundleContainer[]{container});
126
		definition.setBundleContainers(new IBundleContainer[]{container});
126
		return definition;
127
		Set urls = getAllBundleURLs(definition);
127
	}
128
		
128
	
129
		// the old way
129
	/**
130
		IPath location = new Path(TargetPlatform.getDefaultLocation());
130
	 * Used to reset the target platform to original settings after a test that changes
131
		URL[] pluginPaths = P2Utils.readBundlesTxt(location.toOSString(), location.append("configuration").toFile().toURL());
131
	 * the target platform.
132
		assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
132
	 */
133
		for (int i = 0; i < pluginPaths.length; i++) {
133
	protected void resetTargetPlatform() {
134
			URL url = pluginPaths[i];
134
		ITargetDefinition definition = getDefaultTargetPlatorm();
135
			assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
135
		setTargetPlatform(definition);
136
		}
136
	}
137
		
137
	
138
	}
138
	/**
139
	
139
	 * Sets the target platform based on the given definition.
140
	/**
140
	 * 
141
	 * Tests that a target definition equivalent to the default target platform
141
	 * @param target target definition
142
	 * contains the same bundles as the default target platform using the
142
	 */
143
	 * platform's configuration location (which will do target weaving). This
143
	protected void setTargetPlatform(ITargetDefinition target) {
144
	 * is really only tested when run as a JUnit plug-in test suite from
144
		LoadTargetDefinitionJob job = new LoadTargetDefinitionJob(target);
145
	 * within Eclipse.
145
		job.schedule();
146
	 * 
146
		try {
147
	 * @throws Exception
147
			job.join();
148
	 */
148
		} catch (InterruptedException e) {
149
	public void testWovenTargetPlatform() throws Exception {
149
			assertFalse("Target platform reset interrupted", true);
150
		// the new way
150
		}
151
		ITargetDefinition definition = getTargetService().newTarget();
151
	}	
152
		IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(),
152
	
153
				new File(Platform.getConfigurationLocation().getURL().getFile()).getAbsolutePath());
153
	/**
154
		definition.setBundleContainers(new IBundleContainer[]{container});
154
	 * Tests that resetting the target platform should work OK (i.e. is equivalent to the
155
		Set urls = getAllBundleURLs(definition);
155
	 * models in the default target platform).
156
		
156
	 * 
157
		// the old way
157
	 * @throws CoreException
158
		URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation());
158
	 */
159
		assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
159
	public void testResetTargetPlatform() throws Exception {
160
		for (int i = 0; i < pluginPaths.length; i++) {
160
		ITargetDefinition definition = getDefaultTargetPlatorm();
161
			URL url = pluginPaths[i];
161
		Set urls = getAllBundleURLs(definition);
162
			assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
162
		
163
		}
163
		// current platform
164
		
164
		IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();
165
	}	
165
		
166
166
		// should be equivalent
167
	/**
167
		assertEquals("Should have same number of bundles", urls.size(), models.length);
168
	 * Tests that a bundle directory container is equivalent to scanning locations.
168
		for (int i = 0; i < models.length; i++) {
169
	 * 
169
			String location = models[i].getInstallLocation();
170
	 * @throws Exception
170
			assertTrue("Missing plug-in " + location, urls.contains(new File(location).toURL()));
171
	 */
171
		}
172
	public void testDirectoryBundleContainer() throws Exception {
172
	}	
173
		// the new way
173
174
		ITargetDefinition definition = getTargetService().newTarget();
174
	/**
175
		IBundleContainer container = getTargetService().newDirectoryContainer(TargetPlatform.getDefaultLocation() + "/plugins");
175
	 * Tests that a target definition equivalent to the default target platform
176
		definition.setBundleContainers(new IBundleContainer[]{container});
176
	 * contains the same bundles as the default target platform (this is an 
177
		Set urls = getAllBundleURLs(definition);
177
	 * explicit location with no target weaving).
178
		
178
	 * 
179
		Preferences store = PDECore.getDefault().getPluginPreferences();
179
	 * @throws Exception
180
		boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
180
	 */
181
		try {
181
	public void testDefaultTargetPlatform() throws Exception {
182
			store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
182
		// the new way
183
			// the old way
183
		ITargetDefinition definition = getTargetService().newTarget();
184
			URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation());
184
		IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation());
185
			assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
185
		definition.setBundleContainers(new IBundleContainer[]{container});
186
			for (int i = 0; i < pluginPaths.length; i++) {
186
		Set urls = getAllBundleURLs(definition);
187
				URL url = pluginPaths[i];
187
		
188
				assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
188
		// the old way
189
			}
189
		IPath location = new Path(TargetPlatform.getDefaultLocation());
190
		}
190
		URL[] pluginPaths = P2Utils.readBundlesTxt(location.toOSString(), location.append("configuration").toFile().toURL());
191
		finally {
191
		assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
192
			store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
192
		for (int i = 0; i < pluginPaths.length; i++) {
193
		}
193
			URL url = pluginPaths[i];
194
	}
194
			assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
195
	
195
		}
196
	/**
196
		
197
	 * Tests reading a 3.0.2 install with a mix of classic and OSGi plug-ins.
197
	}
198
	 * 
198
	
199
	 * @throws Exception
199
	/**
200
	 */
200
	 * Tests that a target definition equivalent to the default target platform
201
	public void testClassicPlugins() throws Exception {
201
	 * contains the same bundles as the default target platform (this is an 
202
		// extract the 3.0.2 skeleton
202
	 * explicit location with no target weaving), when created with a variable
203
		IPath location = extractClassicPlugins();
203
	 * referencing ${eclipse_home}
204
		
204
	 * 
205
		// the new way
205
	 * @throws Exception
206
		ITargetDefinition definition = getTargetService().newTarget();
206
	 */
207
		IBundleContainer container = getTargetService().newDirectoryContainer(location.toOSString());
207
	public void testEclipseHomeTargetPlatform() throws Exception {
208
		definition.setBundleContainers(new IBundleContainer[]{container});
208
		// the new way
209
		Set urls = getAllBundleURLs(definition);
209
		ITargetDefinition definition = getTargetService().newTarget();
210
		
210
		IBundleContainer container = getTargetService().newProfileContainer("${eclipse_home}");
211
		Preferences store = PDECore.getDefault().getPluginPreferences();
211
		definition.setBundleContainers(new IBundleContainer[]{container});
212
		boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
212
		Set urls = getAllBundleURLs(definition);
213
		try {
213
		
214
			store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
214
		// the old way
215
			// the old way
215
		IPath location = new Path(TargetPlatform.getDefaultLocation());
216
			URL[] pluginPaths = PluginPathFinder.getPluginPaths(location.toOSString());
216
		URL[] pluginPaths = P2Utils.readBundlesTxt(location.toOSString(), location.append("configuration").toFile().toURL());
217
			for (int i = 0; i < pluginPaths.length; i++) {
217
		assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
218
				URL url = pluginPaths[i];
218
		for (int i = 0; i < pluginPaths.length; i++) {
219
				if (!urls.contains(url)) {
219
			URL url = pluginPaths[i];
220
					System.err.println(url.toString());
220
			assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
221
				}
221
		}
222
			}
222
		
223
			assertEquals("Wrong number of bundles", pluginPaths.length, urls.size());
223
	}	
224
		}
224
	
225
		finally {
225
	/**
226
			store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
226
	 * Tests that a target definition equivalent to the default target platform
227
		}		
227
	 * contains the same bundles as the default target platform (this is an 
228
	}
228
	 * explicit location with no target weaving), when created with a variable
229
	
229
	 * referencing ${eclipse_home}.
230
	/**
230
	 * 
231
	 * Tests identification of source bundles in a 3.0.2 install.
231
	 * @throws Exception
232
	 * 
232
	 */
233
	 * @throws Exception
233
	public void testEclipseHomeTargetPlatformAndConfigurationArea() throws Exception {
234
	 */
234
		// the new way
235
	public void testClassicSourcePlugins() throws Exception {
235
		ITargetDefinition definition = getTargetService().newTarget();
236
		// extract the 3.0.2 skeleton
236
		IBundleContainer container = getTargetService().newProfileContainer("${eclipse_home}", "${eclipse_home}/configuration");
237
		IPath location = extractClassicPlugins();
237
		definition.setBundleContainers(new IBundleContainer[]{container});
238
		
238
		Set urls = getAllBundleURLs(definition);
239
		// the new way
239
		
240
		ITargetDefinition definition = getTargetService().newTarget();
240
		// the old way
241
		IBundleContainer container = getTargetService().newDirectoryContainer(location.toOSString());
241
		IPath location = new Path(TargetPlatform.getDefaultLocation());
242
		definition.setBundleContainers(new IBundleContainer[]{container});
242
		URL[] pluginPaths = P2Utils.readBundlesTxt(location.toOSString(), location.append("configuration").toFile().toURL());
243
		BundleInfo[] bundles = definition.resolveSourceBundles(null);
243
		assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
244
		assertEquals("Wrong number of source bundles", 3, bundles.length);
244
		for (int i = 0; i < pluginPaths.length; i++) {
245
		Set names = new HashSet();
245
			URL url = pluginPaths[i];
246
		for (int i = 0; i < bundles.length; i++) {
246
			assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
247
			names.add(bundles[i].getSymbolicName());
247
		}
248
		}
248
		
249
		String[] expected = new String[]{"org.eclipse.platform.source", "org.eclipse.jdt.source", "org.eclipse.pde.source"};
249
	}		
250
		for (int i = 0; i < expected.length; i++) {
250
	
251
			assertTrue("Missing source for " + expected[i], names.contains(expected[i]));	
251
	/**
252
		}
252
	 * Tests that a target definition equivalent to the default target platform
253
	}
253
	 * contains the same bundles as the default target platform using the
254
254
	 * platform's configuration location (which will do target weaving). This
255
	/**
255
	 * is really only tested when run as a JUnit plug-in test suite from
256
	 * Returns the given input stream as a byte array
256
	 * within Eclipse.
257
	 * @param stream the stream to get as a byte array
257
	 * 
258
	 * @param length the length to read from the stream or -1 for unknown
258
	 * @throws Exception
259
	 * @return the given input stream as a byte array
259
	 */
260
	 * @throws IOException
260
	public void testWovenTargetPlatform() throws Exception {
261
	 */
261
		// the new way
262
	public static byte[] getInputStreamAsByteArray(InputStream stream, int length) throws IOException {
262
		ITargetDefinition definition = getTargetService().newTarget();
263
		byte[] contents;
263
		IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(),
264
		if (length == -1) {
264
				new File(Platform.getConfigurationLocation().getURL().getFile()).getAbsolutePath());
265
			contents = new byte[0];
265
		definition.setBundleContainers(new IBundleContainer[]{container});
266
			int contentsLength = 0;
266
		Set urls = getAllBundleURLs(definition);
267
			int amountRead = -1;
267
		
268
			do {
268
		// the old way
269
				// read at least 8K
269
		URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation());
270
				int amountRequested = Math.max(stream.available(), 8192);
270
		assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
271
				// resize contents if needed
271
		for (int i = 0; i < pluginPaths.length; i++) {
272
				if (contentsLength + amountRequested > contents.length) {
272
			URL url = pluginPaths[i];
273
					System.arraycopy(contents,
273
			assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
274
							0,
274
		}
275
							contents = new byte[contentsLength + amountRequested],
275
		
276
							0,
276
	}	
277
							contentsLength);
277
278
				}
278
	/**
279
				// read as many bytes as possible
279
	 * Tests that a bundle directory container is equivalent to scanning locations.
280
				amountRead = stream.read(contents, contentsLength, amountRequested);
280
	 * 
281
				if (amountRead > 0) {
281
	 * @throws Exception
282
					// remember length of contents
282
	 */
283
					contentsLength += amountRead;
283
	public void testDirectoryBundleContainer() throws Exception {
284
				}
284
		// the new way
285
			} while (amountRead != -1);
285
		ITargetDefinition definition = getTargetService().newTarget();
286
			// resize contents if necessary
286
		IBundleContainer container = getTargetService().newDirectoryContainer(TargetPlatform.getDefaultLocation() + "/plugins");
287
			if (contentsLength < contents.length) {
287
		definition.setBundleContainers(new IBundleContainer[]{container});
288
				System.arraycopy(contents, 0, contents = new byte[contentsLength], 0, contentsLength);
288
		Set urls = getAllBundleURLs(definition);
289
			}
289
		
290
		} else {
290
		Preferences store = PDECore.getDefault().getPluginPreferences();
291
			contents = new byte[length];
291
		boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
292
			int len = 0;
292
		try {
293
			int readSize = 0;
293
			store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
294
			while ((readSize != -1) && (len != length)) {
294
			// the old way
295
				// See PR 1FMS89U
295
			URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation());
296
				// We record first the read size. In this case length is the actual
296
			assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
297
				// read size.
297
			for (int i = 0; i < pluginPaths.length; i++) {
298
				len += readSize;
298
				URL url = pluginPaths[i];
299
				readSize = stream.read(contents, len, length - len);
299
				assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
300
			}
300
			}
301
		}
301
		}
302
		return contents;
302
		finally {
303
	}	
303
			store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
304
	
304
		}
305
	/**
305
	}
306
	 * Tests restoration of a handle to target definition in an IFile 
306
	
307
	 * @throws CoreException 
307
	/**
308
	 */
308
	 * Tests that a bundle directory container is equivalent to scanning locations
309
	public void testWorkspaceTargetHandleMemento() throws CoreException {
309
	 * when it uses a variable to specify its location.
310
		ITargetPlatformService service = getTargetService();
310
	 * 
311
		IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("does/not/exist"));
311
	 * @throws Exception
312
		ITargetHandle handle = service.getTarget(file);
312
	 */
313
		assertFalse("Target should not exist", handle.exists());
313
	public void testVariableDirectoryBundleContainer() throws Exception {
314
		String memento = handle.getMemento();
314
		// the new way
315
		assertNotNull("Missing memento", memento);
315
		ITargetDefinition definition = getTargetService().newTarget();
316
		ITargetHandle handle2 = service.getTarget(memento);
316
		IBundleContainer container = getTargetService().newDirectoryContainer("${eclipse_home}/plugins");
317
		assertEquals("Restore failed", handle, handle2);
317
		definition.setBundleContainers(new IBundleContainer[]{container});
318
		IFile file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("does/not/exist/either"));
318
		Set urls = getAllBundleURLs(definition);
319
		ITargetHandle handle3 = service.getTarget(file2);
319
		
320
		assertFalse("Should be different targets", handle.equals(handle3));
320
		Preferences store = PDECore.getDefault().getPluginPreferences();
321
	}
321
		boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
322
	
322
		try {
323
	/**
323
			store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
324
	 * Tests restoration of a handle to target definition in local metadata 
324
			// the old way
325
	 * 
325
			URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation());
326
	 * @throws CoreException 
326
			assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
327
	 * @throws InterruptedException 
327
			for (int i = 0; i < pluginPaths.length; i++) {
328
	 */
328
				URL url = pluginPaths[i];
329
	public void testLocalTargetHandleMemento() throws CoreException, InterruptedException {
329
				assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
330
		ITargetPlatformService service = getTargetService();
330
			}
331
		ITargetHandle handle = service.newTarget().getHandle();
331
		}
332
		assertFalse("Target should not exist", handle.exists());
332
		finally {
333
		String memento = handle.getMemento();
333
			store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
334
		assertNotNull("Missing memento", memento);
334
		}
335
		ITargetHandle handle2 = service.getTarget(memento);
335
	}	
336
		assertEquals("Restore failed", handle, handle2);
336
	
337
		ITargetHandle handle3 = service.newTarget().getHandle();
337
	/**
338
		assertFalse("Should be different targets", handle.equals(handle3));
338
	 * Tests reading a 3.0.2 install with a mix of classic and OSGi plug-ins.
339
	}	
339
	 * 
340
}
340
	 * @throws Exception
341
	 */
342
	public void testClassicPlugins() throws Exception {
343
		// extract the 3.0.2 skeleton
344
		IPath location = extractClassicPlugins();
345
		
346
		// the new way
347
		ITargetDefinition definition = getTargetService().newTarget();
348
		IBundleContainer container = getTargetService().newDirectoryContainer(location.toOSString());
349
		definition.setBundleContainers(new IBundleContainer[]{container});
350
		Set urls = getAllBundleURLs(definition);
351
		
352
		Preferences store = PDECore.getDefault().getPluginPreferences();
353
		boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
354
		try {
355
			store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
356
			// the old way
357
			URL[] pluginPaths = PluginPathFinder.getPluginPaths(location.toOSString());
358
			for (int i = 0; i < pluginPaths.length; i++) {
359
				URL url = pluginPaths[i];
360
				if (!urls.contains(url)) {
361
					System.err.println(url.toString());
362
				}
363
			}
364
			assertEquals("Wrong number of bundles", pluginPaths.length, urls.size());
365
		}
366
		finally {
367
			store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
368
		}		
369
	}
370
	
371
	/**
372
	 * Tests identification of source bundles in a 3.0.2 install.
373
	 * 
374
	 * @throws Exception
375
	 */
376
	public void testClassicSourcePlugins() throws Exception {
377
		// extract the 3.0.2 skeleton
378
		IPath location = extractClassicPlugins();
379
		
380
		// the new way
381
		ITargetDefinition definition = getTargetService().newTarget();
382
		IBundleContainer container = getTargetService().newDirectoryContainer(location.toOSString());
383
		definition.setBundleContainers(new IBundleContainer[]{container});
384
		BundleInfo[] bundles = definition.resolveSourceBundles(null);
385
		assertEquals("Wrong number of source bundles", 3, bundles.length);
386
		Set names = new HashSet();
387
		for (int i = 0; i < bundles.length; i++) {
388
			names.add(bundles[i].getSymbolicName());
389
		}
390
		String[] expected = new String[]{"org.eclipse.platform.source", "org.eclipse.jdt.source", "org.eclipse.pde.source"};
391
		for (int i = 0; i < expected.length; i++) {
392
			assertTrue("Missing source for " + expected[i], names.contains(expected[i]));	
393
		}
394
	}
395
396
	/**
397
	 * Returns the given input stream as a byte array
398
	 * @param stream the stream to get as a byte array
399
	 * @param length the length to read from the stream or -1 for unknown
400
	 * @return the given input stream as a byte array
401
	 * @throws IOException
402
	 */
403
	public static byte[] getInputStreamAsByteArray(InputStream stream, int length) throws IOException {
404
		byte[] contents;
405
		if (length == -1) {
406
			contents = new byte[0];
407
			int contentsLength = 0;
408
			int amountRead = -1;
409
			do {
410
				// read at least 8K
411
				int amountRequested = Math.max(stream.available(), 8192);
412
				// resize contents if needed
413
				if (contentsLength + amountRequested > contents.length) {
414
					System.arraycopy(contents,
415
							0,
416
							contents = new byte[contentsLength + amountRequested],
417
							0,
418
							contentsLength);
419
				}
420
				// read as many bytes as possible
421
				amountRead = stream.read(contents, contentsLength, amountRequested);
422
				if (amountRead > 0) {
423
					// remember length of contents
424
					contentsLength += amountRead;
425
				}
426
			} while (amountRead != -1);
427
			// resize contents if necessary
428
			if (contentsLength < contents.length) {
429
				System.arraycopy(contents, 0, contents = new byte[contentsLength], 0, contentsLength);
430
			}
431
		} else {
432
			contents = new byte[length];
433
			int len = 0;
434
			int readSize = 0;
435
			while ((readSize != -1) && (len != length)) {
436
				// See PR 1FMS89U
437
				// We record first the read size. In this case length is the actual
438
				// read size.
439
				len += readSize;
440
				readSize = stream.read(contents, len, length - len);
441
			}
442
		}
443
		return contents;
444
	}	
445
	
446
	/**
447
	 * Tests restoration of a handle to target definition in an IFile 
448
	 * @throws CoreException 
449
	 */
450
	public void testWorkspaceTargetHandleMemento() throws CoreException {
451
		ITargetPlatformService service = getTargetService();
452
		IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("does/not/exist"));
453
		ITargetHandle handle = service.getTarget(file);
454
		assertFalse("Target should not exist", handle.exists());
455
		String memento = handle.getMemento();
456
		assertNotNull("Missing memento", memento);
457
		ITargetHandle handle2 = service.getTarget(memento);
458
		assertEquals("Restore failed", handle, handle2);
459
		IFile file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("does/not/exist/either"));
460
		ITargetHandle handle3 = service.getTarget(file2);
461
		assertFalse("Should be different targets", handle.equals(handle3));
462
	}
463
	
464
	/**
465
	 * Tests restoration of a handle to target definition in local metadata 
466
	 * 
467
	 * @throws CoreException 
468
	 * @throws InterruptedException 
469
	 */
470
	public void testLocalTargetHandleMemento() throws CoreException, InterruptedException {
471
		ITargetPlatformService service = getTargetService();
472
		ITargetHandle handle = service.newTarget().getHandle();
473
		assertFalse("Target should not exist", handle.exists());
474
		String memento = handle.getMemento();
475
		assertNotNull("Missing memento", memento);
476
		ITargetHandle handle2 = service.getTarget(memento);
477
		assertEquals("Restore failed", handle, handle2);
478
		ITargetHandle handle3 = service.newTarget().getHandle();
479
		assertFalse("Should be different targets", handle.equals(handle3));
480
	}
481
	
482
	/**
483
	 * Returns the location of the JDT feature in the running host as
484
	 * a path in the local file system.
485
	 * 
486
	 * @return path to JDT feature
487
	 */
488
	protected IPath getJdtFeatureLocation() {
489
		IPath path = new Path(TargetPlatform.getDefaultLocation());
490
		path = path.append("features");
491
		File dir = path.toFile();
492
		assertTrue("Missing features directory", dir.exists() && !dir.isFile());
493
		String[] files = dir.list();
494
		String location = null;
495
		for (int i = 0; i < files.length; i++) {
496
			if (files[i].startsWith("org.eclipse.jdt_")) {
497
				location = path.append(files[i]).toOSString();
498
				break;
499
			}
500
		}
501
		assertNotNull("Missing JDT feature", location);
502
		return new Path(location);
503
	}
504
	
505
	/**
506
	 * Tests a JDT feature bundle container contains the appropriate bundles
507
	 * @throws Exception 
508
	 */
509
	public void testFeatureBundleContainer() throws Exception {
510
		IBundleContainer container = getTargetService().newFeatureContainer("${eclipse_home}", "org.eclipse.jdt", null);
511
		BundleInfo[] bundles = container.resolveBundles(null);
512
		
513
		Set expected = new HashSet();
514
		expected.add("org.eclipse.jdt");
515
		expected.add("org.eclipse.ant.ui");
516
		expected.add("org.eclipse.jdt.apt.core");
517
		expected.add("org.eclipse.jdt.apt.ui");
518
		expected.add("org.eclipse.jdt.apt.pluggable.core");
519
		expected.add("org.eclipse.jdt.compiler.apt");
520
		expected.add("org.eclipse.jdt.compiler.tool");
521
		expected.add("org.eclipse.jdt.core");
522
		expected.add("org.eclipse.jdt.core.manipulation");
523
		expected.add("org.eclipse.jdt.debug.ui");
524
		expected.add("org.eclipse.jdt.debug");
525
		expected.add("org.eclipse.jdt.junit");
526
		expected.add("org.eclipse.jdt.junit.runtime");
527
		expected.add("org.eclipse.jdt.junit4.runtime");
528
		expected.add("org.eclipse.jdt.launching");
529
		expected.add("org.eclipse.jdt.ui");
530
		expected.add("org.junit");
531
		expected.add("org.junit4");
532
		expected.add("org.eclipse.jdt.doc.user");
533
		if (Platform.getOS() == Platform.OS_MACOSX) {
534
			expected.add("org.eclipse.jdt.launching.macosx");
535
		}
536
		assertEquals("Wrong number of bundles in JDT feature", expected.size(), bundles.length);
537
		for (int i = 0; i < bundles.length; i++) {
538
			expected.remove(bundles[i].getSymbolicName());
539
		}
540
		Iterator iterator = expected.iterator();
541
		while (iterator.hasNext()) {
542
			String name = (String) iterator.next();
543
			System.err.println("Missing: " + name);
544
		}
545
		assertTrue("Wrong bundles in JDT feature", expected.isEmpty());
546
		
547
		
548
		// should be no source bundles
549
		bundles = container.resolveSourceBundles(null);
550
		assertEquals("Wrong source bundle count", 0, bundles.length);
551
	}
552
	
553
	/**
554
	 * Tests a JDT source feature bundle container contains the appropriate bundles
555
	 * @throws Exception 
556
	 */
557
	public void testSourceFeatureBundleContainer() throws Exception {
558
		IBundleContainer container = getTargetService().newFeatureContainer("${eclipse_home}", "org.eclipse.jdt.source", null);
559
		BundleInfo[] bundles = container.resolveSourceBundles(null);
560
		
561
		Set expected = new HashSet();
562
		expected.add("org.eclipse.jdt.source");
563
		expected.add("org.eclipse.ant.ui.source");
564
		expected.add("org.eclipse.jdt.apt.core.source");
565
		expected.add("org.eclipse.jdt.apt.ui.source");
566
		expected.add("org.eclipse.jdt.apt.pluggable.core.source");
567
		expected.add("org.eclipse.jdt.compiler.apt.source");
568
		expected.add("org.eclipse.jdt.compiler.tool.source");
569
		expected.add("org.eclipse.jdt.core.source");
570
		expected.add("org.eclipse.jdt.core.manipulation.source");
571
		expected.add("org.eclipse.jdt.debug.ui.source");
572
		expected.add("org.eclipse.jdt.debug.source");
573
		expected.add("org.eclipse.jdt.junit.source");
574
		expected.add("org.eclipse.jdt.junit.runtime.source");
575
		expected.add("org.eclipse.jdt.junit4.runtime.source");
576
		expected.add("org.eclipse.jdt.launching.source");
577
		expected.add("org.eclipse.jdt.ui.source");
578
		expected.add("org.junit.source");
579
		expected.add("org.junit4.source");
580
		if (Platform.getOS() == Platform.OS_MACOSX) {
581
			expected.add("org.eclipse.jdt.launching.macosx.source");
582
		}
583
		for (int i = 0; i < bundles.length; i++) {
584
			expected.remove(bundles[i].getSymbolicName());
585
		}
586
		Iterator iterator = expected.iterator();
587
		while (iterator.hasNext()) {
588
			String name = (String) iterator.next();
589
			System.err.println("Missing: " + name);
590
		}
591
		assertTrue("Wrong bundles in JDT feature", expected.isEmpty());
592
		
593
		
594
		// should be one doc bundle
595
		bundles = container.resolveBundles(null);
596
		assertEquals("Wrong bundle count", 1, bundles.length);
597
		assertEquals("Missing bundle", "org.eclipse.jdt.doc.isv", bundles[0].getSymbolicName());
598
	}
599
	
600
	
601
	/**
602
	 * Tests setting the target platform to the JDT feature with a specific version.
603
	 * 
604
	 * @throws Exception 
605
	 */
606
	public void testSetTargetPlatformToJdtFeature() throws Exception {
607
		try {
608
			IPath location = getJdtFeatureLocation();
609
			String segment = location.lastSegment();
610
			int index = segment.indexOf('_');
611
			assertTrue("Missing version id", index > 0);
612
			String version = segment.substring(index + 1);
613
			ITargetPlatformService targetService = getTargetService();
614
			IBundleContainer container = targetService.newFeatureContainer("${eclipse_home}", "org.eclipse.jdt", version);
615
			ITargetDefinition target = targetService.newTarget();
616
			target.setBundleContainers(new IBundleContainer[]{container});
617
			
618
			setTargetPlatform(target);
619
			
620
			Set expected = new HashSet();
621
			expected.add("org.eclipse.jdt");
622
			expected.add("org.eclipse.ant.ui");
623
			expected.add("org.eclipse.jdt.apt.core");
624
			expected.add("org.eclipse.jdt.apt.ui");
625
			expected.add("org.eclipse.jdt.apt.pluggable.core");
626
			expected.add("org.eclipse.jdt.compiler.apt");
627
			expected.add("org.eclipse.jdt.compiler.tool");
628
			expected.add("org.eclipse.jdt.core");
629
			expected.add("org.eclipse.jdt.core.manipulation");
630
			expected.add("org.eclipse.jdt.debug.ui");
631
			expected.add("org.eclipse.jdt.debug");
632
			expected.add("org.eclipse.jdt.junit");
633
			expected.add("org.eclipse.jdt.junit.runtime");
634
			expected.add("org.eclipse.jdt.junit4.runtime");
635
			expected.add("org.eclipse.jdt.launching");
636
			expected.add("org.eclipse.jdt.ui");
637
			expected.add("org.junit");
638
			expected.add("org.junit4");
639
			expected.add("org.eclipse.jdt.doc.user");
640
			if (Platform.getOS() == Platform.OS_MACOSX) {
641
				expected.add("org.eclipse.jdt.launching.macosx");
642
			}
643
			
644
			// current platform
645
			IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();
646
			
647
			assertEquals("Wrong number of bundles in JDT feature", expected.size(), models.length);
648
			for (int i = 0; i < models.length; i++) {
649
				expected.remove(models[i].getPluginBase().getId());
650
			}
651
			Iterator iterator = expected.iterator();
652
			while (iterator.hasNext()) {
653
				String name = (String) iterator.next();
654
				System.err.println("Missing: " + name);
655
			}
656
			assertTrue("Wrong bundles in target platform", expected.isEmpty());
657
		} finally {
658
			resetTargetPlatform();
659
		}
660
	}	
661
	
662
	/**
663
	 * Tests setting the target platform to empty.
664
	 */
665
	public void testSetEmptyTargetPlatform() {
666
		try {
667
			ITargetPlatformService targetService = getTargetService();
668
			ITargetDefinition target = targetService.newTarget();
669
			
670
			setTargetPlatform(target);
671
						
672
			// current platform
673
			IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();
674
			
675
			assertEquals("Wrong number of bundles in empty target", 0, models.length);
676
677
		} finally {
678
			resetTargetPlatform();
679
		}		
680
	}
681
}
(-)src/org/eclipse/pde/internal/core/target/impl/DirectoryBundleContainer.java (-289 / +291 lines)
Lines 1-289 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.target.impl;
11
package org.eclipse.pde.internal.core.target.impl;
12
12
13
import java.io.*;
13
import java.io.*;
14
import java.util.*;
14
import java.util.*;
15
import java.util.jar.JarFile;
15
import java.util.jar.JarFile;
16
import java.util.zip.ZipEntry;
16
import java.util.zip.ZipEntry;
17
import java.util.zip.ZipFile;
17
import java.util.zip.ZipFile;
18
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.spi.RegistryContributor;
19
import org.eclipse.core.runtime.spi.RegistryContributor;
20
import org.eclipse.core.variables.IStringVariableManager;
20
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
21
import org.eclipse.core.variables.VariablesPlugin;
21
import org.eclipse.osgi.service.pluginconversion.PluginConversionException;
22
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
22
import org.eclipse.osgi.service.pluginconversion.PluginConverter;
23
import org.eclipse.osgi.service.pluginconversion.PluginConversionException;
23
import org.eclipse.osgi.util.ManifestElement;
24
import org.eclipse.osgi.service.pluginconversion.PluginConverter;
24
import org.eclipse.osgi.util.NLS;
25
import org.eclipse.osgi.util.ManifestElement;
25
import org.eclipse.pde.internal.core.ICoreConstants;
26
import org.eclipse.osgi.util.NLS;
26
import org.eclipse.pde.internal.core.PDECore;
27
import org.eclipse.pde.internal.core.ICoreConstants;
27
import org.osgi.framework.BundleException;
28
import org.eclipse.pde.internal.core.PDECore;
28
import org.osgi.framework.Constants;
29
import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
29
30
import org.osgi.framework.BundleException;
30
/**
31
import org.osgi.framework.Constants;
31
 * A directory of bundles.
32
32
 * 
33
/**
33
 * @since 3.5
34
 * A directory of bundles.
34
 */
35
 * 
35
class DirectoryBundleContainer extends AbstractBundleContainer {
36
 * @since 3.5
36
37
 */
37
	/**
38
class DirectoryBundleContainer implements IBundleContainer {
38
	 * Path to this container's directory in the local file system.
39
39
	 * The path may contain string substitution variables.
40
	/**
40
	 */
41
	 * Path to this container's directory in the local file system.
41
	private String fPath;
42
	 * The path may contain string substitution variables.
42
43
	 */
43
	/**
44
	private String fPath;
44
	 * A registry can be built to identify old school source bundles.
45
45
	 */
46
	/**
46
	private IExtensionRegistry fRegistry;
47
	 * A registry can be build to identify old school source bundles.
47
48
	 */
48
	/**
49
	private IExtensionRegistry fRegistry;
49
	 * Constructs a directory bundle container at the given location.
50
50
	 * 
51
	/**
51
	 * @param path directory location in the local file system, may contain string substitution variables
52
	 * Constructs a directory bundle container at the given location.
52
	 */
53
	 * 
53
	public DirectoryBundleContainer(String path) {
54
	 * @param path directory location in the local file system
54
		fPath = path;
55
	 */
55
	}
56
	public DirectoryBundleContainer(String path) {
56
57
		fPath = path;
57
	/* (non-Javadoc)
58
	}
58
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#getHomeLocation()
59
59
	 */
60
	/* (non-Javadoc)
60
	public String getHomeLocation() throws CoreException {
61
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
61
		return getDirectory().toString();
62
	 */
62
	}
63
	public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
63
64
		return resolveBundles(monitor, false);
64
	/* (non-Javadoc)
65
	}
65
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
66
66
	 */
67
	/* (non-Javadoc)
67
	public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
68
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
68
		return resolveBundles(monitor, false);
69
	 */
69
	}
70
	public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
70
71
		return resolveBundles(monitor, true);
71
	/* (non-Javadoc)
72
	}
72
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
73
73
	 */
74
	/**
74
	public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
75
	 * Resolves and returns source or code bundles based on the given flag.
75
		return resolveBundles(monitor, true);
76
	 * 
76
	}
77
	 * @param monitor progress monitor or <code>null</code>
77
78
	 * @param source whether to retrieve source bundles
78
	/**
79
	 * @return bundles
79
	 * Resolves and returns source or code bundles based on the given flag.
80
	 * @throws CoreException
80
	 * 
81
	 */
81
	 * @param monitor progress monitor or <code>null</code>
82
	private BundleInfo[] resolveBundles(IProgressMonitor monitor, boolean source) throws CoreException {
82
	 * @param source whether to retrieve source bundles
83
		File dir = getDirectory();
83
	 * @return bundles
84
		if (dir.exists() && dir.isDirectory()) {
84
	 * @throws CoreException
85
			try {
85
	 */
86
				File[] files = dir.listFiles();
86
	private BundleInfo[] resolveBundles(IProgressMonitor monitor, boolean source) throws CoreException {
87
				SubMonitor localMonitor = SubMonitor.convert(monitor, Messages.DirectoryBundleContainer_0, files.length);
87
		File dir = getDirectory();
88
				List bundles = new ArrayList(files.length);
88
		if (dir.exists() && dir.isDirectory()) {
89
				for (int i = 0; i < files.length; i++) {
89
			try {
90
					if (localMonitor.isCanceled()) {
90
				File[] files = dir.listFiles();
91
						throw new OperationCanceledException();
91
				SubMonitor localMonitor = SubMonitor.convert(monitor, Messages.DirectoryBundleContainer_0, files.length);
92
					}
92
				List bundles = new ArrayList(files.length);
93
					Map manifest = loadManifest(files[i]);
93
				for (int i = 0; i < files.length; i++) {
94
					if (manifest != null) {
94
					if (localMonitor.isCanceled()) {
95
						try {
95
						throw new OperationCanceledException();
96
							String header = (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME);
96
					}
97
							if (header != null) {
97
					Map manifest = loadManifest(files[i]);
98
								ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, header);
98
					if (manifest != null) {
99
								if (elements != null) {
99
						try {
100
									String name = elements[0].getValue();
100
							String header = (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME);
101
									if (name != null) {
101
							if (header != null) {
102
										BundleInfo info = new BundleInfo();
102
								ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, header);
103
										info.setSymbolicName(name);
103
								if (elements != null) {
104
										info.setLocation(files[i].toURI());
104
									String name = elements[0].getValue();
105
										header = (String) manifest.get(Constants.BUNDLE_VERSION);
105
									if (name != null) {
106
										if (header != null) {
106
										BundleInfo info = new BundleInfo();
107
											elements = ManifestElement.parseHeader(Constants.BUNDLE_VERSION, header);
107
										info.setSymbolicName(name);
108
											if (elements != null) {
108
										info.setLocation(files[i].toURI());
109
												info.setVersion(elements[0].getValue());
109
										header = (String) manifest.get(Constants.BUNDLE_VERSION);
110
											}
110
										if (header != null) {
111
										}
111
											elements = ManifestElement.parseHeader(Constants.BUNDLE_VERSION, header);
112
										if (source == isSourceBundle(files[i], name, manifest)) {
112
											if (elements != null) {
113
											bundles.add(info);
113
												info.setVersion(elements[0].getValue());
114
										}
114
											}
115
									}
115
										}
116
								}
116
										if (source == isSourceBundle(files[i], name, manifest)) {
117
							}
117
											bundles.add(info);
118
						} catch (BundleException e) {
118
										}
119
							// ignore invalid bundles
119
									}
120
						}
120
								}
121
					}
121
							}
122
					localMonitor.worked(1);
122
						} catch (BundleException e) {
123
				}
123
							// ignore invalid bundles
124
				localMonitor.done();
124
						}
125
				return (BundleInfo[]) bundles.toArray(new BundleInfo[bundles.size()]);
125
					}
126
			} finally {
126
					localMonitor.worked(1);
127
				if (fRegistry != null) {
127
				}
128
					fRegistry.stop(this);
128
				localMonitor.done();
129
					fRegistry = null;
129
				return (BundleInfo[]) bundles.toArray(new BundleInfo[bundles.size()]);
130
				}
130
			} finally {
131
			}
131
				if (fRegistry != null) {
132
		}
132
					fRegistry.stop(this);
133
		throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_1, fPath)));
133
					fRegistry = null;
134
	}
134
				}
135
135
			}
136
	/**
136
		}
137
	 * Returns whether the given bundle is a source bundle.
137
		throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_1, dir.toString())));
138
	 * 
138
	}
139
	 * @param bundle location of the bundle in the file system
139
140
	 * @param symbolicName symbolic name of the bundle
140
	/**
141
	 * @param manifest the bundle's manifest
141
	 * Returns whether the given bundle is a source bundle.
142
	 * @return whether the given bundle is a source bundle
142
	 * 
143
	 */
143
	 * @param bundle location of the bundle in the file system
144
	private boolean isSourceBundle(File bundle, String symbolicName, Map manifest) {
144
	 * @param symbolicName symbolic name of the bundle
145
		if (manifest.containsKey(ICoreConstants.ECLIPSE_SOURCE_BUNDLE)) {
145
	 * @param manifest the bundle's manifest
146
			// this is the new source bundle identifier
146
	 * @return whether the given bundle is a source bundle
147
			return true;
147
	 */
148
		}
148
	private boolean isSourceBundle(File bundle, String symbolicName, Map manifest) {
149
		// old source bundles were never jar'd
149
		if (manifest.containsKey(ICoreConstants.ECLIPSE_SOURCE_BUNDLE)) {
150
		if (bundle.isFile()) {
150
			// this is the new source bundle identifier
151
			return false;
151
			return true;
152
		}
152
		}
153
		// source bundles never have a class path
153
		// old source bundles were never jar'd
154
		if (manifest.containsKey(Constants.BUNDLE_CLASSPATH)) {
154
		if (bundle.isFile()) {
155
			return false;
155
			return false;
156
		}
156
		}
157
		// check for an "org.eclipse.pde.core.source" extension 
157
		// source bundles never have a class path
158
		File pxml = new File(bundle, ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR);
158
		if (manifest.containsKey(Constants.BUNDLE_CLASSPATH)) {
159
		if (pxml.exists()) {
159
			return false;
160
			IExtensionRegistry registry = getRegistry();
160
		}
161
			RegistryContributor contributor = new RegistryContributor(symbolicName, symbolicName, null, null);
161
		// check for an "org.eclipse.pde.core.source" extension 
162
			try {
162
		File pxml = new File(bundle, ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR);
163
				registry.addContribution(new BufferedInputStream(new FileInputStream(pxml)), contributor, false, null, null, this);
163
		if (pxml.exists()) {
164
				IExtension[] extensions = registry.getExtensions(contributor);
164
			IExtensionRegistry registry = getRegistry();
165
				for (int i = 0; i < extensions.length; i++) {
165
			RegistryContributor contributor = new RegistryContributor(symbolicName, symbolicName, null, null);
166
					IExtension extension = extensions[i];
166
			try {
167
					if (ICoreConstants.EXTENSION_POINT_SOURCE.equals(extension.getExtensionPointUniqueIdentifier())) {
167
				registry.addContribution(new BufferedInputStream(new FileInputStream(pxml)), contributor, false, null, null, this);
168
						return true;
168
				IExtension[] extensions = registry.getExtensions(contributor);
169
					}
169
				for (int i = 0; i < extensions.length; i++) {
170
				}
170
					IExtension extension = extensions[i];
171
			} catch (FileNotFoundException e) {
171
					if (ICoreConstants.EXTENSION_POINT_SOURCE.equals(extension.getExtensionPointUniqueIdentifier())) {
172
			}
172
						return true;
173
		}
173
					}
174
		return false;
174
				}
175
	}
175
			} catch (FileNotFoundException e) {
176
176
			}
177
	/**
177
		}
178
	 * Returns an extension registry used to identify source bundles.
178
		return false;
179
	 * 
179
	}
180
	 * @return extension registry
180
181
	 */
181
	/**
182
	private IExtensionRegistry getRegistry() {
182
	 * Returns an extension registry used to identify source bundles.
183
		if (fRegistry == null) {
183
	 * 
184
			fRegistry = RegistryFactory.createRegistry(null, this, this);
184
	 * @return extension registry
185
			// contribute PDE source extension point
185
	 */
186
			String bogusDef = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?eclipse version=\"3.2\"?>\n<plugin><extension-point id=\"source\" name=\"source\"/>\n</plugin>"; //$NON-NLS-1$
186
	private IExtensionRegistry getRegistry() {
187
			RegistryContributor contributor = new RegistryContributor(PDECore.PLUGIN_ID, PDECore.PLUGIN_ID, null, null);
187
		if (fRegistry == null) {
188
			fRegistry.addContribution(new ByteArrayInputStream(bogusDef.getBytes()), contributor, false, null, null, this);
188
			fRegistry = RegistryFactory.createRegistry(null, this, this);
189
		}
189
			// contribute PDE source extension point
190
		return fRegistry;
190
			String bogusDef = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?eclipse version=\"3.2\"?>\n<plugin><extension-point id=\"source\" name=\"source\"/>\n</plugin>"; //$NON-NLS-1$
191
	}
191
			RegistryContributor contributor = new RegistryContributor(PDECore.PLUGIN_ID, PDECore.PLUGIN_ID, null, null);
192
192
			fRegistry.addContribution(new ByteArrayInputStream(bogusDef.getBytes()), contributor, false, null, null, this);
193
	/**
193
		}
194
	 * Returns the directory to search for bundles in.
194
		return fRegistry;
195
	 * 
195
	}
196
	 * @return directory if unable to resolve variables in the path
196
197
	 */
197
	/**
198
	protected File getDirectory() throws CoreException {
198
	 * Returns the directory to search for bundles in.
199
		String path = fPath;
199
	 * 
200
		IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
200
	 * @return directory if unable to resolve variables in the path
201
		path = manager.performStringSubstitution(fPath);
201
	 */
202
		return new File(path);
202
	protected File getDirectory() throws CoreException {
203
	}
203
		String path = resolveVariables(fPath);
204
204
		return new File(path);
205
	/**
205
	}
206
	 * Parses a bunlde's manifest into a dictionary. The bundle may be in a jar
206
207
	 * or in a directory at the specified location.
207
	/**
208
	 * 
208
	 * Parses a bunlde's manifest into a dictionary. The bundle may be in a jar
209
	 * @param bundleLocation root location of the bundle
209
	 * or in a directory at the specified location.
210
	 * @return bundle manifest dictionary or <code>null</code> if none
210
	 * 
211
	 * @throws CoreException if manifest has invalid syntax
211
	 * @param bundleLocation root location of the bundle
212
	 */
212
	 * @return bundle manifest dictionary or <code>null</code> if none
213
	protected Map loadManifest(File bundleLocation) throws CoreException {
213
	 * @throws CoreException if manifest has invalid syntax
214
		ZipFile jarFile = null;
214
	 */
215
		InputStream manifestStream = null;
215
	protected Map loadManifest(File bundleLocation) throws CoreException {
216
		String extension = new Path(bundleLocation.getName()).getFileExtension();
216
		ZipFile jarFile = null;
217
		try {
217
		InputStream manifestStream = null;
218
			if (extension != null && extension.equals("jar") && bundleLocation.isFile()) { //$NON-NLS-1$
218
		String extension = new Path(bundleLocation.getName()).getFileExtension();
219
				jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ);
219
		try {
220
				ZipEntry manifestEntry = jarFile.getEntry(JarFile.MANIFEST_NAME);
220
			if (extension != null && extension.equals("jar") && bundleLocation.isFile()) { //$NON-NLS-1$
221
				if (manifestEntry != null) {
221
				jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ);
222
					manifestStream = jarFile.getInputStream(manifestEntry);
222
				ZipEntry manifestEntry = jarFile.getEntry(JarFile.MANIFEST_NAME);
223
				}
223
				if (manifestEntry != null) {
224
			} else {
224
					manifestStream = jarFile.getInputStream(manifestEntry);
225
				File file = new File(bundleLocation, JarFile.MANIFEST_NAME);
225
				}
226
				if (file.exists()) {
226
			} else {
227
					manifestStream = new FileInputStream(file);
227
				File file = new File(bundleLocation, JarFile.MANIFEST_NAME);
228
				} else {
228
				if (file.exists()) {
229
					File pxml = new File(bundleLocation, ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR);
229
					manifestStream = new FileInputStream(file);
230
					File fxml = new File(bundleLocation, ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR);
230
				} else {
231
					if (pxml.exists() || fxml.exists()) {
231
					File pxml = new File(bundleLocation, ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR);
232
						// support classic non-OSGi plug-in
232
					File fxml = new File(bundleLocation, ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR);
233
						PluginConverter converter = (PluginConverter) PDECore.getDefault().acquireService(PluginConverter.class.getName());
233
					if (pxml.exists() || fxml.exists()) {
234
						if (converter != null) {
234
						// support classic non-OSGi plug-in
235
							try {
235
						PluginConverter converter = (PluginConverter) PDECore.getDefault().acquireService(PluginConverter.class.getName());
236
								Dictionary convert = converter.convertManifest(bundleLocation, false, null, false, null);
236
						if (converter != null) {
237
								if (convert != null) {
237
							try {
238
									Map map = new HashMap(convert.size(), 1.0f);
238
								Dictionary convert = converter.convertManifest(bundleLocation, false, null, false, null);
239
									Enumeration keys = convert.keys();
239
								if (convert != null) {
240
									while (keys.hasMoreElements()) {
240
									Map map = new HashMap(convert.size(), 1.0f);
241
										Object key = keys.nextElement();
241
									Enumeration keys = convert.keys();
242
										map.put(key, convert.get(key));
242
									while (keys.hasMoreElements()) {
243
									}
243
										Object key = keys.nextElement();
244
									return map;
244
										map.put(key, convert.get(key));
245
								}
245
									}
246
							} catch (PluginConversionException e) {
246
									return map;
247
								throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_2, bundleLocation.getAbsolutePath()), e));
247
								}
248
							}
248
							} catch (PluginConversionException e) {
249
						}
249
								throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_2, bundleLocation.getAbsolutePath()), e));
250
					}
250
							}
251
				}
251
						}
252
			}
252
					}
253
			if (manifestStream == null) {
253
				}
254
				return null;
254
			}
255
			}
255
			if (manifestStream == null) {
256
			return ManifestElement.parseBundleManifest(manifestStream, new Hashtable(10));
256
				return null;
257
		} catch (BundleException e) {
257
			}
258
			PDECore.log(e);
258
			return ManifestElement.parseBundleManifest(manifestStream, new Hashtable(10));
259
		} catch (IOException e) {
259
		} catch (BundleException e) {
260
			throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_3, bundleLocation.getAbsolutePath()), e));
260
			PDECore.log(e);
261
		} finally {
261
		} catch (IOException e) {
262
			closeZipFileAndStream(manifestStream, jarFile);
262
			throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_3, bundleLocation.getAbsolutePath()), e));
263
		}
263
		} finally {
264
		return null;
264
			closeZipFileAndStream(manifestStream, jarFile);
265
	}
265
		}
266
266
		return null;
267
	/**
267
	}
268
	 * Closes the stream and jar file if not <code>null</code>.
268
269
	 * 
269
	/**
270
	 * @param stream stream to close or <code>null</code>
270
	 * Closes the stream and jar file if not <code>null</code>.
271
	 * @param jarFile jar to close or <code>null</code>
271
	 * 
272
	 */
272
	 * @param stream stream to close or <code>null</code>
273
	private void closeZipFileAndStream(InputStream stream, ZipFile jarFile) {
273
	 * @param jarFile jar to close or <code>null</code>
274
		try {
274
	 */
275
			if (stream != null) {
275
	private void closeZipFileAndStream(InputStream stream, ZipFile jarFile) {
276
				stream.close();
276
		try {
277
			}
277
			if (stream != null) {
278
		} catch (IOException e) {
278
				stream.close();
279
			PDECore.log(e);
279
			}
280
		}
280
		} catch (IOException e) {
281
		try {
281
			PDECore.log(e);
282
			if (jarFile != null) {
282
		}
283
				jarFile.close();
283
		try {
284
			}
284
			if (jarFile != null) {
285
		} catch (IOException e) {
285
				jarFile.close();
286
			PDECore.log(e);
286
			}
287
		}
287
		} catch (IOException e) {
288
	}
288
			PDECore.log(e);
289
}
289
		}
290
	}
291
}
(-)src/org/eclipse/pde/internal/core/target/impl/ProfileBundleContainer.java (-95 / +114 lines)
Lines 1-95 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.target.impl;
11
package org.eclipse.pde.internal.core.target.impl;
12
12
13
import java.net.MalformedURLException;
13
import java.net.MalformedURLException;
14
import java.net.URL;
14
import java.net.URL;
15
import org.eclipse.core.runtime.*;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
16
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
17
import org.eclipse.osgi.util.NLS;
17
import org.eclipse.osgi.util.NLS;
18
import org.eclipse.pde.internal.core.P2Utils;
18
import org.eclipse.pde.internal.core.P2Utils;
19
import org.eclipse.pde.internal.core.PDECore;
19
import org.eclipse.pde.internal.core.PDECore;
20
import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
20
21
21
/**
22
/**
22
 * A bundle container representing an installed profile.
23
 * A bundle container representing an installed profile.
23
 * 
24
 * 
24
 * @since 3.5 
25
 * @since 3.5 
25
 */
26
 */
26
class ProfileBundleContainer extends AbstractBundleContainer {
27
class ProfileBundleContainer implements IBundleContainer {
27
28
28
	/**
29
	/**
29
	 * Path to home/root install location. May contain string variables.
30
	 * Path to home/root install location
30
	 */
31
	 */
31
	private String fHome;
32
	private String fHome;
32
33
33
	/**
34
	/**
34
	 * Alternate configuration location or <code>null</code> if default.
35
	 * Alternate configuration location or <code>null</code> if default
35
	 * May contain string variables.
36
	 */
36
	 */
37
	private String fConfiguration;
37
	private String fConfiguration;
38
38
39
	/**
39
	/**
40
	 * Creates a new bundle container for the profile at the specified location.
40
	 * Creates a new bundle container for the profile at the specified location.
41
	 * 
41
	 * 
42
	 * @param home path in local file system
42
	 * @param home path in local file system, may contain string variables
43
	 * @param configurationLocation alternate configuration location or <code>null</code> for default
43
	 * @param configurationLocation alternate configuration location or <code>null</code> for default,
44
	 */
44
	 *  may contain string variables
45
	public ProfileBundleContainer(String home, String configurationLocation) {
45
	 */
46
		fHome = home;
46
	public ProfileBundleContainer(String home, String configurationLocation) {
47
		fConfiguration = configurationLocation;
47
		fHome = home;
48
	}
48
		fConfiguration = configurationLocation;
49
49
	}
50
	/* (non-Javadoc)
50
51
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
51
	/* (non-Javadoc)
52
	 */
52
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#getHomeLocation()
53
	public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
53
	 */
54
		URL configUrl = getConfigurationArea();
54
	public String getHomeLocation() throws CoreException {
55
		BundleInfo[] infos = P2Utils.readBundles(new Path(fHome).toOSString(), configUrl);
55
		return resolveHomeLocation().toOSString();
56
		if (infos == null) {
56
	}
57
			throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.ProfileBundleContainer_0, fHome)));
57
58
		}
58
	/* (non-Javadoc)
59
		return infos;
59
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
60
	}
60
	 */
61
61
	public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
62
	/* (non-Javadoc)
62
		URL configUrl = getConfigurationArea();
63
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
63
		IPath home = resolveHomeLocation();
64
	 */
64
		BundleInfo[] infos = P2Utils.readBundles(home.toOSString(), configUrl);
65
	public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
65
		if (infos == null) {
66
		URL configUrl = getConfigurationArea();
66
			throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.ProfileBundleContainer_0, home.toOSString())));
67
		BundleInfo[] source = P2Utils.readSourceBundles(new Path(fHome).toOSString(), configUrl);
67
		}
68
		if (source == null) {
68
		return infos;
69
			source = new BundleInfo[0];
69
	}
70
		}
70
71
		return source;
71
	/* (non-Javadoc)
72
	}
72
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
73
73
	 */
74
	/**
74
	public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
75
	 * Returns a URL to the configuration area associated with this profile.
75
		URL configUrl = getConfigurationArea();
76
	 * 
76
		BundleInfo[] source = P2Utils.readSourceBundles(resolveHomeLocation().toOSString(), configUrl);
77
	 * @return configuration area URL
77
		if (source == null) {
78
	 * @throws CoreException if unable to generate a URL
78
			source = new BundleInfo[0];
79
	 */
79
		}
80
	private URL getConfigurationArea() throws CoreException {
80
		return source;
81
		IPath home = new Path(fHome);
81
	}
82
		IPath configuration = null;
82
83
		if (fConfiguration == null) {
83
	/**
84
			configuration = home.append("configuration"); //$NON-NLS-1$
84
	 * Returns the home location with all variables resolved as a path.
85
		} else {
85
	 * 
86
			configuration = new Path(fConfiguration);
86
	 * @return resolved home location
87
		}
87
	 * @throws CoreException
88
		try {
88
	 */
89
			return configuration.toFile().toURL();
89
	private IPath resolveHomeLocation() throws CoreException {
90
		} catch (MalformedURLException e) {
90
		return new Path(resolveVariables(fHome));
91
			throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.ProfileBundleContainer_1, fHome), e));
91
	}
92
		}
92
93
	}
93
	/**
94
94
	 * Returns a URL to the configuration area associated with this profile.
95
}
95
	 * 
96
	 * @return configuration area URL
97
	 * @throws CoreException if unable to generate a URL
98
	 */
99
	private URL getConfigurationArea() throws CoreException {
100
		IPath home = resolveHomeLocation();
101
		IPath configuration = null;
102
		if (fConfiguration == null) {
103
			configuration = home.append("configuration"); //$NON-NLS-1$
104
		} else {
105
			configuration = new Path(resolveVariables(fConfiguration));
106
		}
107
		try {
108
			return configuration.toFile().toURL();
109
		} catch (MalformedURLException e) {
110
			throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.ProfileBundleContainer_1, home.toOSString()), e));
111
		}
112
	}
113
114
}
(-)src/org/eclipse/pde/internal/core/target/impl/Messages.java (-39 / +54 lines)
Lines 1-39 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.target.impl;
11
package org.eclipse.pde.internal.core.target.impl;
12
12
13
import org.eclipse.osgi.util.NLS;
13
import org.eclipse.osgi.util.NLS;
14
14
15
/**
15
/**
16
 *
16
 *
17
 */
17
 */
18
public class Messages extends NLS {
18
public class Messages extends NLS {
19
	private static final String BUNDLE_NAME = "org.eclipse.pde.internal.core.target.impl.Messages"; //$NON-NLS-1$
19
	private static final String BUNDLE_NAME = "org.eclipse.pde.internal.core.target.impl.Messages"; //$NON-NLS-1$
20
	public static String DirectoryBundleContainer_0;
20
	public static String DirectoryBundleContainer_0;
21
	public static String DirectoryBundleContainer_1;
21
	public static String DirectoryBundleContainer_1;
22
	public static String DirectoryBundleContainer_2;
22
	public static String DirectoryBundleContainer_2;
23
	public static String DirectoryBundleContainer_3;
23
	public static String DirectoryBundleContainer_3;
24
	public static String LocalTargetHandle_0;
24
	public static String FeatureBundleContainer_0;
25
	public static String LocalTargetHandle_1;
25
	public static String FeatureBundleContainer_1;
26
	public static String LocalTargetHandle_2;
26
	public static String FeatureBundleContainer_2;
27
	public static String ProfileBundleContainer_0;
27
	public static String FeatureBundleContainer_3;
28
	public static String ProfileBundleContainer_1;
28
	public static String FeatureBundleContainer_4;
29
	public static String TargetPlatformService_0;
29
	public static String FeatureBundleContainer_5;
30
	public static String TargetPlatformService_1;
30
	public static String LoadTargetDefinitionJob_0;
31
	public static String WorkspaceFileTargetHandle_0;
31
	public static String LoadTargetDefinitionJob_1;
32
	static {
32
	public static String LoadTargetOperation_argsTaskName;
33
		// initialize resource bundle
33
	public static String LoadTargetOperation_envTaskName;
34
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
34
	public static String LoadTargetOperation_implicitPluginsTaskName;
35
	}
35
	public static String LoadTargetOperation_jreTaskName;
36
36
	public static String LoadTargetOperation_loadPluginsTaskName;
37
	private Messages() {
37
	public static String LoadTargetOperation_mainTaskName;
38
	}
38
	public static String LoadTargetOperation_reloadTaskName;
39
}
39
	public static String LocalTargetHandle_0;
40
	public static String LocalTargetHandle_1;
41
	public static String LocalTargetHandle_2;
42
	public static String ProfileBundleContainer_0;
43
	public static String ProfileBundleContainer_1;
44
	public static String TargetPlatformService_0;
45
	public static String TargetPlatformService_1;
46
	public static String WorkspaceFileTargetHandle_0;
47
	static {
48
		// initialize resource bundle
49
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
50
	}
51
52
	private Messages() {
53
	}
54
}
(-)src/org/eclipse/pde/internal/core/target/impl/TargetDefinition.java (-248 / +252 lines)
Lines 1-248 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.target.impl;
11
package org.eclipse.pde.internal.core.target.impl;
12
12
13
import java.io.InputStream;
13
import java.io.InputStream;
14
import java.io.OutputStream;
14
import java.io.OutputStream;
15
import java.util.*;
15
import java.util.*;
16
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
18
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
19
import org.eclipse.pde.internal.core.target.provisional.*;
19
import org.eclipse.pde.internal.core.target.provisional.*;
20
20
21
/**
21
/**
22
 * Target definition implementation.
22
 * Target definition implementation.
23
 * 
23
 * 
24
 * @since 3.5
24
 * @since 3.5
25
 */
25
 */
26
class TargetDefinition implements ITargetDefinition {
26
class TargetDefinition implements ITargetDefinition {
27
27
28
	// name and description
28
	// name and description
29
	private String fName;
29
	private String fName;
30
	private String fDescription;
30
	private String fDescription;
31
31
32
	// arguments
32
	// arguments
33
	private String fProgramArgs;
33
	private String fProgramArgs;
34
	private String fVMArgs;
34
	private String fVMArgs;
35
35
36
	// environment settings
36
	// environment settings
37
	private String fEE;
37
	private String fEE;
38
	private String fArch;
38
	private String fArch;
39
	private String fOS;
39
	private String fOS;
40
	private String fWS;
40
	private String fWS;
41
	private String fNL;
41
	private String fNL;
42
42
43
	// bundle containers
43
	// bundle containers
44
	private IBundleContainer[] fContainers;
44
	private IBundleContainer[] fContainers;
45
45
46
	// handle
46
	// handle
47
	private ITargetHandle fHandle;
47
	private ITargetHandle fHandle;
48
48
49
	/**
49
	/**
50
	 * Constructs a target definition based on the given handle. 
50
	 * Constructs a target definition based on the given handle. 
51
	 */
51
	 */
52
	TargetDefinition(ITargetHandle handle) {
52
	TargetDefinition(ITargetHandle handle) {
53
		fHandle = handle;
53
		fHandle = handle;
54
	}
54
	}
55
55
56
	/* (non-Javadoc)
56
	/* (non-Javadoc)
57
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getArch()
57
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getArch()
58
	 */
58
	 */
59
	public String getArch() {
59
	public String getArch() {
60
		return fArch;
60
		return fArch;
61
	}
61
	}
62
62
63
	/* (non-Javadoc)
63
	/* (non-Javadoc)
64
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getBundleContainers()
64
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getBundleContainers()
65
	 */
65
	 */
66
	public IBundleContainer[] getBundleContainers() {
66
	public IBundleContainer[] getBundleContainers() {
67
		return fContainers;
67
		return fContainers;
68
	}
68
	}
69
69
70
	/* (non-Javadoc)
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getDescription()
71
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getDescription()
72
	 */
72
	 */
73
	public String getDescription() {
73
	public String getDescription() {
74
		return fDescription;
74
		return fDescription;
75
	}
75
	}
76
76
77
	/* (non-Javadoc)
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getExecutionEnvironment()
78
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getExecutionEnvironment()
79
	 */
79
	 */
80
	public String getExecutionEnvironment() {
80
	public String getExecutionEnvironment() {
81
		return fEE;
81
		return fEE;
82
	}
82
	}
83
83
84
	/* (non-Javadoc)
84
	/* (non-Javadoc)
85
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getNL()
85
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getNL()
86
	 */
86
	 */
87
	public String getNL() {
87
	public String getNL() {
88
		return fNL;
88
		return fNL;
89
	}
89
	}
90
90
91
	/* (non-Javadoc)
91
	/* (non-Javadoc)
92
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getName()
92
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getName()
93
	 */
93
	 */
94
	public String getName() {
94
	public String getName() {
95
		return fName;
95
		return fName;
96
	}
96
	}
97
97
98
	/* (non-Javadoc)
98
	/* (non-Javadoc)
99
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getOS()
99
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getOS()
100
	 */
100
	 */
101
	public String getOS() {
101
	public String getOS() {
102
		return fOS;
102
		return fOS;
103
	}
103
	}
104
104
105
	/* (non-Javadoc)
105
	/* (non-Javadoc)
106
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getProgramArguments()
106
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getProgramArguments()
107
	 */
107
	 */
108
	public String getProgramArguments() {
108
	public String getProgramArguments() {
109
		return fProgramArgs;
109
		return fProgramArgs;
110
	}
110
	}
111
111
112
	/* (non-Javadoc)
112
	/* (non-Javadoc)
113
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getVMArguments()
113
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getVMArguments()
114
	 */
114
	 */
115
	public String getVMArguments() {
115
	public String getVMArguments() {
116
		return fVMArgs;
116
		return fVMArgs;
117
	}
117
	}
118
118
119
	/* (non-Javadoc)
119
	/* (non-Javadoc)
120
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getWS()
120
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getWS()
121
	 */
121
	 */
122
	public String getWS() {
122
	public String getWS() {
123
		return fWS;
123
		return fWS;
124
	}
124
	}
125
125
126
	/* (non-Javadoc)
126
	/* (non-Javadoc)
127
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setArch(java.lang.String)
127
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setArch(java.lang.String)
128
	 */
128
	 */
129
	public void setArch(String arch) {
129
	public void setArch(String arch) {
130
		fArch = arch;
130
		fArch = arch;
131
	}
131
	}
132
132
133
	/* (non-Javadoc)
133
	/* (non-Javadoc)
134
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setDescription(java.lang.String)
134
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setDescription(java.lang.String)
135
	 */
135
	 */
136
	public void setDescription(String description) {
136
	public void setDescription(String description) {
137
		fDescription = description;
137
		fDescription = description;
138
	}
138
	}
139
139
140
	/* (non-Javadoc)
140
	/* (non-Javadoc)
141
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setExecutionEnvironment(java.lang.String)
141
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setExecutionEnvironment(java.lang.String)
142
	 */
142
	 */
143
	public void setExecutionEnvironment(String environment) {
143
	public void setExecutionEnvironment(String environment) {
144
		fEE = environment;
144
		fEE = environment;
145
	}
145
	}
146
146
147
	/* (non-Javadoc)
147
	/* (non-Javadoc)
148
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setNL(java.lang.String)
148
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setNL(java.lang.String)
149
	 */
149
	 */
150
	public void setNL(String nl) {
150
	public void setNL(String nl) {
151
		fNL = nl;
151
		fNL = nl;
152
	}
152
	}
153
153
154
	/* (non-Javadoc)
154
	/* (non-Javadoc)
155
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setName(java.lang.String)
155
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setName(java.lang.String)
156
	 */
156
	 */
157
	public void setName(String name) {
157
	public void setName(String name) {
158
		fName = name;
158
		fName = name;
159
	}
159
	}
160
160
161
	/* (non-Javadoc)
161
	/* (non-Javadoc)
162
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setOS(java.lang.String)
162
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setOS(java.lang.String)
163
	 */
163
	 */
164
	public void setOS(String os) {
164
	public void setOS(String os) {
165
		fOS = os;
165
		fOS = os;
166
	}
166
	}
167
167
168
	/* (non-Javadoc)
168
	/* (non-Javadoc)
169
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setProgramArguments(java.lang.String)
169
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setProgramArguments(java.lang.String)
170
	 */
170
	 */
171
	public void setProgramArguments(String args) {
171
	public void setProgramArguments(String args) {
172
		fProgramArgs = args;
172
		fProgramArgs = args;
173
	}
173
	}
174
174
175
	/* (non-Javadoc)
175
	/* (non-Javadoc)
176
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setVMArguments(java.lang.String)
176
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setVMArguments(java.lang.String)
177
	 */
177
	 */
178
	public void setVMArguments(String args) {
178
	public void setVMArguments(String args) {
179
		fVMArgs = args;
179
		fVMArgs = args;
180
	}
180
	}
181
181
182
	/* (non-Javadoc)
182
	/* (non-Javadoc)
183
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setWS(java.lang.String)
183
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setWS(java.lang.String)
184
	 */
184
	 */
185
	public void setWS(String ws) {
185
	public void setWS(String ws) {
186
		fWS = ws;
186
		fWS = ws;
187
	}
187
	}
188
188
189
	/* (non-Javadoc)
189
	/* (non-Javadoc)
190
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setBundleContainers(org.eclipse.pde.internal.core.target.provisional.IBundleContainer[])
190
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setBundleContainers(org.eclipse.pde.internal.core.target.provisional.IBundleContainer[])
191
	 */
191
	 */
192
	public void setBundleContainers(IBundleContainer[] containers) {
192
	public void setBundleContainers(IBundleContainer[] containers) {
193
		fContainers = containers;
193
		fContainers = containers;
194
	}
194
	}
195
195
196
	/* (non-Javadoc)
196
	/* (non-Javadoc)
197
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
197
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
198
	 */
198
	 */
199
	public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
199
	public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
200
		IBundleContainer[] containers = getBundleContainers();
200
		IBundleContainer[] containers = getBundleContainers();
201
		List bundles = new ArrayList();
201
		List bundles = new ArrayList();
202
		for (int i = 0; i < containers.length; i++) {
202
		if (containers != null) {
203
			BundleInfo[] infos = containers[i].resolveBundles(monitor);
203
			for (int i = 0; i < containers.length; i++) {
204
			bundles.addAll(Arrays.asList(infos));
204
				BundleInfo[] infos = containers[i].resolveBundles(monitor);
205
		}
205
				bundles.addAll(Arrays.asList(infos));
206
		return (BundleInfo[]) bundles.toArray(new BundleInfo[bundles.size()]);
206
			}
207
	}
207
		}
208
208
		return (BundleInfo[]) bundles.toArray(new BundleInfo[bundles.size()]);
209
	/* (non-Javadoc)
209
	}
210
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
210
211
	 */
211
	/* (non-Javadoc)
212
	public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
212
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
213
		IBundleContainer[] containers = getBundleContainers();
213
	 */
214
		List source = new ArrayList();
214
	public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
215
		for (int i = 0; i < containers.length; i++) {
215
		IBundleContainer[] containers = getBundleContainers();
216
			BundleInfo[] infos = containers[i].resolveSourceBundles(monitor);
216
		List source = new ArrayList();
217
			source.addAll(Arrays.asList(infos));
217
		if (containers != null) {
218
		}
218
			for (int i = 0; i < containers.length; i++) {
219
		return (BundleInfo[]) source.toArray(new BundleInfo[source.size()]);
219
				BundleInfo[] infos = containers[i].resolveSourceBundles(monitor);
220
	}
220
				source.addAll(Arrays.asList(infos));
221
221
			}
222
	/* (non-Javadoc)
222
		}
223
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getHandle()
223
		return (BundleInfo[]) source.toArray(new BundleInfo[source.size()]);
224
	 */
224
	}
225
	public ITargetHandle getHandle() {
225
226
		return fHandle;
226
	/* (non-Javadoc)
227
	}
227
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getHandle()
228
228
	 */
229
	/**
229
	public ITargetHandle getHandle() {
230
	 * Build contents from the given stream.
230
		return fHandle;
231
	 * 
231
	}
232
	 * @param stream input stream
232
233
	 * @throws CoreException if an error occurs
233
	/**
234
	 */
234
	 * Build contents from the given stream.
235
	void setContents(InputStream stream) throws CoreException {
235
	 * 
236
		// TODO: read stream
236
	 * @param stream input stream
237
	}
237
	 * @throws CoreException if an error occurs
238
238
	 */
239
	/**
239
	void setContents(InputStream stream) throws CoreException {
240
	 * Persists contents to the given stream.
240
		// TODO: read stream
241
	 * 
241
	}
242
	 * @param stream output stream
242
243
	 * @throws CoreException if an error occurs
243
	/**
244
	 */
244
	 * Persists contents to the given stream.
245
	void write(OutputStream stream) throws CoreException {
245
	 * 
246
		// TODO: persist content
246
	 * @param stream output stream
247
	}
247
	 * @throws CoreException if an error occurs
248
}
248
	 */
249
	void write(OutputStream stream) throws CoreException {
250
		// TODO: persist content
251
	}
252
}
(-)src/org/eclipse/pde/internal/core/target/impl/Messages.properties (-23 / +38 lines)
Lines 1-23 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2009 IBM Corporation and others.
2
# Copyright (c) 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
7
#
8
# Contributors:
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
10
###############################################################################
11
11
12
DirectoryBundleContainer_0=Reading bundles...
12
DirectoryBundleContainer_0=Reading bundles...
13
DirectoryBundleContainer_1=Directory does not exist: {0}
13
DirectoryBundleContainer_1=Directory does not exist: {0}
14
DirectoryBundleContainer_2=Error converting manifest for {0}
14
DirectoryBundleContainer_2=Error converting manifest for {0}
15
DirectoryBundleContainer_3=Error reading manifest for {0}
15
DirectoryBundleContainer_3=Error reading manifest for {0}
16
LocalTargetHandle_0=Unable to restore target handle
16
FeatureBundleContainer_0=Directory does not exist: {0}
17
LocalTargetHandle_1=Target file not found
17
FeatureBundleContainer_1=Unable to locate feature: {0}
18
LocalTargetHandle_2=Unable to generate memento for target platform
18
FeatureBundleContainer_2=Unable to resolve bunldes for feature {0}
19
ProfileBundleContainer_0=Unable to resolve bundles in {0}
19
FeatureBundleContainer_3=Unable to resolve bunldes for feature {0}
20
ProfileBundleContainer_1=Unable resolve configuration area in {0}
20
FeatureBundleContainer_4=Unable to acquire target platform service
21
TargetPlatformService_0=Unable to restore target memento
21
FeatureBundleContainer_5=Plug-ins directry does not exist for feature {0}
22
TargetPlatformService_1=Unrecognized target memento scheme
22
LoadTargetDefinitionJob_0=Load Target Platform
23
WorkspaceFileTargetHandle_0=Unable to generate memento for target platform
23
LoadTargetDefinitionJob_1=Unable to resolve plug-ins in target definition
24
LoadTargetOperation_argsTaskName=Setting arguments
25
LoadTargetOperation_envTaskName=Setting environment
26
LoadTargetOperation_implicitPluginsTaskName=loading implicit dependencies
27
LoadTargetOperation_jreTaskName=Setting JRE
28
LoadTargetOperation_loadPluginsTaskName=Loading Plugins
29
LoadTargetOperation_mainTaskName=Resetting target platform information
30
LoadTargetOperation_reloadTaskName=reloading target platform
31
LocalTargetHandle_0=Unable to restore target handle
32
LocalTargetHandle_1=Target file not found
33
LocalTargetHandle_2=Unable to generate memento for target platform
34
ProfileBundleContainer_0=Unable to resolve bundles in {0}
35
ProfileBundleContainer_1=Unable resolve configuration area in {0}
36
TargetPlatformService_0=Unable to restore target memento
37
TargetPlatformService_1=Unrecognized target memento scheme
38
WorkspaceFileTargetHandle_0=Unable to generate memento for target platform
(-)src/org/eclipse/pde/internal/core/target/impl/TargetPlatformService.java (-116 / +123 lines)
Lines 1-116 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.target.impl;
11
package org.eclipse.pde.internal.core.target.impl;
12
12
13
import java.net.URI;
13
import java.net.URI;
14
import java.net.URISyntaxException;
14
import java.net.URISyntaxException;
15
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.pde.internal.core.PDECore;
17
import org.eclipse.pde.internal.core.PDECore;
18
import org.eclipse.pde.internal.core.target.provisional.*;
18
import org.eclipse.pde.internal.core.target.provisional.*;
19
19
20
/**
20
/**
21
 * Target platform service implementation.
21
 * Target platform service implementation.
22
 * 
22
 * 
23
 * @since 3.5
23
 * @since 3.5
24
 */
24
 */
25
public class TargetPlatformService implements ITargetPlatformService {
25
public class TargetPlatformService implements ITargetPlatformService {
26
26
27
	private static ITargetPlatformService fgDefault;
27
	private static ITargetPlatformService fgDefault;
28
28
29
	private TargetPlatformService() {
29
	private TargetPlatformService() {
30
	}
30
	}
31
31
32
	public synchronized static ITargetPlatformService getDefault() {
32
	public synchronized static ITargetPlatformService getDefault() {
33
		if (fgDefault == null) {
33
		if (fgDefault == null) {
34
			fgDefault = new TargetPlatformService();
34
			fgDefault = new TargetPlatformService();
35
		}
35
		}
36
		return fgDefault;
36
		return fgDefault;
37
	}
37
	}
38
38
39
	/* (non-Javadoc)
39
	/* (non-Javadoc)
40
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#deleteTarget(org.eclipse.pde.internal.core.target.provisional.ITargetHandle)
40
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#deleteTarget(org.eclipse.pde.internal.core.target.provisional.ITargetHandle)
41
	 */
41
	 */
42
	public void deleteTarget(ITargetHandle handle) throws CoreException {
42
	public void deleteTarget(ITargetHandle handle) throws CoreException {
43
		// TODO Auto-generated method stub
43
		// TODO Auto-generated method stub
44
44
45
	}
45
	}
46
46
47
	/* (non-Javadoc)
47
	/* (non-Javadoc)
48
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTarget(org.eclipse.core.resources.IFile)
48
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTarget(org.eclipse.core.resources.IFile)
49
	 */
49
	 */
50
	public ITargetHandle getTarget(IFile file) {
50
	public ITargetHandle getTarget(IFile file) {
51
		return new WorkspaceFileTargetHandle(file);
51
		return new WorkspaceFileTargetHandle(file);
52
	}
52
	}
53
53
54
	/* (non-Javadoc)
54
	/* (non-Javadoc)
55
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTarget(java.lang.String)
55
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTarget(java.lang.String)
56
	 */
56
	 */
57
	public ITargetHandle getTarget(String memento) throws CoreException {
57
	public ITargetHandle getTarget(String memento) throws CoreException {
58
		try {
58
		try {
59
			URI uri = new URI(memento);
59
			URI uri = new URI(memento);
60
			String scheme = uri.getScheme();
60
			String scheme = uri.getScheme();
61
			if (WorkspaceFileTargetHandle.SCHEME.equals(scheme)) {
61
			if (WorkspaceFileTargetHandle.SCHEME.equals(scheme)) {
62
				return WorkspaceFileTargetHandle.restoreHandle(uri);
62
				return WorkspaceFileTargetHandle.restoreHandle(uri);
63
			} else if (LocalTargetHandle.SCHEME.equals(scheme)) {
63
			} else if (LocalTargetHandle.SCHEME.equals(scheme)) {
64
				return LocalTargetHandle.restoreHandle(uri);
64
				return LocalTargetHandle.restoreHandle(uri);
65
			}
65
			}
66
		} catch (URISyntaxException e) {
66
		} catch (URISyntaxException e) {
67
			throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.TargetPlatformService_0, e));
67
			throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.TargetPlatformService_0, e));
68
		}
68
		}
69
		throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.TargetPlatformService_1, null));
69
		throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.TargetPlatformService_1, null));
70
	}
70
	}
71
71
72
	/* (non-Javadoc)
72
	/* (non-Javadoc)
73
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTargets(org.eclipse.core.runtime.IProgressMonitor)
73
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTargets(org.eclipse.core.runtime.IProgressMonitor)
74
	 */
74
	 */
75
	public ITargetHandle[] getTargets(IProgressMonitor monitor) {
75
	public ITargetHandle[] getTargets(IProgressMonitor monitor) {
76
		// TODO Auto-generated method stub
76
		// TODO Auto-generated method stub
77
		return null;
77
		return null;
78
	}
78
	}
79
79
80
	/* (non-Javadoc)
80
	/* (non-Javadoc)
81
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newDirectoryContainer(java.lang.String)
81
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newDirectoryContainer(java.lang.String)
82
	 */
82
	 */
83
	public IBundleContainer newDirectoryContainer(String path) {
83
	public IBundleContainer newDirectoryContainer(String path) {
84
		return new DirectoryBundleContainer(path);
84
		return new DirectoryBundleContainer(path);
85
	}
85
	}
86
86
87
	/* (non-Javadoc)
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newProfileContainer(java.lang.String)
88
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newProfileContainer(java.lang.String)
89
	 */
89
	 */
90
	public IBundleContainer newProfileContainer(String home) {
90
	public IBundleContainer newProfileContainer(String home) {
91
		return newProfileContainer(home, null);
91
		return newProfileContainer(home, null);
92
	}
92
	}
93
93
94
	/* (non-Javadoc)
94
	/* (non-Javadoc)
95
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newProfileContainer(java.lang.String, java.lang.String)
95
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newProfileContainer(java.lang.String, java.lang.String)
96
	 */
96
	 */
97
	public IBundleContainer newProfileContainer(String home, String configurationLocation) {
97
	public IBundleContainer newProfileContainer(String home, String configurationLocation) {
98
		return new ProfileBundleContainer(home, configurationLocation);
98
		return new ProfileBundleContainer(home, configurationLocation);
99
	}
99
	}
100
100
101
	/* (non-Javadoc)
101
	/* (non-Javadoc)
102
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newTarget()
102
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newTarget()
103
	 */
103
	 */
104
	public ITargetDefinition newTarget() {
104
	public ITargetDefinition newTarget() {
105
		return new TargetDefinition(new LocalTargetHandle());
105
		return new TargetDefinition(new LocalTargetHandle());
106
	}
106
	}
107
107
108
	/* (non-Javadoc)
108
	/* (non-Javadoc)
109
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#saveTargetDefinition(org.eclipse.pde.internal.core.target.provisional.ITargetDefinition)
109
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#saveTargetDefinition(org.eclipse.pde.internal.core.target.provisional.ITargetDefinition)
110
	 */
110
	 */
111
	public void saveTargetDefinition(ITargetDefinition definition) throws CoreException {
111
	public void saveTargetDefinition(ITargetDefinition definition) throws CoreException {
112
		// TODO Auto-generated method stub
112
		// TODO Auto-generated method stub
113
113
114
	}
114
	}
115
115
116
}
116
	/* (non-Javadoc)
117
	 * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newFeatureContainer(java.lang.String, java.lang.String, java.lang.String)
118
	 */
119
	public IBundleContainer newFeatureContainer(String home, String id, String version) {
120
		return new FeatureBundleContainer(home, id, version);
121
	}
122
123
}
(-)src/org/eclipse/pde/internal/core/target/provisional/IBundleContainer.java (-43 / +54 lines)
Lines 1-43 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.target.provisional;
11
package org.eclipse.pde.internal.core.target.provisional;
12
12
13
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
15
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
16
16
17
/**
17
/**
18
 * A collection of bundles. A bundle container abstracts the storage and location of the
18
 * A collection of bundles. A bundle container abstracts the storage and location of the
19
 * underlying bundles and may contain a combination of executable and source bundles.
19
 * underlying bundles and may contain a combination of executable and source bundles.
20
 * 
20
 * 
21
 * @since 3.5
21
 * @since 3.5
22
 */
22
 */
23
public interface IBundleContainer {
23
public interface IBundleContainer {
24
24
25
	/**
25
	/**
26
	 * Resolves and returns the executable bundles in this container, possibly empty.
26
	 * Returns a path in the local file system to the root of the bundle container.
27
	 * 
27
	 * <p>
28
	 * @param monitor progress monitor or <code>null</code>
28
	 * TODO: Ideally we won't need this method. Currently the PDE target platform preferences are
29
	 * @return executable bundles
29
	 * based on a home location and additional locations, so we need the information.
30
	 * @exception CoreException if unable to resolve bundles
30
	 * </p>
31
	 */
31
	 * @return home location
32
	public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException;
32
	 * @exception CoreException if unable to resolve the location
33
33
	 */
34
	/**
34
	public String getHomeLocation() throws CoreException;
35
	 * Resolves and returns the source bundles in this container, possibly empty.
35
36
	 * 
36
	/**
37
	 * @param monitor progress monitor or <code>null</code>
37
	 * Resolves and returns the executable bundles in this container, possibly empty.
38
	 * @return source bundles
38
	 * 
39
	 * @exception CoreException if unable to resolve bundles
39
	 * @param monitor progress monitor or <code>null</code>
40
	 */
40
	 * @return executable bundles
41
	public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException;
41
	 * @exception CoreException if unable to resolve bundles
42
42
	 */
43
}
43
	public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException;
44
45
	/**
46
	 * Resolves and returns the source bundles in this container, possibly empty.
47
	 * 
48
	 * @param monitor progress monitor or <code>null</code>
49
	 * @return source bundles
50
	 * @exception CoreException if unable to resolve bundles
51
	 */
52
	public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException;
53
54
}
(-)src/org/eclipse/pde/internal/core/target/provisional/ITargetPlatformService.java (-110 / +129 lines)
Lines 1-110 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.target.provisional;
11
package org.eclipse.pde.internal.core.target.provisional;
12
12
13
import org.eclipse.core.resources.IFile;
13
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
16
17
/**
17
/**
18
 * A service to manage target platform definitions available to the workspace.
18
 * A service to manage target platform definitions available to the workspace.
19
 * 
19
 * 
20
 * @since 3.5
20
 * @since 3.5
21
 */
21
 */
22
public interface ITargetPlatformService {
22
public interface ITargetPlatformService {
23
23
24
	/**
24
	/**
25
	 * Returns handles to all target definitions known in the workspace.
25
	 * Returns handles to all target definitions known in the workspace.
26
	 * 
26
	 * 
27
	 * @return handles to all target definitions known in the workspace
27
	 * @return handles to all target definitions known in the workspace
28
	 */
28
	 */
29
	public ITargetHandle[] getTargets(IProgressMonitor monitor);
29
	public ITargetHandle[] getTargets(IProgressMonitor monitor);
30
30
31
	/**
31
	/**
32
	 * Returns a handle to a target definition backed by the underlying file.
32
	 * Returns a handle to a target definition backed by the underlying file.
33
	 * The target definition may or may not exist. If the file does not exist
33
	 * The target definition may or may not exist. If the file does not exist
34
	 * then this is a new target definition which becomes one of the known
34
	 * then this is a new target definition which becomes one of the known
35
	 * workspace target definitions when it is saved.
35
	 * workspace target definitions when it is saved.
36
	 * 
36
	 * 
37
	 * @param file target definition file that may or may not exist 
37
	 * @param file target definition file that may or may not exist 
38
	 * @return target handle
38
	 * @return target handle
39
	 */
39
	 */
40
	public ITargetHandle getTarget(IFile file);
40
	public ITargetHandle getTarget(IFile file);
41
41
42
	/**
42
	/**
43
	 * Returns a new target definition to be stored with local metadata. The target
43
	 * Returns a new target definition to be stored with local metadata. The target
44
	 * becomes one of the known workspace target definitions when it is saved.
44
	 * becomes one of the known workspace target definitions when it is saved.
45
	 * 
45
	 * 
46
	 * @return new empty target definition
46
	 * @return new empty target definition
47
	 */
47
	 */
48
	public ITargetDefinition newTarget();
48
	public ITargetDefinition newTarget();
49
49
50
	/**
50
	/**
51
	 * Persists the given target definition. The target becomes one of known
51
	 * Persists the given target definition. The target becomes one of known
52
	 * workspace target definitions when it is saved.
52
	 * workspace target definitions when it is saved.
53
	 * <p>
53
	 * <p>
54
	 * The target is persisted in a location determined by its handle. A handle
54
	 * The target is persisted in a location determined by its handle. A handle
55
	 * may refer to an {@link IFile} or a workspace metadata location. Any existing
55
	 * may refer to an {@link IFile} or a workspace metadata location. Any existing
56
	 * target definition at the same location is overwritten.
56
	 * target definition at the same location is overwritten.
57
	 * </p>
57
	 * </p>
58
	 * @param definition definition to persist
58
	 * @param definition definition to persist
59
	 * @throws CoreException if unable to persist the definition
59
	 * @throws CoreException if unable to persist the definition
60
	 */
60
	 */
61
	public void saveTargetDefinition(ITargetDefinition definition) throws CoreException;
61
	public void saveTargetDefinition(ITargetDefinition definition) throws CoreException;
62
62
63
	/**
63
	/**
64
	 * Deletes the target definition associated with the given handle.
64
	 * Deletes the target definition associated with the given handle.
65
	 * 
65
	 * 
66
	 * @param handle target handle
66
	 * @param handle target handle
67
	 * @throws CoreException if the associated target does not exist or deletion fails
67
	 * @throws CoreException if the associated target does not exist or deletion fails
68
	 */
68
	 */
69
	public void deleteTarget(ITargetHandle handle) throws CoreException;
69
	public void deleteTarget(ITargetHandle handle) throws CoreException;
70
70
71
	/**
71
	/**
72
	 * Creates and returns a target handle from the given memento. The memento must
72
	 * Creates and returns a target handle from the given memento. The memento must
73
	 * have been generated from {@link ITargetHandle#getMemento()}.
73
	 * have been generated from {@link ITargetHandle#getMemento()}.
74
	 * 
74
	 * 
75
	 * @param memento a target handle memento
75
	 * @param memento a target handle memento
76
	 * @return target handle
76
	 * @return target handle
77
	 * @throws CoreException if the target handle format is invalid
77
	 * @throws CoreException if the target handle format is invalid
78
	 */
78
	 */
79
	public ITargetHandle getTarget(String memento) throws CoreException;
79
	public ITargetHandle getTarget(String memento) throws CoreException;
80
80
81
	/**
81
	/**
82
	 * Creates and returns a bundle container that contains all bundles in the
82
	 * Creates and returns a bundle container that contains all bundles in the
83
	 * specified directory.
83
	 * specified directory which may contain string substitution variables.
84
	 * 
84
	 * 
85
	 * @param path absolute path in the local file system, may contain string variables
85
	 * @param path absolute path in the local file system, may contain string variables
86
	 * @return bundle container
86
	 * @return bundle container
87
	 */
87
	 */
88
	public IBundleContainer newDirectoryContainer(String path);
88
	public IBundleContainer newDirectoryContainer(String path);
89
89
90
	/**
90
	/**
91
	 * Creates and returns a bundle container that contains all bundles installed in
91
	 * Creates and returns a bundle container that contains all bundles installed in
92
	 * a profile at the specified location with a default configuration area.
92
	 * a profile at the specified location with a default configuration area.
93
	 * 
93
	 * The specified home location may contain string substitution variables.
94
	 * @param home absolute path in the local file system to the root of an installed profile
94
	 * 
95
	 * @return bundle container
95
	 * @param home absolute path in the local file system to the root of an installed profile
96
	 */
96
	 * 	which may contain string substitution variables
97
	public IBundleContainer newProfileContainer(String home);
97
	 * @return bundle container
98
98
	 */
99
	/**
99
	public IBundleContainer newProfileContainer(String home);
100
	 * Creates and returns a bundle container that contains all bundles installed in
100
101
	 * a profile at the specified location with the specified configuration area.
101
	/**
102
	 * 
102
	 * Creates and returns a bundle container that contains all bundles referenced by
103
	 * @param home absolute path in the local file system to the root of an installed profile
103
	 * the feature at the specified location. The location is the directory that defines
104
	 * @param configurationLocation absolute path in the local file system to the
104
	 * the feature.
105
	 *  configuration area for the specified installation
105
	 * 
106
	 * @return bundle container
106
	 * @param home installation location containing a features directory which may contain
107
	 */
107
	 *  string substitution variables
108
	public IBundleContainer newProfileContainer(String home, String configurationLocation);
108
	 * @param featureId feature symbolic name
109
109
	 * @param version feature version identifier or <code>null</code> to use most recent available
110
}
110
	 * @return bundle container
111
	 */
112
	public IBundleContainer newFeatureContainer(String home, String featureId, String version);
113
114
	/**
115
	 * Creates and returns a bundle container that contains all bundles installed in
116
	 * a profile at the specified location with the specified configuration area.
117
	 * The specified home location and configuration location may contain string substitution
118
	 * variables.
119
	 * 
120
	 * @param home absolute path in the local file system to the root of an installed profile
121
	 * 	which may contain string substitution variables
122
	 * @param configurationLocation absolute path in the local file system to the
123
	 *  configuration area for the specified installation which may contain string substitution
124
	 *  variables
125
	 * @return bundle container
126
	 */
127
	public IBundleContainer newProfileContainer(String home, String configurationLocation);
128
129
}
(-)src/org/eclipse/pde/internal/core/ExternalFeatureModelManager.java (-18 / +7 lines)
Lines 10-32 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core;
11
package org.eclipse.pde.internal.core;
12
12
13
import java.io.BufferedInputStream;
13
import java.io.*;
14
import java.io.File;
15
import java.io.FileInputStream;
16
import java.io.IOException;
17
import java.io.InputStream;
18
import java.net.URL;
14
import java.net.URL;
19
import java.util.ArrayList;
15
import java.util.*;
20
import java.util.Collection;
16
import org.eclipse.core.runtime.*;
21
import java.util.HashMap;
22
import java.util.Iterator;
23
import java.util.Map;
24
import java.util.StringTokenizer;
25
import java.util.Vector;
26
27
import org.eclipse.core.runtime.IProgressMonitor;
28
import org.eclipse.core.runtime.NullProgressMonitor;
29
import org.eclipse.core.runtime.Preferences;
30
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
17
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
31
import org.eclipse.pde.core.IModelProviderEvent;
18
import org.eclipse.pde.core.IModelProviderEvent;
32
import org.eclipse.pde.core.IModelProviderListener;
19
import org.eclipse.pde.core.IModelProviderListener;
Lines 37-47 Link Here
37
public class ExternalFeatureModelManager implements Preferences.IPropertyChangeListener {
24
public class ExternalFeatureModelManager implements Preferences.IPropertyChangeListener {
38
25
39
	/**
26
	/**
27
	 * Creates a feature model for the feature based on the given feature XML
28
	 * file.
40
	 * 
29
	 * 
41
	 * @param manifest
30
	 * @param manifest feature XML file in the local file system
42
	 * @return ExternalFeatureModel or null
31
	 * @return ExternalFeatureModel or null
43
	 */
32
	 */
44
	private static IFeatureModel createModel(File manifest) {
33
	public static IFeatureModel createModel(File manifest) {
45
		ExternalFeatureModel model = new ExternalFeatureModel();
34
		ExternalFeatureModel model = new ExternalFeatureModel();
46
		model.setInstallLocation(manifest.getParent());
35
		model.setInstallLocation(manifest.getParent());
47
		InputStream stream = null;
36
		InputStream stream = null;
(-)src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java (+327 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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.pde.internal.core.target.provisional;
12
13
import org.eclipse.pde.internal.core.target.impl.Messages;
14
15
import java.io.File;
16
import java.net.MalformedURLException;
17
import java.net.URL;
18
import java.util.*;
19
import org.eclipse.core.resources.WorkspaceJob;
20
import org.eclipse.core.runtime.*;
21
import org.eclipse.core.runtime.jobs.Job;
22
import org.eclipse.core.variables.IStringVariableManager;
23
import org.eclipse.core.variables.VariablesPlugin;
24
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
25
import org.eclipse.jdt.launching.IVMInstall;
26
import org.eclipse.jdt.launching.JavaRuntime;
27
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
28
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
29
import org.eclipse.pde.core.plugin.TargetPlatform;
30
import org.eclipse.pde.internal.core.*;
31
import org.eclipse.pde.internal.core.itarget.IImplicitDependenciesInfo;
32
import org.eclipse.pde.internal.core.itarget.ITargetPlugin;
33
34
/**
35
 * Sets the current target platform based on a target definition.
36
 * 
37
 * @since 3.5
38
 */
39
public class LoadTargetDefinitionJob extends WorkspaceJob {
40
41
	/**
42
	 * Target definition being loaded
43
	 */
44
	private ITargetDefinition fTarget;
45
46
	/**
47
	 * Constructs a new operation to load the specified target definition
48
	 * as the current target platform.
49
	 * 
50
	 * @param target target definition
51
	 */
52
	public LoadTargetDefinitionJob(ITargetDefinition target) {
53
		super(Messages.LoadTargetDefinitionJob_0);
54
		fTarget = target;
55
	}
56
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.core.resources.WorkspaceJob#runInWorkspace(org.eclipse.core.runtime.IProgressMonitor)
59
	 */
60
	public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
61
		try {
62
			Preferences preferences = PDECore.getDefault().getPluginPreferences();
63
			monitor.beginTask(Messages.LoadTargetOperation_mainTaskName, 100);
64
			loadEnvironment(preferences, new SubProgressMonitor(monitor, 5));
65
			loadArgs(preferences, new SubProgressMonitor(monitor, 5));
66
			loadJRE(preferences, new SubProgressMonitor(monitor, 15));
67
			loadImplicitPlugins(preferences, new SubProgressMonitor(monitor, 15));
68
			loadPlugins(preferences, new SubProgressMonitor(monitor, 60));
69
			loadAdditionalPreferences(preferences);
70
			PDECore.getDefault().savePluginPreferences();
71
		} finally {
72
			monitor.done();
73
		}
74
		return Status.OK_STATUS;
75
	}
76
77
	/**
78
	 * Configures program and VM argument preferences based on the target
79
	 * definition.
80
	 * 
81
	 * @param pref preference store
82
	 * @param monitor progress monitor
83
	 */
84
	private void loadArgs(Preferences pref, IProgressMonitor monitor) {
85
		monitor.beginTask(Messages.LoadTargetOperation_argsTaskName, 2);
86
		String args = fTarget.getProgramArguments();
87
		pref.setValue(ICoreConstants.PROGRAM_ARGS, (args != null) ? args : ""); //$NON-NLS-1$
88
		monitor.worked(1);
89
		args = fTarget.getVMArguments();
90
		pref.setValue(ICoreConstants.VM_ARGS, (args != null) ? args : ""); //$NON-NLS-1$
91
		monitor.done();
92
	}
93
94
	/**
95
	 * Configures the environment preferences from the target definition.
96
	 * 
97
	 * @param pref preference store
98
	 * @param monitor progress monitor
99
	 */
100
	private void loadEnvironment(Preferences pref, IProgressMonitor monitor) {
101
		monitor.beginTask(Messages.LoadTargetOperation_envTaskName, 1);
102
		setEnvironmentPref(pref, ICoreConstants.ARCH, fTarget.getArch());
103
		setEnvironmentPref(pref, ICoreConstants.NL, fTarget.getNL());
104
		setEnvironmentPref(pref, ICoreConstants.OS, fTarget.getOS());
105
		setEnvironmentPref(pref, ICoreConstants.WS, fTarget.getWS());
106
		monitor.done();
107
	}
108
109
	/**
110
	 * Sets the given preference to default when <code>null</code> or the
111
	 * specified value.
112
	 * 
113
	 * @param pref preference store
114
	 * @param key preference key
115
	 * @param value preference value or <code>null</code>
116
	 */
117
	private void setEnvironmentPref(Preferences pref, String key, String value) {
118
		if (value == null) {
119
			pref.setToDefault(key);
120
		} else {
121
			pref.setValue(key, value);
122
		}
123
	}
124
125
	/**
126
	 * Sets the workspace default JRE based on the target's execution environment.
127
	 * <p>
128
	 * This is a hold over from the old target definition files where a specific
129
	 * JRE could be specified. It seems wrong to be changing the workspace default
130
	 * JRE as a side effect of this operation, but we do it for backwards compatibility.
131
	 * </p> 
132
	 * @param pref
133
	 * @param monitor
134
	 */
135
	private void loadJRE(Preferences pref, IProgressMonitor monitor) {
136
		String id = fTarget.getExecutionEnvironment();
137
		monitor.beginTask(Messages.LoadTargetOperation_jreTaskName, 1);
138
		IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
139
		IExecutionEnvironment environment = manager.getEnvironment(id);
140
		if (environment != null) {
141
			IVMInstall jre = environment.getDefaultVM();
142
			if (jre != null) {
143
				IVMInstall[] vms = environment.getCompatibleVMs();
144
				for (int i = 0; i < vms.length; i++) {
145
					IVMInstall vm = vms[i];
146
					if (environment.isStrictlyCompatible(vm)) {
147
						jre = vm;
148
						break;
149
					}
150
				}
151
				if (jre == null && vms.length > 0) {
152
					jre = vms[0];
153
				}
154
			}
155
			IVMInstall def = JavaRuntime.getDefaultVMInstall();
156
			if (def != null && !jre.equals(def))
157
				try {
158
					JavaRuntime.setDefaultVMInstall(jre, null);
159
				} catch (CoreException e) {
160
				}
161
		}
162
		monitor.done();
163
	}
164
165
	/**
166
	 * TODO: we don't currently have implicit plug-ins in the new model.
167
	 * 
168
	 * @param pref
169
	 * @param monitor
170
	 */
171
	private void loadImplicitPlugins(Preferences pref, IProgressMonitor monitor) {
172
		IImplicitDependenciesInfo info = null;
173
		if (info != null) {
174
			ITargetPlugin[] plugins = info.getPlugins();
175
			monitor.beginTask(Messages.LoadTargetOperation_implicitPluginsTaskName, plugins.length + 1);
176
			StringBuffer buffer = new StringBuffer();
177
			for (int i = 0; i < plugins.length; i++) {
178
				buffer.append(plugins[i].getId()).append(',');
179
				monitor.worked(1);
180
			}
181
			if (plugins.length > 0)
182
				buffer.setLength(buffer.length() - 1);
183
			pref.setValue(ICoreConstants.IMPLICIT_DEPENDENCIES, buffer.toString());
184
		}
185
		monitor.done();
186
	}
187
188
	/**
189
	 * Resolves the bundles in the target platform and sets them in the corresponding
190
	 * CHECKED_PLUGINS preference. Sets home and addition location preferences as well.
191
	 * 
192
	 * @param pref
193
	 * @param monitor
194
	 * @throws CoreException
195
	 */
196
	private void loadPlugins(Preferences pref, IProgressMonitor monitor) throws CoreException {
197
		monitor.beginTask(Messages.LoadTargetOperation_loadPluginsTaskName, 100);
198
		String currentPath = pref.getString(ICoreConstants.PLATFORM_PATH);
199
		IBundleContainer[] containers = fTarget.getBundleContainers();
200
		// the first container is assumed to be the primary/home location
201
		String path = null;
202
		if (containers != null && containers.length > 0) {
203
			path = containers[0].getHomeLocation();
204
		}
205
		if (path == null) {
206
			path = TargetPlatform.getDefaultLocation();
207
		} else {
208
			try {
209
				IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
210
				path = manager.performStringSubstitution(path);
211
			} catch (CoreException e) {
212
				return;
213
			}
214
		}
215
		monitor.worked(10);
216
		List additional = getAdditionalLocs();
217
		handleReload(path, additional, pref, new SubProgressMonitor(monitor, 85));
218
219
		// update preferences (Note: some preferences updated in handleReload())
220
		pref.setValue(ICoreConstants.PLATFORM_PATH, path);
221
		String mode = new Path(path).equals(new Path(TargetPlatform.getDefaultLocation())) ? ICoreConstants.VALUE_USE_THIS : ICoreConstants.VALUE_USE_OTHER;
222
		pref.setValue(ICoreConstants.TARGET_MODE, mode);
223
224
		ListIterator li = additional.listIterator();
225
		StringBuffer buffer = new StringBuffer();
226
		while (li.hasNext())
227
			buffer.append(li.next()).append(","); //$NON-NLS-1$
228
		if (buffer.length() > 0)
229
			buffer.setLength(buffer.length() - 1);
230
		pref.setValue(ICoreConstants.ADDITIONAL_LOCATIONS, buffer.toString());
231
232
		String newValue = currentPath;
233
		for (int i = 0; i < 4; i++) {
234
			String value = pref.getString(ICoreConstants.SAVED_PLATFORM + i);
235
			pref.setValue(ICoreConstants.SAVED_PLATFORM + i, newValue);
236
			if (!value.equals(currentPath))
237
				newValue = value;
238
			else
239
				break;
240
		}
241
		monitor.done();
242
	}
243
244
	/**
245
	 * Sets the TARGET_PROFILE preference which stores the ID of the target profile used 
246
	 * (if based on an target extension) or the workspace location of the file that
247
	 * was used.
248
	 * <p>
249
	 * For now we just clear it.
250
	 * </p>
251
	 * @param pref
252
	 */
253
	private void loadAdditionalPreferences(Preferences pref) {
254
		pref.setValue(ICoreConstants.TARGET_PROFILE, ""); //$NON-NLS-1$
255
	}
256
257
	/**
258
	 * Returns a list of additional locations of bundles.
259
	 * 
260
	 * @return additional bundle locations
261
	 */
262
	private List getAdditionalLocs() throws CoreException {
263
		ArrayList additional = new ArrayList();
264
		// secondary containers are considered additional
265
		IBundleContainer[] containers = fTarget.getBundleContainers();
266
		if (containers != null && containers.length > 1) {
267
			IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
268
			for (int i = 1; i < containers.length; i++) {
269
				try {
270
					additional.add(manager.performStringSubstitution(containers[i].getHomeLocation()));
271
				} catch (CoreException e) {
272
					additional.add(containers[i].getHomeLocation());
273
				}
274
			}
275
		}
276
		return additional;
277
	}
278
279
	private void handleReload(String targetLocation, List additionalLocations, Preferences pref, IProgressMonitor monitor) throws CoreException {
280
		monitor.beginTask(Messages.LoadTargetOperation_reloadTaskName, 85);
281
282
		List infos = new ArrayList();
283
		BundleInfo[] code = fTarget.resolveBundles(null);
284
		for (int i = 0; i < code.length; i++) {
285
			infos.add(code[i]);
286
		}
287
		// to be consistent with previous implementation, add source bundles
288
		BundleInfo[] sourceBundles = fTarget.resolveSourceBundles(null);
289
		for (int i = 0; i < sourceBundles.length; i++) {
290
			infos.add(sourceBundles[i]);
291
		}
292
		BundleInfo[] bundles = (BundleInfo[]) infos.toArray(new BundleInfo[infos.size()]);
293
		// generate URLs and save CHECKED_PLUGINS
294
		StringBuffer checked = new StringBuffer();
295
296
		URL[] paths = new URL[bundles.length];
297
		for (int i = 0; i < paths.length; i++) {
298
			try {
299
				paths[i] = new File(bundles[i].getLocation()).toURL();
300
				if (i > 0) {
301
					checked.append(" "); //$NON-NLS-1$
302
				}
303
				checked.append(bundles[i].getSymbolicName());
304
			} catch (MalformedURLException e) {
305
				throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.LoadTargetDefinitionJob_1, e));
306
			}
307
		}
308
309
		PDEState state = new PDEState(paths, true, new SubProgressMonitor(monitor, 45));
310
		// save CHECKED_PLUGINS
311
		if (paths.length == 0) {
312
			pref.setValue(ICoreConstants.CHECKED_PLUGINS, ICoreConstants.VALUE_SAVED_NONE);
313
		} else {
314
			pref.setValue(ICoreConstants.CHECKED_PLUGINS, checked.toString());
315
		}
316
317
		Job job = new TargetPlatformResetJob(state);
318
		job.schedule();
319
		try {
320
			job.join();
321
		} catch (InterruptedException e) {
322
			// TODO Auto-generated catch block
323
		}
324
		monitor.done();
325
	}
326
327
}
(-)src/org/eclipse/pde/internal/core/target/impl/FeatureBundleContainer.java (+201 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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.pde.internal.core.target.impl;
12
13
import java.io.File;
14
import java.util.*;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
17
import org.eclipse.osgi.util.NLS;
18
import org.eclipse.pde.internal.core.ExternalFeatureModelManager;
19
import org.eclipse.pde.internal.core.PDECore;
20
import org.eclipse.pde.internal.core.ifeature.*;
21
import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
22
import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService;
23
24
/**
25
 * A container of the bundles contained in a feature.
26
 * 
27
 * @since 3.5
28
 */
29
public class FeatureBundleContainer extends AbstractBundleContainer {
30
31
	/**
32
	 * Feature symbolic name 
33
	 */
34
	private String fId;
35
36
	/**
37
	 * Feature version or <code>null</code>
38
	 */
39
	private String fVersion;
40
41
	/**
42
	 * Install location which may contain string substitution variables
43
	 */
44
	private String fHome;
45
46
	/**
47
	 * Constructs a new feature bundle container for the feature at the specified
48
	 * location. Plug-ins are resolved in the plug-ins directory of the given home
49
	 * directory. When version is unspecified, the most recent version is used.
50
	 * 
51
	 * @param home root directory containing the features directory which
52
	 *  may contain string substitution variables
53
	 * @param name feature symbolic name
54
	 * @param version feature version, or <code>null</code> if unspecified
55
	 */
56
	FeatureBundleContainer(String home, String name, String version) {
57
		fId = name;
58
		fVersion = version;
59
		fHome = home;
60
	}
61
62
	/* (non-Javadoc)
63
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#getHomeLocation()
64
	 */
65
	public String getHomeLocation() throws CoreException {
66
		return resolveHomeLocation().toOSString();
67
	}
68
69
	/**
70
	 * Returns the home location with all variables resolved as a path.
71
	 * 
72
	 * @return resolved home location
73
	 * @throws CoreException
74
	 */
75
	private IPath resolveHomeLocation() throws CoreException {
76
		return new Path(resolveVariables(fHome));
77
	}
78
79
	/**
80
	 * Resolves and returns the directory containing the feature.
81
	 * 
82
	 * @return feature directory
83
	 * @throws CoreException if unable to resolve
84
	 */
85
	private File resolveFeatureLocation() throws CoreException {
86
		File features = resolveHomeLocation().append("features").toFile(); //$NON-NLS-1$
87
		if (!features.exists() || features.isFile()) {
88
			throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.FeatureBundleContainer_0, features.toString())));
89
		}
90
		// if a specific version is specified, use it
91
		if (fVersion != null) {
92
			StringBuffer buf = new StringBuffer();
93
			String name = buf.append(fId).append("_").append(fVersion).toString(); //$NON-NLS-1$
94
			return new File(features, name);
95
		}
96
		// use most recent version
97
		String[] list = features.list();
98
		List versions = new ArrayList();
99
		StringBuffer buf = new StringBuffer();
100
		String prefix = buf.append(fId).append("_").toString(); //$NON-NLS-1$
101
		for (int i = 0; i < list.length; i++) {
102
			String name = list[i];
103
			if (name.startsWith(prefix)) {
104
				versions.add(name);
105
			}
106
		}
107
		if (versions.isEmpty()) {
108
			throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.FeatureBundleContainer_1, fId)));
109
		}
110
		Collections.sort(versions);
111
		String name = (String) versions.get(versions.size() - 1);
112
		return new File(features, name);
113
	}
114
115
	/* (non-Javadoc)
116
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
117
	 */
118
	public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
119
		return resolveBundles0(monitor, false);
120
	}
121
122
	/* (non-Javadoc)
123
	 * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
124
	 */
125
	public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
126
		return resolveBundles0(monitor, true);
127
	}
128
129
	private BundleInfo[] resolveBundles0(IProgressMonitor monitor, boolean source) throws CoreException {
130
		IFeatureModel model = null;
131
		try {
132
			File location = resolveFeatureLocation();
133
			File manifest = new File(location, "feature.xml"); //$NON-NLS-1$
134
			if (!manifest.exists() || !manifest.isFile()) {
135
				throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.FeatureBundleContainer_2, fId)));
136
			}
137
			model = ExternalFeatureModelManager.createModel(manifest);
138
			if (model == null || !model.isLoaded()) {
139
				throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.FeatureBundleContainer_3, fId)));
140
			}
141
			// search bundles in plug-ins directory
142
			ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
143
			if (service == null) {
144
				throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.FeatureBundleContainer_4));
145
			}
146
			File dir = new File(manifest.getParentFile().getParentFile().getParentFile(), "plugins"); //$NON-NLS-1$
147
			if (!dir.exists() || !dir.isDirectory()) {
148
				throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.FeatureBundleContainer_5, fId)));
149
			}
150
			IBundleContainer container = service.newDirectoryContainer(dir.getAbsolutePath());
151
			BundleInfo[] bundles = null;
152
			if (source) {
153
				bundles = container.resolveSourceBundles(null);
154
			} else {
155
				bundles = container.resolveBundles(null);
156
			}
157
			Map bundleMap = new HashMap();
158
			for (int i = 0; i < bundles.length; i++) {
159
				BundleInfo info = bundles[i];
160
				List list = (List) bundleMap.get(info.getSymbolicName());
161
				if (list == null) {
162
					list = new ArrayList();
163
					bundleMap.put(info.getSymbolicName(), list);
164
				}
165
				list.add(info);
166
			}
167
			IFeature feature = model.getFeature();
168
			IFeaturePlugin[] plugins = feature.getPlugins();
169
			List results = new ArrayList();
170
			for (int i = 0; i < plugins.length; i++) {
171
				IFeaturePlugin plugin = plugins[i];
172
				List list = (List) bundleMap.get(plugin.getId());
173
				if (list != null) {
174
					Iterator iterator = list.iterator();
175
					boolean added = false;
176
					while (iterator.hasNext()) {
177
						BundleInfo info = (BundleInfo) iterator.next();
178
						if (info.getVersion().equals(plugin.getVersion())) {
179
							results.add(info);
180
							added = true;
181
							break;
182
						}
183
					}
184
					if (!added) {
185
						// use first one
186
						results.add(list.get(0));
187
					}
188
				} else {
189
					// TODO: missing plug-in, we should probably include a status with resolution
190
				}
191
192
			}
193
			return (BundleInfo[]) results.toArray(new BundleInfo[results.size()]);
194
		} finally {
195
			if (model != null) {
196
				model.dispose();
197
			}
198
		}
199
	}
200
201
}
(-)src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java (+37 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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.pde.internal.core.target.impl;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.variables.IStringVariableManager;
15
import org.eclipse.core.variables.VariablesPlugin;
16
import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
17
18
/**
19
 * Common function for bundle containers.
20
 * 
21
 * @since 3.5
22
 */
23
public abstract class AbstractBundleContainer implements IBundleContainer {
24
25
	/**
26
	 * Resolves any string substitution variables in the given text returning
27
	 * the result.
28
	 * 
29
	 * @param text text to resolve
30
	 * @return result of the resolution
31
	 * @throws CoreException if unable to resolve 
32
	 */
33
	protected String resolveVariables(String text) throws CoreException {
34
		IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
35
		return manager.performStringSubstitution(text);
36
	}
37
}

Return to bug 256910