From 85ad9719778aa0aa5b9e6655c015a352adb5540a Mon Sep 17 00:00:00 2001 From: Roland Grunberg Date: Thu, 7 Apr 2016 10:23:49 -0400 Subject: [PATCH] Support reading BundleInfo from p2 Droplets enabled installations. - Additionally support reading source bundles from p2 Droplets location --- .../org.eclipse.pde.core/META-INF/MANIFEST.MF | 1 + .../eclipse/pde/internal/core/P2Utils.java | 50 +++++++++++++++++-- .../org.eclipse.pde.doc.user/pdeOptions.txt | 1 + 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/eclipse.pde.ui/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF b/eclipse.pde.ui/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF index 8b65b7b6f..ff1a881a0 100644 --- a/eclipse.pde.ui/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF +++ b/eclipse.pde.ui/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF @@ -102,5 +102,6 @@ Require-Bundle: org.eclipse.core.filesystem;bundle-version="[1.0.0,2.0.0)" Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: JavaSE-11 +Import-Package: org.eclipse.equinox.internal.simpleconfigurator.utils Bundle-ActivationPolicy: lazy Automatic-Module-Name: org.eclipse.pde.core diff --git a/eclipse.pde.ui/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/P2Utils.java b/eclipse.pde.ui/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/P2Utils.java index bd0be54a9..d9259321e 100644 --- a/eclipse.pde.ui/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/P2Utils.java +++ b/eclipse.pde.ui/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/P2Utils.java @@ -17,10 +17,11 @@ package org.eclipse.pde.internal.core; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.nio.file.Files; +import java.nio.file.Paths; import java.nio.file.NoSuchFileException; +import java.util.Arrays; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -34,6 +35,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.equinox.frameworkadmin.BundleInfo; +import org.eclipse.core.runtime.URIUtil; import org.eclipse.equinox.internal.simpleconfigurator.utils.SimpleConfiguratorUtils; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.IProvisioningAgentProvider; import org.eclipse.equinox.p2.engine.IEngine; @@ -62,6 +64,7 @@ import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.TargetPlatform; import org.eclipse.pde.internal.build.BundleHelper; import org.eclipse.pde.internal.core.plugin.PluginBase; +import org.eclipse.pde.internal.core.util.ManifestUtils; import org.osgi.framework.Constants; /** @@ -141,7 +144,17 @@ public class P2Utils { try { File bundlesTxt = new File(configurationArea, SimpleConfiguratorManipulator.BUNDLES_INFO_PATH); File home = basePath.toFile(); - BundleInfo[] bundles = getBundlesFromFile(bundlesTxt, home); + List ibundleList = SimpleConfiguratorUtils.readConfiguration(bundlesTxt.toURI().toURL(), home.toURI()); + List bundleList = new ArrayList<>(); + for (org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo b : ibundleList) { + URI location = b.getLocation(); + if (!location.isAbsolute() && b.getBaseLocation() != null) + location = URIUtil.makeAbsolute(location, b.getBaseLocation()); + BundleInfo binfo = new BundleInfo(b.getSymbolicName(), b.getVersion(), location, b.getStartLevel(), b.isMarkedAsStarted()); + bundleList.add(binfo); + } + BundleInfo[] bundles = bundleList.toArray(new BundleInfo[0]); + if (bundles == null || bundles.length == 0) { return null; } @@ -170,11 +183,38 @@ public class P2Utils { try { File home = basePath.toFile(); File srcBundlesTxt = new File(configurationArea, SimpleConfiguratorManipulator.SOURCE_INFO_PATH); + final List allSrcBundles = new ArrayList<>(); + try { + for (File infoFile : SimpleConfiguratorUtils.getInfoFiles()) { + File pluginsDir = Paths.get(infoFile.getParent(), "plugins").toFile(); //$NON-NLS-1$ + File[] sourceJars = pluginsDir.listFiles((dir, name) -> { + return name.matches(".*\\.source_.*\\.jar$"); //$NON-NLS-1$ + }); + for (File sourceJar : sourceJars) { + Map manifest; + try { + manifest = ManifestUtils.loadManifest(sourceJar); + final String bsn = manifest.get(Constants.BUNDLE_SYMBOLICNAME); + final String version = manifest.get(Constants.BUNDLE_VERSION); + BundleInfo info = new BundleInfo(bsn, version, sourceJar.toURI(), -1, false); + allSrcBundles.add(info); + } catch (CoreException e) { + // continue + } + } + } + } catch (URISyntaxException e) { + // continue + } + BundleInfo[] srcBundles = getBundlesFromFile(srcBundlesTxt, home); - if (srcBundles == null || srcBundles.length == 0) { + if (srcBundles != null && srcBundles.length > 0) { + allSrcBundles.addAll(Arrays.asList(srcBundles)); + } + if (allSrcBundles.size() == 0) { return null; } - return srcBundles; + return allSrcBundles.toArray(new BundleInfo[0]); } catch (IOException e) { PDECore.log(e); return null; diff --git a/eclipse.platform.common/bundles/org.eclipse.pde.doc.user/pdeOptions.txt b/eclipse.platform.common/bundles/org.eclipse.pde.doc.user/pdeOptions.txt index 0f71564d2..874580e04 100644 --- a/eclipse.platform.common/bundles/org.eclipse.pde.doc.user/pdeOptions.txt +++ b/eclipse.platform.common/bundles/org.eclipse.pde.doc.user/pdeOptions.txt @@ -76,6 +76,7 @@ ;${rt.equinox.p2.bundles}/org.eclipse.equinox.p2.repository.tools/${dot.classes} ;${rt.equinox.p2.bundles}/org.eclipse.equinox.p2.touchpoint.eclipse/${dot.classes} ;${rt.equinox.p2.bundles}/org.eclipse.equinox.simpleconfigurator.manipulator/${dot.classes} +;${rt.equinox.p2.bundles}/org.eclipse.equinox.simpleconfigurator/${dot.classes} -breakiterator -use -- 2.28.0