Search in sources :

Example 1 with JAVA

use of aQute.bnd.osgi.Clazz.JAVA in project bnd by bndtools.

the class JavaElement method getLocalAPI.

private Element getLocalAPI() throws Exception {
    Set<Element> result = new HashSet<Element>();
    for (Map.Entry<PackageRef, List<Element>> entry : packages.entrySet()) {
        List<Element> set = entry.getValue();
        for (Iterator<Element> i = set.iterator(); i.hasNext(); ) {
            if (notAccessible.contains(analyzer.getTypeRefFromFQN(i.next().getName())))
                i.remove();
        }
        String version = exports.get(entry.getKey()).get(Constants.VERSION_ATTRIBUTE);
        if (version != null) {
            Version v = new Version(version);
            set.add(new Element(VERSION, v.getWithoutQualifier().toString(), null, IGNORED, IGNORED, null));
        }
        Element pd = new Element(PACKAGE, entry.getKey().getFQN(), set, MINOR, MAJOR, null);
        result.add(pd);
    }
    for (JAVA java : javas) {
        result.add(new Element(CLASS_VERSION, java.toString(), null, CHANGED, CHANGED, null));
    }
    return new Element(API, "<api>", result, CHANGED, CHANGED, null);
}
Also used : JAVA(aQute.bnd.osgi.Clazz.JAVA) Version(aQute.bnd.version.Version) List(java.util.List) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with JAVA

use of aQute.bnd.osgi.Clazz.JAVA in project bnd by bndtools.

the class Analyzer method calcManifest.

/**
	 * One of the main workhorses of this class. This will analyze the current
	 * setup and calculate a new manifest according to this setup.
	 * 
	 * @throws IOException
	 */
public Manifest calcManifest() throws Exception {
    try {
        analyze();
        Manifest manifest = new Manifest();
        Attributes main = manifest.getMainAttributes();
        main.put(Attributes.Name.MANIFEST_VERSION, "1.0");
        main.putValue(BUNDLE_MANIFESTVERSION, "2");
        boolean noExtraHeaders = "true".equalsIgnoreCase(getProperty(NOEXTRAHEADERS));
        if (!noExtraHeaders) {
            main.putValue(CREATED_BY, System.getProperty("java.version") + " (" + System.getProperty("java.vendor") + ")");
            main.putValue(TOOL, "Bnd-" + getBndVersion());
            main.putValue(BND_LASTMODIFIED, "" + System.currentTimeMillis());
        }
        String exportHeader = printClauses(exports, true);
        if (exportHeader.length() > 0)
            main.putValue(EXPORT_PACKAGE, exportHeader);
        else
            main.remove(EXPORT_PACKAGE);
        // Divide imports with resolution:=dynamic to DynamicImport-Package
        // and add them to the existing DynamicImport-Package instruction
        Pair<Packages, Parameters> regularAndDynamicImports = divideRegularAndDynamicImports();
        Packages regularImports = regularAndDynamicImports.getFirst();
        if (!regularImports.isEmpty()) {
            main.putValue(IMPORT_PACKAGE, printClauses(regularImports));
        } else {
            main.remove(IMPORT_PACKAGE);
        }
        Parameters dynamicImports = regularAndDynamicImports.getSecond();
        if (!dynamicImports.isEmpty()) {
            main.putValue(DYNAMICIMPORT_PACKAGE, printClauses(dynamicImports));
        } else {
            main.remove(DYNAMICIMPORT_PACKAGE);
        }
        Packages temp = new Packages(contained);
        temp.keySet().removeAll(exports.keySet());
        for (Iterator<PackageRef> i = temp.keySet().iterator(); i.hasNext(); ) {
            String binary = i.next().getBinary();
            Resource r = dot.getResource(binary);
            if (r != null)
                i.remove();
        }
        if (!temp.isEmpty())
            main.putValue(PRIVATE_PACKAGE, printClauses(temp));
        else
            main.remove(PRIVATE_PACKAGE);
        Parameters bcp = getBundleClasspath();
        if (bcp.isEmpty() || (bcp.containsKey(".") && bcp.size() == 1))
            main.remove(BUNDLE_CLASSPATH);
        else
            main.putValue(BUNDLE_CLASSPATH, printClauses(bcp));
        // ----- Require/Capabilities section
        Parameters requirements = new Parameters(annotationHeaders.getHeader(REQUIRE_CAPABILITY), this);
        Parameters capabilities = new Parameters(annotationHeaders.getHeader(PROVIDE_CAPABILITY), this);
        //
        // Do any contracts contracts
        //
        contracts.addToRequirements(requirements);
        if (//
        !isTrue(getProperty(NOEE)) && // no use otherwise
        !ees.isEmpty() && // we want people to not have to
        since(About._2_3) && // automatically add it
        !// and
        requirements.containsKey(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE)) // it
        // should
        // not
        // be
        // there
        // already
        {
            JAVA highest = ees.last();
            Attrs attrs = new Attrs();
            String filter = doEEProfiles(highest);
            attrs.put(Constants.FILTER_DIRECTIVE, filter);
            //
            // Java 1.8 introduced profiles.
            // If -eeprofile= auto | (<profile>="...")+ is set then
            // we add a
            requirements.add(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE, attrs);
        }
        if (!requirements.isEmpty())
            main.putValue(REQUIRE_CAPABILITY, requirements.toString());
        if (!capabilities.isEmpty())
            main.putValue(PROVIDE_CAPABILITY, capabilities.toString());
        // -----
        doNamesection(dot, manifest);
        for (Enumeration<?> h = getProperties().propertyNames(); h.hasMoreElements(); ) {
            String header = (String) h.nextElement();
            if (header.trim().length() == 0) {
                warning("Empty property set with value: %s", getProperties().getProperty(header));
                continue;
            }
            if (isMissingPlugin(header.trim())) {
                error("Missing plugin for command %s", header);
            }
            if (!Character.isUpperCase(header.charAt(0))) {
                if (header.charAt(0) == '@')
                    doNameSection(manifest, header);
                continue;
            }
            if (header.equals(BUNDLE_CLASSPATH) || header.equals(EXPORT_PACKAGE) || header.equals(IMPORT_PACKAGE) || header.equals(DYNAMICIMPORT_PACKAGE) || header.equals(REQUIRE_CAPABILITY) || header.equals(PROVIDE_CAPABILITY))
                continue;
            if (header.equalsIgnoreCase("Name")) {
                error("Your bnd file contains a header called 'Name'. This interferes with the manifest name section.");
                continue;
            }
            if (Verifier.HEADER_PATTERN.matcher(header).matches()) {
                doHeader(main, header);
            } else {
            // TODO should we report?
            }
        }
        //
        // Ensure we pick up any headers only set by the
        // annotations (see AnnotationHeaders)
        //
        doHeader(main, BUNDLE_LICENSE);
        doHeader(main, BUNDLE_DEVELOPERS);
        doHeader(main, BUNDLE_CONTRIBUTORS);
        doHeader(main, BUNDLE_COPYRIGHT);
        doHeader(main, BUNDLE_DOCURL);
        doHeader(main, BUNDLE_LICENSE);
        doHeader(main, BUNDLE_CATEGORY);
        // Copy old values into new manifest, when they
        // exist in the old one, but not in the new one
        merge(manifest, dot.getManifest());
        //
        // Calculate the bundle symbolic name if it is
        // not set.
        // 1. set
        // 2. name of properties file (must be != bnd.bnd)
        // 3. name of directory, which is usualy project name
        //
        String bsn = getBsn();
        if (main.getValue(BUNDLE_SYMBOLICNAME) == null) {
            main.putValue(BUNDLE_SYMBOLICNAME, bsn);
        }
        //
        if (main.getValue(BUNDLE_NAME) == null) {
            main.putValue(BUNDLE_NAME, bsn);
        }
        if (main.getValue(BUNDLE_VERSION) == null)
            main.putValue(BUNDLE_VERSION, "0");
        // Remove all the headers mentioned in -removeheaders
        Instructions instructions = new Instructions(mergeProperties(REMOVEHEADERS));
        Collection<Object> result = instructions.select(main.keySet(), false);
        main.keySet().removeAll(result);
        // dot.setManifest(manifest);
        return manifest;
    } catch (Exception e) {
        // information. So to help diagnostics. We do a full property dump
        throw new IllegalStateException("Calc manifest failed, state=\n" + getFlattenedProperties(), e);
    }
}
Also used : JAVA(aQute.bnd.osgi.Clazz.JAVA) Parameters(aQute.bnd.header.Parameters) Attributes(java.util.jar.Attributes) Attrs(aQute.bnd.header.Attrs) Manifest(java.util.jar.Manifest) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef)

