use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class ContractTest method testWarningUses.
/**
* Test the warnings that we have no uses
*
* @throws Exception
*/
public void testWarningUses() throws Exception {
Jar bjara = getContractExporter("abc", "2.5", null);
Builder a = newBuilder();
a.setTrace(true);
a.addClasspath(bjara);
a.setProperty(Constants.CONTRACT, "*");
a.setImportPackage("test.packageinfo,*");
a.setProperty("Export-Package", "test.refer");
Jar ajar = a.build();
assertTrue(a.check("Contract abc has no uses: directive"));
Domain domain = Domain.domain(ajar.getManifest());
Parameters p = domain.getRequireCapability();
p.remove("osgi.ee");
assertEquals(0, p.size());
}
use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class PomFromManifest method write.
@Override
public void write(OutputStream out) throws IOException {
PrintWriter ps = IO.writer(out);
String name = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_NAME);
String description = manifest.getMainAttributes().getValue(Constants.BUNDLE_DESCRIPTION);
String docUrl = manifest.getMainAttributes().getValue(Constants.BUNDLE_DOCURL);
String bundleVendor = manifest.getMainAttributes().getValue(Constants.BUNDLE_VENDOR);
String licenses = manifest.getMainAttributes().getValue(Constants.BUNDLE_LICENSE);
Tag project = new Tag("project");
project.addAttribute("xmlns", "http://maven.apache.org/POM/4.0.0");
project.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
project.addAttribute("xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd");
project.addContent(new Tag("modelVersion").addContent("4.0.0"));
project.addContent(new Tag("groupId").addContent(getGroupId()));
project.addContent(new Tag("artifactId").addContent(getArtifactId()));
project.addContent(new Tag("version").addContent(getVersion().toString()));
if (description != null) {
new Tag(project, "description").addContent(description);
}
if (name != null) {
new Tag(project, "name").addContent(name);
}
if (projectURL != null)
new Tag(project, "url").addContent(projectURL);
else if (docUrl != null) {
new Tag(project, "url").addContent(docUrl);
} else
new Tag(project, "url").addContent("http://no-url");
String scmheader = manifest.getMainAttributes().getValue("Bundle-SCM");
if (scmheader != null)
scm.add(scmheader);
Tag scmtag = new Tag(project, "scm");
if (scm != null && !scm.isEmpty()) {
for (String cm : this.scm) {
new Tag(scmtag, "url").addContent(cm);
new Tag(scmtag, "connection").addContent(cm);
new Tag(scmtag, "developerConnection").addContent(cm);
}
} else {
new Tag(scmtag, "url").addContent("private");
new Tag(scmtag, "connection").addContent("private");
new Tag(scmtag, "developerConnection").addContent("private");
}
if (bundleVendor != null) {
Matcher m = NAME_URL.matcher(bundleVendor);
String namePart = bundleVendor;
String urlPart = this.projectURL;
if (m.matches()) {
namePart = m.group(1);
urlPart = m.group(2);
}
Tag organization = new Tag(project, "organization");
new Tag(organization, "name").addContent(namePart.trim());
if (urlPart != null) {
new Tag(organization, "url").addContent(urlPart.trim());
}
}
if (!developers.isEmpty()) {
Tag d = new Tag(project, "developers");
for (String email : developers) {
String id = email;
String xname = email;
String organization = null;
Matcher m = Pattern.compile("([^@]+)@([\\d\\w\\-_\\.]+)\\.([\\d\\w\\-_\\.]+)").matcher(email);
if (m.matches()) {
xname = m.group(1);
organization = m.group(2);
}
Tag developer = new Tag(d, "developer");
new Tag(developer, "id").addContent(id);
new Tag(developer, "name").addContent(xname);
new Tag(developer, "email").addContent(email);
if (organization != null)
new Tag(developer, "organization").addContent(organization);
}
}
if (licenses != null) {
Tag ls = new Tag(project, "licenses");
Parameters map = Processor.parseHeader(licenses, null);
for (Iterator<Entry<String, Attrs>> e = map.entrySet().iterator(); e.hasNext(); ) {
// Bundle-License:
// http://www.opensource.org/licenses/apache2.0.php; \
// description="${Bundle-Copyright}"; \
// link=LICENSE
//
// <license>
// <name>This material is licensed under the Apache
// Software License, Version 2.0</name>
// <url>http://www.apache.org/licenses/LICENSE-2.0</url>
// <distribution>repo</distribution>
// </license>
Entry<String, Attrs> entry = e.next();
Tag l = new Tag(ls, "license");
Map<String, String> values = entry.getValue();
String url = entry.getKey();
if (values.containsKey("description"))
tagFromMap(l, values, "description", "name", url);
else
tagFromMap(l, values, "name", "name", url);
tagFromMap(l, values, "url", "url", url);
tagFromMap(l, values, "distribution", "distribution", "repo");
}
}
project.print(0, ps);
ps.flush();
}
use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class MetatypeAnnotations method analyzeJar.
public boolean analyzeJar(Analyzer analyzer) throws Exception {
this.minVersion = MetatypeVersion.VERSION_1_2;
Parameters header = OSGiHeader.parseHeader(analyzer.getProperty(Constants.METATYPE_ANNOTATIONS, "*"));
if (header.size() == 0)
return false;
Parameters optionsHeader = OSGiHeader.parseHeader(analyzer.getProperty(Constants.METATYPE_ANNOTATIONS_OPTIONS));
EnumSet<Options> options = EnumSet.noneOf(Options.class);
for (Map.Entry<String, Attrs> entry : optionsHeader.entrySet()) {
try {
Options.parseOption(entry, options, this);
} catch (IllegalArgumentException e) {
analyzer.error("Unrecognized %s value %s with attributes %s, expected values are %s", Constants.METATYPE_ANNOTATIONS_OPTIONS, entry.getKey(), entry.getValue(), EnumSet.allOf(Options.class));
}
}
Map<TypeRef, OCDDef> classToOCDMap = new HashMap<TypeRef, OCDDef>();
Set<String> ocdIds = new HashSet<String>();
Set<String> pids = new HashSet<String>();
Instructions instructions = new Instructions(header);
XMLAttributeFinder finder = new XMLAttributeFinder(analyzer);
List<Clazz> list = Create.list();
for (Clazz c : analyzer.getClassspace().values()) {
for (Instruction instruction : instructions.keySet()) {
if (instruction.matches(c.getFQN())) {
if (!instruction.isNegated()) {
list.add(c);
OCDDef definition = OCDReader.getOCDDef(c, analyzer, options, finder, minVersion);
if (definition != null) {
classToOCDMap.put(c.getClassName(), definition);
}
}
break;
}
}
}
// process Designate annotations after OCD annotations
for (Clazz c : list) {
DesignateReader.getDesignate(c, analyzer, classToOCDMap, finder);
}
for (Map.Entry<TypeRef, OCDDef> entry : classToOCDMap.entrySet()) {
TypeRef c = entry.getKey();
OCDDef definition = entry.getValue();
definition.prepare(analyzer);
if (!ocdIds.add(definition.id)) {
analyzer.error("Duplicate OCD id %s from class %s; known ids %s", definition.id, c.getFQN(), ocdIds);
}
for (DesignateDef dDef : definition.designates) {
if (dDef.pid != null && !pids.add(dDef.pid)) {
analyzer.error("Duplicate pid %s from class %s", dDef.pid, c.getFQN());
}
}
String name = "OSGI-INF/metatype/" + analyzer.validResourcePath(definition.id, "Invalid resource name") + ".xml";
analyzer.getJar().putResource(name, new TagResource(definition.getTag()));
}
return false;
}
use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class OBRFragment method parse.
@SuppressWarnings("deprecation")
public static Reporter parse(Jar jar, ResourceBuilder resource) throws Exception {
Manifest m = jar.getManifest();
if (m == null)
return null;
Domain d = Domain.domain(m);
d.setTranslation(jar);
Entry<String, Attrs> bundleSymbolicName = d.getBundleSymbolicName();
if (bundleSymbolicName == null)
return null;
boolean singleton = "true".equals(bundleSymbolicName.getValue().get(Constants.SINGLETON_DIRECTIVE + ":"));
boolean isFragment = d.get(Constants.FRAGMENT_HOST) != null;
Version version = d.getBundleVersion() == null ? Version.emptyVersion : new Version(d.getBundleVersion());
CapReqBuilder identity = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE);
identity.addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, bundleSymbolicName.getKey());
identity.addAttribute(IdentityNamespace.CAPABILITY_COPYRIGHT_ATTRIBUTE, d.translate(Constants.BUNDLE_COPYRIGHT));
identity.addAttribute(IdentityNamespace.CAPABILITY_DESCRIPTION_ATTRIBUTE, d.translate(Constants.BUNDLE_DESCRIPTION));
identity.addAttribute(IdentityNamespace.CAPABILITY_DOCUMENTATION_ATTRIBUTE, d.translate(Constants.BUNDLE_DOCURL));
identity.addAttribute(IdentityNamespace.CAPABILITY_LICENSE_ATTRIBUTE, d.translate(aQute.bnd.osgi.Constants.BUNDLE_LICENSE));
if (singleton)
identity.addAttribute(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE, "true");
identity.addAttribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, isFragment ? IdentityNamespace.TYPE_FRAGMENT : IdentityNamespace.TYPE_BUNDLE);
identity.addAttribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, new Version(d.getBundleVersion()));
resource.addCapability(identity);
if (isFragment) {
//
// Fragment-Host
//
Entry<String, Attrs> fragmentHost = d.getFragmentHost();
CapReqBuilder fragment = new CapReqBuilder(HostNamespace.HOST_NAMESPACE);
String v = fragmentHost.getValue().get("version");
if (v == null)
v = "0";
Version fragmentVersion = new Version(v);
String filter = filter(PackageNamespace.PACKAGE_NAMESPACE, fragmentHost.getKey(), fragmentHost.getValue());
fragment.addDirective(HostNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
resource.addRequirement(fragment);
} else {
//
// Bundle-SymbolicName
//
CapReqBuilder bundle = new CapReqBuilder(BundleNamespace.BUNDLE_NAMESPACE);
CapReqBuilder host = new CapReqBuilder(HostNamespace.HOST_NAMESPACE);
bundle.addAttribute("version", version);
host.addAttribute("version", version);
for (Entry<String, String> e : bundleSymbolicName.getValue().entrySet()) {
String key = e.getKey();
if (key.endsWith(":")) {
String directive = key.substring(0, key.length() - 1);
if (Constants.FRAGMENT_ATTACHMENT_DIRECTIVE.equalsIgnoreCase(directive)) {
if (Constants.FRAGMENT_ATTACHMENT_NEVER.equalsIgnoreCase(e.getValue()))
host = null;
} else if (!Constants.SINGLETON_DIRECTIVE.equalsIgnoreCase(directive)) {
bundle.addDirective(directive, e.getValue());
}
if (host != null)
host.addDirective(directive, e.getValue());
bundle.addDirective(directive, e.getValue());
} else {
if (host != null)
host.addAttribute(key, e.getValue());
bundle.addAttribute(key, e.getValue());
}
}
if (host != null)
resource.addCapability(host);
resource.addCapability(bundle);
}
//
// Export-Package
//
Parameters exports = d.getExportPackage();
for (Entry<String, Attrs> entry : exports.entrySet()) {
CapReqBuilder exported = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
String pkgName = Processor.removeDuplicateMarker(entry.getKey());
exported.addAttribute(PackageNamespace.PACKAGE_NAMESPACE, pkgName);
String versionStr = entry.getValue().get(Constants.VERSION_ATTRIBUTE);
Version v = Version.parseVersion(entry.getValue().get("version"));
exported.addAttribute(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
for (Entry<String, String> attribEntry : entry.getValue().entrySet()) {
String key = attribEntry.getKey();
if (key.endsWith(":")) {
String directive = key.substring(0, key.length() - 1);
exported.addDirective(directive, attribEntry.getValue());
} else {
if (key.equals("specification-version") || key.equals("version"))
exported.addAttribute("version", Version.parseVersion(attribEntry.getValue()));
else
exported.addAttribute(key, attribEntry.getValue());
}
}
exported.addAttribute(PackageNamespace.CAPABILITY_BUNDLE_SYMBOLICNAME_ATTRIBUTE, bundleSymbolicName.getKey());
exported.addAttribute(PackageNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, version);
resource.addCapability(exported);
}
//
// Import-Package
//
Parameters imports = d.getImportPackage();
for (Entry<String, Attrs> entry : imports.entrySet()) {
CapReqBuilder imported = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
String name = Processor.removeDuplicateMarker(entry.getKey());
String filter = filter(PackageNamespace.PACKAGE_NAMESPACE, Processor.removeDuplicateMarker(entry.getKey()), entry.getValue());
imported.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
resource.addRequirement(imported);
}
//
// Require-Bundle
//
Parameters requires = d.getRequireBundle();
for (Entry<String, Attrs> entry : requires.entrySet()) {
CapReqBuilder req = new CapReqBuilder(BundleNamespace.BUNDLE_NAMESPACE);
String bsn = Processor.removeDuplicateMarker(entry.getKey());
String filter = filter(BundleNamespace.BUNDLE_NAMESPACE, bsn, entry.getValue());
req.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
resource.addRequirement(req);
}
//
// Bundle-RequiredExecutionEnvironment
//
Parameters brees = d.getBundleRequiredExecutionEnvironment();
try (Formatter formatter = new Formatter()) {
formatter.format("(|");
for (Entry<String, Attrs> bree : brees.entrySet()) {
String name = Processor.removeDuplicateMarker(bree.getKey());
Matcher matcher = EE_PATTERN.matcher(name);
if (matcher.matches()) {
name = matcher.group(1);
Version v = Version.parseVersion(matcher.group(2));
formatter.format("%s", filter(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE, name, MAP.$("version", v.toString())));
}
}
formatter.format(")");
CapReqBuilder breeReq = new CapReqBuilder(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE);
breeReq.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, formatter.toString());
for (Entry<String, Attrs> export : d.getParameters(Constants.EXPORT_SERVICE).entrySet()) {
CapReqBuilder exportedService = new CapReqBuilder(ServiceNamespace.SERVICE_NAMESPACE);
String service = Processor.removeDuplicateMarker(export.getKey());
exportedService.addAttribute(ServiceNamespace.SERVICE_NAMESPACE, service);
exportedService.addAttribute(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, export.getValue().get("objectclass"));
resource.addCapability(exportedService);
}
for (Entry<String, Attrs> imported : d.getParameters(Constants.IMPORT_SERVICE).entrySet()) {
CapReqBuilder importedService = new CapReqBuilder(ServiceNamespace.SERVICE_NAMESPACE);
String service = Processor.removeDuplicateMarker(imported.getKey());
importedService.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter(ServiceNamespace.SERVICE_NAMESPACE, service, imported.getValue()));
resource.addRequirement(importedService);
}
for (Entry<String, Attrs> rc : d.getProvideCapability().entrySet()) {
resource.addCapability(toCapability(rc.getKey(), rc.getValue()));
}
for (Entry<String, Attrs> rc : d.getRequireCapability().entrySet()) {
resource.addCapability(toRequirement(rc.getKey(), rc.getValue()));
}
}
return null;
}
use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class MetatypePlugin method analyzeJar.
public boolean analyzeJar(Analyzer analyzer) throws Exception {
Parameters map = analyzer.parseHeader(analyzer.getProperty(Constants.METATYPE));
Jar jar = analyzer.getJar();
for (String name : map.keySet()) {
Collection<Clazz> metatypes = analyzer.getClasses("", QUERY.ANNOTATED.toString(), //
"aQute.bnd.annotation.metatype.Meta$OCD", //
QUERY.NAMED.toString(), //
name);
for (Clazz c : metatypes) {
analyzer.warning("%s annotation used in class %s. Bnd metatype annotations are deprecated as of Bnd 3.2 and support will be removed in Bnd 4.0. Please change to use OSGi Metatype annotations.", "aQute.bnd.annotation.metatype.Meta$OCD", c);
jar.putResource("OSGI-INF/metatype/" + c.getFQN() + ".xml", new MetaTypeReader(c, analyzer));
}
}
return false;
}
Aggregations