Search in sources :

Example 26 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 27 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)

Example 28 with FileCollection

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

the class DefaultBuildOutputCleanupRegistry method doResolvePaths.

private synchronized void doResolvePaths() {
    if (resolvedPaths == null) {
        Set<String> result = new LinkedHashSet<String>();
        for (FileCollection output : outputs) {
            for (File file : output.getFiles()) {
                result.add(file.getAbsolutePath());
            }
        }
        resolvedPaths = result;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File)

Example 29 with FileCollection

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

the class SkipEmptySourceFilesTaskExecuter method execute.

public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    TaskProperties taskProperties = context.getTaskProperties();
    FileCollection sourceFiles = taskProperties.getSourceFiles();
    if (taskProperties.hasSourceFiles() && sourceFiles.isEmpty()) {
        TaskArtifactState taskArtifactState = context.getTaskArtifactState();
        TaskExecutionHistory executionHistory = taskArtifactState.getExecutionHistory();
        Set<File> outputFiles = executionHistory.getOutputFiles();
        if (outputFiles.isEmpty()) {
            state.setOutcome(TaskExecutionOutcome.NO_SOURCE);
            LOGGER.info("Skipping {} as it has no source files and no previous output files.", task);
        } else {
            boolean cleanupDirectories = executionHistory.getOverlappingOutputs() == null;
            if (!cleanupDirectories) {
                LOGGER.info("No leftover directories for {} will be deleted since overlapping outputs were detected.", task);
            }
            taskOutputChangesListener.beforeTaskOutputChanged();
            boolean deletedFiles = false;
            boolean debugEnabled = LOGGER.isDebugEnabled();
            for (File file : outputFiles) {
                if (file.exists() && buildOutputCleanupRegistry.isOutputOwnedByBuild(file)) {
                    if (!cleanupDirectories && file.isDirectory()) {
                        continue;
                    }
                    if (debugEnabled) {
                        LOGGER.debug("Deleting stale output file '{}'.", file.getAbsolutePath());
                    }
                    GFileUtils.forceDelete(file);
                    deletedFiles = true;
                }
            }
            if (deletedFiles) {
                LOGGER.info("Cleaned previous output of {} as it has no source files.", task);
                state.setOutcome(TaskExecutionOutcome.EXECUTED);
            } else {
                state.setOutcome(TaskExecutionOutcome.NO_SOURCE);
            }
            taskArtifactState.snapshotAfterTaskExecution(null, buildInvocationScopeId.getId(), context);
        }
        taskInputsListener.onExecute(task, Cast.cast(FileCollectionInternal.class, sourceFiles));
        return;
    } else {
        taskInputsListener.onExecute(task, Cast.cast(FileCollectionInternal.class, taskProperties.getInputFiles()));
    }
    executer.execute(task, state, context);
}
Also used : TaskArtifactState(org.gradle.api.internal.changedetection.TaskArtifactState) FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) TaskExecutionHistory(org.gradle.api.internal.TaskExecutionHistory)

Example 30 with FileCollection

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

the class GetInputPropertiesVisitor method prepareValue.

@Nullable
private static Object prepareValue(@Nullable Object value) {
    while (true) {
        if (value instanceof Callable) {
            Callable callable = (Callable) value;
            value = uncheckedCall(callable);
        } else if (value instanceof FileCollection) {
            FileCollection fileCollection = (FileCollection) value;
            return fileCollection.getFiles();
        } else {
            return avoidGString(value);
        }
    }
}
Also used : FileCollection(org.gradle.api.file.FileCollection) Callable(java.util.concurrent.Callable) Nullable(javax.annotation.Nullable)

Aggregations

FileCollection (org.gradle.api.file.FileCollection)39 File (java.io.File)20 Callable (java.util.concurrent.Callable)6 ArrayList (java.util.ArrayList)5 ConventionMapping (org.gradle.api.internal.ConventionMapping)5 LinkedHashSet (java.util.LinkedHashSet)4 Set (java.util.Set)3 FileCollectionInternal (org.gradle.api.internal.file.FileCollectionInternal)3 SimpleFileCollection (org.gradle.api.internal.file.collections.SimpleFileCollection)3 CompileOptions (com.android.build.gradle.internal.CompileOptions)2 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Project (org.gradle.api.Project)2 Task (org.gradle.api.Task)2 Transformer (org.gradle.api.Transformer)2 Configuration (org.gradle.api.artifacts.Configuration)2 CompositeFileCollection (org.gradle.api.internal.file.CompositeFileCollection)2 MinimalFileSet (org.gradle.api.internal.file.collections.MinimalFileSet)2 Expectations (org.jmock.Expectations)2