### Eclipse Workspace Patch 1.0
#P org.eclipse.pde.ui.tests
Index: src/org/eclipse/pde/ui/tests/target/TargetDefinitionTests.java
===================================================================
RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionTests.java,v
retrieving revision 1.1
diff -u -r1.1 TargetDefinitionTests.java
--- src/org/eclipse/pde/ui/tests/target/TargetDefinitionTests.java 8 Jan 2009 17:25:13 -0000 1.1
+++ src/org/eclipse/pde/ui/tests/target/TargetDefinitionTests.java 9 Jan 2009 22:24:16 -0000
@@ -1,340 +1,681 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.pde.ui.tests.target;
-
-import org.eclipse.core.runtime.CoreException;
-
-import org.eclipse.pde.internal.core.target.provisional.ITargetHandle;
-
-import org.eclipse.core.resources.IFile;
-
-import org.eclipse.core.resources.ResourcesPlugin;
-
-import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService;
-
-import java.io.*;
-import java.net.URL;
-import java.util.*;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import junit.framework.TestCase;
-import org.eclipse.core.runtime.*;
-import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
-import org.eclipse.pde.core.plugin.TargetPlatform;
-import org.eclipse.pde.internal.core.*;
-import org.eclipse.pde.internal.core.target.provisional.*;
-import org.eclipse.pde.internal.ui.tests.macro.MacroPlugin;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Tests for target definitions.
- *
- * @since 3.5
- */
-public class TargetDefinitionTests extends TestCase {
-
- /**
- * Retrieves all bundles (source and code) in the given target definition
- * returning them as a set of URLs.
- *
- * @param target target definition
- * @return all bundle URLs
- */
- protected Set getAllBundleURLs(ITargetDefinition target) throws Exception {
- BundleInfo[] code = target.resolveBundles(null);
- BundleInfo[] source = target.resolveSourceBundles(null);
- Set urls = new HashSet(code.length + source.length);
- for (int i = 0; i < code.length; i++) {
- urls.add(new File(code[i].getLocation()).toURL());
- }
- for (int i = 0; i < source.length; i++) {
- urls.add(new File(source[i].getLocation()).toURL());
- }
- return urls;
- }
-
- /**
- * Extracts the classic plug-ins archive, if not already done, and returns a path to the
- * root directory containing the plug-ins.
- *
- * @return path to the plug-ins directory
- * @throws Exception
- */
- protected IPath extractClassicPlugins() throws Exception {
- // extract the 3.0.2 skeleton
- IPath stateLocation = MacroPlugin.getDefault().getStateLocation();
- IPath location = stateLocation.append("classic-plugins");
- if (location.toFile().exists()) {
- return location;
- }
- URL zipURL = MacroPlugin.getBundleContext().getBundle().getEntry("/tests/targets/classic-plugins.zip");
- Path zipPath = new Path(new File(FileLocator.toFileURL(zipURL).getFile()).getAbsolutePath());
- ZipFile zipFile = new ZipFile(zipPath.toFile());
- Enumeration entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- ZipEntry entry = (ZipEntry) entries.nextElement();
- if (!entry.isDirectory()) {
- IPath entryPath = stateLocation.append(entry.getName());
- File dir = entryPath.removeLastSegments(1).toFile();
- dir.mkdirs();
- File file = entryPath.toFile();
- file.createNewFile();
- InputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry));
- byte[] bytes = getInputStreamAsByteArray(inputStream, -1);
- inputStream.close();
- BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
- outputStream.write(bytes);
- outputStream.close();
- }
- }
- zipFile.close();
- return location;
- }
-
- /**
- * Returns the target platform service or null
if none
- *
- * @return target platform service
- */
- protected ITargetPlatformService getTargetService() {
- ServiceReference reference = MacroPlugin.getBundleContext().getServiceReference(ITargetPlatformService.class.getName());
- assertNotNull("Missing target platform service", reference);
- if (reference == null)
- return null;
- return (ITargetPlatformService) MacroPlugin.getBundleContext().getService(reference);
- }
-
- /**
- * Tests that a target definition equivalent to the default target platform
- * contains the same bundles as the default target platform (this is an
- * explicit location with no target weaving).
- *
- * @throws Exception
- */
- public void testDefaultTargetPlatform() throws Exception {
- // the new way
- ITargetDefinition definition = getTargetService().newTarget();
- IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation());
- definition.setBundleContainers(new IBundleContainer[]{container});
- Set urls = getAllBundleURLs(definition);
-
- // the old way
- IPath location = new Path(TargetPlatform.getDefaultLocation());
- URL[] pluginPaths = P2Utils.readBundlesTxt(location.toOSString(), location.append("configuration").toFile().toURL());
- assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
- for (int i = 0; i < pluginPaths.length; i++) {
- URL url = pluginPaths[i];
- assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
- }
-
- }
-
- /**
- * Tests that a target definition equivalent to the default target platform
- * contains the same bundles as the default target platform using the
- * platform's configuration location (which will do target weaving). This
- * is really only tested when run as a JUnit plug-in test suite from
- * within Eclipse.
- *
- * @throws Exception
- */
- public void testWovenTargetPlatform() throws Exception {
- // the new way
- ITargetDefinition definition = getTargetService().newTarget();
- IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(),
- new File(Platform.getConfigurationLocation().getURL().getFile()).getAbsolutePath());
- definition.setBundleContainers(new IBundleContainer[]{container});
- Set urls = getAllBundleURLs(definition);
-
- // the old way
- URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation());
- assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
- for (int i = 0; i < pluginPaths.length; i++) {
- URL url = pluginPaths[i];
- assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
- }
-
- }
-
- /**
- * Tests that a bundle directory container is equivalent to scanning locations.
- *
- * @throws Exception
- */
- public void testDirectoryBundleContainer() throws Exception {
- // the new way
- ITargetDefinition definition = getTargetService().newTarget();
- IBundleContainer container = getTargetService().newDirectoryContainer(TargetPlatform.getDefaultLocation() + "/plugins");
- definition.setBundleContainers(new IBundleContainer[]{container});
- Set urls = getAllBundleURLs(definition);
-
- Preferences store = PDECore.getDefault().getPluginPreferences();
- boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
- try {
- store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
- // the old way
- URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation());
- assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
- for (int i = 0; i < pluginPaths.length; i++) {
- URL url = pluginPaths[i];
- assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
- }
- }
- finally {
- store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
- }
- }
-
- /**
- * Tests reading a 3.0.2 install with a mix of classic and OSGi plug-ins.
- *
- * @throws Exception
- */
- public void testClassicPlugins() throws Exception {
- // extract the 3.0.2 skeleton
- IPath location = extractClassicPlugins();
-
- // the new way
- ITargetDefinition definition = getTargetService().newTarget();
- IBundleContainer container = getTargetService().newDirectoryContainer(location.toOSString());
- definition.setBundleContainers(new IBundleContainer[]{container});
- Set urls = getAllBundleURLs(definition);
-
- Preferences store = PDECore.getDefault().getPluginPreferences();
- boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
- try {
- store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
- // the old way
- URL[] pluginPaths = PluginPathFinder.getPluginPaths(location.toOSString());
- for (int i = 0; i < pluginPaths.length; i++) {
- URL url = pluginPaths[i];
- if (!urls.contains(url)) {
- System.err.println(url.toString());
- }
- }
- assertEquals("Wrong number of bundles", pluginPaths.length, urls.size());
- }
- finally {
- store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
- }
- }
-
- /**
- * Tests identification of source bundles in a 3.0.2 install.
- *
- * @throws Exception
- */
- public void testClassicSourcePlugins() throws Exception {
- // extract the 3.0.2 skeleton
- IPath location = extractClassicPlugins();
-
- // the new way
- ITargetDefinition definition = getTargetService().newTarget();
- IBundleContainer container = getTargetService().newDirectoryContainer(location.toOSString());
- definition.setBundleContainers(new IBundleContainer[]{container});
- BundleInfo[] bundles = definition.resolveSourceBundles(null);
- assertEquals("Wrong number of source bundles", 3, bundles.length);
- Set names = new HashSet();
- for (int i = 0; i < bundles.length; i++) {
- names.add(bundles[i].getSymbolicName());
- }
- String[] expected = new String[]{"org.eclipse.platform.source", "org.eclipse.jdt.source", "org.eclipse.pde.source"};
- for (int i = 0; i < expected.length; i++) {
- assertTrue("Missing source for " + expected[i], names.contains(expected[i]));
- }
- }
-
- /**
- * Returns the given input stream as a byte array
- * @param stream the stream to get as a byte array
- * @param length the length to read from the stream or -1 for unknown
- * @return the given input stream as a byte array
- * @throws IOException
- */
- public static byte[] getInputStreamAsByteArray(InputStream stream, int length) throws IOException {
- byte[] contents;
- if (length == -1) {
- contents = new byte[0];
- int contentsLength = 0;
- int amountRead = -1;
- do {
- // read at least 8K
- int amountRequested = Math.max(stream.available(), 8192);
- // resize contents if needed
- if (contentsLength + amountRequested > contents.length) {
- System.arraycopy(contents,
- 0,
- contents = new byte[contentsLength + amountRequested],
- 0,
- contentsLength);
- }
- // read as many bytes as possible
- amountRead = stream.read(contents, contentsLength, amountRequested);
- if (amountRead > 0) {
- // remember length of contents
- contentsLength += amountRead;
- }
- } while (amountRead != -1);
- // resize contents if necessary
- if (contentsLength < contents.length) {
- System.arraycopy(contents, 0, contents = new byte[contentsLength], 0, contentsLength);
- }
- } else {
- contents = new byte[length];
- int len = 0;
- int readSize = 0;
- while ((readSize != -1) && (len != length)) {
- // See PR 1FMS89U
- // We record first the read size. In this case length is the actual
- // read size.
- len += readSize;
- readSize = stream.read(contents, len, length - len);
- }
- }
- return contents;
- }
-
- /**
- * Tests restoration of a handle to target definition in an IFile
- * @throws CoreException
- */
- public void testWorkspaceTargetHandleMemento() throws CoreException {
- ITargetPlatformService service = getTargetService();
- IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("does/not/exist"));
- ITargetHandle handle = service.getTarget(file);
- assertFalse("Target should not exist", handle.exists());
- String memento = handle.getMemento();
- assertNotNull("Missing memento", memento);
- ITargetHandle handle2 = service.getTarget(memento);
- assertEquals("Restore failed", handle, handle2);
- IFile file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("does/not/exist/either"));
- ITargetHandle handle3 = service.getTarget(file2);
- assertFalse("Should be different targets", handle.equals(handle3));
- }
-
- /**
- * Tests restoration of a handle to target definition in local metadata
- *
- * @throws CoreException
- * @throws InterruptedException
- */
- public void testLocalTargetHandleMemento() throws CoreException, InterruptedException {
- ITargetPlatformService service = getTargetService();
- ITargetHandle handle = service.newTarget().getHandle();
- assertFalse("Target should not exist", handle.exists());
- String memento = handle.getMemento();
- assertNotNull("Missing memento", memento);
- ITargetHandle handle2 = service.getTarget(memento);
- assertEquals("Restore failed", handle, handle2);
- ITargetHandle handle3 = service.newTarget().getHandle();
- assertFalse("Should be different targets", handle.equals(handle3));
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.ui.tests.target;
+
+import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService;
+
+import org.eclipse.pde.internal.core.target.provisional.LoadTargetDefinitionJob;
+
+import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
+
+import java.io.*;
+import java.net.URL;
+import java.util.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import junit.framework.TestCase;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
+import org.eclipse.pde.core.plugin.IPluginModelBase;
+import org.eclipse.pde.core.plugin.TargetPlatform;
+import org.eclipse.pde.internal.core.*;
+import org.eclipse.pde.internal.core.target.provisional.*;
+import org.eclipse.pde.internal.ui.tests.macro.MacroPlugin;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Tests for target definitions.
+ *
+ * @since 3.5
+ */
+public class TargetDefinitionTests extends TestCase {
+
+ /**
+ * Retrieves all bundles (source and code) in the given target definition
+ * returning them as a set of URLs.
+ *
+ * @param target target definition
+ * @return all bundle URLs
+ */
+ protected Set getAllBundleURLs(ITargetDefinition target) throws Exception {
+ BundleInfo[] code = target.resolveBundles(null);
+ BundleInfo[] source = target.resolveSourceBundles(null);
+ Set urls = new HashSet(code.length + source.length);
+ for (int i = 0; i < code.length; i++) {
+ urls.add(new File(code[i].getLocation()).toURL());
+ }
+ for (int i = 0; i < source.length; i++) {
+ urls.add(new File(source[i].getLocation()).toURL());
+ }
+ return urls;
+ }
+
+ /**
+ * Extracts the classic plug-ins archive, if not already done, and returns a path to the
+ * root directory containing the plug-ins.
+ *
+ * @return path to the plug-ins directory
+ * @throws Exception
+ */
+ protected IPath extractClassicPlugins() throws Exception {
+ // extract the 3.0.2 skeleton
+ IPath stateLocation = MacroPlugin.getDefault().getStateLocation();
+ IPath location = stateLocation.append("classic-plugins");
+ if (location.toFile().exists()) {
+ return location;
+ }
+ URL zipURL = MacroPlugin.getBundleContext().getBundle().getEntry("/tests/targets/classic-plugins.zip");
+ Path zipPath = new Path(new File(FileLocator.toFileURL(zipURL).getFile()).getAbsolutePath());
+ ZipFile zipFile = new ZipFile(zipPath.toFile());
+ Enumeration entries = zipFile.entries();
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = (ZipEntry) entries.nextElement();
+ if (!entry.isDirectory()) {
+ IPath entryPath = stateLocation.append(entry.getName());
+ File dir = entryPath.removeLastSegments(1).toFile();
+ dir.mkdirs();
+ File file = entryPath.toFile();
+ file.createNewFile();
+ InputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry));
+ byte[] bytes = getInputStreamAsByteArray(inputStream, -1);
+ inputStream.close();
+ BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
+ outputStream.write(bytes);
+ outputStream.close();
+ }
+ }
+ zipFile.close();
+ return location;
+ }
+
+ /**
+ * Returns the target platform service or null
if none
+ *
+ * @return target platform service
+ */
+ protected ITargetPlatformService getTargetService() {
+ ServiceReference reference = MacroPlugin.getBundleContext().getServiceReference(ITargetPlatformService.class.getName());
+ assertNotNull("Missing target platform service", reference);
+ if (reference == null)
+ return null;
+ return (ITargetPlatformService) MacroPlugin.getBundleContext().getService(reference);
+ }
+
+ /**
+ * Returns a default target platform that takes target weaving into account
+ * if in a second instance of Eclipse. This allows the target platfrom to be
+ * reset after changing it in a test.
+ *
+ * @return default settings for target platform
+ */
+ protected ITargetDefinition getDefaultTargetPlatorm() {
+ ITargetDefinition definition = getTargetService().newTarget();
+ IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(),
+ new File(Platform.getConfigurationLocation().getURL().getFile()).getAbsolutePath());
+ definition.setBundleContainers(new IBundleContainer[]{container});
+ return definition;
+ }
+
+ /**
+ * Used to reset the target platform to original settings after a test that changes
+ * the target platform.
+ */
+ protected void resetTargetPlatform() {
+ ITargetDefinition definition = getDefaultTargetPlatorm();
+ setTargetPlatform(definition);
+ }
+
+ /**
+ * Sets the target platform based on the given definition.
+ *
+ * @param target target definition
+ */
+ protected void setTargetPlatform(ITargetDefinition target) {
+ LoadTargetDefinitionJob job = new LoadTargetDefinitionJob(target);
+ job.schedule();
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ assertFalse("Target platform reset interrupted", true);
+ }
+ }
+
+ /**
+ * Tests that resetting the target platform should work OK (i.e. is equivalent to the
+ * models in the default target platform).
+ *
+ * @throws CoreException
+ */
+ public void testResetTargetPlatform() throws Exception {
+ ITargetDefinition definition = getDefaultTargetPlatorm();
+ Set urls = getAllBundleURLs(definition);
+
+ // current platform
+ IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();
+
+ // should be equivalent
+ assertEquals("Should have same number of bundles", urls.size(), models.length);
+ for (int i = 0; i < models.length; i++) {
+ String location = models[i].getInstallLocation();
+ assertTrue("Missing plug-in " + location, urls.contains(new File(location).toURL()));
+ }
+ }
+
+ /**
+ * Tests that a target definition equivalent to the default target platform
+ * contains the same bundles as the default target platform (this is an
+ * explicit location with no target weaving).
+ *
+ * @throws Exception
+ */
+ public void testDefaultTargetPlatform() throws Exception {
+ // the new way
+ ITargetDefinition definition = getTargetService().newTarget();
+ IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation());
+ definition.setBundleContainers(new IBundleContainer[]{container});
+ Set urls = getAllBundleURLs(definition);
+
+ // the old way
+ IPath location = new Path(TargetPlatform.getDefaultLocation());
+ URL[] pluginPaths = P2Utils.readBundlesTxt(location.toOSString(), location.append("configuration").toFile().toURL());
+ assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
+ for (int i = 0; i < pluginPaths.length; i++) {
+ URL url = pluginPaths[i];
+ assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
+ }
+
+ }
+
+ /**
+ * Tests that a target definition equivalent to the default target platform
+ * contains the same bundles as the default target platform (this is an
+ * explicit location with no target weaving), when created with a variable
+ * referencing ${eclipse_home}
+ *
+ * @throws Exception
+ */
+ public void testEclipseHomeTargetPlatform() throws Exception {
+ // the new way
+ ITargetDefinition definition = getTargetService().newTarget();
+ IBundleContainer container = getTargetService().newProfileContainer("${eclipse_home}");
+ definition.setBundleContainers(new IBundleContainer[]{container});
+ Set urls = getAllBundleURLs(definition);
+
+ // the old way
+ IPath location = new Path(TargetPlatform.getDefaultLocation());
+ URL[] pluginPaths = P2Utils.readBundlesTxt(location.toOSString(), location.append("configuration").toFile().toURL());
+ assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
+ for (int i = 0; i < pluginPaths.length; i++) {
+ URL url = pluginPaths[i];
+ assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
+ }
+
+ }
+
+ /**
+ * Tests that a target definition equivalent to the default target platform
+ * contains the same bundles as the default target platform (this is an
+ * explicit location with no target weaving), when created with a variable
+ * referencing ${eclipse_home}.
+ *
+ * @throws Exception
+ */
+ public void testEclipseHomeTargetPlatformAndConfigurationArea() throws Exception {
+ // the new way
+ ITargetDefinition definition = getTargetService().newTarget();
+ IBundleContainer container = getTargetService().newProfileContainer("${eclipse_home}", "${eclipse_home}/configuration");
+ definition.setBundleContainers(new IBundleContainer[]{container});
+ Set urls = getAllBundleURLs(definition);
+
+ // the old way
+ IPath location = new Path(TargetPlatform.getDefaultLocation());
+ URL[] pluginPaths = P2Utils.readBundlesTxt(location.toOSString(), location.append("configuration").toFile().toURL());
+ assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
+ for (int i = 0; i < pluginPaths.length; i++) {
+ URL url = pluginPaths[i];
+ assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
+ }
+
+ }
+
+ /**
+ * Tests that a target definition equivalent to the default target platform
+ * contains the same bundles as the default target platform using the
+ * platform's configuration location (which will do target weaving). This
+ * is really only tested when run as a JUnit plug-in test suite from
+ * within Eclipse.
+ *
+ * @throws Exception
+ */
+ public void testWovenTargetPlatform() throws Exception {
+ // the new way
+ ITargetDefinition definition = getTargetService().newTarget();
+ IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(),
+ new File(Platform.getConfigurationLocation().getURL().getFile()).getAbsolutePath());
+ definition.setBundleContainers(new IBundleContainer[]{container});
+ Set urls = getAllBundleURLs(definition);
+
+ // the old way
+ URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation());
+ assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
+ for (int i = 0; i < pluginPaths.length; i++) {
+ URL url = pluginPaths[i];
+ assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
+ }
+
+ }
+
+ /**
+ * Tests that a bundle directory container is equivalent to scanning locations.
+ *
+ * @throws Exception
+ */
+ public void testDirectoryBundleContainer() throws Exception {
+ // the new way
+ ITargetDefinition definition = getTargetService().newTarget();
+ IBundleContainer container = getTargetService().newDirectoryContainer(TargetPlatform.getDefaultLocation() + "/plugins");
+ definition.setBundleContainers(new IBundleContainer[]{container});
+ Set urls = getAllBundleURLs(definition);
+
+ Preferences store = PDECore.getDefault().getPluginPreferences();
+ boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
+ try {
+ store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
+ // the old way
+ URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation());
+ assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
+ for (int i = 0; i < pluginPaths.length; i++) {
+ URL url = pluginPaths[i];
+ assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
+ }
+ }
+ finally {
+ store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
+ }
+ }
+
+ /**
+ * Tests that a bundle directory container is equivalent to scanning locations
+ * when it uses a variable to specify its location.
+ *
+ * @throws Exception
+ */
+ public void testVariableDirectoryBundleContainer() throws Exception {
+ // the new way
+ ITargetDefinition definition = getTargetService().newTarget();
+ IBundleContainer container = getTargetService().newDirectoryContainer("${eclipse_home}/plugins");
+ definition.setBundleContainers(new IBundleContainer[]{container});
+ Set urls = getAllBundleURLs(definition);
+
+ Preferences store = PDECore.getDefault().getPluginPreferences();
+ boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
+ try {
+ store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
+ // the old way
+ URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation());
+ assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
+ for (int i = 0; i < pluginPaths.length; i++) {
+ URL url = pluginPaths[i];
+ assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
+ }
+ }
+ finally {
+ store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
+ }
+ }
+
+ /**
+ * Tests reading a 3.0.2 install with a mix of classic and OSGi plug-ins.
+ *
+ * @throws Exception
+ */
+ public void testClassicPlugins() throws Exception {
+ // extract the 3.0.2 skeleton
+ IPath location = extractClassicPlugins();
+
+ // the new way
+ ITargetDefinition definition = getTargetService().newTarget();
+ IBundleContainer container = getTargetService().newDirectoryContainer(location.toOSString());
+ definition.setBundleContainers(new IBundleContainer[]{container});
+ Set urls = getAllBundleURLs(definition);
+
+ Preferences store = PDECore.getDefault().getPluginPreferences();
+ boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
+ try {
+ store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
+ // the old way
+ URL[] pluginPaths = PluginPathFinder.getPluginPaths(location.toOSString());
+ for (int i = 0; i < pluginPaths.length; i++) {
+ URL url = pluginPaths[i];
+ if (!urls.contains(url)) {
+ System.err.println(url.toString());
+ }
+ }
+ assertEquals("Wrong number of bundles", pluginPaths.length, urls.size());
+ }
+ finally {
+ store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
+ }
+ }
+
+ /**
+ * Tests identification of source bundles in a 3.0.2 install.
+ *
+ * @throws Exception
+ */
+ public void testClassicSourcePlugins() throws Exception {
+ // extract the 3.0.2 skeleton
+ IPath location = extractClassicPlugins();
+
+ // the new way
+ ITargetDefinition definition = getTargetService().newTarget();
+ IBundleContainer container = getTargetService().newDirectoryContainer(location.toOSString());
+ definition.setBundleContainers(new IBundleContainer[]{container});
+ BundleInfo[] bundles = definition.resolveSourceBundles(null);
+ assertEquals("Wrong number of source bundles", 3, bundles.length);
+ Set names = new HashSet();
+ for (int i = 0; i < bundles.length; i++) {
+ names.add(bundles[i].getSymbolicName());
+ }
+ String[] expected = new String[]{"org.eclipse.platform.source", "org.eclipse.jdt.source", "org.eclipse.pde.source"};
+ for (int i = 0; i < expected.length; i++) {
+ assertTrue("Missing source for " + expected[i], names.contains(expected[i]));
+ }
+ }
+
+ /**
+ * Returns the given input stream as a byte array
+ * @param stream the stream to get as a byte array
+ * @param length the length to read from the stream or -1 for unknown
+ * @return the given input stream as a byte array
+ * @throws IOException
+ */
+ public static byte[] getInputStreamAsByteArray(InputStream stream, int length) throws IOException {
+ byte[] contents;
+ if (length == -1) {
+ contents = new byte[0];
+ int contentsLength = 0;
+ int amountRead = -1;
+ do {
+ // read at least 8K
+ int amountRequested = Math.max(stream.available(), 8192);
+ // resize contents if needed
+ if (contentsLength + amountRequested > contents.length) {
+ System.arraycopy(contents,
+ 0,
+ contents = new byte[contentsLength + amountRequested],
+ 0,
+ contentsLength);
+ }
+ // read as many bytes as possible
+ amountRead = stream.read(contents, contentsLength, amountRequested);
+ if (amountRead > 0) {
+ // remember length of contents
+ contentsLength += amountRead;
+ }
+ } while (amountRead != -1);
+ // resize contents if necessary
+ if (contentsLength < contents.length) {
+ System.arraycopy(contents, 0, contents = new byte[contentsLength], 0, contentsLength);
+ }
+ } else {
+ contents = new byte[length];
+ int len = 0;
+ int readSize = 0;
+ while ((readSize != -1) && (len != length)) {
+ // See PR 1FMS89U
+ // We record first the read size. In this case length is the actual
+ // read size.
+ len += readSize;
+ readSize = stream.read(contents, len, length - len);
+ }
+ }
+ return contents;
+ }
+
+ /**
+ * Tests restoration of a handle to target definition in an IFile
+ * @throws CoreException
+ */
+ public void testWorkspaceTargetHandleMemento() throws CoreException {
+ ITargetPlatformService service = getTargetService();
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("does/not/exist"));
+ ITargetHandle handle = service.getTarget(file);
+ assertFalse("Target should not exist", handle.exists());
+ String memento = handle.getMemento();
+ assertNotNull("Missing memento", memento);
+ ITargetHandle handle2 = service.getTarget(memento);
+ assertEquals("Restore failed", handle, handle2);
+ IFile file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("does/not/exist/either"));
+ ITargetHandle handle3 = service.getTarget(file2);
+ assertFalse("Should be different targets", handle.equals(handle3));
+ }
+
+ /**
+ * Tests restoration of a handle to target definition in local metadata
+ *
+ * @throws CoreException
+ * @throws InterruptedException
+ */
+ public void testLocalTargetHandleMemento() throws CoreException, InterruptedException {
+ ITargetPlatformService service = getTargetService();
+ ITargetHandle handle = service.newTarget().getHandle();
+ assertFalse("Target should not exist", handle.exists());
+ String memento = handle.getMemento();
+ assertNotNull("Missing memento", memento);
+ ITargetHandle handle2 = service.getTarget(memento);
+ assertEquals("Restore failed", handle, handle2);
+ ITargetHandle handle3 = service.newTarget().getHandle();
+ assertFalse("Should be different targets", handle.equals(handle3));
+ }
+
+ /**
+ * Returns the location of the JDT feature in the running host as
+ * a path in the local file system.
+ *
+ * @return path to JDT feature
+ */
+ protected IPath getJdtFeatureLocation() {
+ IPath path = new Path(TargetPlatform.getDefaultLocation());
+ path = path.append("features");
+ File dir = path.toFile();
+ assertTrue("Missing features directory", dir.exists() && !dir.isFile());
+ String[] files = dir.list();
+ String location = null;
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].startsWith("org.eclipse.jdt_")) {
+ location = path.append(files[i]).toOSString();
+ break;
+ }
+ }
+ assertNotNull("Missing JDT feature", location);
+ return new Path(location);
+ }
+
+ /**
+ * Tests a JDT feature bundle container contains the appropriate bundles
+ * @throws Exception
+ */
+ public void testFeatureBundleContainer() throws Exception {
+ IBundleContainer container = getTargetService().newFeatureContainer("${eclipse_home}", "org.eclipse.jdt", null);
+ BundleInfo[] bundles = container.resolveBundles(null);
+
+ Set expected = new HashSet();
+ expected.add("org.eclipse.jdt");
+ expected.add("org.eclipse.ant.ui");
+ expected.add("org.eclipse.jdt.apt.core");
+ expected.add("org.eclipse.jdt.apt.ui");
+ expected.add("org.eclipse.jdt.apt.pluggable.core");
+ expected.add("org.eclipse.jdt.compiler.apt");
+ expected.add("org.eclipse.jdt.compiler.tool");
+ expected.add("org.eclipse.jdt.core");
+ expected.add("org.eclipse.jdt.core.manipulation");
+ expected.add("org.eclipse.jdt.debug.ui");
+ expected.add("org.eclipse.jdt.debug");
+ expected.add("org.eclipse.jdt.junit");
+ expected.add("org.eclipse.jdt.junit.runtime");
+ expected.add("org.eclipse.jdt.junit4.runtime");
+ expected.add("org.eclipse.jdt.launching");
+ expected.add("org.eclipse.jdt.ui");
+ expected.add("org.junit");
+ expected.add("org.junit4");
+ expected.add("org.eclipse.jdt.doc.user");
+ if (Platform.getOS() == Platform.OS_MACOSX) {
+ expected.add("org.eclipse.jdt.launching.macosx");
+ }
+ assertEquals("Wrong number of bundles in JDT feature", expected.size(), bundles.length);
+ for (int i = 0; i < bundles.length; i++) {
+ expected.remove(bundles[i].getSymbolicName());
+ }
+ Iterator iterator = expected.iterator();
+ while (iterator.hasNext()) {
+ String name = (String) iterator.next();
+ System.err.println("Missing: " + name);
+ }
+ assertTrue("Wrong bundles in JDT feature", expected.isEmpty());
+
+
+ // should be no source bundles
+ bundles = container.resolveSourceBundles(null);
+ assertEquals("Wrong source bundle count", 0, bundles.length);
+ }
+
+ /**
+ * Tests a JDT source feature bundle container contains the appropriate bundles
+ * @throws Exception
+ */
+ public void testSourceFeatureBundleContainer() throws Exception {
+ IBundleContainer container = getTargetService().newFeatureContainer("${eclipse_home}", "org.eclipse.jdt.source", null);
+ BundleInfo[] bundles = container.resolveSourceBundles(null);
+
+ Set expected = new HashSet();
+ expected.add("org.eclipse.jdt.source");
+ expected.add("org.eclipse.ant.ui.source");
+ expected.add("org.eclipse.jdt.apt.core.source");
+ expected.add("org.eclipse.jdt.apt.ui.source");
+ expected.add("org.eclipse.jdt.apt.pluggable.core.source");
+ expected.add("org.eclipse.jdt.compiler.apt.source");
+ expected.add("org.eclipse.jdt.compiler.tool.source");
+ expected.add("org.eclipse.jdt.core.source");
+ expected.add("org.eclipse.jdt.core.manipulation.source");
+ expected.add("org.eclipse.jdt.debug.ui.source");
+ expected.add("org.eclipse.jdt.debug.source");
+ expected.add("org.eclipse.jdt.junit.source");
+ expected.add("org.eclipse.jdt.junit.runtime.source");
+ expected.add("org.eclipse.jdt.junit4.runtime.source");
+ expected.add("org.eclipse.jdt.launching.source");
+ expected.add("org.eclipse.jdt.ui.source");
+ expected.add("org.junit.source");
+ expected.add("org.junit4.source");
+ if (Platform.getOS() == Platform.OS_MACOSX) {
+ expected.add("org.eclipse.jdt.launching.macosx.source");
+ }
+ for (int i = 0; i < bundles.length; i++) {
+ expected.remove(bundles[i].getSymbolicName());
+ }
+ Iterator iterator = expected.iterator();
+ while (iterator.hasNext()) {
+ String name = (String) iterator.next();
+ System.err.println("Missing: " + name);
+ }
+ assertTrue("Wrong bundles in JDT feature", expected.isEmpty());
+
+
+ // should be one doc bundle
+ bundles = container.resolveBundles(null);
+ assertEquals("Wrong bundle count", 1, bundles.length);
+ assertEquals("Missing bundle", "org.eclipse.jdt.doc.isv", bundles[0].getSymbolicName());
+ }
+
+
+ /**
+ * Tests setting the target platform to the JDT feature with a specific version.
+ *
+ * @throws Exception
+ */
+ public void testSetTargetPlatformToJdtFeature() throws Exception {
+ try {
+ IPath location = getJdtFeatureLocation();
+ String segment = location.lastSegment();
+ int index = segment.indexOf('_');
+ assertTrue("Missing version id", index > 0);
+ String version = segment.substring(index + 1);
+ ITargetPlatformService targetService = getTargetService();
+ IBundleContainer container = targetService.newFeatureContainer("${eclipse_home}", "org.eclipse.jdt", version);
+ ITargetDefinition target = targetService.newTarget();
+ target.setBundleContainers(new IBundleContainer[]{container});
+
+ setTargetPlatform(target);
+
+ Set expected = new HashSet();
+ expected.add("org.eclipse.jdt");
+ expected.add("org.eclipse.ant.ui");
+ expected.add("org.eclipse.jdt.apt.core");
+ expected.add("org.eclipse.jdt.apt.ui");
+ expected.add("org.eclipse.jdt.apt.pluggable.core");
+ expected.add("org.eclipse.jdt.compiler.apt");
+ expected.add("org.eclipse.jdt.compiler.tool");
+ expected.add("org.eclipse.jdt.core");
+ expected.add("org.eclipse.jdt.core.manipulation");
+ expected.add("org.eclipse.jdt.debug.ui");
+ expected.add("org.eclipse.jdt.debug");
+ expected.add("org.eclipse.jdt.junit");
+ expected.add("org.eclipse.jdt.junit.runtime");
+ expected.add("org.eclipse.jdt.junit4.runtime");
+ expected.add("org.eclipse.jdt.launching");
+ expected.add("org.eclipse.jdt.ui");
+ expected.add("org.junit");
+ expected.add("org.junit4");
+ expected.add("org.eclipse.jdt.doc.user");
+ if (Platform.getOS() == Platform.OS_MACOSX) {
+ expected.add("org.eclipse.jdt.launching.macosx");
+ }
+
+ // current platform
+ IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();
+
+ assertEquals("Wrong number of bundles in JDT feature", expected.size(), models.length);
+ for (int i = 0; i < models.length; i++) {
+ expected.remove(models[i].getPluginBase().getId());
+ }
+ Iterator iterator = expected.iterator();
+ while (iterator.hasNext()) {
+ String name = (String) iterator.next();
+ System.err.println("Missing: " + name);
+ }
+ assertTrue("Wrong bundles in target platform", expected.isEmpty());
+ } finally {
+ resetTargetPlatform();
+ }
+ }
+
+ /**
+ * Tests setting the target platform to empty.
+ */
+ public void testSetEmptyTargetPlatform() {
+ try {
+ ITargetPlatformService targetService = getTargetService();
+ ITargetDefinition target = targetService.newTarget();
+
+ setTargetPlatform(target);
+
+ // current platform
+ IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();
+
+ assertEquals("Wrong number of bundles in empty target", 0, models.length);
+
+ } finally {
+ resetTargetPlatform();
+ }
+ }
+}
#P org.eclipse.pde.core
Index: src/org/eclipse/pde/internal/core/target/impl/DirectoryBundleContainer.java
===================================================================
RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/impl/DirectoryBundleContainer.java,v
retrieving revision 1.1
diff -u -r1.1 DirectoryBundleContainer.java
--- src/org/eclipse/pde/internal/core/target/impl/DirectoryBundleContainer.java 8 Jan 2009 17:25:10 -0000 1.1
+++ src/org/eclipse/pde/internal/core/target/impl/DirectoryBundleContainer.java 9 Jan 2009 22:24:18 -0000
@@ -1,289 +1,291 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.pde.internal.core.target.impl;
-
-import java.io.*;
-import java.util.*;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.runtime.spi.RegistryContributor;
-import org.eclipse.core.variables.IStringVariableManager;
-import org.eclipse.core.variables.VariablesPlugin;
-import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
-import org.eclipse.osgi.service.pluginconversion.PluginConversionException;
-import org.eclipse.osgi.service.pluginconversion.PluginConverter;
-import org.eclipse.osgi.util.ManifestElement;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.pde.internal.core.ICoreConstants;
-import org.eclipse.pde.internal.core.PDECore;
-import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
-
-/**
- * A directory of bundles.
- *
- * @since 3.5
- */
-class DirectoryBundleContainer implements IBundleContainer {
-
- /**
- * Path to this container's directory in the local file system.
- * The path may contain string substitution variables.
- */
- private String fPath;
-
- /**
- * A registry can be build to identify old school source bundles.
- */
- private IExtensionRegistry fRegistry;
-
- /**
- * Constructs a directory bundle container at the given location.
- *
- * @param path directory location in the local file system
- */
- public DirectoryBundleContainer(String path) {
- fPath = path;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
- */
- public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
- return resolveBundles(monitor, false);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
- */
- public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
- return resolveBundles(monitor, true);
- }
-
- /**
- * Resolves and returns source or code bundles based on the given flag.
- *
- * @param monitor progress monitor or null
- * @param source whether to retrieve source bundles
- * @return bundles
- * @throws CoreException
- */
- private BundleInfo[] resolveBundles(IProgressMonitor monitor, boolean source) throws CoreException {
- File dir = getDirectory();
- if (dir.exists() && dir.isDirectory()) {
- try {
- File[] files = dir.listFiles();
- SubMonitor localMonitor = SubMonitor.convert(monitor, Messages.DirectoryBundleContainer_0, files.length);
- List bundles = new ArrayList(files.length);
- for (int i = 0; i < files.length; i++) {
- if (localMonitor.isCanceled()) {
- throw new OperationCanceledException();
- }
- Map manifest = loadManifest(files[i]);
- if (manifest != null) {
- try {
- String header = (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME);
- if (header != null) {
- ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, header);
- if (elements != null) {
- String name = elements[0].getValue();
- if (name != null) {
- BundleInfo info = new BundleInfo();
- info.setSymbolicName(name);
- info.setLocation(files[i].toURI());
- header = (String) manifest.get(Constants.BUNDLE_VERSION);
- if (header != null) {
- elements = ManifestElement.parseHeader(Constants.BUNDLE_VERSION, header);
- if (elements != null) {
- info.setVersion(elements[0].getValue());
- }
- }
- if (source == isSourceBundle(files[i], name, manifest)) {
- bundles.add(info);
- }
- }
- }
- }
- } catch (BundleException e) {
- // ignore invalid bundles
- }
- }
- localMonitor.worked(1);
- }
- localMonitor.done();
- return (BundleInfo[]) bundles.toArray(new BundleInfo[bundles.size()]);
- } finally {
- if (fRegistry != null) {
- fRegistry.stop(this);
- fRegistry = null;
- }
- }
- }
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_1, fPath)));
- }
-
- /**
- * Returns whether the given bundle is a source bundle.
- *
- * @param bundle location of the bundle in the file system
- * @param symbolicName symbolic name of the bundle
- * @param manifest the bundle's manifest
- * @return whether the given bundle is a source bundle
- */
- private boolean isSourceBundle(File bundle, String symbolicName, Map manifest) {
- if (manifest.containsKey(ICoreConstants.ECLIPSE_SOURCE_BUNDLE)) {
- // this is the new source bundle identifier
- return true;
- }
- // old source bundles were never jar'd
- if (bundle.isFile()) {
- return false;
- }
- // source bundles never have a class path
- if (manifest.containsKey(Constants.BUNDLE_CLASSPATH)) {
- return false;
- }
- // check for an "org.eclipse.pde.core.source" extension
- File pxml = new File(bundle, ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR);
- if (pxml.exists()) {
- IExtensionRegistry registry = getRegistry();
- RegistryContributor contributor = new RegistryContributor(symbolicName, symbolicName, null, null);
- try {
- registry.addContribution(new BufferedInputStream(new FileInputStream(pxml)), contributor, false, null, null, this);
- IExtension[] extensions = registry.getExtensions(contributor);
- for (int i = 0; i < extensions.length; i++) {
- IExtension extension = extensions[i];
- if (ICoreConstants.EXTENSION_POINT_SOURCE.equals(extension.getExtensionPointUniqueIdentifier())) {
- return true;
- }
- }
- } catch (FileNotFoundException e) {
- }
- }
- return false;
- }
-
- /**
- * Returns an extension registry used to identify source bundles.
- *
- * @return extension registry
- */
- private IExtensionRegistry getRegistry() {
- if (fRegistry == null) {
- fRegistry = RegistryFactory.createRegistry(null, this, this);
- // contribute PDE source extension point
- String bogusDef = "\n\nnull
if none
- * @throws CoreException if manifest has invalid syntax
- */
- protected Map loadManifest(File bundleLocation) throws CoreException {
- ZipFile jarFile = null;
- InputStream manifestStream = null;
- String extension = new Path(bundleLocation.getName()).getFileExtension();
- try {
- if (extension != null && extension.equals("jar") && bundleLocation.isFile()) { //$NON-NLS-1$
- jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ);
- ZipEntry manifestEntry = jarFile.getEntry(JarFile.MANIFEST_NAME);
- if (manifestEntry != null) {
- manifestStream = jarFile.getInputStream(manifestEntry);
- }
- } else {
- File file = new File(bundleLocation, JarFile.MANIFEST_NAME);
- if (file.exists()) {
- manifestStream = new FileInputStream(file);
- } else {
- File pxml = new File(bundleLocation, ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR);
- File fxml = new File(bundleLocation, ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR);
- if (pxml.exists() || fxml.exists()) {
- // support classic non-OSGi plug-in
- PluginConverter converter = (PluginConverter) PDECore.getDefault().acquireService(PluginConverter.class.getName());
- if (converter != null) {
- try {
- Dictionary convert = converter.convertManifest(bundleLocation, false, null, false, null);
- if (convert != null) {
- Map map = new HashMap(convert.size(), 1.0f);
- Enumeration keys = convert.keys();
- while (keys.hasMoreElements()) {
- Object key = keys.nextElement();
- map.put(key, convert.get(key));
- }
- return map;
- }
- } catch (PluginConversionException e) {
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_2, bundleLocation.getAbsolutePath()), e));
- }
- }
- }
- }
- }
- if (manifestStream == null) {
- return null;
- }
- return ManifestElement.parseBundleManifest(manifestStream, new Hashtable(10));
- } catch (BundleException e) {
- PDECore.log(e);
- } catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_3, bundleLocation.getAbsolutePath()), e));
- } finally {
- closeZipFileAndStream(manifestStream, jarFile);
- }
- return null;
- }
-
- /**
- * Closes the stream and jar file if not null
.
- *
- * @param stream stream to close or null
- * @param jarFile jar to close or null
- */
- private void closeZipFileAndStream(InputStream stream, ZipFile jarFile) {
- try {
- if (stream != null) {
- stream.close();
- }
- } catch (IOException e) {
- PDECore.log(e);
- }
- try {
- if (jarFile != null) {
- jarFile.close();
- }
- } catch (IOException e) {
- PDECore.log(e);
- }
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.internal.core.target.impl;
+
+import java.io.*;
+import java.util.*;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.spi.RegistryContributor;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
+import org.eclipse.osgi.service.pluginconversion.PluginConversionException;
+import org.eclipse.osgi.service.pluginconversion.PluginConverter;
+import org.eclipse.osgi.util.ManifestElement;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.pde.internal.core.ICoreConstants;
+import org.eclipse.pde.internal.core.PDECore;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+/**
+ * A directory of bundles.
+ *
+ * @since 3.5
+ */
+class DirectoryBundleContainer extends AbstractBundleContainer {
+
+ /**
+ * Path to this container's directory in the local file system.
+ * The path may contain string substitution variables.
+ */
+ private String fPath;
+
+ /**
+ * A registry can be built to identify old school source bundles.
+ */
+ private IExtensionRegistry fRegistry;
+
+ /**
+ * Constructs a directory bundle container at the given location.
+ *
+ * @param path directory location in the local file system, may contain string substitution variables
+ */
+ public DirectoryBundleContainer(String path) {
+ fPath = path;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#getHomeLocation()
+ */
+ public String getHomeLocation() throws CoreException {
+ return getDirectory().toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
+ return resolveBundles(monitor, false);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
+ return resolveBundles(monitor, true);
+ }
+
+ /**
+ * Resolves and returns source or code bundles based on the given flag.
+ *
+ * @param monitor progress monitor or null
+ * @param source whether to retrieve source bundles
+ * @return bundles
+ * @throws CoreException
+ */
+ private BundleInfo[] resolveBundles(IProgressMonitor monitor, boolean source) throws CoreException {
+ File dir = getDirectory();
+ if (dir.exists() && dir.isDirectory()) {
+ try {
+ File[] files = dir.listFiles();
+ SubMonitor localMonitor = SubMonitor.convert(monitor, Messages.DirectoryBundleContainer_0, files.length);
+ List bundles = new ArrayList(files.length);
+ for (int i = 0; i < files.length; i++) {
+ if (localMonitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ Map manifest = loadManifest(files[i]);
+ if (manifest != null) {
+ try {
+ String header = (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME);
+ if (header != null) {
+ ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, header);
+ if (elements != null) {
+ String name = elements[0].getValue();
+ if (name != null) {
+ BundleInfo info = new BundleInfo();
+ info.setSymbolicName(name);
+ info.setLocation(files[i].toURI());
+ header = (String) manifest.get(Constants.BUNDLE_VERSION);
+ if (header != null) {
+ elements = ManifestElement.parseHeader(Constants.BUNDLE_VERSION, header);
+ if (elements != null) {
+ info.setVersion(elements[0].getValue());
+ }
+ }
+ if (source == isSourceBundle(files[i], name, manifest)) {
+ bundles.add(info);
+ }
+ }
+ }
+ }
+ } catch (BundleException e) {
+ // ignore invalid bundles
+ }
+ }
+ localMonitor.worked(1);
+ }
+ localMonitor.done();
+ return (BundleInfo[]) bundles.toArray(new BundleInfo[bundles.size()]);
+ } finally {
+ if (fRegistry != null) {
+ fRegistry.stop(this);
+ fRegistry = null;
+ }
+ }
+ }
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_1, dir.toString())));
+ }
+
+ /**
+ * Returns whether the given bundle is a source bundle.
+ *
+ * @param bundle location of the bundle in the file system
+ * @param symbolicName symbolic name of the bundle
+ * @param manifest the bundle's manifest
+ * @return whether the given bundle is a source bundle
+ */
+ private boolean isSourceBundle(File bundle, String symbolicName, Map manifest) {
+ if (manifest.containsKey(ICoreConstants.ECLIPSE_SOURCE_BUNDLE)) {
+ // this is the new source bundle identifier
+ return true;
+ }
+ // old source bundles were never jar'd
+ if (bundle.isFile()) {
+ return false;
+ }
+ // source bundles never have a class path
+ if (manifest.containsKey(Constants.BUNDLE_CLASSPATH)) {
+ return false;
+ }
+ // check for an "org.eclipse.pde.core.source" extension
+ File pxml = new File(bundle, ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR);
+ if (pxml.exists()) {
+ IExtensionRegistry registry = getRegistry();
+ RegistryContributor contributor = new RegistryContributor(symbolicName, symbolicName, null, null);
+ try {
+ registry.addContribution(new BufferedInputStream(new FileInputStream(pxml)), contributor, false, null, null, this);
+ IExtension[] extensions = registry.getExtensions(contributor);
+ for (int i = 0; i < extensions.length; i++) {
+ IExtension extension = extensions[i];
+ if (ICoreConstants.EXTENSION_POINT_SOURCE.equals(extension.getExtensionPointUniqueIdentifier())) {
+ return true;
+ }
+ }
+ } catch (FileNotFoundException e) {
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns an extension registry used to identify source bundles.
+ *
+ * @return extension registry
+ */
+ private IExtensionRegistry getRegistry() {
+ if (fRegistry == null) {
+ fRegistry = RegistryFactory.createRegistry(null, this, this);
+ // contribute PDE source extension point
+ String bogusDef = "\n\nnull
if none
+ * @throws CoreException if manifest has invalid syntax
+ */
+ protected Map loadManifest(File bundleLocation) throws CoreException {
+ ZipFile jarFile = null;
+ InputStream manifestStream = null;
+ String extension = new Path(bundleLocation.getName()).getFileExtension();
+ try {
+ if (extension != null && extension.equals("jar") && bundleLocation.isFile()) { //$NON-NLS-1$
+ jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ);
+ ZipEntry manifestEntry = jarFile.getEntry(JarFile.MANIFEST_NAME);
+ if (manifestEntry != null) {
+ manifestStream = jarFile.getInputStream(manifestEntry);
+ }
+ } else {
+ File file = new File(bundleLocation, JarFile.MANIFEST_NAME);
+ if (file.exists()) {
+ manifestStream = new FileInputStream(file);
+ } else {
+ File pxml = new File(bundleLocation, ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR);
+ File fxml = new File(bundleLocation, ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR);
+ if (pxml.exists() || fxml.exists()) {
+ // support classic non-OSGi plug-in
+ PluginConverter converter = (PluginConverter) PDECore.getDefault().acquireService(PluginConverter.class.getName());
+ if (converter != null) {
+ try {
+ Dictionary convert = converter.convertManifest(bundleLocation, false, null, false, null);
+ if (convert != null) {
+ Map map = new HashMap(convert.size(), 1.0f);
+ Enumeration keys = convert.keys();
+ while (keys.hasMoreElements()) {
+ Object key = keys.nextElement();
+ map.put(key, convert.get(key));
+ }
+ return map;
+ }
+ } catch (PluginConversionException e) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_2, bundleLocation.getAbsolutePath()), e));
+ }
+ }
+ }
+ }
+ }
+ if (manifestStream == null) {
+ return null;
+ }
+ return ManifestElement.parseBundleManifest(manifestStream, new Hashtable(10));
+ } catch (BundleException e) {
+ PDECore.log(e);
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_3, bundleLocation.getAbsolutePath()), e));
+ } finally {
+ closeZipFileAndStream(manifestStream, jarFile);
+ }
+ return null;
+ }
+
+ /**
+ * Closes the stream and jar file if not null
.
+ *
+ * @param stream stream to close or null
+ * @param jarFile jar to close or null
+ */
+ private void closeZipFileAndStream(InputStream stream, ZipFile jarFile) {
+ try {
+ if (stream != null) {
+ stream.close();
+ }
+ } catch (IOException e) {
+ PDECore.log(e);
+ }
+ try {
+ if (jarFile != null) {
+ jarFile.close();
+ }
+ } catch (IOException e) {
+ PDECore.log(e);
+ }
+ }
+}
Index: src/org/eclipse/pde/internal/core/target/impl/ProfileBundleContainer.java
===================================================================
RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/impl/ProfileBundleContainer.java,v
retrieving revision 1.1
diff -u -r1.1 ProfileBundleContainer.java
--- src/org/eclipse/pde/internal/core/target/impl/ProfileBundleContainer.java 8 Jan 2009 17:25:10 -0000 1.1
+++ src/org/eclipse/pde/internal/core/target/impl/ProfileBundleContainer.java 9 Jan 2009 22:24:18 -0000
@@ -1,95 +1,114 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.pde.internal.core.target.impl;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import org.eclipse.core.runtime.*;
-import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.pde.internal.core.P2Utils;
-import org.eclipse.pde.internal.core.PDECore;
-import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
-
-/**
- * A bundle container representing an installed profile.
- *
- * @since 3.5
- */
-class ProfileBundleContainer implements IBundleContainer {
-
- /**
- * Path to home/root install location
- */
- private String fHome;
-
- /**
- * Alternate configuration location or null
if default
- */
- private String fConfiguration;
-
- /**
- * Creates a new bundle container for the profile at the specified location.
- *
- * @param home path in local file system
- * @param configurationLocation alternate configuration location or null
for default
- */
- public ProfileBundleContainer(String home, String configurationLocation) {
- fHome = home;
- fConfiguration = configurationLocation;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
- */
- public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
- URL configUrl = getConfigurationArea();
- BundleInfo[] infos = P2Utils.readBundles(new Path(fHome).toOSString(), configUrl);
- if (infos == null) {
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.ProfileBundleContainer_0, fHome)));
- }
- return infos;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
- */
- public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
- URL configUrl = getConfigurationArea();
- BundleInfo[] source = P2Utils.readSourceBundles(new Path(fHome).toOSString(), configUrl);
- if (source == null) {
- source = new BundleInfo[0];
- }
- return source;
- }
-
- /**
- * Returns a URL to the configuration area associated with this profile.
- *
- * @return configuration area URL
- * @throws CoreException if unable to generate a URL
- */
- private URL getConfigurationArea() throws CoreException {
- IPath home = new Path(fHome);
- IPath configuration = null;
- if (fConfiguration == null) {
- configuration = home.append("configuration"); //$NON-NLS-1$
- } else {
- configuration = new Path(fConfiguration);
- }
- try {
- return configuration.toFile().toURL();
- } catch (MalformedURLException e) {
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.ProfileBundleContainer_1, fHome), e));
- }
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.internal.core.target.impl;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.pde.internal.core.P2Utils;
+import org.eclipse.pde.internal.core.PDECore;
+
+/**
+ * A bundle container representing an installed profile.
+ *
+ * @since 3.5
+ */
+class ProfileBundleContainer extends AbstractBundleContainer {
+
+ /**
+ * Path to home/root install location. May contain string variables.
+ */
+ private String fHome;
+
+ /**
+ * Alternate configuration location or null
if default.
+ * May contain string variables.
+ */
+ private String fConfiguration;
+
+ /**
+ * Creates a new bundle container for the profile at the specified location.
+ *
+ * @param home path in local file system, may contain string variables
+ * @param configurationLocation alternate configuration location or null
for default,
+ * may contain string variables
+ */
+ public ProfileBundleContainer(String home, String configurationLocation) {
+ fHome = home;
+ fConfiguration = configurationLocation;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#getHomeLocation()
+ */
+ public String getHomeLocation() throws CoreException {
+ return resolveHomeLocation().toOSString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
+ URL configUrl = getConfigurationArea();
+ IPath home = resolveHomeLocation();
+ BundleInfo[] infos = P2Utils.readBundles(home.toOSString(), configUrl);
+ if (infos == null) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.ProfileBundleContainer_0, home.toOSString())));
+ }
+ return infos;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
+ URL configUrl = getConfigurationArea();
+ BundleInfo[] source = P2Utils.readSourceBundles(resolveHomeLocation().toOSString(), configUrl);
+ if (source == null) {
+ source = new BundleInfo[0];
+ }
+ return source;
+ }
+
+ /**
+ * Returns the home location with all variables resolved as a path.
+ *
+ * @return resolved home location
+ * @throws CoreException
+ */
+ private IPath resolveHomeLocation() throws CoreException {
+ return new Path(resolveVariables(fHome));
+ }
+
+ /**
+ * Returns a URL to the configuration area associated with this profile.
+ *
+ * @return configuration area URL
+ * @throws CoreException if unable to generate a URL
+ */
+ private URL getConfigurationArea() throws CoreException {
+ IPath home = resolveHomeLocation();
+ IPath configuration = null;
+ if (fConfiguration == null) {
+ configuration = home.append("configuration"); //$NON-NLS-1$
+ } else {
+ configuration = new Path(resolveVariables(fConfiguration));
+ }
+ try {
+ return configuration.toFile().toURL();
+ } catch (MalformedURLException e) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.ProfileBundleContainer_1, home.toOSString()), e));
+ }
+ }
+
+}
Index: src/org/eclipse/pde/internal/core/target/impl/Messages.java
===================================================================
RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/impl/Messages.java,v
retrieving revision 1.1
diff -u -r1.1 Messages.java
--- src/org/eclipse/pde/internal/core/target/impl/Messages.java 8 Jan 2009 17:25:10 -0000 1.1
+++ src/org/eclipse/pde/internal/core/target/impl/Messages.java 9 Jan 2009 22:24:18 -0000
@@ -1,39 +1,54 @@
-/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.pde.internal.core.target.impl;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- *
- */
-public class Messages extends NLS {
- private static final String BUNDLE_NAME = "org.eclipse.pde.internal.core.target.impl.Messages"; //$NON-NLS-1$
- public static String DirectoryBundleContainer_0;
- public static String DirectoryBundleContainer_1;
- public static String DirectoryBundleContainer_2;
- public static String DirectoryBundleContainer_3;
- public static String LocalTargetHandle_0;
- public static String LocalTargetHandle_1;
- public static String LocalTargetHandle_2;
- public static String ProfileBundleContainer_0;
- public static String ProfileBundleContainer_1;
- public static String TargetPlatformService_0;
- public static String TargetPlatformService_1;
- public static String WorkspaceFileTargetHandle_0;
- static {
- // initialize resource bundle
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-
- private Messages() {
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.internal.core.target.impl;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.pde.internal.core.target.impl.Messages"; //$NON-NLS-1$
+ public static String DirectoryBundleContainer_0;
+ public static String DirectoryBundleContainer_1;
+ public static String DirectoryBundleContainer_2;
+ public static String DirectoryBundleContainer_3;
+ public static String FeatureBundleContainer_0;
+ public static String FeatureBundleContainer_1;
+ public static String FeatureBundleContainer_2;
+ public static String FeatureBundleContainer_3;
+ public static String FeatureBundleContainer_4;
+ public static String FeatureBundleContainer_5;
+ public static String LoadTargetDefinitionJob_0;
+ public static String LoadTargetDefinitionJob_1;
+ public static String LoadTargetOperation_argsTaskName;
+ public static String LoadTargetOperation_envTaskName;
+ public static String LoadTargetOperation_implicitPluginsTaskName;
+ public static String LoadTargetOperation_jreTaskName;
+ public static String LoadTargetOperation_loadPluginsTaskName;
+ public static String LoadTargetOperation_mainTaskName;
+ public static String LoadTargetOperation_reloadTaskName;
+ public static String LocalTargetHandle_0;
+ public static String LocalTargetHandle_1;
+ public static String LocalTargetHandle_2;
+ public static String ProfileBundleContainer_0;
+ public static String ProfileBundleContainer_1;
+ public static String TargetPlatformService_0;
+ public static String TargetPlatformService_1;
+ public static String WorkspaceFileTargetHandle_0;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
Index: src/org/eclipse/pde/internal/core/target/impl/TargetDefinition.java
===================================================================
RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/impl/TargetDefinition.java,v
retrieving revision 1.1
diff -u -r1.1 TargetDefinition.java
--- src/org/eclipse/pde/internal/core/target/impl/TargetDefinition.java 8 Jan 2009 17:25:11 -0000 1.1
+++ src/org/eclipse/pde/internal/core/target/impl/TargetDefinition.java 9 Jan 2009 22:24:18 -0000
@@ -1,248 +1,252 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.pde.internal.core.target.impl;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
-import org.eclipse.pde.internal.core.target.provisional.*;
-
-/**
- * Target definition implementation.
- *
- * @since 3.5
- */
-class TargetDefinition implements ITargetDefinition {
-
- // name and description
- private String fName;
- private String fDescription;
-
- // arguments
- private String fProgramArgs;
- private String fVMArgs;
-
- // environment settings
- private String fEE;
- private String fArch;
- private String fOS;
- private String fWS;
- private String fNL;
-
- // bundle containers
- private IBundleContainer[] fContainers;
-
- // handle
- private ITargetHandle fHandle;
-
- /**
- * Constructs a target definition based on the given handle.
- */
- TargetDefinition(ITargetHandle handle) {
- fHandle = handle;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getArch()
- */
- public String getArch() {
- return fArch;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getBundleContainers()
- */
- public IBundleContainer[] getBundleContainers() {
- return fContainers;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getDescription()
- */
- public String getDescription() {
- return fDescription;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getExecutionEnvironment()
- */
- public String getExecutionEnvironment() {
- return fEE;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getNL()
- */
- public String getNL() {
- return fNL;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getName()
- */
- public String getName() {
- return fName;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getOS()
- */
- public String getOS() {
- return fOS;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getProgramArguments()
- */
- public String getProgramArguments() {
- return fProgramArgs;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getVMArguments()
- */
- public String getVMArguments() {
- return fVMArgs;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getWS()
- */
- public String getWS() {
- return fWS;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setArch(java.lang.String)
- */
- public void setArch(String arch) {
- fArch = arch;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setDescription(java.lang.String)
- */
- public void setDescription(String description) {
- fDescription = description;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setExecutionEnvironment(java.lang.String)
- */
- public void setExecutionEnvironment(String environment) {
- fEE = environment;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setNL(java.lang.String)
- */
- public void setNL(String nl) {
- fNL = nl;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setName(java.lang.String)
- */
- public void setName(String name) {
- fName = name;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setOS(java.lang.String)
- */
- public void setOS(String os) {
- fOS = os;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setProgramArguments(java.lang.String)
- */
- public void setProgramArguments(String args) {
- fProgramArgs = args;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setVMArguments(java.lang.String)
- */
- public void setVMArguments(String args) {
- fVMArgs = args;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setWS(java.lang.String)
- */
- public void setWS(String ws) {
- fWS = ws;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setBundleContainers(org.eclipse.pde.internal.core.target.provisional.IBundleContainer[])
- */
- public void setBundleContainers(IBundleContainer[] containers) {
- fContainers = containers;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
- */
- public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
- IBundleContainer[] containers = getBundleContainers();
- List bundles = new ArrayList();
- for (int i = 0; i < containers.length; i++) {
- BundleInfo[] infos = containers[i].resolveBundles(monitor);
- bundles.addAll(Arrays.asList(infos));
- }
- return (BundleInfo[]) bundles.toArray(new BundleInfo[bundles.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
- */
- public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
- IBundleContainer[] containers = getBundleContainers();
- List source = new ArrayList();
- for (int i = 0; i < containers.length; i++) {
- BundleInfo[] infos = containers[i].resolveSourceBundles(monitor);
- source.addAll(Arrays.asList(infos));
- }
- return (BundleInfo[]) source.toArray(new BundleInfo[source.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getHandle()
- */
- public ITargetHandle getHandle() {
- return fHandle;
- }
-
- /**
- * Build contents from the given stream.
- *
- * @param stream input stream
- * @throws CoreException if an error occurs
- */
- void setContents(InputStream stream) throws CoreException {
- // TODO: read stream
- }
-
- /**
- * Persists contents to the given stream.
- *
- * @param stream output stream
- * @throws CoreException if an error occurs
- */
- void write(OutputStream stream) throws CoreException {
- // TODO: persist content
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.internal.core.target.impl;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
+import org.eclipse.pde.internal.core.target.provisional.*;
+
+/**
+ * Target definition implementation.
+ *
+ * @since 3.5
+ */
+class TargetDefinition implements ITargetDefinition {
+
+ // name and description
+ private String fName;
+ private String fDescription;
+
+ // arguments
+ private String fProgramArgs;
+ private String fVMArgs;
+
+ // environment settings
+ private String fEE;
+ private String fArch;
+ private String fOS;
+ private String fWS;
+ private String fNL;
+
+ // bundle containers
+ private IBundleContainer[] fContainers;
+
+ // handle
+ private ITargetHandle fHandle;
+
+ /**
+ * Constructs a target definition based on the given handle.
+ */
+ TargetDefinition(ITargetHandle handle) {
+ fHandle = handle;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getArch()
+ */
+ public String getArch() {
+ return fArch;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getBundleContainers()
+ */
+ public IBundleContainer[] getBundleContainers() {
+ return fContainers;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getDescription()
+ */
+ public String getDescription() {
+ return fDescription;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getExecutionEnvironment()
+ */
+ public String getExecutionEnvironment() {
+ return fEE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getNL()
+ */
+ public String getNL() {
+ return fNL;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getName()
+ */
+ public String getName() {
+ return fName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getOS()
+ */
+ public String getOS() {
+ return fOS;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getProgramArguments()
+ */
+ public String getProgramArguments() {
+ return fProgramArgs;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getVMArguments()
+ */
+ public String getVMArguments() {
+ return fVMArgs;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getWS()
+ */
+ public String getWS() {
+ return fWS;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setArch(java.lang.String)
+ */
+ public void setArch(String arch) {
+ fArch = arch;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setDescription(java.lang.String)
+ */
+ public void setDescription(String description) {
+ fDescription = description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setExecutionEnvironment(java.lang.String)
+ */
+ public void setExecutionEnvironment(String environment) {
+ fEE = environment;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setNL(java.lang.String)
+ */
+ public void setNL(String nl) {
+ fNL = nl;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setName(java.lang.String)
+ */
+ public void setName(String name) {
+ fName = name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setOS(java.lang.String)
+ */
+ public void setOS(String os) {
+ fOS = os;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setProgramArguments(java.lang.String)
+ */
+ public void setProgramArguments(String args) {
+ fProgramArgs = args;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setVMArguments(java.lang.String)
+ */
+ public void setVMArguments(String args) {
+ fVMArgs = args;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setWS(java.lang.String)
+ */
+ public void setWS(String ws) {
+ fWS = ws;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setBundleContainers(org.eclipse.pde.internal.core.target.provisional.IBundleContainer[])
+ */
+ public void setBundleContainers(IBundleContainer[] containers) {
+ fContainers = containers;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
+ IBundleContainer[] containers = getBundleContainers();
+ List bundles = new ArrayList();
+ if (containers != null) {
+ for (int i = 0; i < containers.length; i++) {
+ BundleInfo[] infos = containers[i].resolveBundles(monitor);
+ bundles.addAll(Arrays.asList(infos));
+ }
+ }
+ return (BundleInfo[]) bundles.toArray(new BundleInfo[bundles.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
+ IBundleContainer[] containers = getBundleContainers();
+ List source = new ArrayList();
+ if (containers != null) {
+ for (int i = 0; i < containers.length; i++) {
+ BundleInfo[] infos = containers[i].resolveSourceBundles(monitor);
+ source.addAll(Arrays.asList(infos));
+ }
+ }
+ return (BundleInfo[]) source.toArray(new BundleInfo[source.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getHandle()
+ */
+ public ITargetHandle getHandle() {
+ return fHandle;
+ }
+
+ /**
+ * Build contents from the given stream.
+ *
+ * @param stream input stream
+ * @throws CoreException if an error occurs
+ */
+ void setContents(InputStream stream) throws CoreException {
+ // TODO: read stream
+ }
+
+ /**
+ * Persists contents to the given stream.
+ *
+ * @param stream output stream
+ * @throws CoreException if an error occurs
+ */
+ void write(OutputStream stream) throws CoreException {
+ // TODO: persist content
+ }
+}
Index: src/org/eclipse/pde/internal/core/target/impl/Messages.properties
===================================================================
RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/impl/Messages.properties,v
retrieving revision 1.1
diff -u -r1.1 Messages.properties
--- src/org/eclipse/pde/internal/core/target/impl/Messages.properties 8 Jan 2009 17:25:10 -0000 1.1
+++ src/org/eclipse/pde/internal/core/target/impl/Messages.properties 9 Jan 2009 22:24:18 -0000
@@ -1,23 +1,38 @@
-###############################################################################
-# Copyright (c) 2009 IBM Corporation and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
-
-DirectoryBundleContainer_0=Reading bundles...
-DirectoryBundleContainer_1=Directory does not exist: {0}
-DirectoryBundleContainer_2=Error converting manifest for {0}
-DirectoryBundleContainer_3=Error reading manifest for {0}
-LocalTargetHandle_0=Unable to restore target handle
-LocalTargetHandle_1=Target file not found
-LocalTargetHandle_2=Unable to generate memento for target platform
-ProfileBundleContainer_0=Unable to resolve bundles in {0}
-ProfileBundleContainer_1=Unable resolve configuration area in {0}
-TargetPlatformService_0=Unable to restore target memento
-TargetPlatformService_1=Unrecognized target memento scheme
-WorkspaceFileTargetHandle_0=Unable to generate memento for target platform
+###############################################################################
+# Copyright (c) 2009 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+
+DirectoryBundleContainer_0=Reading bundles...
+DirectoryBundleContainer_1=Directory does not exist: {0}
+DirectoryBundleContainer_2=Error converting manifest for {0}
+DirectoryBundleContainer_3=Error reading manifest for {0}
+FeatureBundleContainer_0=Directory does not exist: {0}
+FeatureBundleContainer_1=Unable to locate feature: {0}
+FeatureBundleContainer_2=Unable to resolve bunldes for feature {0}
+FeatureBundleContainer_3=Unable to resolve bunldes for feature {0}
+FeatureBundleContainer_4=Unable to acquire target platform service
+FeatureBundleContainer_5=Plug-ins directry does not exist for feature {0}
+LoadTargetDefinitionJob_0=Load Target Platform
+LoadTargetDefinitionJob_1=Unable to resolve plug-ins in target definition
+LoadTargetOperation_argsTaskName=Setting arguments
+LoadTargetOperation_envTaskName=Setting environment
+LoadTargetOperation_implicitPluginsTaskName=loading implicit dependencies
+LoadTargetOperation_jreTaskName=Setting JRE
+LoadTargetOperation_loadPluginsTaskName=Loading Plugins
+LoadTargetOperation_mainTaskName=Resetting target platform information
+LoadTargetOperation_reloadTaskName=reloading target platform
+LocalTargetHandle_0=Unable to restore target handle
+LocalTargetHandle_1=Target file not found
+LocalTargetHandle_2=Unable to generate memento for target platform
+ProfileBundleContainer_0=Unable to resolve bundles in {0}
+ProfileBundleContainer_1=Unable resolve configuration area in {0}
+TargetPlatformService_0=Unable to restore target memento
+TargetPlatformService_1=Unrecognized target memento scheme
+WorkspaceFileTargetHandle_0=Unable to generate memento for target platform
Index: src/org/eclipse/pde/internal/core/target/impl/TargetPlatformService.java
===================================================================
RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/impl/TargetPlatformService.java,v
retrieving revision 1.1
diff -u -r1.1 TargetPlatformService.java
--- src/org/eclipse/pde/internal/core/target/impl/TargetPlatformService.java 8 Jan 2009 17:25:10 -0000 1.1
+++ src/org/eclipse/pde/internal/core/target/impl/TargetPlatformService.java 9 Jan 2009 22:24:18 -0000
@@ -1,116 +1,123 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.pde.internal.core.target.impl;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.*;
-import org.eclipse.pde.internal.core.PDECore;
-import org.eclipse.pde.internal.core.target.provisional.*;
-
-/**
- * Target platform service implementation.
- *
- * @since 3.5
- */
-public class TargetPlatformService implements ITargetPlatformService {
-
- private static ITargetPlatformService fgDefault;
-
- private TargetPlatformService() {
- }
-
- public synchronized static ITargetPlatformService getDefault() {
- if (fgDefault == null) {
- fgDefault = new TargetPlatformService();
- }
- return fgDefault;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#deleteTarget(org.eclipse.pde.internal.core.target.provisional.ITargetHandle)
- */
- public void deleteTarget(ITargetHandle handle) throws CoreException {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTarget(org.eclipse.core.resources.IFile)
- */
- public ITargetHandle getTarget(IFile file) {
- return new WorkspaceFileTargetHandle(file);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTarget(java.lang.String)
- */
- public ITargetHandle getTarget(String memento) throws CoreException {
- try {
- URI uri = new URI(memento);
- String scheme = uri.getScheme();
- if (WorkspaceFileTargetHandle.SCHEME.equals(scheme)) {
- return WorkspaceFileTargetHandle.restoreHandle(uri);
- } else if (LocalTargetHandle.SCHEME.equals(scheme)) {
- return LocalTargetHandle.restoreHandle(uri);
- }
- } catch (URISyntaxException e) {
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.TargetPlatformService_0, e));
- }
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.TargetPlatformService_1, null));
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTargets(org.eclipse.core.runtime.IProgressMonitor)
- */
- public ITargetHandle[] getTargets(IProgressMonitor monitor) {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newDirectoryContainer(java.lang.String)
- */
- public IBundleContainer newDirectoryContainer(String path) {
- return new DirectoryBundleContainer(path);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newProfileContainer(java.lang.String)
- */
- public IBundleContainer newProfileContainer(String home) {
- return newProfileContainer(home, null);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newProfileContainer(java.lang.String, java.lang.String)
- */
- public IBundleContainer newProfileContainer(String home, String configurationLocation) {
- return new ProfileBundleContainer(home, configurationLocation);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newTarget()
- */
- public ITargetDefinition newTarget() {
- return new TargetDefinition(new LocalTargetHandle());
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#saveTargetDefinition(org.eclipse.pde.internal.core.target.provisional.ITargetDefinition)
- */
- public void saveTargetDefinition(ITargetDefinition definition) throws CoreException {
- // TODO Auto-generated method stub
-
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.internal.core.target.impl;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.*;
+import org.eclipse.pde.internal.core.PDECore;
+import org.eclipse.pde.internal.core.target.provisional.*;
+
+/**
+ * Target platform service implementation.
+ *
+ * @since 3.5
+ */
+public class TargetPlatformService implements ITargetPlatformService {
+
+ private static ITargetPlatformService fgDefault;
+
+ private TargetPlatformService() {
+ }
+
+ public synchronized static ITargetPlatformService getDefault() {
+ if (fgDefault == null) {
+ fgDefault = new TargetPlatformService();
+ }
+ return fgDefault;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#deleteTarget(org.eclipse.pde.internal.core.target.provisional.ITargetHandle)
+ */
+ public void deleteTarget(ITargetHandle handle) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTarget(org.eclipse.core.resources.IFile)
+ */
+ public ITargetHandle getTarget(IFile file) {
+ return new WorkspaceFileTargetHandle(file);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTarget(java.lang.String)
+ */
+ public ITargetHandle getTarget(String memento) throws CoreException {
+ try {
+ URI uri = new URI(memento);
+ String scheme = uri.getScheme();
+ if (WorkspaceFileTargetHandle.SCHEME.equals(scheme)) {
+ return WorkspaceFileTargetHandle.restoreHandle(uri);
+ } else if (LocalTargetHandle.SCHEME.equals(scheme)) {
+ return LocalTargetHandle.restoreHandle(uri);
+ }
+ } catch (URISyntaxException e) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.TargetPlatformService_0, e));
+ }
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.TargetPlatformService_1, null));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#getTargets(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public ITargetHandle[] getTargets(IProgressMonitor monitor) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newDirectoryContainer(java.lang.String)
+ */
+ public IBundleContainer newDirectoryContainer(String path) {
+ return new DirectoryBundleContainer(path);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newProfileContainer(java.lang.String)
+ */
+ public IBundleContainer newProfileContainer(String home) {
+ return newProfileContainer(home, null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newProfileContainer(java.lang.String, java.lang.String)
+ */
+ public IBundleContainer newProfileContainer(String home, String configurationLocation) {
+ return new ProfileBundleContainer(home, configurationLocation);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newTarget()
+ */
+ public ITargetDefinition newTarget() {
+ return new TargetDefinition(new LocalTargetHandle());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#saveTargetDefinition(org.eclipse.pde.internal.core.target.provisional.ITargetDefinition)
+ */
+ public void saveTargetDefinition(ITargetDefinition definition) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService#newFeatureContainer(java.lang.String, java.lang.String, java.lang.String)
+ */
+ public IBundleContainer newFeatureContainer(String home, String id, String version) {
+ return new FeatureBundleContainer(home, id, version);
+ }
+
+}
Index: src/org/eclipse/pde/internal/core/target/provisional/IBundleContainer.java
===================================================================
RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/provisional/IBundleContainer.java,v
retrieving revision 1.1
diff -u -r1.1 IBundleContainer.java
--- src/org/eclipse/pde/internal/core/target/provisional/IBundleContainer.java 8 Jan 2009 17:25:11 -0000 1.1
+++ src/org/eclipse/pde/internal/core/target/provisional/IBundleContainer.java 9 Jan 2009 22:24:18 -0000
@@ -1,43 +1,54 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.pde.internal.core.target.provisional;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
-
-/**
- * A collection of bundles. A bundle container abstracts the storage and location of the
- * underlying bundles and may contain a combination of executable and source bundles.
- *
- * @since 3.5
- */
-public interface IBundleContainer {
-
- /**
- * Resolves and returns the executable bundles in this container, possibly empty.
- *
- * @param monitor progress monitor or null
- * @return executable bundles
- * @exception CoreException if unable to resolve bundles
- */
- public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException;
-
- /**
- * Resolves and returns the source bundles in this container, possibly empty.
- *
- * @param monitor progress monitor or null
- * @return source bundles
- * @exception CoreException if unable to resolve bundles
- */
- public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException;
-
-}
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.internal.core.target.provisional;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
+
+/**
+ * A collection of bundles. A bundle container abstracts the storage and location of the
+ * underlying bundles and may contain a combination of executable and source bundles.
+ *
+ * @since 3.5
+ */
+public interface IBundleContainer {
+
+ /**
+ * Returns a path in the local file system to the root of the bundle container.
+ *
+ * TODO: Ideally we won't need this method. Currently the PDE target platform preferences are + * based on a home location and additional locations, so we need the information. + *
+ * @return home location + * @exception CoreException if unable to resolve the location + */ + public String getHomeLocation() throws CoreException; + + /** + * Resolves and returns the executable bundles in this container, possibly empty. + * + * @param monitor progress monitor ornull
+ * @return executable bundles
+ * @exception CoreException if unable to resolve bundles
+ */
+ public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException;
+
+ /**
+ * Resolves and returns the source bundles in this container, possibly empty.
+ *
+ * @param monitor progress monitor or null
+ * @return source bundles
+ * @exception CoreException if unable to resolve bundles
+ */
+ public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException;
+
+}
Index: src/org/eclipse/pde/internal/core/target/provisional/ITargetPlatformService.java
===================================================================
RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/provisional/ITargetPlatformService.java,v
retrieving revision 1.1
diff -u -r1.1 ITargetPlatformService.java
--- src/org/eclipse/pde/internal/core/target/provisional/ITargetPlatformService.java 8 Jan 2009 17:25:11 -0000 1.1
+++ src/org/eclipse/pde/internal/core/target/provisional/ITargetPlatformService.java 9 Jan 2009 22:24:18 -0000
@@ -1,110 +1,129 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.pde.internal.core.target.provisional;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-
-/**
- * A service to manage target platform definitions available to the workspace.
- *
- * @since 3.5
- */
-public interface ITargetPlatformService {
-
- /**
- * Returns handles to all target definitions known in the workspace.
- *
- * @return handles to all target definitions known in the workspace
- */
- public ITargetHandle[] getTargets(IProgressMonitor monitor);
-
- /**
- * Returns a handle to a target definition backed by the underlying file.
- * The target definition may or may not exist. If the file does not exist
- * then this is a new target definition which becomes one of the known
- * workspace target definitions when it is saved.
- *
- * @param file target definition file that may or may not exist
- * @return target handle
- */
- public ITargetHandle getTarget(IFile file);
-
- /**
- * Returns a new target definition to be stored with local metadata. The target
- * becomes one of the known workspace target definitions when it is saved.
- *
- * @return new empty target definition
- */
- public ITargetDefinition newTarget();
-
- /**
- * Persists the given target definition. The target becomes one of known
- * workspace target definitions when it is saved.
- * - * The target is persisted in a location determined by its handle. A handle - * may refer to an {@link IFile} or a workspace metadata location. Any existing - * target definition at the same location is overwritten. - *
- * @param definition definition to persist - * @throws CoreException if unable to persist the definition - */ - public void saveTargetDefinition(ITargetDefinition definition) throws CoreException; - - /** - * Deletes the target definition associated with the given handle. - * - * @param handle target handle - * @throws CoreException if the associated target does not exist or deletion fails - */ - public void deleteTarget(ITargetHandle handle) throws CoreException; - - /** - * Creates and returns a target handle from the given memento. The memento must - * have been generated from {@link ITargetHandle#getMemento()}. - * - * @param memento a target handle memento - * @return target handle - * @throws CoreException if the target handle format is invalid - */ - public ITargetHandle getTarget(String memento) throws CoreException; - - /** - * Creates and returns a bundle container that contains all bundles in the - * specified directory. - * - * @param path absolute path in the local file system, may contain string variables - * @return bundle container - */ - public IBundleContainer newDirectoryContainer(String path); - - /** - * Creates and returns a bundle container that contains all bundles installed in - * a profile at the specified location with a default configuration area. - * - * @param home absolute path in the local file system to the root of an installed profile - * @return bundle container - */ - public IBundleContainer newProfileContainer(String home); - - /** - * Creates and returns a bundle container that contains all bundles installed in - * a profile at the specified location with the specified configuration area. - * - * @param home absolute path in the local file system to the root of an installed profile - * @param configurationLocation absolute path in the local file system to the - * configuration area for the specified installation - * @return bundle container - */ - public IBundleContainer newProfileContainer(String home, String configurationLocation); - -} +/******************************************************************************* + * Copyright (c) 2008, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.core.target.provisional; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * A service to manage target platform definitions available to the workspace. + * + * @since 3.5 + */ +public interface ITargetPlatformService { + + /** + * Returns handles to all target definitions known in the workspace. + * + * @return handles to all target definitions known in the workspace + */ + public ITargetHandle[] getTargets(IProgressMonitor monitor); + + /** + * Returns a handle to a target definition backed by the underlying file. + * The target definition may or may not exist. If the file does not exist + * then this is a new target definition which becomes one of the known + * workspace target definitions when it is saved. + * + * @param file target definition file that may or may not exist + * @return target handle + */ + public ITargetHandle getTarget(IFile file); + + /** + * Returns a new target definition to be stored with local metadata. The target + * becomes one of the known workspace target definitions when it is saved. + * + * @return new empty target definition + */ + public ITargetDefinition newTarget(); + + /** + * Persists the given target definition. The target becomes one of known + * workspace target definitions when it is saved. + *+ * The target is persisted in a location determined by its handle. A handle + * may refer to an {@link IFile} or a workspace metadata location. Any existing + * target definition at the same location is overwritten. + *
+ * @param definition definition to persist + * @throws CoreException if unable to persist the definition + */ + public void saveTargetDefinition(ITargetDefinition definition) throws CoreException; + + /** + * Deletes the target definition associated with the given handle. + * + * @param handle target handle + * @throws CoreException if the associated target does not exist or deletion fails + */ + public void deleteTarget(ITargetHandle handle) throws CoreException; + + /** + * Creates and returns a target handle from the given memento. The memento must + * have been generated from {@link ITargetHandle#getMemento()}. + * + * @param memento a target handle memento + * @return target handle + * @throws CoreException if the target handle format is invalid + */ + public ITargetHandle getTarget(String memento) throws CoreException; + + /** + * Creates and returns a bundle container that contains all bundles in the + * specified directory which may contain string substitution variables. + * + * @param path absolute path in the local file system, may contain string variables + * @return bundle container + */ + public IBundleContainer newDirectoryContainer(String path); + + /** + * Creates and returns a bundle container that contains all bundles installed in + * a profile at the specified location with a default configuration area. + * The specified home location may contain string substitution variables. + * + * @param home absolute path in the local file system to the root of an installed profile + * which may contain string substitution variables + * @return bundle container + */ + public IBundleContainer newProfileContainer(String home); + + /** + * Creates and returns a bundle container that contains all bundles referenced by + * the feature at the specified location. The location is the directory that defines + * the feature. + * + * @param home installation location containing a features directory which may contain + * string substitution variables + * @param featureId feature symbolic name + * @param version feature version identifier ornull
to use most recent available
+ * @return bundle container
+ */
+ public IBundleContainer newFeatureContainer(String home, String featureId, String version);
+
+ /**
+ * Creates and returns a bundle container that contains all bundles installed in
+ * a profile at the specified location with the specified configuration area.
+ * The specified home location and configuration location may contain string substitution
+ * variables.
+ *
+ * @param home absolute path in the local file system to the root of an installed profile
+ * which may contain string substitution variables
+ * @param configurationLocation absolute path in the local file system to the
+ * configuration area for the specified installation which may contain string substitution
+ * variables
+ * @return bundle container
+ */
+ public IBundleContainer newProfileContainer(String home, String configurationLocation);
+
+}
Index: src/org/eclipse/pde/internal/core/ExternalFeatureModelManager.java
===================================================================
RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ExternalFeatureModelManager.java,v
retrieving revision 1.8
diff -u -r1.8 ExternalFeatureModelManager.java
--- src/org/eclipse/pde/internal/core/ExternalFeatureModelManager.java 2 Jan 2008 15:56:17 -0000 1.8
+++ src/org/eclipse/pde/internal/core/ExternalFeatureModelManager.java 9 Jan 2009 22:24:18 -0000
@@ -10,23 +10,10 @@
*******************************************************************************/
package org.eclipse.pde.internal.core;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Preferences;
+import java.util.*;
+import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
import org.eclipse.pde.core.IModelProviderEvent;
import org.eclipse.pde.core.IModelProviderListener;
@@ -37,11 +24,13 @@
public class ExternalFeatureModelManager implements Preferences.IPropertyChangeListener {
/**
+ * Creates a feature model for the feature based on the given feature XML
+ * file.
*
- * @param manifest
+ * @param manifest feature XML file in the local file system
* @return ExternalFeatureModel or null
*/
- private static IFeatureModel createModel(File manifest) {
+ public static IFeatureModel createModel(File manifest) {
ExternalFeatureModel model = new ExternalFeatureModel();
model.setInstallLocation(manifest.getParent());
InputStream stream = null;
Index: src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java
===================================================================
RCS file: src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java
diff -N src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,327 @@
+/*******************************************************************************
+ * Copyright (c) 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.internal.core.target.provisional;
+
+import org.eclipse.pde.internal.core.target.impl.Messages;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.*;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.variables.IStringVariableManager;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
+import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
+import org.eclipse.pde.core.plugin.TargetPlatform;
+import org.eclipse.pde.internal.core.*;
+import org.eclipse.pde.internal.core.itarget.IImplicitDependenciesInfo;
+import org.eclipse.pde.internal.core.itarget.ITargetPlugin;
+
+/**
+ * Sets the current target platform based on a target definition.
+ *
+ * @since 3.5
+ */
+public class LoadTargetDefinitionJob extends WorkspaceJob {
+
+ /**
+ * Target definition being loaded
+ */
+ private ITargetDefinition fTarget;
+
+ /**
+ * Constructs a new operation to load the specified target definition
+ * as the current target platform.
+ *
+ * @param target target definition
+ */
+ public LoadTargetDefinitionJob(ITargetDefinition target) {
+ super(Messages.LoadTargetDefinitionJob_0);
+ fTarget = target;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.resources.WorkspaceJob#runInWorkspace(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
+ try {
+ Preferences preferences = PDECore.getDefault().getPluginPreferences();
+ monitor.beginTask(Messages.LoadTargetOperation_mainTaskName, 100);
+ loadEnvironment(preferences, new SubProgressMonitor(monitor, 5));
+ loadArgs(preferences, new SubProgressMonitor(monitor, 5));
+ loadJRE(preferences, new SubProgressMonitor(monitor, 15));
+ loadImplicitPlugins(preferences, new SubProgressMonitor(monitor, 15));
+ loadPlugins(preferences, new SubProgressMonitor(monitor, 60));
+ loadAdditionalPreferences(preferences);
+ PDECore.getDefault().savePluginPreferences();
+ } finally {
+ monitor.done();
+ }
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * Configures program and VM argument preferences based on the target
+ * definition.
+ *
+ * @param pref preference store
+ * @param monitor progress monitor
+ */
+ private void loadArgs(Preferences pref, IProgressMonitor monitor) {
+ monitor.beginTask(Messages.LoadTargetOperation_argsTaskName, 2);
+ String args = fTarget.getProgramArguments();
+ pref.setValue(ICoreConstants.PROGRAM_ARGS, (args != null) ? args : ""); //$NON-NLS-1$
+ monitor.worked(1);
+ args = fTarget.getVMArguments();
+ pref.setValue(ICoreConstants.VM_ARGS, (args != null) ? args : ""); //$NON-NLS-1$
+ monitor.done();
+ }
+
+ /**
+ * Configures the environment preferences from the target definition.
+ *
+ * @param pref preference store
+ * @param monitor progress monitor
+ */
+ private void loadEnvironment(Preferences pref, IProgressMonitor monitor) {
+ monitor.beginTask(Messages.LoadTargetOperation_envTaskName, 1);
+ setEnvironmentPref(pref, ICoreConstants.ARCH, fTarget.getArch());
+ setEnvironmentPref(pref, ICoreConstants.NL, fTarget.getNL());
+ setEnvironmentPref(pref, ICoreConstants.OS, fTarget.getOS());
+ setEnvironmentPref(pref, ICoreConstants.WS, fTarget.getWS());
+ monitor.done();
+ }
+
+ /**
+ * Sets the given preference to default when null
or the
+ * specified value.
+ *
+ * @param pref preference store
+ * @param key preference key
+ * @param value preference value or null
+ */
+ private void setEnvironmentPref(Preferences pref, String key, String value) {
+ if (value == null) {
+ pref.setToDefault(key);
+ } else {
+ pref.setValue(key, value);
+ }
+ }
+
+ /**
+ * Sets the workspace default JRE based on the target's execution environment.
+ * + * This is a hold over from the old target definition files where a specific + * JRE could be specified. It seems wrong to be changing the workspace default + * JRE as a side effect of this operation, but we do it for backwards compatibility. + *
+ * @param pref + * @param monitor + */ + private void loadJRE(Preferences pref, IProgressMonitor monitor) { + String id = fTarget.getExecutionEnvironment(); + monitor.beginTask(Messages.LoadTargetOperation_jreTaskName, 1); + IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); + IExecutionEnvironment environment = manager.getEnvironment(id); + if (environment != null) { + IVMInstall jre = environment.getDefaultVM(); + if (jre != null) { + IVMInstall[] vms = environment.getCompatibleVMs(); + for (int i = 0; i < vms.length; i++) { + IVMInstall vm = vms[i]; + if (environment.isStrictlyCompatible(vm)) { + jre = vm; + break; + } + } + if (jre == null && vms.length > 0) { + jre = vms[0]; + } + } + IVMInstall def = JavaRuntime.getDefaultVMInstall(); + if (def != null && !jre.equals(def)) + try { + JavaRuntime.setDefaultVMInstall(jre, null); + } catch (CoreException e) { + } + } + monitor.done(); + } + + /** + * TODO: we don't currently have implicit plug-ins in the new model. + * + * @param pref + * @param monitor + */ + private void loadImplicitPlugins(Preferences pref, IProgressMonitor monitor) { + IImplicitDependenciesInfo info = null; + if (info != null) { + ITargetPlugin[] plugins = info.getPlugins(); + monitor.beginTask(Messages.LoadTargetOperation_implicitPluginsTaskName, plugins.length + 1); + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < plugins.length; i++) { + buffer.append(plugins[i].getId()).append(','); + monitor.worked(1); + } + if (plugins.length > 0) + buffer.setLength(buffer.length() - 1); + pref.setValue(ICoreConstants.IMPLICIT_DEPENDENCIES, buffer.toString()); + } + monitor.done(); + } + + /** + * Resolves the bundles in the target platform and sets them in the corresponding + * CHECKED_PLUGINS preference. Sets home and addition location preferences as well. + * + * @param pref + * @param monitor + * @throws CoreException + */ + private void loadPlugins(Preferences pref, IProgressMonitor monitor) throws CoreException { + monitor.beginTask(Messages.LoadTargetOperation_loadPluginsTaskName, 100); + String currentPath = pref.getString(ICoreConstants.PLATFORM_PATH); + IBundleContainer[] containers = fTarget.getBundleContainers(); + // the first container is assumed to be the primary/home location + String path = null; + if (containers != null && containers.length > 0) { + path = containers[0].getHomeLocation(); + } + if (path == null) { + path = TargetPlatform.getDefaultLocation(); + } else { + try { + IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); + path = manager.performStringSubstitution(path); + } catch (CoreException e) { + return; + } + } + monitor.worked(10); + List additional = getAdditionalLocs(); + handleReload(path, additional, pref, new SubProgressMonitor(monitor, 85)); + + // update preferences (Note: some preferences updated in handleReload()) + pref.setValue(ICoreConstants.PLATFORM_PATH, path); + String mode = new Path(path).equals(new Path(TargetPlatform.getDefaultLocation())) ? ICoreConstants.VALUE_USE_THIS : ICoreConstants.VALUE_USE_OTHER; + pref.setValue(ICoreConstants.TARGET_MODE, mode); + + ListIterator li = additional.listIterator(); + StringBuffer buffer = new StringBuffer(); + while (li.hasNext()) + buffer.append(li.next()).append(","); //$NON-NLS-1$ + if (buffer.length() > 0) + buffer.setLength(buffer.length() - 1); + pref.setValue(ICoreConstants.ADDITIONAL_LOCATIONS, buffer.toString()); + + String newValue = currentPath; + for (int i = 0; i < 4; i++) { + String value = pref.getString(ICoreConstants.SAVED_PLATFORM + i); + pref.setValue(ICoreConstants.SAVED_PLATFORM + i, newValue); + if (!value.equals(currentPath)) + newValue = value; + else + break; + } + monitor.done(); + } + + /** + * Sets the TARGET_PROFILE preference which stores the ID of the target profile used + * (if based on an target extension) or the workspace location of the file that + * was used. + *+ * For now we just clear it. + *
+ * @param pref + */ + private void loadAdditionalPreferences(Preferences pref) { + pref.setValue(ICoreConstants.TARGET_PROFILE, ""); //$NON-NLS-1$ + } + + /** + * Returns a list of additional locations of bundles. + * + * @return additional bundle locations + */ + private List getAdditionalLocs() throws CoreException { + ArrayList additional = new ArrayList(); + // secondary containers are considered additional + IBundleContainer[] containers = fTarget.getBundleContainers(); + if (containers != null && containers.length > 1) { + IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); + for (int i = 1; i < containers.length; i++) { + try { + additional.add(manager.performStringSubstitution(containers[i].getHomeLocation())); + } catch (CoreException e) { + additional.add(containers[i].getHomeLocation()); + } + } + } + return additional; + } + + private void handleReload(String targetLocation, List additionalLocations, Preferences pref, IProgressMonitor monitor) throws CoreException { + monitor.beginTask(Messages.LoadTargetOperation_reloadTaskName, 85); + + List infos = new ArrayList(); + BundleInfo[] code = fTarget.resolveBundles(null); + for (int i = 0; i < code.length; i++) { + infos.add(code[i]); + } + // to be consistent with previous implementation, add source bundles + BundleInfo[] sourceBundles = fTarget.resolveSourceBundles(null); + for (int i = 0; i < sourceBundles.length; i++) { + infos.add(sourceBundles[i]); + } + BundleInfo[] bundles = (BundleInfo[]) infos.toArray(new BundleInfo[infos.size()]); + // generate URLs and save CHECKED_PLUGINS + StringBuffer checked = new StringBuffer(); + + URL[] paths = new URL[bundles.length]; + for (int i = 0; i < paths.length; i++) { + try { + paths[i] = new File(bundles[i].getLocation()).toURL(); + if (i > 0) { + checked.append(" "); //$NON-NLS-1$ + } + checked.append(bundles[i].getSymbolicName()); + } catch (MalformedURLException e) { + throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.LoadTargetDefinitionJob_1, e)); + } + } + + PDEState state = new PDEState(paths, true, new SubProgressMonitor(monitor, 45)); + // save CHECKED_PLUGINS + if (paths.length == 0) { + pref.setValue(ICoreConstants.CHECKED_PLUGINS, ICoreConstants.VALUE_SAVED_NONE); + } else { + pref.setValue(ICoreConstants.CHECKED_PLUGINS, checked.toString()); + } + + Job job = new TargetPlatformResetJob(state); + job.schedule(); + try { + job.join(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + } + monitor.done(); + } + +} Index: src/org/eclipse/pde/internal/core/target/impl/FeatureBundleContainer.java =================================================================== RCS file: src/org/eclipse/pde/internal/core/target/impl/FeatureBundleContainer.java diff -N src/org/eclipse/pde/internal/core/target/impl/FeatureBundleContainer.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/internal/core/target/impl/FeatureBundleContainer.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,201 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.core.target.impl; + +import java.io.File; +import java.util.*; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; +import org.eclipse.osgi.util.NLS; +import org.eclipse.pde.internal.core.ExternalFeatureModelManager; +import org.eclipse.pde.internal.core.PDECore; +import org.eclipse.pde.internal.core.ifeature.*; +import org.eclipse.pde.internal.core.target.provisional.IBundleContainer; +import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService; + +/** + * A container of the bundles contained in a feature. + * + * @since 3.5 + */ +public class FeatureBundleContainer extends AbstractBundleContainer { + + /** + * Feature symbolic name + */ + private String fId; + + /** + * Feature version ornull
+ */
+ private String fVersion;
+
+ /**
+ * Install location which may contain string substitution variables
+ */
+ private String fHome;
+
+ /**
+ * Constructs a new feature bundle container for the feature at the specified
+ * location. Plug-ins are resolved in the plug-ins directory of the given home
+ * directory. When version is unspecified, the most recent version is used.
+ *
+ * @param home root directory containing the features directory which
+ * may contain string substitution variables
+ * @param name feature symbolic name
+ * @param version feature version, or null
if unspecified
+ */
+ FeatureBundleContainer(String home, String name, String version) {
+ fId = name;
+ fVersion = version;
+ fHome = home;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#getHomeLocation()
+ */
+ public String getHomeLocation() throws CoreException {
+ return resolveHomeLocation().toOSString();
+ }
+
+ /**
+ * Returns the home location with all variables resolved as a path.
+ *
+ * @return resolved home location
+ * @throws CoreException
+ */
+ private IPath resolveHomeLocation() throws CoreException {
+ return new Path(resolveVariables(fHome));
+ }
+
+ /**
+ * Resolves and returns the directory containing the feature.
+ *
+ * @return feature directory
+ * @throws CoreException if unable to resolve
+ */
+ private File resolveFeatureLocation() throws CoreException {
+ File features = resolveHomeLocation().append("features").toFile(); //$NON-NLS-1$
+ if (!features.exists() || features.isFile()) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.FeatureBundleContainer_0, features.toString())));
+ }
+ // if a specific version is specified, use it
+ if (fVersion != null) {
+ StringBuffer buf = new StringBuffer();
+ String name = buf.append(fId).append("_").append(fVersion).toString(); //$NON-NLS-1$
+ return new File(features, name);
+ }
+ // use most recent version
+ String[] list = features.list();
+ List versions = new ArrayList();
+ StringBuffer buf = new StringBuffer();
+ String prefix = buf.append(fId).append("_").toString(); //$NON-NLS-1$
+ for (int i = 0; i < list.length; i++) {
+ String name = list[i];
+ if (name.startsWith(prefix)) {
+ versions.add(name);
+ }
+ }
+ if (versions.isEmpty()) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.FeatureBundleContainer_1, fId)));
+ }
+ Collections.sort(versions);
+ String name = (String) versions.get(versions.size() - 1);
+ return new File(features, name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException {
+ return resolveBundles0(monitor, false);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException {
+ return resolveBundles0(monitor, true);
+ }
+
+ private BundleInfo[] resolveBundles0(IProgressMonitor monitor, boolean source) throws CoreException {
+ IFeatureModel model = null;
+ try {
+ File location = resolveFeatureLocation();
+ File manifest = new File(location, "feature.xml"); //$NON-NLS-1$
+ if (!manifest.exists() || !manifest.isFile()) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.FeatureBundleContainer_2, fId)));
+ }
+ model = ExternalFeatureModelManager.createModel(manifest);
+ if (model == null || !model.isLoaded()) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.FeatureBundleContainer_3, fId)));
+ }
+ // search bundles in plug-ins directory
+ ITargetPlatformService service = (ITargetPlatformService) PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
+ if (service == null) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.FeatureBundleContainer_4));
+ }
+ File dir = new File(manifest.getParentFile().getParentFile().getParentFile(), "plugins"); //$NON-NLS-1$
+ if (!dir.exists() || !dir.isDirectory()) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.FeatureBundleContainer_5, fId)));
+ }
+ IBundleContainer container = service.newDirectoryContainer(dir.getAbsolutePath());
+ BundleInfo[] bundles = null;
+ if (source) {
+ bundles = container.resolveSourceBundles(null);
+ } else {
+ bundles = container.resolveBundles(null);
+ }
+ Map bundleMap = new HashMap();
+ for (int i = 0; i < bundles.length; i++) {
+ BundleInfo info = bundles[i];
+ List list = (List) bundleMap.get(info.getSymbolicName());
+ if (list == null) {
+ list = new ArrayList();
+ bundleMap.put(info.getSymbolicName(), list);
+ }
+ list.add(info);
+ }
+ IFeature feature = model.getFeature();
+ IFeaturePlugin[] plugins = feature.getPlugins();
+ List results = new ArrayList();
+ for (int i = 0; i < plugins.length; i++) {
+ IFeaturePlugin plugin = plugins[i];
+ List list = (List) bundleMap.get(plugin.getId());
+ if (list != null) {
+ Iterator iterator = list.iterator();
+ boolean added = false;
+ while (iterator.hasNext()) {
+ BundleInfo info = (BundleInfo) iterator.next();
+ if (info.getVersion().equals(plugin.getVersion())) {
+ results.add(info);
+ added = true;
+ break;
+ }
+ }
+ if (!added) {
+ // use first one
+ results.add(list.get(0));
+ }
+ } else {
+ // TODO: missing plug-in, we should probably include a status with resolution
+ }
+
+ }
+ return (BundleInfo[]) results.toArray(new BundleInfo[results.size()]);
+ } finally {
+ if (model != null) {
+ model.dispose();
+ }
+ }
+ }
+
+}
Index: src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java
===================================================================
RCS file: src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java
diff -N src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.internal.core.target.impl;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.variables.IStringVariableManager;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
+
+/**
+ * Common function for bundle containers.
+ *
+ * @since 3.5
+ */
+public abstract class AbstractBundleContainer implements IBundleContainer {
+
+ /**
+ * Resolves any string substitution variables in the given text returning
+ * the result.
+ *
+ * @param text text to resolve
+ * @return result of the resolution
+ * @throws CoreException if unable to resolve
+ */
+ protected String resolveVariables(String text) throws CoreException {
+ IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
+ return manager.performStringSubstitution(text);
+ }
+}