Example usage for java.util.jar Attributes getValue

List of usage examples for java.util.jar Attributes getValue

Introduction

In this page you can find the example usage for java.util.jar Attributes getValue.

Prototype

public String getValue(Name name) 

Source Link

Document

Returns the value of the specified Attributes.Name, or null if the attribute was not found.

Usage

From source file:test.BuilderTest.java

public static void testBsnAssignmentNoFile() throws Exception {
    Properties p = new Properties();
    p.setProperty("Private-Package", "org.objectweb.asm");
    Attributes m = setup(p, null).getMainAttributes();

    // We use properties so the default BSN is then the project name
    // because that is the base directory
    assertEquals(m.getValue("Bundle-SymbolicName"), "biz.aQute.bndlib.tests");

    // The file name for the properties is not bnd.bnd, so the
    // name of the properties file is the default bsn
    m = setup(null, IO.getFile("src/test/com.acme/defaultbsn.bnd")).getMainAttributes();
    assertEquals("com.acme.defaultbsn", m.getValue("Bundle-SymbolicName"));

    // If the file is called bnd.bnd, then we take the parent directory
    m = setup(null, IO.getFile("src/test/com.acme/bnd.bnd")).getMainAttributes();
    assertEquals("com.acme", m.getValue("Bundle-SymbolicName"));

    // If the file is called bnd.bnd, then we take the parent directory
    m = setup(null, IO.getFile("src/test/com.acme/setsbsn.bnd")).getMainAttributes();
    assertEquals("is.a.set.bsn", m.getValue("Bundle-SymbolicName"));

    // This sets the bsn, se we should see it back
    p.setProperty("Bundle-SymbolicName", "this.is.my.test");
    m = setup(p, null).getMainAttributes();
    assertEquals(m.getValue("Bundle-SymbolicName"), "this.is.my.test");
}

From source file:org.apache.catalina.loader.WebappClassLoader.java

/**
 * Returns true if the specified package name is sealed according to the
 * given manifest./*from   www . j a v  a2s.co  m*/
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name + "/";
    Attributes attr = man.getAttributes(path);
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);

}

From source file:test.BuilderTest.java

/**
 * Test private imports. We first build a jar with a import:=private packge.
 * Then place it// ww  w  .j  av a  2 s  .  c o  m
 * 
 * @throws Exception
 */

public static void testClassnames() throws Exception {
    Builder b = new Builder();
    try {
        b.addClasspath(IO.getFile("jar/osgi.jar"));
        b.addClasspath(IO.getFile("jar/ds.jar"));
        b.addClasspath(IO.getFile("jar/ifc112.jar"));
        b.setProperty("Export-Package", "*");
        b.setProperty("C1", "${classes;implementing;org.osgi.service.component.*}");
        b.setProperty("C2", "${classes;extending;org.xml.sax.helpers.*}");
        b.setProperty("C3", "${classes;importing;org.xml.sax}");
        b.setProperty("C4", "${classes;named;*Parser*}");
        b.setProperty("C5", "${classes;named;*Parser*;version;45.*}");
        Jar jar = b.build();
        assertTrue(b.check());

        Manifest m = jar.getManifest();
        m.write(System.err);
        Attributes main = m.getMainAttributes();
        assertList(asl(
                "org.eclipse.equinox.ds.service.ComponentContextImpl,org.eclipse.equinox.ds.service.ComponentFactoryImpl,org.eclipse.equinox.ds.service.ComponentInstanceImpl"),
                asl(main.getValue("C1")));
        assertList(asl("org.eclipse.equinox.ds.parser.ElementHandler, "
                + "org.eclipse.equinox.ds.parser.IgnoredElement,"
                + "org.eclipse.equinox.ds.parser.ImplementationElement,"
                + "org.eclipse.equinox.ds.parser.ParserHandler, "
                + "org.eclipse.equinox.ds.parser.PropertiesElement,"
                + "org.eclipse.equinox.ds.parser.PropertyElement, "
                + "org.eclipse.equinox.ds.parser.ProvideElement, "
                + "org.eclipse.equinox.ds.parser.ReferenceElement, "
                + "org.eclipse.equinox.ds.parser.ServiceElement,"
                + "org.eclipse.equinox.ds.parser.ComponentElement"), asl(main.getValue("C2")));
        assertList(asl(
                "org.eclipse.equinox.ds.parser.ComponentElement,org.eclipse.equinox.ds.parser.ElementHandler,org.eclipse.equinox.ds.parser.IgnoredElement,org.eclipse.equinox.ds.parser.ImplementationElement,org.eclipse.equinox.ds.parser.Parser,org.eclipse.equinox.ds.parser.ParserHandler,org.eclipse.equinox.ds.parser.PropertiesElement,org.eclipse.equinox.ds.parser.PropertyElement,org.eclipse.equinox.ds.parser.ProvideElement,org.eclipse.equinox.ds.parser.ReferenceElement,org.eclipse.equinox.ds.parser.ServiceElement"),
                asl(main.getValue("C3")));
        assertList(asl(
                "org.eclipse.equinox.ds.parser.XMLParserNotAvailableException,org.eclipse.equinox.ds.parser.Parser,org.eclipse.equinox.ds.parser.ParserHandler,netscape.application.HTMLParser,org.eclipse.equinox.ds.parser.ParserConstants,org.osgi.util.xml.XMLParserActivator"),
                asl(main.getValue("C4")));
        assertEquals("netscape.application.HTMLParser", main.getValue("C5"));
    } finally {
        b.close();
    }
}

