use of org.apache.storm.hack.resource.ResourceTransformer in project storm by apache.
the class StormShadeRequest method makeRequest.
public static ShadeRequest makeRequest() {
ShadeRequest request = new ShadeRequest();
request.setRelocators(Arrays.asList((Relocator) new SimpleRelocator("backtype.storm", "org.apache.storm"), (Relocator) new SimpleRelocator("storm.trident", "org.apache.storm.trident"), (Relocator) new SimpleRelocator("org.apache.thrift7", "org.apache.storm.thrift")));
request.setResourceTransformers(Arrays.asList((ResourceTransformer) new ClojureTransformer()));
return request;
}
use of org.apache.storm.hack.resource.ResourceTransformer in project storm by apache.
the class DefaultShader method shadeJarStream.
public void shadeJarStream(ShadeRequest shadeRequest, InputStream in, final OutputStream fileOutputStream) throws IOException {
Set<String> resources = new HashSet<>();
List<ResourceTransformer> transformers = new ArrayList<>(shadeRequest.getResourceTransformers());
LOG.debug("Transformers {}", transformers);
RelocatorRemapper remapper = new RelocatorRemapper(shadeRequest.getRelocators());
LOG.debug("Remapper {}", remapper);
JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(fileOutputStream));
JarInputStream jarFile = new JarInputStream(in);
for (JarEntry entry = jarFile.getNextJarEntry(); entry != null; entry = jarFile.getNextJarEntry()) {
String name = entry.getName();
LOG.debug("Processing " + name);
remapper.setClassName(name);
if ("META-INF/INDEX.LIST".equals(name)) {
LOG.debug("Skipping INDEX.LIST...");
// later
continue;
}
if (!entry.isDirectory()) {
InputStream is = jarFile;
String mappedName = remapper.map(name);
LOG.debug(name + " -> " + mappedName);
int idx = mappedName.lastIndexOf('/');
if (idx != -1) {
// make sure dirs are created
String dir = mappedName.substring(0, idx);
if (!resources.contains(dir)) {
addDirectory(resources, jos, dir);
}
}
if (name.endsWith(".class")) {
addRemappedClass(remapper, jos, name, is);
} else if (name.endsWith(".java")) {
// Avoid duplicates
if (resources.contains(mappedName)) {
continue;
}
addJavaSource(resources, jos, mappedName, is, shadeRequest.getRelocators());
} else {
if (!resourceTransformed(transformers, mappedName, is, shadeRequest.getRelocators())) {
// Avoid duplicates that aren't accounted for by the resource transformers
if (resources.contains(mappedName)) {
continue;
}
addResource(resources, jos, mappedName, is);
}
}
}
}
jarFile.close();
for (ResourceTransformer transformer : transformers) {
if (transformer.hasTransformedResource()) {
transformer.modifyOutputStream(jos);
}
}
jos.close();
}
use of org.apache.storm.hack.resource.ResourceTransformer in project storm by apache.
the class DefaultShader method resourceTransformed.
private boolean resourceTransformed(List<ResourceTransformer> resourceTransformers, String name, InputStream is, List<Relocator> relocators) throws IOException {
boolean resourceTransformed = false;
for (ResourceTransformer transformer : resourceTransformers) {
if (transformer.canTransformResource(name)) {
LOG.debug("Transforming " + name + " using " + transformer.getClass().getName());
transformer.processResource(name, is, relocators);
resourceTransformed = true;
break;
}
}
return resourceTransformed;
}
Aggregations