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);
}
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);
}
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;
}
}
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);
}
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);
}
}
}
Aggregations