Search in sources :

Example 1 with EtaOptions

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

the class EtaAndroidPlugin method addEtaOptionsToDefaultConfig.

private void addEtaOptionsToDefaultConfig() {
    EtaOptions options = ExtensionHelper.createExtension(androidExtension, ETA_OPTIONS_DSL_NAME, EtaOptions.class).setExtensions(project.container(LanguageExtension.class));
    options.setProjectPath(project.getProjectDir().toPath());
}
Also used : EtaOptions(com.typelead.gradle.eta.api.EtaOptions) LanguageExtension(com.typelead.gradle.eta.api.LanguageExtension)

Example 2 with EtaOptions

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

the class EtaInstallDependencies method installDependencies.

@TaskAction
public void installDependencies() {
    final EtaOptions etaOptions = getOptions();
    etaOptions.validate(etaInfo.get());
    final File workingDir = getDestinationDir();
    copyFreezeConfigIfChanged(workingDir);
    /* Calculate all the modules */
    final List<String> modules = getModules();
    /* Determine if it's an executable */
    String exec = executable.getOrNull();
    if (exec != null && exec.length() <= 0) {
        exec = null;
    }
    final String executableSpec = exec;
    /* Generate the .cabal & cabal.project files. */
    final WriteResult[] writeResults = new WriteResult[2];
    final String targetConfigurationName = getTargetConfiguration();
    Set<File> packageDBs = ConfigurationUtils.getEtaConfiguration(ConfigurationUtils.getConfiguration(project, targetConfigurationName)).getAllArtifacts(project).stream().map(Provider::get).collect(Collectors.toSet());
    packageDBs.addAll(project.files(extraPackageDBs.values()).getFiles());
    DependencyUtils.foldEtaDependencies(project, dependencies.get(), (directDeps, projectDeps, gitStringDeps, gitDeps) -> {
        /* Include the project dependencies and git dependencies in the Etlas
                   dependency list. */
        directDeps.addAll(projectDeps);
        directDeps.addAll(gitStringDeps);
        directDeps.addAll(extraPackageDBs.keySet());
        writeResults[0] = CabalHelper.generateCabalFile(getPackageName(), getPackageVersion(), executableSpec, getSourceDirs().getFiles().stream().map(File::getAbsolutePath).collect(Collectors.toList()), modules, etaOptions, directDeps, workingDir);
        writeResults[1] = CabalHelper.generateCabalProjectFile(gitDeps, packageDBs, workingDir);
    });
    /* Delete existing *.cabal files to avoid errors when changing the project
           name. */
    final File oldCabalFile = writeResults[0].getFile();
    project.delete(project.fileTree(workingDir, fileTree -> {
        fileTree.include("*.cabal");
        fileTree.exclude(fileTreeElement -> {
            try {
                return fileTreeElement.getFile().getCanonicalPath().equals(oldCabalFile.getCanonicalPath());
            } catch (IOException e) {
                return true;
            }
        });
    }));
    /* Fork an etlas process to install the dependencies.  */
    final EtlasCommand etlas = new EtlasCommand(project);
    etlas.getWorkingDirectory().set(workingDir);
    boolean isUpToDate = etlas.deps(EtlasCommand.libTarget(getPackageName()), dependencyGraph -> {
        /* Inject the dependencies into the respective configurations. */
        DependencyHandler dependencies = project.getDependencies();
        final EtaConfiguration targetEtaConfiguration = ConfigurationUtils.getEtaConfiguration(project, getTargetConfiguration());
        targetEtaConfiguration.resolve(project, dependencies, dependencyGraph);
    });
    setDidWork(!isUpToDate);
}
Also used : Buildable(org.gradle.api.Buildable) SourceTask(org.gradle.api.tasks.SourceTask) EtaOptions(com.typelead.gradle.eta.api.EtaOptions) EtlasCommand(com.typelead.gradle.utils.EtlasCommand) Callable(java.util.concurrent.Callable) FileCollection(org.gradle.api.file.FileCollection) InputFiles(org.gradle.api.tasks.InputFiles) CabalHelper(com.typelead.gradle.utils.CabalHelper) OutputDirectory(org.gradle.api.tasks.OutputDirectory) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) TaskAction(org.gradle.api.tasks.TaskAction) Configuration(org.gradle.api.artifacts.Configuration) Provider(org.gradle.api.provider.Provider) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) ConfigurationUtils(com.typelead.gradle.eta.internal.ConfigurationUtils) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) DirectoryProperty(org.gradle.api.file.DirectoryProperty) Map(java.util.Map) EtaInfo(com.typelead.gradle.utils.EtaInfo) DefaultTask(org.gradle.api.DefaultTask) Directory(org.gradle.api.file.Directory) Internal(org.gradle.api.tasks.Internal) WriteResult(com.typelead.gradle.utils.CabalHelper.WriteResult) Project(org.gradle.api.Project) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) Set(java.util.Set) IOException(java.io.IOException) EtaExtension(com.typelead.gradle.eta.api.EtaExtension) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) OutputFile(org.gradle.api.tasks.OutputFile) PackageInfo(com.typelead.gradle.utils.PackageInfo) GradleException(org.gradle.api.GradleException) RegularFile(org.gradle.api.file.RegularFile) DependencyUtils(com.typelead.gradle.eta.internal.DependencyUtils) Property(org.gradle.api.provider.Property) Nested(org.gradle.api.tasks.Nested) Input(org.gradle.api.tasks.Input) IOException(java.io.IOException) EtlasCommand(com.typelead.gradle.utils.EtlasCommand) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) EtaOptions(com.typelead.gradle.eta.api.EtaOptions) WriteResult(com.typelead.gradle.utils.CabalHelper.WriteResult) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) RegularFile(org.gradle.api.file.RegularFile) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with EtaOptions

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

