use of com.taobao.android.builder.tools.classinject.InjectParam in project atlas by alibaba.
the class DexBuildTask method doFullTaskAction.
@TaskAction
public void doFullTaskAction() throws IOException {
classJar = getClassJar();
dependencyJars = getDependencyJars();
File mergeJar = new File(classJar.getParentFile(), "merge.jar");
JarMergerWithOverride jarMergerWithOverride = new JarMergerWithOverride(mergeJar);
jarMergerWithOverride.addJar(classJar);
for (File file : dependencyJars) {
jarMergerWithOverride.addJar(file);
}
jarMergerWithOverride.close();
ClassPool classPool = initClassPool(mergeJar);
String jarFileName = classJar.getName();
String outFileName = FilenameUtils.getBaseName(jarFileName) + "-inject.jar";
File outPutJar = new File(classJar.getParentFile(), outFileName);
CodeInjectByJavassist.inject(classPool, mergeJar, outPutJar, new InjectParam());
getOutputDexFile().getParentFile().mkdirs();
outputDexFile = DexBuilderUtils.buildDexInJvm(outPutJar, getOutputDexFile(), new ArrayList<String>());
}
use of com.taobao.android.builder.tools.classinject.InjectParam in project atlas by alibaba.
the class ClassInjectTransform method transform.
@Override
public void transform(TransformInvocation transformInvocation) throws TransformException, IOException, InterruptedException {
TransformOutputProvider outputProvider = transformInvocation.getOutputProvider();
checkNotNull(outputProvider, "Missing output object for transform " + getName());
// Gather a full list of all inputs.
List<JarInput> jarInputs = Lists.newArrayList();
List<DirectoryInput> directoryInputs = Lists.newArrayList();
for (TransformInput input : transformInvocation.getInputs()) {
jarInputs.addAll(input.getJarInputs());
directoryInputs.addAll(input.getDirectoryInputs());
}
outputProvider.deleteAll();
ClassPool classPool = initClassPool(jarInputs, directoryInputs);
Set<String> outFileNames = Sets.newHashSet();
InjectParam injectParam = null;
try {
injectParam = AtlasBuildContext.sApkInjectInfoCreator.creteInjectParam(appVariantContext);
} catch (DocumentException e) {
throw new TransformException(e);
}
for (JarInput jarInput : jarInputs) {
if (null != logger) {
logger.debug("[ClassInject]" + jarInput.getFile().getAbsolutePath());
}
String jarFileName = jarInput.getFile().getName();
if (jarFileName.equalsIgnoreCase("classes.jar")) {
jarFileName = jarInput.getFile().getParentFile().getParentFile().getParentFile().getName() + "-" + jarInput.getFile().getParentFile().getParentFile().getName() + DOT_JAR;
}
String outFileName = jarFileName.substring(0, jarFileName.length() - DOT_JAR.length());
String fileName = outFileName;
int index = 1;
while (outFileNames.contains(fileName)) {
fileName = outFileName + "-" + index;
index++;
}
outFileNames.add(fileName);
File to = outputProvider.getContentLocation(fileName, jarInput.getContentTypes(), getScopes(), Format.JAR);
//只对 atlas 做代码注入, 没有做多jarmerge
if (injectParam.removePreverify && !jarFileName.contains("atlas") && jarInputs.size() > 1) {
FileUtils.copyFile(jarInput.getFile(), to);
} else {
CodeInjectByJavassist.inject(classPool, jarInput.getFile(), to, injectParam);
}
}
for (DirectoryInput directoryInput : directoryInputs) {
if (null != logger) {
logger.debug("[ClassInject]" + directoryInput.getFile().getAbsolutePath());
}
String folderName = directoryInput.getFile().getName();
File to = outputProvider.getContentLocation(folderName, getOutputTypes(), getScopes(), Format.DIRECTORY);
if (!injectParam.removePreverify) {
CodeInjectByJavassist.injectFolder(classPool, directoryInput.getFile(), to, injectParam);
} else {
FileUtils.copyDirectory(directoryInput.getFile(), to);
}
}
}
Aggregations