Example usage for java.util.jar Manifest getMainAttributes

List of usage examples for java.util.jar Manifest getMainAttributes

Introduction

In this page you can find the example usage for java.util.jar Manifest getMainAttributes.

Prototype

public Attributes getMainAttributes() 

Source Link

Document

Returns the main Attributes for the Manifest.

Usage

From source file:de.cologneintelligence.fitgoodies.maven.FitIntegrationTestMojo.java

public File writeBootJar(String classpath) throws IOException {
    File bootJar = new File(outputDirectory, "boot.jar");

    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, classpath);

    JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(bootJar), manifest);
    jarOutputStream.close();/*from  ww w.  jav a  2  s .c om*/

    return bootJar;
}

From source file:com.lwr.software.reporter.utils.Q2RContextListener.java

@Override
public void contextInitialized(ServletContextEvent contextEvent) {
    logger.info("Creating directories if already created");

    logger.info("Creating config directory tree " + DashboardConstants.CONFIG_PATH);
    File dir = new File(DashboardConstants.CONFIG_PATH);
    if (dir.exists()) {
        logger.info("Config directory tree already exists");
    } else {/*  w w  w  . ja va 2s .  com*/
        boolean dirCreated = dir.mkdirs();
        if (dirCreated) {
            logger.info("Config directory tree created successfully");
        } else {
            logger.error("Config directory tree creation failed, please check for file permission on "
                    + DashboardConstants.CONFIG_PATH);
        }
    }

    logger.info("Creating public report directory tree " + DashboardConstants.PUBLIC_REPORT_DIR);
    dir = new File(DashboardConstants.PUBLIC_REPORT_DIR);
    if (dir.exists()) {
        logger.info("Public report directory tree already exists");
    } else {
        boolean dirCreated = dir.mkdirs();
        if (dirCreated) {
            logger.info("Public report directory tree created successfully");
        } else {
            logger.error("Public report directory tree creation failed, please check for file permission on "
                    + DashboardConstants.PUBLIC_REPORT_DIR);
        }
    }

    logger.info("Creating private report directory tree " + DashboardConstants.PRIVATE_REPORT_DIR);
    dir = new File(DashboardConstants.PRIVATE_REPORT_DIR);
    if (dir.exists()) {
        logger.info("Private report directory tree already exists");
    } else {
        boolean dirCreated = dir.mkdirs();
        if (dirCreated) {
            logger.info("Private report directory tree created successfully");
        } else {
            logger.error("Private report directory tree creation failed, please check for file permission on "
                    + DashboardConstants.PRIVATE_REPORT_DIR);
        }
    }

    logger.info("Creating private report directory tree " + DashboardConstants.APPLN_TEMP_DIR);
    dir = new File(DashboardConstants.APPLN_TEMP_DIR);
    if (dir.exists()) {
        logger.info("Private report directory tree already exists");
    } else {
        boolean dirCreated = dir.mkdirs();
        if (dirCreated) {
            logger.info("Private report directory tree created successfully");
        } else {
            logger.error("Private report directory tree creation failed, please check for file permission on "
                    + DashboardConstants.APPLN_TEMP_DIR);
        }
    }

    File logoFile = new File(DashboardConstants.APPLN_LOGO_FILE);
    if (logoFile.exists()) {
        String appLogo = contextEvent.getServletContext().getRealPath("/") + File.separatorChar + "images"
                + File.separatorChar + "q2r.png";
        File appLogoFile = new File(appLogo);
        logger.info("Coping of custom logo file " + logoFile.getAbsolutePath() + " to folder "
                + appLogoFile.getAbsolutePath());
        try {
            Files.copy(logoFile, appLogoFile);
            logger.info("Coping of custom logo file " + logoFile.getAbsolutePath() + " to folder "
                    + appLogoFile.getAbsolutePath() + " -- Copied");
        } catch (IOException e) {
            logger.error("Coping of custom logo file " + logoFile.getAbsolutePath() + " to folder "
                    + appLogoFile.getAbsolutePath() + " -- Failed", e);
        }
    }

    Q2RProperties.getInstance();
    logger.info("Loading build time from manifest file");
    try {
        InputStream inputStream = getClass().getClassLoader().getResourceAsStream("/META-INF/MANIFEST.MF");
        Manifest manifest = new Manifest(inputStream);
        String buildTime = manifest.getMainAttributes().getValue("Build-Time");
        logger.info("Build time is " + buildTime);
        if (buildTime != null)
            Q2RProperties.getInstance().put("buildTime", buildTime);
    } catch (IOException e) {
        logger.error("Error loading manifest file", e);
    }
}

