use of org.apache.commons.compress.archivers.jar.JarArchiveEntry in project tomee by apache.
the class MonkeyTest method prepareProject.
private File prepareProject() throws IOException {
final File target = new File("target/MonkeyTest_run" + System.currentTimeMillis() + "/mvn/target");
target.mkdirs();
final File classes = new File(target, "classes");
classes.mkdirs();
writeBinary(classes, "target/test-classes/test/patch/MyMain.class", "test/patch/MyMain.class");
writeBinary(classes, "target/test-classes/test/patch/foo/Another.class", "test/patch/foo/Another.class");
final File tomee = new File(target, "tomee");
final File lib = new File(tomee, "lib");
lib.mkdirs();
// create the jar to patch, it is invalid but when patched it should work
JarArchiveOutputStream stream = null;
try {
stream = new JarArchiveOutputStream(new FileOutputStream(new File(lib, "t.jar")));
stream.putArchiveEntry(new JarArchiveEntry("test/patch/MyMain.class"));
stream.write("invalid".getBytes());
stream.closeArchiveEntry();
stream.putArchiveEntry(new JarArchiveEntry("test/patch/foo/Another.class"));
stream.write("invalid-too".getBytes());
stream.closeArchiveEntry();
} catch (final IOException e) {
throw new IllegalArgumentException(e);
} finally {
IO.close(stream);
}
return tomee;
}
use of org.apache.commons.compress.archivers.jar.JarArchiveEntry in project incubator-systemml by apache.
the class BuildLite method getAllClassesInJar.
/**
* Obtain a list of all classes in a jar file corresponding to a referenced
* class.
*
* @param classInJarFile
* @return list of all the commons-math3 classes in the referenced
* commons-math3 jar file
* @throws IOException
* if an IOException occurs
* @throws ClassNotFoundException
* if a ClassNotFoundException occurs
*/
private static List<String> getAllClassesInJar(Class<?> classInJarFile) throws IOException, ClassNotFoundException {
List<String> classPathNames = new ArrayList<>();
String jarLocation = classInJarFile.getProtectionDomain().getCodeSource().getLocation().getPath();
File f = new File(jarLocation);
try (FileInputStream fis = new FileInputStream(f);
JarArchiveInputStream jais = new JarArchiveInputStream(fis)) {
while (true) {
JarArchiveEntry jae = jais.getNextJarEntry();
if (jae == null) {
break;
}
String name = jae.getName();
if (name.endsWith(".class")) {
classPathNames.add(name);
}
}
}
String jarName = jarLocation.substring(jarLocation.lastIndexOf("/") + 1);
addClassPathNamesToJarsAndClasses(jarName, classPathNames);
return classPathNames;
}
Aggregations