Skip to content

Commit

Permalink
Add ManifestElement.parseBundleManifest without map parameter
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
laeubi committed May 8, 2024
1 parent 1b7612a commit 6dd92be
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -485,6 +486,26 @@ 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.
* <p>
* The supplied input stream is consumed by this method and will be closed.
* </p>
*
* @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
*/
public static Map<String, String> parseBundleManifest(InputStream manifest) throws IOException, BundleException {
Map<String, String> 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
Expand Down

0 comments on commit 6dd92be

Please sign in to comment.