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:org.apache.sling.ide.test.impl.helpers.ProjectAdapter.java

public void createOsgiBundleManifest(OsgiBundleManifest osgiManifest) throws CoreException, IOException {

    Manifest m = new Manifest();
    for (Map.Entry<String, String> entry : osgiManifest.getAttributes().entrySet()) {
        m.getMainAttributes().putValue(entry.getKey(), entry.getValue());
    }//from   w  w w.ja v  a  2  s .  c o  m

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    m.write(out);

    createOrUpdateFile(Path.fromPortableString("src/META-INF/MANIFEST.MF"),
            new ByteArrayInputStream(out.toByteArray()));
}

From source file:de.micromata.mgc.application.ManifestMgcApplicationInfo.java

protected void init() {
    if (inited == true) {
        return;/*ww w  .ja v  a 2  s.  c o m*/
    }

    Manifest manifest = findManifest();
    if (manifest == null) {
        LOG.error("Canot find MANIFEST.MF with " + MgcAppName + " defined");
        return;
    }
    name = manifest.getMainAttributes().getValue(MgcAppName);
    copyright = manifest.getMainAttributes().getValue(MgcCopyright);
    version = manifest.getMainAttributes().getValue(MgcVersion);
    detailInfo = manifest.getMainAttributes().getValue(MgcDescription);
    logoLargePath = manifest.getMainAttributes().getValue(MgcLargLogoPath);
    license = manifest.getMainAttributes().getValue(MgcLicense);
    homeUrl = manifest.getMainAttributes().getValue(MgcHomeUrl);
    helpUrl = manifest.getMainAttributes().getValue(MgcHelpUrl);
    inited = true;

}

From source file:com.amalto.core.jobox.component.JobAware.java

private boolean recognizeTISJob(File entity) {
    boolean isTISEntry = false;
    List<File> checkList = new ArrayList<File>();
    JoboxUtil.findFirstFile(null, entity, "classpath.jar", checkList); //$NON-NLS-1$
    if (checkList.size() > 0) {
        try {/*  w  ww .j a  v a 2s. c o  m*/
            JarFile jarFile = new JarFile(checkList.get(0).getAbsolutePath());
            Manifest jarFileManifest = jarFile.getManifest();
            String vendorInfo = jarFileManifest.getMainAttributes().getValue("Implementation-Vendor"); //$NON-NLS-1$
            if (vendorInfo.trim().toUpperCase().startsWith("TALEND")) //$NON-NLS-1$
                isTISEntry = true;
        } catch (IOException e) {
            throw new JoboxException(e);
        }
    }
    return isTISEntry;
}

From source file:org.nuxeo.osgi.application.BundleWalker.java

@Override
public int visitDirectory(File file) {
    // System.out.println("###### Processing DIR: " + file);
    // first check if this is a possible bundle
    String fileName = file.getName();
    if (patterns != null) {
        if (!acceptFile(fileName, patterns)) {
            return FileWalker.CONTINUE;
        }/*w  w  w  .  ja  v a  2s .  c  om*/
    }
    // check if this is an OSGi bundle
    try {
        Manifest mf = JarUtils.getDirectoryManifest(file);
        if (mf == null) {
            return FileWalker.CONTINUE;
        }
        String bundleName = mf.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
        if (bundleName != null) {
            // notify the callback about the new bundle
            callback.visitBundle(new DirectoryBundleFile(file, mf));
            // assume that a directory OSGi bundle cannot contain other bundles so skip it
            return FileWalker.BREAK;
        }
    } catch (IOException e) {
        log.error(e, e);
    }
    return FileWalker.CONTINUE;
}

From source file:org.kuali.student.common.util.ManifestInspector.java

/**
 * Examine the manifest provided for build information. Returns null if manifest is null
 */// w  w  w .j a  v  a2  s .c  o  m
protected BuildInformation getBuildInformation(Manifest manifest) {
    // No Manifest is available
    if (manifest == null) {
        return null;
    }

    // Extract the attributes
    Attributes attributes = manifest.getMainAttributes();

    // Manifest attributes containing the build information
    String name = attributes.getValue(BUNDLE_NAME);
    String version = attributes.getValue(BUNDLE_VERSION);
    String buildNumber = attributes.getValue(BUNDLE_BUILD_NUMBER);
    String timestamp = attributes.getValue(BUNDLE_TIMESTAMP);

    // Create and populate a BuildInformation object
    BuildInformation bi = new BuildInformation();
    bi.setName(name);
    bi.setVersion(version);
    bi.setBuildNumber(buildNumber);
    bi.setTimestamp(timestamp);
    return bi;
}

