use of org.gradle.api.tasks.compile.AbstractCompile in project gradle-eta by typelead.
the class EtaPlugin method configureSourceSet.
private void configureSourceSet(SourceSet sourceSet) {
final EtaOptions etaOptions = createEtaOptions();
final DefaultEtaSourceSet etaSourceSet = ExtensionHelper.createExtension(sourceSet, "eta", DefaultEtaSourceSet.class, sourceSet, sourceDirectorySetFactory);
final SourceDirectorySet etaSourceDirectorySet = etaSourceSet.getEta();
etaSourceDirectorySet.srcDir("src/" + sourceSet.getName() + "/eta");
/* Ensure that you exclude any Eta source files from the
resources set. */
sourceSet.getResources().getFilter().exclude(element -> etaSourceSet.getEta().contains(element.getFile()));
sourceSet.getAllSource().source(etaSourceDirectorySet);
final EtaResolveDependencies resolveDependenciesTask = (EtaResolveDependencies) project.getRootProject().getTasks().getByPath(EtaBasePlugin.ETA_RESOLVE_DEPENDENCIES_TASK_NAME);
final FileCollection freezeConfigFile = resolveDependenciesTask.getOutputs().getFiles();
final Provider<String> targetConfiguration = project.provider(() -> sourceSet.getCompileClasspathConfigurationName());
final Provider<Directory> destinationDir = project.getLayout().getBuildDirectory().dir(etaSourceSet.getRelativeOutputDir());
/* Create the install dependencies task. */
final EtaInstallDependencies installDependenciesTask = project.getTasks().create(etaSourceSet.getInstallDependenciesTaskName(), EtaInstallDependencies.class);
installDependenciesTask.setTargetConfiguration(targetConfiguration);
installDependenciesTask.setFreezeConfigFile(freezeConfigFile);
installDependenciesTask.setFreezeConfigChanged(project.provider(() -> resolveDependenciesTask.getDidWork()));
installDependenciesTask.setDestinationDir(destinationDir);
installDependenciesTask.setOptions(etaOptions);
installDependenciesTask.setSource(etaSourceDirectorySet);
installDependenciesTask.dependsOn(resolveDependenciesTask);
installDependenciesTask.setDescription("Installs dependencies for the " + sourceSet.getName() + " Eta source.");
installDependenciesTask.dependsOnOtherEtaProjects();
/* The install dependencies tasks injects into this configuration so we must
ensure that it runs before the Java compilation. */
final AbstractCompile javaCompileTask = (AbstractCompile) project.getTasks().getByName(sourceSet.getCompileJavaTaskName());
javaCompileTask.dependsOn(installDependenciesTask);
/* Create the compile task. */
EtaCompile compileTask = project.getTasks().create(etaSourceSet.getCompileTaskName(), EtaCompile.class);
Provider<Directory> classesDir = project.provider(() -> {
final DirectoryProperty buildDir = project.getLayout().getBuildDirectory();
if (sourceSet.getOutput().isLegacyLayout()) {
return buildDir.dir(buildDir.getAsFile().get().toPath().relativize(sourceSet.getOutput().getClassesDir().toPath()).toString()).get();
}
return buildDir.dir(etaSourceSet.getClassesDir()).get();
});
compileTask.setClasspath(project.provider(() -> sourceSet.getCompileClasspath()));
compileTask.setCabalProjectFile(installDependenciesTask.getCabalProjectFileProvider());
compileTask.setCabalFile(installDependenciesTask.getCabalFileProvider());
compileTask.setDestinationDir(destinationDir);
compileTask.addExtraClasspath(javaCompileTask.getDestinationDir());
compileTask.setClassesDir(classesDir);
compileTask.setOptions(etaOptions);
compileTask.setSource(etaSourceDirectorySet);
compileTask.dependsOn(javaCompileTask);
compileTask.setDescription("Compiles the " + sourceSet.getName() + " Eta source.");
/* Register the Eta classes directory as an output so that the Jar task
will pick it up nicely. */
Map<String, Object> builtByOptions = new HashMap<String, Object>();
builtByOptions.put("builtBy", compileTask);
etaSourceDirectorySet.setOutputDir(project.provider(() -> classesDir.get().getAsFile()));
/* TODO: Are both classesDir and the output registration below required? */
((DefaultSourceSetOutput) sourceSet.getOutput()).addClassesDir(() -> etaSourceDirectorySet.getOutputDir());
sourceSet.getOutput().dir(builtByOptions, classesDir);
/* Register the package databases as artifacts that will be collected
upon dependency resolution of project dependencies. */
addArtifacts(compileTask.getPackageDBProvider(), sourceSet.getApiElementsConfigurationName(), sourceSet.getRuntimeConfigurationName(), sourceSet.getRuntimeElementsConfigurationName());
}
Aggregations