use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class StateBuilder method validateHeaders.
private static void validateHeaders(Dictionary<String, String> manifest, boolean jreBundle) throws BundleException {
for (int i = 0; i < DEFINED_OSGI_VALIDATE_HEADERS.length; i++) {
String header = manifest.get(DEFINED_OSGI_VALIDATE_HEADERS[i]);
if (header != null) {
ManifestElement[] elements = ManifestElement.parseHeader(DEFINED_OSGI_VALIDATE_HEADERS[i], header);
checkForDuplicateDirectivesAttributes(DEFINED_OSGI_VALIDATE_HEADERS[i], elements);
if (DEFINED_OSGI_VALIDATE_HEADERS[i] == Constants.IMPORT_PACKAGE)
checkImportExportSyntax(DEFINED_OSGI_VALIDATE_HEADERS[i], elements, false, false, jreBundle);
if (DEFINED_OSGI_VALIDATE_HEADERS[i] == Constants.DYNAMICIMPORT_PACKAGE)
checkImportExportSyntax(DEFINED_OSGI_VALIDATE_HEADERS[i], elements, false, true, jreBundle);
if (DEFINED_OSGI_VALIDATE_HEADERS[i] == Constants.EXPORT_PACKAGE)
checkImportExportSyntax(DEFINED_OSGI_VALIDATE_HEADERS[i], elements, true, false, jreBundle);
if (DEFINED_OSGI_VALIDATE_HEADERS[i] == Constants.FRAGMENT_HOST)
checkExtensionBundle(DEFINED_OSGI_VALIDATE_HEADERS[i], elements);
} else if (DEFINED_OSGI_VALIDATE_HEADERS[i] == Constants.BUNDLE_SYMBOLICNAME) {
throw new BundleException(NLS.bind(StateMsg.HEADER_REQUIRED, Constants.BUNDLE_SYMBOLICNAME), BundleException.MANIFEST_ERROR);
}
}
}
use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class StateBuilder method createBundleDescription.
static BundleDescription createBundleDescription(StateImpl state, Dictionary<String, String> manifest, String location) throws BundleException {
BundleDescriptionImpl result = new BundleDescriptionImpl();
String manifestVersionHeader = manifest.get(Constants.BUNDLE_MANIFESTVERSION);
// $NON-NLS-1$
boolean jreBundle = "true".equals(manifest.get(StateImpl.Eclipse_JREBUNDLE));
int manifestVersion = 1;
if (manifestVersionHeader != null)
manifestVersion = Integer.parseInt(manifestVersionHeader);
if (manifestVersion >= 2)
validateHeaders(manifest, jreBundle);
// retrieve the symbolic-name and the singleton status
String symbolicNameHeader = manifest.get(Constants.BUNDLE_SYMBOLICNAME);
if (symbolicNameHeader != null) {
ManifestElement[] symbolicNameElements = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, symbolicNameHeader);
if (symbolicNameElements.length > 0) {
ManifestElement bsnElement = symbolicNameElements[0];
result.setSymbolicName(bsnElement.getValue());
String singleton = bsnElement.getDirective(Constants.SINGLETON_DIRECTIVE);
if (// TODO this is for backward compatibility; need to check manifest version < 2 to allow this after everyone has converted to new syntax
singleton == null)
singleton = bsnElement.getAttribute(Constants.SINGLETON_DIRECTIVE);
// $NON-NLS-1$
result.setStateBit(BundleDescriptionImpl.SINGLETON, "true".equals(singleton));
String fragmentAttachment = bsnElement.getDirective(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE);
if (fragmentAttachment != null) {
if (fragmentAttachment.equals(Constants.FRAGMENT_ATTACHMENT_RESOLVETIME)) {
result.setStateBit(BundleDescriptionImpl.ATTACH_FRAGMENTS, true);
result.setStateBit(BundleDescriptionImpl.DYNAMIC_FRAGMENTS, false);
} else if (fragmentAttachment.equals(Constants.FRAGMENT_ATTACHMENT_NEVER)) {
result.setStateBit(BundleDescriptionImpl.ATTACH_FRAGMENTS, false);
result.setStateBit(BundleDescriptionImpl.DYNAMIC_FRAGMENTS, false);
}
}
result.setDirective(Constants.MANDATORY_DIRECTIVE, ManifestElement.getArrayFromList(bsnElement.getDirective(Constants.MANDATORY_DIRECTIVE)));
result.setAttributes(getAttributes(bsnElement, DEFINED_BSN_MATCHING_ATTRS));
result.setArbitraryDirectives(getDirectives(bsnElement, DEFINED_BSN_DIRECTIVES));
}
}
// retrieve other headers
String version = manifest.get(Constants.BUNDLE_VERSION);
try {
result.setVersion((version != null) ? Version.parseVersion(version) : Version.emptyVersion);
} catch (IllegalArgumentException ex) {
if (manifestVersion >= 2) {
String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, Constants.BUNDLE_VERSION, version);
// $NON-NLS-1$
throw new BundleException(message + " : " + ex.getMessage(), BundleException.MANIFEST_ERROR, ex);
}
// prior to R4 the Bundle-Version header was not interpreted by the Framework;
// must not fail for old R3 style bundles
}
result.setLocation(location);
result.setPlatformFilter(manifest.get(StateImpl.ECLIPSE_PLATFORMFILTER));
String[] brees = ManifestElement.getArrayFromList(manifest.get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT));
result.setExecutionEnvironments(brees);
ManifestElement[] host = ManifestElement.parseHeader(Constants.FRAGMENT_HOST, manifest.get(Constants.FRAGMENT_HOST));
if (host != null)
result.setHost(createHostSpecification(host[0], state));
ManifestElement[] exports = ManifestElement.parseHeader(Constants.EXPORT_PACKAGE, manifest.get(Constants.EXPORT_PACKAGE));
ManifestElement[] provides = ManifestElement.parseHeader(StateImpl.PROVIDE_PACKAGE, manifest.get(StateImpl.PROVIDE_PACKAGE));
boolean strict = state != null && state.inStrictMode();
List<String> providedExports = new ArrayList<>(provides == null ? 0 : provides.length);
result.setExportPackages(createExportPackages(exports, provides, providedExports, strict));
ManifestElement[] imports = ManifestElement.parseHeader(Constants.IMPORT_PACKAGE, manifest.get(Constants.IMPORT_PACKAGE));
ManifestElement[] dynamicImports = ManifestElement.parseHeader(Constants.DYNAMICIMPORT_PACKAGE, manifest.get(Constants.DYNAMICIMPORT_PACKAGE));
result.setImportPackages(createImportPackages(result.getExportPackages(), providedExports, imports, dynamicImports, manifestVersion));
ManifestElement[] requires = ManifestElement.parseHeader(Constants.REQUIRE_BUNDLE, manifest.get(Constants.REQUIRE_BUNDLE));
result.setRequiredBundles(createRequiredBundles(requires));
String[][] genericAliases = getGenericAliases(state);
ManifestElement[] genericRequires = getGenericRequires(manifest, genericAliases);
ManifestElement[] osgiRequires = ManifestElement.parseHeader(Constants.REQUIRE_CAPABILITY, manifest.get(Constants.REQUIRE_CAPABILITY));
result.setGenericRequires(createGenericRequires(genericRequires, osgiRequires, brees));
ManifestElement[] genericCapabilities = getGenericCapabilities(manifest, genericAliases);
ManifestElement[] osgiCapabilities = ManifestElement.parseHeader(Constants.PROVIDE_CAPABILITY, manifest.get(Constants.PROVIDE_CAPABILITY));
result.setGenericCapabilities(createGenericCapabilities(genericCapabilities, osgiCapabilities, result));
ManifestElement[] nativeCode = ManifestElement.parseHeader(Constants.BUNDLE_NATIVECODE, manifest.get(Constants.BUNDLE_NATIVECODE));
result.setNativeCodeSpecification(createNativeCode(nativeCode));
return result;
}
use of org.eclipse.osgi.util.ManifestElement in project tycho by eclipse.
the class SourceBundlesNestedJarsTest method testDistinctSourceRoots.
@Test
public void testDistinctSourceRoots() throws Exception {
Verifier verifier = getVerifier("sourceBundle.nestedJars", false);
verifier.executeGoal("package");
verifier.verifyErrorFreeLog();
File sourceJar = new File(verifier.getBasedir(), "target/test.distinct.sourceroots-1.0.0-sources.jar");
assertTrue(sourceJar.isFile());
JarFile jar = new JarFile(sourceJar);
try {
String sourceBundleHeader = jar.getManifest().getMainAttributes().getValue("Eclipse-SourceBundle");
ManifestElement element = ManifestElement.parseHeader("", sourceBundleHeader)[0];
String[] roots = element.getDirective("roots").split(",");
assertEquals(new HashSet<>(asList(".", "foosrc", "barsrc")), new HashSet<>(asList(roots)));
assertNotNull(jar.getEntry("Main.java"));
assertNotNull(jar.getEntry("foosrc/Foo1.java"));
assertNotNull(jar.getEntry("foosrc/Foo2.java"));
assertNotNull(jar.getEntry("barsrc/Bar1.java"));
assertNotNull(jar.getEntry("barsrc/Bar2.java"));
} finally {
jar.close();
}
}
use of org.eclipse.osgi.util.ManifestElement in project eclipse.jdt.ls by eclipse.
the class BundleUtils method getBundleInfo.
private static BundleInfo getBundleInfo(String bundleLocation) throws IOException, BundleException {
try (JarFile jarFile = new JarFile(bundleLocation)) {
Manifest manifest = jarFile.getManifest();
if (manifest != null) {
Attributes mainAttributes = manifest.getMainAttributes();
if (mainAttributes != null) {
String bundleVersion = mainAttributes.getValue(Constants.BUNDLE_VERSION);
if (StringUtils.isBlank(bundleVersion)) {
return null;
}
String symbolicName = mainAttributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
boolean isSingleton = false;
if (StringUtils.isNotBlank(symbolicName)) {
ManifestElement[] symbolicNameElements = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, symbolicName);
if (symbolicNameElements.length > 0) {
symbolicName = symbolicNameElements[0].getValue();
String singleton = symbolicNameElements[0].getDirective(Constants.SINGLETON_DIRECTIVE);
isSingleton = "true".equals(singleton);
}
}
return new BundleInfo(bundleVersion, symbolicName, isSingleton);
}
}
}
return null;
}
Aggregations