Search in sources :

Example 36 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class Verifier method verifyRequirements.

private void verifyRequirements() throws IllegalArgumentException, Exception {
    Parameters map = parseHeader(manifest.getMainAttributes().getValue(Constants.REQUIRE_CAPABILITY));
    for (String key : map.keySet()) {
        verifyNamespace(key, "Require");
        Attrs attrs = map.get(key);
        verify(attrs, "filter:", FILTERPATTERN, false, "Requirement %s filter not correct", key);
        String filter = attrs.get("filter:");
        if (filter != null) {
            String verify = new Filter(filter).verify();
            if (verify != null)
                error("Invalid filter syntax in requirement %s=%s. Reason %s", key, attrs, verify);
        }
        verify(attrs, "cardinality:", CARDINALITY_PATTERN, false, "Requirement %s cardinality not correct", key);
        verify(attrs, "resolution:", RESOLUTION_PATTERN, false, "Requirement %s resolution not correct", key);
        if (key.equals("osgi.extender")) {
        // No requirements on extender
        } else if (key.equals("osgi.serviceloader")) {
        } else if (key.equals("osgi.contract")) {
        } else if (key.equals("osgi.service")) {
        } else if (key.equals("osgi.ee")) {
        } else if (key.equals("osgi.native")) {
        } else if (key.equals("osgi.identity")) {
        } else if (key.startsWith("osgi.wiring.")) {
            error("%s namespace must not be specified with generic requirements", key);
        }
        verifyAttrs(key, attrs);
        if (attrs.containsKey("mandatory:"))
            error("%s directive is intended for Capabilities, not Requirement %s", "mandatory:", key);
        if (attrs.containsKey("uses:"))
            error("%s directive is intended for Capabilities, not Requirement %s", "uses:", key);
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Filter(aQute.lib.filter.Filter) Attrs(aQute.bnd.header.Attrs)

Example 37 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class Verifier method verifyImports.

/**
	 * Verify that the imports properly use version ranges.
	 */
private void verifyImports() {
    if (isStrict()) {
        Parameters map = parseHeader(manifest.getMainAttributes().getValue(Constants.IMPORT_PACKAGE));
        Set<String> noimports = new HashSet<String>();
        Set<String> toobroadimports = new HashSet<String>();
        for (Entry<String, Attrs> e : map.entrySet()) {
            String version = e.getValue().get(Constants.VERSION_ATTRIBUTE);
            if (version == null) {
                if (!e.getKey().startsWith("javax.")) {
                    noimports.add(e.getKey());
                }
            } else {
                if (!VERSIONRANGE.matcher(version).matches()) {
                    Location location = error("Import Package %s has an invalid version range syntax %s", e.getKey(), version).location();
                    location.header = Constants.IMPORT_PACKAGE;
                    location.context = e.getKey();
                } else {
                    try {
                        VersionRange range = new VersionRange(version);
                        if (!range.isRange()) {
                            toobroadimports.add(e.getKey());
                        }
                        if (range.includeHigh() == false && range.includeLow() == false && range.getLow().equals(range.getHigh())) {
                            Location location = error("Import Package %s has an empty version range syntax %s, likely want to use [%s,%s]", e.getKey(), version, range.getLow(), range.getHigh()).location();
                            location.header = Constants.IMPORT_PACKAGE;
                            location.context = e.getKey();
                        }
                    // TODO check for exclude low, include high?
                    } catch (Exception ee) {
                        Location location = exception(ee, "Import Package %s has an invalid version range syntax %s: %s", e.getKey(), version, ee).location();
                        location.header = Constants.IMPORT_PACKAGE;
                        location.context = e.getKey();
                    }
                }
            }
        }
        if (!noimports.isEmpty()) {
            Location location = error("Import Package clauses without version range (excluding javax.*): %s", noimports).location();
            location.header = Constants.IMPORT_PACKAGE;
        }
        if (!toobroadimports.isEmpty()) {
            Location location = error("Import Package clauses which use a version instead of a version range. This imports EVERY later package and not as many expect until the next major number: %s", toobroadimports).location();
            location.header = Constants.IMPORT_PACKAGE;
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) VersionRange(aQute.bnd.version.VersionRange) HashSet(java.util.HashSet)

Example 38 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class Verifier method verifyDynamicImportPackage.

/**
	 * <pre>
	 *          DynamicImport-Package ::= dynamic-description
	 *              ( ',' dynamic-description )*
	 *              
	 *          dynamic-description::= wildcard-names ( ';' parameter )*
	 *          wildcard-names ::= wildcard-name ( ';' wildcard-name )*
	 *          wildcard-name ::= package-name 
	 *                         | ( package-name '.*' ) // See 1.4.2
	 *                         | '*'
	 * </pre>
	 */
private void verifyDynamicImportPackage() {
    verifyListHeader(Constants.DYNAMICIMPORT_PACKAGE, WILDCARDPACKAGE, true);
    String dynamicImportPackage = get(Constants.DYNAMICIMPORT_PACKAGE);
    if (dynamicImportPackage == null)
        return;
    Parameters map = main.getDynamicImportPackage();
    for (String name : map.keySet()) {
        name = name.trim();
        if (!verify(name, WILDCARDPACKAGE))
            error(Constants.DYNAMICIMPORT_PACKAGE + " header contains an invalid package name: %s", name);
        Map<String, String> sub = map.get(name);
        if (r3 && sub.size() != 0) {
            error("DynamicPackage-Import has attributes on import: %s. This is however, an <=R3 bundle and attributes on this header were introduced in R4.", name);
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters)

Example 39 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class BndrunResolveContext method init.

/**
	 * Initializes the resolver. Here we will load all the information from the
	 * model.
	 */
@Override
public synchronized void init() {
    if (initialized)
        return;
    initialized = true;
    try {
        if (getLevel() <= 0) {
            Integer level = Converter.cnv(Integer.class, properties.getProperty("-resolvedebug", "0"));
            if (level != null)
                setLevel(level);
        }
        loadPreferences();
        Processor augments = loadRepositories();
        constructBlacklist(augments);
        Map<String, Set<String>> effectiveSet = loadEffectiveSet();
        if (effectiveSet != null)
            addEffectiveSet(effectiveSet);
        //
        // Create a resource from the -runrequire that contains
        // all the requirement
        //
        setInputResource(constructInputRequirements());
        //
        // We gradually build up the system resource that contains
        // the system packages, the EE, etc.
        //
        ResourceBuilder system = new ResourceBuilder();
        //
        // Let's identify the system resource to make it look less
        // ugly
        //
        //
        // If we have a distro, we do not load the environment
        // settings
        //
        String distro = properties.mergeProperties(Constants.DISTRO);
        if (distro != null && !distro.trim().isEmpty()) {
            loadPath(system, distro, Constants.DISTRO);
            loadProvidedCapabilities(system);
        } else {
            //
            // Load the EE's and packages that belong to it.
            //
            EE tmp = EE.parse(properties.getProperty(Constants.RUNEE));
            EE ee = (tmp != null) ? tmp : EE.JavaSE_1_6;
            system.addAllExecutionEnvironments(ee);
            //
            // We make the system packages as coming from the system
            // resource
            //
            Parameters systemPackages = new Parameters(properties.mergeProperties(Constants.RUNSYSTEMPACKAGES), project);
            system.addExportPackages(systemPackages);
            //
            // We make the system capabilities as coming from the system
            // resource
            //
            Parameters systemCapabilities = new Parameters(properties.mergeProperties(Constants.RUNSYSTEMCAPABILITIES), project);
            system.addProvideCapabilities(systemCapabilities);
            loadProvidedCapabilities(system);
            //
            // Load the frameworks capabilities
            //
            loadFramework(system);
            //
            // Analyze the path and add all exported packages and provided
            // capabilities
            // to the system resource
            //
            String runpath = properties.mergeProperties(Constants.RUNPATH);
            if (runpath != null && !runpath.trim().isEmpty())
                loadPath(system, runpath, Constants.RUNPATH);
        }
        //
        // We've not gathered all the capabilities of the system
        // so we can create the resource and set it as the system resource
        //
        //
        // TODO Add osgi.wiring.bundle + osgi.wiring.host
        // filed a bug about using the impl version for the system
        // capabilities
        //
        List<Capability> frameworkPackages = system.findCapabilities(PackageNamespace.PACKAGE_NAMESPACE, "(" + PackageNamespace.PACKAGE_NAMESPACE + "=org.osgi.framework)");
        if (!frameworkPackages.isEmpty()) {
            Capability c = frameworkPackages.get(0);
            Version version = (Version) c.getAttributes().get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
            CapReqBuilder crb = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE);
            crb.addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, "system.bundle");
            crb.addAttribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
            system.addCapability(crb);
        }
        setSystemResource(system.build());
    } catch (Exception e) {
        log.log(LogService.LOG_ERROR, e.getMessage(), e);
        throw new RuntimeException(e);
    }
    super.init();
}
Also used : EE(aQute.bnd.build.model.EE) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Processor(aQute.bnd.osgi.Processor) Set(java.util.Set) HashSet(java.util.HashSet) Parameters(aQute.bnd.header.Parameters) Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version)

Example 40 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class BndrunResolveContext method constructInputRequirements.

Resource constructInputRequirements() throws Exception {
    ResourceBuilder resBuilder = new ResourceBuilder();
    CapReqBuilder identity = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, IDENTITY_INITIAL_RESOURCE);
    resBuilder.addCapability(identity);
    Parameters inputRequirements = new Parameters(properties.mergeProperties(Constants.RUNREQUIRES), project);
    if (inputRequirements != null && !inputRequirements.isEmpty()) {
        List<Requirement> requires = CapReqBuilder.getRequirementsFrom(inputRequirements);
        resBuilder.addRequirements(requires);
    }
    return resBuilder.build();
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Parameters(aQute.bnd.header.Parameters)

Aggregations

Parameters (aQute.bnd.header.Parameters)167 Attrs (aQute.bnd.header.Attrs)80 File (java.io.File)45 Jar (aQute.bnd.osgi.Jar)44 Manifest (java.util.jar.Manifest)39 Builder (aQute.bnd.osgi.Builder)35 Domain (aQute.bnd.osgi.Domain)24 ArrayList (java.util.ArrayList)23 Map (java.util.Map)19 Attributes (java.util.jar.Attributes)17 IOException (java.io.IOException)15 HashMap (java.util.HashMap)15 Version (aQute.bnd.version.Version)11 HashSet (java.util.HashSet)10 Instructions (aQute.bnd.osgi.Instructions)9 FileNotFoundException (java.io.FileNotFoundException)8 Properties (java.util.Properties)8 Matcher (java.util.regex.Matcher)8 Analyzer (aQute.bnd.osgi.Analyzer)7 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)7