Example usage for java.util.jar Manifest Manifest

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

Introduction

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

Prototype

public Manifest() 

Source Link

Document

Constructs a new, empty Manifest.

Usage

From source file:com.aliyun.odps.mapred.BridgeJobRunner.java

/**
 * Create jar with jobconf./*from  w  ww  .j  a va  2  s . c o  m*/
 *
 * @return
 * @throws OdpsException
 */
private ByteArrayOutputStream createJarArchive() throws OdpsException {
    try {
        ByteArrayOutputStream archiveOut = new ByteArrayOutputStream();
        // Open archive file
        JarOutputStream out = new JarOutputStream(archiveOut, new Manifest());

        ByteArrayOutputStream jobOut = new ByteArrayOutputStream();
        job.writeXml(jobOut);
        // Add jobconf entry
        JarEntry jobconfEntry = new JarEntry("jobconf.xml");
        out.putNextEntry(jobconfEntry);
        out.write(jobOut.toByteArray());

        out.close();
        return archiveOut;
    } catch (IOException ex) {
        throw new OdpsException(ErrorCode.UNEXPECTED.toString(), ex);
    }
}

From source file:org.craftercms.commons.monitoring.VersionMonitor.java

/**
 * Gets the current VersionMonitor base on a Class that will load it's manifest file.
 * @param clazz Class that will load the manifest MF file
 * @return A {@link VersionMonitor} pojo with the information.
 * @throws IOException If Unable to read the Manifest file.
 *///  w w  w  . j  a  v a2  s  . co  m
public static VersionMonitor getVersion(Class clazz) throws IOException {
    Manifest manifest = new Manifest();
    manifest.read(clazz.getResourceAsStream(MANIFEST_PATH));
    return getVersion(manifest);
}

From source file:pxb.android.tinysign.TinySign.java

private static Manifest generateSF(Manifest manifest)
        throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest md = MessageDigest.getInstance("SHA1");
    PrintStream print = new PrintStream(new DigestOutputStream(new OutputStream() {

        @Override/*from  w  ww. j av  a  2 s  .c o  m*/
        public void write(byte[] arg0) throws IOException {
        }

        @Override
        public void write(byte[] arg0, int arg1, int arg2) throws IOException {
        }

        @Override
        public void write(int arg0) throws IOException {
        }
    }, md), true, "UTF-8");
    Manifest sf = new Manifest();
    Map<String, Attributes> entries = manifest.getEntries();
    for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
        // Digest of the manifest stanza for this entry.
        print.print("Name: " + entry.getKey() + "\r\n");
        for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
            print.print(att.getKey() + ": " + att.getValue() + "\r\n");
        }
        print.print("\r\n");
        print.flush();

        Attributes sfAttr = new Attributes();
        sfAttr.putValue("SHA1-Digest", eBase64(md.digest()));
        sf.getEntries().put(entry.getKey(), sfAttr);
    }
    return sf;
}

From source file:rubah.tools.ConversionClassGenerator.java

public void generateConversionClasses(File outJar) throws IOException {

    FileOutputStream fos = new FileOutputStream(outJar);
    JarOutputStream jos = new JarOutputStream(fos, new Manifest());

    for (Clazz cl : this.namespace.getDefinedClasses()) {
        this.addConversionClassesToJar(jos, cl);
    }/*from  ww  w . j a  v a 2  s.c o  m*/

    jos.close();
    fos.close();

}

From source file:io.fabric8.vertx.maven.plugin.utils.PackageHelper.java

/**
 *
 *///from   w w w.j  a v a 2  s . c  o  m