From source file:org.apache.hive.beeline.BeeLine.java

String getManifestAttribute(String name) {
    try {/*from w w w .  ja v a 2s. c  o  m*/
        Manifest m = getManifest();
        if (m == null) {
            return "??";
        }

        Attributes attrs = m.getAttributes("beeline");
        if (attrs == null) {
            return "???";
        }

        String val = attrs.getValue(name);
        if (val == null || "".equals(val)) {
            return "????";
        }

        return val;
    } catch (Exception e) {
        e.printStackTrace(errorStream);
        return "?????";
    }
}

From source file:me.azenet.UHPlugin.UHPluginCommand.java

/**
 * This command prints some informations about the plugin and the translation.
 * /*from  ww  w  .j  av  a2s.c o m*/
 * Usage: /uh about
 * 
 * @param sender
 * @param command
 * @param label
 * @param args
 */
@SuppressWarnings("unused")
private void doAbout(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player)
        sender.sendMessage("");
    sender.sendMessage(
            i.t("cmd.titleHelp", p.getDescription().getDescription(), p.getDescription().getVersion()));

    // Authors

    String authors = "";
    List<String> listAuthors = p.getDescription().getAuthors();
    for (String author : listAuthors) {
        if (author == listAuthors.get(0)) {
            // Nothing
        } else if (author == listAuthors.get(listAuthors.size() - 1)) {
            authors += " " + i.t("about.and") + " ";
        } else {
            authors += ", ";
        }
        authors += author;
    }
    sender.sendMessage(i.t("about.authors", authors));

    // Build number

    String build = null;
    try {
        Class<? extends UHPlugin> clazz = p.getClass();
        String className = clazz.getSimpleName() + ".class";
        String classPath = clazz.getResource(className).toString();
        if (classPath.startsWith("jar")) { // Class from JAR
            String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1)
                    + "/META-INF/MANIFEST.MF";
            Manifest manifest = new Manifest(new URL(manifestPath).openStream());
            Attributes attr = manifest.getMainAttributes();

            build = attr.getValue("Git-Commit");
        }
    } catch (IOException e) {
        // Build not available.
    }

    if (build != null) {
        sender.sendMessage(i.t("about.build.number", build));
    } else {
        sender.sendMessage(i.t("about.build.notAvailable"));
    }

    // Translation

    sender.sendMessage(i.t("about.i18n.title"));
    sender.sendMessage(
            i.t("about.i18n.selected", i.getSelectedLanguage(), i.getTranslator(i.getSelectedLanguage())));
    sender.sendMessage(
            i.t("about.i18n.fallback", i.getDefaultLanguage(), i.getTranslator(i.getDefaultLanguage())));
    sender.sendMessage(i.t("about.license.title"));
    sender.sendMessage(i.t("about.license.license"));
}