Search in sources :

Example 1 with EtlasCommand

use of com.typelead.gradle.utils.EtlasCommand 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 EtlasCommand

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

the class EtaSetupEnvironment method setupEnvironment.

@TaskAction
public void setupEnvironment() {
    EtlasCommand etlas = new EtlasCommand(getProject());
    ResolvedExecutable etlasExec = resolveEtlas();
    /* This is a bootstrap step since we need to populate
           this property in order for the following etlas
           invocation to work. */
    resolvedEtlas.set(etlasExec);
    ensureTelemetryPreferencesAndUpdate(etlas);
    if (etlasExec.getVersion() == null) {
        etlasExec.setVersion(etlas.numericVersion());
    }
    ResolvedExecutable etaExec = resolveEta(etlas);
    resolvedEta.set(etaExec);
    if (etaExec.isFresh()) {
        getProject().getLogger().lifecycle("Installing Eta v" + friendlyVersion(etaExec.getVersion()));
        etlas.installEta();
    }
    boolean changed = SnapshotUtils.takeSnapshotAndCompare(getVersionsSnapshot(), etaExec, etlasExec, getEtaSpec(), getEtlasSpec());
    resolvedEtaInfo.set(fetchEtaInfo(etlas, etaExec, changed));
    versionsChanged.set(Boolean.valueOf(changed));
    setDidWork(changed);
}
Also used : ResolvedExecutable(com.typelead.gradle.utils.ResolvedExecutable) EtlasCommand(com.typelead.gradle.utils.EtlasCommand) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with EtlasCommand

use of com.typelead.gradle.utils.EtlasCommand 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 4 with EtlasCommand

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

the class EtaCompile method compile.

@TaskAction
public void compile() {
    final Project project = getProject();
    final File workingDir = getDestinationDir();
    /* Create cabal.project.local file that will contain configuration options:
           - Configure the `-cp` flag
        */
    Set<File> classpathFiles = new LinkedHashSet<File>(getClasspath().getFiles());
    classpathFiles.addAll(getExtraClasspath());
    CabalHelper.generateCabalProjectLocalFile(getPackageName(), classpathFiles, workingDir);
    /* Fork an etlas process to fetch the dependencies. */
    final EtlasCommand etlas = new EtlasCommand(project);
    etlas.getWorkingDirectory().set(workingDir);
    boolean isUpToDate = etlas.build();
    setDidWork(!isUpToDate);
    Directory classesDir = this.classesDir.getOrNull();
    File outputJarFile = getOutputJarFile();
    if (classesDir != null && !isUpToDate && outputJarFile.exists()) {
        /* Extract the Jar file into the classes directory so the rest of the
               Gradle Java pipeline can work as intended.

               TODO: Add an option for the Eta compiler to generate classfiles directly.
            */
        project.copy(copySpec -> {
            copySpec.from(project.zipTree(outputJarFile));
            copySpec.into(classesDir);
        });
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Project(org.gradle.api.Project) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) RegularFile(org.gradle.api.file.RegularFile) InputFile(org.gradle.api.tasks.InputFile) EtlasCommand(com.typelead.gradle.utils.EtlasCommand) InputDirectory(org.gradle.api.tasks.InputDirectory) OutputDirectory(org.gradle.api.tasks.OutputDirectory) Directory(org.gradle.api.file.Directory) TaskAction(org.gradle.api.tasks.TaskAction)

Example 5 with EtlasCommand

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

the class EtaInstallAllDependencies method installAllDependencies.

@TaskAction
public void installAllDependencies() {
    final File workingDir = getDestinationDir();
    /* Fork an etlas process to install the dependencies.  */
    final EtlasCommand etlas = new EtlasCommand(project);
    etlas.getWorkingDirectory().set(workingDir);
    boolean isUpToDate = etlas.deps(EtlasCommand.libTarget(getProject().getName()), dependencyGraph -> {
        for (Project p : project.getAllprojects()) {
            if (p.getConvention().findPlugin(EtaPluginConvention.class) != null) {
                DependencyHandler dependencies = p.getDependencies();
                for (Configuration c : p.getConfigurations()) {
                    final EtaConfiguration etaConfiguration = ExtensionHelper.getExtension(c, EtaConfiguration.class);
                    if (etaConfiguration != null) {
                        etaConfiguration.resolve(project, dependencies, dependencyGraph);
                    }
                }
            }
        }
        for (Project p : project.getAllprojects()) {
            if (p.getPlugins().findPlugin(EtaPlugin.class) == null && p.getConvention().findPlugin(JavaPluginConvention.class) != null) {
                p.getTasks().withType(EtaInjectDependencies.class).all(EtaInjectDependencies::injectDependencies);
            }
        }
    });
    setDidWork(!isUpToDate);
}
Also used : Project(org.gradle.api.Project) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) Configuration(org.gradle.api.artifacts.Configuration) EtaPluginConvention(com.typelead.gradle.eta.plugins.EtaPluginConvention) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) File(java.io.File) RegularFile(org.gradle.api.file.RegularFile) InputFile(org.gradle.api.tasks.InputFile) EtlasCommand(com.typelead.gradle.utils.EtlasCommand) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

EtlasCommand (com.typelead.gradle.utils.EtlasCommand)6 TaskAction (org.gradle.api.tasks.TaskAction)6 File (java.io.File)5 Project (org.gradle.api.Project)4 RegularFile (org.gradle.api.file.RegularFile)4 EtaConfiguration (com.typelead.gradle.eta.api.EtaConfiguration)3 Configuration (org.gradle.api.artifacts.Configuration)3 OutputDirectory (org.gradle.api.tasks.OutputDirectory)3 OutputFile (org.gradle.api.tasks.OutputFile)3 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 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 DefaultTask (org.gradle.api.DefaultTask)2 GradleException (org.gradle.api.GradleException)2