Search in sources :

Example 1 with EtaSourceSet

use of com.typelead.gradle.eta.api.EtaSourceSet in project gradle-eta by typelead.

the class EtaAndroidPlugin method configureBaseVariant.

private void configureBaseVariant(BaseVariant variant) {
    final EtaOptions etaOptions = createEtaOptions();
    final String variantName = variant.getName();
    final Provider<String> packageName = project.provider(() -> NamingScheme.getPackageName(project, variantName));
    final Provider<String> packageVersion = project.provider(() -> NamingScheme.fixVersion(project.getVersion().toString()));
    project.getLogger().debug("Processing variant " + variantName + " for Eta compilation.");
    final JavaCompile javaCompileTask = variant.getJavaCompile();
    if (javaCompileTask == null) {
        project.getLogger().info("EtaAndroidPlugin: javaCompileTask is missing for " + variantName + " so the Eta compilation tasks will be skipped.");
        return;
    }
    final SourceDirectorySet etaSourceDirectorySet = sourceDirectorySetFactory.create("eta", variantName + " Eta source");
    for (SourceProvider sourceProvider : variant.getSourceSets()) {
        final EtaSourceSet etaSourceSet = ExtensionHelper.getConvention(sourceProvider, EtaSourceSet.class);
        if (etaSourceSet != null) {
            etaSourceDirectorySet.source(etaSourceSet.getEta());
        }
    }
    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(() -> variant.getCompileConfiguration().getName());
    final Provider<Directory> destinationDir = project.getLayout().getBuildDirectory().dir(NamingScheme.getRelativeOutputDir(variant.getDirName()));
    /* Create the install dependencies task. */
    final EtaInstallDependencies installDependenciesTask = project.getTasks().create(NamingScheme.getInstallDependenciesTaskName(variantName), EtaInstallDependencies.class);
    installDependenciesTask.setPackageName(packageName);
    installDependenciesTask.setPackageVersion(packageVersion);
    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 " + variantName + " Eta source.");
    installDependenciesTask.dependsOnOtherEtaProjects();
    /* Because the installDependenciesTask injects dependencies into the
           configuration, it must run *before* the preBuild phase since every task
           after that will resolve configurations. */
    variant.getPreBuild().dependsOn(installDependenciesTask);
    /* Create the compile task. */
    EtaCompile compileTask = project.getTasks().create(NamingScheme.getCompileTaskName(variantName), EtaCompile.class);
    compileTask.setPackageName(packageName);
    compileTask.setPackageVersion(packageVersion);
    compileTask.setCabalProjectFile(installDependenciesTask.getCabalProjectFileProvider());
    compileTask.setCabalFile(installDependenciesTask.getCabalFileProvider());
    compileTask.setDestinationDir(destinationDir);
    compileTask.setOptions(etaOptions);
    compileTask.setSource(etaSourceDirectorySet);
    compileTask.dependsOn(installDependenciesTask);
    compileTask.setDescription("Compiles the " + variantName + " Eta source.");
    /* Register the Eta output jar file with the Android build system. */
    Object etaClasspathKey = variant.registerPreJavacGeneratedBytecode(project.files(compileTask.getOutputJarFileProvider()).builtBy(compileTask));
    /* Setup the classpath for Eta */
    compileTask.setClasspath(project.provider(() -> variant.getCompileClasspath(etaClasspathKey).plus(project.files(AndroidHelper.getAndroidSDKClasspath(androidExtension)))));
    /* Register the package databases as artifacts that will be collected
           upon dependency resolution of project dependencies. */
    addArtifacts(compileTask.getPackageDBProvider(), variant.getRuntimeConfiguration());
}
Also used : EtaResolveDependencies(com.typelead.gradle.eta.tasks.EtaResolveDependencies) SourceProvider(com.android.builder.model.SourceProvider) FileCollection(org.gradle.api.file.FileCollection) EtaOptions(com.typelead.gradle.eta.api.EtaOptions) EtaInstallDependencies(com.typelead.gradle.eta.tasks.EtaInstallDependencies) EtaSourceSet(com.typelead.gradle.eta.api.EtaSourceSet) DefaultEtaSourceSet(com.typelead.gradle.eta.internal.DefaultEtaSourceSet) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) EtaCompile(com.typelead.gradle.eta.tasks.EtaCompile) Directory(org.gradle.api.file.Directory)

Aggregations

SourceProvider (com.android.builder.model.SourceProvider)1 EtaOptions (com.typelead.gradle.eta.api.EtaOptions)1 EtaSourceSet (com.typelead.gradle.eta.api.EtaSourceSet)1 DefaultEtaSourceSet (com.typelead.gradle.eta.internal.DefaultEtaSourceSet)1 EtaCompile (com.typelead.gradle.eta.tasks.EtaCompile)1 EtaInstallDependencies (com.typelead.gradle.eta.tasks.EtaInstallDependencies)1 EtaResolveDependencies (com.typelead.gradle.eta.tasks.EtaResolveDependencies)1 Directory (org.gradle.api.file.Directory)1 FileCollection (org.gradle.api.file.FileCollection)1 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)1 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)1