Search in sources :

Example 1 with TaskAction

use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.

the class CopyAwoSolibTask method doFullTaskAction.

@TaskAction
public void doFullTaskAction() {
    if (!outputDir.exists()) {
        outputDir.mkdirs();
    }
    Set<String> removeSoFiles = new HashSet<String>();
    Set<String> supportAbis = new HashSet<String>();
    //为了兼容之前老的aar,awb格式
    File libJniFolder = new File(awbBundle.getFolder(), "libs");
    if (libJniFolder.exists() && libJniFolder.isDirectory()) {
        NativeSoUtils.copyLocalNativeLibraries(libJniFolder, outputDir, supportAbis, removeSoFiles, getILogger());
    }
    File libJniFolder2 = new File(awbBundle.getFolder(), "jni");
    if (libJniFolder2.exists() && libJniFolder2.isDirectory()) {
        NativeSoUtils.copyLocalNativeLibraries(libJniFolder2, outputDir, supportAbis, removeSoFiles, getILogger());
    }
    File libJniFolder3 = new File(awbBundle.getFolder(), "jniLibs");
    if (libJniFolder3.exists() && libJniFolder3.isDirectory()) {
        NativeSoUtils.copyLocalNativeLibraries(libJniFolder3, outputDir, supportAbis, removeSoFiles, getILogger());
    }
    List<? extends AndroidLibrary> deps = awbBundle.getLibraryDependencies();
    for (AndroidLibrary dep : deps) {
        File depJniFolder = dep.getJniFolder();
        if (depJniFolder.exists() && depJniFolder.isDirectory()) {
            NativeSoUtils.copyLocalNativeLibraries(depJniFolder, outputDir, supportAbis, removeSoFiles, getILogger());
        }
        //为了兼容之前老的aar,awb格式
        File depLibsFolder = new File(dep.getFolder(), "libs");
        if (depLibsFolder.exists() && depLibsFolder.isDirectory()) {
            NativeSoUtils.copyLocalNativeLibraries(depLibsFolder, outputDir, supportAbis, removeSoFiles, getILogger());
        }
    }
    List<SoLibrary> solibs = awbBundle.getSoLibraries();
    if (null != solibs) {
        for (SoLibrary solib : solibs) {
            File explodeFolder = solib.getFolder();
            if (!explodeFolder.exists()) {
                LibraryCache.unzipAar(solib.getSoLibFile(), explodeFolder, getProject());
            }
            if (explodeFolder.exists() && explodeFolder.isDirectory()) {
                NativeSoUtils.copyLocalNativeLibraries(explodeFolder, outputDir, supportAbis, removeSoFiles, getILogger());
            }
        }
    }
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary) File(java.io.File) HashSet(java.util.HashSet) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with TaskAction

use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.

the class DiffDependencyTask method doTask.