From source file:org.sonar.updatecenter.common.PluginManifest.java

private void loadManifest(Manifest manifest) {
    Attributes attributes = manifest.getMainAttributes();
    this.key = attributes.getValue(KEY);
    this.mainClass = attributes.getValue(MAIN_CLASS);
    this.name = attributes.getValue(NAME);
    this.description = attributes.getValue(DESCRIPTION);
    this.license = attributes.getValue(LICENSE);
    this.organization = attributes.getValue(ORGANIZATION);
    this.organizationUrl = attributes.getValue(ORGANIZATION_URL);
    this.version = attributes.getValue(VERSION);
    this.homepage = attributes.getValue(HOMEPAGE);
    this.termsConditionsUrl = attributes.getValue(TERMS_CONDITIONS_URL);
    this.sonarVersion = attributes.getValue(SONAR_VERSION);
    this.issueTrackerUrl = attributes.getValue(ISSUE_TRACKER_URL);
    this.buildDate = toDate(attributes.getValue(BUILD_DATE), true);

    String deps = attributes.getValue(DEPENDENCIES);
    this.dependencies = StringUtils.split(StringUtils.defaultString(deps), ' ');
}

From source file:org.echocat.jomon.runtime.ManifestInformationFactory.java

@Nullable
protected String getManifestValue(@Nonnull Name mainAttributes, @Nonnull Manifest of) {
    final String result;
    final Object plainVersion = of.getMainAttributes().get(mainAttributes);
    if (plainVersion != null) {
        result = plainVersion.toString();
    } else {/*from w  ww. j a v a2s  . c o  m*/
        result = null;
    }
    return result;
}

From source file:org.echocat.nodoodle.transport.HandlerPacker.java

protected Manifest createManifest(String dataFileName, Collection<String> dependencyFileNames) {
    if (dataFileName == null) {
        throw new NullPointerException();
    }/*from   ww  w .ja  v a  2  s .  co  m*/
    if (dependencyFileNames == null) {
        throw new NullPointerException();
    }
    final Manifest manifest = new Manifest();
    final Attributes mainAttributes = manifest.getMainAttributes();
    mainAttributes.put(MANIFEST_VERSION, "1.0");
    mainAttributes.put(new Attributes.Name("Created-By"), getSmappserVersionString());
    mainAttributes.put(CLASS_PATH, StringUtils.join(dependencyFileNames, ' '));

    final Attributes extensionAttributes = new Attributes();
    extensionAttributes.put(MANIFEST_DATE_FILE, dataFileName);
    manifest.getEntries().put(MANIFEST_EXTENSION_NAME, extensionAttributes);
    return manifest;
}

From source file:org.apache.phoenix.end2end.UserDefinedFunctionsIT.java

/**
 * Compiles the test class with bogus code into a .class file.
 * Upon finish, the bogus jar will be left at dynamic.jar.dir location
 *///from w ww  .j av a  2 s .co  m
private static void compileTestClass(String className, String program, int counter) throws Exception {
    String javaFileName = className + ".java";
    File javaFile = new File(javaFileName);
    String classFileName = className + ".class";
    File classFile = new File(classFileName);
    String jarName = "myjar" + counter + ".jar";
    String jarPath = "." + File.separator + jarName;
    File jarFile = new File(jarPath);
    try {
        String packageName = "org.apache.phoenix.end2end";
        FileOutputStream fos = new FileOutputStream(javaFileName);
        fos.write(program.getBytes());
        fos.close();

        JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
        int result = jc.run(null, null, null, javaFileName);
        assertEquals(0, result);

        Manifest manifest = new Manifest();
        manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
        FileOutputStream jarFos = new FileOutputStream(jarPath);
        JarOutputStream jarOutputStream = new JarOutputStream(jarFos, manifest);
        String pathToAdd = packageName.replace('.', '/') + '/';
        String jarPathStr = new String(pathToAdd);
        Set<String> pathsInJar = new HashSet<String>();

        while (pathsInJar.add(jarPathStr)) {
            int ix = jarPathStr.lastIndexOf('/', jarPathStr.length() - 2);
            if (ix < 0) {
                break;
            }
            jarPathStr = jarPathStr.substring(0, ix);
        }
        for (String pathInJar : pathsInJar) {
            jarOutputStream.putNextEntry(new JarEntry(pathInJar));
            jarOutputStream.closeEntry();
        }

        jarOutputStream.putNextEntry(new JarEntry(pathToAdd + classFile.getName()));
        byte[] allBytes = new byte[(int) classFile.length()];
        FileInputStream fis = new FileInputStream(classFile);
        fis.read(allBytes);
        fis.close();
        jarOutputStream.write(allBytes);
        jarOutputStream.closeEntry();
        jarOutputStream.close();
        jarFos.close();

        assertTrue(jarFile.exists());
        Connection conn = driver.connect(url, EMPTY_PROPS);
        Statement stmt = conn.createStatement();
        stmt.execute("add jars '" + jarFile.getAbsolutePath() + "'");
    } finally {
        if (javaFile != null)
            javaFile.delete();
        if (classFile != null)
            classFile.delete();
        if (jarFile != null)
            jarFile.delete();
    }
}

