use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.
the class AwbDataBindingRenameTask method createAwbPackages.
/**
* Directory of so
*/
@TaskAction
void createAwbPackages() throws ExecutionException, InterruptedException {
WaitableExecutor workerExecutor = WaitableExecutor.useGlobalSharedThreadPool();
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == atlasDependencyTree) {
return;
}
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
for (final AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
if (!appVariantContext.getAtlasExtension().getTBuildConfig().getDataBindingBundles().contains(awbBundle.getPackageName())) {
continue;
}
if (!awbBundle.isDataBindEnabled() || awbBundle.isMBundle) {
continue;
}
workerExecutor.execute(new Callable() {
@Override
public Object call() {
try {
File dataBindingClazzFolder = appVariantOutputContext.getVariantContext().getJAwbavaOutputDir(awbBundle);
String packageName = awbBundle.getPackageName();
String appName = awbBundle.getPackageName() + "._bundleapp_";
// Remove classes that already exist
File dataMapperClazz = new File(dataBindingClazzFolder, "android/databinding/DataBinderMapper.class");
if (!dataMapperClazz.exists()) {
throw new GradleException("missing datamapper class");
}
File dataBindComponentClazz = new File(dataBindingClazzFolder, "android/databinding/DataBindingComponent.class");
if (!dataBindComponentClazz.exists()) {
throw new GradleException("missing dataBindComponent.class");
}
File dataBindDynamicUtilsClazz = new File(dataBindingClazzFolder, "android/databinding/DynamicUtil.class");
if (!dataBindDynamicUtilsClazz.exists()) {
throw new GradleException("missing dataBindDynamicUtils.class");
}
ClassNameRenamer.rewriteDataBinderMapper(dataBindingClazzFolder, "android/databinding/DataBinderMapper", packageName.replace(".", "/") + "/DataBinderMapper", dataMapperClazz);
ClassNameRenamer.rewriteDataBinderMapper(dataBindingClazzFolder, "android/databinding/DataBindingComponent", packageName.replace(".", "/") + "/DataBindingComponent", dataBindComponentClazz);
ClassNameRenamer.rewriteDataBinderMapper(dataBindingClazzFolder, "android/databinding/dataBindDynamicUtils", packageName.replace(".", "/") + "/dataBindDynamicUtils", dataBindDynamicUtilsClazz);
FileUtils.deleteDirectory(new File(dataBindingClazzFolder, "android/databinding"));
// FileUtils.deleteDirectory(new File(dataBindingClazzFolder, packageName.replace(".", "/") +
// "/_bundleapp_" ));
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);
}
}
// rename DataBindUtils
AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get(awbBundle.getName());
List<File> files = awbTransform.getInputLibraries();
Map<String, String> replaceMap = new HashMap<>();
replaceMap.put("android/databinding/DataBindingUtil", "android/databinding/AtlasDataBindingUtil");
List<File> newLibrarys = new ArrayList<>();
for (File inputJar : files) {
File outputJar = new File(appVariantContext.getAwbLibraryDirForDataBinding(awbBundle), FileNameUtils.getUniqueJarName(inputJar) + ".jar");
outputJar.delete();
outputJar.getParentFile().mkdirs();
outputJar.createNewFile();
new ClazzReplacer(inputJar, outputJar, replaceMap).execute();
newLibrarys.add(outputJar);
awbTransform.getFileTransform().put(inputJar, outputJar);
}
awbTransform.setInputLibraries(newLibrarys);
} catch (Throwable e) {
e.printStackTrace();
throw new GradleException("databinding awb failed", e);
}
return null;
}
});
}
workerExecutor.waitForTasksWithQuickFail(true);
}
use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.
the class TaobaoExtractJarsTransform method transform.
@Override
public void transform(TransformInvocation transformInvocation) throws IOException, TransformException, InterruptedException {
TransformOutputProvider outputProvider = transformInvocation.getOutputProvider();
boolean isIncremental = transformInvocation.isIncremental();
checkNotNull(outputProvider, "Missing output object for transform " + getName());
// as_input transform and no referenced scopes, all the inputs will in InputOutputStreams.
final boolean extractCode = contentTypes.contains(QualifiedContent.DefaultContentType.CLASSES);
if (!isIncremental) {
outputProvider.deleteAll();
}
try {
WaitableExecutor executor = WaitableExecutor.useGlobalSharedThreadPool();
AtlasBuildContext.atlasMainDexHelperMap.get(variantContext.getVariantName()).getInputDirs().clear();
for (File jarFile : AtlasBuildContext.atlasMainDexHelperMap.get(variantContext.getVariantName()).getAllMainDexJars()) {
// final File jarFile = jarInput.getFile();
JarInput jarInput = makeJarInput(jarFile);
LOGGER.warn("input JarFile:" + jarFile.getAbsolutePath());
// create an output folder for this jar, keeping its type and scopes.
final File outJarFolder = outputProvider.getContentLocation(jarInput.getName(), jarInput.getContentTypes(), jarInput.getScopes(), Format.DIRECTORY);
FileUtils.mkdirs(outJarFolder);
LOGGER.warn("outJar Folder:" + outJarFolder.getAbsolutePath());
AtlasBuildContext.atlasMainDexHelperMap.get(variantContext.getVariantName()).getInputDirs().add(outJarFolder);
if (!isIncremental) {
executor.execute(() -> {
extractJar(outJarFolder, jarFile, extractCode);
return null;
});
} else {
switch(jarInput.getStatus()) {
case CHANGED:
executor.execute(() -> {
FileUtils.cleanOutputDir(outJarFolder);
extractJar(outJarFolder, jarFile, extractCode);
return null;
});
break;
case ADDED:
executor.execute(() -> {
extractJar(outJarFolder, jarFile, extractCode);
return null;
});
break;
case REMOVED:
executor.execute(() -> {
FileUtils.cleanOutputDir(outJarFolder);
return null;
});
break;
case NOTCHANGED:
break;
}
}
}
AtlasBuildContext.atlasMainDexHelperMap.get(variantContext.getVariantName()).addMainDexJars(Sets.newHashSet());
for (AwbTransform awbTransform : variantOutputContext.getAwbTransformMap().values()) {
File outJarFolder = variantOutputContext.getAwbExtractJarsFolder(awbTransform.getAwbBundle());
awbTransform.getInputFiles().forEach(file -> executor.execute(() -> {
LOGGER.warn("ExtractAwbJar[" + awbTransform.getAwbBundle().getPackageName() + "]---------------------" + file.getAbsolutePath());
extractJar(outJarFolder, file, extractCode);
return null;
}));
awbTransform.getInputLibraries().forEach(file -> executor.execute(() -> {
LOGGER.warn("ExtractAwbJar[" + awbTransform.getAwbBundle().getPackageName() + "]---------------------" + file.getAbsolutePath());
extractJar(outJarFolder, file, extractCode);
return null;
}));
awbTransform.addDir(outJarFolder);
awbTransform.getInputFiles().clear();
}
executor.waitForTasksWithQuickFail(true);
} catch (InterruptedException e) {
throw e;
} catch (Exception e) {
throw new TransformException(e);
}
}
use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.
the class AwbProguardConfiguration method printConfigFile.
/**
* 打印proguard的config文件到指定文件
* @param outConfigFile
*/
public void printConfigFile(File outConfigFile) throws IOException {
List<String> configs = Lists.newArrayList();
for (AwbTransform awbTransform : awbTransforms) {
String name = awbTransform.getAwbBundle().getName();
File obuscateFile = new File(awbObfuscatedDir, awbTransform.getAwbBundle().getName() + File.separator + OBUSCATED_JAR);
obuscateFile.getParentFile().mkdirs();
// configs.add();
if (null != awbTransform.getInputDir() && awbTransform.getInputDir().exists()) {
configs.add(INJARS_OPTION + " " + awbTransform.getInputDir().getAbsolutePath());
}
for (File inputLibrary : awbTransform.getInputLibraries()) {
configs.add(INJARS_OPTION + " " + inputLibrary.getAbsolutePath());
}
// configs.add();
configs.add(OUTJARS_OPTION + " " + obuscateFile.getAbsolutePath());
List<File> inputLibraries = Lists.newArrayList();
inputLibraries.add(obuscateFile);
awbTransform.setInputFiles(inputLibraries);
awbTransform.setInputDir(null);
awbTransform.getInputLibraries().clear();
appVariantOutputContext.getAwbTransformMap().put(name, awbTransform);
}
FileUtils.writeLines(outConfigFile, configs);
}
Aggregations