Search in sources :

Example 1 with EtaDependency

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

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

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

the class DependencyUtils method foldEtaDependencies.

public static void foldEtaDependencies(final Project project, Collection<EtaDependency> dependencies, BiConsumer<List<String>, List<String>> directProjectConsumer, Consumer<Set<SourceRepository>> gitConsumer) {
    List<String> directDependencies = new ArrayList<>();
    List<String> projectDependencies = new ArrayList<>();
    Set<SourceRepository> gitDependencies = new LinkedHashSet<>();
    for (EtaDependency dependency : dependencies) {
        if (dependency instanceof EtaDirectDependency) {
            directDependencies.add(((EtaDirectDependency) dependency).toString());
        } else if (dependency instanceof EtaProjectDependency) {
            final Project targetProject = ((EtaProjectDependency) dependency).getProject(project);
            if (isEtaProject(targetProject)) {
                projectDependencies.add(targetProject.getName());
            }
        } else if (dependency instanceof EtaGitDependency) {
            gitDependencies.add(((EtaGitDependency) dependency).getSourceRepository());
        }
    }
    if (directProjectConsumer != null) {
        directProjectConsumer.accept(directDependencies, projectDependencies);
    }
    if (gitConsumer != null) {
        gitConsumer.accept(gitDependencies);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) EtaGitDependency(com.typelead.gradle.eta.api.EtaGitDependency) Project(org.gradle.api.Project) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) ArrayList(java.util.ArrayList) EtaDirectDependency(com.typelead.gradle.eta.api.EtaDirectDependency) SourceRepository(com.typelead.gradle.eta.api.SourceRepository)

Example 4 with EtaDependency

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

the class EtaBasePlugin method populateEtaConfiguration.

private void populateEtaConfiguration(final Configuration configuration) {
    final DefaultEtaConfiguration etaConfiguration = ExtensionHelper.createExtension(configuration, ETA_CONFIGURATION_EXTENSION_NAME, DefaultEtaConfiguration.class, configuration, mavenRepository);
    DomainObjectCollection<EtaDependency> dependencies = etaConfiguration.getDependencies();
    configuration.getDependencies().all(dependency -> {
        if (dependency instanceof ProjectDependency) {
            final ProjectDependency projectDependency = (ProjectDependency) dependency;
            dependencies.add(new DefaultEtaProjectDependency(projectDependency.getDependencyProject(), projectDependency.getTargetConfiguration()));
        } else if (dependency instanceof EtaDependency) {
            dependencies.add((EtaDependency) dependency);
        }
    });
}
Also used : DefaultEtaProjectDependency(com.typelead.gradle.eta.internal.DefaultEtaProjectDependency) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) DefaultEtaConfiguration(com.typelead.gradle.eta.internal.DefaultEtaConfiguration) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) DefaultEtaProjectDependency(com.typelead.gradle.eta.internal.DefaultEtaProjectDependency)

Example 5 with EtaDependency

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

the class DefaultEtaConfiguration method getAllResolvedDependencies.

@Override
public List<String> getAllResolvedDependencies(final Project project) {
    List<String> allResolvedDependencies = new ArrayList<String>(getResolvedDependencies());
    for (EtaDependency dependency : dependencies) {
        if (dependency instanceof EtaProjectDependency) {
            final EtaProjectDependency projectDependency = (EtaProjectDependency) dependency;
            final Project targetProject = projectDependency.getProject(project);
            final String targetConfiguration = projectDependency.getTargetConfiguration();
            List<String> mavenDependencies;
            if (targetProject.getPlugins().hasPlugin(EtaBasePlugin.class)) {
                mavenDependencies = ConfigurationUtils.getEtaConfiguration(targetProject, targetConfiguration).getAllResolvedDependencies(project);
            } else {
                mavenDependencies = searchForEtaProjectDependencies(project, ConfigurationUtils.getConfiguration(targetProject, targetConfiguration));
            }
            allResolvedDependencies.addAll(mavenDependencies);
        }
    }
    for (Configuration configuration : parentConfiguration.getExtendsFrom()) {
        allResolvedDependencies.addAll(ConfigurationUtils.getEtaConfiguration(configuration).getAllResolvedDependencies(project));
    }
    return allResolvedDependencies;
}
Also used : EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) Project(org.gradle.api.Project) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) Configuration(org.gradle.api.artifacts.Configuration) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) ArrayList(java.util.ArrayList)

Aggregations

EtaDependency (com.typelead.gradle.eta.api.EtaDependency)6 EtaConfiguration (com.typelead.gradle.eta.api.EtaConfiguration)4 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)4 LinkedHashSet (java.util.LinkedHashSet)4 Configuration (org.gradle.api.artifacts.Configuration)4 ArrayList (java.util.ArrayList)3 Project (org.gradle.api.Project)3 File (java.io.File)2 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)2 Provider (org.gradle.api.provider.Provider)2 EtaDirectDependency (com.typelead.gradle.eta.api.EtaDirectDependency)1 EtaGitDependency (com.typelead.gradle.eta.api.EtaGitDependency)1 HasPackageName (com.typelead.gradle.eta.api.HasPackageName)1 SourceRepository (com.typelead.gradle.eta.api.SourceRepository)1 ConfigurationUtils (com.typelead.gradle.eta.internal.ConfigurationUtils)1 DefaultEtaConfiguration (com.typelead.gradle.eta.internal.DefaultEtaConfiguration)1 DefaultEtaProjectDependency (com.typelead.gradle.eta.internal.DefaultEtaProjectDependency)1 EtlasMavenRepository (com.typelead.gradle.eta.internal.EtlasMavenRepository)1 EtaBasePlugin (com.typelead.gradle.eta.plugins.EtaBasePlugin)1 ExtensionHelper (com.typelead.gradle.utils.ExtensionHelper)1