use of java.util.jar.JarEntry in project storm by apache.
the class DefaultShader method addRemappedClass.
private void addRemappedClass(RelocatorRemapper remapper, JarOutputStream jos, String name, InputStream is) throws IOException {
LOG.debug("Remapping class... " + name);
if (!remapper.hasRelocators()) {
try {
LOG.debug("Just copy class...");
jos.putNextEntry(new JarEntry(name));
IOUtil.copy(is, jos);
} catch (ZipException e) {
LOG.info("zip exception ", e);
}
return;
}
ClassReader cr = new ClassReader(is);
// We don't pass the ClassReader here. This forces the ClassWriter to rebuild the constant pool.
// Copying the original constant pool should be avoided because it would keep references
// to the original class names. This is not a problem at runtime (because these entries in the
// constant pool are never used), but confuses some tools such as Felix' maven-bundle-plugin
// that use the constant pool to determine the dependencies of a class.
ClassWriter cw = new ClassWriter(0);
final String pkg = name.substring(0, name.lastIndexOf('/') + 1);
ClassVisitor cv = new RemappingClassAdapter(cw, remapper) {
@Override
public void visitSource(final String source, final String debug) {
LOG.debug("visitSource " + source);
if (source == null) {
super.visitSource(source, debug);
} else {
final String fqSource = pkg + source;
final String mappedSource = remapper.map(fqSource);
final String filename = mappedSource.substring(mappedSource.lastIndexOf('/') + 1);
LOG.debug("Remapped to " + filename);
super.visitSource(filename, debug);
}
}
};
try {
cr.accept(cv, ClassReader.EXPAND_FRAMES);
} catch (Throwable ise) {
throw new IOException("Error in ASM processing class " + name, ise);
}
byte[] renamedClass = cw.toByteArray();
// Need to take the .class off for remapping evaluation
String mappedName = remapper.map(name.substring(0, name.indexOf('.')));
LOG.debug("Remapped class name to " + mappedName);
try {
// Now we put it back on so the class file is written out with the right extension.
jos.putNextEntry(new JarEntry(mappedName + ".class"));
jos.write(renamedClass);
} catch (ZipException e) {
LOG.info("zip exception ", e);
}
}
use of java.util.jar.JarEntry in project storm by apache.
the class DefaultShader method addJavaSource.
private void addJavaSource(Set<String> resources, JarOutputStream jos, String name, InputStream is, List<Relocator> relocators) throws IOException {
jos.putNextEntry(new JarEntry(name));
String sourceContent = IOUtil.toString(new InputStreamReader(is, "UTF-8"));
for (Relocator relocator : relocators) {
sourceContent = relocator.applyToSourceContent(sourceContent);
}
OutputStreamWriter writer = new OutputStreamWriter(jos, "UTF-8");
writer.append(sourceContent);
writer.flush();
resources.add(name);
}
use of java.util.jar.JarEntry in project storm by apache.
the class DefaultShader method addDirectory.
private void addDirectory(Set<String> resources, JarOutputStream jos, String name) throws IOException {
if (name.lastIndexOf('/') > 0) {
String parent = name.substring(0, name.lastIndexOf('/'));
if (!resources.contains(parent)) {
addDirectory(resources, jos, parent);
}
}
// directory entries must end in "/"
JarEntry entry = new JarEntry(name + "/");
LOG.debug("Adding JAR directory " + entry);
jos.putNextEntry(entry);
resources.add(name);
}
use of java.util.jar.JarEntry in project tomcat by apache.
the class AbstractArchiveResourceSet method getResource.
@Override
public final WebResource getResource(String path) {
checkPath(path);
String webAppMount = getWebAppMount();
WebResourceRoot root = getRoot();
if (path.startsWith(webAppMount)) {
String pathInJar = getInternalPath() + path.substring(webAppMount.length(), path.length());
// Always strip off the leading '/' to get the JAR path
if (pathInJar.length() > 0 && pathInJar.charAt(0) == '/') {
pathInJar = pathInJar.substring(1);
}
if (pathInJar.equals("")) {
// This is a directory resource so the path must end with /
if (!path.endsWith("/")) {
path = path + "/";
}
return new JarResourceRoot(root, new File(getBase()), baseUrlString, path);
} else {
Map<String, JarEntry> jarEntries = getArchiveEntries(true);
JarEntry jarEntry = null;
if (!(pathInJar.charAt(pathInJar.length() - 1) == '/')) {
if (jarEntries == null) {
jarEntry = getArchiveEntry(pathInJar + '/');
} else {
jarEntry = jarEntries.get(pathInJar + '/');
}
if (jarEntry != null) {
path = path + '/';
}
}
if (jarEntry == null) {
if (jarEntries == null) {
jarEntry = getArchiveEntry(pathInJar);
} else {
jarEntry = jarEntries.get(pathInJar);
}
}
if (jarEntry == null) {
return new EmptyResource(root, path);
} else {
return createArchiveResource(jarEntry, path, getManifest());
}
}
} else {
return new EmptyResource(root, path);
}
}
use of java.util.jar.JarEntry in project tomcat by apache.
the class AbstractSingleArchiveResourceSet method getArchiveEntries.
@Override
protected HashMap<String, JarEntry> getArchiveEntries(boolean single) {
synchronized (archiveLock) {
if (archiveEntries == null && !single) {
JarFile jarFile = null;
archiveEntries = new HashMap<>();
try {
jarFile = openJarFile();
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
archiveEntries.put(entry.getName(), entry);
}
} catch (IOException ioe) {
// Should never happen
archiveEntries = null;
throw new IllegalStateException(ioe);
} finally {
if (jarFile != null) {
closeJarFile();
}
}
}
return archiveEntries;
}
}
Aggregations