Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright (c) 2023 EquoTech, Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* EquoTech, Inc. - initial API and implementation
*******************************************************************************/
package dev.equo.solstice;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.jar.Manifest;
import javax.annotation.Nullable;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
/**
* Parses a jar manifest, removing some fine-grained details for the purpose of simplifying the
* developer experience.
*
*
*
optional imports and requirements are removed
*
version constraints are removed
*
*/
public class SolsticeManifest {
public static SolsticeManifest parseJar(File file) throws MalformedURLException {
var url = new URL("jar:" + file.toURI() + "!" + SLASH_MANIFEST_PATH);
return new SolsticeManifest(url, -1);
}
public static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
public static final String SLASH_MANIFEST_PATH = "/" + MANIFEST_PATH;
private final String jarUrl;
final int classpathOrder;
private final @Nullable String symbolicName;
private final Version version;
private final LinkedHashMap headersOriginal = new LinkedHashMap<>();
final ArrayList requiredBundles;
final ArrayList pkgImports;
final ArrayList pkgExports;
final List capProvides;
final List capRequires;
final boolean lazy;
final List fragments = new ArrayList<>();
Bundle hydrated;
SolsticeManifest(URL manifestURL, int classpathOrder) {
this.classpathOrder = classpathOrder;
var externalForm = manifestURL.toExternalForm();
if (!externalForm.endsWith(SLASH_MANIFEST_PATH)) {
throw new IllegalArgumentException(
"Expected manifest to end with " + SLASH_MANIFEST_PATH + " but was " + externalForm);
}
jarUrl = externalForm.substring(0, externalForm.length() - SLASH_MANIFEST_PATH.length());
if (!jarUrl.endsWith("!")) {
if (jarUrl.endsWith("build/resources/main")) {
// we're inside a Gradle build/test, no worries
} else {
throw new IllegalArgumentException(
"Must end with ! SEE getEntry if this changes " + jarUrl);
}
}
Manifest manifest;
try (InputStream stream = manifestURL.openStream()) {
manifest = new Manifest(stream);
} catch (IOException e) {
throw Unchecked.wrap(e);
}
for (Map.Entry