From source file:com.amalto.core.jobox.component.JobAware.java

private void setClassPath4TISJob(File entity, JobInfo jobInfo) {
    String newClassPath = ""; //$NON-NLS-1$
    String separator = System.getProperty("path.separator"); //$NON-NLS-1$
    List<File> checkList = new ArrayList<File>();
    JoboxUtil.findFirstFile(null, entity, "classpath.jar", checkList); //$NON-NLS-1$
    if (checkList.size() > 0) {
        try {//from  w w  w  .  j  a  va 2s . c om
            String basePath = checkList.get(0).getParent();
            JarFile jarFile = new JarFile(checkList.get(0).getAbsolutePath());
            Manifest jarFileManifest = jarFile.getManifest();
            String cxt = jarFileManifest.getMainAttributes().getValue("activeContext"); //$NON-NLS-1$
            jobInfo.setContextStr(cxt);
            String classPaths = jarFileManifest.getMainAttributes().getValue("Class-Path"); //$NON-NLS-1$
            String[] classPathsArray = classPaths.split("\\s+", 0); //$NON-NLS-1$
            List<String> classPathsArrayList = new ArrayList<String>(Arrays.asList(classPathsArray));
            List<String> classPathsExtArray = new ArrayList<String>();
            if (!classPathsArrayList.contains(".")) { //$NON-NLS-1$
                classPathsExtArray.add("."); //$NON-NLS-1$
            }
            if (classPathsArrayList.size() > 0) {
                classPathsExtArray.addAll(classPathsArrayList);
            }
            for (String classPath : classPathsExtArray) {
                File libFile = new File(basePath + File.separator + classPath);
                if (libFile.exists()) {
                    if (newClassPath.length() == 0) {
                        newClassPath += libFile.getAbsolutePath();
                    } else if (newClassPath.length() > 0) {
                        newClassPath += separator + libFile.getAbsolutePath();
                    }
                }
            }
        } catch (IOException e) {
            throw new JoboxException(e);
        }
    }
    jobInfo.setClasspath(newClassPath);
}

From source file:com.taobao.android.apatch.FastBuild.java

@Override
protected Manifest getMeta() {
    Manifest manifest = new Manifest();
    Attributes main = manifest.getMainAttributes();
    main.putValue("Manifest-Version", "1.0");
    main.putValue("Created-By", "1.0 (ApkPatch)");
    main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString());
    main.putValue("Patch-Name", name);
    main.putValue(name + "-Patch-Classes", Formater.dotStringList(classes));
    main.putValue(name + "-Prepare-Classes", Formater.dotStringList(prepareClasses));
    main.putValue(name + "-Used-Methods", Formater.dotStringList(usedMethods));
    main.putValue(name + "-Modified-Classes", Formater.dotStringList(modifiedClasses));
    main.putValue(name + "-Used-Classes", Formater.dotStringList(usedClasses));
    main.putValue(name + "-add-classes", Formater.dotStringList(addClasses));
    return manifest;
}

From source file:org.wso2.carbon.server.util.Utils.java

/**
 * Create an OSGi bundle out of a JAR file
 *
 * @param jarFile         The jarfile to be bundled
 * @param targetDir       The directory into which the created OSGi bundle needs to be placed into.
 * @param mf              The bundle manifest file
 * @param extensionPrefix Prefix, if any, for the bundle
 * @throws java.io.IOException If an error occurs while reading the jar or creating the bundle
 *///from   w w w .ja v a 2  s  .  co m
public static void createBundle(File jarFile, File targetDir, Manifest mf, String extensionPrefix)
        throws IOException {
    if (mf == null) {
        mf = new Manifest();
    }
    String exportedPackages = Utils.parseJar(jarFile);

    String fileName = jarFile.getName();
    fileName = fileName.replaceAll("-", "_");
    if (fileName.endsWith(".jar")) {
        fileName = fileName.substring(0, fileName.length() - 4);
    }
    String symbolicName = extensionPrefix + fileName;
    String pluginName = extensionPrefix + fileName + "_1.0.0.jar";
    File extensionBundle = new File(targetDir, pluginName);

    Attributes attribs = mf.getMainAttributes();
    attribs.putValue(LauncherConstants.MANIFEST_VERSION, "1.0");
    attribs.putValue(LauncherConstants.BUNDLE_MANIFEST_VERSION, "2");
    attribs.putValue(LauncherConstants.BUNDLE_NAME, fileName);
    attribs.putValue(LauncherConstants.BUNDLE_SYMBOLIC_NAME, symbolicName);
    attribs.putValue(LauncherConstants.BUNDLE_VERSION, "1.0.0");
    attribs.putValue(LauncherConstants.EXPORT_PACKAGE, exportedPackages);
    attribs.putValue(LauncherConstants.BUNDLE_CLASSPATH, ".," + jarFile.getName());

    Utils.createBundle(jarFile, extensionBundle, mf);
}

