Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 122768 Details for
Bug 256910
target platform: the next wave
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
support for implicit dependencies
implicit-dep.patch (text/plain), 176.48 KB, created by
Darin Wright
on 2009-01-15 23:14:04 EST
(
hide
)
Description:
support for implicit dependencies
Filename:
MIME Type:
Creator:
Darin Wright
Created:
2009-01-15 23:14:04 EST
Size:
176.48 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.pde.core >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.3 >diff -u -r1.3 TargetDefinition.java >--- src/org/eclipse/pde/internal/core/target/impl/TargetDefinition.java 14 Jan 2009 22:16:01 -0000 1.3 >+++ src/org/eclipse/pde/internal/core/target/impl/TargetDefinition.java 16 Jan 2009 04:11:54 -0000 >@@ -1,276 +1,313 @@ >-/******************************************************************************* >- * 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 javax.xml.parsers.ParserConfigurationException; >-import javax.xml.transform.TransformerException; >-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.*; >-import org.xml.sax.SAXException; >- >-/** >- * 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 { >- try { >- TargetDefinitionPersistenceHelper.initFromXML(this, stream); >- } catch (ParserConfigurationException e) { >- // TODO Auto-generated catch block >- e.printStackTrace(); >- } catch (SAXException e) { >- // TODO Auto-generated catch block >- e.printStackTrace(); >- } catch (IOException e) { >- // TODO Auto-generated catch block >- e.printStackTrace(); >- } >- } >- >- /** >- * Persists contents to the given stream. >- * >- * @param stream output stream >- * @throws CoreException if an error occurs >- */ >- void write(OutputStream stream) throws CoreException { >- try { >- TargetDefinitionPersistenceHelper.persistXML(this, stream); >- } catch (IOException e) { >- // TODO Auto-generated catch block >- e.printStackTrace(); >- } catch (ParserConfigurationException e) { >- // TODO Auto-generated catch block >- e.printStackTrace(); >- } catch (TransformerException e) { >- // TODO Auto-generated catch block >- e.printStackTrace(); >- } >- } >-} >+/******************************************************************************* >+ * 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 javax.xml.parsers.ParserConfigurationException; >+import javax.xml.transform.TransformerException; >+import org.eclipse.core.runtime.*; >+import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; >+import org.eclipse.pde.internal.core.PDECore; >+import org.eclipse.pde.internal.core.target.provisional.*; >+import org.xml.sax.SAXException; >+ >+/** >+ * 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; >+ >+ // implicit dependencies >+ private BundleInfo[] fImplicit; >+ >+ /** >+ * 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 { >+ try { >+ TargetDefinitionPersistenceHelper.initFromXML(this, stream); >+ } catch (ParserConfigurationException e) { >+ abort(Messages.TargetDefinition_0, e); >+ } catch (SAXException e) { >+ abort(Messages.TargetDefinition_0, e); >+ } catch (IOException e) { >+ abort(Messages.TargetDefinition_0, e); >+ } >+ } >+ >+ /** >+ * Persists contents to the given stream. >+ * >+ * @param stream output stream >+ * @throws CoreException if an error occurs >+ */ >+ void write(OutputStream stream) throws CoreException { >+ try { >+ TargetDefinitionPersistenceHelper.persistXML(this, stream); >+ } catch (IOException e) { >+ abort(Messages.TargetDefinition_3, e); >+ } catch (ParserConfigurationException e) { >+ abort(Messages.TargetDefinition_3, e); >+ } catch (TransformerException e) { >+ abort(Messages.TargetDefinition_3, e); >+ } >+ } >+ >+ /** >+ * Throws a core exception with the given message and underlying exception (possibly >+ * <code>null</code>). >+ * >+ * @param message message >+ * @param e underlying cause of the exception or <code>null</code> >+ * @throws CoreException >+ */ >+ private void abort(String message, Exception e) throws CoreException { >+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, message, e)); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#getImplicitDependencies() >+ */ >+ public BundleInfo[] getImplicitDependencies() { >+ return fImplicit; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#resolveImplicitDependencies(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public BundleInfo[] resolveImplicitDependencies(IProgressMonitor monitor) throws CoreException { >+ int size = 0; >+ if (fImplicit != null) { >+ size = fImplicit.length; >+ } >+ if (size == 0) { >+ return new BundleInfo[0]; >+ } >+ return AbstractBundleContainer.getMatchingBundles(resolveBundles(null), fImplicit); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.ITargetDefinition#setImplicitDependencies(org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo[]) >+ */ >+ public void setImplicitDependencies(BundleInfo[] bundles) { >+ fImplicit = bundles; >+ } >+} >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.4 >diff -u -r1.4 Messages.java >--- src/org/eclipse/pde/internal/core/target/impl/Messages.java 15 Jan 2009 23:36:11 -0000 1.4 >+++ src/org/eclipse/pde/internal/core/target/impl/Messages.java 16 Jan 2009 04:11:54 -0000 >@@ -1,55 +1,57 @@ >-/******************************************************************************* >- * 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_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 LocalTargetHandle_3; >- public static String LocalTargetHandle_4; >- 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_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 LocalTargetHandle_3; >+ public static String LocalTargetHandle_4; >+ public static String ProfileBundleContainer_0; >+ public static String ProfileBundleContainer_1; >+ public static String TargetDefinition_0; >+ public static String TargetDefinition_3; >+ 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/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.4 >diff -u -r1.4 Messages.properties >--- src/org/eclipse/pde/internal/core/target/impl/Messages.properties 15 Jan 2009 23:36:11 -0000 1.4 >+++ src/org/eclipse/pde/internal/core/target/impl/Messages.properties 16 Jan 2009 04:11:54 -0000 >@@ -1,39 +1,41 @@ >-############################################################################### >-# 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 bundles for feature {0} >-FeatureBundleContainer_4=Unable to acquire target platform service >-FeatureBundleContainer_5=Plug-ins directory 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 >-LocalTargetHandle_3=Failed to delete target definition: {0} >-LocalTargetHandle_4=Error saving target definition {0} >-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 bundles for feature {0} >+FeatureBundleContainer_4=Unable to acquire target platform service >+FeatureBundleContainer_5=Plug-ins directory 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 >+LocalTargetHandle_3=Failed to delete target definition: {0} >+LocalTargetHandle_4=Error saving target definition {0} >+ProfileBundleContainer_0=Unable to resolve bundles in {0} >+ProfileBundleContainer_1=Unable resolve configuration area in {0} >+TargetDefinition_0=Error reading target definition >+TargetDefinition_3=Error writing target definition >+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/FeatureBundleContainer.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/impl/FeatureBundleContainer.java,v >retrieving revision 1.3 >diff -u -r1.3 FeatureBundleContainer.java >--- src/org/eclipse/pde/internal/core/target/impl/FeatureBundleContainer.java 15 Jan 2009 23:36:11 -0000 1.3 >+++ src/org/eclipse/pde/internal/core/target/impl/FeatureBundleContainer.java 16 Jan 2009 04:11:54 -0000 >@@ -1,232 +1,203 @@ >-/******************************************************************************* >- * 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 { >- >- /** >- * Constant describing the type of bundle container >- */ >- public static final String TYPE = "Feature"; //$NON-NLS-1$ >- >- /** >- * Feature symbolic name >- */ >- private String fId; >- >- /** >- * Feature version or <code>null</code> >- */ >- 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 <code>null</code> 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(); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.impl.AbstractBundleContainer#getType() >- */ >- public String getType() { >- return TYPE; >- } >- >- /** >- * Returns the symbolic name of the feature this bundle container resolves from >- * >- * @return string feature id (symbolic name) >- */ >- public String getFeatureId() { >- return fId; >- } >- >- /** >- * Returns the version of the feature this bundle container resolves from if >- * a version was specified. >- * >- * @return string feature version or <code>null</code> >- */ >- public String getFeatureVersion() { >- return fVersion; >- } >- >- /** >- * 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.impl.AbstractBundleContainer#resolveAllBundles(org.eclipse.core.runtime.IProgressMonitor) >- */ >- protected BundleInfo[] resolveAllBundles(IProgressMonitor monitor) throws CoreException { >- return resolveBundles0(monitor, false); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.impl.AbstractBundleContainer#resolveAllSourceBundles(org.eclipse.core.runtime.IProgressMonitor) >- */ >- protected BundleInfo[] resolveAllSourceBundles(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_2, 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(); >- } >- } >- } >- >-} >+/******************************************************************************* >+ * 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 { >+ >+ /** >+ * Constant describing the type of bundle container >+ */ >+ public static final String TYPE = "Feature"; //$NON-NLS-1$ >+ >+ /** >+ * Feature symbolic name >+ */ >+ private String fId; >+ >+ /** >+ * Feature version or <code>null</code> >+ */ >+ 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 <code>null</code> 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(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.impl.AbstractBundleContainer#getType() >+ */ >+ public String getType() { >+ return TYPE; >+ } >+ >+ /** >+ * Returns the symbolic name of the feature this bundle container resolves from >+ * >+ * @return string feature id (symbolic name) >+ */ >+ public String getFeatureId() { >+ return fId; >+ } >+ >+ /** >+ * Returns the version of the feature this bundle container resolves from if >+ * a version was specified. >+ * >+ * @return string feature version or <code>null</code> >+ */ >+ public String getFeatureVersion() { >+ return fVersion; >+ } >+ >+ /** >+ * 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.impl.AbstractBundleContainer#resolveAllBundles(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ protected BundleInfo[] resolveAllBundles(IProgressMonitor monitor) throws CoreException { >+ return resolveBundles0(monitor, false); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.impl.AbstractBundleContainer#resolveAllSourceBundles(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ protected BundleInfo[] resolveAllSourceBundles(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_2, 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); >+ } >+ IFeature feature = model.getFeature(); >+ IFeaturePlugin[] plugins = feature.getPlugins(); >+ BundleInfo[] matchInfos = new BundleInfo[plugins.length]; >+ for (int i = 0; i < plugins.length; i++) { >+ IFeaturePlugin plugin = plugins[i]; >+ matchInfos[i] = new BundleInfo(plugin.getId(), plugin.getVersion(), null, BundleInfo.NO_LEVEL, false); >+ } >+ return AbstractBundleContainer.getMatchingBundles(bundles, matchInfos); >+ } finally { >+ if (model != null) { >+ model.dispose(); >+ } >+ } >+ } >+ >+} >Index: src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java,v >retrieving revision 1.3 >diff -u -r1.3 AbstractBundleContainer.java >--- src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java 15 Jan 2009 23:36:11 -0000 1.3 >+++ src/org/eclipse/pde/internal/core/target/impl/AbstractBundleContainer.java 16 Jan 2009 04:11:54 -0000 >@@ -1,170 +1,171 @@ >-/******************************************************************************* >- * 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.util.*; >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.core.variables.IStringVariableManager; >-import org.eclipse.core.variables.VariablesPlugin; >-import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; >-import org.eclipse.pde.internal.core.target.provisional.IBundleContainer; >- >-/** >- * Common function for bundle containers. >- * >- * @since 3.5 >- */ >-public abstract class AbstractBundleContainer implements IBundleContainer { >- >- /** >- * Bundle restrictions (subset) this container is restricted to or <code>null</code> if >- * no restrictions. >- */ >- private BundleInfo[] fRestrictions; >- >- /** >- * 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); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor) >- */ >- public final BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException { >- BundleInfo[] all = resolveAllBundles(monitor); >- return getMatchingBundles(all); >- } >- >- /** >- * Resolves all executable bundles in this container regardless of any bundle restrictions. >- * <p> >- * Subclasses must implement this method. >- * </p> >- * @param monitor progress monitor >- * @return all executable bundles in this container regardless of any bundle restrictions >- * @throws CoreException if an error occurs >- */ >- protected abstract BundleInfo[] resolveAllBundles(IProgressMonitor monitor) throws CoreException; >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor) >- */ >- public final BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException { >- BundleInfo[] all = resolveAllSourceBundles(monitor); >- return getMatchingBundles(all); >- } >- >- /** >- * Resolves all source bundles in this container regardless of any bundle restrictions. >- * <p> >- * Subclasses must implement this method. >- * </p> >- * @param monitor progress monitor >- * @return all source bundles in this container regardless of any bundle restrictions >- * @throws CoreException if an error occurs >- */ >- protected abstract BundleInfo[] resolveAllSourceBundles(IProgressMonitor monitor) throws CoreException; >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#getRestrictions() >- */ >- public BundleInfo[] getRestrictions() { >- return fRestrictions; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#setRestrictions(org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo[]) >- */ >- public void setRestrictions(BundleInfo[] bundles) { >- fRestrictions = bundles; >- } >- >- /** >- * Returns bundles from the specified collection that match restrictions on this >- * container. >- * >- * @param all bundles to choose from >- * @return bundles that match this container's restrictions >- */ >- private BundleInfo[] getMatchingBundles(BundleInfo[] all) { >- BundleInfo[] restrictions = getRestrictions(); >- if (restrictions == null) { >- return all; >- } >- // map bundles names to available versions >- Map bundleMap = new HashMap(all.length); >- for (int i = 0; i < all.length; i++) { >- BundleInfo info = all[i]; >- List list = (List) bundleMap.get(info.getSymbolicName()); >- if (list == null) { >- list = new ArrayList(3); >- bundleMap.put(info.getSymbolicName(), list); >- } >- list.add(info); >- } >- List subset = new ArrayList(restrictions.length); >- for (int i = 0; i < restrictions.length; i++) { >- BundleInfo info = restrictions[i]; >- List list = (List) bundleMap.get(info.getSymbolicName()); >- if (list != null) { >- String version = info.getVersion(); >- if (version == null) { >- // select newest >- if (list.size() > 1) { >- // sort the list >- Collections.sort(list, new Comparator() { >- public int compare(Object o1, Object o2) { >- return ((BundleInfo) o1).getVersion().compareTo(o2); >- } >- }); >- } >- // select the last one >- subset.add(list.get(list.size() - 1)); >- } else { >- Iterator iterator = list.iterator(); >- boolean found = false; >- while (iterator.hasNext() && !found) { >- BundleInfo bundle = (BundleInfo) iterator.next(); >- if (bundle.getVersion().equals(version)) { >- subset.add(bundle); >- found = true; >- } >- } >- if (!found) { >- // TODO: report not found? exception? >- } >- } >- } else { >- // TODO: report not found? exception? >- } >- } >- return (BundleInfo[]) subset.toArray(new BundleInfo[subset.size()]); >- } >- >- /** >- * Returns a string that identifies the type of bundle container. This type is persisted to xml >- * so that the correct bundle container is created when deserializing the xml. This type is also >- * used to alter how the containers are presented to the user in the UI. >- * >- * @return string identifier for the type of bundle container. >- */ >- public abstract String getType(); >- >-} >+/******************************************************************************* >+ * 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.util.*; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.variables.IStringVariableManager; >+import org.eclipse.core.variables.VariablesPlugin; >+import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; >+import org.eclipse.pde.internal.core.target.provisional.IBundleContainer; >+ >+/** >+ * Common function for bundle containers. >+ * >+ * @since 3.5 >+ */ >+public abstract class AbstractBundleContainer implements IBundleContainer { >+ >+ /** >+ * Bundle restrictions (subset) this container is restricted to or <code>null</code> if >+ * no restrictions. >+ */ >+ private BundleInfo[] fRestrictions; >+ >+ /** >+ * 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); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveBundles(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public final BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException { >+ BundleInfo[] all = resolveAllBundles(monitor); >+ return getMatchingBundles(all, getRestrictions()); >+ } >+ >+ /** >+ * Resolves all executable bundles in this container regardless of any bundle restrictions. >+ * <p> >+ * Subclasses must implement this method. >+ * </p> >+ * @param monitor progress monitor >+ * @return all executable bundles in this container regardless of any bundle restrictions >+ * @throws CoreException if an error occurs >+ */ >+ protected abstract BundleInfo[] resolveAllBundles(IProgressMonitor monitor) throws CoreException; >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#resolveSourceBundles(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public final BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException { >+ BundleInfo[] all = resolveAllSourceBundles(monitor); >+ return getMatchingBundles(all, getRestrictions()); >+ } >+ >+ /** >+ * Resolves all source bundles in this container regardless of any bundle restrictions. >+ * <p> >+ * Subclasses must implement this method. >+ * </p> >+ * @param monitor progress monitor >+ * @return all source bundles in this container regardless of any bundle restrictions >+ * @throws CoreException if an error occurs >+ */ >+ protected abstract BundleInfo[] resolveAllSourceBundles(IProgressMonitor monitor) throws CoreException; >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#getRestrictions() >+ */ >+ public BundleInfo[] getRestrictions() { >+ return fRestrictions; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.pde.internal.core.target.provisional.IBundleContainer#setRestrictions(org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo[]) >+ */ >+ public void setRestrictions(BundleInfo[] bundles) { >+ fRestrictions = bundles; >+ } >+ >+ /** >+ * Returns bundles from the specified collection that match the symbolic names >+ * and/or version in the specified criteria. When no version is specified >+ * the newest version (if any) is selected. >+ * >+ * @param collection bundles to resolve against match criteria >+ * @param criteria bundles to select or <code>null</code> if no restrictions >+ * @return bundles that match this container's restrictions >+ */ >+ static BundleInfo[] getMatchingBundles(BundleInfo[] collection, BundleInfo[] criteria) { >+ if (criteria == null) { >+ return collection; >+ } >+ // map bundles names to available versions >+ Map bundleMap = new HashMap(collection.length); >+ for (int i = 0; i < collection.length; i++) { >+ BundleInfo info = collection[i]; >+ List list = (List) bundleMap.get(info.getSymbolicName()); >+ if (list == null) { >+ list = new ArrayList(3); >+ bundleMap.put(info.getSymbolicName(), list); >+ } >+ list.add(info); >+ } >+ List subset = new ArrayList(criteria.length); >+ for (int i = 0; i < criteria.length; i++) { >+ BundleInfo info = criteria[i]; >+ List list = (List) bundleMap.get(info.getSymbolicName()); >+ if (list != null) { >+ String version = info.getVersion(); >+ if (version == null) { >+ // select newest >+ if (list.size() > 1) { >+ // sort the list >+ Collections.sort(list, new Comparator() { >+ public int compare(Object o1, Object o2) { >+ return ((BundleInfo) o1).getVersion().compareTo(o2); >+ } >+ }); >+ } >+ // select the last one >+ subset.add(list.get(list.size() - 1)); >+ } else { >+ Iterator iterator = list.iterator(); >+ boolean found = false; >+ while (iterator.hasNext() && !found) { >+ BundleInfo bundle = (BundleInfo) iterator.next(); >+ if (bundle.getVersion().equals(version)) { >+ subset.add(bundle); >+ found = true; >+ } >+ } >+ if (!found) { >+ // TODO: report not found? exception? >+ } >+ } >+ } else { >+ // TODO: report not found? exception? >+ } >+ } >+ return (BundleInfo[]) subset.toArray(new BundleInfo[subset.size()]); >+ } >+ >+ /** >+ * Returns a string that identifies the type of bundle container. This type is persisted to xml >+ * so that the correct bundle container is created when deserializing the xml. This type is also >+ * used to alter how the containers are presented to the user in the UI. >+ * >+ * @return string identifier for the type of bundle container. >+ */ >+ public abstract String getType(); >+ >+} >Index: src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java,v >retrieving revision 1.1 >diff -u -r1.1 LoadTargetDefinitionJob.java >--- src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java 12 Jan 2009 23:12:39 -0000 1.1 >+++ src/org/eclipse/pde/internal/core/target/provisional/LoadTargetDefinitionJob.java 16 Jan 2009 04:11:54 -0000 >@@ -1,327 +1,323 @@ >-/******************************************************************************* >- * 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 <code>null</code> or the >- * specified value. >- * >- * @param pref preference store >- * @param key preference key >- * @param value preference value or <code>null</code> >- */ >- 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. >- * <p> >- * 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. >- * </p> >- * @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. >- * <p> >- * For now we just clear it. >- * </p> >- * @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(); >- } >- >-} >+/******************************************************************************* >+ * 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 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.target.impl.Messages; >+ >+/** >+ * 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 <code>null</code> or the >+ * specified value. >+ * >+ * @param pref preference store >+ * @param key preference key >+ * @param value preference value or <code>null</code> >+ */ >+ 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. >+ * <p> >+ * 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. >+ * </p> >+ * @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(); >+ } >+ >+ /** >+ * Sets implicit dependencies, if any >+ * >+ * @param pref preference store >+ * @param monitor progress monitor >+ */ >+ private void loadImplicitPlugins(Preferences pref, IProgressMonitor monitor) { >+ BundleInfo[] infos = fTarget.getImplicitDependencies(); >+ if (infos != null) { >+ monitor.beginTask(Messages.LoadTargetOperation_implicitPluginsTaskName, infos.length + 1); >+ StringBuffer buffer = new StringBuffer(); >+ for (int i = 0; i < infos.length; i++) { >+ buffer.append(infos[i].getSymbolicName()).append(','); >+ monitor.worked(1); >+ } >+ if (infos.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. >+ * <p> >+ * For now we just clear it. >+ * </p> >+ * @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/provisional/ITargetDefinition.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/provisional/ITargetDefinition.java,v >retrieving revision 1.1 >diff -u -r1.1 ITargetDefinition.java >--- src/org/eclipse/pde/internal/core/target/provisional/ITargetDefinition.java 8 Jan 2009 17:25:11 -0000 1.1 >+++ src/org/eclipse/pde/internal/core/target/provisional/ITargetDefinition.java 16 Jan 2009 04:11:54 -0000 >@@ -1,212 +1,241 @@ >-/******************************************************************************* >- * 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; >-import org.eclipse.osgi.service.environment.Constants; >- >-/** >- * Defines a target platform. A target platform is a collection of bundles configured >- * for a specific environment. >- * >- * @since 3.5 >- */ >-public interface ITargetDefinition { >- >- /** >- * Returns the name of this target, or <code>null</code> if none >- * >- * @return name or <code>null</code> >- */ >- public String getName(); >- >- /** >- * Sets the name of this target. >- * >- * @param name target name or <code>null</code> >- */ >- public void setName(String name); >- >- /** >- * Returns the description of this target or <code>null</code> if none. >- * >- * @return target description >- */ >- public String getDescription(); >- >- /** >- * Sets the description of this target, possibly <code>null</code>. >- * >- * @param description target description or <code>null</code> >- */ >- public void setDescription(String description); >- >- /** >- * Sets the execution environment this target requires to run. An execution >- * environment is specified by its associated OSGi profile identifier - for >- * example, <code>J2SE-1.4</code>. >- * >- * @param environment execution environment identifier >- */ >- public void setExecutionEnvironment(String environment); >- >- /** >- * Returns the identifier of the execution environment this target requires to run. >- * >- * @return execution environment identifier >- */ >- public String getExecutionEnvironment(); >- >- /** >- * Returns the identifier of the operating system this target is configured for, >- * possibly <code>null</code>. >- * >- * @return operating system identifier or <code>null</code> to default to the >- * running operating system >- */ >- public String getOS(); >- >- /** >- * Sets the operating system this target is configured for or <code>null</code> to >- * default to the running operating system. >- * >- * @param operating system identifier - one of the operating system constants >- * defined by {@link Constants} or <code>null</code> to default to the running >- * operating system >- */ >- public void setOS(String os); >- >- /** >- * Returns the identifier of the window system this target is configured for, >- * possibly <code>null</code>. >- * >- * @return window system identifier - one of the window system constants >- * defined by {@link Constants}, or <code>null</code> to default to the >- * running window system >- */ >- public String getWS(); >- >- /** >- * Sets the window system this target is configured for or <code>null</code> to >- * default to the running window system. >- * >- * @param window system identifier or <code>null</code> to default to the >- * running window system >- */ >- public void setWS(String ws); >- >- /** >- * Returns the identifier of the architecture this target is configured for, >- * or <code>null</code> to default to the running architecture. >- * >- * @return architecture identifier - one of the architecture constants >- * defined by {@link Constants} or <code>null</code> to default to the running >- * architecture >- */ >- public String getArch(); >- >- /** >- * Sets the architecture this target is configured for, or <code>null</code> to default >- * to the running architecture. >- * >- * @param architecture identifier or <code>null</code> to default to the >- * running architecture. >- */ >- public void setArch(String arch); >- >- /** >- * Returns the identifier of the locale this target is configured for, or <code>null</code> >- * for default. >- * >- * @return locale identifier or <code>null</code> for default >- */ >- public String getNL(); >- >- /** >- * Sets the locale this target is configured for or <code>null</code> for default. >- * >- * @param locale identifier or <code>null</code> for default >- */ >- public void setNL(String nl); >- >- /** >- * Returns the bundle containers defined by this target, possible <code>null</code>. >- * >- * @return bundle containers or <code>null</code> >- */ >- public IBundleContainer[] getBundleContainers(); >- >- /** >- * Sets the bundle containers in this target definition or <code>null</code> if none. >- * >- * @param containers bundle containers or <code>null</code> >- */ >- public void setBundleContainers(IBundleContainer[] containers); >- >- /** >- * Resolves and returns all executable bundles in this target definition, possibly empty. >- * >- * @param monitor progress monitor or <code>null</code> >- * @return all executable bundles in this target definition >- * @throws CoreException if unable to resolve >- */ >- public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException; >- >- /** >- * Resolves and returns all source bundles in this target definition, possibly empty. >- * >- * @param monitor progress monitor or <code>null</code> >- * @return all source bundles in this target definition >- * @throws CoreException if unable to resolve >- */ >- public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException; >- >- /** >- * Returns any program arguments that should be used when launching this target >- * or <code>null</code> if none. >- * >- * @return program arguments or <code>null</code> if none >- */ >- public String getProgramArguments(); >- >- /** >- * Sets any program arguments that should be used when launching this target >- * or <code>null</code> if none. >- * >- * @param args program arguments or <code>null</code> >- */ >- public void setProgramArguments(String args); >- >- /** >- * Returns any VM arguments that should be used when launching this target >- * or <code>null</code> if none. >- * >- * @return VM arguments or <code>null</code> if none >- */ >- public String getVMArguments(); >- >- /** >- * Sets any VM arguments that should be used when launching this target >- * or <code>null</code> if none. >- * >- * @param args VM arguments or <code>null</code> >- */ >- public void setVMArguments(String args); >- >- /** >- * Returns a handle to this target definition. >- * >- * @return target handle >- */ >- public ITargetHandle getHandle(); >-} >+/******************************************************************************* >+ * 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; >+import org.eclipse.osgi.service.environment.Constants; >+ >+/** >+ * Defines a target platform. A target platform is a collection of bundles configured >+ * for a specific environment. >+ * >+ * @since 3.5 >+ */ >+public interface ITargetDefinition { >+ >+ /** >+ * Returns the name of this target, or <code>null</code> if none >+ * >+ * @return name or <code>null</code> >+ */ >+ public String getName(); >+ >+ /** >+ * Sets the name of this target. >+ * >+ * @param name target name or <code>null</code> >+ */ >+ public void setName(String name); >+ >+ /** >+ * Returns the description of this target or <code>null</code> if none. >+ * >+ * @return target description >+ */ >+ public String getDescription(); >+ >+ /** >+ * Sets the description of this target, possibly <code>null</code>. >+ * >+ * @param description target description or <code>null</code> >+ */ >+ public void setDescription(String description); >+ >+ /** >+ * Sets the execution environment this target requires to run. An execution >+ * environment is specified by its associated OSGi profile identifier - for >+ * example, <code>J2SE-1.4</code>. >+ * >+ * @param environment execution environment identifier >+ */ >+ public void setExecutionEnvironment(String environment); >+ >+ /** >+ * Returns the identifier of the execution environment this target requires to run. >+ * >+ * @return execution environment identifier >+ */ >+ public String getExecutionEnvironment(); >+ >+ /** >+ * Returns the identifier of the operating system this target is configured for, >+ * possibly <code>null</code>. >+ * >+ * @return operating system identifier or <code>null</code> to default to the >+ * running operating system >+ */ >+ public String getOS(); >+ >+ /** >+ * Sets the operating system this target is configured for or <code>null</code> to >+ * default to the running operating system. >+ * >+ * @param operating system identifier - one of the operating system constants >+ * defined by {@link Constants} or <code>null</code> to default to the running >+ * operating system >+ */ >+ public void setOS(String os); >+ >+ /** >+ * Returns the identifier of the window system this target is configured for, >+ * possibly <code>null</code>. >+ * >+ * @return window system identifier - one of the window system constants >+ * defined by {@link Constants}, or <code>null</code> to default to the >+ * running window system >+ */ >+ public String getWS(); >+ >+ /** >+ * Sets the window system this target is configured for or <code>null</code> to >+ * default to the running window system. >+ * >+ * @param window system identifier or <code>null</code> to default to the >+ * running window system >+ */ >+ public void setWS(String ws); >+ >+ /** >+ * Returns the identifier of the architecture this target is configured for, >+ * or <code>null</code> to default to the running architecture. >+ * >+ * @return architecture identifier - one of the architecture constants >+ * defined by {@link Constants} or <code>null</code> to default to the running >+ * architecture >+ */ >+ public String getArch(); >+ >+ /** >+ * Sets the architecture this target is configured for, or <code>null</code> to default >+ * to the running architecture. >+ * >+ * @param architecture identifier or <code>null</code> to default to the >+ * running architecture. >+ */ >+ public void setArch(String arch); >+ >+ /** >+ * Returns the identifier of the locale this target is configured for, or <code>null</code> >+ * for default. >+ * >+ * @return locale identifier or <code>null</code> for default >+ */ >+ public String getNL(); >+ >+ /** >+ * Sets the locale this target is configured for or <code>null</code> for default. >+ * >+ * @param locale identifier or <code>null</code> for default >+ */ >+ public void setNL(String nl); >+ >+ /** >+ * Returns the bundle containers defined by this target, possible <code>null</code>. >+ * >+ * @return bundle containers or <code>null</code> >+ */ >+ public IBundleContainer[] getBundleContainers(); >+ >+ /** >+ * Sets the bundle containers in this target definition or <code>null</code> if none. >+ * >+ * @param containers bundle containers or <code>null</code> >+ */ >+ public void setBundleContainers(IBundleContainer[] containers); >+ >+ /** >+ * Resolves and returns all executable bundles in this target definition, possibly empty. >+ * >+ * @param monitor progress monitor or <code>null</code> >+ * @return all executable bundles in this target definition >+ * @throws CoreException if unable to resolve >+ */ >+ public BundleInfo[] resolveBundles(IProgressMonitor monitor) throws CoreException; >+ >+ /** >+ * Resolves and returns all source bundles in this target definition, possibly empty. >+ * >+ * @param monitor progress monitor or <code>null</code> >+ * @return all source bundles in this target definition >+ * @throws CoreException if unable to resolve >+ */ >+ public BundleInfo[] resolveSourceBundles(IProgressMonitor monitor) throws CoreException; >+ >+ /** >+ * Returns any program arguments that should be used when launching this target >+ * or <code>null</code> if none. >+ * >+ * @return program arguments or <code>null</code> if none >+ */ >+ public String getProgramArguments(); >+ >+ /** >+ * Sets any program arguments that should be used when launching this target >+ * or <code>null</code> if none. >+ * >+ * @param args program arguments or <code>null</code> >+ */ >+ public void setProgramArguments(String args); >+ >+ /** >+ * Returns any VM arguments that should be used when launching this target >+ * or <code>null</code> if none. >+ * >+ * @return VM arguments or <code>null</code> if none >+ */ >+ public String getVMArguments(); >+ >+ /** >+ * Sets any VM arguments that should be used when launching this target >+ * or <code>null</code> if none. >+ * >+ * @param args VM arguments or <code>null</code> >+ */ >+ public void setVMArguments(String args); >+ >+ /** >+ * Returns a handle to this target definition. >+ * >+ * @return target handle >+ */ >+ public ITargetHandle getHandle(); >+ >+ /** >+ * Sets implicit dependencies for this target. Bundles in this collection are always >+ * considered by PDE when computing plug-in dependencies. Only symbolic names need to >+ * be specified in the given bundle descriptions. >+ * >+ * @param bundles implicit dependencies or <code>null</code> if none >+ */ >+ public void setImplicitDependencies(BundleInfo[] bundles); >+ >+ /** >+ * Returns the implicit dependencies set on this target or <code>null</code> if none. >+ * Note that this does not resolve the actual bundles used as implicit dependencies - see >+ * {@link #resolveImplicitDependencies(IProgressMonitor)} for resolution. >+ * >+ * @return implicit dependencies or <code>null</code> >+ */ >+ public BundleInfo[] getImplicitDependencies(); >+ >+ /** >+ * Resolves and returns implicit dependencies against the actual bundles contained >+ * in this target. Matches symbolic names and optional versions of implicit dependencies >+ * against the actual bundles in this target. >+ * >+ * @param monitor progress monitor or <code>null</code> >+ * @return resolved implicit dependencies >+ * @throws CoreException if unable to resolve >+ */ >+ public BundleInfo[] resolveImplicitDependencies(IProgressMonitor monitor) throws CoreException; >+} >#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.4 >diff -u -r1.4 TargetDefinitionTests.java >--- src/org/eclipse/pde/ui/tests/target/TargetDefinitionTests.java 15 Jan 2009 23:36:28 -0000 1.4 >+++ src/org/eclipse/pde/ui/tests/target/TargetDefinitionTests.java 16 Jan 2009 04:11:56 -0000 >@@ -1,955 +1,984 @@ >-/******************************************************************************* >- * 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 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.impl.TargetDefinitionPersistenceHelper; >-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; >- } >- >- /** >- * Retrieves all bundles (source and code) in the given target definition >- * returning them as a list of BundleInfos. >- * >- * @param target target definition >- * @return all BundleInfos >- */ >- protected List getAllBundleInfos(ITargetDefinition target) throws Exception { >- BundleInfo[] code = target.resolveBundles(null); >- BundleInfo[] source = target.resolveSourceBundles(null); >- List list = new ArrayList(code.length + source.length); >- for (int i = 0; i < code.length; i++) { >- list.add(code[i]); >- } >- for (int i = 0; i < source.length; i++) { >- list.add(source[i]); >- } >- return list; >- } >- >- /** >- * Collects all bundle symbolic names into a set. >- * >- * @param infos bundles >- * @return bundle symbolic names >- */ >- protected Set collectAllSymbolicNames(List infos) { >- Set set = new HashSet(infos.size()); >- Iterator iterator = infos.iterator(); >- while (iterator.hasNext()) { >- BundleInfo info = (BundleInfo) iterator.next(); >- set.add(info.getSymbolicName()); >- } >- return set; >- } >- >- /** >- * 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 <code>null</code> 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(), null); >- 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 based on the default target platform >- * restricted to a subset of bundles contains the right set. >- * >- * @throws Exception >- */ >- public void testRestrictedDefaultTargetPlatform() throws Exception { >- ITargetDefinition definition = getTargetService().newTarget(); >- IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(), null); >- BundleInfo[] restrictions = new BundleInfo[]{ >- new BundleInfo("org.eclipse.jdt.launching", null, null, BundleInfo.NO_LEVEL, false), >- new BundleInfo("org.eclipse.jdt.debug", null, null, BundleInfo.NO_LEVEL, false) >- }; >- container.setRestrictions(restrictions); >- definition.setBundleContainers(new IBundleContainer[]{container}); >- List infos = getAllBundleInfos(definition); >- >- assertEquals("Wrong number of bundles", 2, infos.size()); >- Set set = collectAllSymbolicNames(infos); >- for (int i = 0; i < restrictions.length; i++) { >- BundleInfo info = restrictions[i]; >- set.remove(info.getSymbolicName()); >- } >- assertEquals("Wrong bundles", 0, set.size()); >- >- } >- >- /** >- * Tests that a target definition based on the default target platform >- * restricted to a subset of bundle versions contains the right set. >- * >- * @throws Exception >- */ >- public void testVersionRestrictedDefaultTargetPlatform() throws Exception { >- ITargetDefinition definition = getTargetService().newTarget(); >- IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(), null); >- definition.setBundleContainers(new IBundleContainer[]{container}); >- List infos = getAllBundleInfos(definition); >- // find right versions >- String v1 = null; >- String v2 = null; >- Iterator iterator = infos.iterator(); >- while (iterator.hasNext() && (v2 == null || v1 == null)) { >- BundleInfo info = (BundleInfo) iterator.next(); >- if (info.getSymbolicName().equals("org.eclipse.jdt.launching")) { >- v1 = info.getVersion(); >- } else if (info.getSymbolicName().equals("org.eclipse.jdt.debug")) { >- v2 = info.getVersion(); >- } >- } >- assertNotNull(v1); >- assertNotNull(v2); >- >- BundleInfo[] restrictions = new BundleInfo[]{ >- new BundleInfo("org.eclipse.jdt.launching", v1, null, BundleInfo.NO_LEVEL, false), >- new BundleInfo("org.eclipse.jdt.debug", v2, null, BundleInfo.NO_LEVEL, false) >- }; >- container.setRestrictions(restrictions); >- infos = getAllBundleInfos(definition); >- >- assertEquals("Wrong number of bundles", 2, infos.size()); >- iterator = infos.iterator(); >- while (iterator.hasNext()) { >- BundleInfo info = (BundleInfo) iterator.next(); >- if (info.getSymbolicName().equals("org.eclipse.jdt.launching")) { >- assertEquals(v1, info.getVersion()); >- } else if (info.getSymbolicName().equals("org.eclipse.jdt.debug")) { >- assertEquals(v2, info.getVersion()); >- } >- } >- } >- >- /** >- * Tests that a target definition based on the default target platform >- * restricted to a subset of bundles contains the right set. In this case >- * empty, since the versions specified are bogus. >- * >- * @throws Exception >- */ >- public void testMissingVersionRestrictedDefaultTargetPlatform() throws Exception { >- ITargetDefinition definition = getTargetService().newTarget(); >- IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(), null); >- BundleInfo[] restrictions = new BundleInfo[]{ >- new BundleInfo("org.eclipse.jdt.launching", "xyz", null, BundleInfo.NO_LEVEL, false), >- new BundleInfo("org.eclipse.jdt.debug", "abc", null, BundleInfo.NO_LEVEL, false) >- }; >- container.setRestrictions(restrictions); >- definition.setBundleContainers(new IBundleContainer[]{container}); >- List infos = getAllBundleInfos(definition); >- >- assertEquals("Wrong number of bundles", 0, infos.size()); >- } >- >- /** >- * 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}", null); >- 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 that a target definition based on the JDT feature >- * restricted to a subset of bundles contains the right set. >- * >- * @throws Exception >- */ >- public void testRestrictedFeatureBundleContainer() throws Exception { >- ITargetDefinition definition = getTargetService().newTarget(); >- IBundleContainer container = getTargetService().newFeatureContainer("${eclipse_home}", "org.eclipse.jdt", null); >- BundleInfo[] restrictions = new BundleInfo[]{ >- new BundleInfo("org.eclipse.jdt.launching", null, null, BundleInfo.NO_LEVEL, false), >- new BundleInfo("org.eclipse.jdt.debug", null, null, BundleInfo.NO_LEVEL, false) >- }; >- container.setRestrictions(restrictions); >- definition.setBundleContainers(new IBundleContainer[]{container}); >- List infos = getAllBundleInfos(definition); >- >- assertEquals("Wrong number of bundles", 2, infos.size()); >- Set set = collectAllSymbolicNames(infos); >- for (int i = 0; i < restrictions.length; i++) { >- BundleInfo info = restrictions[i]; >- set.remove(info.getSymbolicName()); >- } >- assertEquals("Wrong bundles", 0, set.size()); >- >- } >- >- /** >- * 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(); >- } >- } >- >- /** >- * Tests that a complex target definition can be serialized to xml, then deserialized without >- * any loss of data. >- * >- * @throws Exception >- */ >- public void testPersistComplexDefinition() throws Exception { >- ITargetDefinition definitionA = getTargetService().newTarget(); >- >- definitionA.setName("name"); >- definitionA.setDescription("description"); >- definitionA.setOS("os"); >- definitionA.setWS("ws"); >- definitionA.setArch("arch"); >- definitionA.setNL("nl"); >- definitionA.setProgramArguments("program\nargs"); >- definitionA.setVMArguments("vm\nargs"); >- definitionA.setExecutionEnvironment("execution env"); >- >- // Directory container >- IBundleContainer dirContainer = getTargetService().newDirectoryContainer(TargetPlatform.getDefaultLocation() + "/plugins"); >- // Profile container with specific config area >- IBundleContainer profileContainer = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(), new File(Platform.getConfigurationLocation().getURL().getFile()).getAbsolutePath()); >- // Feature container with specific version >- // TODO Unexpected CoreException when running >-// IPath location = getJdtFeatureLocation(); >-// String segment = location.lastSegment(); >-// int index = segment.indexOf('_'); >-// assertTrue("Missing version id", index > 0); >-// String version = segment.substring(index + 1); >-// IBundleContainer featureContainer = getTargetService().newFeatureContainer("${eclipse_home}", "org.eclipse.jdt", version); >- // Profile container restricted to just two bundles >- IBundleContainer restrictedProfileContainer = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(), null); >- BundleInfo[] restrictions = new BundleInfo[]{ >- new BundleInfo("org.eclipse.jdt.launching", null, null, BundleInfo.NO_LEVEL, false), >- new BundleInfo("org.eclipse.jdt.debug", null, null, BundleInfo.NO_LEVEL, false) >- }; >- restrictedProfileContainer.setRestrictions(restrictions); >- definitionA.setBundleContainers(new IBundleContainer[]{dirContainer, profileContainer, /*featureContainer,*/ restrictedProfileContainer}); >- >- ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); >- TargetDefinitionPersistenceHelper.persistXML(definitionA, outputStream); >- ITargetDefinition definitionB = getTargetService().newTarget(); >- ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); >- TargetDefinitionPersistenceHelper.initFromXML(definitionB, inputStream); >- >- assertTargetDefinitionsEqual(definitionA, definitionB); >- } >- >- /** >- * Tests that an empty target definition can be serialized to xml, then deserialized without >- * any loss of data. >- * >- * @throws Exception >- */ >- public void testPersistEmptyDefinition() throws Exception { >- ITargetDefinition definitionA = getTargetService().newTarget(); >- ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); >- TargetDefinitionPersistenceHelper.persistXML(definitionA, outputStream); >- ITargetDefinition definitionB = getTargetService().newTarget(); >- ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); >- TargetDefinitionPersistenceHelper.initFromXML(definitionB, inputStream); >- assertTargetDefinitionsEqual(definitionA, definitionB); >- } >- >- protected void assertTargetDefinitionsEqual(ITargetDefinition targetA, ITargetDefinition targetB) throws CoreException{ >- assertEquals(targetA.getName(),targetB.getName()); >- assertEquals(targetA.getDescription(),targetB.getDescription()); >- assertEquals(targetA.getOS(),targetB.getOS()); >- assertEquals(targetA.getWS(),targetB.getWS()); >- assertEquals(targetA.getArch(),targetB.getArch()); >- assertEquals(targetA.getNL(),targetB.getNL()); >- assertEquals(targetA.getProgramArguments(),targetB.getProgramArguments()); >- assertEquals(targetA.getVMArguments(),targetB.getVMArguments()); >- // TODO Execution environment and Implicit dependencies not implemented yet >-// assertEquals(targetA.getExecutionEnvironment(),targetB.getExecutionEnvironment()); >- >- >- IBundleContainer[] containersA = targetA.getBundleContainers(); >- IBundleContainer[] containersB = targetB.getBundleContainers(); >- if (containersA != null){ >- assertNotNull("Bundle containers are missing",containersB); >- for (int aIndex = 0; aIndex < containersA.length; aIndex++) { >- boolean foundMatch = false; >- for (int bIndex = 0; bIndex < containersB.length; bIndex++) { >- if (containersA[aIndex].getClass().getName().equals(containersB[bIndex].getClass().getName()) >- && containersA[aIndex].getHomeLocation().equals(containersB[bIndex].getHomeLocation()) >- && containersA[aIndex].resolveBundles(null).length == containersB[bIndex].resolveBundles(null).length){ >- >- boolean matchingRestrictions = true; >- if (containersA[aIndex].getRestrictions() != null){ >- List restrictionsA = Arrays.asList(containersA[aIndex].getRestrictions()); >- Set restrictionIDs = collectAllSymbolicNames(restrictionsA); >- BundleInfo[] restrictionsB = containersB[bIndex].getRestrictions(); >- assertNotNull("Bundle container's restrictions are missing",restrictionsB); >- for (int restrictB = 0; restrictB < restrictionsB.length; restrictB++) { >- if (!restrictionIDs.contains(restrictionsB[restrictB].getSymbolicName())){ >- matchingRestrictions = false; >- } >- } >- } >- if (matchingRestrictions){ >- foundMatch = true; >- } >- } >- } >- assertTrue("The target definitions have non matching bundle containers",foundMatch); >- } >- } >- >- } >- >- /** >- * Tests that we can deserialize an old style target definition file (version 3.2) and retrieve the correct >- * contents. >- * >- * @throws Exception >- */ >- public void testReadOldTargetFile() throws Exception { >- // TODO Create an example old style target definition to test with >- } >- >-} >+/******************************************************************************* >+ * 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 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.impl.TargetDefinitionPersistenceHelper; >+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; >+ } >+ >+ /** >+ * Retrieves all bundles (source and code) in the given target definition >+ * returning them as a list of BundleInfos. >+ * >+ * @param target target definition >+ * @return all BundleInfos >+ */ >+ protected List getAllBundleInfos(ITargetDefinition target) throws Exception { >+ BundleInfo[] code = target.resolveBundles(null); >+ BundleInfo[] source = target.resolveSourceBundles(null); >+ List list = new ArrayList(code.length + source.length); >+ for (int i = 0; i < code.length; i++) { >+ list.add(code[i]); >+ } >+ for (int i = 0; i < source.length; i++) { >+ list.add(source[i]); >+ } >+ return list; >+ } >+ >+ /** >+ * Collects all bundle symbolic names into a set. >+ * >+ * @param infos bundles >+ * @return bundle symbolic names >+ */ >+ protected Set collectAllSymbolicNames(List infos) { >+ Set set = new HashSet(infos.size()); >+ Iterator iterator = infos.iterator(); >+ while (iterator.hasNext()) { >+ BundleInfo info = (BundleInfo) iterator.next(); >+ set.add(info.getSymbolicName()); >+ } >+ return set; >+ } >+ >+ /** >+ * 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 <code>null</code> 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(), null); >+ 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 based on the default target platform >+ * restricted to a subset of bundles contains the right set. >+ * >+ * @throws Exception >+ */ >+ public void testRestrictedDefaultTargetPlatform() throws Exception { >+ ITargetDefinition definition = getTargetService().newTarget(); >+ IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(), null); >+ BundleInfo[] restrictions = new BundleInfo[]{ >+ new BundleInfo("org.eclipse.jdt.launching", null, null, BundleInfo.NO_LEVEL, false), >+ new BundleInfo("org.eclipse.jdt.debug", null, null, BundleInfo.NO_LEVEL, false) >+ }; >+ container.setRestrictions(restrictions); >+ definition.setBundleContainers(new IBundleContainer[]{container}); >+ List infos = getAllBundleInfos(definition); >+ >+ assertEquals("Wrong number of bundles", 2, infos.size()); >+ Set set = collectAllSymbolicNames(infos); >+ for (int i = 0; i < restrictions.length; i++) { >+ BundleInfo info = restrictions[i]; >+ set.remove(info.getSymbolicName()); >+ } >+ assertEquals("Wrong bundles", 0, set.size()); >+ >+ } >+ >+ /** >+ * Tests that a target definition based on the default target platform >+ * restricted to a subset of bundle versions contains the right set. >+ * >+ * @throws Exception >+ */ >+ public void testVersionRestrictedDefaultTargetPlatform() throws Exception { >+ ITargetDefinition definition = getTargetService().newTarget(); >+ IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(), null); >+ definition.setBundleContainers(new IBundleContainer[]{container}); >+ List infos = getAllBundleInfos(definition); >+ // find right versions >+ String v1 = null; >+ String v2 = null; >+ Iterator iterator = infos.iterator(); >+ while (iterator.hasNext() && (v2 == null || v1 == null)) { >+ BundleInfo info = (BundleInfo) iterator.next(); >+ if (info.getSymbolicName().equals("org.eclipse.jdt.launching")) { >+ v1 = info.getVersion(); >+ } else if (info.getSymbolicName().equals("org.eclipse.jdt.debug")) { >+ v2 = info.getVersion(); >+ } >+ } >+ assertNotNull(v1); >+ assertNotNull(v2); >+ >+ BundleInfo[] restrictions = new BundleInfo[]{ >+ new BundleInfo("org.eclipse.jdt.launching", v1, null, BundleInfo.NO_LEVEL, false), >+ new BundleInfo("org.eclipse.jdt.debug", v2, null, BundleInfo.NO_LEVEL, false) >+ }; >+ container.setRestrictions(restrictions); >+ infos = getAllBundleInfos(definition); >+ >+ assertEquals("Wrong number of bundles", 2, infos.size()); >+ iterator = infos.iterator(); >+ while (iterator.hasNext()) { >+ BundleInfo info = (BundleInfo) iterator.next(); >+ if (info.getSymbolicName().equals("org.eclipse.jdt.launching")) { >+ assertEquals(v1, info.getVersion()); >+ } else if (info.getSymbolicName().equals("org.eclipse.jdt.debug")) { >+ assertEquals(v2, info.getVersion()); >+ } >+ } >+ } >+ >+ /** >+ * Tests that a target definition based on the default target platform >+ * restricted to a subset of bundles contains the right set. In this case >+ * empty, since the versions specified are bogus. >+ * >+ * @throws Exception >+ */ >+ public void testMissingVersionRestrictedDefaultTargetPlatform() throws Exception { >+ ITargetDefinition definition = getTargetService().newTarget(); >+ IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(), null); >+ BundleInfo[] restrictions = new BundleInfo[]{ >+ new BundleInfo("org.eclipse.jdt.launching", "xyz", null, BundleInfo.NO_LEVEL, false), >+ new BundleInfo("org.eclipse.jdt.debug", "abc", null, BundleInfo.NO_LEVEL, false) >+ }; >+ container.setRestrictions(restrictions); >+ definition.setBundleContainers(new IBundleContainer[]{container}); >+ List infos = getAllBundleInfos(definition); >+ >+ assertEquals("Wrong number of bundles", 0, infos.size()); >+ } >+ >+ /** >+ * 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}", null); >+ 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 that a target definition based on the JDT feature >+ * restricted to a subset of bundles contains the right set. >+ * >+ * @throws Exception >+ */ >+ public void testRestrictedFeatureBundleContainer() throws Exception { >+ ITargetDefinition definition = getTargetService().newTarget(); >+ IBundleContainer container = getTargetService().newFeatureContainer("${eclipse_home}", "org.eclipse.jdt", null); >+ BundleInfo[] restrictions = new BundleInfo[]{ >+ new BundleInfo("org.eclipse.jdt.launching", null, null, BundleInfo.NO_LEVEL, false), >+ new BundleInfo("org.eclipse.jdt.debug", null, null, BundleInfo.NO_LEVEL, false) >+ }; >+ container.setRestrictions(restrictions); >+ definition.setBundleContainers(new IBundleContainer[]{container}); >+ List infos = getAllBundleInfos(definition); >+ >+ assertEquals("Wrong number of bundles", 2, infos.size()); >+ Set set = collectAllSymbolicNames(infos); >+ for (int i = 0; i < restrictions.length; i++) { >+ BundleInfo info = restrictions[i]; >+ set.remove(info.getSymbolicName()); >+ } >+ assertEquals("Wrong bundles", 0, set.size()); >+ >+ } >+ >+ /** >+ * 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(); >+ } >+ } >+ >+ /** >+ * Tests that a complex target definition can be serialized to xml, then deserialized without >+ * any loss of data. >+ * >+ * @throws Exception >+ */ >+ public void testPersistComplexDefinition() throws Exception { >+ ITargetDefinition definitionA = getTargetService().newTarget(); >+ >+ definitionA.setName("name"); >+ definitionA.setDescription("description"); >+ definitionA.setOS("os"); >+ definitionA.setWS("ws"); >+ definitionA.setArch("arch"); >+ definitionA.setNL("nl"); >+ definitionA.setProgramArguments("program\nargs"); >+ definitionA.setVMArguments("vm\nargs"); >+ definitionA.setExecutionEnvironment("execution env"); >+ >+ // Directory container >+ IBundleContainer dirContainer = getTargetService().newDirectoryContainer(TargetPlatform.getDefaultLocation() + "/plugins"); >+ // Profile container with specific config area >+ IBundleContainer profileContainer = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(), new File(Platform.getConfigurationLocation().getURL().getFile()).getAbsolutePath()); >+ // Feature container with specific version >+ // TODO Unexpected CoreException when running >+// IPath location = getJdtFeatureLocation(); >+// String segment = location.lastSegment(); >+// int index = segment.indexOf('_'); >+// assertTrue("Missing version id", index > 0); >+// String version = segment.substring(index + 1); >+// IBundleContainer featureContainer = getTargetService().newFeatureContainer("${eclipse_home}", "org.eclipse.jdt", version); >+ // Profile container restricted to just two bundles >+ IBundleContainer restrictedProfileContainer = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(), null); >+ BundleInfo[] restrictions = new BundleInfo[]{ >+ new BundleInfo("org.eclipse.jdt.launching", null, null, BundleInfo.NO_LEVEL, false), >+ new BundleInfo("org.eclipse.jdt.debug", null, null, BundleInfo.NO_LEVEL, false) >+ }; >+ restrictedProfileContainer.setRestrictions(restrictions); >+ definitionA.setBundleContainers(new IBundleContainer[]{dirContainer, profileContainer, /*featureContainer,*/ restrictedProfileContainer}); >+ >+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); >+ TargetDefinitionPersistenceHelper.persistXML(definitionA, outputStream); >+ ITargetDefinition definitionB = getTargetService().newTarget(); >+ ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); >+ TargetDefinitionPersistenceHelper.initFromXML(definitionB, inputStream); >+ >+ assertTargetDefinitionsEqual(definitionA, definitionB); >+ } >+ >+ /** >+ * Tests that an empty target definition can be serialized to xml, then deserialized without >+ * any loss of data. >+ * >+ * @throws Exception >+ */ >+ public void testPersistEmptyDefinition() throws Exception { >+ ITargetDefinition definitionA = getTargetService().newTarget(); >+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); >+ TargetDefinitionPersistenceHelper.persistXML(definitionA, outputStream); >+ ITargetDefinition definitionB = getTargetService().newTarget(); >+ ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); >+ TargetDefinitionPersistenceHelper.initFromXML(definitionB, inputStream); >+ assertTargetDefinitionsEqual(definitionA, definitionB); >+ } >+ >+ protected void assertTargetDefinitionsEqual(ITargetDefinition targetA, ITargetDefinition targetB) throws CoreException{ >+ assertEquals(targetA.getName(),targetB.getName()); >+ assertEquals(targetA.getDescription(),targetB.getDescription()); >+ assertEquals(targetA.getOS(),targetB.getOS()); >+ assertEquals(targetA.getWS(),targetB.getWS()); >+ assertEquals(targetA.getArch(),targetB.getArch()); >+ assertEquals(targetA.getNL(),targetB.getNL()); >+ assertEquals(targetA.getProgramArguments(),targetB.getProgramArguments()); >+ assertEquals(targetA.getVMArguments(),targetB.getVMArguments()); >+ // TODO Execution environment and Implicit dependencies not implemented yet >+// assertEquals(targetA.getExecutionEnvironment(),targetB.getExecutionEnvironment()); >+ >+ >+ IBundleContainer[] containersA = targetA.getBundleContainers(); >+ IBundleContainer[] containersB = targetB.getBundleContainers(); >+ if (containersA != null){ >+ assertNotNull("Bundle containers are missing",containersB); >+ for (int aIndex = 0; aIndex < containersA.length; aIndex++) { >+ boolean foundMatch = false; >+ for (int bIndex = 0; bIndex < containersB.length; bIndex++) { >+ if (containersA[aIndex].getClass().getName().equals(containersB[bIndex].getClass().getName()) >+ && containersA[aIndex].getHomeLocation().equals(containersB[bIndex].getHomeLocation()) >+ && containersA[aIndex].resolveBundles(null).length == containersB[bIndex].resolveBundles(null).length){ >+ >+ boolean matchingRestrictions = true; >+ if (containersA[aIndex].getRestrictions() != null){ >+ List restrictionsA = Arrays.asList(containersA[aIndex].getRestrictions()); >+ Set restrictionIDs = collectAllSymbolicNames(restrictionsA); >+ BundleInfo[] restrictionsB = containersB[bIndex].getRestrictions(); >+ assertNotNull("Bundle container's restrictions are missing",restrictionsB); >+ for (int restrictB = 0; restrictB < restrictionsB.length; restrictB++) { >+ if (!restrictionIDs.contains(restrictionsB[restrictB].getSymbolicName())){ >+ matchingRestrictions = false; >+ } >+ } >+ } >+ if (matchingRestrictions){ >+ foundMatch = true; >+ } >+ } >+ } >+ assertTrue("The target definitions have non matching bundle containers",foundMatch); >+ } >+ } >+ >+ } >+ >+ /** >+ * Tests that we can deserialize an old style target definition file (version 3.2) and retrieve the correct >+ * contents. >+ * >+ * @throws Exception >+ */ >+ public void testReadOldTargetFile() throws Exception { >+ // TODO Create an example old style target definition to test with >+ } >+ >+ /** >+ * Tests resolution of implicit dependencies in a default target platform >+ * >+ * @throws Exception >+ */ >+ public void testImplicitDependencies() throws Exception { >+ ITargetDefinition definition = getTargetService().newTarget(); >+ IBundleContainer container = getTargetService().newProfileContainer(TargetPlatform.getDefaultLocation(), null); >+ definition.setBundleContainers(new IBundleContainer[]{container}); >+ BundleInfo[] implicit = new BundleInfo[]{ >+ new BundleInfo("org.eclipse.jdt.launching", null, null, BundleInfo.NO_LEVEL, false), >+ new BundleInfo("org.eclipse.jdt.debug", null, null, BundleInfo.NO_LEVEL, false) >+ }; >+ definition.setImplicitDependencies(implicit); >+ BundleInfo[] infos = definition.resolveImplicitDependencies(null); >+ >+ assertEquals("Wrong number of bundles", 2, infos.length); >+ Set set = new HashSet(); >+ for (int i = 0; i < infos.length; i++) { >+ set.add(infos[i].getSymbolicName()); >+ } >+ for (int i = 0; i < implicit.length; i++) { >+ BundleInfo info = implicit[i]; >+ set.remove(info.getSymbolicName()); >+ } >+ assertEquals("Wrong bundles", 0, set.size()); >+ >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 256910
:
119021
|
119023
|
119050
|
119547
|
120975
|
120980
|
121558
|
121570
|
122001
|
122175
|
122423
|
122424
|
122437
|
122498
| 122768 |
122847
|
122848
|
122849
|
122885
|
122887
|
123013
|
123025
|
123285
|
123446
|
123596
|
123639
|
123770
|
123771