Search in sources :

Example 31 with FileCollection

use of org.gradle.api.file.FileCollection in project atlas by alibaba.

the class AwoJavaCompileConfigAction method execute.

/**
     * Awb的编译,暂不支持instantRun
     *
     * @param javacTask
     */
@Override
public void execute(JavaCompile javacTask) {
    //        libVariantContext.setJavacTask(javacTask);
    javacTask.setSource(libVariantContext.getSourceOutputDir());
    ConventionMappingHelper.map(javacTask, "classpath", new Callable<FileCollection>() {

        @Override
        public FileCollection call() {
            FileCollection classpath = scope.getJavaClasspath();
            return classpath;
        }
    });
    javacTask.setDestinationDir(libVariantContext.getJavaCDir());
    javacTask.setDependencyCacheDir(new File(scope.getGlobalScope().getIntermediatesDir(), "/awb-dependency-cache/" + scope.getVariantConfiguration().getFullName() + "/" + awbBundle.getName()));
    CompileOptions compileOptions = scope.getGlobalScope().getExtension().getCompileOptions();
    AbstractCompilesUtil.configureLanguageLevel(javacTask, compileOptions, scope.getGlobalScope().getExtension().getCompileSdkVersion(), false);
    javacTask.getOptions().setEncoding(compileOptions.getEncoding());
    javacTask.getOptions().setBootClasspath(Joiner.on(File.pathSeparator).join(scope.getGlobalScope().getAndroidBuilder().getBootClasspathAsStrings(false)));
    GlobalScope globalScope = scope.getGlobalScope();
    Project project = globalScope.getProject();
    boolean incremental;
    if (compileOptions.getIncremental() != null) {
        incremental = compileOptions.getIncremental();
    } else {
        // if (globalScope.getExtension().getDataBinding().isEnabled()
        // || project.getPlugins().hasPlugin("com.neenbedankt.android-apt")
        // || project.getPlugins().hasPlugin("me.tatarka.retrolambda")) {
        // incremental = false;
        // } else {
        // For now, default to false, irrespective of Instant Run.
        incremental = false;
    // }
    }
    if (AndroidGradleOptions.isJavaCompileIncrementalPropertySet(project)) {
        scope.getGlobalScope().getAndroidBuilder().getErrorReporter().handleSyncError(null, SyncIssue.TYPE_GENERIC, String.format("The %s property has been replaced by a DSL property. Please add the " + "following to your build.gradle instead:\n" + "android {\n" + "  compileOptions.incremental = false\n" + "}", AndroidGradleOptions.PROPERTY_INCREMENTAL_JAVA_COMPILE));
    }
    if (incremental) {
        LOG.info("Using incremental javac compilation.");
    } else {
        LOG.info("Not using incremental javac compilation.");
    }
    javacTask.getOptions().setIncremental(incremental);
}
Also used : GlobalScope(com.android.build.gradle.internal.scope.GlobalScope) Project(org.gradle.api.Project) CompileOptions(com.android.build.gradle.internal.CompileOptions) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File)

Example 32 with FileCollection

use of org.gradle.api.file.FileCollection in project atlas by alibaba.

the class AwbJavaCompileConfigAction method execute.

/**
     * Awb的编译,暂不支持instantRun
     *
     * @param javacTask
     */
@Override
public void execute(JavaCompile javacTask) {
    appVariantOutputContext.getAwbJavacTasks().put(awbBundle.getName(), javacTask);
    ProcessAwbAndroidResources processAwbAndroidResources = appVariantOutputContext.getAwbAndroidResourcesMap().get(awbBundle.getName());
    assert null != processAwbAndroidResources;
    javacTask.source(processAwbAndroidResources.getSourceOutputDir());
    if (scope.getGlobalScope().getExtension().getDataBinding().isEnabled()) {
        javacTask.source(appVariantOutputContext.getVariantContext().getAwbClassOutputForDataBinding(awbBundle));
    }
    ConventionMappingHelper.map(javacTask, "classpath", new Callable<FileCollection>() {

        @Override
        public FileCollection call() {
            FileCollection classpath = scope.getVariantScope().getJavaClasspath();
            Set<File> dependencies = new HashSet<File>();
            dependencies.addAll(classpath.getFiles());
            //增加awb的依赖
            dependencies.addAll(awbBundle.getLibraryJars());
            FileCollection allClassPatch = appVariantOutputContext.getVariantContext().getProject().files(dependencies);
            return allClassPatch;
        }
    });
    javacTask.setDestinationDir(appVariantOutputContext.getJAwbavaOutputDir(awbBundle));
    javacTask.setDependencyCacheDir(appVariantOutputContext.getAwbJavaDependencyCache(awbBundle));
    CompileOptions compileOptions = scope.getGlobalScope().getExtension().getCompileOptions();
    AbstractCompilesUtil.configureLanguageLevel(javacTask, compileOptions, scope.getGlobalScope().getExtension().getCompileSdkVersion(), false);
    javacTask.getOptions().setEncoding(compileOptions.getEncoding());
    javacTask.getOptions().setBootClasspath(Joiner.on(File.pathSeparator).join(scope.getGlobalScope().getAndroidBuilder().getBootClasspathAsStrings(false)));
    GlobalScope globalScope = scope.getGlobalScope();
    Project project = globalScope.getProject();
    boolean incremental;
    if (compileOptions.getIncremental() != null) {
        incremental = compileOptions.getIncremental();
    } else {
        // if (globalScope.getExtension().getDataBinding().isEnabled()
        // || project.getPlugins().hasPlugin("com.neenbedankt.android-apt")
        // || project.getPlugins().hasPlugin("me.tatarka.retrolambda")) {
        // incremental = false;
        // } else {
        // For now, default to false, irrespective of Instant Run.
        incremental = false;
    // }
    }
    if (AndroidGradleOptions.isJavaCompileIncrementalPropertySet(project)) {
        scope.getGlobalScope().getAndroidBuilder().getErrorReporter().handleSyncError(null, SyncIssue.TYPE_GENERIC, String.format("The %s property has been replaced by a DSL property. Please add the " + "following to your build.gradle instead:\n" + "android {\n" + "  compileOptions.incremental = false\n" + "}", AndroidGradleOptions.PROPERTY_INCREMENTAL_JAVA_COMPILE));
    }
    if (incremental) {
        LOG.info("Using incremental javac compilation.");
    } else {
        LOG.info("Not using incremental javac compilation.");
    }
    javacTask.getOptions().setIncremental(incremental);
}
Also used : GlobalScope(com.android.build.gradle.internal.scope.GlobalScope) Project(org.gradle.api.Project) Set(java.util.Set) HashSet(java.util.HashSet) CompileOptions(com.android.build.gradle.internal.CompileOptions) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File)

Aggregations

FileCollection (org.gradle.api.file.FileCollection)32 File (java.io.File)16 Callable (java.util.concurrent.Callable)6 ArrayList (java.util.ArrayList)5 ConventionMapping (org.gradle.api.internal.ConventionMapping)5 SimpleFileCollection (org.gradle.api.internal.file.collections.SimpleFileCollection)4 Set (java.util.Set)3 CompileOptions (com.android.build.gradle.internal.CompileOptions)2 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)2 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 List (java.util.List)2 Project (org.gradle.api.Project)2 Task (org.gradle.api.Task)2 Configuration (org.gradle.api.artifacts.Configuration)2 FileCollectionInternal (org.gradle.api.internal.file.FileCollectionInternal)2 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2 Predicate (com.google.common.base.Predicate)1 Injector (com.google.inject.Injector)1 Closure (groovy.lang.Closure)1