From source file:org.musicrecital.webapp.listener.StartupListener.java

/**
 * {@inheritDoc}/*  ww  w.jav  a2  s  . c  om*/
 */
@SuppressWarnings("unchecked")
public void contextInitialized(ServletContextEvent event) {
    log.debug("Initializing context...");

    ServletContext context = event.getServletContext();

    // Orion starts Servlets before Listeners, so check if the config
    // object already exists
    Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG);

    if (config == null) {
        config = new HashMap<String, Object>();
    }

    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);

    PasswordEncoder passwordEncoder = null;
    try {
        ProviderManager provider = (ProviderManager) ctx
                .getBean("org.springframework.security.authentication.ProviderManager#0");
        for (Object o : provider.getProviders()) {
            AuthenticationProvider p = (AuthenticationProvider) o;
            if (p instanceof RememberMeAuthenticationProvider) {
                config.put("rememberMeEnabled", Boolean.TRUE);
            } else if (ctx.getBean("passwordEncoder") != null) {
                passwordEncoder = (PasswordEncoder) ctx.getBean("passwordEncoder");
            }
        }
    } catch (NoSuchBeanDefinitionException n) {
        log.debug("authenticationManager bean not found, assuming test and ignoring...");
        // ignore, should only happen when testing
    }

    context.setAttribute(Constants.CONFIG, config);

    // output the retrieved values for the Init and Context Parameters
    if (log.isDebugEnabled()) {
        log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled"));
        if (passwordEncoder != null) {
            log.debug("Password Encoder: " + passwordEncoder.getClass().getSimpleName());
        }
        log.debug("Populating drop-downs...");
    }

    setupContext(context);

    // Determine version number for CSS and JS Assets
    String appVersion = null;
    try {
        InputStream is = context.getResourceAsStream("/META-INF/MANIFEST.MF");
        if (is == null) {
            log.warn("META-INF/MANIFEST.MF not found.");
        } else {
            Manifest mf = new Manifest();
            mf.read(is);
            Attributes atts = mf.getMainAttributes();
            appVersion = atts.getValue("Implementation-Version");
        }
    } catch (IOException e) {
        log.error("I/O Exception reading manifest: " + e.getMessage());
    }

    // If there was a build number defined in the war, then use it for
    // the cache buster. Otherwise, assume we are in development mode
    // and use a random cache buster so developers don't have to clear
    // their browser cache.
    if (appVersion == null || appVersion.contains("SNAPSHOT")) {
        appVersion = "" + new Random().nextInt(100000);
    }

    log.info("Application version set to: " + appVersion);
    context.setAttribute(Constants.ASSETS_VERSION, appVersion);
}

From source file:com.kotcrab.vis.editor.plugin.PluginDescriptor.java

