use of java.util.jar.JarInputStream in project aries by apache.
the class WarToWabConverterImpl method convert.
private void convert() throws IOException {
if (wab != null) {
// WAB is already converted
return;
}
generateManifest();
CachedOutputStream output = new CachedOutputStream();
JarOutputStream jarOutput = null;
JarInputStream jarInput = null;
ZipEntry entry = null;
// Copy across all entries from the original jar
int val;
try {
jarOutput = new JarOutputStream(output, wabManifest);
jarInput = new JarInputStream(input.getInputStream());
byte[] buffer = new byte[2048];
while ((entry = jarInput.getNextEntry()) != null) {
// skip signature files if war is signed
if (signed && isSignatureFile(entry.getName())) {
continue;
}
jarOutput.putNextEntry(entry);
while ((val = jarInput.read(buffer)) > 0) {
jarOutput.write(buffer, 0, val);
}
}
} finally {
if (jarOutput != null) {
jarOutput.close();
}
if (jarInput != null) {
jarInput.close();
}
}
wab = output;
}
use of java.util.jar.JarInputStream in project aries by apache.
the class WarToWabConverterImpl method scanRecursive.
private void scanRecursive(final JarInputStream jarInput, boolean topLevel) throws IOException {
ZipEntry entry;
while ((entry = jarInput.getNextEntry()) != null) {
if (entry.getName().endsWith(".class")) {
PackageFinder pkgFinder = new PackageFinder();
new ClassReader(jarInput).accept(pkgFinder, ClassReader.SKIP_DEBUG);
importPackages.addAll(pkgFinder.getImportPackages());
exemptPackages.addAll(pkgFinder.getExemptPackages());
} else if (entry.getName().endsWith(".jsp")) {
Collection<String> thisJSPsImports = JSPImportParser.getImports(jarInput);
importPackages.addAll(thisJSPsImports);
} else if (entry.getName().endsWith(".jar")) {
JarInputStream newJar = new JarInputStream(new InputStream() {
@Override
public int read() throws IOException {
return jarInput.read();
}
});
// discard return, we only care about the top level jars
scanRecursive(newJar, false);
// do not add jar embedded in already embedded jars
if (topLevel) {
manifests.put(entry.getName(), newJar.getManifest());
}
}
}
}
use of java.util.jar.JarInputStream in project maven-plugins by apache.
the class EvaluateMojo method addAlias.
/**
* @param xstreamObject not null
* @param jarFile not null
* @param packageFilter a package name to filter.
*/
private void addAlias(XStream xstreamObject, File jarFile, String packageFilter) {
JarInputStream jarStream = null;
try {
jarStream = new JarInputStream(new FileInputStream(jarFile));
for (JarEntry jarEntry = jarStream.getNextJarEntry(); jarEntry != null; jarEntry = jarStream.getNextJarEntry()) {
if (jarEntry.getName().toLowerCase(Locale.ENGLISH).endsWith(".class")) {
String name = jarEntry.getName().substring(0, jarEntry.getName().indexOf("."));
name = name.replaceAll("/", "\\.");
if (name.contains(packageFilter)) {
try {
Class<?> clazz = ClassUtils.getClass(name);
String alias = StringUtils.lowercaseFirstLetter(clazz.getSimpleName());
xstreamObject.alias(alias, clazz);
if (!clazz.equals(Model.class)) {
// unnecessary field
xstreamObject.omitField(clazz, "modelEncoding");
}
} catch (ClassNotFoundException e) {
getLog().error(e);
}
}
}
jarStream.closeEntry();
}
jarStream.close();
jarStream = null;
} catch (IOException e) {
if (getLog().isDebugEnabled()) {
getLog().debug("IOException: " + e.getMessage(), e);
}
} finally {
IOUtil.close(jarStream);
}
}
use of java.util.jar.JarInputStream in project karaf by apache.
the class BlueprintDeploymentListenerTest method testAppendDescriptorFileExtension.
// KARAF-1617
public void testAppendDescriptorFileExtension() throws Exception {
final String expectedFileName = "test-fileextension";
File f = File.createTempFile("smx", ".jar");
try {
ZipEntry zipEntry = null;
OutputStream os = new FileOutputStream(f);
BlueprintTransformer.transform(getClass().getClassLoader().getResource(expectedFileName), os);
os.close();
InputStream is = new FileInputStream(f);
JarInputStream jar = new JarInputStream(is);
while (true) {
zipEntry = jar.getNextEntry();
if (null == zipEntry) {
break;
}
if (zipEntry.getName() != null && zipEntry.getName().contains(expectedFileName)) {
break;
}
}
is.close();
assertNotNull("blueprint service descriptor JAR file entry", zipEntry);
assertEquals(BLUEPRINT_ENTRY + expectedFileName + ".xml", zipEntry.getName());
} finally {
f.delete();
}
}
use of java.util.jar.JarInputStream in project karaf by apache.
the class BlueprintDeploymentListenerTest method testAppendNotTwiceDescriptorFileExtension.
public void testAppendNotTwiceDescriptorFileExtension() throws Exception {
final String expectedFileName = "test.xml";
File f = File.createTempFile("smx", ".jar");
try {
ZipEntry zipEntry = null;
OutputStream os = new FileOutputStream(f);
BlueprintTransformer.transform(getClass().getClassLoader().getResource(expectedFileName), os);
os.close();
InputStream is = new FileInputStream(f);
JarInputStream jar = new JarInputStream(is);
while (true) {
zipEntry = jar.getNextEntry();
if (null == zipEntry) {
break;
}
if (zipEntry.getName() != null && zipEntry.getName().contains(expectedFileName)) {
break;
}
}
is.close();
assertNotNull("blueprint service descriptor JAR file entry", zipEntry);
assertEquals(BLUEPRINT_ENTRY + expectedFileName, zipEntry.getName());
} finally {
f.delete();
}
}
Aggregations