use of java.util.jar.Manifest in project felix by apache.
the class Utils method merge.
public static void merge(File targetIndex, File target, File sourceIndex, File source) throws IOException {
List targetFiles = readIndex(targetIndex);
List sourceFiles = readIndex(sourceIndex);
List result = new ArrayList(targetFiles);
File manifestFile = new File(source, (String) sourceFiles.remove(0));
Manifest resultManifest = Utils.readManifest(manifestFile);
resultManifest.getMainAttributes().remove(new Name(Constants.DEPLOYMENTPACKAGE_FIXPACK));
for (Iterator i = result.iterator(); i.hasNext(); ) {
String targetFile = (String) i.next();
if (!MANIFEST_NAME.equals(targetFile) && !resultManifest.getEntries().containsKey(targetFile)) {
i.remove();
}
}
for (Iterator iter = sourceFiles.iterator(); iter.hasNext(); ) {
String path = (String) iter.next();
File from = new File(source, path);
File to = new File(target, path);
if (targetFiles.contains(path)) {
if (!to.delete()) {
throw new IOException("Could not delete " + to);
}
} else {
result.add(path);
}
if (!rename(from, to)) {
throw new IOException("Could not rename " + from + " to " + to);
}
}
targetFiles.removeAll(sourceFiles);
for (Iterator iter = resultManifest.getEntries().keySet().iterator(); iter.hasNext(); ) {
String path = (String) iter.next();
Attributes sourceAttribute = (Attributes) resultManifest.getEntries().get(path);
if ("true".equals(sourceAttribute.remove(new Name(Constants.DEPLOYMENTPACKAGE_MISSING)))) {
targetFiles.remove(path);
}
}
for (Iterator iter = targetFiles.iterator(); iter.hasNext(); ) {
String path = (String) iter.next();
File targetFile = new File(target, path);
if (!targetFile.delete()) {
throw new IOException("Could not delete " + targetFile);
}
}
GZIPOutputStream outputStream = new GZIPOutputStream(new FileOutputStream(new File(target, MANIFEST_NAME)));
try {
resultManifest.write(outputStream);
} finally {
outputStream.close();
}
writeIndex(targetIndex, result);
}
use of java.util.jar.Manifest in project felix by apache.
the class ContentCopyingJarInputStreamTest method testCopyJarWithoutIndexAndWithManifestOk.
/**
* Tests that we can copy a simple {@link JarInputStream}.
*/
public void testCopyJarWithoutIndexAndWithManifestOk() throws Exception {
Manifest man = createManifest();
createJar(man, false);
assertJarContents(man);
}
use of java.util.jar.Manifest in project felix by apache.
the class DeploymentPackageBuilderTest method testCreateMissingBundleResourceOk.
/**
* Tests that we can build a deployment package with a bundle resource.
*/
@Test
public void testCreateMissingBundleResourceOk() throws Exception {
DeploymentPackageBuilder dpBuilder = DeploymentPackageBuilder.create("dp-test", "1.0.0");
dpBuilder.setFixPackage().add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")).setMissing());
JarInputStream jis = new JarInputStream(dpBuilder.generate());
assertNotNull(jis);
Manifest manifest = jis.getManifest();
assertManifestHeader(manifest, "DeploymentPackage-SymbolicName", "dp-test");
assertManifestHeader(manifest, "DeploymentPackage-Version", "1.0.0");
String filename = getBundleName("bundle1");
assertManifestEntry(manifest, filename, "Name", filename);
assertManifestEntry(manifest, filename, "Bundle-SymbolicName", "testbundles.bundle1");
assertManifestEntry(manifest, filename, "Bundle-Version", "1.0.0");
assertManifestEntry(manifest, filename, "DeploymentPackage-Missing", "true");
int count = countJarEntries(jis);
assertEquals("Expected two entries in the JAR!", 0, count);
}
use of java.util.jar.Manifest in project felix by apache.
the class DeploymentPackageBuilderTest method testResourceFilterOk.
/**
* Tests that we can filter a resource.
*/
@Test
public void testResourceFilterOk() throws Exception {
DeploymentPackageBuilder dpBuilder = DeploymentPackageBuilder.create("dp-test", "1.0.0");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle2"))).add(dpBuilder.createBundleResource().setVersion("1.1.0").setFilter(new JarManifestManipulatingFilter("Bundle-Version", "1.1.0", "Foo", "bar")).setUrl(getTestBundle("bundle1")));
JarInputStream jis = new JarInputStream(dpBuilder.generate());
assertNotNull(jis);
Manifest manifest = jis.getManifest();
assertManifestHeader(manifest, "DeploymentPackage-SymbolicName", "dp-test");
assertManifestHeader(manifest, "DeploymentPackage-Version", "1.0.0");
String filename = getBundleName("bundle1");
assertManifestEntry(manifest, filename, "Name", filename);
assertManifestEntry(manifest, filename, "Bundle-SymbolicName", "testbundles.bundle1");
assertManifestEntry(manifest, filename, "Bundle-Version", "1.1.0");
filename = getBundleName("bundle2");
assertManifestEntry(manifest, filename, "Name", filename);
assertManifestEntry(manifest, filename, "Bundle-SymbolicName", "testbundles.bundle2");
assertManifestEntry(manifest, filename, "Bundle-Version", "1.0.0");
try {
byte[] buf = new byte[32 * 1024];
JarEntry entry;
while ((entry = jis.getNextJarEntry()) != null) {
if (entry.getName().endsWith("valid-bundle1.jar")) {
int read = jis.read(buf);
JarInputStream jis2 = new JarInputStream(new ByteArrayInputStream(Arrays.copyOf(buf, read)));
Manifest manifest2 = jis2.getManifest();
Attributes mainAttributes = manifest2.getMainAttributes();
assertEquals("1.1.0", mainAttributes.getValue("Bundle-Version"));
assertEquals("bar", mainAttributes.getValue("Foo"));
jis2.close();
}
jis.closeEntry();
}
} finally {
jis.close();
}
}
use of java.util.jar.Manifest in project felix by apache.
the class ManipulationMetadataTest method setUp.
public void setUp() {
File manFile = new File("src/test/resources/manipulation/MANIFEST.MF");
Manifest manifest;
try {
manifest = new Manifest(new FileInputStream(manFile));
header = manifest.getMainAttributes().getValue("iPOJO-Components");
} catch (FileNotFoundException e) {
fail(e.getMessage());
} catch (IOException e) {
fail(e.getMessage());
}
}
Aggregations