use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class LogDependenciesTask method generate.
@TaskAction
void generate() {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == androidDependencyTree) {
return;
}
File treeFile = new File(getProject().getBuildDir(), "outputs/dependencyTree-" + getVariantName() + ".json");
File dependenciesFile = new File(getProject().getBuildDir(), "outputs/dependencies.txt");
File versionProperties = new File(getProject().getBuildDir(), "outputs/version.properties");
File buildInfo = new File(getProject().getBuildDir(), "outputs/build.txt");
File atlasConfig = new File(getProject().getBuildDir(), "outputs/atlasConfig.json");
appBuildInfo.setDependencyTreeFile(treeFile);
appBuildInfo.setDependenciesFile(dependenciesFile);
appBuildInfo.setVersionPropertiesFile(versionProperties);
appBuildInfo.setBuildInfoFile(buildInfo);
treeFile.delete();
dependenciesFile.delete();
versionProperties.delete();
buildInfo.delete();
treeFile.getParentFile().mkdirs();
try {
DependencyJson dependencyJson = androidDependencyTree.getDependencyJson();
Collections.sort(dependencyJson.getMainDex());
FileUtils.write(treeFile, JSON.toJSONString(dependencyJson, true));
//add to ap
appBuildInfo.getOtherFilesMap().put("awo/dependencyTree.json", treeFile);
} catch (IOException e) {
e.printStackTrace();
}
try {
FileUtils.writeStringToFile(dependenciesFile, JSON.toJSONString(androidDependencyTree.getDependencyJson()));
} catch (IOException e) {
e.printStackTrace();
}
try {
FileUtils.writeLines(versionProperties, getSortVersionList(androidDependencyTree));
} catch (IOException e) {
e.printStackTrace();
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("gradleVersion:").append(getProject().getGradle().getGradleVersion()).append("\r\n");
stringBuilder.append("mtlVersion:").append(Version.ANDROID_GRADLE_PLUGIN_VERSION).append("\r\n");
stringBuilder.append("androidVersion:").append(PathUtil.getJarFile(AndroidBuilder.class)).append("\r\n");
try {
FileUtils.writeStringToFile(buildInfo, stringBuilder.toString());
} catch (IOException e) {
e.printStackTrace();
}
try {
FileUtils.write(atlasConfig, JSON.toJSONString(new AtlasExtensionOutput(appVariantContext.getAtlasExtension(), getVariantName()), true));
} catch (IOException e) {
e.printStackTrace();
}
if (null != AtlasBuildContext.conflictDependencies && !AtlasBuildContext.conflictDependencies.isEmpty()) {
try {
FileUtils.writeLines(new File(getProject().getBuildDir(), "outputs/warning-dependencyConflict.properties"), AtlasBuildContext.conflictDependencies);
} catch (IOException e) {
e.printStackTrace();
}
if (appVariantContext.getAtlasExtension().getTBuildConfig().isAbortIfDependencyConflict()) {
throw new GradleException("依赖冲突,具体见warning-dependencyConflict.properties");
}
}
}
use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class JavacAwbsTask method run.
@TaskAction
void run() 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 {
AwbJavaCompileConfigAction awbJavaCompileConfigAction = new AwbJavaCompileConfigAction(awbBundle, appVariantOutputContext);
JavaCompile awbJavaCompile = TaskCreater.create(getProject(), awbJavaCompileConfigAction.getName(), awbJavaCompileConfigAction.getType());
awbJavaCompileConfigAction.execute(awbJavaCompile);
awbJavaCompile.execute();
AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get(awbBundle.getName());
awbTransform.setInputDir(awbJavaCompile.getDestinationDir());
} catch (Throwable e) {
e.printStackTrace();
throw new GradleException("javac " + awbBundle.getName() + " failed");
}
}
});
}
executorServicesHelper.execute(runnables);
}
use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class MergeResV4Dir method taskAction.
@TaskAction
public void taskAction() throws IOException {
File resDir = variantScope.getFinalResourcesDir();
moveFiles(resDir);
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null != androidDependencyTree) {
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
File awbResDir = variantContext.getMergeResources(awbBundle);
moveFiles(awbResDir);
}
}
}
use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class PrepareAwbTask method run.
@TaskAction
void run() throws ExecutionException, InterruptedException, IOException, DocumentException {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == androidDependencyTree) {
return;
}
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
List<Runnable> runnables = new ArrayList<>();
Set<SoLibrary> soLibraries = androidDependencyTree.getALLSoLibDependencies();
for (final SoLibrary soLibrary : soLibraries) {
runnables.add(new Runnable() {
@Override
public void run() {
prepare(soLibrary.getSoLibFile(), soLibrary.getFolder(), false);
}
});
}
executorServicesHelper.execute(runnables);
runnables.clear();
List<AwbBundle> awbBundles = androidDependencyTree.getAwbBundles();
for (final AwbBundle awbBundle : awbBundles) {
runnables.add(new Runnable() {
@Override
public void run() {
prepare(awbBundle.getBundle(), awbBundle.getFolder(), true);
}
});
}
executorServicesHelper.execute(runnables);
runnables.clear();
Set<AarBundle> aarBundles = androidDependencyTree.getALLAarDependencies();
for (final AarBundle aarBundle : aarBundles) {
runnables.add(new Runnable() {
@Override
public void run() {
prepare(aarBundle.getBundle(), aarBundle.getFolder(), true);
}
});
}
executorServicesHelper.execute(runnables);
runnables.clear();
}
use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class PreparePackageIdsTask method generate.
/**
* packageid 范围是 30 - 127
*/
@TaskAction
void generate() throws IOException {
File packageIdFile = appVariantContext.getAtlasExtension().getTBuildConfig().getPackageIdFile();
File apPackageIdFile = appVariantContext.apContext.getPackageIdFile();
boolean isAutoPackageId = appVariantContext.getAtlasExtension().getTBuildConfig().isAutoPackageId();
Map<String, String> autoConfigMap = new HashMap<String, String>();
if (null != apPackageIdFile && apPackageIdFile.exists()) {
autoConfigMap.putAll(loadPackageIdProperties(apPackageIdFile));
} else if (null != packageIdFile && packageIdFile.exists()) {
autoConfigMap.putAll(loadPackageIdProperties(packageIdFile));
}
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
String key = awbBundle.getResolvedCoordinates().getGroupId() + ":" + awbBundle.getResolvedCoordinates().getArtifactId();
if (autoConfigMap.containsKey(key)) {
continue;
}
File customPackageIDFile = new File(awbBundle.getFolder(), "customPackageID.txt");
String packageId = getCustomPackageId(customPackageIDFile);
if (StringUtils.isNotEmpty(packageId) && StringUtils.isNumeric(packageId)) {
autoConfigMap.put(key, packageId);
} else {
autoConfigMap.put(key, "");
}
}
if (isAutoPackageId && autoConfigMap.containsValue("")) {
//自动分配autoConfig
List<String> keys = new ArrayList<String>(autoConfigMap.keySet());
Collections.sort(keys);
for (String key : keys) {
if ("".equals(autoConfigMap.get(key))) {
for (int i = 30; i <= 127; i++) {
if (!autoConfigMap.values().contains(String.valueOf(i))) {
autoConfigMap.put(key, String.valueOf(i));
break;
}
}
}
}
}
AtlasBuildContext.customPackageIdMaps = autoConfigMap;
//wite package Id file
File outPkgFile = new File(getProject().getBuildDir(), "outputs/packageIdFile.properties");
writeProperties(autoConfigMap, outPkgFile);
appBuildInfo.setPackageIdFile(outPkgFile);
//check value
if (autoConfigMap.containsValue("")) {
getLogger().error(JSON.toJSONString(autoConfigMap, true));
throw new GradleException("packageId 配置错误,请检查");
}
if (autoConfigMap.size() != new HashSet(autoConfigMap.values()).size()) {
// getLogger().error(JSON.toJSONString(autoConfigMap, true));
Map<String, PackageIdItem> idItemMap = new HashMap<String, PackageIdItem>();
for (String key : autoConfigMap.keySet()) {
String customPackageId = autoConfigMap.get(key);
PackageIdItem packageIdItem = idItemMap.get(customPackageId);
if (null == packageIdItem) {
String[] split = customPackageId.split("\\.");
packageIdItem = new PackageIdItem();
packageIdItem.packageId = Integer.valueOf(split[0]);
if (split.length > 1) {
packageIdItem.typeIdOffset = Integer.valueOf(split[1]);
}
idItemMap.put(customPackageId, packageIdItem);
}
packageIdItem.bundles.add(key);
}
Collection<PackageIdItem> collection = idItemMap.values();
List<PackageIdItem> packageList = new ArrayList<PackageIdItem>(collection);
Collections.sort(packageList, new Comparator<PackageIdItem>() {
@Override
public int compare(PackageIdItem o1, PackageIdItem o2) {
return o1.packageId - o2.packageId;
}
});
getLogger().error(JSON.toJSONString(packageList, true));
throw new GradleException("packageId 配置错误,有重复,请检查");
}
// check if packageID is not used
Map<String, String> autoConfigMap2 = new HashMap<>(autoConfigMap);
for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
String key = awbBundle.getResolvedCoordinates().getGroupId() + ":" + awbBundle.getResolvedCoordinates().getArtifactId();
autoConfigMap2.remove(key);
}
if (autoConfigMap2.size() > 0) {
File outPkgFile2 = new File(getProject().getBuildDir(), "outputs/warning-unusedPackageIdFile.properties");
writeProperties(autoConfigMap2, outPkgFile2);
}
}
Aggregations