Search in sources :

Example 1 with EtaConfiguration

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

the class DefaultEtaConfiguration method doResolve.

public void doResolve(final Project project, final DependencyHandler handler, final ImmutableDAG<String, PackageInfo> dependencyGraph, Set<String> resolvedDependencies) {
    final Logger logger = project.getLogger();
    final String configurationName = parentConfiguration.getName();
    Set<String> resolvedDeps = new HashSet<String>();
    for (Configuration configuration : parentConfiguration.getExtendsFrom()) {
        DefaultEtaConfiguration etaConfiguration = ExtensionHelper.getExtension(configuration, DefaultEtaConfiguration.class);
        etaConfiguration.doResolve(project, handler, dependencyGraph, resolvedDeps);
    }
    List<String> keys = new ArrayList<String>();
    for (EtaDependency dep : dependencies) {
        if (dep instanceof HasPackageName) {
            keys.add(((HasPackageName) dep).getPackageName());
        }
    }
    if (!resolved.get() && resolved.compareAndSet(false, true)) {
        logger.info("Resolving Eta Configuration '" + configurationName + "'");
        List<PackageInfo> packageInfos = dependencyGraph.differenceClosure(keys, resolvedDeps);
        if (packageInfos.size() > 0) {
            mavenRepository.installPackages(packageInfos, dependencyGraph);
            resolvedMavenDependencies = packageInfos.stream().filter(packageInfo -> keys.contains(packageInfo.getName())).map(mavenRepository::getMavenDependency).collect(Collectors.toList());
            for (String mavenDep : resolvedMavenDependencies) {
                handler.add(configurationName, mavenDep);
                logger.info("Injecting maven dependency '" + mavenDep + "'");
            }
        } else {
            resolvedMavenDependencies = Collections.emptyList();
        }
    }
    resolvedDependencies.addAll(resolvedDeps);
    resolvedDependencies.addAll(keys);
}
Also used : DomainObjectCollection(org.gradle.api.DomainObjectCollection) DefaultDomainObjectCollection(org.gradle.api.internal.DefaultDomainObjectCollection) ExtensionHelper(com.typelead.gradle.utils.ExtensionHelper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) FileCollection(org.gradle.api.file.FileCollection) Logger(org.gradle.api.logging.Logger) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) 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) Map(java.util.Map) EtaBasePlugin(com.typelead.gradle.eta.plugins.EtaBasePlugin) LinkedHashSet(java.util.LinkedHashSet) ImmutableDAG(com.typelead.gradle.utils.ImmutableDAG) Project(org.gradle.api.Project) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) HasPackageName(com.typelead.gradle.eta.api.HasPackageName) PackageInfo(com.typelead.gradle.utils.PackageInfo) GradleException(org.gradle.api.GradleException) EtlasMavenRepository(com.typelead.gradle.eta.internal.EtlasMavenRepository) Collections(java.util.Collections) Dependency(org.gradle.api.artifacts.Dependency) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) Configuration(org.gradle.api.artifacts.Configuration) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) PackageInfo(com.typelead.gradle.utils.PackageInfo) ArrayList(java.util.ArrayList) Logger(org.gradle.api.logging.Logger) HasPackageName(com.typelead.gradle.eta.api.HasPackageName) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with EtaConfiguration

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

the class DefaultEtaConfiguration method getAllDependencies.

@Override
public Set<EtaDependency> getAllDependencies() {
    Set<EtaDependency> allDependencies = new LinkedHashSet<>();
    allDependencies.addAll(dependencies);
    for (Configuration configuration : parentConfiguration.getExtendsFrom()) {
        EtaConfiguration etaConfiguration = ExtensionHelper.getExtension(configuration, EtaConfiguration.class);
        allDependencies.addAll(etaConfiguration.getAllDependencies());
    }
    return allDependencies;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) Configuration(org.gradle.api.artifacts.Configuration) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration)

Example 3 with EtaConfiguration

use of com.typelead.gradle.eta.api.EtaConfiguration 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());
    DependencyUtils.foldEtaDependencies(project, dependencies.get(), (directDeps, projectDeps) -> {
        /* Include the project dependencies in the Etlas
                   dependency list. */
        directDeps.addAll(projectDeps);
        writeResults[0] = CabalHelper.generateCabalFile(project.getName(), project.getVersion().toString(), executableSpec, getSourceDirs().getFiles().stream().map(File::getAbsolutePath).collect(Collectors.toList()), modules, etaOptions, directDeps, workingDir);
    }, gitDeps -> {
        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(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) HashMap(java.util.HashMap) 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) 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 EtaConfiguration

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

the class DefaultEtaConfiguration method getAllArtifacts.

@Override
public Set<Provider<File>> getAllArtifacts(final Project project) {
    Set<Provider<File>> allArtifacts = new LinkedHashSet<Provider<File>>();
    allArtifacts.addAll(artifacts);
    for (EtaDependency dependency : getDependencies()) {
        if (dependency instanceof EtaProjectDependency) {
            final EtaProjectDependency projectDependency = ((EtaProjectDependency) dependency);
            final EtaConfiguration etaConfiguration = ConfigurationUtils.getEtaConfiguration(projectDependency.getProject(project), projectDependency.getTargetConfiguration());
            if (etaConfiguration != null) {
                allArtifacts.addAll(etaConfiguration.getAllArtifacts(project));
            }
        }
    }
    for (Configuration configuration : parentConfiguration.getExtendsFrom()) {
        final EtaConfiguration etaConfiguration = ExtensionHelper.getExtension(configuration, EtaConfiguration.class);
        allArtifacts.addAll(etaConfiguration.getAllArtifacts(project));
    }
    return allArtifacts;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) Configuration(org.gradle.api.artifacts.Configuration) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) File(java.io.File) Provider(org.gradle.api.provider.Provider)

Aggregations

EtaConfiguration (com.typelead.gradle.eta.api.EtaConfiguration)4 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)4 Configuration (org.gradle.api.artifacts.Configuration)4 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)3 File (java.io.File)3 LinkedHashSet (java.util.LinkedHashSet)3 Provider (org.gradle.api.provider.Provider)3 ConfigurationUtils (com.typelead.gradle.eta.internal.ConfigurationUtils)2 PackageInfo (com.typelead.gradle.utils.PackageInfo)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 GradleException (org.gradle.api.GradleException)2 Project (org.gradle.api.Project)2 DependencyHandler (org.gradle.api.artifacts.dsl.DependencyHandler)2 FileCollection (org.gradle.api.file.FileCollection)2 EtaExtension (com.typelead.gradle.eta.api.EtaExtension)1