From a7c0601453f788e0d2f94f9d1a6ddf9e91892d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 7 May 2024 17:13:52 +0200 Subject: [PATCH] Add ManifestElement.parseBundleManifest without map parameter Currently the existing ManifestElement.parseBundleManifest with a wild mixture of parameters, some using access restricted maps, some use null some use a hashmap (what likely causes issue if case of headers is different than expected). This adds a new method that simply removes the map parameter and uses a CaseInsensitiveDictionaryMap that is also used internally in the framework and is most likely the most natural choice for this usecase. --- bundles/org.eclipse.osgi/META-INF/MANIFEST.MF | 4 ++-- bundles/org.eclipse.osgi/pom.xml | 2 +- .../supplement/META-INF/MANIFEST.MF | 2 +- .../eclipse/osgi/util/ManifestElement.java | 22 +++++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF index d5482329f91..73c86e2b391 100644 --- a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF @@ -51,7 +51,7 @@ Export-Package: org.eclipse.core.runtime.adaptor;x-friends:="org.eclipse.core.ru org.eclipse.osgi.storage.bundlefile;x-internal:=true, org.eclipse.osgi.storage.url.reference;x-internal:=true, org.eclipse.osgi.storagemanager;version="1.0", - org.eclipse.osgi.util;version="1.1", + org.eclipse.osgi.util;version="1.2.0", org.osgi.dto;version="1.1.1", org.osgi.framework;version="1.10", org.osgi.framework.connect;version="1.0";uses:="org.osgi.framework.launch", @@ -107,7 +107,7 @@ Bundle-Activator: org.eclipse.osgi.internal.framework.SystemBundleActivator Bundle-Description: %systemBundle Bundle-Copyright: %copyright Bundle-Vendor: %eclipse.org -Bundle-Version: 3.20.100.qualifier +Bundle-Version: 3.21.0.qualifier Bundle-Localization: systembundle Bundle-DocUrl: http://www.eclipse.org Eclipse-ExtensibleAPI: true diff --git a/bundles/org.eclipse.osgi/pom.xml b/bundles/org.eclipse.osgi/pom.xml index 6375514ebd3..d9f4b6e0cf6 100644 --- a/bundles/org.eclipse.osgi/pom.xml +++ b/bundles/org.eclipse.osgi/pom.xml @@ -19,7 +19,7 @@ org.eclipse.osgi org.eclipse.osgi - 3.20.100-SNAPSHOT + 3.21.0-SNAPSHOT eclipse-plugin diff --git a/bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF index 0a60e767518..0b222098fda 100644 --- a/bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.supplement -Bundle-Version: 1.10.900.qualifier +Bundle-Version: 1.11.0.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Export-Package: org.eclipse.equinox.log;version="1.1", diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/ManifestElement.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/ManifestElement.java index 439efc4f65a..64a69198220 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/ManifestElement.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/ManifestElement.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.StringTokenizer; +import java.util.TreeMap; import org.eclipse.osgi.internal.messages.Msg; import org.eclipse.osgi.internal.util.SupplementDebug; import org.eclipse.osgi.internal.util.Tokenizer; @@ -485,6 +486,27 @@ public static String[] getArrayFromList(String stringList, String separator) { return list.toArray(new String[list.size()]); } + /** + * Parses a bundle manifest and returns the header/value pairs into as case + * insensitive map. Only the main section of the manifest is parsed (up to the + * first blank line). All other sections are ignored. If a header is duplicated + * then only the last value is stored in the map. + *

+ * The supplied input stream is consumed by this method and will be closed. + *

+ * + * @param manifest an input stream for a bundle manifest. + * @throws BundleException if the manifest has an invalid syntax + * @throws IOException if an error occurs while reading the manifest + * @return the map with the header/value pairs from the bundle manifest + * @since 3.21 + */ + public static Map parseBundleManifest(InputStream manifest) throws IOException, BundleException { + Map headers = new TreeMap<>(String::compareToIgnoreCase); + parseBundleManifest(manifest, headers); + return headers; + } + /** * Parses a bundle manifest and puts the header/value pairs into the supplied Map. * Only the main section of the manifest is parsed (up to the first blank line). All