use of net.sf.cglib.asm.$ClassReader in project component-runtime by Talend.
the class PluginGenerator method createChainPlugin.
public File createChainPlugin(final File dir, final String plugin) {
final File target = new File(dir, plugin);
try (final JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(target))) {
final String packageName = toPackage(target.getParentFile().getParentFile().getName()).replace(".", "/");
final String sourcePackage = "org/talend/test";
final String fromPack = sourcePackage.replace('/', '.');
final String toPack = packageName.replace('.', '/');
final File root = new File(jarLocation(getClass()), sourcePackage);
ofNullable(root.listFiles()).map(Stream::of).orElseGet(Stream::empty).filter(c -> c.getName().endsWith(".class")).forEach(clazz -> {
try (final InputStream is = new FileInputStream(clazz)) {
final ClassReader reader = new ClassReader(is);
final ClassWriter writer = new ClassWriter(COMPUTE_FRAMES);
reader.accept(new ClassRemapper(writer, new Remapper() {
@Override
public String map(final String key) {
return key.replace(sourcePackage, toPack).replace(fromPack, packageName);
}
}), EXPAND_FRAMES);
outputStream.putNextEntry(new JarEntry(toPack + '/' + clazz.getName()));
outputStream.write(writer.toByteArray());
} catch (final IOException e) {
fail(e.getMessage());
}
});
} catch (final IOException e) {
throw new IllegalStateException(e);
}
return target;
}
use of net.sf.cglib.asm.$ClassReader in project component-runtime by Talend.
the class PluginGenerator method createChainPlugin.
public File createChainPlugin(final File dir, final String plugin) {
final File target = new File(dir, plugin);
try (final JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(target))) {
final String packageName = toPackage(target.getParentFile().getParentFile().getName()).replace(".", "/");
final String sourcePackage = "org/talend/test";
final String fromPack = sourcePackage.replace('/', '.');
final String toPack = packageName.replace('.', '/');
final File root = new File(jarLocation(getClass()), sourcePackage);
ofNullable(root.listFiles()).map(Stream::of).orElseGet(Stream::empty).filter(c -> c.getName().endsWith(".class")).forEach(clazz -> {
try (final InputStream is = new FileInputStream(clazz)) {
final ClassReader reader = new ClassReader(is);
final ClassWriter writer = new ClassWriter(COMPUTE_FRAMES);
reader.accept(new ClassRemapper(writer, new Remapper() {
@Override
public String map(final String key) {
return key.replace(sourcePackage, toPack).replace(fromPack, packageName);
}
}), EXPAND_FRAMES);
outputStream.putNextEntry(new JarEntry(toPack + '/' + clazz.getName()));
outputStream.write(writer.toByteArray());
} catch (final IOException e) {
fail(e.getMessage());
}
});
} catch (final IOException e) {
throw new IllegalStateException(e);
}
return target;
}
use of net.sf.cglib.asm.$ClassReader in project component-runtime by Talend.
the class RepositoryModelBuilderTest method createChainPlugin.
private File createChainPlugin(final File dir, final String plugin) {
final File target = new File(dir, plugin);
try (final JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(target))) {
final String packageName = toPackage(target.getParentFile().getParentFile().getName()).replace(".", "/");
final String sourcePackage = "org/talend/test";
final String fromPack = sourcePackage.replace('/', '.');
final String toPack = packageName.replace('.', '/');
final File root = new File(jarLocation(getClass()), sourcePackage);
ofNullable(root.listFiles()).map(Stream::of).orElseGet(Stream::empty).filter(c -> c.getName().endsWith(".class")).forEach(clazz -> {
try (final InputStream is = new FileInputStream(clazz)) {
final ClassReader reader = new ClassReader(is);
final ClassWriter writer = new ClassWriter(COMPUTE_FRAMES);
reader.accept(new ClassRemapper(writer, new Remapper() {
@Override
public String map(final String key) {
return key.replace(sourcePackage, toPack).replace(fromPack, packageName);
}
}), EXPAND_FRAMES);
outputStream.putNextEntry(new JarEntry(toPack + '/' + clazz.getName()));
outputStream.write(writer.toByteArray());
} catch (final IOException e) {
fail(e.getMessage());
}
});
} catch (final IOException e) {
throw new IllegalStateException(e);
}
return target;
}
use of net.sf.cglib.asm.$ClassReader in project jodd by oblac.
the class ProxyAspectData method getCachedAdviceClassReader.
/**
* Returns class reader for advice.
*/
private ClassReader getCachedAdviceClassReader(Class<? extends ProxyAdvice> advice) {
if (adviceClassReaderCache == null) {
adviceClassReaderCache = new HashMap<>();
}
ClassReader adviceReader = adviceClassReaderCache.get(advice);
if (adviceReader == null) {
adviceReader = createAdviceClassReader(advice);
adviceClassReaderCache.put(advice, adviceReader);
}
return adviceReader;
}
use of net.sf.cglib.asm.$ClassReader in project jodd by oblac.
the class Paramo method resolveParameters.
/**
* Resolves method parameters from a method or constructor.
* Returns an empty array when target does not contain any parameter.
* No caching is involved in this process, i.e. class bytecode
* is examined every time this method is called.
*/
public static MethodParameter[] resolveParameters(AccessibleObject methodOrCtor) {
Class[] paramTypes;
Class declaringClass;
String name;
if (methodOrCtor instanceof Method) {
Method method = (Method) methodOrCtor;
paramTypes = method.getParameterTypes();
name = method.getName();
declaringClass = method.getDeclaringClass();
} else {
Constructor constructor = (Constructor) methodOrCtor;
paramTypes = constructor.getParameterTypes();
declaringClass = constructor.getDeclaringClass();
name = CTOR_METHOD;
}
if (paramTypes.length == 0) {
return MethodParameter.EMPTY_ARRAY;
}
InputStream stream;
try {
stream = ClassLoaderUtil.getClassAsStream(declaringClass);
} catch (IOException ioex) {
throw new ParamoException("Failed to read class bytes: " + declaringClass.getName(), ioex);
}
if (stream == null) {
throw new ParamoException("Class not found: " + declaringClass);
}
try {
ClassReader reader = new ClassReader(stream);
MethodFinder visitor = new MethodFinder(declaringClass, name, paramTypes);
reader.accept(visitor, 0);
return visitor.getResolvedParameters();
} catch (IOException ioex) {
throw new ParamoException(ioex);
} finally {
StreamUtil.close(stream);
}
}
Aggregations