the class EtaAndroidPlugin method createEtaOptions.

private EtaOptions createEtaOptions() {
    EtaOptions options = project.getObjects().newInstance(EtaOptions.class).setExtensions(project.container(LanguageExtension.class));
    options.setProjectPath(project.getProjectDir().toPath());
    return options;
}
Also used : EtaOptions(com.typelead.gradle.eta.api.EtaOptions) LanguageExtension(com.typelead.gradle.eta.api.LanguageExtension)

Example 4 with EtaOptions

use of com.typelead.gradle.eta.api.EtaOptions 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)

Example 5 with EtaOptions

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

the class EtaPlugin method createEtaOptions.

private EtaOptions createEtaOptions() {
    EtaOptions options = project.getObjects().newInstance(EtaOptions.class).setExtensions(project.container(LanguageExtension.class));
    options.setProjectPath(project.getProjectDir().toPath());
    return options;
}
Also used : EtaOptions(com.typelead.gradle.eta.api.EtaOptions) LanguageExtension(com.typelead.gradle.eta.api.LanguageExtension)

Aggregations

EtaOptions (com.typelead.gradle.eta.api.EtaOptions)6 LanguageExtension (com.typelead.gradle.eta.api.LanguageExtension)3 Directory (org.gradle.api.file.Directory)3 FileCollection (org.gradle.api.file.FileCollection)3 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)3 DefaultEtaSourceSet (com.typelead.gradle.eta.internal.DefaultEtaSourceSet)2 EtaCompile (com.typelead.gradle.eta.tasks.EtaCompile)2 EtaInstallDependencies (com.typelead.gradle.eta.tasks.EtaInstallDependencies)2 EtaResolveDependencies (com.typelead.gradle.eta.tasks.EtaResolveDependencies)2 DirectoryProperty (org.gradle.api.file.DirectoryProperty)2 SourceProvider (com.android.builder.model.SourceProvider)1 EtaConfiguration (com.typelead.gradle.eta.api.EtaConfiguration)1 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)1 EtaExtension (com.typelead.gradle.eta.api.EtaExtension)1 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)1 EtaSourceSet (com.typelead.gradle.eta.api.EtaSourceSet)1 ConfigurationUtils (com.typelead.gradle.eta.internal.ConfigurationUtils)1 DependencyUtils (com.typelead.gradle.eta.internal.DependencyUtils)1 EtaRepl (com.typelead.gradle.eta.tasks.EtaRepl)1 CabalHelper (com.typelead.gradle.utils.CabalHelper)1