use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.
the class ScanDupResTask method generate.
@TaskAction
void generate() {
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == atlasDependencyTree) {
return;
}
File dupResFile = new File(appVariantContext.getProject().getBuildDir(), "outputs/warning-dup-res.properties");
File dupAssetsFile = new File(appVariantContext.getProject().getBuildDir(), "outputs/warning-dup-assets.properties");
ArtifactCollection res = appVariantContext.getScope().getArtifactCollection(AndroidArtifacts.ConsumedConfigType.COMPILE_CLASSPATH, AndroidArtifacts.ArtifactScope.ALL, AndroidArtifacts.ArtifactType.ANDROID_RES);
ArtifactCollection assets = appVariantContext.getScope().getArtifactCollection(AndroidArtifacts.ConsumedConfigType.COMPILE_CLASSPATH, AndroidArtifacts.ArtifactScope.ALL, AndroidArtifacts.ArtifactType.ASSETS);
Set<String> errors = new HashSet<>();
Map<Pair<String, File>, String> map1 = new HashMap<>();
for (File file : assets.getArtifactFiles().getFiles()) {
Collection<File> files = FileUtils.listFiles(file, null, true);
for (File file1 : files) {
boolean e = false;
for (Pair stringFilePair : map1.keySet()) {
if (stringFilePair.getKey().equals(file1.getAbsolutePath().substring(file1.getAbsolutePath().indexOf("assets"))) && !isSameFile((File) stringFilePair.getValue(), file1) && !map1.get(stringFilePair).equals(file.getAbsolutePath())) {
errors.add("dup assets:" + file1.getName() + " in " + map1.get(stringFilePair) + " and " + file.getAbsolutePath());
e = true;
break;
}
}
if (!e) {
map1.put(new Pair<>(file1.getAbsolutePath().substring(file1.getAbsolutePath().indexOf("assets")), file1), file.getAbsolutePath());
}
}
}
try {
FileUtils.writeLines(dupAssetsFile, errors);
} catch (IOException e) {
e.printStackTrace();
}
Map<String, File> map = new HashMap<>();
Map<String, Pair<String, File>> valuesMap = new HashMap<>();
List<String> exceptions = new ArrayList<>();
ResourceMerger resourceMerger = new ResourceMerger(14);
if (res != null) {
Set<ResolvedArtifactResult> libArtifacts = res.getArtifacts();
List<ResourceSet> resourceSetList = Lists.newArrayListWithExpectedSize(libArtifacts.size());
// the order of the artifact is descending order, so we need to reverse it.
for (ResolvedArtifactResult artifact : libArtifacts) {
ResourceSet resourceSet = new ResourceSet(MergeManifests.getArtifactName(artifact), null, null, true);
resourceSet.setFromDependency(true);
resourceSet.addSource(artifact.getFile());
// add to 0 always, since we need to reverse the order.
resourceSetList.add(0, resourceSet);
}
resourceSetList.forEach(resourceSet -> {
try {
resourceSet.loadFromFiles(getILogger());
} catch (MergingException e) {
e.printStackTrace();
}
resourceMerger.addDataSet(resourceSet);
});
ListMultimap<String, ResourceItem> mValuesResMap = ArrayListMultimap.create();
try {
resourceMerger.mergeData(new MergeConsumer<ResourceItem>() {
@Override
public void start(DocumentBuilderFactory documentBuilderFactory) throws ConsumerException {
}
@Override
public void end() throws ConsumerException {
}
@Override
public void addItem(ResourceItem item) throws ConsumerException {
DataFile.FileType type = item.getSourceType();
if (type == DataFile.FileType.XML_VALUES) {
mValuesResMap.put(item.getQualifiers(), item);
} else {
File file = null;
String folderName = null;
Preconditions.checkState(item.getSource() != null);
file = item.getFile();
folderName = getFolderName(item);
// if (ResourceItem.isTouched()) {
String tag = folderName + "/" + file.getName();
if (type == DataFile.FileType.GENERATED_FILES) {
if (!map.containsKey(tag)) {
map.put(tag, file);
} else if (!map.get(tag).equals(file)) {
if (!isSameBundle(map.get(tag), file, atlasDependencyTree) && allInMainBundle(getId(map.get(tag)), getId(file), atlasDependencyTree) && !isSameFile(map.get(tag), file))
exceptions.add("dup File:" + tag + "|" + getId(map.get(tag)) + "|" + getId(file));
}
// try {
// MergedResourceWriter.FileGenerationParameters workItem = new MergedResourceWriter.FileGenerationParameters(item, this.mPreprocessor);
// if (workItem.resourceItem.getSource() != null) {
// this.getExecutor().submit(workItem);
// }
// } catch (Exception var6) {
// throw new ConsumerException(var6, ((ResourceFile)item.getSource()).getFile());
// }
} else if (type == DataFile.FileType.SINGLE_FILE) {
if (!map.containsKey(tag)) {
map.put(tag, file);
} else if (!map.get(tag).equals(file)) {
if (!isSameBundle(map.get(tag), file, atlasDependencyTree) && allInMainBundle(getId(map.get(tag)), getId(file), atlasDependencyTree) && !isSameFile(map.get(tag), file))
exceptions.add("dup File:" + tag + "|" + getId(map.get(tag)) + "|" + getId(file));
}
}
// this.mCompileResourceRequests.add(new CompileResourceRequest(file, this.getRootFolder(), folderName));
// }
}
}
@Override
public void removeItem(ResourceItem removedItem, ResourceItem replacedBy) throws ConsumerException {
DataFile.FileType removedType = removedItem.getSourceType();
DataFile.FileType replacedType = replacedBy != null ? replacedBy.getSourceType() : null;
switch(removedType) {
case SINGLE_FILE:
case GENERATED_FILES:
if (replacedType == DataFile.FileType.SINGLE_FILE || replacedType == DataFile.FileType.GENERATED_FILES) {
// System.out.println(removedItem.getQualifiers()+":"+removedItem.getQualifiers());
// File removedFile = getResourceOutputFile(removedItem);
// File replacedFile = getResourceOutputFile(replacedBy);
// if (removedFile.equals(replacedFile)) {
// break;
// }
}
// this.removeOutFile(removedItem);
break;
case XML_VALUES:
mValuesResMap.put(removedItem.getQualifiers(), replacedBy);
// this.mQualifierWithDeletedValues.add(removedItem.getQualifiers());
break;
default:
throw new IllegalStateException();
}
}
@Override
public boolean ignoreItemInMerge(ResourceItem item) {
DataFile.FileType type = item.getSourceType();
if (type == DataFile.FileType.XML_VALUES) {
mValuesResMap.put(item.getQualifiers(), item);
} else {
File file = null;
String folderName = null;
Preconditions.checkState(item.getSource() != null);
file = item.getFile();
folderName = getFolderName(item);
// if (ResourceItem.isTouched()) {
String tag = folderName + "/" + file.getName();
if (type == DataFile.FileType.GENERATED_FILES) {
if (!map.containsKey(tag)) {
map.put(tag, file);
} else if (!map.get(tag).equals(file)) {
if (!isSameBundle(map.get(tag), file, atlasDependencyTree) && allInMainBundle(getId(map.get(tag)), getId(file), atlasDependencyTree) && !isSameFile(map.get(tag), file))
exceptions.add("dup File:" + tag + "|" + getId(map.get(tag)) + "|" + getId(file));
}
// try {
// MergedResourceWriter.FileGenerationParameters workItem = new MergedResourceWriter.FileGenerationParameters(item, this.mPreprocessor);
// if (workItem.resourceItem.getSource() != null) {
// this.getExecutor().submit(workItem);
// }
// } catch (Exception var6) {
// throw new ConsumerException(var6, ((ResourceFile)item.getSource()).getFile());
// }
} else if (type == DataFile.FileType.SINGLE_FILE) {
if (!map.containsKey(tag)) {
map.put(tag, file);
if (!isSameBundle(map.get(tag), file, atlasDependencyTree) && allInMainBundle(getId(map.get(tag)), getId(file), atlasDependencyTree) && !isSameFile(map.get(tag), file))
exceptions.add("dup File:" + tag + "|" + getId(map.get(tag)) + "|" + getId(file));
}
}
// this.mCompileResourceRequests.add(new CompileResourceRequest(file, this.getRootFolder(), folderName));
// }
}
return false;
}
}, false);
} catch (MergingException e) {
e.printStackTrace();
}
mValuesResMap.asMap().values().forEach(resourceItems -> {
for (ResourceItem resourceItem : resourceItems) {
String tag = null;
if (resourceItem.getSource() == null) {
tag = resourceItem.getQualifiers() + ":" + resourceItem.getType().getName() + ":" + resourceItem.getName();
} else {
tag = resourceItem.getQualifiers() + ":" + resourceItem.getKey();
}
if (!valuesMap.containsKey(tag)) {
String value = getOtherString(resourceItem);
if (resourceItem.getSource() == null || resourceItem.getFile() == null) {
valuesMap.put(tag, new Pair<String, File>(value, new File("aa")));
} else {
valuesMap.put(tag, new Pair<String, File>(value, resourceItem.getFile()));
}
} else {
if (resourceItem.getFile() != null && valuesMap.get(tag) != null) {
if (!valuesMap.get(tag).equals(resourceItem.getFile()) && !isSameValue(resourceItem, valuesMap.get(tag).getKey()))
if (!tag.equals(":string/app_name")) {
exceptions.add("dup value " + tag + "|" + valuesMap.get(tag).getKey() + "|" + getOtherString(resourceItem) + "|" + getId(valuesMap.get(tag).getValue()) + "|" + getId(resourceItem.getFile()));
}
}
}
}
});
Collections.sort(exceptions);
try {
FileUtils.writeLines(dupResFile, exceptions);
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.
the class AwbDataBindingMergeArtifactsTask method createAwbPackages.
/**
* Directory of so
*/
@TaskAction
void createAwbPackages() throws ExecutionException, InterruptedException {
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == atlasDependencyTree) {
return;
}
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
List<Runnable> runnables = new ArrayList<>();
for (final AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
if (!appVariantContext.getAtlasExtension().getTBuildConfig().getDataBindingBundles().contains(awbBundle.getPackageName()) || awbBundle.isMBundle) {
continue;
}
runnables.add(new Runnable() {
@Override
public void run() {
try {
fullCopy(appVariantContext.getAwbDataBindingMergeArtifacts(awbBundle), awbBundle);
} catch (Throwable e) {
e.printStackTrace();
throw new GradleException("merge awb artifact failed");
}
}
});
}
executorServicesHelper.execute(runnables);
}
use of com.taobao.android.builder.dependency.AtlasDependencyTree 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.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.
the class PostProcessManifestAction method execute.
@Override
public void execute(Task task) {
AtlasExtension atlasExtension = appVariantContext.getAtlasExtension();
File bundleBaseLineInfo = appVariantContext.getBundleBaseInfoFile();
VariantScope variantScope = appVariantContext.getScope();
GradleVariantConfiguration config = variantScope.getVariantConfiguration();
AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(config.getFullName());
File androidManifest = null;
File file = variantScope.getInstantRunManifestOutputDirectory();
if (null != file && file.exists() && variantScope.getInstantRunBuildContext().isInInstantRunMode()) {
androidManifest = FileUtils.join(baseVariantOutputData.getProcessManifest().getInstantRunManifestOutputDirectory(), baseVariantOutputData.getDirName(), SdkConstants.ANDROID_MANIFEST_XML);
} else {
androidManifest = FileUtils.join(baseVariantOutputData.getProcessManifest().getManifestOutputDirectory(), baseVariantOutputData.getDirName(), SdkConstants.ANDROID_MANIFEST_XML);
}
try {
Result result = ManifestFileUtils.postProcessManifests(androidManifest, getLibManifestMap(), getLibManifestDepenendyMap(), bundleBaseLineInfo, atlasExtension.manifestOptions, isMultiDexEnabled(), variantScope.getInstantRunBuildContext().isInInstantRunMode(), appVariantContext.getBuildType().isDebuggable(), atlasExtension.getTBuildConfig().getOutOfApkBundles(), atlasExtension.getTBuildConfig().getInsideOfApkBundles(), atlasExtension.getTBuildConfig().isPushInstall());
File proxySrcDir = appVariantContext.getAtlasProxySourceDir();
if (AtlasProxy.genProxyJavaSource(proxySrcDir, result)) {
// appVariantContext.getVariantData().javacTask.source(proxySrcDir);
}
ManifestHelper.checkManifest(appVariantContext, androidManifest, dependencyTree, atlasExtension);
} catch (DocumentException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
// ManifestFileUtils.postProcessManifests(
// instantRunAndroidManifest,
// getLibManifestMap(),
// getLibManifestDepenendyMap(),
// bundleBaseLineInfo,
// atlasExtension.manifestOptions,
// isMultiDexEnabled(),
// true,
// appVariantContext.getBuildType().isDebuggable(),
// atlasExtension.getTBuildConfig()
// .getOutOfApkBundles(),atlasExtension.getTBuildConfig().getInsideOfApkBundles(),atlasExtension.getTBuildConfig().isPushInstall());
// }
// manifest list check
// TODO??
// AtlasBuildContext.androidBuilderMap.get(appVariantContext.getProject()).generateKeepList(
// baseVariantOutputData.manifestProcessorTask.getManifestOutputFile(),
// appVariantContext.getScope()
// .getManifestKeepListProguardFile());
}
use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.
the class PreProcessManifestAction method execute.
@Override
public void execute(Task task) {
AtlasExtension atlasExtension = appVariantContext.getAtlasExtension();
ManifestProcessorTask manifestProcessorTask = baseVariantOutput.getProcessManifest();
Set<String> notMergedArtifacts = Sets.newHashSet();
if (null != atlasExtension.getManifestOptions() && null != atlasExtension.getManifestOptions().getNotMergedBundles()) {
notMergedArtifacts = atlasExtension.getManifestOptions().getNotMergedBundles();
}
if (manifestProcessorTask instanceof MergeManifests) {
MergeManifests mergeManifests = (MergeManifests) manifestProcessorTask;
VariantScope variantScope = appVariantContext.getScope();
GradleVariantConfiguration config = variantScope.getVariantConfiguration();
AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(config.getFullName());
List<ManifestProvider> bundleProviders = ManifestHelper.getBundleManifest(appVariantContext, dependencyTree, atlasExtension);
List<ManifestProvider> mainDexProviders = ManifestHelper.getMainDexManifest(appVariantContext, dependencyTree, atlasExtension);
List<ManifestProvider> allManifest = new ArrayList<>();
modifyForIncremental(mergeManifests, allManifest);
// allManifest.addAll(ManifestHelper.convert(mergeManifests.getProviders(), appVariantContext));
allManifest.addAll(bundleProviders);
allManifest.addAll(mainDexProviders);
AtlasBuildContext.androidBuilderMap.get(appVariantContext.getProject()).manifestProviders = allManifest;
mergeManifests.setAndroidBuilder(AtlasBuildContext.androidBuilderMap.get(appVariantContext.getProject()));
// if (sLogger.isInfoEnabled()) {
// for (ManifestProvider manifestProvider : allManifest) {
// sLogger.warn("[manifestLibs] " + manifestProvider.getManifest().getAbsolutePath());
// }
// }
// Without this step, each time getLibraries It's going to be recomputed from the mapping
// mergeManifests.(allManifest);
}
}
Aggregations