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;
}
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;
}
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;
}
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;
}
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));
}
Aggregations