summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis Windatt2013-08-15 15:52:33 (EDT)
committer Curtis Windatt2013-08-15 15:52:33 (EDT)
commit8f0403ba8245908b69d7be55df3b7a4841fefebb (patch)
tree3227c606c718a2874a269b432b6f85daff11985b
parent43513be32d8ca0854403e7d3740f1d5571a01bf3 (diff)
downloadeclipse.pde.ui-8f0403ba8245908b69d7be55df3b7a4841fefebb.zip
eclipse.pde.ui-8f0403ba8245908b69d7be55df3b7a4841fefebb.tar.gz
eclipse.pde.ui-8f0403ba8245908b69d7be55df3b7a4841fefebb.tar.bz2
Bug 407765 - Remove support for old style (pre-OSGi, 2.0) plug-ins
-rw-r--r--apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/BundleComponent.java31
-rw-r--r--apitools/org.eclipse.pde.api.tools/src_ant/org/eclipse/pde/api/tools/internal/tasks/CommonUtilsTask.java7
-rw-r--r--ui/org.eclipse.pde.core/META-INF/MANIFEST.MF4
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/TargetBundle.java5
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/MinimalState.java26
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java5
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEState.java6
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEStateHelper.java147
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetPlatformHelper.java28
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java5
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundleModel.java14
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundlePluginBase.java2
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel.java25
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/IModel.java59
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/PDEPluginConverter.java65
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/PluginConverter.java617
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/PluginConverterParser.java674
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties4
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/PluginBase.java41
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/project/BundleProjectService.java4
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/DirectoryBundleContainer.java14
-rwxr-xr-xui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/Messages.java3
-rwxr-xr-xui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/Messages.properties3
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/ProfileBundleContainer.java14
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/ManifestUtils.java303
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/UtilMessages.java33
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/UtilMessages.properties18
-rwxr-xr-xui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/VMUtil.java7
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/VersionUtil.java7
-rw-r--r--ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/CreateManifestOperation.java9
-rw-r--r--ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/PluginVersionPart.java11
-rw-r--r--ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/AddNewDependenciesOperation.java14
-rw-r--r--ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/ContentPage.java8
-rw-r--r--ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewLibraryPluginCreationOperation.java80
34 files changed, 508 insertions, 1785 deletions
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/BundleComponent.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/BundleComponent.java
index 71d4634..cee19cb 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/BundleComponent.java
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/BundleComponent.java
@@ -39,7 +39,6 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
-import org.eclipse.osgi.service.pluginconversion.PluginConversionException;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.BundleSpecification;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
@@ -73,8 +72,8 @@ import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
import org.eclipse.pde.api.tools.internal.util.FileManager;
import org.eclipse.pde.api.tools.internal.util.SourceDefaultHandler;
import org.eclipse.pde.api.tools.internal.util.Util;
-import org.eclipse.pde.internal.core.PDEStateHelper;
import org.eclipse.pde.internal.core.TargetWeaver;
+import org.eclipse.pde.internal.core.util.ManifestUtils;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
@@ -187,20 +186,22 @@ public class BundleComponent extends Component {
*/
protected synchronized Map getManifest() throws CoreException {
if(fManifest == null) {
- fManifest = PDEStateHelper.loadManifest(new File(fLocation));
- if (isWorkspaceBinary()) {
- // must account for bundles in development mode - look for class files in output
- // folders rather than jars
- TargetWeaver.weaveManifest(fManifest);
- }
- if (fManifest == null || fManifest.get(Constants.BUNDLE_NAME) == null){
- // Check if we have an old style (pre-osgi) bundle (this only works if OSGi is running.
- try {
- fManifest = PDEStateHelper.loadOldStyleManifest(new File(fLocation));
- } catch (PluginConversionException e) {
- // Ignore because isValidBundle will still return false
- }
+ try {
+ fManifest = ManifestUtils.loadManifest(new File(fLocation));
+ } catch (CoreException e){
+ // If we encounter an old style bundle, but can't convert because the service is unavailable, inform the user, but don't quit
+ if (e.getStatus().getCode() == ManifestUtils.STATUS_CODE_PLUGIN_CONVERTER_UNAVAILABLE){
+ System.err.println(e.getMessage());
+ return null;
+ } else {
+ throw e;
}
+ }
+ if (isWorkspaceBinary()) {
+ // must account for bundles in development mode - look for class files in output
+ // folders rather than jars
+ TargetWeaver.weaveManifest(fManifest);
+ }
}
return fManifest;
}
diff --git a/apitools/org.eclipse.pde.api.tools/src_ant/org/eclipse/pde/api/tools/internal/tasks/CommonUtilsTask.java b/apitools/org.eclipse.pde.api.tools/src_ant/org/eclipse/pde/api/tools/internal/tasks/CommonUtilsTask.java
index 5003803..06ce917 100644
--- a/apitools/org.eclipse.pde.api.tools/src_ant/org/eclipse/pde/api/tools/internal/tasks/CommonUtilsTask.java
+++ b/apitools/org.eclipse.pde.api.tools/src_ant/org/eclipse/pde/api/tools/internal/tasks/CommonUtilsTask.java
@@ -54,12 +54,13 @@ public abstract class CommonUtilsTask extends Task {
/**
* Creates a baseline with the given name and EE file location in the given directory. The installLocation
- * will be searched for bundles to add as API components.
+ * will be searched for bundles to add as API components. If an error occurs creating the baseline, the
+ * exception stack trace will be printed and an empty baseline will be returned.
*
* @param baselineName Name to use for the new baseline
* @param installLocation Location of an installation or directory of bundles to add as API components
* @param eeFileLocation execution environment location or <code>null</code> to have the EE determined from API components
- * @return a new {@link IApiBaseline}
+ * @return a new {@link IApiBaseline} or <code>null</code> if an error occurred
*/
protected IApiBaseline createBaseline(String baselineName, String installLocation, String eeFileLocation) {
try {
@@ -79,7 +80,7 @@ public abstract class CommonUtilsTask extends Task {
return baseline;
} catch (CoreException e) {
e.printStackTrace();
- return null;
+ return ApiModelFactory.newApiBaseline(baselineName);
}
}
diff --git a/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF
index a30dcdb..df30205 100644
--- a/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF
+++ b/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF
@@ -25,7 +25,6 @@ Export-Package:
org.eclipse.pde.internal.core.builders;x-friends:="org.eclipse.pde.ui,org.eclipse.pde.launching,org.eclipse.pde.ds.core",
org.eclipse.pde.internal.core.bundle;x-friends:="org.eclipse.pde.ui,org.eclipse.pde.ds.ui",
org.eclipse.pde.internal.core.content;x-internal:=true,
- org.eclipse.pde.internal.core.converter;x-friends:="org.eclipse.pde.ui",
org.eclipse.pde.internal.core.exports;x-friends:="org.eclipse.pde.ui",
org.eclipse.pde.internal.core.feature;x-friends:="org.eclipse.pde.ui",
org.eclipse.pde.internal.core.ibundle;
@@ -70,7 +69,8 @@ Export-Package:
org.eclipse.pde.launching,
org.eclipse.pde.ds.core,
org.eclipse.pde.ds.ui,
- org.eclipse.pde.ua.core",
+ org.eclipse.pde.ua.core,
+ org.eclipse.pde.api.tools",
org.eclipse.pde.internal.core.variables;x-internal:=true
Require-Bundle:
org.eclipse.core.runtime;bundle-version="[3.1.0,4.0.0)",
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/TargetBundle.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/TargetBundle.java
index c05001a..223be32 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/TargetBundle.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/TargetBundle.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2012 IBM Corporation and others.
+ * Copyright (c) 2009, 2013 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
@@ -175,7 +175,7 @@ public class TargetBundle {
}
fIsFragment = manifest.containsKey(Constants.FRAGMENT_HOST);
} catch (BundleException e) {
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, STATUS_INVALID_MANIFEST, NLS.bind(Messages.DirectoryBundleContainer_3, file.getAbsolutePath()), e));
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, STATUS_INVALID_MANIFEST, NLS.bind(Messages.TargetBundle_ErrorReadingManifest, file.getAbsolutePath()), e));
}
}
@@ -259,6 +259,7 @@ public class TargetBundle {
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
+ @Override
public String toString() {
StringBuffer result = new StringBuffer().append(getBundleInfo().toString());
IStatus status = getStatus();
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/MinimalState.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/MinimalState.java
index 40323a9..294d862 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/MinimalState.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/MinimalState.java
@@ -14,12 +14,11 @@ package org.eclipse.pde.internal.core;
import java.io.*;
import java.util.*;
import org.eclipse.core.runtime.*;
-import org.eclipse.osgi.service.pluginconversion.PluginConversionException;
import org.eclipse.osgi.service.resolver.*;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.internal.build.IPDEBuildConstants;
+import org.eclipse.pde.internal.core.util.ManifestUtils;
import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
public class MinimalState {
@@ -71,21 +70,11 @@ public class MinimalState {
model.setBundleDescription(newDesc);
if (newDesc == null && update)
fState.removeBundle(desc);
- } catch (PluginConversionException e) {
} catch (CoreException e) {
PDECore.log(e);
}
}
- public BundleDescription addBundle(IPluginModelBase model, long bundleId) {
- try {
- return addBundle(new File(model.getInstallLocation()), -1);
- } catch (PluginConversionException e) {
- } catch (CoreException e) {
- }
- return null;
- }
-
public BundleDescription addBundle(Map<String, String> manifest, File bundleLocation, long bundleId) {
try {
// OSGi requires a dictionary over any map
@@ -105,16 +94,11 @@ public class MinimalState {
return null;
}
- public BundleDescription addBundle(File bundleLocation, long bundleId) throws PluginConversionException, CoreException {
- Map<String, String> manifest = PDEStateHelper.loadManifest(bundleLocation);
+ public BundleDescription addBundle(File bundleLocation, long bundleId) throws CoreException {
+ Map<String, String> manifest = ManifestUtils.loadManifest(bundleLocation);
// update for development mode
TargetWeaver.weaveManifest(manifest);
- boolean hasBundleStructure = manifest != null && manifest.get(Constants.BUNDLE_SYMBOLICNAME) != null;
- if (!hasBundleStructure) {
- manifest = PDEStateHelper.loadOldStyleManifest(bundleLocation);
- if (manifest == null || manifest.get(Constants.BUNDLE_SYMBOLICNAME) == null)
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, IStatus.ERROR, "Error parsing plug-in manifest file at " + bundleLocation.toString(), null)); //$NON-NLS-1$
- }
+
BundleDescription desc = addBundle(manifest, bundleLocation, bundleId);
if (desc != null && manifest != null && "true".equals(manifest.get(ICoreConstants.ECLIPSE_SYSTEM_BUNDLE))) { //$NON-NLS-1$
// if this is the system bundle then
@@ -124,7 +108,7 @@ public class MinimalState {
fSystemBundle = desc.getSymbolicName();
}
if (desc != null) {
- addAuxiliaryData(desc, manifest, hasBundleStructure);
+ addAuxiliaryData(desc, manifest, true);
}
return desc;
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java
index 4c84c34..5b37cbb 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java
@@ -195,12 +195,9 @@ public class PDECoreMessages extends NLS {
public static String BundleErrorReporter_ClasspathNotEmpty;
public static String BundleErrorReporter_fragmentActivator;
public static String BundleErrorReporter_NoExist;
- public static String BundleErrorReporter_InvalidFormatInBundleVersion;
public static String BundleErrorReporter_NotExistInProject;
public static String BundleErrorReporter_BundleRangeInvalidInBundleVersion;
public static String BundleErrorReporter_R4SyntaxInR3Bundle;
-
- public static String BundleErrorReporter_invalidVersionRangeFormat;
public static String BundleErrorReporter_NotExistPDE;
public static String BundleErrorReporter_HostNotExistPDE;
public static String BundleErrorReporter_HostNeeded;
@@ -346,8 +343,6 @@ public class PDECoreMessages extends NLS {
public static String UpdateSiteBuilder_0;
- public static String VMHelper_noJreForExecEnv;
-
// Target Export ########################################
public static String ExportTargetDefinition_task;
public static String ExportTargetDeleteOldData;
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEState.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEState.java
index c1118e0..6272527 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEState.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEState.java
@@ -18,7 +18,6 @@ import java.util.*;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.*;
-import org.eclipse.osgi.service.pluginconversion.PluginConversionException;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.pde.core.plugin.IPluginModelBase;
@@ -157,8 +156,8 @@ public class PDEState extends MinimalState {
return;
monitor.subTask(file.getName());
addBundle(file, -1);
- } catch (PluginConversionException e) {
} catch (CoreException e) {
+ PDECore.log(e);
} finally {
monitor.worked(1);
}
@@ -166,6 +165,7 @@ public class PDEState extends MinimalState {
fNewState = true;
}
+ @Override
protected void addAuxiliaryData(BundleDescription desc, Map<String, String> manifest, boolean hasBundleStructure) {
fAuxiliaryState.addAuxiliaryData(desc, manifest, hasBundleStructure);
}
@@ -520,8 +520,8 @@ public class PDEState extends MinimalState {
BundleDescription desc = addBundle(file, -1);
if (desc != null)
descriptions.add(desc);
- } catch (PluginConversionException e) {
} catch (CoreException e) {
+ PDECore.log(e);
}
}
// compute Timestamp and save all new information
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEStateHelper.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEStateHelper.java
deleted file mode 100644
index 946ad23..0000000
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEStateHelper.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2013 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;
-
-import java.io.*;
-import java.util.*;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.osgi.service.pluginconversion.PluginConversionException;
-import org.eclipse.osgi.service.pluginconversion.PluginConverter;
-import org.eclipse.osgi.service.resolver.BundleDescription;
-import org.eclipse.osgi.service.resolver.ExportPackageDescription;
-import org.eclipse.osgi.util.ManifestElement;
-import org.osgi.framework.BundleException;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * A collection of static helper methods used when creating
- * the {@link PDEState}
- *
- */
-public class PDEStateHelper {
-
- private static PluginConverter fConverter = null;
-
- /**
- * Parses a bundle's manifest into a dictionary. The bundle may be in a jar
- * or in a directory at the specified location.
- *
- * Note: Used by org.eclipse.pde.api.tools.internal.model.BundleComponent.getManifest()
- * and may be called without OSGi running.
- *
- * @param bundleLocation root location of the bundle
- * @return bundle manifest dictionary or <code>null</code> if none
- */
- public static Map<String, String> loadManifest(File bundleLocation) {
- ZipFile jarFile = null;
- InputStream manifestStream = null;
- try {
- String extension = new Path(bundleLocation.getName()).getFileExtension();
- if (extension != null && bundleLocation.isFile()) {
- jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ);
- ZipEntry manifestEntry = jarFile.getEntry(JarFile.MANIFEST_NAME);
- if (manifestEntry != null) {
- manifestStream = jarFile.getInputStream(manifestEntry);
- }
- } else {
- File file = new File(bundleLocation, JarFile.MANIFEST_NAME);
- if (file.exists())
- manifestStream = new FileInputStream(file);
- }
- } catch (IOException e) {
- }
- if (manifestStream == null)
- return null;
- try {
- return ManifestElement.parseBundleManifest(manifestStream, null);
- } catch (BundleException e) {
- } catch (IOException e) {
- } finally {
- try {
- if (jarFile != null)
- jarFile.close();
- } catch (IOException e2) {
- }
- }
- return null;
- }
-
- /**
- * Uses the Equinox {@link PluginConverter} to load manifest contents of a pre-OSGi style
- * plug-in (plug-in information stored in a plugin.xml or fragment.xml). Will return
- * <code>null</code> if the plugin contents could not be parsed. Will return <code>null</code>
- * if called from a JRE without OSGi running.
- *
- * Note: Used by org.eclipse.pde.api.tools.internal.model.BundleComponent.getManifest()
- * and may be called without OSGi running (will return <code>null</code>
- *
- * @param bundleLocation root location of the bundle to load
- * @return a map of manifest entries or <code>null</code>
- * @throws PluginConversionException if there is a probe parsing the plugin.xml/fragment.xml contents
- */
- public static Map<String, String> loadOldStyleManifest(File bundleLocation) throws PluginConversionException {
- PluginConverter converter = acquirePluginConverter();
- if (converter == null) {
- return null;
- }
-
- Dictionary<String, String> converted = converter.convertManifest(bundleLocation, false, null, false, null);
- if (converted == null) {
- return null;
- }
-
- Map<String, String> manifest = new HashMap<String, String>(converted.size());
- Enumeration<String> keys = converted.keys();
- while (keys.hasMoreElements()) {
- String key = keys.nextElement();
- manifest.put(key, converted.get(key));
- }
- return manifest;
- }
-
- private static PluginConverter acquirePluginConverter() {
- if (fConverter == null) {
- PDECore activator = PDECore.getDefault();
- if (activator != null) {
- // OSGi is running so acquire the PluginConverter service
- ServiceTracker<?, ?> tracker = new ServiceTracker<Object, Object>(activator.getBundleContext(), PluginConverter.class.getName(), null);
- tracker.open();
- fConverter = (PluginConverter) tracker.getService();
- tracker.close();
- tracker = null;
- }
- }
- return fConverter;
- }
-
- /**
- * Returns the bundles that export packages imported by the given bundle
- * via the Import-Package header
- *
- * @param root the given bundle
- *
- * @return an array of bundles that export packages being imported by the given bundle
- */
- public static BundleDescription[] getImportedBundles(BundleDescription root) {
- if (root == null)
- return new BundleDescription[0];
- ExportPackageDescription[] packages = root.getResolvedImports();
- ArrayList<BundleDescription> resolvedImports = new ArrayList<BundleDescription>(packages.length);
- for (int i = 0; i < packages.length; i++)
- if (!root.getLocation().equals(packages[i].getExporter().getLocation()) && !resolvedImports.contains(packages[i].getExporter()))
- resolvedImports.add(packages[i].getExporter());
- return resolvedImports.toArray(new BundleDescription[resolvedImports.size()]);
- }
-
-}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetPlatformHelper.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetPlatformHelper.java
index 458c17d..5377ef8 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetPlatformHelper.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetPlatformHelper.java
@@ -19,12 +19,10 @@ import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.State;
-import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.pde.core.plugin.*;
import org.eclipse.pde.internal.build.IPDEBuildConstants;
import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
-import org.eclipse.pde.internal.core.util.CoreUtility;
-import org.eclipse.pde.internal.core.util.VersionUtil;
+import org.eclipse.pde.internal.core.util.*;
import org.osgi.framework.*;
public class TargetPlatformHelper {
@@ -156,21 +154,25 @@ public class TargetPlatformHelper {
if (fCachedLocations == null)
fCachedLocations = new HashMap<String, String>();
+ if (fCachedLocations.containsKey(path)) {
+ return fCachedLocations.get(path);
+ }
+
+ // TODO There needs to be a better option than loading the entire manifest every time we need a name
File file = new File(path);
- if (file.exists() && !fCachedLocations.containsKey(path)) {
+ if (file.exists()) {
try {
- Map<String, String> manifest = PDEStateHelper.loadManifest(file);
- String value = manifest.get(Constants.BUNDLE_SYMBOLICNAME);
- if (value != null) {
- ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, value);
- String id = elements.length > 0 ? elements[0].getValue() : null;
- if (id != null)
- fCachedLocations.put(path, elements[0].getValue());
+ Map<String, String> manifest = ManifestUtils.loadManifest(file);
+ String name = manifest.get(Constants.BUNDLE_SYMBOLICNAME);
+ if (name != null) {
+ fCachedLocations.put(path, name);
+ return name;
}
- } catch (BundleException e) {
+ } catch (CoreException e) {
+ // Should have already been reported when creating the target platform
}
}
- return fCachedLocations.get(path);
+ return null;
}
public static void checkPluginPropertiesConsistency(Map<?, ?> map, File configDir) {
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java
index e4adf9b..9c990d9 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java
@@ -42,6 +42,7 @@ public class BundleErrorReporter extends JarManifestErrorReporter {
super(file);
}
+ @Override
public void validateContent(IProgressMonitor monitor) {
super.validateContent(monitor);
if (fHeaders == null || getErrorCount() > 0)
@@ -249,7 +250,7 @@ public class BundleErrorReporter extends JarManifestErrorReporter {
if (elems.length > 0) {
if (!VersionUtil.validateVersionRange(elems[0].getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE)).isOK()) {
int line = getLine(header, header.getValue());
- report(PDECoreMessages.BundleErrorReporter_InvalidFormatInBundleVersion, line, CompilerFlags.ERROR, PDEMarkerFactory.CAT_FATAL);
+ report(UtilMessages.BundleErrorReporter_InvalidFormatInBundleVersion, line, CompilerFlags.ERROR, PDEMarkerFactory.CAT_FATAL);
}
}
return;
@@ -602,7 +603,7 @@ public class BundleErrorReporter extends JarManifestErrorReporter {
}
if (versionRange != null && !VersionUtil.validateVersionRange(versionRange).isOK()) {
- report(NLS.bind(PDECoreMessages.BundleErrorReporter_InvalidFormatInBundleVersion, element.getValue()), getPackageLine(header, element), CompilerFlags.ERROR, PDEMarkerFactory.CAT_FATAL);
+ report(NLS.bind(UtilMessages.BundleErrorReporter_InvalidFormatInBundleVersion, element.getValue()), getPackageLine(header, element), CompilerFlags.ERROR, PDEMarkerFactory.CAT_FATAL);
}
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundleModel.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundleModel.java
index 6962da1..6a31f9f 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundleModel.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundleModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -123,4 +123,16 @@ public abstract class BundleModel extends AbstractModel implements IBundleModel
load(source, outOfSync);
fireModelChanged(new ModelChangedEvent(this, IModelChangedEvent.WORLD_CHANGED, new Object[0], null));
}
+
+ @Override
+ public String toString() {
+ if (fBundle != null) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(fBundle.getHeader(Constants.BUNDLE_SYMBOLICNAME));
+ buf.append(" ("); //$NON-NLS-1$
+ buf.append(fBundle.getHeader(Constants.BUNDLE_VERSION));
+ buf.append(')');
+ }
+ return "Unknown bundle model"; //$NON-NLS-1$
+ }
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundlePluginBase.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundlePluginBase.java
index 3991deb..921ee74 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundlePluginBase.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundlePluginBase.java
@@ -337,7 +337,7 @@ public class BundlePluginBase extends PlatformObject implements IBundlePluginBas
imports.add(importElement);
importElement.load(required[i]);
}
- BundleDescription[] imported = PDEStateHelper.getImportedBundles(description);
+ BundleDescription[] imported = PluginBase.getImportedBundles(description);
for (int i = 0; i < imported.length; i++) {
PluginImport importElement = new PluginImport();
importElement.setModel(getModel());
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel.java
index f824be4..968ffd9 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -19,12 +19,15 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.pde.core.IEditableModel;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.internal.core.PDECore;
-import org.eclipse.pde.internal.core.converter.PluginConverter;
import org.eclipse.pde.internal.core.ibundle.IBundle;
import org.eclipse.pde.internal.core.ibundle.IBundleModelFactory;
import org.eclipse.pde.internal.core.text.bundle.BundleModelFactory;
import org.eclipse.pde.internal.core.util.CoreUtility;
+import org.eclipse.pde.internal.core.util.ManifestUtils;
+/**
+ * Represents a bundle in a project in the workspace.
+ */
public class WorkspaceBundleModel extends BundleModel implements IEditableModel {
private static final long serialVersionUID = 1L;
@@ -36,12 +39,11 @@ public class WorkspaceBundleModel extends BundleModel implements IEditableModel
private IBundleModelFactory fFactory;
- private static final String MANIFEST_VERSION = "Manifest-Version"; //$NON-NLS-1$
-
public WorkspaceBundleModel(IFile file) {
fUnderlyingResource = file;
}
+ @Override
public void fireModelChanged(IModelChangedEvent event) {
setDirty(event.getChangeType() != IModelChangedEvent.WORLD_CHANGED);
super.fireModelChanged(event);
@@ -60,10 +62,12 @@ public class WorkspaceBundleModel extends BundleModel implements IEditableModel
return swriter.toString();
}
+ @Override
public IResource getUnderlyingResource() {
return fUnderlyingResource;
}
+ @Override
public String getInstallLocation() {
// Ensure we have an underlying resource
if (fUnderlyingResource == null) {
@@ -83,6 +87,7 @@ public class WorkspaceBundleModel extends BundleModel implements IEditableModel
return fEditable;
}
+ @Override
public void load() {
if (fUnderlyingResource == null)
return;
@@ -115,6 +120,7 @@ public class WorkspaceBundleModel extends BundleModel implements IEditableModel
return isInSync(fUnderlyingResource.getLocation().toFile());
}
+ @Override
protected void updateTimeStamp() {
// If we have no underlying resource, it probably got deleted from right
// underneath us; thus, there is nothing to update the time stamp for
@@ -158,19 +164,16 @@ public class WorkspaceBundleModel extends BundleModel implements IEditableModel
}
}
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.core.IEditable#save(java.io.PrintWriter)
+ */
public void save(PrintWriter writer) {
IBundle bundle = getBundle();
Map<String, String> headers = ((Bundle) bundle).getHeaders();
- boolean addManifestVersion = headers.get(MANIFEST_VERSION) == null;
- if (addManifestVersion)
- headers.put(MANIFEST_VERSION, "1.0"); //$NON-NLS-1$
try {
- PluginConverter.getDefault().writeManifest(headers, writer);
+ ManifestUtils.writeManifest(headers, writer);
} catch (IOException e) {
PDECore.logException(e);
- } finally {
- if (addManifestVersion)
- headers.remove(MANIFEST_VERSION);
}
fDirty = false;
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/IModel.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/IModel.java
deleted file mode 100644
index 013219f..0000000
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/IModel.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 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.converter;
-
-/**
- * Internal class copied from org.eclipse.osgi. Referenced in PluginConverter and PluginConverterParser
- */
-public interface IModel {
-
- public static final String FRAGMENT = "fragment"; //$NON-NLS-1$
- public static final String FRAGMENT_ID = "id"; //$NON-NLS-1$
- public static final String FRAGMENT_NAME = "name"; //$NON-NLS-1$
- public static final String FRAGMENT_PROVIDER = "provider-name"; //$NON-NLS-1$
- public static final String FRAGMENT_VERSION = "version"; //$NON-NLS-1$
- public static final String FRAGMENT_PLUGIN_ID = "plugin-id"; //$NON-NLS-1$
- public static final String FRAGMENT_PLUGIN_VERSION = "plugin-version"; //$NON-NLS-1$
- public static final String FRAGMENT_PLUGIN_MATCH = "match"; //$NON-NLS-1$
-
- public static final String PLUGIN = "plugin"; //$NON-NLS-1$
- public static final String PLUGIN_ID = "id"; //$NON-NLS-1$
- public static final String PLUGIN_NAME = "name"; //$NON-NLS-1$
- public static final String PLUGIN_VENDOR = "vendor-name"; //$NON-NLS-1$
- public static final String PLUGIN_PROVIDER = "provider-name"; //$NON-NLS-1$
- public static final String PLUGIN_VERSION = "version"; //$NON-NLS-1$
- public static final String PLUGIN_CLASS = "class"; //$NON-NLS-1$
-
- public static final String RUNTIME = "runtime"; //$NON-NLS-1$
- public static final String PLUGIN_REQUIRES = "requires"; //$NON-NLS-1$
-
- public static final String EXTENSION_POINT = "extension-point"; //$NON-NLS-1$
- public static final String EXTENSION = "extension"; //$NON-NLS-1$
-
- public static final String LIBRARY = "library"; //$NON-NLS-1$
- public static final String LIBRARY_NAME = "name"; //$NON-NLS-1$
- public static final String LIBRARY_EXPORT_MASK = "name"; //$NON-NLS-1$
- public static final String LIBRARY_PACKAGES = "packages"; //$NON-NLS-1$
- public static final String LIBRARY_EXPORT = "export"; //$NON-NLS-1$
-
- public static final String PLUGIN_REQUIRES_PLUGIN = "plugin"; //$NON-NLS-1$
- public static final String PLUGIN_REQUIRES_IMPORT = "import"; //$NON-NLS-1$
- public static final String PLUGIN_REQUIRES_EXPORT = "export"; //$NON-NLS-1$
- public static final String PLUGIN_REQUIRES_MATCH = "match"; //$NON-NLS-1$
- public static final String PLUGIN_REQUIRES_PLUGIN_VERSION = "version"; //$NON-NLS-1$
- public static final String PLUGIN_REQUIRES_OPTIONAL = "optional"; //$NON-NLS-1$
-
- public static final String PLUGIN_REQUIRES_MATCH_PERFECT = "perfect"; //$NON-NLS-1$ // Brian
- public static final String PLUGIN_REQUIRES_MATCH_EQUIVALENT = "equivalent"; //$NON-NLS-1$ // Brian
- public static final String PLUGIN_REQUIRES_MATCH_COMPATIBLE = "compatible"; //$NON-NLS-1$ // Brian
- public static final String PLUGIN_REQUIRES_MATCH_GREATER_OR_EQUAL = "greaterOrEqual"; //$NON-NLS-1$ // Brian
-}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/PDEPluginConverter.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/PDEPluginConverter.java
deleted file mode 100644
index 3df8567..0000000
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/PDEPluginConverter.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2012 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.converter;
-
-import java.io.*;
-import java.util.*;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.osgi.service.pluginconversion.PluginConversionException;
-import org.eclipse.osgi.util.ManifestElement;
-import org.eclipse.pde.internal.core.project.PDEProject;
-import org.osgi.framework.BundleException;
-
-public class PDEPluginConverter {
-
- public static void convertToOSGIFormat(IProject project, String target, Dictionary<?, ?> dictionary, IProgressMonitor monitor) throws CoreException {
- convertToOSGIFormat(project, target, dictionary, null, monitor);
- }
-
- public static void convertToOSGIFormat(IProject project, String target, Dictionary<?, ?> dictionary, Map<String, String> newProps, IProgressMonitor monitor) throws CoreException {
- try {
- File outputFile = new File(PDEProject.getManifest(project).getLocation().toOSString());
- File inputFile = new File(project.getLocation().toOSString());
- PluginConverter converter = PluginConverter.getDefault();
- converter.convertManifest(inputFile, outputFile, false, target, true, dictionary);
-
- if (newProps != null && newProps.size() > 0)
- converter.writeManifest(outputFile, getProperties(outputFile, newProps), false);
-
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (PluginConversionException e) {
- } finally {
- monitor.done();
- }
- }
-
- private static Map<String, String> getProperties(File file, Map<String, String> newProps) {
- try {
- Map<String, String> prop = ManifestElement.parseBundleManifest(new FileInputStream(file), null);
- if (newProps != null && newProps.size() > 0) {
- Iterator<String> iter = newProps.keySet().iterator();
- while (iter.hasNext()) {
- String key = iter.next().toString();
- prop.put(key, newProps.get(key));
- }
- }
- return prop;
- } catch (FileNotFoundException e) {
- } catch (BundleException e) {
- } catch (IOException e) {
- }
- return Collections.emptyMap();
- }
-
-}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/PluginConverter.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/PluginConverter.java
deleted file mode 100644
index 6230085..0000000
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/PluginConverter.java
+++ /dev/null
@@ -1,617 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2012 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.converter;
-
-import java.io.*;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.*;
-import org.eclipse.core.resources.*;
-import org.eclipse.jdt.core.*;
-import org.eclipse.osgi.service.pluginconversion.PluginConversionException;
-import org.eclipse.osgi.service.resolver.VersionRange;
-import org.eclipse.osgi.util.ManifestElement;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.pde.core.build.IBuild;
-import org.eclipse.pde.core.build.IBuildEntry;
-import org.eclipse.pde.internal.core.*;
-import org.eclipse.pde.internal.core.build.Build;
-import org.eclipse.pde.internal.core.build.WorkspaceBuildModel;
-import org.eclipse.pde.internal.core.converter.PluginConverterParser.PluginInfo;
-import org.eclipse.pde.internal.core.project.PDEProject;
-import org.osgi.framework.*;
-
-public class PluginConverter {
- public static boolean DEBUG = false;
- /** bundle manifest type unknown */
- static public final byte MANIFEST_TYPE_UNKNOWN = 0x00;
- /** bundle manifest type bundle (META-INF/MANIFEST.MF) */
- static public final byte MANIFEST_TYPE_BUNDLE = 0x01;
- /** bundle manifest type plugin (plugin.xml) */
- static public final byte MANIFEST_TYPE_PLUGIN = 0x02;
- /** bundle manifest type fragment (fragment.xml) */
- static public final byte MANIFEST_TYPE_FRAGMENT = 0x04;
- /** bundle manifest type jared bundle */
- static public final byte MANIFEST_TYPE_JAR = 0x08;
-
- private static final String SEMICOLON = "; "; //$NON-NLS-1$
- private static final String UTF_8 = "UTF-8"; //$NON-NLS-1$
- public static final String LIST_SEPARATOR = ",\n "; //$NON-NLS-1$
- public static final String LINE_SEPARATOR = "\n "; //$NON-NLS-1$
- private static int MAXLINE = 511;
- private BundleContext context;
- private PluginInfo pluginInfo;
- private File pluginManifestLocation;
- private Dictionary<String, String> generatedManifest;
- private byte manifestType;
- private Version target;
- static final Version TARGET31 = new Version(3, 1, 0);
- static final Version TARGET32 = new Version(3, 2, 0);
- static final Version TARGET34 = new Version(3, 4, 0);
- private static final String MANIFEST_VERSION = "Manifest-Version"; //$NON-NLS-1$
- private static final String PLUGIN_PROPERTIES_FILENAME = "plugin"; //$NON-NLS-1$
- private static PluginConverter instance;
- static public final String GENERATED_FROM = "Generated-from"; //$NON-NLS-1$
- static public final String MANIFEST_TYPE_ATTRIBUTE = "type"; //$NON-NLS-1$
- protected static final String PI_BOOT = "org.eclipse.core.boot"; //$NON-NLS-1$
- protected static final String PI_RUNTIME_COMPATIBILITY = "org.eclipse.core.runtime.compatibility"; //$NON-NLS-1$
- private static final String COMPATIBILITY_ACTIVATOR = "org.eclipse.core.internal.compatibility.PluginActivator"; //$NON-NLS-1$
- private static final String SOURCE_PREFIX = "source."; //$NON-NLS-1$
-
- public static PluginConverter getDefault() {
- if (instance == null)
- instance = new PluginConverter(PDECore.getDefault().getBundleContext());
- return instance;
- }
-
- public PluginConverter(BundleContext context) {
- this.context = context;
- instance = this;
- }
-
- private void init() {
- // need to make sure these fields are cleared out for each conversion.
- pluginInfo = null;
- pluginManifestLocation = null;
- generatedManifest = new Hashtable<String, String>(10);
- manifestType = MANIFEST_TYPE_UNKNOWN;
- target = null;
- }
-
- private void fillPluginInfo(File pluginBaseLocation) throws PluginConversionException {
- pluginManifestLocation = pluginBaseLocation;
- if (pluginManifestLocation == null)
- throw new IllegalArgumentException();
- URL pluginFile = findPluginManifest(pluginBaseLocation);
- if (pluginFile == null) {
- throw new PluginConversionException(NLS.bind(PDECoreMessages.PluginConverter_EclipseConverterFileNotFound, pluginBaseLocation.getAbsolutePath()));
- }
- pluginInfo = parsePluginInfo(pluginFile);
- String validation = pluginInfo.validateForm();
- if (validation != null)
- throw new PluginConversionException(validation);
- }
-
- private URL findPluginManifest(File baseLocation) {
- //Here, we can not use the bundlefile because it may explode the jar and returns a location from which we will not be able to derive the jars location
- URL xmlFileLocation;
- InputStream stream = null;
- URL baseURL = null;
- try {
- if (!baseLocation.isDirectory()) {
- baseURL = new URL("jar:file:" + baseLocation.toString() + "!/"); //$NON-NLS-1$ //$NON-NLS-2$
- manifestType |= MANIFEST_TYPE_JAR;
- } else {
- baseURL = baseLocation.toURL();
- }
- } catch (MalformedURLException e1) {
- //this can't happen since we are building the urls ourselves from a file
- }
- try {
- xmlFileLocation = new URL(baseURL, ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR);
- stream = xmlFileLocation.openStream();
- manifestType |= MANIFEST_TYPE_PLUGIN;
- return xmlFileLocation;
- } catch (MalformedURLException e) {
- return null;
- } catch (IOException ioe) {
- //ignore
- } finally {
- try {
- if (stream != null)
- stream.close();
- } catch (IOException e) {
- //ignore
- }
- }
- try {
- xmlFileLocation = new URL(baseURL, ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR);
- stream = xmlFileLocation.openStream();
- manifestType |= MANIFEST_TYPE_FRAGMENT;
- return xmlFileLocation;
- } catch (MalformedURLException e) {
- return null;
- } catch (IOException ioe) {
- // Ignore
- } finally {
- try {
- if (stream != null)
- stream.close();
- } catch (IOException e) {
- //ignore
- }
- }
- return null;
- }
-
- protected void fillManifest(boolean compatibilityManifest, boolean analyseJars) {
- generateManifestVersion();
- generateHeaders();
- generateClasspath();
- generateActivator();
- generatePluginClass();
- if (analyseJars)
- generateProvidePackage();
- generateRequireBundle();
- generateLocalizationEntry();
- generateEclipseHeaders();
- if (compatibilityManifest) {
- generateTimestamp();
- }
- }
-
- public void writeManifest(File generationLocation, Map<?, ?> manifestToWrite, boolean compatibilityManifest) throws PluginConversionException {
- long start = System.currentTimeMillis();
- BufferedWriter out = null;
- try {
- File parentFile = new File(generationLocation.getParent());
- parentFile.mkdirs();
- generationLocation.createNewFile();
- if (!generationLocation.isFile()) {
- String message = NLS.bind(PDECoreMessages.PluginConverter_EclipseConverterErrorCreatingBundleManifest, this.pluginInfo.getUniqueId(), generationLocation);
- throw new PluginConversionException(message);
- }
- // MANIFEST.MF files must be written using UTF-8
- out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(generationLocation), UTF_8));
- writeManifest(manifestToWrite, out);
- } catch (IOException e) {
- String message = NLS.bind(PDECoreMessages.PluginConverter_EclipseConverterErrorCreatingBundleManifest, this.pluginInfo.getUniqueId(), generationLocation);
- throw new PluginConversionException(message, e);
- } finally {
- if (out != null)
- try {
- out.close();
- } catch (IOException e) {
- // only report problems writing to/flushing the file
- }
- }
- if (DEBUG)
- System.out.println("Time to write out converted manifest to: " + generationLocation + ": " + (System.currentTimeMillis() - start) + "ms."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void writeManifest(Map<?, ?> manifestToWrite, Writer out) throws IOException {
- // replaces any eventual existing file
- manifestToWrite = new Hashtable<Object, Object>(manifestToWrite);
-
- writeEntry(out, MANIFEST_VERSION, (String) manifestToWrite.remove(MANIFEST_VERSION));
- writeEntry(out, GENERATED_FROM, (String) manifestToWrite.remove(GENERATED_FROM)); //Need to do this first uptoDate check expect the generated-from tag to be in the first line
- // always attempt to write the Bundle-ManifestVersion header if it exists (bug 109863)
- writeEntry(out, Constants.BUNDLE_MANIFESTVERSION, (String) manifestToWrite.remove(Constants.BUNDLE_MANIFESTVERSION));
- writeEntry(out, Constants.BUNDLE_NAME, (String) manifestToWrite.remove(Constants.BUNDLE_NAME));
- writeEntry(out, Constants.BUNDLE_SYMBOLICNAME, (String) manifestToWrite.remove(Constants.BUNDLE_SYMBOLICNAME));
- writeEntry(out, Constants.BUNDLE_VERSION, (String) manifestToWrite.remove(Constants.BUNDLE_VERSION));
- writeEntry(out, Constants.BUNDLE_CLASSPATH, (String) manifestToWrite.remove(Constants.BUNDLE_CLASSPATH));
- writeEntry(out, Constants.BUNDLE_ACTIVATOR, (String) manifestToWrite.remove(Constants.BUNDLE_ACTIVATOR));
- writeEntry(out, Constants.BUNDLE_VENDOR, (String) manifestToWrite.remove(Constants.BUNDLE_VENDOR));
- writeEntry(out, Constants.FRAGMENT_HOST, (String) manifestToWrite.remove(Constants.FRAGMENT_HOST));
- writeEntry(out, Constants.BUNDLE_LOCALIZATION, (String) manifestToWrite.remove(Constants.BUNDLE_LOCALIZATION));
- // always attempt to write the Export-Package header if it exists (bug 109863)
- writeEntry(out, Constants.EXPORT_PACKAGE, (String) manifestToWrite.remove(Constants.EXPORT_PACKAGE));
- // always attempt to write the Provide-Package header if it exists (bug 109863)
- writeEntry(out, ICoreConstants.PROVIDE_PACKAGE, (String) manifestToWrite.remove(ICoreConstants.PROVIDE_PACKAGE));
- writeEntry(out, Constants.REQUIRE_BUNDLE, (String) manifestToWrite.remove(Constants.REQUIRE_BUNDLE));
- Iterator<?> keys = manifestToWrite.keySet().iterator();
- // TODO makes sure the update works from Dictionary
- while (keys.hasNext()) {
- String key = (String) keys.next();
- writeEntry(out, key, (String) manifestToWrite.get(key));
- }
- out.flush();
- }
-
- private void generateLocalizationEntry() {
- generatedManifest.put(Constants.BUNDLE_LOCALIZATION, PLUGIN_PROPERTIES_FILENAME);
- }
-
- private void generateManifestVersion() {
- generatedManifest.put(MANIFEST_VERSION, "1.0"); //$NON-NLS-1$
- }
-
- private boolean requireRuntimeCompatibility() {
- ArrayList<?> requireList = pluginInfo.getRequires();
- for (Iterator<?> iter = requireList.iterator(); iter.hasNext();) {
- if (((PluginConverterParser.Prerequisite) iter.next()).getName().equalsIgnoreCase(PI_RUNTIME_COMPATIBILITY))
- return true;
- }
- return false;
- }
-
- private void generateActivator() {
- if (!pluginInfo.isFragment())
- if (!requireRuntimeCompatibility()) {
- String pluginClass = pluginInfo.getPluginClass();
- if (pluginClass != null && !pluginClass.trim().equals("")) //$NON-NLS-1$
- generatedManifest.put(Constants.BUNDLE_ACTIVATOR, pluginClass);
- } else {
- generatedManifest.put(Constants.BUNDLE_ACTIVATOR, COMPATIBILITY_ACTIVATOR);
- }
- }
-
- private void generateClasspath() {
- String[] classpath = pluginInfo.getLibrariesName();
- if (classpath.length != 0)
- generatedManifest.put(Constants.BUNDLE_CLASSPATH, getStringFromArray(classpath, LIST_SEPARATOR));
- }
-
- private void generateHeaders() {
- if (TARGET31.compareTo(target) <= 0)
- generatedManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$
- generatedManifest.put(Constants.BUNDLE_NAME, pluginInfo.getPluginName());
- generatedManifest.put(Constants.BUNDLE_VERSION, pluginInfo.getVersion());
- generatedManifest.put(Constants.BUNDLE_SYMBOLICNAME, getSymbolicNameEntry());
- String provider = pluginInfo.getProviderName();
- if (provider != null)
- generatedManifest.put(Constants.BUNDLE_VENDOR, provider);
- if (pluginInfo.isFragment()) {
- StringBuffer hostBundle = new StringBuffer();
- hostBundle.append(pluginInfo.getMasterId());
- String versionRange = getVersionRange(pluginInfo.getMasterVersion(), pluginInfo.getMasterMatch()); // TODO need to get match rule here!
- if (versionRange != null)
- hostBundle.append(versionRange);
- generatedManifest.put(Constants.FRAGMENT_HOST, hostBundle.toString());
- }
- }
-
- /*
- * Generates an entry in the form:
- * <symbolic-name>[; singleton=true]
- */
- private String getSymbolicNameEntry() {
- // false is the default, so don't bother adding anything
- if (!pluginInfo.isSingleton())
- return pluginInfo.getUniqueId();
- StringBuffer result = new StringBuffer(pluginInfo.getUniqueId());
- result.append(SEMICOLON);
- result.append(Constants.SINGLETON_DIRECTIVE);
- String assignment = TARGET31.compareTo(target) <= 0 ? ":=" : "="; //$NON-NLS-1$ //$NON-NLS-2$
- result.append(assignment).append("true"); //$NON-NLS-1$
- return result.toString();
- }
-
- private void generatePluginClass() {
- if (requireRuntimeCompatibility()) {
- String pluginClass = pluginInfo.getPluginClass();
- if (pluginClass != null)
- generatedManifest.put(ICoreConstants.PLUGIN_CLASS, pluginClass);
- }
- }
-
- private void generateProvidePackage() {
- Collection<String> exports = getExports();
- if (exports != null && exports.size() != 0) {
- generatedManifest.put(TARGET31.compareTo(target) <= 0 ? Constants.EXPORT_PACKAGE : ICoreConstants.PROVIDE_PACKAGE, getStringFromCollection(exports, LIST_SEPARATOR));
- }
- }
-
- private void generateRequireBundle() {
- ArrayList<?> requiredBundles = pluginInfo.getRequires();
- if (requiredBundles.size() == 0)
- return;
- StringBuffer bundleRequire = new StringBuffer();
- for (Iterator<?> iter = requiredBundles.iterator(); iter.hasNext();) {
- PluginConverterParser.Prerequisite element = (PluginConverterParser.Prerequisite) iter.next();
- StringBuffer modImport = new StringBuffer(element.getName());
- String versionRange = getVersionRange(element.getVersion(), element.getMatch());
- if (versionRange != null)
- modImport.append(versionRange);
- if (element.isExported()) {
- if (TARGET31.compareTo(target) <= 0)
- modImport.append(';').append(Constants.VISIBILITY_DIRECTIVE).append(":=").append(Constants.VISIBILITY_REEXPORT);//$NON-NLS-1$
- else
- modImport.append(';').append(ICoreConstants.REPROVIDE_ATTRIBUTE).append("=true");//$NON-NLS-1$
- }
- if (element.isOptional()) {
- if (TARGET31.compareTo(target) <= 0)
- modImport.append(';').append(Constants.RESOLUTION_DIRECTIVE).append(":=").append(Constants.RESOLUTION_OPTIONAL);//$NON-NLS-1$
- else
- modImport.append(';').append(ICoreConstants.OPTIONAL_ATTRIBUTE).append("=true");//$NON-NLS-1$
- }
- bundleRequire.append(modImport.toString());
- if (iter.hasNext())
- bundleRequire.append(LIST_SEPARATOR);
- }
- generatedManifest.put(Constants.REQUIRE_BUNDLE, bundleRequire.toString());
- }
-
- private void generateTimestamp() {
- // so it is easy to tell which ones are generated
- generatedManifest.put(GENERATED_FROM, Long.toString(getTimeStamp(pluginManifestLocation, manifestType)) + ";" + MANIFEST_TYPE_ATTRIBUTE + "=" + manifestType); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- private void generateEclipseHeaders() {
- if (pluginInfo.isFragment())
- return;
-
- String pluginClass = pluginInfo.getPluginClass();
- if (pluginInfo.hasExtensionExtensionPoints() || (pluginClass != null && !pluginClass.trim().equals(""))) { //$NON-NLS-1$
- if (TARGET34.compareTo(target) <= 0)
- generatedManifest.put(Constants.BUNDLE_ACTIVATIONPOLICY, Constants.ACTIVATION_LAZY);
- else
- generatedManifest.put(TARGET32.compareTo(target) <= 0 ? ICoreConstants.ECLIPSE_LAZYSTART : ICoreConstants.ECLIPSE_AUTOSTART, "true"); //$NON-NLS-1$
- }
- }
-
- private Set<String> getExports() {
- Map<?, ?> libs = pluginInfo.getLibraries();
- if (libs == null)
- return null;
-
- String projName = pluginManifestLocation.getName();
- IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(projName);
- if (proj == null)
- return null;
-
- return getExports(proj, libs);
- }
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- public Set<String> getExports(IProject proj, Map libs) {
- IFile buildProperties = PDEProject.getBuildProperties(proj);
- IBuild build = null;
- if (buildProperties != null) {
- WorkspaceBuildModel buildModel = new WorkspaceBuildModel(buildProperties);
- build = buildModel.getBuild();
- } else
- build = new Build();
- return findPackages(proj, libs, build);
- }
-
- private Set<String> findPackages(IProject proj, Map<?, List<?>> libs, IBuild build) {
- TreeSet<String> result = new TreeSet<String>();
- IJavaProject jp = JavaCore.create(proj);
- Iterator<?> it = libs.entrySet().iterator();
- while (it.hasNext()) {
- @SuppressWarnings("rawtypes")
- Map.Entry entry = (Map.Entry) it.next();
- String libName = entry.getKey().toString();
- List<?> filter = (List<?>) entry.getValue();
- IBuildEntry libEntry = build.getEntry(SOURCE_PREFIX + libName);
- if (libEntry != null) {
- String[] tokens = libEntry.getTokens();
- for (int i = 0; i < tokens.length; i++) {
- IResource folder = null;
- if (tokens[i].equals(".")) //$NON-NLS-1$
- folder = proj;
- else
- folder = proj.getFolder(tokens[i]);
- if (folder != null)
- addPackagesFromFragRoot(jp.getPackageFragmentRoot(folder), result, filter);
- }
- } else {
- IResource res = proj.findMember(libName);
- if (res != null)
- addPackagesFromFragRoot(jp.getPackageFragmentRoot(res), result, filter);
- }
- }
- return result;
- }
-
- private void addPackagesFromFragRoot(IPackageFragmentRoot root, Collection<String> result, List<?> filter) {
- if (root == null)
- return;
- try {
- if (filter != null && !filter.contains("*")) { //$NON-NLS-1$
- ListIterator<?> li = filter.listIterator();
- while (li.hasNext()) {
- String pkgName = li.next().toString();
- if (pkgName.endsWith(".*")) //$NON-NLS-1$
- pkgName = pkgName.substring(0, pkgName.length() - 2);
-
- IPackageFragment frag = root.getPackageFragment(pkgName);
- if (frag != null)
- result.add(pkgName);
- }
- return;
- }
- IJavaElement[] children = root.getChildren();
- for (int j = 0; j < children.length; j++) {
- IPackageFragment fragment = (IPackageFragment) children[j];
- String name = fragment.getElementName();
- if (fragment.hasChildren() && !result.contains(name)) {
- result.add(name);
- }
- }
- } catch (JavaModelException e) {
- }
- }
-
- /**
- * Parses the plugin manifest to find out: - the plug-in unique identifier -
- * the plug-in version - runtime/libraries entries - the plug-in class -
- * the master plugin (for a fragment)
- */
- private PluginInfo parsePluginInfo(URL pluginLocation) throws PluginConversionException {
- InputStream input = null;
- try {
- input = new BufferedInputStream(pluginLocation.openStream());
- return new PluginConverterParser(context, target).parsePlugin(input);
- } catch (Exception e) {
- String message = NLS.bind(PDECoreMessages.PluginConverter_EclipseConverterErrorParsingPluginManifest, pluginManifestLocation);
- throw new PluginConversionException(message, e);
- } finally {
- if (input != null)
- try {
- input.close();
- } catch (IOException e) {
- //ignore exception
- }
- }
- }
-
- public static boolean upToDate(File generationLocation, File pluginLocation, byte manifestType) {
- if (!generationLocation.isFile())
- return false;
- String secondLine = null;
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new InputStreamReader(new FileInputStream(generationLocation)));
- reader.readLine();
- secondLine = reader.readLine();
- } catch (IOException e) {
- // not a big deal - we could not read an existing manifest
- return false;
- } finally {
- if (reader != null)
- try {
- reader.close();
- } catch (IOException e) {
- // ignore
- }
- }
- String tag = GENERATED_FROM + ": "; //$NON-NLS-1$
- if (secondLine == null || !secondLine.startsWith(tag))
- return false;
-
- secondLine = secondLine.substring(tag.length());
- ManifestElement generatedFrom;
- try {
- generatedFrom = ManifestElement.parseHeader(PluginConverter.GENERATED_FROM, secondLine)[0];
- } catch (BundleException be) {
- return false;
- }
- String timestampStr = generatedFrom.getValue();
- try {
- return Long.parseLong(timestampStr.trim()) == getTimeStamp(pluginLocation, manifestType);
- } catch (NumberFormatException nfe) {
- // not a big deal - just a bogus existing manifest that will be ignored
- }
- return false;
- }
-
- public static long getTimeStamp(File pluginLocation, byte manifestType) {
- if ((manifestType & MANIFEST_TYPE_JAR) != 0)
- return pluginLocation.lastModified();
- else if ((manifestType & MANIFEST_TYPE_PLUGIN) != 0)
- return new File(pluginLocation, ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR).lastModified();
- else if ((manifestType & MANIFEST_TYPE_FRAGMENT) != 0)
- return new File(pluginLocation, ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR).lastModified();
- else if ((manifestType & MANIFEST_TYPE_BUNDLE) != 0)
- return new File(pluginLocation, ICoreConstants.BUNDLE_FILENAME_DESCRIPTOR).lastModified();
- return -1;
- }
-
- private void writeEntry(Writer out, String key, String value) throws IOException {
- if (value != null && value.length() > 0) {
- out.write(splitOnComma(key + ": " + value)); //$NON-NLS-1$
- out.write('\n');
- }
- }
-
- private String splitOnComma(String value) {
- if (value.length() < MAXLINE || value.indexOf(LINE_SEPARATOR) >= 0)
- return value; // assume the line is already split
- String[] values = ManifestElement.getArrayFromList(value);
- if (values == null || values.length == 0)
- return value;
- StringBuffer sb = new StringBuffer(value.length() + ((values.length - 1) * LIST_SEPARATOR.length()));
- for (int i = 0; i < values.length - 1; i++)
- sb.append(values[i]).append(LIST_SEPARATOR);
- sb.append(values[values.length - 1]);
- return sb.toString();
- }
-
- private String getStringFromArray(String[] values, String separator) {
- if (values == null)
- return ""; //$NON-NLS-1$
- StringBuffer result = new StringBuffer();
- for (int i = 0; i < values.length; i++) {
- if (i > 0)
- result.append(separator);
- result.append(values[i]);
- }
- return result.toString();
- }
-
- private String getStringFromCollection(Collection<String> collection, String separator) {
- StringBuffer result = new StringBuffer();
- boolean first = true;
- for (Iterator<String> i = collection.iterator(); i.hasNext();) {
- if (first)
- first = false;
- else
- result.append(separator);
- result.append(i.next());
- }
- return result.toString();
- }
-
- public synchronized Dictionary<String, String> convertManifest(File pluginBaseLocation, boolean compatibility, String target, boolean analyseJars, Dictionary<?, ?> devProperties) throws PluginConversionException {
- long start = System.currentTimeMillis();
- if (DEBUG)
- System.out.println("Convert " + pluginBaseLocation); //$NON-NLS-1$
- init();
- this.target = target == null ? TARGET32 : new Version(target);
- fillPluginInfo(pluginBaseLocation);
- fillManifest(compatibility, analyseJars);
- if (DEBUG)
- System.out.println("Time to convert manifest for: " + pluginBaseLocation + ": " + (System.currentTimeMillis() - start) + "ms."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- return generatedManifest;
- }
-
- public synchronized File convertManifest(File pluginBaseLocation, File bundleManifestLocation, boolean compatibilityManifest, String target, boolean analyseJars, Dictionary<?, ?> devProperties) throws PluginConversionException {
- if (bundleManifestLocation == null)
- throw new PluginConversionException(PDECoreMessages.PluginConverter_BundleLocationIsNull);
- convertManifest(pluginBaseLocation, compatibilityManifest, target, analyseJars, devProperties);
- if (upToDate(bundleManifestLocation, pluginManifestLocation, manifestType))
- return bundleManifestLocation;
- writeManifest(bundleManifestLocation, (Map<?, ?>) generatedManifest, compatibilityManifest);
- return bundleManifestLocation;
- }
-
- private String getVersionRange(String reqVersion, String matchRule) {
- if (reqVersion == null)
- return null;
-
- Version minVersion = Version.parseVersion(reqVersion);
- String versionRange;
- if (matchRule != null) {
- if (matchRule.equalsIgnoreCase(IModel.PLUGIN_REQUIRES_MATCH_PERFECT)) {
- versionRange = new VersionRange(minVersion, true, minVersion, true).toString();
- } else if (matchRule.equalsIgnoreCase(IModel.PLUGIN_REQUIRES_MATCH_EQUIVALENT)) {
- versionRange = new VersionRange(minVersion, true, new Version(minVersion.getMajor(), minVersion.getMinor() + 1, 0, ""), false).toString(); //$NON-NLS-1$
- } else if (matchRule.equalsIgnoreCase(IModel.PLUGIN_REQUIRES_MATCH_COMPATIBLE)) {
- versionRange = new VersionRange(minVersion, true, new Version(minVersion.getMajor() + 1, 0, 0, ""), false).toString(); //$NON-NLS-1$
- } else if (matchRule.equalsIgnoreCase(IModel.PLUGIN_REQUIRES_MATCH_GREATER_OR_EQUAL)) {
- // just return the reqVersion here without any version range
- versionRange = reqVersion;
- } else {
- versionRange = new VersionRange(minVersion, true, new Version(minVersion.getMajor() + 1, 0, 0, ""), false).toString(); //$NON-NLS-1$
- }
- } else {
- versionRange = new VersionRange(minVersion, true, new Version(minVersion.getMajor() + 1, 0, 0, ""), false).toString(); //$NON-NLS-1$
- }
-
- StringBuffer result = new StringBuffer();
- result.append(';').append(Constants.BUNDLE_VERSION_ATTRIBUTE).append('=');
- result.append('\"').append(versionRange).append('\"');
- return result.toString();
- }
-}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/PluginConverterParser.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/PluginConverterParser.java
deleted file mode 100644
index 650155a..0000000
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/converter/PluginConverterParser.java
+++ /dev/null
@@ -1,674 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2012 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.converter;
-
-import java.io.InputStream;
-import java.util.*;
-import javax.xml.parsers.SAXParserFactory;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.pde.internal.build.IPDEBuildConstants;
-import org.eclipse.pde.internal.core.PDECoreMessages;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Version;
-import org.osgi.util.tracker.ServiceTracker;
-import org.xml.sax.*;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * Internal class.
- */
-public class PluginConverterParser extends DefaultHandler implements IModel {
- private static ServiceTracker<?, ?> xmlTracker = null;
-
- private PluginInfo manifestInfo = new PluginInfo();
- private BundleContext context;
- private Version target; // The targeted platform for the given manifest
- private static final Version TARGET21 = new Version(2, 1, 0);
-
- public class PluginInfo {
- private String schemaVersion;
- private String pluginId;
- private String version;
- private String vendor;
-
- // an ordered list of library path names.
- private ArrayList<String> libraryPaths;
- // TODO Should get rid of the libraries map and just have a
- // list of library export statements instead. Library paths must
- // preserve order.
- private Map<String, Vector<?>> libraries; //represent the libraries and their export statement
- private ArrayList<Prerequisite> requires;
- private boolean requiresExpanded = false; //indicates if the requires have been processed.
- private boolean compatibilityFound = false; //set to true is the requirement list contain compatilibity
- private String pluginClass;
- private String masterPluginId;
- private String masterVersion;
- private String masterMatch;
- private Set<?> filters;
- private String pluginName;
- private boolean singleton;
- private boolean fragment;
- private final static String TARGET21_STRING = "2.1"; //$NON-NLS-1$
- private boolean hasExtensionExtensionPoints = false;
-
- public boolean isFragment() {
- return fragment;
- }
-
- public String toString() {
- return "plugin-id: " + pluginId + " version: " + version + " libraries: " + libraries + " class:" + pluginClass + " master: " + masterPluginId + " master-version: " + masterVersion + " requires: " + requires + " singleton: " + singleton; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- }
-
- public Map<String, Vector<?>> getLibraries() {
- if (libraries == null)
- return new HashMap<String, Vector<?>>(0);
- return libraries;
- }
-
- public ArrayList<Prerequisite> getRequires() {
- if (!TARGET21.equals(target) && schemaVersion == null && !requiresExpanded) {
- requiresExpanded = true;
- if (requires == null) {
- requires = new ArrayList<Prerequisite>(1);
- requires.add(new Prerequisite(IPDEBuildConstants.BUNDLE_CORE_RUNTIME, TARGET21_STRING, false, false, IModel.PLUGIN_REQUIRES_MATCH_GREATER_OR_EQUAL));
- requires.add(new Prerequisite(PluginConverter.PI_RUNTIME_COMPATIBILITY, null, false, false, null));
- } else {
- //Add elements on the requirement list of ui and help.
- for (int i = 0; i < requires.size(); i++) {
- Prerequisite analyzed = requires.get(i);
- if ("org.eclipse.ui".equals(analyzed.getName())) { //$NON-NLS-1$
- requires.add(i + 1, new Prerequisite("org.eclipse.ui.workbench.texteditor", null, true, analyzed.isExported(), null)); //$NON-NLS-1$
- requires.add(i + 1, new Prerequisite("org.eclipse.jface.text", null, true, analyzed.isExported(), null)); //$NON-NLS-1$
- requires.add(i + 1, new Prerequisite("org.eclipse.ui.editors", null, true, analyzed.isExported(), null)); //$NON-NLS-1$
- requires.add(i + 1, new Prerequisite("org.eclipse.ui.views", null, true, analyzed.isExported(), null)); //$NON-NLS-1$
- requires.add(i + 1, new Prerequisite("org.eclipse.ui.ide", null, true, analyzed.isExported(), null)); //$NON-NLS-1$
- } else if ("org.eclipse.help".equals(analyzed.getName())) { //$NON-NLS-1$
- requires.add(i + 1, new Prerequisite("org.eclipse.help.base", null, true, analyzed.isExported(), null)); //$NON-NLS-1$
- } else if (IPDEBuildConstants.BUNDLE_CORE_RUNTIME.equals(analyzed.getName()) && !compatibilityFound) {
- requires.add(i + 1, new Prerequisite(PluginConverter.PI_RUNTIME_COMPATIBILITY, null, false, analyzed.isExported(), null));
- }
- }
- if (!requires.contains(new Prerequisite(PluginConverter.PI_RUNTIME_COMPATIBILITY, null, false, false, null))) {
- requires.add(new Prerequisite(PluginConverter.PI_RUNTIME_COMPATIBILITY, null, false, false, null));
- }
- //Remove any prereq on runtime and add a prereq on runtime 2.1
- //This is used to recognize the version for which the given plugin was initially targeted.
- Prerequisite runtimePrereq = new Prerequisite(IPDEBuildConstants.BUNDLE_CORE_RUNTIME, null, false, false, null);
- requires.remove(runtimePrereq);
- requires.add(new Prerequisite(IPDEBuildConstants.BUNDLE_CORE_RUNTIME, TARGET21_STRING, false, false, IModel.PLUGIN_REQUIRES_MATCH_GREATER_OR_EQUAL));
- }
- }
- if (requires == null)
- return requires = new ArrayList<Prerequisite>(0);
-
- return requires;
- }
-
- public String getMasterId() {
- return masterPluginId;
- }
-
- public String getMasterVersion() {
- return masterVersion;
- }
-
- public String getMasterMatch() {
- return masterMatch;
- }
-
- public String getPluginClass() {
- return pluginClass;
- }
-
- public String getUniqueId() {
- return pluginId;
- }
-
- public String getVersion() {
- return version;
- }
-
- public Set<?> getPackageFilters() {
- return filters;
- }
-
- public String[] getLibrariesName() {
- if (libraryPaths == null)
- return new String[0];
- return libraryPaths.toArray(new String[libraryPaths.size()]);
- }
-
- public String getPluginName() {
- return pluginName;
- }
-
- public String getProviderName() {
- return vendor;
- }
-
- public boolean isSingleton() {
- return singleton;
- }
-
- public boolean hasExtensionExtensionPoints() {
- return hasExtensionExtensionPoints;
- }
-
- public String getRoot() {
- return isFragment() ? FRAGMENT : PLUGIN;
- }
-
- /*
- * Provides some basic form of validation. Since plugin/fragment is the only mandatory
- * attribute, it is the only one we cara about here.
- */
- public String validateForm() {
- if (this.pluginId == null) {
- return NLS.bind(PDECoreMessages.PluginParser_EclipseConverterMissingAttribute, new String[] {getRoot(), PLUGIN_ID, getRoot()});
- }
- if (this.pluginName == null) {
- return NLS.bind(PDECoreMessages.PluginParser_EclipseConverterMissingAttribute, new String[] {getRoot(), PLUGIN_NAME, getRoot()});
- }
- if (this.version == null) {
- return NLS.bind(PDECoreMessages.PluginParser_EclipseConverterMissingAttribute, new String[] {getRoot(), PLUGIN_VERSION, getRoot()});
- }
- if (isFragment() && this.masterPluginId == null) {
- return NLS.bind(PDECoreMessages.PluginParser_EclipseConverterMissingAttribute, new String[] {getRoot(), FRAGMENT_PLUGIN_ID, getRoot()});
- }
- if (isFragment() && this.masterVersion == null) {
- return NLS.bind(PDECoreMessages.PluginParser_EclipseConverterMissingAttribute, new String[] {getRoot(), FRAGMENT_PLUGIN_VERSION, getRoot()});
- }
- return null;
- }
- }
-
- // Current State Information
- Stack<Integer> stateStack = new Stack<Integer>();
-
- // Current object stack (used to hold the current object we are populating in this plugin info
- Stack<Object> objectStack = new Stack<Object>();
- Locator locator = null;
-
- // Valid States
- private static final int IGNORED_ELEMENT_STATE = 0;
- private static final int INITIAL_STATE = 1;
- private static final int PLUGIN_STATE = 2;
- private static final int PLUGIN_RUNTIME_STATE = 3;
- private static final int PLUGIN_REQUIRES_STATE = 4;
- private static final int PLUGIN_EXTENSION_POINT_STATE = 5;
- private static final int PLUGIN_EXTENSION_STATE = 6;
- private static final int RUNTIME_LIBRARY_STATE = 7;
- private static final int LIBRARY_EXPORT_STATE = 8;
- private static final int PLUGIN_REQUIRES_IMPORT_STATE = 9;
- private static final int FRAGMENT_STATE = 11;
-
- public PluginConverterParser(BundleContext context, Version target) {
- super();
- this.context = context;
- this.target = target;
- }
-
- /**
- * Receive a Locator object for document events.
- *
- * <p>
- * By default, do nothing. Application writers may override this method in
- * a subclass if they wish to store the locator for use with other document
- * events.
- * </p>
- *
- * @param locator A locator for all SAX document events.
- * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
- * @see org.xml.sax.Locator
- */
- public void setDocumentLocator(Locator locator) {
- this.locator = locator;
- }
-
- public void endDocument() {
- }
-
- public void endElement(String uri, String elementName, String qName) {
- switch (stateStack.peek().intValue()) {
- case IGNORED_ELEMENT_STATE :
- stateStack.pop();
- break;
- case INITIAL_STATE :
- // shouldn't get here
- // internalError(Policy.bind("parse.internalStack", elementName)); //$NON-NLS-1$
- break;
- case PLUGIN_STATE :
- case FRAGMENT_STATE :
- break;
- case PLUGIN_RUNTIME_STATE :
- if (elementName.equals(RUNTIME)) {
- stateStack.pop();
- }
- break;
- case PLUGIN_REQUIRES_STATE :
- if (elementName.equals(PLUGIN_REQUIRES)) {
- stateStack.pop();
- objectStack.pop();
- }
- break;
- case PLUGIN_EXTENSION_POINT_STATE :
- if (elementName.equals(EXTENSION_POINT)) {
- stateStack.pop();
- }
- break;
- case PLUGIN_EXTENSION_STATE :
- if (elementName.equals(EXTENSION)) {
- stateStack.pop();
- }
- break;
- case RUNTIME_LIBRARY_STATE :
- if (elementName.equals(LIBRARY)) {
- String curLibrary = (String) objectStack.pop();
- if (!curLibrary.trim().equals("")) { //$NON-NLS-1$
- Vector<?> exportsVector = (Vector<?>) objectStack.pop();
- if (manifestInfo.libraries == null) {
- manifestInfo.libraries = new HashMap<String, Vector<?>>(3);
- manifestInfo.libraryPaths = new ArrayList<String>(3);
- }
- manifestInfo.libraries.put(curLibrary, exportsVector);
- manifestInfo.libraryPaths.add(curLibrary.replace('\\', '/'));
- }
- stateStack.pop();
- }
- break;
- case LIBRARY_EXPORT_STATE :
- if (elementName.equals(LIBRARY_EXPORT)) {
- stateStack.pop();
- }
- break;
- case PLUGIN_REQUIRES_IMPORT_STATE :
- if (elementName.equals(PLUGIN_REQUIRES_IMPORT)) {
- stateStack.pop();
- }
- break;
- }
- }
-
- public void handleExtensionPointState(String elementName, Attributes attributes) {
- // nothing to do for extension-points' children
- stateStack.push(new Integer(IGNORED_ELEMENT_STATE));
- manifestInfo.hasExtensionExtensionPoints = true;
- }
-
- public void handleExtensionState(String elementName, Attributes attributes) {
- // nothing to do for extensions' children
- stateStack.push(new Integer(IGNORED_ELEMENT_STATE));
- manifestInfo.hasExtensionExtensionPoints = true;
- }
-
- public void handleInitialState(String elementName, Attributes attributes) {
- if (elementName.equals(PLUGIN)) {
- stateStack.push(new Integer(PLUGIN_STATE));
- parsePluginAttributes(attributes);
- } else if (elementName.equals(FRAGMENT)) {
- manifestInfo.fragment = true;
- stateStack.push(new Integer(FRAGMENT_STATE));
- parseFragmentAttributes(attributes);
- } else {
- stateStack.push(new Integer(IGNORED_ELEMENT_STATE));
- internalError(elementName);
- }
- }
-
- public void handleLibraryExportState(String elementName, Attributes attributes) {
- // All elements ignored.
- stateStack.push(new Integer(IGNORED_ELEMENT_STATE));
- }
-
- public void handleLibraryState(String elementName, Attributes attributes) {
- if (elementName.equals(LIBRARY_EXPORT)) {
- // Change State
- stateStack.push(new Integer(LIBRARY_EXPORT_STATE));
- // The top element on the stack much be a library element
- String currentLib = (String) objectStack.peek();
- if (attributes == null)
- return;
- String maskValue = attributes.getValue("", LIBRARY_EXPORT_MASK); //$NON-NLS-1$
- // pop off the library - already in currentLib
- objectStack.pop();
- @SuppressWarnings("unchecked")
- Vector<String> exportMask = (Vector<String>) objectStack.peek();
- // push library back on
- objectStack.push(currentLib);
- //Split the export upfront
- if (maskValue != null) {
- StringTokenizer tok = new StringTokenizer(maskValue, ","); //$NON-NLS-1$
- while (tok.hasMoreTokens()) {
- String value = tok.nextToken();
- if (!exportMask.contains(maskValue))
- exportMask.addElement(value.trim());
- }
- }
- return;
- }
- if (elementName.equals(LIBRARY_PACKAGES)) {
- stateStack.push(new Integer(IGNORED_ELEMENT_STATE));
- return;
- }
- stateStack.push(new Integer(IGNORED_ELEMENT_STATE));
- internalError(elementName);
- return;
- }
-
- public void handlePluginState(String elementName, Attributes attributes) {
- if (elementName.equals(RUNTIME)) {
- // We should only have one Runtime element in a plugin or fragment
- Object whatIsIt = objectStack.peek();
- if ((whatIsIt instanceof PluginInfo) && ((PluginInfo) objectStack.peek()).libraries != null) {
- // This is at least the 2nd Runtime element we have hit. Ignore it.
- stateStack.push(new Integer(IGNORED_ELEMENT_STATE));
- return;
- }
- stateStack.push(new Integer(PLUGIN_RUNTIME_STATE));
- // Push a new vector to hold all the library entries objectStack.push(new Vector());
- return;
- }
- if (elementName.equals(PLUGIN_REQUIRES)) {
- stateStack.push(new Integer(PLUGIN_REQUIRES_STATE));
- // Push a new vector to hold all the prerequisites
- objectStack.push(new Vector<Object>());
- parseRequiresAttributes(attributes);
- return;
- }
- if (elementName.equals(EXTENSION_POINT)) {
- // mark the plugin as singleton and ignore all elements under extension (if there are any)
- manifestInfo.singleton = true;
- stateStack.push(new Integer(PLUGIN_EXTENSION_POINT_STATE));
- return;
- }
- if (elementName.equals(EXTENSION)) {
- // mark the plugin as singleton and ignore all elements under extension (if there are any)
- manifestInfo.singleton = true;
- stateStack.push(new Integer(PLUGIN_EXTENSION_STATE));
- return;
- }
- // If we get to this point, the element name is one we don't currently accept.
- // Set the state to indicate that this element will be ignored
- stateStack.push(new Integer(IGNORED_ELEMENT_STATE));
- internalError(elementName);
- }
-
- public void handleRequiresImportState(String elementName, Attributes attributes) {
- // All elements ignored.
- stateStack.push(new Integer(IGNORED_ELEMENT_STATE));
- }
-
- public void handleRequiresState(String elementName, Attributes attributes) {
- if (elementName.equals(PLUGIN_REQUIRES_IMPORT)) {
- parsePluginRequiresImport(attributes);
- return;
- }
- // If we get to this point, the element name is one we don't currently accept.
- // Set the state to indicate that this element will be ignored
- stateStack.push(new Integer(IGNORED_ELEMENT_STATE));
- internalError(elementName);
- }
-
- public void handleRuntimeState(String elementName, Attributes attributes) {
- if (elementName.equals(LIBRARY)) {
- // Change State
- stateStack.push(new Integer(RUNTIME_LIBRARY_STATE));
- // Process library attributes
- parseLibraryAttributes(attributes);
- return;
- }
- // If we get to this point, the element name is one we don't currently accept.
- // Set the state to indicate that this element will be ignored
- stateStack.push(new Integer(IGNORED_ELEMENT_STATE));
- internalError(elementName);
- }
-
- synchronized public PluginInfo parsePlugin(InputStream in) throws Exception {
- SAXParserFactory factory = acquireXMLParsing(context);
- if (factory == null) {
- // commented out to not fill up log
- // PDECore.logErrorMessage("No SAX factory parser has been found.");
- return null;
- }
-
- factory.setNamespaceAware(true);
- factory.setNamespaceAware(true);
- try {
- factory.setFeature("http://xml.org/sax/features/string-interning", true); //$NON-NLS-1$
- } catch (SAXException se) {
- // ignore; we can still operate without string-interning
- }
- factory.setValidating(false);
- factory.newSAXParser().parse(in, this);
- return manifestInfo;
- }
-
- public static SAXParserFactory acquireXMLParsing(BundleContext context) {
- if (xmlTracker == null) {
- xmlTracker = new ServiceTracker<Object, Object>(context, "javax.xml.parsers.SAXParserFactory", null); //$NON-NLS-1$
- xmlTracker.open();
- }
- SAXParserFactory result = (SAXParserFactory) xmlTracker.getService();
- if (result != null)
- return result;
- // backup to using jaxp to create a new instance
- return SAXParserFactory.newInstance();
- }
-
- public static void releaseXMLParsing() {
- if (xmlTracker != null)
- xmlTracker.close();
- }
-
- public void parseFragmentAttributes(Attributes attributes) {
- // process attributes
- objectStack.push(manifestInfo);
- int len = attributes.getLength();
- for (int i = 0; i < len; i++) {
- String attrName = attributes.getLocalName(i);
- String attrValue = attributes.getValue(i).trim();
- if (attrName.equals(FRAGMENT_ID))
- manifestInfo.pluginId = attrValue;
- else if (attrName.equals(FRAGMENT_NAME))
- manifestInfo.pluginName = attrValue;
- else if (attrName.equals(FRAGMENT_VERSION))
- manifestInfo.version = attrValue;
- else if (attrName.equals(FRAGMENT_PROVIDER))
- manifestInfo.vendor = attrValue;
- else if (attrName.equals(FRAGMENT_PLUGIN_ID))
- manifestInfo.masterPluginId = attrValue;
- else if (attrName.equals(FRAGMENT_PLUGIN_VERSION))
- manifestInfo.masterVersion = attrValue;
- else if (attrName.equals(FRAGMENT_PLUGIN_MATCH))
- manifestInfo.masterMatch = attrValue;
- }
- }
-
- public void parseLibraryAttributes(Attributes attributes) {
- // Push a vector to hold the export mask
- objectStack.push(new Vector<Object>());
- String current = attributes.getValue("", LIBRARY_NAME); //$NON-NLS-1$
- objectStack.push(current);
- }
-
- public void parsePluginAttributes(Attributes attributes) {
- // process attributes
- objectStack.push(manifestInfo);
- int len = attributes.getLength();
- for (int i = 0; i < len; i++) {
- String attrName = attributes.getLocalName(i);
- String attrValue = attributes.getValue(i).trim();
- if (attrName.equals(PLUGIN_ID))
- manifestInfo.pluginId = attrValue;
- else if (attrName.equals(PLUGIN_NAME))
- manifestInfo.pluginName = attrValue;
- else if (attrName.equals(PLUGIN_VERSION))
- manifestInfo.version = attrValue;
- else if (attrName.equals(PLUGIN_VENDOR) || (attrName.equals(PLUGIN_PROVIDER)))
- manifestInfo.vendor = attrValue;
- else if (attrName.equals(PLUGIN_CLASS))
- manifestInfo.pluginClass = attrValue;
- }
- }
-
- public class Prerequisite {
- String name;
- String version;
- boolean optional;
- boolean export;
- String match;
-
- public boolean isExported() {
- return export;
- }
-
- public String getMatch() {
- return match;
- }
-
- public String getName() {
- return name;
- }
-
- public boolean isOptional() {
- return optional;
- }
-
- public String getVersion() {
- return version;
- }
-
- public Prerequisite(String preqName, String prereqVersion, boolean isOtional, boolean isExported, String prereqMatch) {
- name = preqName;
- version = prereqVersion;
- optional = isOtional;
- export = isExported;
- match = prereqMatch;
- }
-
- public String toString() {
- return name;
- }
-
- public boolean equals(Object prereq) {
- if (!(prereq instanceof Prerequisite))
- return false;
- return name.equals(((Prerequisite) prereq).name);
- }
- }
-
- public void parsePluginRequiresImport(Attributes attributes) {
- if (manifestInfo.requires == null) {
- manifestInfo.requires = new ArrayList<Prerequisite>();
- // to avoid cycles
- // if (!manifestInfo.pluginId.equals(PluginConverterImpl.PI_RUNTIME)) //$NON-NLS-1$
- // manifestInfo.requires.add(new Prerequisite(PluginConverterImpl.PI_RUNTIME, null, false, false, null)); //$NON-NLS-1$
- }
- // process attributes
- String plugin = attributes.getValue("", PLUGIN_REQUIRES_PLUGIN); //$NON-NLS-1$
- if (plugin == null)
- return;
- if (plugin.equals(PluginConverter.PI_BOOT))
- return;
- if (plugin.equals(PluginConverter.PI_RUNTIME_COMPATIBILITY))
- manifestInfo.compatibilityFound = true;
- String version = attributes.getValue("", PLUGIN_REQUIRES_PLUGIN_VERSION); //$NON-NLS-1$
- String optional = attributes.getValue("", PLUGIN_REQUIRES_OPTIONAL); //$NON-NLS-1$
- String export = attributes.getValue("", PLUGIN_REQUIRES_EXPORT); //$NON-NLS-1$
- String match = attributes.getValue("", PLUGIN_REQUIRES_MATCH); //$NON-NLS-1$
- manifestInfo.requires.add(new Prerequisite(plugin, version, "true".equalsIgnoreCase(optional) ? true : false, "true".equalsIgnoreCase(export) ? true : false, match)); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void parseRequiresAttributes(Attributes attributes) {
- //Nothing to do.
- }
-
- static String replace(String s, String from, String to) {
- String str = s;
- int fromLen = from.length();
- int toLen = to.length();
- int ix = str.indexOf(from);
- while (ix != -1) {
- str = str.substring(0, ix) + to + str.substring(ix + fromLen);
- ix = str.indexOf(from, ix + toLen);
- }
- return str;
- }
-
- public void startDocument() {
- stateStack.push(new Integer(INITIAL_STATE));
- }
-
- public void startElement(String uri, String elementName, String qName, Attributes attributes) {
- switch (stateStack.peek().intValue()) {
- case INITIAL_STATE :
- handleInitialState(elementName, attributes);
- break;
- case FRAGMENT_STATE :
- case PLUGIN_STATE :
- handlePluginState(elementName, attributes);
- break;
- case PLUGIN_RUNTIME_STATE :
- handleRuntimeState(elementName, attributes);
- break;
- case PLUGIN_REQUIRES_STATE :
- handleRequiresState(elementName, attributes);
- break;
- case PLUGIN_EXTENSION_POINT_STATE :
- handleExtensionPointState(elementName, attributes);
- break;
- case PLUGIN_EXTENSION_STATE :
- handleExtensionState(elementName, attributes);
- break;
- case RUNTIME_LIBRARY_STATE :
- handleLibraryState(elementName, attributes);
- break;
- case LIBRARY_EXPORT_STATE :
- handleLibraryExportState(elementName, attributes);
- break;
- case PLUGIN_REQUIRES_IMPORT_STATE :
- handleRequiresImportState(elementName, attributes);
- break;
- default :
- stateStack.push(new Integer(IGNORED_ELEMENT_STATE));
- }
- }
-
- private void internalError(String elementName) {
- // commented out to not fill up log
- // String message = NLS.bind("Unknown element \"{0}\", found at the top level, ignored.", elementName);
- // PDECore.logErrorMessage(message);
- }
-
- public void processingInstruction(String target, String data) throws SAXException {
- // Since 3.0, a processing instruction of the form <?eclipse version="3.0"?> at
- // the start of the manifest file is used to indicate the plug-in manifest
- // schema version in effect. Pre-3.0 (i.e., 2.1) plug-in manifest files do not
- // have one of these, and this is how we can distinguish the manifest of a
- // pre-3.0 plug-in from a post-3.0 one (for compatibility tranformations).
- if (target.equalsIgnoreCase("eclipse")) { //$NON-NLS-1$
- // just the presence of this processing instruction indicates that this
- // plug-in is at least 3.0
- manifestInfo.schemaVersion = "3.0"; //$NON-NLS-1$
- StringTokenizer tokenizer = new StringTokenizer(data, "=\""); //$NON-NLS-1$
- while (tokenizer.hasMoreTokens()) {
- String token = tokenizer.nextToken();
- if (token.equalsIgnoreCase("version")) { //$NON-NLS-1$
- if (!tokenizer.hasMoreTokens()) {
- break;
- }
- manifestInfo.schemaVersion = tokenizer.nextToken();
- break;
- }
- }
- }
- }
-}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties
index d739135..4f91105 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties
@@ -161,11 +161,9 @@ BundleErrorReporter_ClasspathNotEmpty=Bundle-Classpath cannot be empty
BundleErrorReporter_fragmentActivator=A fragment must not declare a bundle activator
BundleErrorReporter_NoExist=The type ''{0}'' is not on the plug-in classpath
BundleErrorReporter_startHeader_autoStartDeprecated=The ''{0}'' header is deprecated, use ''{1}''
-BundleErrorReporter_InvalidFormatInBundleVersion=The specified version does not have the correct format (major.minor.micro.qualifier) or contains invalid characters
BundleErrorReporter_NotExistInProject=Package ''{0}'' does not exist in this plug-in
BundleErrorReporter_missingPackagesInProject=This plug-in does not export all of its packages
BundleErrorReporter_BundleRangeInvalidInBundleVersion=Unsatisfied version constraint: ''{0}''
-BundleErrorReporter_invalidVersionRangeFormat=Invalid version range format
BundleErrorReporter_NotExistPDE=Bundle ''{0}'' cannot be resolved
BundleErrorReporter_exportNoJRE=Cannot export packages prefixed with 'java'
BundleErrorReporter_importNoJRE=Cannot import packages prefixed with 'java'
@@ -273,8 +271,6 @@ SourceEntryErrorReporter_MissingOutputLibForClassFolder=The class folder ''{0}''
SourceLocationManager_problemProcessingBundleManifestSourceHeader=Problem processing bundle manifest source header in plug-in {0} version {1}
UpdateSiteBuilder_0=Cleaning {0}
-VMHelper_noJreForExecEnv=No installed JREs satisfy this Execution Environment: "{0}". Launch aborted.
-
######### Target Export Wizard ###################################33
ExportTargetDefinition_task = Exporting current target definition...
ExportTargetDeleteOldData = Deleting old data...
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/PluginBase.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/PluginBase.java
index 3e162da..4d37dd1 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/PluginBase.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/PluginBase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -10,9 +10,6 @@
*******************************************************************************/
package org.eclipse.pde.internal.core.plugin;
-import org.eclipse.pde.core.plugin.IPluginImport;
-import org.eclipse.pde.core.plugin.IPluginLibrary;
-
import java.util.ArrayList;
import java.util.Locale;
import javax.xml.parsers.*;
@@ -20,7 +17,9 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.osgi.service.resolver.*;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.core.plugin.*;
-import org.eclipse.pde.internal.core.*;
+import org.eclipse.pde.internal.core.PDECoreMessages;
+import org.eclipse.pde.internal.core.PDEState;
+import org.eclipse.pde.internal.core.bundle.BundlePluginBase;
import org.osgi.framework.Version;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -82,6 +81,7 @@ public abstract class PluginBase extends AbstractExtensions implements IPluginBa
return fImports.toArray(new IPluginImport[fImports.size()]);
}
+ @Override
public IPluginBase getPluginBase() {
return this;
}
@@ -109,6 +109,7 @@ public abstract class PluginBase extends AbstractExtensions implements IPluginBa
loadImports(bundleDesc);
}
+ @Override
public void restoreProperty(String name, Object oldValue, Object newValue) throws CoreException {
if (name.equals(P_ID)) {
setId(newValue != null ? newValue.toString() : null);
@@ -184,7 +185,7 @@ public abstract class PluginBase extends AbstractExtensions implements IPluginBa
fImports.add(importElement);
importElement.load(required[i]);
}
- BundleDescription[] imported = PDEStateHelper.getImportedBundles(description);
+ BundleDescription[] imported = getImportedBundles(description);
for (int i = 0; i < imported.length; i++) {
PluginImport importElement = new PluginImport();
importElement.setModel(getModel());
@@ -195,6 +196,26 @@ public abstract class PluginBase extends AbstractExtensions implements IPluginBa
}
}
+ /**
+ * Returns the bundles that export packages imported by the given bundle
+ * via the Import-Package header. Provided as a static utility method so
+ * it can be reused in {@link BundlePluginBase}
+ *
+ * @param root the given bundle
+ *
+ * @return an array of bundles that export packages being imported by the given bundle
+ */
+ public static BundleDescription[] getImportedBundles(BundleDescription root) {
+ if (root == null)
+ return new BundleDescription[0];
+ ExportPackageDescription[] packages = root.getResolvedImports();
+ ArrayList<BundleDescription> resolvedImports = new ArrayList<BundleDescription>(packages.length);
+ for (int i = 0; i < packages.length; i++)
+ if (!root.getLocation().equals(packages[i].getExporter().getLocation()) && !resolvedImports.contains(packages[i].getExporter()))
+ resolvedImports.add(packages[i].getExporter());
+ return resolvedImports.toArray(new BundleDescription[resolvedImports.size()]);
+ }
+
void loadImports(Node node) {
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
@@ -210,6 +231,7 @@ public abstract class PluginBase extends AbstractExtensions implements IPluginBa
}
}
+ @Override
protected void processChild(Node child) {
String name = child.getNodeName().toLowerCase(Locale.ENGLISH);
if (name.equals("runtime")) { //$NON-NLS-1$
@@ -248,6 +270,7 @@ public abstract class PluginBase extends AbstractExtensions implements IPluginBa
fireStructureChanged(iimports, IModelChangedEvent.REMOVE);
}
+ @Override
public void reset() {
fLibraries = new ArrayList<IPluginLibrary>();
fImports = new ArrayList<IPluginImport>();
@@ -314,10 +337,12 @@ public abstract class PluginBase extends AbstractExtensions implements IPluginBa
firePropertyChanged(this, P_IMPORT_ORDER, import1, import2);
}
+ @Override
public boolean isValid() {
return hasRequiredAttributes();
}
+ @Override
protected boolean hasRequiredAttributes() {
if (fName == null)
return false;
@@ -349,8 +374,8 @@ public abstract class PluginBase extends AbstractExtensions implements IPluginBa
if (versionRange == null || versionRange.getMinimum() == null)
return IMatchRules.NONE;
- Version minimum = versionRange.getMinimum();
- Version maximum = versionRange.getMaximum() == null ? maxVersion : versionRange.getMaximum();
+ Version minimum = versionRange.getLeft();
+ Version maximum = versionRange.getRight() == null ? maxVersion : versionRange.getRight();
if (maximum.compareTo(maxVersion) >= 0)
return IMatchRules.GREATER_OR_EQUAL;
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/project/BundleProjectService.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/project/BundleProjectService.java
index 1779eea..9b1c32b 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/project/BundleProjectService.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/project/BundleProjectService.java
@@ -262,9 +262,9 @@ public final class BundleProjectService implements IBundleProjectService {
}
return ManifestElement.parseBundleManifest(manifestStream, new Hashtable<String, String>(10));
} catch (BundleException e) {
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, TargetBundle.STATUS_INVALID_MANIFEST, NLS.bind(Messages.DirectoryBundleContainer_3, bundleLocation.getAbsolutePath()), e));
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, TargetBundle.STATUS_INVALID_MANIFEST, NLS.bind(Messages.TargetBundle_ErrorReadingManifest, bundleLocation.getAbsolutePath()), e));
} catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, TargetBundle.STATUS_INVALID_MANIFEST, NLS.bind(Messages.DirectoryBundleContainer_3, bundleLocation.getAbsolutePath()), e));
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, TargetBundle.STATUS_INVALID_MANIFEST, NLS.bind(Messages.TargetBundle_ErrorReadingManifest, bundleLocation.getAbsolutePath()), e));
} finally {
closeZipFileAndStream(manifestStream, jarFile);
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/DirectoryBundleContainer.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/DirectoryBundleContainer.java
index e45e240..1fc6504 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/DirectoryBundleContainer.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/DirectoryBundleContainer.java
@@ -18,6 +18,7 @@ import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.core.target.*;
import org.eclipse.pde.internal.build.IPDEBuildConstants;
import org.eclipse.pde.internal.core.PDECore;
+import org.eclipse.pde.internal.core.util.ManifestUtils;
/**
* A directory of bundles.
@@ -49,6 +50,7 @@ public class DirectoryBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see org.eclipse.pde.internal.core.target.impl.AbstractBundleContainer#getLocation(boolean)
*/
+ @Override
public String getLocation(boolean resolve) throws CoreException {
if (resolve) {
return getDirectory().toString();
@@ -59,6 +61,7 @@ public class DirectoryBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see org.eclipse.pde.internal.core.target.impl.AbstractBundleContainer#getType()
*/
+ @Override
public String getType() {
return TYPE;
}
@@ -66,6 +69,7 @@ public class DirectoryBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see org.eclipse.pde.internal.core.target.impl.AbstractBundleContainer#resolveBundles(org.eclipse.pde.core.target.ITargetDefinition, org.eclipse.core.runtime.IProgressMonitor)
*/
+ @Override
protected TargetBundle[] resolveBundles(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
File dir = getDirectory();
if (dir.isDirectory()) {
@@ -81,7 +85,11 @@ public class DirectoryBundleContainer extends AbstractBundleContainer {
TargetBundle rb = new TargetBundle(files[i]);
bundles.add(rb);
} catch (CoreException e) {
- // ignore files that are not valid bundles (users may have non-bundle files in their target directory)
+ // If an old style conversion fails because the service is not available, log the error.
+ // Otherwise, ignore non-bundle files
+ if (e.getStatus().getCode() == ManifestUtils.STATUS_CODE_PLUGIN_CONVERTER_UNAVAILABLE) {
+ PDECore.log(e);
+ }
}
localMonitor.worked(1);
}
@@ -94,6 +102,7 @@ public class DirectoryBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see org.eclipse.pde.internal.core.target.AbstractBundleContainer#resolveFeatures(org.eclipse.pde.core.target.ITargetDefinition, org.eclipse.core.runtime.IProgressMonitor)
*/
+ @Override
protected TargetFeature[] resolveFeatures(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
if (definition instanceof TargetDefinition) {
return ((TargetDefinition) definition).resolveFeatures(getLocation(false), monitor);
@@ -114,6 +123,7 @@ public class DirectoryBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see org.eclipse.pde.internal.core.target.AbstractBundleContainer#equals(java.lang.Object)
*/
+ @Override
public boolean equals(Object o) {
if (o instanceof DirectoryBundleContainer) {
DirectoryBundleContainer dbc = (DirectoryBundleContainer) o;
@@ -125,6 +135,7 @@ public class DirectoryBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see org.eclipse.pde.internal.core.target.AbstractBundleContainer#hashCode()
*/
+ @Override
public int hashCode() {
return fPath.hashCode();
}
@@ -132,6 +143,7 @@ public class DirectoryBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
+ @Override
public String toString() {
return new StringBuffer().append("Directory ").append(fPath).toString(); //$NON-NLS-1$
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/Messages.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/Messages.java
index 0b75620..66ff216 100755
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/Messages.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/Messages.java
@@ -22,8 +22,6 @@ public class Messages extends NLS {
public static String AbstractTargetHandle_0;
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;
@@ -60,6 +58,7 @@ public class Messages extends NLS {
public static String ProfileBundleContainer_0;
public static String ProfileBundleContainer_1;
public static String ProfileBundleContainer_2;
+ public static String TargetBundle_ErrorReadingManifest;
public static String TargetDefinition_0;
public static String TargetDefinition_1;
public static String TargetDefinition_2;
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/Messages.properties b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/Messages.properties
index 5f93c64..4a7b98c 100755
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/Messages.properties
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/Messages.properties
@@ -14,8 +14,6 @@ AbstractBundleContainer_1=Required plug-in with version {0} not found: {1}
AbstractTargetHandle_0=Profile registry service not found
DirectoryBundleContainer_0=Reading bundles...
DirectoryBundleContainer_1=Directory does not exist: {0}
-DirectoryBundleContainer_2=Error reading non-OSGi plug-in 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}
@@ -52,6 +50,7 @@ P2TargetUtils_ProvisioningSourceTask=Provisioning source bundles
ProfileBundleContainer_0=Installation directory does not exist: {0}
ProfileBundleContainer_1=Unable resolve configuration area in {0}
ProfileBundleContainer_2=Configuration directory does not exist: {0}
+TargetBundle_ErrorReadingManifest=Error reading manifest for {0}
TargetDefinition_0=Error reading target definition
TargetDefinition_1=Resolving Target Contents...
TargetDefinition_2=Problems occurred while resolving the target contents
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/ProfileBundleContainer.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/ProfileBundleContainer.java
index cf70418..ac1aeb5 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/ProfileBundleContainer.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/ProfileBundleContainer.java
@@ -21,6 +21,7 @@ import org.eclipse.pde.core.target.*;
import org.eclipse.pde.internal.build.site.PluginPathFinder;
import org.eclipse.pde.internal.core.P2Utils;
import org.eclipse.pde.internal.core.PDECore;
+import org.eclipse.pde.internal.core.util.ManifestUtils;
/**
* A bundle container representing an installed profile.
@@ -71,6 +72,7 @@ public class ProfileBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see org.eclipse.pde.internal.core.target.impl.AbstractBundleContainer#getLocation(boolean)
*/
+ @Override
public String getLocation(boolean resolve) throws CoreException {
if (resolve) {
return resolveHomeLocation().toOSString();
@@ -81,6 +83,7 @@ public class ProfileBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see org.eclipse.pde.internal.core.target.impl.AbstractBundleContainer#getType()
*/
+ @Override
public String getType() {
return TYPE;
}
@@ -97,6 +100,7 @@ public class ProfileBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see org.eclipse.pde.internal.core.target.impl.AbstractBundleContainer#resolveBundles(org.eclipse.pde.core.target.ITargetDefinition, org.eclipse.core.runtime.IProgressMonitor)
*/
+ @Override
protected TargetBundle[] resolveBundles(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
String home = resolveHomeLocation().toOSString();
if (!new File(home).isDirectory()) {
@@ -162,6 +166,7 @@ public class ProfileBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see org.eclipse.pde.internal.core.target.AbstractBundleContainer#resolveFeatures(org.eclipse.pde.core.target.ITargetDefinition, org.eclipse.core.runtime.IProgressMonitor)
*/
+ @Override
protected TargetFeature[] resolveFeatures(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
if (definition instanceof TargetDefinition) {
return ((TargetDefinition) definition).resolveFeatures(getLocation(false), monitor);
@@ -190,7 +195,11 @@ public class ProfileBundleContainer extends AbstractBundleContainer {
try {
all.add(new TargetBundle(files[i]));
} catch (CoreException e) {
- // ignore files that are not valid bundles (users may have non-bundle files in their target directory)
+ // If an old style conversion fails because the service is not available, log the error.
+ // Otherwise, ignore non-bundle files
+ if (e.getStatus().getCode() == ManifestUtils.STATUS_CODE_PLUGIN_CONVERTER_UNAVAILABLE) {
+ PDECore.log(e);
+ }
}
localMonitor.worked(1);
}
@@ -244,6 +253,7 @@ public class ProfileBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see org.eclipse.pde.internal.core.target.AbstractBundleContainer#equals(java.lang.Object)
*/
+ @Override
public boolean equals(Object o) {
if (o instanceof ProfileBundleContainer) {
ProfileBundleContainer pbc = (ProfileBundleContainer) o;
@@ -255,6 +265,7 @@ public class ProfileBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see org.eclipse.pde.internal.core.target.AbstractBundleContainer#hashCode()
*/
+ @Override
public int hashCode() {
int hash = fHome.hashCode();
if (fConfiguration != null) {
@@ -381,6 +392,7 @@ public class ProfileBundleContainer extends AbstractBundleContainer {
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
+ @Override
public String toString() {
return new StringBuffer().append("Installation ").append(fHome).append(' ').append(fConfiguration == null ? "Default Configuration" : fConfiguration).toString(); //$NON-NLS-1$ //$NON-NLS-2$
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/ManifestUtils.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/ManifestUtils.java
index db4d7f4..e4c8889 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/ManifestUtils.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/ManifestUtils.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2012 IBM Corporation and others.
+ * Copyright (c) 2006, 2013 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
@@ -24,93 +24,45 @@ import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.core.build.IBuild;
import org.eclipse.pde.core.build.IBuildEntry;
-import org.eclipse.pde.internal.core.ICoreConstants;
-import org.eclipse.pde.internal.core.PDECore;
+import org.eclipse.pde.internal.core.*;
import org.eclipse.pde.internal.core.build.WorkspaceBuildModel;
import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
import org.eclipse.pde.internal.core.project.PDEProject;
-import org.eclipse.pde.internal.core.target.Messages;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
public class ManifestUtils {
- private ManifestUtils() {
- }
-
- public static IPackageFragmentRoot[] findPackageFragmentRoots(IManifestHeader header, IProject project) {
- IJavaProject javaProject = JavaCore.create(project);
-
- String[] libs;
- if (header == null || header.getValue() == null)
- libs = new String[] {"."}; //$NON-NLS-1$
- else
- libs = header.getValue().split(","); //$NON-NLS-1$
-
- IBuild build = getBuild(project);
- if (build == null) {
- try {
- return javaProject.getPackageFragmentRoots();
- } catch (JavaModelException e) {
- return new IPackageFragmentRoot[0];
- }
- }
- List<IPackageFragmentRoot> pkgFragRoots = new LinkedList<IPackageFragmentRoot>();
- for (int j = 0; j < libs.length; j++) {
- String lib = libs[j];
- //https://bugs.eclipse.org/bugs/show_bug.cgi?id=230469
- IPackageFragmentRoot root = null;
- if (!lib.equals(".")) { //$NON-NLS-1$
- try {
- root = javaProject.getPackageFragmentRoot(project.getFile(lib));
- } catch (IllegalArgumentException e) {
- return new IPackageFragmentRoot[0];
- }
- }
- if (root != null && root.exists()) {
- pkgFragRoots.add(root);
- } else {
- IBuildEntry entry = build.getEntry("source." + lib); //$NON-NLS-1$
- if (entry == null)
- continue;
- String[] tokens = entry.getTokens();
- for (int i = 0; i < tokens.length; i++) {
- IResource resource = project.findMember(tokens[i]);
- if (resource == null)
- continue;
- root = javaProject.getPackageFragmentRoot(resource);
- if (root != null && root.exists())
- pkgFragRoots.add(root);
- }
- }
- }
- return pkgFragRoots.toArray(new IPackageFragmentRoot[pkgFragRoots.size()]);
- }
+ public static final String MANIFEST_LIST_SEPARATOR = ",\n "; //$NON-NLS-1$
+ public static final String MANIFEST_LINE_SEPARATOR = "\n "; //$NON-NLS-1$
+ private static int MANIFEST_MAXLINE = 511;
- public final static IBuild getBuild(IProject project) {
- IFile buildProps = PDEProject.getBuildProperties(project);
- if (buildProps.exists()) {
- WorkspaceBuildModel model = new WorkspaceBuildModel(buildProps);
- return model.getBuild();
- }
- return null;
- }
-
- public static boolean isImmediateRoot(IPackageFragmentRoot root) throws JavaModelException {
- int kind = root.getKind();
- return kind == IPackageFragmentRoot.K_SOURCE || (kind == IPackageFragmentRoot.K_BINARY && !root.isExternal());
- }
+ /**
+ * Status code given to the returned core exception when an old style plug-in manifest
+ * cannot be converted because the {@link PluginConverter} service is not available.
+ */
+ public static final int STATUS_CODE_PLUGIN_CONVERTER_UNAVAILABLE = 201;
/**
* Utility method to parse a bundle's manifest into a dictionary. The bundle may be in
* a directory or an archive at the specified location. If the manifest does not contain
- * the necessary entries, the plugin.xml and fragment.xml will be checked for a non-osgi plug-in.
- *
+ * the necessary entries, the plugin.xml and fragment.xml will be checked for an old style
+ * plug-in. If the plugin.xml cannot be converted because the {@link PluginConverter}
+ * service is not available, the thrown core exception will have a status code of
+ * {@link #STATUS_CODE_PLUGIN_CONVERTER_UNAVAILABLE} to allow special processing.
+ * <p>
+ * If this method is being called from a dev mode workspace, the returned map should be passed to
+ * {@link TargetWeaver#weaveManifest(Map)} so that the bundle classpath can be corrected.
+ * </p><p>
+ * This method is called by org.eclipse.pde.api.tools.internal.model.BundleComponent.getManifest()
+ * when OSGi is not running to load manifest information for a bundle.
+ * </p><p>
* TODO This method may be removed in favour of one that caches manifest contents
+ * </p>
*
- * @param bundleLocation root location of the bundle
- * @return bundle manifest dictionary
- * @throws CoreException if manifest has invalid syntax or is missing
+ * @param bundleLocation root location of the bundle, may be a archive file or directory
+ * @return map of bundle manifest properties
+ * @throws CoreException if manifest has invalid syntax, is missing or there is a problem converting as old style plug-in
*/
public static Map<String, String> loadManifest(File bundleLocation) throws CoreException {
// Check if the file is a archive or a directory
@@ -175,43 +127,189 @@ public class ManifestUtils {
}
// The necessary bundle information has not been found in manifest.mf or plugin.xml
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, 0, NLS.bind(Messages.DirectoryBundleContainer_3, bundleLocation.getAbsolutePath()), null));
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, 0, NLS.bind(UtilMessages.ErrorReadingManifest, bundleLocation.getAbsolutePath()), null));
} catch (BundleException e) {
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, 0, NLS.bind(Messages.DirectoryBundleContainer_3, bundleLocation.getAbsolutePath()), e));
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, 0, NLS.bind(UtilMessages.ErrorReadingManifest, bundleLocation.getAbsolutePath()), e));
} catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, 0, NLS.bind(Messages.DirectoryBundleContainer_3, bundleLocation.getAbsolutePath()), e));
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, 0, NLS.bind(UtilMessages.ErrorReadingManifest, bundleLocation.getAbsolutePath()), e));
}
}
/**
+ * Uses the OSGi PluginConverter to generate a manifest for the given project. Will
+ * attempt to refresh the project when complete. If the plugin.xml cannot be
+ * converted because the {@link PluginConverter} service is not available, the
+ * thrown core exception will have a status code of
+ * {@link #STATUS_CODE_PLUGIN_CONVERTER_UNAVAILABLE} to allow special processing.
+ *
+ * @param project the project to convert
+ * @param targetVersion the runtime version the converted manifest is targeted for
+ * @param devProperties a dictionary of development time classpath properties.
+ * The dictionary contains a mapping from plugin id to development time
+ * classpath. A value of null indicates that the default development time
+ * classpath properties will be used.
+ * @throws CoreException if there is a problem converting the manifest or the compatibility fragment hosting the converter service is not available
+ */
+ public static void convertToOSGIFormat(IProject project, String targetVersion, Dictionary<String, String> devProperties) throws CoreException {
+ File outputFile = new File(PDEProject.getManifest(project).getLocation().toOSString());
+ File inputFile = new File(project.getLocation().toOSString());
+ PluginConverter converter = (PluginConverter) PDECore.getDefault().acquireService(PluginConverter.class.getName());
+ if (converter == null) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, STATUS_CODE_PLUGIN_CONVERTER_UNAVAILABLE, NLS.bind(UtilMessages.ManifestUtils_NeedCompatFragmentToConvertManifest, project.getLocation()), null));
+ }
+ try {
+ converter.convertManifest(inputFile, outputFile, false, targetVersion, true, devProperties);
+ } catch (PluginConversionException e) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(UtilMessages.ErrorReadingOldStyleManifest, inputFile.getAbsolutePath()), e));
+ }
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ // If there is a problem due to resource lock, skip the refresh
+ }
+ }
+
+ public static IPackageFragmentRoot[] findPackageFragmentRoots(IManifestHeader header, IProject project) {
+ IJavaProject javaProject = JavaCore.create(project);
+
+ String[] libs;
+ if (header == null || header.getValue() == null)
+ libs = new String[] {"."}; //$NON-NLS-1$
+ else
+ libs = header.getValue().split(","); //$NON-NLS-1$
+
+ IBuild build = getBuild(project);
+ if (build == null) {
+ try {
+ return javaProject.getPackageFragmentRoots();
+ } catch (JavaModelException e) {
+ return new IPackageFragmentRoot[0];
+ }
+ }
+ List<IPackageFragmentRoot> pkgFragRoots = new LinkedList<IPackageFragmentRoot>();
+ for (int j = 0; j < libs.length; j++) {
+ String lib = libs[j];
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=230469
+ IPackageFragmentRoot root = null;
+ if (!lib.equals(".")) { //$NON-NLS-1$
+ try {
+ root = javaProject.getPackageFragmentRoot(project.getFile(lib));
+ } catch (IllegalArgumentException e) {
+ return new IPackageFragmentRoot[0];
+ }
+ }
+ if (root != null && root.exists()) {
+ pkgFragRoots.add(root);
+ } else {
+ IBuildEntry entry = build.getEntry("source." + lib); //$NON-NLS-1$
+ if (entry == null)
+ continue;
+ String[] tokens = entry.getTokens();
+ for (int i = 0; i < tokens.length; i++) {
+ IResource resource = project.findMember(tokens[i]);
+ if (resource == null)
+ continue;
+ root = javaProject.getPackageFragmentRoot(resource);
+ if (root != null && root.exists())
+ pkgFragRoots.add(root);
+ }
+ }
+ }
+ return pkgFragRoots.toArray(new IPackageFragmentRoot[pkgFragRoots.size()]);
+ }
+
+ public static boolean isImmediateRoot(IPackageFragmentRoot root) throws JavaModelException {
+ int kind = root.getKind();
+ return kind == IPackageFragmentRoot.K_SOURCE || (kind == IPackageFragmentRoot.K_BINARY && !root.isExternal());
+ }
+
+ /**
+ * Writes out a manifest file to the given stream. Orders the manifest in an expected
+ * order. Will flush the output, but will not close the stream.
+ *
+ * @param manifestToWrite manifest headers to write to the stream
+ * @param out stream to write output to
+ * @throws IOException if there is a problem with the stream
+ */
+ public static void writeManifest(Map<String, String> manifestToWrite, Writer out) throws IOException {
+ // replaces any eventual existing file
+ manifestToWrite = new Hashtable<String, String>(manifestToWrite);
+
+ // This value has never changed or been used for anything in PDE. The Bundle-ManifestVersion header is available for syntax changes
+ // private static final String MANIFEST_VERSION = "Manifest-Version"; //$NON-NLS-1$
+ // writeEntry(out, MANIFEST_VERSION, (String) manifestToWrite.remove(MANIFEST_VERSION));
+ // always attempt to write the Bundle-ManifestVersion header if it exists (bug 109863)
+ writeEntry(out, Constants.BUNDLE_MANIFESTVERSION, manifestToWrite.remove(Constants.BUNDLE_MANIFESTVERSION));
+ writeEntry(out, Constants.BUNDLE_NAME, manifestToWrite.remove(Constants.BUNDLE_NAME));
+ writeEntry(out, Constants.BUNDLE_SYMBOLICNAME, manifestToWrite.remove(Constants.BUNDLE_SYMBOLICNAME));
+ writeEntry(out, Constants.BUNDLE_VERSION, manifestToWrite.remove(Constants.BUNDLE_VERSION));
+ writeEntry(out, Constants.BUNDLE_CLASSPATH, manifestToWrite.remove(Constants.BUNDLE_CLASSPATH));
+ writeEntry(out, Constants.BUNDLE_ACTIVATOR, manifestToWrite.remove(Constants.BUNDLE_ACTIVATOR));
+ writeEntry(out, Constants.BUNDLE_VENDOR, manifestToWrite.remove(Constants.BUNDLE_VENDOR));
+ writeEntry(out, Constants.FRAGMENT_HOST, manifestToWrite.remove(Constants.FRAGMENT_HOST));
+ writeEntry(out, Constants.BUNDLE_LOCALIZATION, manifestToWrite.remove(Constants.BUNDLE_LOCALIZATION));
+ writeEntry(out, Constants.EXPORT_PACKAGE, manifestToWrite.remove(Constants.EXPORT_PACKAGE));
+ writeEntry(out, ICoreConstants.PROVIDE_PACKAGE, manifestToWrite.remove(ICoreConstants.PROVIDE_PACKAGE));
+ writeEntry(out, Constants.REQUIRE_BUNDLE, manifestToWrite.remove(Constants.REQUIRE_BUNDLE));
+ Iterator<?> keys = manifestToWrite.keySet().iterator();
+ while (keys.hasNext()) {
+ String key = (String) keys.next();
+ writeEntry(out, key, manifestToWrite.get(key));
+ }
+ out.flush();
+ }
+
+ private static IBuild getBuild(IProject project) {
+ IFile buildProps = PDEProject.getBuildProperties(project);
+ if (buildProps.exists()) {
+ WorkspaceBuildModel model = new WorkspaceBuildModel(buildProps);
+ return model.getBuild();
+ }
+ return null;
+ }
+
+ /**
* Parses an old style plug-in's (or fragment's) XML definition file into a dictionary.
* The provided file may be an zip archive or directory. The existence of a plugin.xml
- * or fragment.xml is not checked in this method.
+ * or fragment.xml is not checked in this method. If the plugin.xml cannot be converted
+ * because the {@link PluginConverter} service is not available, the thrown core
+ * exception will have a status code of {@link #STATUS_CODE_PLUGIN_CONVERTER_UNAVAILABLE}
+ * to allow special processing.
*
* @param pluginLocation location of the bundle (archive file or directory)
* @return bundle manifest dictionary or <code>null</code> if none
* @throws CoreException if manifest has invalid syntax
*/
private static Map<String, String> loadPluginXML(File pluginLocation) throws CoreException {
+ // This may be called from API Tools without OSGi running, so we try to return a useful status
+ if (PDECore.getDefault() == null) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, STATUS_CODE_PLUGIN_CONVERTER_UNAVAILABLE, UtilMessages.ManifestUtils_PluginConverterOnlyAvailableWithOSGi, null));
+ }
+
PluginConverter converter = (PluginConverter) PDECore.getDefault().acquireService(PluginConverter.class.getName());
- if (converter != null) {
- try {
- Dictionary<String, String> convert = converter.convertManifest(pluginLocation, false, null, false, null);
- if (convert != null) {
- Map<String, String> map = new HashMap<String, String>(convert.size(), 1.0f);
- Enumeration<String> keys = convert.keys();
- while (keys.hasMoreElements()) {
- String key = keys.nextElement();
- map.put(key, convert.get(key));
- }
- return map;
- }
- } catch (PluginConversionException e) {
- throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(Messages.DirectoryBundleContainer_2, pluginLocation.getAbsolutePath()), e));
- }
+ if (converter == null) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, STATUS_CODE_PLUGIN_CONVERTER_UNAVAILABLE, NLS.bind(UtilMessages.ManifestUtils_NeedCompatFragmentToConvertManifest, pluginLocation.toString()), null));
}
- return null;
+
+ Dictionary<String, String> convert;
+ try {
+ convert = converter.convertManifest(pluginLocation, false, null, false, null);
+ } catch (PluginConversionException e) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(UtilMessages.ErrorReadingOldStyleManifest, pluginLocation.getAbsolutePath()), e));
+ }
+
+ if (convert == null) {
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(UtilMessages.ErrorReadingOldStyleManifest, pluginLocation.getAbsolutePath())));
+ }
+
+ Map<String, String> map = new HashMap<String, String>(convert.size(), 1.0f);
+ Enumeration<String> keys = convert.keys();
+ while (keys.hasMoreElements()) {
+ String key = keys.nextElement();
+ map.put(key, convert.get(key));
+ }
+ return map;
}
/**
@@ -236,4 +334,23 @@ public class ManifestUtils {
}
}
+ private static void writeEntry(Writer out, String key, String value) throws IOException {
+ if (value != null && value.length() > 0) {
+ out.write(splitOnComma(key + ": " + value)); //$NON-NLS-1$
+ out.write('\n');
+ }
+ }
+
+ private static String splitOnComma(String value) {
+ if (value.length() < MANIFEST_MAXLINE || value.indexOf(MANIFEST_LINE_SEPARATOR) >= 0)
+ return value; // assume the line is already split
+ String[] values = ManifestElement.getArrayFromList(value);
+ if (values == null || values.length == 0)
+ return value;
+ StringBuffer sb = new StringBuffer(value.length() + ((values.length - 1) * MANIFEST_LIST_SEPARATOR.length()));
+ for (int i = 0; i < values.length - 1; i++)
+ sb.append(values[i]).append(MANIFEST_LIST_SEPARATOR);
+ sb.append(values[values.length - 1]);
+ return sb.toString();
+ }
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/UtilMessages.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/UtilMessages.java
new file mode 100644
index 0000000..46acdc1
--- /dev/null
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/UtilMessages.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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
+ * Les Jones <lesojones@gmail.com> - Bug 214457
+ * EclipseSource Corporation - ongoing enhancements
+ *******************************************************************************/
+package org.eclipse.pde.internal.core.util;
+
+import org.eclipse.osgi.util.NLS;
+
+public class UtilMessages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.pde.internal.core.util.UtilMessages"; //$NON-NLS-1$
+ public static String ErrorReadingManifest;
+ public static String ErrorReadingOldStyleManifest;
+ public static String ManifestUtils_NeedCompatFragmentToConvertManifest;
+ public static String ManifestUtils_PluginConverterOnlyAvailableWithOSGi;
+ public static String VMHelper_noJreForExecEnv;
+ public static String BundleErrorReporter_InvalidFormatInBundleVersion;
+ public static String BundleErrorReporter_invalidVersionRangeFormat;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, UtilMessages.class);
+ }
+
+ private UtilMessages() {
+ }
+}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/UtilMessages.properties b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/UtilMessages.properties
new file mode 100644
index 0000000..093d44f
--- /dev/null
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/UtilMessages.properties
@@ -0,0 +1,18 @@
+###############################################################################
+# Copyright (c) 2013 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
+# Simon Muschel <smuschel@gmx.de> - bugs 215743, 260549
+###############################################################################
+ErrorReadingManifest=Error reading manifest for {0}
+ErrorReadingOldStyleManifest=Error reading non-OSGi plug-in manifest for {0}
+ManifestUtils_NeedCompatFragmentToConvertManifest=Plug-in at ''{0}'' does not have a manifest. The PluginConverter service used to create manifests for old style plug-ins is not available, please install the ''org.eclipse.osgi.compatibility.plugins'' compatibility fragment.
+ManifestUtils_PluginConverterOnlyAvailableWithOSGi=The PluginConverter service to create a manifest for old style plug-ins is not available without an OSGi runtime
+BundleErrorReporter_InvalidFormatInBundleVersion=The specified version does not have the correct format (major.minor.micro.qualifier) or contains invalid characters
+BundleErrorReporter_invalidVersionRangeFormat=Invalid version range format
+VMHelper_noJreForExecEnv=No installed JREs satisfy this Execution Environment: "{0}". Launch aborted. \ No newline at end of file
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/VMUtil.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/VMUtil.java
index 126fad2..22d6381 100755
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/VMUtil.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/VMUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 IBM Corporation and others.
+ * Copyright (c) 2008, 2013 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
@@ -11,8 +11,6 @@
*******************************************************************************/
package org.eclipse.pde.internal.core.util;
-import org.eclipse.jdt.launching.IVMInstall;
-
import java.util.ArrayList;
import org.eclipse.core.runtime.*;
import org.eclipse.jdt.launching.*;
@@ -20,7 +18,6 @@ import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.internal.core.PDECore;
-import org.eclipse.pde.internal.core.PDECoreMessages;
public class VMUtil {
@@ -89,7 +86,7 @@ public class VMUtil {
IPath containerPath = JavaRuntime.newJREContainerPath(ee);
IVMInstall vmi = JavaRuntime.getVMInstall(containerPath);
if (vmi == null)
- throw new CoreException(createErrorStatus(NLS.bind(PDECoreMessages.VMHelper_noJreForExecEnv, ee.getId())));
+ throw new CoreException(createErrorStatus(NLS.bind(UtilMessages.VMHelper_noJreForExecEnv, ee.getId())));
return vmi.getName();
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/VersionUtil.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/VersionUtil.java
index 6851d8d..8e9fd3d 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/VersionUtil.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/VersionUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 IBM Corporation and others.
+ * Copyright (c) 2006, 2013 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
@@ -15,7 +15,6 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.pde.core.plugin.IMatchRules;
import org.eclipse.pde.internal.core.PDECore;
-import org.eclipse.pde.internal.core.PDECoreMessages;
import org.osgi.framework.Version;
public class VersionUtil {
@@ -25,7 +24,7 @@ public class VersionUtil {
if (versionString != null)
new Version(versionString.trim());
} catch (IllegalArgumentException e) {
- return new Status(IStatus.ERROR, PDECore.PLUGIN_ID, IStatus.ERROR, PDECoreMessages.BundleErrorReporter_InvalidFormatInBundleVersion, e);
+ return new Status(IStatus.ERROR, PDECore.PLUGIN_ID, IStatus.ERROR, UtilMessages.BundleErrorReporter_InvalidFormatInBundleVersion, e);
}
return Status.OK_STATUS;
}
@@ -34,7 +33,7 @@ public class VersionUtil {
try {
new VersionRange(versionRangeString);
} catch (IllegalArgumentException e) {
- return new Status(IStatus.ERROR, PDECore.PLUGIN_ID, IStatus.ERROR, PDECoreMessages.BundleErrorReporter_invalidVersionRangeFormat, e);
+ return new Status(IStatus.ERROR, PDECore.PLUGIN_ID, IStatus.ERROR, UtilMessages.BundleErrorReporter_invalidVersionRangeFormat, e);
}
return Status.OK_STATUS;
}
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/CreateManifestOperation.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/CreateManifestOperation.java
index 54cd46b..3ce254c 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/CreateManifestOperation.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/CreateManifestOperation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 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
@@ -14,14 +14,15 @@ import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.filebuffers.*;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.text.*;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.internal.core.ClasspathHelper;
import org.eclipse.pde.internal.core.TargetPlatformHelper;
-import org.eclipse.pde.internal.core.converter.PDEPluginConverter;
import org.eclipse.pde.internal.core.project.PDEProject;
+import org.eclipse.pde.internal.core.util.ManifestUtils;
import org.eclipse.text.edits.*;
public class CreateManifestOperation implements IRunnableWithProgress {
@@ -46,7 +47,7 @@ public class CreateManifestOperation implements IRunnableWithProgress {
private void handleConvert() throws CoreException {
IProject project = fModel.getUnderlyingResource().getProject();
String target = TargetPlatformHelper.getTargetVersionString();
- PDEPluginConverter.convertToOSGIFormat(project, target, ClasspathHelper.getDevDictionary(fModel), new NullProgressMonitor());
+ ManifestUtils.convertToOSGIFormat(project, target, ClasspathHelper.getDevDictionary(fModel));
}
private void trimOldManifest() throws BadLocationException, CoreException {
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/PluginVersionPart.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/PluginVersionPart.java
index a71da77..b82c754 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/PluginVersionPart.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/PluginVersionPart.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 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
@@ -15,7 +15,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.*;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.pde.core.plugin.*;
-import org.eclipse.pde.internal.core.PDECoreMessages;
+import org.eclipse.pde.internal.core.util.UtilMessages;
import org.eclipse.pde.internal.core.util.VersionUtil;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.pde.internal.ui.PDEUIMessages;
@@ -35,6 +35,7 @@ public class PluginVersionPart {
super(buttonLabels);
}
+ @Override
protected void selectionChanged(IStructuredSelection selection) {
if (selection.size() < 1) {
setButtonEnabled(0, false);
@@ -43,6 +44,7 @@ public class PluginVersionPart {
}
}
+ @Override
protected void handleDoubleClick(IStructuredSelection selection) {
if (selection.size() == 1) {
IPluginModelBase entry = (IPluginModelBase) selection.getFirstElement();
@@ -51,6 +53,7 @@ public class PluginVersionPart {
}
}
+ @Override
protected void buttonSelected(Button button, int index) {
IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection();
if (selection.size() == 1) {
@@ -219,7 +222,7 @@ public class PluginVersionPart {
errorMessage = PDEUIMessages.DependencyPropertiesDialog_invalidFormat;
} else {
// For everything else: Field assist, wizards
- errorMessage = PDECoreMessages.BundleErrorReporter_InvalidFormatInBundleVersion;
+ errorMessage = UtilMessages.BundleErrorReporter_InvalidFormatInBundleVersion;
}
return new Status(IStatus.ERROR, "org.eclipse.pde.ui", //$NON-NLS-1$
IStatus.ERROR, PDELabelUtility.qualifyMessage(PDELabelUtility.getFieldLabel(textWidget), errorMessage), null);
@@ -240,7 +243,7 @@ public class PluginVersionPart {
errorMessage = PDEUIMessages.DependencyPropertiesDialog_invalidFormat;
} else {
// For everything else: Field assist, wizards
- errorMessage = PDECoreMessages.BundleErrorReporter_InvalidFormatInBundleVersion;
+ errorMessage = UtilMessages.BundleErrorReporter_InvalidFormatInBundleVersion;
}
Version v1;
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/AddNewDependenciesOperation.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/AddNewDependenciesOperation.java
index eb08f38..1a08109 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/AddNewDependenciesOperation.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/AddNewDependenciesOperation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 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
@@ -28,12 +28,12 @@ import org.eclipse.pde.internal.core.ICoreConstants;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.build.WorkspaceBuildModel;
import org.eclipse.pde.internal.core.bundle.BundlePluginBase;
-import org.eclipse.pde.internal.core.converter.PluginConverter;
import org.eclipse.pde.internal.core.ibundle.*;
import org.eclipse.pde.internal.core.plugin.PluginImport;
import org.eclipse.pde.internal.core.project.PDEProject;
import org.eclipse.pde.internal.core.search.PluginJavaSearchUtil;
import org.eclipse.pde.internal.core.text.bundle.*;
+import org.eclipse.pde.internal.core.util.ManifestUtils;
import org.eclipse.pde.internal.ui.PDEUIMessages;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.osgi.framework.*;
@@ -47,6 +47,7 @@ public class AddNewDependenciesOperation extends WorkspaceModifyOperation {
protected static class ReferenceFinder extends SearchRequestor {
private boolean found = false;
+ @Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
found = true;
}
@@ -61,6 +62,7 @@ public class AddNewDependenciesOperation extends WorkspaceModifyOperation {
fBase = base;
}
+ @Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
monitor.beginTask(PDEUIMessages.AddNewDependenciesOperation_mainTask, 100);
final IBundle bundle = fBase.getBundleModel().getBundle();
@@ -378,10 +380,10 @@ public class AddNewDependenciesOperation extends WorkspaceModifyOperation {
ExportPackageDescription desc = it.next();
String value = (desc.getVersion().equals(Version.emptyVersion)) ? desc.getName() : desc.getName() + "; version=\"" + desc.getVersion() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
// use same separator as used when writing out Manifest
- buffer.append(value).append(PluginConverter.LIST_SEPARATOR);
+ buffer.append(value).append(ManifestUtils.MANIFEST_LIST_SEPARATOR);
}
if (buffer.length() > 0)
- buffer.setLength(buffer.length() - PluginConverter.LIST_SEPARATOR.length());
+ buffer.setLength(buffer.length() - ManifestUtils.MANIFEST_LIST_SEPARATOR.length());
bundle.setHeader(Constants.IMPORT_PACKAGE, buffer.toString());
}
}
@@ -411,14 +413,14 @@ public class AddNewDependenciesOperation extends WorkspaceModifyOperation {
String pluginId = it.next();
if (!added.contains(pluginId))
try {
- buffer.append(pluginId).append(PluginConverter.LIST_SEPARATOR);
+ buffer.append(pluginId).append(ManifestUtils.MANIFEST_LIST_SEPARATOR);
added.add(pluginId);
entry.removeToken(pluginId);
} catch (CoreException e) {
}
}
if (buffer.length() > 0)
- buffer.setLength(buffer.length() - PluginConverter.LIST_SEPARATOR.length());
+ buffer.setLength(buffer.length() - ManifestUtils.MANIFEST_LIST_SEPARATOR.length());
bundle.setHeader(Constants.REQUIRE_BUNDLE, buffer.toString());
}
}
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/ContentPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/ContentPage.java
index 9fe007b..62fbd6b 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/ContentPage.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/ContentPage.java
@@ -15,9 +15,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.pde.internal.core.PDECoreMessages;
-import org.eclipse.pde.internal.core.util.IdUtil;
-import org.eclipse.pde.internal.core.util.VersionUtil;
+import org.eclipse.pde.internal.core.util.*;
import org.eclipse.pde.internal.ui.PDEUIMessages;
import org.eclipse.pde.internal.ui.util.PDELabelUtility;
import org.eclipse.pde.internal.ui.wizards.BundleProviderHistoryUtil;
@@ -126,7 +124,7 @@ public abstract class ContentPage extends WizardPage {
if (text.getText().trim().length() == 0) {
return PDELabelUtility.qualifyMessage(PDELabelUtility.getFieldLabel(text), PDEUIMessages.ControlValidationUtility_errorMsgValueMustBeSpecified);
} else if (!isVersionValid(text.getText().trim())) {
- return PDELabelUtility.qualifyMessage(PDELabelUtility.getFieldLabel(text), PDECoreMessages.BundleErrorReporter_InvalidFormatInBundleVersion);
+ return PDELabelUtility.qualifyMessage(PDELabelUtility.getFieldLabel(text), UtilMessages.BundleErrorReporter_InvalidFormatInBundleVersion);
}
return null;
}
@@ -146,6 +144,7 @@ public abstract class ContentPage extends WizardPage {
return VersionUtil.validateVersion(version).getSeverity() == IStatus.OK;
}
+ @Override
public IWizardPage getNextPage() {
updateData();
return super.getNextPage();
@@ -156,6 +155,7 @@ public abstract class ContentPage extends WizardPage {
*
* @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
*/
+ @Override
public void setVisible(boolean visible) {
if (visible) {
String id = computeId();
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewLibraryPluginCreationOperation.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewLibraryPluginCreationOperation.java
index d156b65..916e616 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewLibraryPluginCreationOperation.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewLibraryPluginCreationOperation.java
@@ -25,13 +25,12 @@ import org.eclipse.jdt.core.*;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
-import org.eclipse.pde.core.build.IBuildEntry;
-import org.eclipse.pde.core.build.IBuildModelFactory;
+import org.eclipse.pde.core.build.*;
import org.eclipse.pde.core.plugin.*;
import org.eclipse.pde.internal.core.ICoreConstants;
+import org.eclipse.pde.internal.core.build.Build;
import org.eclipse.pde.internal.core.build.WorkspaceBuildModel;
import org.eclipse.pde.internal.core.bundle.BundlePluginBase;
-import org.eclipse.pde.internal.core.converter.PluginConverter;
import org.eclipse.pde.internal.core.ibundle.IBundle;
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
import org.eclipse.pde.internal.core.natures.PDE;
@@ -50,6 +49,8 @@ import org.osgi.framework.Constants;
public class NewLibraryPluginCreationOperation extends NewProjectCreationOperation {
+ private static final String SOURCE_PREFIX = "source."; //$NON-NLS-1$
+
private LibraryPluginFieldData fData;
public NewLibraryPluginCreationOperation(LibraryPluginFieldData data, IProjectProvider provider, IPluginContentWizard contentWizard) {
@@ -441,13 +442,84 @@ public class NewLibraryPluginCreationOperation extends NewProjectCreationOperati
filter.add("*"); //$NON-NLS-1$
map.put(elems[i].getValue(), filter);
}
- Set<String> packages = PluginConverter.getDefault().getExports(project, map);
+ Set<String> packages = getExports(project, map);
String pkgValue = getCommaValuesFromPackagesSet(packages, fData.getVersion());
bundle.setHeader(Constants.EXPORT_PACKAGE, pkgValue);
} catch (BundleException e) {
}
}
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public Set<String> getExports(IProject proj, Map libs) {
+ IFile buildProperties = PDEProject.getBuildProperties(proj);
+ IBuild build = null;
+ if (buildProperties != null) {
+ WorkspaceBuildModel buildModel = new WorkspaceBuildModel(buildProperties);
+ build = buildModel.getBuild();
+ } else
+ build = new Build();
+ return findPackages(proj, libs, build);
+ }
+
+ private Set<String> findPackages(IProject proj, Map<?, List<?>> libs, IBuild build) {
+ TreeSet<String> result = new TreeSet<String>();
+ IJavaProject jp = JavaCore.create(proj);
+ Iterator<?> it = libs.entrySet().iterator();
+ while (it.hasNext()) {
+ @SuppressWarnings("rawtypes")
+ Map.Entry entry = (Map.Entry) it.next();
+ String libName = entry.getKey().toString();
+ List<?> filter = (List<?>) entry.getValue();
+ IBuildEntry libEntry = build.getEntry(SOURCE_PREFIX + libName);
+ if (libEntry != null) {
+ String[] tokens = libEntry.getTokens();
+ for (int i = 0; i < tokens.length; i++) {
+ IResource folder = null;
+ if (tokens[i].equals(".")) //$NON-NLS-1$
+ folder = proj;
+ else
+ folder = proj.getFolder(tokens[i]);
+ if (folder != null)
+ addPackagesFromFragRoot(jp.getPackageFragmentRoot(folder), result, filter);
+ }
+ } else {
+ IResource res = proj.findMember(libName);
+ if (res != null)
+ addPackagesFromFragRoot(jp.getPackageFragmentRoot(res), result, filter);
+ }
+ }
+ return result;
+ }
+
+ private void addPackagesFromFragRoot(IPackageFragmentRoot root, Collection<String> result, List<?> filter) {
+ if (root == null)
+ return;
+ try {
+ if (filter != null && !filter.contains("*")) { //$NON-NLS-1$
+ ListIterator<?> li = filter.listIterator();
+ while (li.hasNext()) {
+ String pkgName = li.next().toString();
+ if (pkgName.endsWith(".*")) //$NON-NLS-1$
+ pkgName = pkgName.substring(0, pkgName.length() - 2);
+
+ IPackageFragment frag = root.getPackageFragment(pkgName);
+ if (frag != null)
+ result.add(pkgName);
+ }
+ return;
+ }
+ IJavaElement[] children = root.getChildren();
+ for (int j = 0; j < children.length; j++) {
+ IPackageFragment fragment = (IPackageFragment) children[j];
+ String name = fragment.getElementName();
+ if (fragment.hasChildren() && !result.contains(name)) {
+ result.add(name);
+ }
+ }
+ } catch (JavaModelException e) {
+ }
+ }
+
private void addDependencies(IProject project, ISharedPluginModel model, IProgressMonitor monitor) {
if (!(model instanceof IBundlePluginModelBase)) {
monitor.done();