Search in sources :

Example 1 with SourceRepository

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

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

the class DefaultEtaGitDependency method create.

public static DefaultEtaGitDependency create(Project project, Map<String, String> attributes) {
    validateAttributes(attributes);
    String packageName = attributes.get(PACKAGE_ATTRIBUTE);
    String location = attributes.get(LOCATION_ATTRIBUTE);
    String commit = attributes.get(COMMIT_ATTRIBUTE);
    String branch = attributes.get(BRANCH_ATTRIBUTE);
    String tag = attributes.get(TAG_ATTRIBUTE);
    CommitIdentifierType commitIdType;
    String commitId;
    if (commit != null) {
        commitIdType = COMMIT;
        commitId = commit;
    } else if (tag != null) {
        commitIdType = TAG;
        commitId = tag;
    } else {
        commitIdType = BRANCH;
        commitId = branch;
    }
    return new DefaultEtaGitDependency(project, packageName, new SourceRepository(location, commitIdType, commitId));
}
Also used : CommitIdentifierType(com.typelead.gradle.eta.api.SourceRepository.CommitIdentifierType) SourceRepository(com.typelead.gradle.eta.api.SourceRepository)

Example 3 with SourceRepository

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

the class CabalHelper method generateCabalProjectFile.

public static WriteResult generateCabalProjectFile(final Set<SourceRepository> sourceRepositories, final Collection<File> packageDBs, final File workingDir) {
    StringBuilder sb = new StringBuilder();
    println(sb, "packages: .");
    if (Collections.isNonEmpty(packageDBs)) {
        println(sb, "package-dbs:");
        for (File packageDB : packageDBs) {
            print(sb, "  ");
            println(sb, packageDB.getAbsolutePath());
        }
        print(sb, NEWLINE);
    }
    if (Collections.isNonEmpty(sourceRepositories)) {
        for (SourceRepository sourceRepository : sourceRepositories) {
            println(sb, "source-repository-package");
            println(sb, "  type: git");
            println(sb, "  location: " + sourceRepository.getLocation());
            switch(sourceRepository.getCommitIdentifierType()) {
                case BRANCH:
                    print(sb, "  branch: ");
                    break;
                case TAG:
                    print(sb, "  tag: ");
                    break;
                case COMMIT:
                    print(sb, "  commit: ");
                    break;
            }
            println(sb, sourceRepository.getCommitIdentifier());
        }
    }
    return snapshotWrite(new File(workingDir, "cabal.project"), sb.toString(), new File(workingDir, "cabal.project.snapshot"));
}
Also used : File(java.io.File) SourceRepository(com.typelead.gradle.eta.api.SourceRepository)

Example 4 with SourceRepository

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

the class DependencyUtils method foldEtaDependencies.

public static void foldEtaDependencies(final Project project, final Collection<EtaDependency> dependencies, final QuadConsumer<List<String>, List<String>, List<String>, Set<SourceRepository>> directProjectConsumer) {
    List<String> directDependencies = new ArrayList<>();
    List<String> projectDependencies = new ArrayList<>();
    List<String> gitStringDependencies = 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(NamingScheme.getPackageName(targetProject, SourceSet.MAIN_SOURCE_SET_NAME));
            }
        } else if (dependency instanceof EtaGitDependency) {
            final EtaGitDependency gitDep = (EtaGitDependency) dependency;
            gitDependencies.add(gitDep.getSourceRepository());
            gitStringDependencies.add(gitDep.getPackageName());
        }
    }
    if (directProjectConsumer != null) {
        directProjectConsumer.accept(directDependencies, projectDependencies, gitStringDependencies, 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)

Aggregations

SourceRepository (com.typelead.gradle.eta.api.SourceRepository)4 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)2 EtaDirectDependency (com.typelead.gradle.eta.api.EtaDirectDependency)2 EtaGitDependency (com.typelead.gradle.eta.api.EtaGitDependency)2 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 Project (org.gradle.api.Project)2 CommitIdentifierType (com.typelead.gradle.eta.api.SourceRepository.CommitIdentifierType)1 File (java.io.File)1