use of java.util.jar.Manifest in project maven-plugins by apache.
the class ProjectAnalyzer method extractManifest.
private Manifest extractManifest(File file) throws IOException {
Manifest manifest;
if (file.isFile()) {
JarFile jarFile = null;
try {
jarFile = new JarFile(file);
manifest = jarFile.getManifest();
} finally {
jarFile.close();
}
} else if (new File(file, "META-INF/MANIFEST.MF").exists()) {
manifest = new Manifest(new FileInputStream(new File(file, "META-INF/MANIFEST.MF")));
} else {
manifest = null;
}
return manifest;
}
use of java.util.jar.Manifest in project karaf by apache.
the class SpringTransformer method transform.
public static void transform(URL url, OutputStream os) throws Exception {
// Build dom document
Document doc = parse(url);
// Heuristicly retrieve name and version
String name = getPath(url);
int idx = name.lastIndexOf('/');
if (idx >= 0) {
name = name.substring(idx + 1);
}
String[] str = DeployerUtils.extractNameVersionType(name);
// Create manifest
Manifest m = new Manifest();
m.getMainAttributes().putValue("Manifest-Version", "2");
m.getMainAttributes().putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
m.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, str[0]);
m.getMainAttributes().putValue(Constants.BUNDLE_VERSION, str[1]);
m.getMainAttributes().putValue("Spring-Context", "*;publish-context:=false;create-asynchronously:=true");
String importPkgs = getImportPackages(analyze(new DOMSource(doc)));
if (importPkgs != null && importPkgs.length() > 0) {
m.getMainAttributes().putValue(Constants.IMPORT_PACKAGE, importPkgs);
}
m.getMainAttributes().putValue(Constants.DYNAMICIMPORT_PACKAGE, "*");
// Extract manifest entries from the DOM
NodeList l = doc.getElementsByTagName("manifest");
if (l != null) {
for (int i = 0; i < l.getLength(); i++) {
Element e = (Element) l.item(i);
String text = e.getTextContent();
Properties props = new Properties();
props.load(new ByteArrayInputStream(text.trim().getBytes()));
Enumeration<?> en = props.propertyNames();
while (en.hasMoreElements()) {
String k = (String) en.nextElement();
String v = props.getProperty(k);
m.getMainAttributes().putValue(k, v);
}
e.getParentNode().removeChild(e);
}
}
// get original last modification date
long lastModified = getLastModified(url);
JarOutputStream out = new JarOutputStream(os);
ZipEntry e = new ZipEntry(JarFile.MANIFEST_NAME);
e.setTime(lastModified);
out.putNextEntry(e);
m.write(out);
out.closeEntry();
e = new ZipEntry("META-INF/");
e.setTime(lastModified);
out.putNextEntry(e);
e = new ZipEntry("META-INF/spring/");
e.setTime(lastModified);
out.putNextEntry(e);
out.closeEntry();
e = new ZipEntry("META-INF/spring/" + name);
e.setTime(lastModified);
out.putNextEntry(e);
// Copy the new DOM
XmlUtils.transform(new DOMSource(doc), new StreamResult(out));
out.closeEntry();
out.close();
}
use of java.util.jar.Manifest in project intellij-community by JetBrains.
the class JdkUtil method setClasspathJarParams.
private static boolean setClasspathJarParams(SimpleJavaParameters javaParameters, GeneralCommandLine commandLine, ParametersList vmParametersList, Class commandLineWrapper) throws CantRunException {
boolean dynamicVMOptions = javaParameters.isDynamicVMOptions() && useDynamicVMOptions();
boolean dynamicParameters = javaParameters.isDynamicParameters() && useDynamicParameters();
try {
final Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Created-By", ApplicationNamesInfo.getInstance().getFullProductName());
if (dynamicVMOptions) {
List<String> properties = new ArrayList<>();
for (String param : vmParametersList.getList()) {
if (isUserDefinedProperty(param)) {
properties.add(param);
} else {
commandLine.addParameter(param);
}
}
manifest.getMainAttributes().putValue("VM-Options", ParametersListUtil.join(properties));
} else {
commandLine.addParameters(vmParametersList.getList());
}
if (dynamicParameters) {
manifest.getMainAttributes().putValue("Program-Parameters", ParametersListUtil.join(javaParameters.getProgramParametersList().getList()));
}
final boolean notEscape = vmParametersList.hasParameter(PROPERTY_DO_NOT_ESCAPE_CLASSPATH_URL);
final List<String> classPathList = javaParameters.getClassPath().getPathList();
final File classpathJarFile = CommandLineWrapperUtil.createClasspathJarFile(manifest, classPathList, notEscape);
getFilesToDeleteUserData(commandLine).add(classpathJarFile);
final String jarFile = classpathJarFile.getAbsolutePath();
commandLine.addParameter("-classpath");
if (dynamicVMOptions || dynamicParameters) {
commandLine.addParameter(PathUtil.getJarPathForClass(commandLineWrapper) + File.pathSeparator + jarFile);
appendEncoding(javaParameters, commandLine, vmParametersList);
commandLine.addParameter(commandLineWrapper.getName());
commandLine.addParameter(jarFile);
} else {
commandLine.addParameters(jarFile);
appendEncoding(javaParameters, commandLine, vmParametersList);
}
} catch (IOException e) {
throwUnableToCreateTempFile(e);
}
return dynamicParameters;
}
use of java.util.jar.Manifest in project sling by apache.
the class BSNRenamer method processManifest.
protected Manifest processManifest(Manifest inputMF) {
Attributes inputAttrs = inputMF.getMainAttributes();
String orgBSN = inputAttrs.getValue(BUNDLE_SYMBOLIC_NAME);
Manifest newMF = new Manifest(inputMF);
Attributes outputAttrs = newMF.getMainAttributes();
outputAttrs.putValue(BUNDLE_SYMBOLIC_NAME, newBSN);
outputAttrs.putValue(X_ORIG_BSN, orgBSN);
return newMF;
}
use of java.util.jar.Manifest in project sling by apache.
the class BundleFileProcessorTest method testBSNRenaming.
@Test
public void testBSNRenaming() throws IOException {
File tempDir = new File(System.getProperty("java.io.tmpdir"));
// Just take any bundle from the maven deps as an example...
File originalFile = getMavenArtifactFile(getMavenRepoRoot(), "com.google.guava", "guava", "15.0");
File generatedFile = new BSNRenamer(originalFile, tempDir, "org.acme.baklava.guava").process();
try {
compareJarContents(originalFile, generatedFile);
JarFile jfOrg = null;
JarFile jfNew = null;
try {
jfOrg = new JarFile(originalFile);
jfNew = new JarFile(generatedFile);
Manifest mfOrg = jfOrg.getManifest();
Manifest mfNew = jfNew.getManifest();
Attributes orgAttrs = mfOrg.getMainAttributes();
Attributes newAttrs = mfNew.getMainAttributes();
for (Object key : orgAttrs.keySet()) {
String orgVal = orgAttrs.getValue(key.toString());
String newVal = newAttrs.getValue(key.toString());
if ("Bundle-SymbolicName".equals(key.toString())) {
assertEquals("Should have recorded the original Bundle-SymbolicName", orgVal, newAttrs.getValue("X-Original-Bundle-SymbolicName"));
assertEquals("org.acme.baklava.guava", newVal);
} else {
assertEquals("Different keys: " + key, orgVal, newVal);
}
}
} finally {
closeQuietly(jfOrg);
closeQuietly(jfNew);
}
} finally {
assertTrue("Unable to delete temporary file", generatedFile.delete());
}
}
Aggregations