Search in sources :

Example 6 with AndroidDependencyTree

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");
        }
    }
}
Also used : AtlasExtensionOutput(com.taobao.android.builder.tools.guide.AtlasExtensionOutput) GradleException(org.gradle.api.GradleException) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) DependencyJson(com.taobao.android.builder.dependency.output.DependencyJson) IOException(java.io.IOException) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 7 with AndroidDependencyTree

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);
}
Also used : ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) AwbTransform(com.android.build.gradle.internal.api.AwbTransform) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 8 with AndroidDependencyTree

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);
        }
    }
}
Also used : AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 9 with AndroidDependencyTree

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();
}
Also used : ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) ArrayList(java.util.ArrayList) AarBundle(com.taobao.android.builder.dependency.model.AarBundle) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 10 with AndroidDependencyTree

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);
    }
}
Also used : AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) GradleException(org.gradle.api.GradleException) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)24 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)19 ArrayList (java.util.ArrayList)14 File (java.io.File)12 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)9 TaskAction (org.gradle.api.tasks.TaskAction)9 GradleException (org.gradle.api.GradleException)8 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)5 DefaultTask (org.gradle.api.DefaultTask)5 BundleInfo (com.taobao.android.builder.tools.bundleinfo.model.BundleInfo)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 StopExecutionException (org.gradle.api.tasks.StopExecutionException)3 DataBindingBuilder (android.databinding.tool.DataBindingBuilder)2 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)2 AwbTransform (com.android.build.gradle.internal.api.AwbTransform)2 VariantScope (com.android.build.gradle.internal.scope.VariantScope)2 BaseVariantOutputData (com.android.build.gradle.internal.variant.BaseVariantOutputData)2 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 AwoDependency (com.taobao.android.builder.tasks.awo.utils.AwoDependency)2