protected void generateManifest() {
    Manifest manifest = new Manifest();
    Attributes attributes = manifest.getMainAttributes();
    attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    attributes.put(Attributes.Name.MAIN_CLASS, mainClass);
    //This is a typical situation when application is launched with custom launcher
    if (mainVerticle != null) {
        attributes.put(MAIN_VERTICLE, mainVerticle);
    }

    try {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        manifest.write(bout);
        bout.close();
        byte[] bytes = bout.toByteArray();
        //TODO: merge existing manifest with current one
        this.archive.setManifest(new ByteArrayAsset(bytes));
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.pongasoft.kiwidoc.builder.KiwidocBuilder.java

/**
 * Builds the kiwidoc for the given library
 *
 * @param library (optional, <code>null</code> ok) dependencies
 * @return the model builder//from  w  ww.  j  av  a 2 s . c o  m
 * @throws BuilderException when there is a problem indexing
 */
public LibraryModelBuilder buildKiwidoc(Library library) throws IOException, BuilderException {
    Set<BuiltFrom> builtFrom = EnumSet.noneOf(BuiltFrom.class);
    Manifest manifest = null;

    LibraryModelBuilder libFromByteCode = null;

    // if we have the library itself (jar file)
    if (library.classes != null) {
        builtFrom.add(BuiltFrom.BYTECODE);

        // manifest
        FileObject manifestResource = library.classes.resolveFile("META-INF/MANIFEST.MF");
        if (manifestResource.exists()) {
            manifest = new Manifest();
            InputStream is = manifestResource.getContent().getInputStream();
            try {
                manifest.read(new BufferedInputStream(is));
            } finally {
                is.close();
            }
        }

        // byte code
        libFromByteCode = new LibraryModelBuilder(library.libraryVersionResource);
        new ByteCodeParser().parseClasses(libFromByteCode, library.classes);
    }

    LibraryModelBuilder libFromSource = null;
    // if we have the source code
    if (library.sources != null) {
        try {
            libFromSource = new LibraryModelBuilder(library.libraryVersionResource);
            if (libFromByteCode != null)
                libFromSource.setJdkVersion(libFromByteCode.getJdkVersion());
            else
                libFromSource.setJdkVersion(library.jdkVersion);

            int sourceCount = new SourceCodeParser().parseSources(libFromSource, library.sources,
                    library.overviewFilename, library.publicOnly ? library.javadoc : null, library.classpath);

            if (sourceCount == 0) {
                libFromSource = null;
                log.warn("No sources found in " + library.sources);
            } else {
                builtFrom.add(BuiltFrom.SOURCE);
            }
        } catch (IOException e) {
            throw e;
        } catch (Throwable th) {
            throw new BuilderException(th);
        }
    }

    // compute which version to use (source code wins if available)
    LibraryModelBuilder lib = new LibraryModelBuilder(library.libraryVersionResource);

    if (libFromByteCode != null) {
        lib = libFromByteCode;
    }

    if (libFromSource != null) {
        lib = libFromSource;
    }

    log.info("Processed source|bytecode: " + (libFromSource == null ? "N/A" : libFromSource.getClassCount())
            + " | " + (libFromByteCode == null ? "N/A" : libFromByteCode.getClassCount()));

    // TODO MED YP: use byte code for resolving unresolved types during javadoc processing  

    // if we have the original javadoc (used for determining exported classes)
    if (library.javadoc != null) {
        builtFrom.add(BuiltFrom.JAVADOC);

        for (PackageModelBuilder packageModelBuilder : lib.getAllPackages()) {
            for (ClassModelBuilder classModelBuilder : packageModelBuilder.getAllClasses()) {
                String javadocFile = classModelBuilder.getFqcn();
                javadocFile = javadocFile.replace('.', '/');
                javadocFile = javadocFile.replace('$', '.'); // for inner classes
                javadocFile += ".html";

                try {
                    classModelBuilder.setExportedClass(
                            library.javadoc.resolveFile(javadocFile, NameScope.DESCENDENT).exists());
                } catch (FileSystemException e) {
                    log.warn("Error while setting exported class on " + javadocFile + " ["
                            + classModelBuilder.getFqcn() + "]", e);
                }
            }
        }
    }

    // dependencies
    lib.setDependencies(library.dependencies);

    // manifest
    lib.setManifest(manifest);

    // built from
    lib.addBuiltFrom(builtFrom);

    return lib;
}

From source file:org.apache.hadoop.yarn.util.TestFSDownload.java

static LocalResource createJar(FileContext files, Path p, LocalResourceVisibility vis) throws IOException {
    LOG.info("Create jar file " + p);
    File jarFile = new File((files.makeQualified(p)).toUri());
    FileOutputStream stream = new FileOutputStream(jarFile);
    LOG.info("Create jar out stream ");
    JarOutputStream out = new JarOutputStream(stream, new Manifest());
    LOG.info("Done writing jar stream ");
    out.close();//from w ww.j  a  v  a  2 s .c  om
    LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
    ret.setResource(URL.fromPath(p));
    FileStatus status = files.getFileStatus(p);
    ret.setSize(status.getLen());
    ret.setTimestamp(status.getModificationTime());
    ret.setType(LocalResourceType.PATTERN);
    ret.setVisibility(vis);
    ret.setPattern("classes/.*");
    return ret;
}

From source file:org.sourcepit.common.maven.testing.ArtifactRepositoryFacade.java

private static File createStubJar(File dir) throws IOException {
    final File jarFile = File.createTempFile("stub", ".jar", dir);

    JarOutputStream jarOut = null;
    try {//  w  w w.  ja  v  a  2  s  .  com
        jarOut = new JarOutputStream(new FileOutputStream(jarFile));

        final JarEntry mfEntry = new JarEntry(JarFile.MANIFEST_NAME);
        jarOut.putNextEntry(mfEntry);

        final Manifest mf = new Manifest();
        mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1");
        mf.write(jarOut);

        jarOut.closeEntry();
    } finally {
        IOUtils.closeQuietly(jarOut);
    }

    return jarFile;
}

From source file:ManifestWriter.java

/** Get the Manifest object that this object created.
  * @return the Manifest that this builder created
  *///  w w  w. j ava  2  s . c  om
public Manifest getManifest() {
    try {
        Manifest m = new Manifest();
        m.read(getInputStream());
        return m;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

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

/**
 * {@inheritDoc}//from   w  w  w. j  av  a 2 s.  c o m
 */
@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);
}