Search in sources :

Example 1 with WriteResult

use of com.typelead.gradle.utils.CabalHelper.WriteResult in project gradle-eta by typelead.

the class EtaResolveDependencies method resolveDependencies.

@TaskAction
public void resolveDependencies() {
    /* Create the destination directory if it doesn't exist. */
    File workingDir = getDestinationDirectory();
    if (!workingDir.exists() && !workingDir.mkdirs()) {
        throw new GradleException("Unable to create destination directory: " + workingDir.getAbsolutePath());
    }
    /* Remove the cabal.project.freeze file from a previous run, if it exists. */
    File existingFreezeFile = getFreezeConfigFile();
    if (existingFreezeFile.exists() && !existingFreezeFile.delete()) {
        throw new GradleException("Unable to delete existing freeze file: " + existingFreezeFile.getAbsolutePath());
    }
    /* Generate the .cabal & cabal.project files. */
    final WriteResult[] writeResults = new WriteResult[2];
    DependencyUtils.foldEtaDependencies(project, dependencies.get(), (directDeps, projectDeps, gitStringDeps, gitDeps) -> {
        /* Include the git dependencies in the Etlas
                   dependency list, but avoid project dependencies because they will be
                   built separately and will not be found. */
        directDeps.addAll(gitStringDeps);
        writeResults[0] = CabalHelper.generateCabalFile(getProject().getName(), NamingScheme.fixVersion(getProject().getVersion().toString()), directDeps, workingDir);
        writeResults[1] = CabalHelper.generateCabalProjectFile(gitDeps, 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;
            }
        });
    }));
    /* Only run the freeze command if the cabal files have changed or the
           Eta version state has changed. */
    boolean changed = writeResults[0].isChanged() || writeResults[0].isChanged() || getVersionsChanged();
    if (changed) {
        /* Fork an etlas process to freeze the dependencies.  */
        EtlasCommand etlas = new EtlasCommand(getProject());
        etlas.getWorkingDirectory().set(workingDir);
        etlas.freeze();
    }
    setDidWork(changed);
}
Also used : ExtensionHelper(com.typelead.gradle.utils.ExtensionHelper) EtlasCommand(com.typelead.gradle.utils.EtlasCommand) CabalHelper(com.typelead.gradle.utils.CabalHelper) OutputDirectory(org.gradle.api.tasks.OutputDirectory) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) Inject(javax.inject.Inject) 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) DirectoryProperty(org.gradle.api.file.DirectoryProperty) EtaDirectDependency(com.typelead.gradle.eta.api.EtaDirectDependency) DefaultTask(org.gradle.api.DefaultTask) EtaBasePlugin(com.typelead.gradle.eta.plugins.EtaBasePlugin) LinkedHashSet(java.util.LinkedHashSet) Internal(org.gradle.api.tasks.Internal) WriteResult(com.typelead.gradle.utils.CabalHelper.WriteResult) Project(org.gradle.api.Project) Set(java.util.Set) IOException(java.io.IOException) EtaExtension(com.typelead.gradle.eta.api.EtaExtension) Collectors(java.util.stream.Collectors) NamingScheme(com.typelead.gradle.eta.api.NamingScheme) File(java.io.File) ProviderFactory(org.gradle.api.provider.ProviderFactory) Stream(java.util.stream.Stream) ProjectLayout(org.gradle.api.file.ProjectLayout) OutputFile(org.gradle.api.tasks.OutputFile) GradleException(org.gradle.api.GradleException) RegularFile(org.gradle.api.file.RegularFile) EtaGitDependency(com.typelead.gradle.eta.api.EtaGitDependency) DependencyUtils(com.typelead.gradle.eta.internal.DependencyUtils) Input(org.gradle.api.tasks.Input) SourceRepository(com.typelead.gradle.eta.api.SourceRepository) WriteResult(com.typelead.gradle.utils.CabalHelper.WriteResult) GradleException(org.gradle.api.GradleException) IOException(java.io.IOException) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) RegularFile(org.gradle.api.file.RegularFile) EtlasCommand(com.typelead.gradle.utils.EtlasCommand) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with WriteResult

use of com.typelead.gradle.utils.CabalHelper.WriteResult 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)

Aggregations

EtaConfiguration (com.typelead.gradle.eta.api.EtaConfiguration)2 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)2 EtaExtension (com.typelead.gradle.eta.api.EtaExtension)2 DependencyUtils (com.typelead.gradle.eta.internal.DependencyUtils)2 CabalHelper (com.typelead.gradle.utils.CabalHelper)2 WriteResult (com.typelead.gradle.utils.CabalHelper.WriteResult)2 EtlasCommand (com.typelead.gradle.utils.EtlasCommand)2 File (java.io.File)2 IOException (java.io.IOException)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 DefaultTask (org.gradle.api.DefaultTask)2 GradleException (org.gradle.api.GradleException)2 Project (org.gradle.api.Project)2 Configuration (org.gradle.api.artifacts.Configuration)2 DirectoryProperty (org.gradle.api.file.DirectoryProperty)2 RegularFile (org.gradle.api.file.RegularFile)2 Provider (org.gradle.api.provider.Provider)2 Input (org.gradle.api.tasks.Input)2 Internal (org.gradle.api.tasks.Internal)2