use of org.objectweb.asm.commons.SimpleRemapper in project drill by apache.
the class MergeAdapter method visitEnd.
@Override
public void visitEnd() {
// add all the fields of the class we're going to merge.
for (Iterator<?> it = classToMerge.fields.iterator(); it.hasNext(); ) {
// Special handling for nested classes. Drill uses non-static nested
// "inner" classes in some templates. Prior versions of Drill would
// create the generated nested classes as static, then this line
// would copy the "this$0" field to convert the static nested class
// into a non-static inner class. However, that approach is not
// compatible with plain-old Java compilation. Now, Drill generates
// the nested classes as non-static inner classes. As a result, we
// do not want to copy the hidden fields; we'll end up with two if
// we do.
FieldNode field = (FieldNode) it.next();
if (!field.name.startsWith("this$")) {
field.accept(this);
}
}
// add all the methods that we to include.
for (Iterator<?> it = classToMerge.methods.iterator(); it.hasNext(); ) {
MethodNode mn = (MethodNode) it.next();
if (mn.name.equals("<init>")) {
continue;
}
String[] exceptions = new String[mn.exceptions.size()];
mn.exceptions.toArray(exceptions);
MethodVisitor mv = cv.visitMethod(mn.access | Modifier.FINAL, mn.name, mn.desc, mn.signature, exceptions);
if (verifyBytecode) {
mv = new CheckMethodVisitorFsm(api, mv);
}
mn.instructions.resetLabels();
// mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, new
// SimpleRemapper("org.apache.drill.exec.compile.ExampleTemplate", "Bunky")));
ClassSet top = set;
while (top.parent != null) {
top = top.parent;
}
mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, new SimpleRemapper(top.precompiled.slash, top.generated.slash)));
}
super.visitEnd();
}
use of org.objectweb.asm.commons.SimpleRemapper in project atlas by alibaba.
the class DataBindingRenameTask method createAwbPackages.
/**
* 生成so的目录
*/
@TaskAction
void createAwbPackages() throws ExecutionException, InterruptedException {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == androidDependencyTree) {
return;
}
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
List<Runnable> runnables = new ArrayList<>();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
runnables.add(new Runnable() {
@Override
public void run() {
try {
File dataBindingClazzFolder = appVariantOutputContext.getVariantContext().getJAwbavaOutputDir(awbBundle);
String packageName = ManifestFileUtils.getPackage(awbBundle.getOrgManifestFile());
String appName = appVariantContext.getVariantConfiguration().getOriginalApplicationId();
//删除那些已经存在的类
File dataMapperClazz = new File(dataBindingClazzFolder, "android/databinding/DataBinderMapper.class");
if (!dataMapperClazz.exists()) {
throw new GradleException("missing datamapper class");
}
FileInputStream fileInputStream = new FileInputStream(dataMapperClazz);
ClassReader in1 = new ClassReader(fileInputStream);
ClassWriter cw = new ClassWriter(0);
Map<String, String> reMapping = new HashedMap();
reMapping.put(appName.replace(".", "/") + "/BR", packageName.replace(".", "/") + "/BR");
RemappingClassAdapter remappingClassAdapter = new RemappingClassAdapter(cw, new SimpleRemapper(reMapping));
in1.accept(remappingClassAdapter, 8);
ClassReader in2 = new ClassReader(cw.toByteArray());
ClassWriter cw2 = new ClassWriter(0);
Set<String> renames = new HashSet<String>();
renames.add("android/databinding/DataBinderMapper");
in2.accept(new ClassRenamer(cw2, renames, packageName.replace(".", "/") + "/DataBinderMapper"), 8);
File destClass = new File(dataBindingClazzFolder, packageName.replace(".", "/") + "/DataBinderMapper.class");
destClass.getParentFile().mkdirs();
FileOutputStream fileOutputStream = new FileOutputStream(destClass);
fileOutputStream.write(cw2.toByteArray());
IOUtils.closeQuietly(fileOutputStream);
IOUtils.closeQuietly(fileInputStream);
FileUtils.deleteDirectory(new File(dataBindingClazzFolder, "android/databinding"));
FileUtils.deleteDirectory(new File(dataBindingClazzFolder, "com/android/databinding"));
File appDir = new File(dataBindingClazzFolder, appName.replace(".", "/"));
if (appDir.exists()) {
File[] files = appDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile() && !pathname.isDirectory();
}
});
for (File tmp : files) {
FileUtils.forceDelete(tmp);
}
}
} catch (Throwable e) {
e.printStackTrace();
throw new GradleException("package awb failed");
}
}
});
}
executorServicesHelper.execute(runnables);
}
Aggregations