Package java.util.jar

Examples of java.util.jar.Attributes$Name


    }

    private void augmentImports(Builder builder, Jar jar, IBldBundle bundle)
        throws IOException
    {
        Attributes main = jar.getManifest().getMainAttributes();
        String impHeader = main.getValue(Constants.IMPORT_PACKAGE);
        Map<String, Map<String, String>> bndImports = Processor.parseHeader(impHeader,
            builder);

        if (bndImports.isEmpty())
            return;

        ArrayList<String> self = new ArrayList<String>();
        ArrayList<String> missing = new ArrayList<String>();
        ArrayList<String> modified = new ArrayList<String>();
        ArrayList<String> unversioned = new ArrayList<String>();

        String expHeader = main.getValue(Constants.EXPORT_PACKAGE);
        Set<String> bndExports = Processor.parseHeader(expHeader, builder).keySet();

        HashMap<String, IPackageImport> imports = new HashMap<String, IPackageImport>();
        for (IPackageImport pi : getImports(bundle))
        {
            switch (pi.getOSGiImport())
            {
                case NEVER:
                    break;
                case ALWAYS:
                    String pkg = pi.getPackageName();
                    if (!bndImports.containsKey(pkg))
                    {
                        // Bnd doesn't think this import is needed - but we know
                        // better
                        HashMap<String, String> attrs = new HashMap<String, String>();
                        attrs.put(BldAttr.VERSION_ATTRIBUTE, pi.getVersions().toString());
                        bndImports.put(pkg, attrs);
                        modified.add(pkg + ";resolve=runtime");
                    }
                    // fall thru */
                case AUTO:
                    imports.put(pi.getPackageName(), pi);
                    break;
            }
        }

        boolean importDot = false;

        for (String pkg : bndImports.keySet())
        {
            unused.remove(pkg);
            Map<String, String> attrs = bndImports.get(pkg);
            String currentVersion = (String) attrs.get(BldAttr.VERSION_ATTRIBUTE);
            IPackageImport pi = imports.get(pkg);

            if (pi != null)
            {
                VersionRange range = pi.getVersions();
                String version = range.toString();

                if (!version.equals(currentVersion)
                    && !range.equals(VersionRange.ANY_VERSION))
                {
                    attrs.put(BldAttr.VERSION_ATTRIBUTE, version);
                    if (pi.isOptional())
                        attrs.put(BldAttr.RESOLUTION_ATTRIBUTE,
                            BldAttr.RESOLUTION_OPTIONAL);
                    modified.add(pkg + ";version=" + version
                        + (pi.isOptional() ? ";optional" : ""));
                }
                else if ((currentVersion == null) && !systemPkgs.contains(pkg))
                {
                    unversioned.add(pkg);
                }
            }
            else
            {
                // bnd added the import ...
                if (currentVersion == null)
                {
                    String defaultVersion = project.getDefaultPackageVersion(pkg);
                    if (defaultVersion != null)
                    {
                        attrs.put(BldAttr.VERSION_ATTRIBUTE, defaultVersion);
                        currentVersion = defaultVersion;
                    }
                }

                String imp = pkg
                    + (currentVersion == null ? "" : ";version=" + currentVersion);
                if (bndExports.contains(pkg))
                {
                    self.add(imp);
                }
                else
                {
                    if (pkg.equals("."))
                    {
                        warnings.add("Bnd wants to import '.' (ignored)");
                        importDot = true;
                    }
                    else
                    {
                        missing.add(imp);
                    }
                }
            }
        }

        if (!modified.isEmpty() || importDot)
        {
            if (importDot)
                bndImports.remove(".");
            // warnings.add("INFO: sigil modified imports: " + modified);
            main.putValue(Constants.IMPORT_PACKAGE, Processor.printClauses(bndImports,
                "resolution:"));
        }

        if (!self.isEmpty())
        {
View Full Code Here


        Manifest mf = getManifest(zip);
       
        if (mf != null)
        {
            Attributes attrs = mf.getMainAttributes();
            String name = attrs.getValue("Bundle-SymbolicName");
            if (name == null)
            {
                // framework.jar doesn't have Bundle-SymbolicName!
                name = attrs.getValue("Bundle-Name");
            }

            if (name != null)
            {
                try
                {
                    info = ModelElementFactory.getInstance().newModelElement(
                        IBundleModelElement.class);
                    info.setSymbolicName(name.split(";")[0]);
                    info.setVersion(VersionTable.getVersion(attrs.getValue("Bundle-Version")));
                    info.setName(attrs.getValue("Bundle-Name"));
                    info.setDescription(attrs.getValue("Bundle-Description"));
                    info.setVendor(attrs.getValue("Bundle-Vendor"));

                    String str = attrs.getValue("Import-Package");
                    if (str != null)
                    {
                        addImports(info, str);
                    }

                    str = attrs.getValue("Export-Package");
                    if (str != null)
                    {
                        addExports(info, str);
                    }

                    str = attrs.getValue("Require-Bundle");
                    if (str != null)
                    {
                        addRequires(info, str);
                    }

                    str = attrs.getValue("Bundle-Classpath");

                    if (str != null)
                    {
                        addClasspath(info, str);
                    }

                    str = attrs.getValue("Fragment-Host");
                    if (str != null)
                    {
                        addHost(info, str);
                    }
                }
View Full Code Here

        }
       
        mainAttributes = manifest.getMainAttributes();       
        if (mainAttributes == null)
        {
            mainAttributes = new Attributes();
        }
       
        String val = mainAttributes.getValue(Constants.BUNDLE_CLASSPATH);
        if (val != null)
        {
            parseBundleClassPath(val, currentInnerJars);
        }

        // look for mangen rules in manifest
        mangenAttributes = manifest.getAttributes("com/ascert/openosgi/mangen");
        if (mangenAttributes == null)
        {
            mangenAttributes = new Attributes();
        }
       
        bundleRuleHandler = new RuleHandler(mangenAttributes);
    }
View Full Code Here

     * exports etc.
     */
    protected Manifest updateHeaders()
    {
        Manifest newManifest = new Manifest(manifest);
        Attributes newAtts = newManifest.getMainAttributes();
       
        // First determine whether to mark for R3 or R4 usage
        String val = PropertyManager.getProperty("mangen.osgi.level", "3");
        if (val.equals("4"))
        {
            newAtts.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
        }
        else
        {
            newAtts.putValue(Constants.BUNDLE_MANIFESTVERSION, "1");
        }

        putValueIfNotEmpty(newAtts, Constants.EXPORT_PACKAGE, getAsHeaderValue(possibleExports));
        putValueIfNotEmpty(newAtts, Constants.IMPORT_PACKAGE, getAsHeaderValue(possibleImports));
        //TODO: implement generation of bundle classpath if mangen.innerjar.auto set
View Full Code Here

    }

    public static boolean hasEmbedComponents(Analyzer analyzer) throws Exception {
        for (Jar jar : analyzer.getClasspath()) {
            // Check if the bundle was manipulated before
            Attributes attr = jar.getManifest().getMainAttributes();
            if (getComponents(attr) != null) {
                return true;
            }
        }
        return false;
View Full Code Here

                // Is it a Bundle ?
                if (jar.getBsn() != null) {
                    // OSGi Bundle case

                    // Check if the bundle was manipulated before
                    Attributes attr = jar.getManifest().getMainAttributes();
                    if (Manifests.getComponents(attr) != null) {
                        // Bundle has been previously manipulated
                        // TODO We should ignore the resource since it was already manipulated
                        // TODO But we should also merge its IPOJO-Components header
                    } else {
View Full Code Here

        if (m_includeEmbedComponents) {
            // Incorporate metadata of embed dependencies (if any)
            for (Jar jar : m_analyzer.getClasspath()) {
                try {
                    Manifest manifest = jar.getManifest();
                    Attributes main = manifest.getMainAttributes();
                    String components = Manifests.getComponents(main);
                    if (components != null) {
                        m_reporter.trace("Merging components from %s", jar.getName());
                        builder.append(components);
                    }
View Full Code Here

        if ((manifest == null) || (manifest.getMainAttributes() == null)) {
            throw new DeploymentException(CODE_BAD_HEADER);
        }
        m_manifest = manifest;

        Attributes mainAttributes = m_manifest.getMainAttributes();

        // TODO: verify symbolic name and entry-names for valid format/chars
        m_symbolicName = getNonNullHeader(mainAttributes.getValue(DEPLOYMENTPACKAGE_SYMBOLICMAME));

        String version = getNonNullHeader(mainAttributes.getValue(DEPLOYMENTPACKAGE_VERSION));
        try {
            m_version = new Version(version);
        }
        catch (IllegalArgumentException e) {
            throw new DeploymentException(CODE_BAD_HEADER);
        }

        String fixPackage = mainAttributes.getValue(DEPLOYMENTPACKAGE_FIXPACK);
        if (fixPackage != null) {
            try {
                m_fixPackage = VersionRange.parse(fixPackage);
            }
            catch (IllegalArgumentException iae) {
View Full Code Here

        try
        {
            Manifest mf = findManifest(uri);
            if (mf == null)
                return null;
            Attributes attr = mf.getMainAttributes();
            String bsn = attr.getValue(Constants.BUNDLE_SYMBOLICNAME);
            String ver = attr.getValue(Constants.BUNDLE_VERSION);
            BundleStatus st = new BundleStatus();
            st.setBundleSymbolicName(bsn);
            st.setVersion(ver);
            st.setLocation(uri.toURL().toExternalForm());
            st.setStatus(started ? Bundle.ACTIVE : Bundle.INSTALLED);
View Full Code Here

    private DataModelHelper dmh = new DataModelHelperImpl();

    public void testResource() throws Exception
    {
        Attributes attr = new Attributes();
        attr.putValue("Manifest-Version", "1.0");
        attr.putValue("Bundle-Name", "Apache Felix Utils");
        attr.putValue("Bundle-Version", "0.1.0.SNAPSHOT");
        attr.putValue("Bundle-ManifestVersion", "2");
        attr.putValue("Bundle-License", "http://www.apache.org/licenses/LICENSE-2.0.txt");
        attr.putValue("Bundle-Description", "Utility classes for OSGi.");
        attr.putValue("Import-Package", "org.osgi.framework;version=\"[1.4,2)\"");
        attr.putValue("Bundle-SymbolicName", "org.apache.felix.utils");

        Resource resource = dmh.createResource(attr);

        String xml = dmh.writeResource(resource);
        System.out.println(xml);
View Full Code Here

TOP

Related Classes of java.util.jar.Attributes$Name

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.