public PluginDescriptor(FileHandle file, Manifest manifest) throws EditorException {
    this.file = file;
    folderName = file.parent().name();/* www. ja  v a2  s .  co m*/
    libs.addAll(file.parent().child("lib").list());

    Attributes attributes = manifest.getMainAttributes();

    id = attributes.getValue(PLUGIN_ID);
    name = attributes.getValue(PLUGIN_NAME);
    description = attributes.getValue(PLUGIN_DESCRIPTION);
    provider = attributes.getValue(PLUGIN_PROVIDER);
    version = attributes.getValue(PLUGIN_VERSION);
    String comp = attributes.getValue(PLUGIN_COMPATIBILITY);
    String licenseFile = attributes.getValue(PLUGIN_LICENSE);

    if (id == null || name == null || description == null || provider == null || version == null
            || comp == null)
        throw new EditorException("Missing one of required field in plugin manifest, plugin: " + file.name());

    try {
        compatibility = Integer.valueOf(comp);
    } catch (NumberFormatException e) {
        throw new EditorException("Failed to parse compatibility code, value must be integer!", e);
    }

    if (licenseFile != null && !licenseFile.isEmpty()) {
        JarFile jar = null;
        try {
            jar = new JarFile(file.file());
            JarEntry licenseEntry = jar.getJarEntry(licenseFile);
            license = StreamUtils.copyStreamToString(jar.getInputStream(licenseEntry));
        } catch (Exception e) {
            throw new EditorException("Failed to read license file for plugin: " + file.name(), e);
        } finally {
            IOUtils.closeQuietly(jar);
        }
    }
}

From source file:at.gv.egiz.bku.spring.ConfigurationFactoryBean.java

protected Configuration getVersionConfiguration() throws IOException {

    Map<String, Object> map = new HashMap<String, Object>();
    map.put(MOCCA_IMPLEMENTATIONNAME_PROPERTY, "MOCCA");

    // implementation version
    String version = null;// w w  w. ja v  a2 s. c o m
    try {
        Resource resource = resourceLoader.getResource("META-INF/MANIFEST.MF");
        Manifest properties = new Manifest(resource.getInputStream());
        Attributes attributes = properties.getMainAttributes();
        // TODO: replace by Implementation-Version ?
        version = attributes.getValue("Implementation-Build");
    } catch (Exception e) {
        log.warn("Failed to get implemenation version from manifest. {}", e.getMessage());
    }

    if (version == null) {
        version = "UNKNOWN";
    }
    map.put(MOCCA_IMPLEMENTATIONVERSION_PROPERTY, version);

    // signature layout
    try {
        String classContainer = JarLocation.get(CreateXMLSignatureCommandImpl.class);
        URL manifestUrl = new URL("jar:" + classContainer + "!/META-INF/MANIFEST.MF");
        log.debug(manifestUrl.toString());
        Manifest manifest = new Manifest(manifestUrl.openStream());
        Attributes attributes = manifest.getMainAttributes();
        String signatureLayout = attributes.getValue("SignatureLayout");
        if (signatureLayout != null) {
            map.put(SIGNATURE_LAYOUT_PROPERTY, signatureLayout);
        }
    } catch (Exception e) {
        log.warn("Failed to get signature layout from manifest.", e);
    }

    return new MapConfiguration(map);
}

From source file:org.sonarsource.sonarlint.core.plugin.PluginManifest.java

private void loadManifest(Manifest manifest) {
    Attributes attributes = manifest.getMainAttributes();
    this.key = PluginKeyUtils.sanitize(attributes.getValue(KEY_ATTRIBUTE));
    this.mainClass = attributes.getValue(MAIN_CLASS_ATTRIBUTE);
    this.name = attributes.getValue(NAME_ATTRIBUTE);
    this.version = attributes.getValue(VERSION_ATTRIBUTE);
    this.sonarVersion = attributes.getValue(SONAR_VERSION_ATTRIBUTE);
    this.useChildFirstClassLoader = StringUtils
            .equalsIgnoreCase(attributes.getValue(USE_CHILD_FIRST_CLASSLOADER), "true");
    String slSupported = attributes.getValue(SONARLINT_SUPPORTED);
    this.sonarLintSupported = slSupported != null ? StringUtils.equalsIgnoreCase(slSupported, "true") : null;
    this.basePlugin = attributes.getValue(BASE_PLUGIN);
    this.implementationBuild = attributes.getValue(IMPLEMENTATION_BUILD);

    String deps = attributes.getValue(DEPENDENCIES_ATTRIBUTE);
    this.dependencies = StringUtils.split(StringUtils.defaultString(deps), ' ');

    String requires = attributes.getValue(REQUIRE_PLUGINS_ATTRIBUTE);
    this.requirePlugins = StringUtils.split(StringUtils.defaultString(requires), ',');
}