Search in sources :

Example 31 with Manifest

use of java.util.jar.Manifest in project tdi-studio-se by Talend.

the class JobJavaScriptOSGIForESBManager method genMetaInfoFolder.

private ExportFileResource genMetaInfoFolder(ExportFileResource libResource, ProcessItem processItem) throws IOException {
    ExportFileResource metaInfoResource = new ExportFileResource(null, FileConstants.META_INF_FOLDER_NAME);
    // generate the MANIFEST.MF file in the temp folder
    File manifestFile = new File(getTmpFolder() + PATH_SEPARATOR + FileConstants.MANIFEST_MF_FILE_NAME);
    FileOutputStream fos = null;
    try {
        Manifest manifest = getManifest(libResource, processItem);
        fos = new FileOutputStream(manifestFile);
        manifest.write(fos);
    } finally {
        if (fos != null) {
            fos.close();
        }
    }
    metaInfoResource.addResources(Collections.singletonList(manifestFile.toURI().toURL()));
    return metaInfoResource;
}
Also used : ExportFileResource(org.talend.repository.documentation.ExportFileResource) FileOutputStream(java.io.FileOutputStream) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 32 with Manifest

use of java.util.jar.Manifest in project intellij-community by JetBrains.

the class XsltDebuggerExtension method isValidXalanPresent.

@Nullable
private static Boolean isValidXalanPresent(SimpleJavaParameters parameters) {
    final List<VirtualFile> files = parameters.getClassPath().getVirtualFiles();
    for (VirtualFile file : files) {
        if (file.getName().matches(".*xalan.*\\.jar")) {
            final VirtualFile root = JarFileSystem.getInstance().getJarRootForLocalFile(file);
            final VirtualFile manifestFile = root != null ? root.findFileByRelativePath("META-INF/MANIFEST.MF") : null;
            if (manifestFile != null) {
                try {
                    Manifest manifest = manifestFile.getUserData(MANIFEST);
                    if (manifest == null) {
                        manifest = new Manifest(manifestFile.getInputStream());
                        manifestFile.putUserData(MANIFEST, manifest);
                    }
                    Attributes attributes = manifest.getAttributes("org/apache/xalan/");
                    if (attributes == null) {
                        attributes = manifest.getAttributes("org/apache/xalan");
                    }
                    if (attributes == null) {
                        LOG.info("No manifest attributes for 'org/apache/xalan/' in " + manifestFile.getPresentableUrl());
                        continue;
                    }
                    final String version = attributes.getValue("Implementation-Version");
                    if (version != null) {
                        final String[] parts = version.split("\\.");
                        if (parts.length >= 2) {
                            if (Integer.parseInt(parts[0]) >= 2 && Integer.parseInt(parts[1]) >= 6) {
                                return true;
                            }
                        }
                        LOG.info("Unsupported Xalan version: " + version);
                    } else {
                        LOG.info("No Xalan version information in " + file.getPath());
                    }
                } catch (IOException e) {
                    LOG.warn("Unable to read manifest from " + file.getName(), e);
                }
            } else {
                LOG.info("No manifest file in " + file.getPath());
            }
            return false;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Attributes(java.util.jar.Attributes) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with Manifest

use of java.util.jar.Manifest in project ACS by ACS-Community.

the class JarSourceExtractorRunner method needsProcessing.

/**
	 * Encapsulates evaluation of possible flags (properties) that may restrict the set of jar files to be processed
	 * for source extraction, for example based on the manifest information.
	 * <p>
	 * Currently only looks at the boolean property <code>jarExtract.onlyGeneratedJars</code>.
	 *  
	 * @param jarFile
	 * @return
	 * @throws IOException
	 */
static boolean needsProcessing(JarFile jarFile) throws IOException {
    // flag to 
    boolean onlyGeneratedJars = Boolean.getBoolean(PROPERTY_EXTRACT_ONLY_GENERATED_JARS);
    boolean needed = !onlyGeneratedJars;
    // only look inside if we are not already sure that this jar file is needed
    if (!needed) {
        Manifest mani = jarFile.getManifest();
        if (mani != null) {
            Map<String, Attributes> entries = mani.getEntries();
            //			System.out.println("\n\nManifest for file " + jarFile.getName());
            Attributes mainAttrs = mani.getMainAttributes();
            for (Iterator mainAttrIter = mainAttrs.keySet().iterator(); mainAttrIter.hasNext(); ) {
                String attr = ((Attributes.Name) mainAttrIter.next()).toString();
                String value = mainAttrs.getValue(attr);
                if (attr.equals(Manifest_Attr_ACSGeneratedFromFile)) {
                    needed = true;
                    break;
                }
            //				System.out.println(attr + "=" + value);
            }
        }
    }
    return needed;
}
Also used : Attributes(java.util.jar.Attributes) Iterator(java.util.Iterator) Manifest(java.util.jar.Manifest)

Example 34 with Manifest

use of java.util.jar.Manifest in project kotlin by JetBrains.

the class ClassPreloadingUtils method extractManifestClasspath.

private static Collection<File> extractManifestClasspath(ResourceData manifestData) throws IOException {
    Manifest manifest = new Manifest(new ByteArrayInputStream(manifestData.bytes));
    String classpathSpaceSeparated = (String) manifest.getMainAttributes().get(Attributes.Name.CLASS_PATH);
    if (classpathSpaceSeparated == null)
        return Collections.emptyList();
    Collection<File> classpath = new ArrayList<File>(1);
    for (String jar : classpathSpaceSeparated.split(" ")) {
        if (".".equals(jar))
            continue;
        if (!jar.endsWith(".jar")) {
            throw new UnsupportedOperationException("Class-Path attribute should only contain paths to JAR files: " + jar);
        }
        classpath.add(new File(manifestData.jarFile.getParent(), jar));
    }
    return classpath;
}
Also used : Manifest(java.util.jar.Manifest) JarFile(java.util.jar.JarFile)

Example 35 with Manifest

use of java.util.jar.Manifest in project intellij-community by JetBrains.

the class ArtifactsTestUtil method assertManifest.

public static void assertManifest(CompositePackagingElement<?> rootElement, PackagingElementResolvingContext context, ArtifactType type, @Nullable String mainClass, @Nullable String classpath) {
    final VirtualFile file = ManifestFileUtil.findManifestFile(rootElement, context, type);
    assertNotNull(file);
    final Manifest manifest = ManifestFileUtil.readManifest(file);
    assertEquals(mainClass, manifest.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS));
    assertEquals(classpath, manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Manifest(java.util.jar.Manifest)

Aggregations

Manifest (java.util.jar.Manifest)1226 Attributes (java.util.jar.Attributes)392 File (java.io.File)391 IOException (java.io.IOException)336 JarFile (java.util.jar.JarFile)231 InputStream (java.io.InputStream)184 URL (java.net.URL)177 JarOutputStream (java.util.jar.JarOutputStream)145 FileOutputStream (java.io.FileOutputStream)131 Test (org.junit.Test)129 FileInputStream (java.io.FileInputStream)119 Jar (aQute.bnd.osgi.Jar)105 JarInputStream (java.util.jar.JarInputStream)104 Builder (aQute.bnd.osgi.Builder)99 ZipEntry (java.util.zip.ZipEntry)99 ByteArrayOutputStream (java.io.ByteArrayOutputStream)96 JarEntry (java.util.jar.JarEntry)96 ByteArrayInputStream (java.io.ByteArrayInputStream)93 ArrayList (java.util.ArrayList)83 Map (java.util.Map)83