use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.
the class BuildAtlasEnvTask method generate.
@TaskAction
void generate() throws TransformException {
Set<ResolvedArtifactResult> compileArtifacts = compileManifests.getArtifacts();
Set<ResolvedArtifactResult> jarArtifacts = compileJars.getArtifacts();
Set<ResolvedArtifactResult> nativeLibsArtifacts = nativeLibs.getArtifacts();
Set<ResolvedArtifactResult> javaResourcesArtifacts = javaResources.getArtifacts();
Set<ResolvedArtifactResult> androidRes = res.getArtifacts();
Set<ResolvedArtifactResult> androidAssets = assets.getArtifacts();
Set<ResolvedArtifactResult> androidRnames = symbolListWithPackageNames.getArtifacts();
AtlasDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
List<AwbBundle> bundles = new ArrayList<>();
bundles.add(androidDependencyTree.getMainBundle());
bundles.addAll(androidDependencyTree.getAwbBundles());
// this is no used ,if used in future add to transform!
Set<ResolvedArtifactResult> nativeLibsArtifacts2 = nativeLibs2.getArtifacts();
nativeLibsArtifacts.addAll(nativeLibsArtifacts2);
AtlasBuildContext.localLibs = nativeLibs2.getArtifactFiles().getFiles();
for (ResolvedArtifactResult resolvedArtifactResult : jarArtifacts) {
ComponentIdentifier componentIdentifier = resolvedArtifactResult.getId().getComponentIdentifier();
if (componentIdentifier instanceof DefaultModuleComponentIdentifier) {
allJars.add(new FileIdentity(((DefaultModuleComponentIdentifier) componentIdentifier).getGroup() + ":" + ((DefaultModuleComponentIdentifier) componentIdentifier).getModule(), resolvedArtifactResult.getFile(), resolvedArtifactResult.getId().getDisplayName().startsWith("classes.jar") ? false : true, false));
} else if (componentIdentifier instanceof DefaultProjectComponentIdentifier) {
String projectPath = ((DefaultProjectComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getProjectPath();
allJars.add(new FileIdentity(projectPath.substring(projectPath.lastIndexOf(":") + 1), resolvedArtifactResult.getFile(), resolvedArtifactResult.getId().getDisplayName().startsWith("classes.jar") ? false : true, true));
} else if (componentIdentifier instanceof OpaqueComponentArtifactIdentifier) {
if (resolvedArtifactResult.getFile().getAbsolutePath().contains("renderscript"))
appLocalJars.add(new FileIdentity(componentIdentifier.getDisplayName(), resolvedArtifactResult.getFile(), true, false));
}
}
for (ResolvedArtifactResult resolvedArtifactResult : compileArtifacts) {
if (resolvedArtifactResult.getId().getComponentIdentifier() instanceof DefaultModuleComponentIdentifier) {
allManifests.put(((DefaultModuleComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getGroup() + ":" + ((DefaultModuleComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getModule(), resolvedArtifactResult.getFile());
} else if (resolvedArtifactResult.getId().getComponentIdentifier() instanceof DefaultProjectComponentIdentifier) {
String projectPath = ((DefaultProjectComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getProjectPath();
allManifests.put(projectPath.substring(projectPath.lastIndexOf(":") + 1), resolvedArtifactResult.getFile());
}
}
for (ResolvedArtifactResult resolvedArtifactResult : nativeLibsArtifacts) {
if (resolvedArtifactResult.getId().getComponentIdentifier() instanceof DefaultModuleComponentIdentifier) {
allSolibs.put(((DefaultModuleComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getGroup() + ":" + ((DefaultModuleComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getModule(), resolvedArtifactResult.getFile());
} else if (resolvedArtifactResult.getId().getComponentIdentifier() instanceof DefaultProjectComponentIdentifier) {
String projectPath = ((DefaultProjectComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getProjectPath();
allSolibs.put(projectPath.substring(projectPath.lastIndexOf(":") + 1), resolvedArtifactResult.getFile());
}
}
for (ResolvedArtifactResult resolvedArtifactResult : javaResourcesArtifacts) {
if (resolvedArtifactResult.getId().getComponentIdentifier() instanceof DefaultModuleComponentIdentifier) {
allJavaRes.put(((DefaultModuleComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getGroup() + ":" + ((DefaultModuleComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getModule(), resolvedArtifactResult.getFile());
} else if (resolvedArtifactResult.getId().getComponentIdentifier() instanceof DefaultProjectComponentIdentifier) {
String projectPath = ((DefaultProjectComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getProjectPath();
allJavaRes.put(projectPath.substring(projectPath.lastIndexOf(":") + 1), resolvedArtifactResult.getFile());
}
}
for (ResolvedArtifactResult resolvedArtifactResult : androidRes) {
if (resolvedArtifactResult.getId().getComponentIdentifier() instanceof DefaultModuleComponentIdentifier) {
allAndroidRes.put(((DefaultModuleComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getGroup() + ":" + ((DefaultModuleComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getModule(), resolvedArtifactResult);
} else if (resolvedArtifactResult.getId().getComponentIdentifier() instanceof DefaultProjectComponentIdentifier) {
String projectPath = ((DefaultProjectComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getProjectPath();
allAndroidRes.put(projectPath.substring(projectPath.lastIndexOf(":") + 1), resolvedArtifactResult);
}
}
for (ResolvedArtifactResult resolvedArtifactResult : androidAssets) {
if (resolvedArtifactResult.getId().getComponentIdentifier() instanceof DefaultModuleComponentIdentifier) {
allAndroidAssets.put(((DefaultModuleComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getGroup() + ":" + ((DefaultModuleComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getModule(), resolvedArtifactResult);
} else if (resolvedArtifactResult.getId().getComponentIdentifier() instanceof DefaultProjectComponentIdentifier) {
String projectPath = ((DefaultProjectComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getProjectPath();
allAndroidAssets.put(projectPath.substring(projectPath.lastIndexOf(":") + 1), resolvedArtifactResult);
}
}
for (ResolvedArtifactResult resolvedArtifactResult : androidRnames) {
if (resolvedArtifactResult.getId().getComponentIdentifier() instanceof DefaultModuleComponentIdentifier) {
allAndroidRnames.put(((DefaultModuleComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getGroup() + ":" + ((DefaultModuleComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getModule(), resolvedArtifactResult);
} else if (resolvedArtifactResult.getId().getComponentIdentifier() instanceof DefaultProjectComponentIdentifier) {
String projectPath = ((DefaultProjectComponentIdentifier) resolvedArtifactResult.getId().getComponentIdentifier()).getProjectPath();
allAndroidRnames.put(projectPath.substring(projectPath.lastIndexOf(":") + 1), resolvedArtifactResult);
}
}
// app localJar is not support , this may course duplicate localjars
appLocalJars.stream().forEach(fileIdentity -> AtlasBuildContext.atlasMainDexHelperMap.get(getVariantName()).addMainDex(fileIdentity));
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
List<AndroidLibrary> androidLibraries = atlasDependencyTree.getAllAndroidLibrarys();
androidLibraries.stream().forEach(androidLibrary -> {
if (androidLibrary instanceof AtlasAndroidLibraryImpl) {
AndroidDependency fakeAndroidLibrary = ((AtlasAndroidLibraryImpl) androidLibrary).getAndroidLibrary();
File id = null;
if ((id = allManifests.get(androidLibrary.getResolvedCoordinates().getGroupId() + ":" + androidLibrary.getResolvedCoordinates().getArtifactId())) == null) {
id = allManifests.get(androidLibrary.getResolvedCoordinates().toString().split(":")[1]);
}
if (id == null) {
getLogger().warn("id == null---------------------" + androidLibrary.getResolvedCoordinates().getGroupId() + ":" + androidLibrary.getResolvedCoordinates().getArtifactId());
throw new GradleException("excute failed! ");
}
ReflectUtils.updateField(fakeAndroidLibrary, "extractedFolder", id.getParentFile());
ReflectUtils.updateField(fakeAndroidLibrary, "jarsRootFolder", id.getParentFile());
((AtlasAndroidLibraryImpl) androidLibrary).setAndroidLibrary(AndroidDependency.createExplodedAarLibrary(null, androidLibrary.getResolvedCoordinates(), androidLibrary.getName(), ((AtlasAndroidLibraryImpl) androidLibrary).getPath(), id.getParentFile()));
appVariantContext.manifestMap.put(androidLibrary.getManifest().getAbsolutePath(), appVariantContext.getModifyManifest(androidLibrary));
}
});
List<AndroidLibrary> mainDexAndroidLibraries = atlasDependencyTree.getMainBundle().getAndroidLibraries();
List<JavaLibrary> mainDexJarLibraries = atlasDependencyTree.getMainBundle().getJavaLibraries();
List<SoLibrary> mainSoLibraries = atlasDependencyTree.getMainBundle().getSoLibraries();
for (AndroidLibrary androidLibrary : mainDexAndroidLibraries) {
String name = androidLibrary.getResolvedCoordinates().getGroupId() + ":" + androidLibrary.getResolvedCoordinates().getArtifactId();
String moudleName = androidLibrary.getResolvedCoordinates().toString().split(":")[1];
fillMainManifest(name, moudleName);
fillMainJar(name, moudleName);
fillAllJavaRes(name, moudleName);
fillMainSolibs(name, moudleName);
}
for (JavaLibrary jarLibrary : mainDexJarLibraries) {
String moudleName = jarLibrary.getName().split(":")[1];
String name = jarLibrary.getResolvedCoordinates().getGroupId() + ":" + jarLibrary.getResolvedCoordinates().getArtifactId();
fillMainJar(name, moudleName);
fillAllJavaRes(name, moudleName);
}
for (SoLibrary soLibrary : mainSoLibraries) {
String name = soLibrary.getResolvedCoordinates().getGroupId() + ":" + soLibrary.getResolvedCoordinates().getArtifactId();
String moudleName = soLibrary.getResolvedCoordinates().toString().split(":")[1];
fillMainSolibs(name, moudleName);
}
for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
List<AndroidLibrary> awbAndroidLibraries = awbBundle.getAndroidLibraries();
List<JavaLibrary> awbJarLibraries = awbBundle.getJavaLibraries();
List<SoLibrary> awbSoLibraries = awbBundle.getSoLibraries();
for (AndroidLibrary androidLibrary : awbAndroidLibraries) {
String name = androidLibrary.getResolvedCoordinates().getGroupId() + ":" + androidLibrary.getResolvedCoordinates().getArtifactId();
String moudleName = androidLibrary.getResolvedCoordinates().toString().split(":")[1];
fillAwbManifest(name, moudleName, awbBundle);
fillAwbJar(name, moudleName, awbBundle);
fillAwbAllJavaRes(name, moudleName, awbBundle);
fillAwbSolibs(name, moudleName, awbBundle);
fillAwbAndroidRes(name, moudleName, awbBundle);
fillAwbAndroidAssets(name, moudleName, awbBundle);
fillAwbAndroidRs(name, moudleName, awbBundle);
}
for (JavaLibrary jarLibrary : awbJarLibraries) {
String moudleName = jarLibrary.getName().split(":")[1];
String name = jarLibrary.getResolvedCoordinates().getGroupId() + ":" + jarLibrary.getResolvedCoordinates().getArtifactId();
fillAwbJar(name, moudleName, awbBundle);
}
for (SoLibrary soLibrary : awbSoLibraries) {
String name = soLibrary.getResolvedCoordinates().getGroupId() + ":" + soLibrary.getResolvedCoordinates().getArtifactId();
String moudleName = soLibrary.getResolvedCoordinates().toString().split(":")[1];
fillAwbSolibs(name, moudleName, awbBundle);
}
String name = awbBundle.getResolvedCoordinates().getGroupId() + ":" + awbBundle.getResolvedCoordinates().getArtifactId();
String moudleName = awbBundle.getResolvedCoordinates().toString().split(":")[1];
fillAwbManifest(name, moudleName, awbBundle);
fillAwbJar(name, moudleName, awbBundle);
fillAwbAllJavaRes(name, moudleName, awbBundle);
fillAwbSolibs(name, moudleName, awbBundle);
fillAwbAndroidRes(name, moudleName, awbBundle);
fillAwbAndroidAssets(name, moudleName, awbBundle);
fillAwbAndroidRs(name, moudleName, awbBundle);
}
MergeResources mergeResources = appVariantContext.getScope().getMergeResourcesTask().get(new TaskContainerAdaptor(getProject().getTasks()));
try {
// mergeresources
Field field = MergeResources.class.getDeclaredField("libraries");
field.setAccessible(true);
field.set(mergeResources, new MainArtifactsCollection((ArtifactCollection) field.get(mergeResources), getProject(), mergeResources.getVariantName()));
appVariantOutputContext.getAwbTransformMap().values().stream().forEach(awbTransform -> {
if (isMBundle(appVariantContext, awbTransform.getAwbBundle())) {
try {
awbTransform.getAwbBundle().isMBundle = true;
awbTransform.getAwbBundle().bundleInfo.setIsMBundle(true);
field.set(mergeResources, new AppendMainArtifactsCollection(appVariantContext.getProject(), (ArtifactCollection) field.get(mergeResources), awbTransform.getAwbBundle(), ANDROID_RES));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
});
mergeResources.doLast(task -> FileUtils.listFiles(((MergeResources) task).getOutputDir(), new String[] { "xml" }, true).parallelStream().forEach(file -> {
if (!AppendMainArtifactsCollection.bundle2Map.containsKey(file.getName())) {
return;
}
List<String> lines = null;
List<String> newLines = new ArrayList<>();
try {
lines = FileUtils.readLines(file);
lines.forEach(s -> {
String s1 = s;
if (s.contains("http://schemas.android.com/apk/res/" + AppendMainArtifactsCollection.bundle2Map.get(file.getName()))) {
s1 = s.replace("http://schemas.android.com/apk/res/" + AppendMainArtifactsCollection.bundle2Map.get(file.getName()), "http://schemas.android.com/apk/res-auto");
}
newLines.add(s1);
});
FileUtils.writeLines(file, newLines);
} catch (IOException e) {
e.printStackTrace();
}
}));
// mergeSourcesSets
MergeSourceSetFolders mergeSourceSetFolders = appVariantContext.getScope().getMergeAssetsTask().get(new TaskContainerAdaptor(getProject().getTasks()));
Field assetsField = MergeSourceSetFolders.class.getDeclaredField("libraries");
assetsField.setAccessible(true);
assetsField.set(mergeSourceSetFolders, new MainArtifactsCollection((ArtifactCollection) assetsField.get(mergeSourceSetFolders), getProject(), mergeSourceSetFolders.getVariantName()));
appVariantOutputContext.getAwbTransformMap().values().stream().forEach(awbTransform -> {
if (isMBundle(appVariantContext, awbTransform.getAwbBundle())) {
try {
awbTransform.getAwbBundle().isMBundle = true;
awbTransform.getAwbBundle().bundleInfo.setIsMBundle(true);
assetsField.set(mergeSourceSetFolders, new AppendMainArtifactsCollection(appVariantContext.getProject(), (ArtifactCollection) assetsField.get(mergeSourceSetFolders), awbTransform.getAwbBundle(), ASSETS));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
});
AtlasBuildContext.atlasMainDexHelperMap.get(getVariantName()).getMainSoFiles().put(appVariantContext.getScope().getMergeNativeLibsOutputDir().getAbsolutePath(), true);
} catch (Exception e) {
}
// process resources
ProcessAndroidResources processAndroidResources = appVariantContext.getScope().getProcessResourcesTask().get(new TaskContainerAdaptor(appVariantContext.getProject().getTasks()));
FileCollection fileCollection = processAndroidResources.getSymbolListsWithPackageNames();
Set<String> filesNames = new HashSet<>();
for (String fileName : AtlasBuildContext.atlasMainDexHelperMap.get(getVariantName()).getMainManifestFiles().keySet()) {
filesNames.add(fileName.substring(fileName.lastIndexOf(File.separatorChar) + 1));
}
FileCollection updateFileCollection = fileCollection.filter(element -> filesNames.contains(element.getParentFile().getParentFile().getName()));
ReflectUtils.updateField(processAndroidResources, "symbolListsWithPackageNames", updateFileCollection);
appVariantOutputContext.getAwbTransformMap().values().stream().forEach(awbTransform -> {
if (isMBundle(appVariantContext, awbTransform.getAwbBundle())) {
awbTransform.getAwbBundle().isMBundle = true;
awbTransform.getAwbBundle().bundleInfo.setIsMBundle(true);
FileCollection fc = new AppendMainArtifactsCollection(appVariantContext.getProject(), processAndroidResources.getSymbolListsWithPackageNames(), awbTransform.getAwbBundle(), SYMBOL_LIST_WITH_PACKAGE_NAME).getArtifactFiles();
ReflectUtils.updateField(processAndroidResources, "symbolListsWithPackageNames", fc);
}
});
appVariantContext.processResAwbsTask.mainDexSymbolFileCollection = updateFileCollection;
// FileCollection fs = appVariantContext.getScope().getArtifactFileCollection(AndroidArtifacts.ConsumedConfigType.COMPILE_CLASSPATH,AndroidArtifacts.ArtifactScope.ALL,AndroidArtifacts.ArtifactType.CLASSES);
// fs.getFiles().forEach(new Consumer<File>() {
// @Override
// public void accept(File file) {
// if (file.exists()){
// try {
// JarFile jarFile = new JarFile(file);
// Enumeration<JarEntry>enumeration = jarFile.entries();
// while (enumeration.hasMoreElements()){
// JarEntry jarEntry = enumeration.nextElement();
// if (jarEntry.getName().endsWith(".class")){
// ClassReader classReader = new ClassReader(jarFile.getInputStream(jarEntry));
// String[]ss = classReader.getInterfaces();
// if (ss!= null){
// for (String s:ss){
// if (s.contains("IExternalComponentGetter")||s.contains("IExternalComponentGetter.class")){
// System.out.println("IExternalComponentGetter:"+jarEntry.getName());
// }else if (s.contains("IExternalModuleGetter")||s.contains("IExternalModuleGetter.class")){
// System.out.println("IExternalModuleGetter:"+jarEntry.getName());
// }
// }
// }
//
// }
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// }
// });
allManifests.clear();
allJavaRes.clear();
allSolibs.clear();
allJars.clear();
allAndroidAssets.clear();
allAndroidRes.clear();
//
// try {
// duplicateClazzNote();
// } catch (IOException e) {
// e.printStackTrace();
// }
}
use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.
the class JavacAwbsTask method run.
@TaskAction
void run() throws ExecutionException, InterruptedException {
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == atlasDependencyTree) {
return;
}
BaseExtension androidExtension = appVariantOutputContext.getVariantContext().getAppExtension();
boolean isDatabindEnabled = null != androidExtension.getDataBinding() && androidExtension.getDataBinding().isEnabled();
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
ExecutorServicesHelper executorServicesHelper2 = new ExecutorServicesHelper(taskName + "databinding", getLogger(), 1);
List<Runnable> runnables = new ArrayList<>();
List<Runnable> runnables2 = new ArrayList<>();
for (final AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
if (awbBundle.isMBundle) {
continue;
}
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
AwbJavaCompileConfigAction awbJavaCompileConfigAction = new AwbJavaCompileConfigAction(awbBundle, appVariantOutputContext);
AwbAndroidJavaCompile awbJavaCompile = TaskCreater.create(getProject(), awbJavaCompileConfigAction.getName(), awbJavaCompileConfigAction.getType());
awbJavaCompileConfigAction.execute(awbJavaCompile);
awbJavaCompile.execute();
AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get(awbBundle.getName());
awbTransform.addDir(awbJavaCompile.getDestinationDir());
} catch (Throwable e) {
e.printStackTrace();
throw new GradleException("javac " + awbBundle.getName() + " failed");
}
}
};
if (appVariantOutputContext.getVariantContext().isDataBindEnabled(awbBundle)) {
runnables2.add(runnable);
} else {
runnables.add(runnable);
}
}
executorServicesHelper.execute(runnables);
executorServicesHelper2.execute(runnables2);
}
use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.
the class AtlasProguardHelper method addLibraryProguardFiles.
@NotNull
private static void addLibraryProguardFiles(AppVariantContext appVariantContext, Input input) {
if (!appVariantContext.getAtlasExtension().getTBuildConfig().isBundleProguardConfigEnabled()) {
return;
}
Set<String> blackList = appVariantContext.getAtlasExtension().getTBuildConfig().getBundleProguardConfigBlackList();
for (AwbTransform awbTransform : input.getAwbBundles()) {
AwbBundle awbBundle = awbTransform.getAwbBundle();
for (AndroidLibrary androidDependency : awbBundle.getAllLibraryAars()) {
File proguardRules = androidDependency.getProguardRules();
String groupName = androidDependency.getResolvedCoordinates().getGroupId() + ":" + androidDependency.getResolvedCoordinates().getArtifactId();
if (blackList.contains(groupName)) {
sLogger.info("[proguard] skip proguard from " + androidDependency.getResolvedCoordinates());
continue;
}
if (proguardRules.exists() && proguardRules.isFile()) {
input.getLibraryProguardFiles().add(proguardRules);
sLogger.warn("[proguard] load proguard from " + androidDependency.getResolvedCoordinates());
} else {
sLogger.info("[proguard] missing proguard from " + androidDependency.getResolvedCoordinates());
}
}
}
}
use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.
the class BundleProguarder method cacheProguard.
private static void cacheProguard(AppVariantContext appVariantContext, Input input, Result result) throws FileCacheException, IOException {
AwbBundle awbBundle = input.getAwbBundles().get(0).getAwbBundle();
File tmpDir = new File(appVariantContext.getScope().getGlobalScope().getIntermediatesDir(), "progurad-cache/" + awbBundle.getName());
tmpDir.mkdirs();
for (AwbTransform awbTransform : input.getAwbBundles()) {
for (File file : awbTransform.getInputFiles()) {
if (file.exists()) {
String md5 = input.proguardJarMap.get(file);
if (StringUtils.isNoneEmpty(md5)) {
FileUtils.copyFile(file, new File(tmpDir, md5 + ".jar"));
} else {
FileUtils.copyFileToDirectory(file, tmpDir);
}
} else {
new File(tmpDir, file.getName()).createNewFile();
}
}
}
// Keep cache. Json
File keepFile = awbBundle.getKeepProguardFile();
if (null != keepFile && keepFile.exists()) {
FileUtils.copyFileToDirectory(keepFile, tmpDir);
}
File proguardCfg = new File(null != input.proguardOutputDir ? input.proguardOutputDir : appVariantContext.getAwbProguardDir(awbBundle), "proguard.cfg");
if (!proguardCfg.exists()) {
proguardCfg = input.printConfiguration;
}
if (null != proguardCfg && proguardCfg.exists()) {
FileUtils.copyFileToDirectory(proguardCfg, tmpDir);
}
File usageCfg = new File(null != input.proguardOutputDir ? input.proguardOutputDir : appVariantContext.getAwbProguardDir(awbBundle), "usage.cfg");
if (!usageCfg.exists()) {
usageCfg = input.printUsage;
}
if (null != usageCfg && usageCfg.exists()) {
FileUtils.copyFileToDirectory(usageCfg, tmpDir);
}
FileCacheCenter.cacheFile(CACHE_TYPE, result.key, tmpDir, AtlasBuildContext.sBuilderAdapter.pushCacheToNetwork && isRemoteCacheEnabled(appVariantContext));
}
use of com.android.build.gradle.internal.api.AwbTransform in project atlas by alibaba.
the class AtlasDexArchiveBuilderTransform method processAwbDexArchive.
private void processAwbDexArchive(TransformInvocation transformInvocation, List<QualifiedContent> listFiles) throws Exception {
File awbApkOutputDir = ((AppVariantContext) variantContext).getAwbApkOutputDir();
FileUtils.cleanOutputDir(awbApkOutputDir);
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantContext.getScope().getFullVariantName());
if (null == atlasDependencyTree) {
return;
}
for (final AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
Multimap<QualifiedContent, File> cacheableItems = HashMultimap.create();
List<QualifiedContent> qualifiedContents = new LinkedList<>();
long start = System.currentTimeMillis();
// if some of our .jar input files exist, just reset the inputDir to null
AwbTransform awbTransform = variantContext.getAppVariantOutputContext(ApkDataUtils.get(variantOutput)).getAwbTransformMap().get(awbBundle.getName());
List<File> inputFiles = new ArrayList<File>();
inputFiles.addAll(awbTransform.getInputFiles());
inputFiles.addAll(awbTransform.getInputLibraries());
if (null != awbTransform.getInputDirs()) {
inputFiles.addAll(awbTransform.getInputDirs());
}
for (File file : inputFiles) {
logger.warning(awbBundle.getName() + ":" + file.getAbsolutePath());
boolean find = false;
for (QualifiedContent content : listFiles) {
if (content.getFile().getAbsolutePath().equals(file.getAbsolutePath())) {
find = true;
qualifiedContents.add(content);
break;
}
}
if (!find) {
if (file.isDirectory()) {
DirectoryInput directoryInput = TransformInputUtils.makeDirectoryInput(file, variantContext);
qualifiedContents.add(directoryInput);
} else if (file.isFile()) {
JarInput jarInput = TransformInputUtils.makeJarInput(file, variantContext);
qualifiedContents.add(jarInput);
}
}
}
for (QualifiedContent qualifiedContent : qualifiedContents) {
if (qualifiedContent.getFile().isDirectory()) {
List<File> awbFiles = convertAwbToDexArchive(transformInvocation.getContext(), qualifiedContent, variantContext.getAwbDexAchiveOutput(awbBundle), transformInvocation.isIncremental(), true);
cacheableItems.putAll(qualifiedContent, awbFiles);
} else {
List<File> jarFiles = processAwbJarInput(transformInvocation.getContext(), transformInvocation.isIncremental(), (JarInput) qualifiedContent, variantContext.getAwbDexAchiveOutput(awbBundle));
cacheableItems.putAll(qualifiedContent, jarFiles);
}
}
cacheItems.putAll(cacheableItems);
}
}
Aggregations