@TaskAction
public void doTask() throws IOException {
    apDependenciesFile = getApDependenciesFile();
    diffOutFile = getDiffOutFile();
    DependencyJson apDependencyJson = JSON.parseObject(FileUtils.readFileToString(apDependenciesFile), DependencyJson.class);
    Set<String> apMainDependencies = Sets.newHashSet();
    for (String mainDep : apDependencyJson.getMainDex()) {
        String name = mainDep.substring(0, mainDep.lastIndexOf(":"));
        apMainDependencies.add(name);
    }
    AwbBundle awbBundle = libVariantContext.getAwbBundle();
    //aars
    if (null != awbBundle.getLibraryDependencies()) {
        for (int index = 0; index < awbBundle.getLibraryDependencies().size(); index++) {
            AndroidLibrary libraryDependency = awbBundle.getLibraryDependencies().get(index);
            MavenCoordinates mavenCoordinates = libraryDependency.getResolvedCoordinates();
            String name = getMavenName(mavenCoordinates);
            if (apMainDependencies.contains(name)) {
                getLogger().info("[Remove]" + name);
                awbBundle.getLibraryDependencies().remove(index);
            } else {
                inAwbDependencies.add(name);
            }
        }
    }
    //solibs
    if (null != awbBundle.getSoLibraries()) {
        for (int index = 0; index < awbBundle.getSoLibraries().size(); index++) {
            SoLibrary soLibrary = awbBundle.getSoLibraries().get(index);
            MavenCoordinates mavenCoordinates = soLibrary.getResolvedCoordinates();
            String name = getMavenName(mavenCoordinates);
            if (apMainDependencies.contains(name)) {
                getLogger().info("[Remove]" + name);
                awbBundle.getSoLibraries().remove(index);
            } else {
                inAwbDependencies.add(name);
            }
        }
    }
    // jars
    if (null != awbBundle.getJavaDependencies()) {
        Iterator<? extends JavaLibrary> iterator = awbBundle.getJavaDependencies().iterator();
        while (iterator.hasNext()) {
            JavaLibrary jarInfo = iterator.next();
            MavenCoordinates mavenCoordinates = jarInfo.getResolvedCoordinates();
            String name = getMavenName(mavenCoordinates);
            if (apMainDependencies.contains(name)) {
                getLogger().info("[Remove]" + name);
                iterator.remove();
            } else {
                inAwbDependencies.add(name);
            }
        }
    }
    FileUtils.writeStringToFile(diffOutFile, StringUtils.join(inAwbDependencies, "\n"));
}
Also used : MavenCoordinates(com.android.builder.model.MavenCoordinates) JavaLibrary(com.android.builder.model.JavaLibrary) AndroidLibrary(com.android.builder.model.AndroidLibrary) DependencyJson(com.taobao.android.builder.dependency.output.DependencyJson) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with TaskAction

use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.

the class MtlParallelTask method run.

@TaskAction
void run() throws ExecutionException, InterruptedException {
    if (null == parallelTask || parallelTask.isEmpty()) {
        return;
    }
    if (concurrent) {
        String taskName = uniqueTaskName;
        if (StringUtils.isEmpty(taskName)) {
            taskName = parallelTask.get(0).getClass().getSimpleName();
        }
        ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
        List<Runnable> runnables = new ArrayList<>();
        for (final DefaultTask task : parallelTask) {
            runnables.add(new Runnable() {

                @Override
                public void run() {
                    task.execute();
                }
            });
        }
        executorServicesHelper.execute(runnables);
    } else {
        for (final DefaultTask task : parallelTask) {
            task.execute();
        }
    }
}
Also used : ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) ArrayList(java.util.ArrayList) DefaultTask(org.gradle.api.DefaultTask) TaskAction(org.gradle.api.tasks.TaskAction)

Example 4 with TaskAction

use of org.gradle.api.tasks.TaskAction 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 5 with TaskAction

use of org.gradle.api.tasks.TaskAction in project atlas by alibaba.

the class AwbDexTask method taskAction.

/**
     * Actual entry point for the action.
     * Calls out to the doTaskAction as needed.
     */
@TaskAction
public void taskAction() throws InterruptedException, ProcessException, IOException {
    Collection<File> _inputFiles = getInputFiles();
    File _inputDir = getInputDir();
    if (_inputFiles == null && _inputDir == null) {
        throw new StopExecutionException("Dex task " + getName() + ": inputDir and inputFiles cannot both be null");
    }
    doTaskAction(_inputFiles, _inputDir, false);
}
Also used : StopExecutionException(org.gradle.api.tasks.StopExecutionException) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

TaskAction (org.gradle.api.tasks.TaskAction)229 File (java.io.File)92 IOException (java.io.IOException)53 GradleException (org.gradle.api.GradleException)48 ArrayList (java.util.ArrayList)34 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)32 Path (java.nio.file.Path)25 OutputFile (org.gradle.api.tasks.OutputFile)25 DefaultTask (org.gradle.api.DefaultTask)22 InputFile (org.gradle.api.tasks.InputFile)20 Map (java.util.Map)19 Project (org.gradle.api.Project)17 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)16 List (java.util.List)15 FileCollection (org.gradle.api.file.FileCollection)15 HashMap (java.util.HashMap)14 FileWriter (java.io.FileWriter)13 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)12 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)12 WorkResult (org.gradle.api.tasks.WorkResult)11