Example 3 with JAVA

use of aQute.bnd.osgi.Clazz.JAVA in project bnd by bndtools.

the class ClassReferenceTest method doit.

public void doit(String p) throws Exception {
    Properties properties = new Properties();
    properties.put("-classpath", "compilerversions/compilerversions.jar");
    System.out.println("compiler version " + p);
    Builder builder = new Builder();
    properties.put(Constants.EEPROFILE, "auto");
    properties.put("Export-Package", p);
    builder.setProperties(properties);
    Jar jar = builder.build();
    assertTrue(builder.check());
    JAVA highestEE = builder.getHighestEE();
    Map<String, Set<String>> profiles = highestEE.getProfiles();
    if (profiles != null) {
        System.out.println("profiles" + profiles);
        jar.getManifest().write(System.out);
    }
    assertTrue(builder.check());
    Manifest manifest = jar.getManifest();
    String imports = manifest.getMainAttributes().getValue("Import-Package");
    assertTrue("Package " + p + "contains swing ref ", imports.indexOf("javax.swing") >= 0);
    assertFalse("Package " + p + "should not contain ClassRef", imports.indexOf("ClassRef") >= 0);
}
Also used : JAVA(aQute.bnd.osgi.Clazz.JAVA) Set(java.util.Set) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties) Manifest(java.util.jar.Manifest)

Aggregations

JAVA (aQute.bnd.osgi.Clazz.JAVA)3 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)2 Manifest (java.util.jar.Manifest)2 Attrs (aQute.bnd.header.Attrs)1 Parameters (aQute.bnd.header.Parameters)1 Builder (aQute.bnd.osgi.Builder)1 Jar (aQute.bnd.osgi.Jar)1 Version (aQute.bnd.version.Version)1 MultiMap (aQute.lib.collections.MultiMap)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Attributes (java.util.jar.Attributes)1