From source file:org.jasig.ssp.service.impl.ServerServiceImpl.java

private void cacheVersionProfile() throws IOException {

    InputStream mfStream = null;//from   ww w  . j  a va  2  s .  c o m
    try {
        mfStream = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF");
        Manifest mf = new Manifest(mfStream);
        final Attributes mainAttributes = mf.getMainAttributes();
        final Map<String, Object> tmpVersionProfile = new HashMap<String, Object>();
        tmpVersionProfile.put(NAME_API_FIELD_NAME, SSP_VERSION_PROFILE_NAME);

        // For SSP itself the entry format is:
        //  SSP-<EntryName>
        // e.g.:
        //  SSP-Artifact-Version
        //
        // For "extensions" the entry format is:
        //  SSP-Ext-<ExtensionName>-<EntryName>
        // e.g.:
        //  SSP-Ext-UPOverlay-Artifact-Version
        //
        // We do not want to accidentally expose any sensitive config
        // placed into the manifest. So we only output values from recognized
        // <EntryName> values.
        Map<String, Object> extensions = null;
        for (Map.Entry<Object, Object> entry : mainAttributes.entrySet()) {
            String rawEntryName = entry.getKey().toString();
            if (rawEntryName.startsWith(SSP_EXTENSION_ENTRY_PREFIX)) {
                String[] parsedEntryName = rawEntryName.split(SSP_EXTENSION_ENTRY_DELIM);
                if (parsedEntryName.length < 4) {
                    continue;
                }
                String unqualifiedEntryName = StringUtils.join(parsedEntryName, SSP_EXTENSION_ENTRY_DELIM, 3,
                        parsedEntryName.length);
                if (!(isWellKnownEntryName(unqualifiedEntryName))) {
                    continue;
                }
                String extName = parsedEntryName[2];
                if (extensions == null) {
                    extensions = new HashMap<String, Object>();
                }
                Map<String, Object> thisExtension = (Map<String, Object>) extensions.get(extName);
                if (thisExtension == null) {
                    thisExtension = new HashMap<String, Object>();
                    thisExtension.put(NAME_API_FIELD_NAME, extName);
                    extensions.put(extName, thisExtension);
                }
                mapWellKnownEntryName(unqualifiedEntryName, (String) entry.getValue(), thisExtension);
            } else if (rawEntryName.startsWith(SSP_ENTRY_PREFIX)) {
                String unqualifiedEntryName = rawEntryName.substring(SSP_ENTRY_PREFIX.length());
                if (isWellKnownEntryName(unqualifiedEntryName)) {
                    mapWellKnownEntryName(unqualifiedEntryName, (String) entry.getValue(), tmpVersionProfile);
                }
            }
        }

        if (extensions == null) {
            tmpVersionProfile.put(EXTENSIONS_API_FIELD_NAME, Collections.EMPTY_MAP);
        } else {
            tmpVersionProfile.put(EXTENSIONS_API_FIELD_NAME, Lists.newArrayList(extensions.values()));
        }

        this.versionProfile = tmpVersionProfile; // lets not cache it until we're sure we loaded everything

    } finally {
        if (mfStream != null) {
            try {
                mfStream.close();
            } catch (Exception e) {
            }
        }
    }
}

From source file:org.nuxeo.osgi.application.loader.FrameworkLoader.java

protected static boolean isBundle(File f) {
    Manifest mf;
    try {//from  w w  w.j a v a 2  s. c o m
        if (f.isFile()) { // jar file
            JarFile jf = new JarFile(f);
            try {
                mf = jf.getManifest();
            } finally {
                jf.close();
            }
            if (mf == null) {
                return false;
            }
        } else if (f.isDirectory()) { // directory
            f = new File(f, "META-INF/MANIFEST.MF");
            if (!f.isFile()) {
                return false;
            }
            mf = new Manifest();
            FileInputStream input = new FileInputStream(f);
            try {
                mf.read(input);
            } finally {
                input.close();
            }
        } else {
            return false;
        }
    } catch (IOException e) {
        return false;
    }
    return mf.getMainAttributes().containsKey(SYMBOLIC_NAME);
}