Search in sources :

Example 1 with PackageInfo

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

the class EtlasMavenRepository method writePomFile.

private void writePomFile(PackageInfo packageInfo, ImmutableDAG<String, PackageInfo> graph) {
    final StringBuilder sb = new StringBuilder();
    println(sb, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    println(sb, "<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
    println(sb, "  <modelVersion>4.0.0</modelVersion>");
    print(sb, "  <groupId>");
    print(sb, getGroupId());
    println(sb, "</groupId>");
    print(sb, "  <artifactId>");
    print(sb, packageInfo.getName());
    println(sb, "</artifactId>");
    print(sb, "  <version>");
    print(sb, packageInfo.getFullVersion());
    println(sb, "</version>");
    println(sb, "  <dependencies>");
    for (PackageInfo dependency : graph.getNodeValues(packageInfo.getName())) {
        println(sb, "    <dependency>");
        print(sb, "      <groupId>");
        print(sb, getGroupId());
        println(sb, "</groupId>");
        print(sb, "      <artifactId>");
        print(sb, dependency.getName());
        println(sb, "</artifactId>");
        print(sb, "      <version>");
        print(sb, dependency.getFullVersion());
        println(sb, "</version>");
        println(sb, "    </dependency>");
    }
    for (String mavenDependency : packageInfo.getMavenDependencies()) {
        String[] parts = mavenDependency.split(":");
        println(sb, "    <dependency>");
        print(sb, "      <groupId>");
        print(sb, parts[0]);
        println(sb, "</groupId>");
        print(sb, "      <artifactId>");
        print(sb, parts[1]);
        println(sb, "</artifactId>");
        print(sb, "      <version>");
        print(sb, parts[2]);
        println(sb, "</version>");
        println(sb, "    </dependency>");
    }
    println(sb, "  </dependencies>");
    println(sb, "</project>");
    try {
        final File packageVersionDirectory = getPackageVersionDirectory(packageInfo);
        packageVersionDirectory.mkdirs();
        Files.write(packageVersionDirectory.toPath().resolve(getPomFileName(packageInfo)), sb.toString().getBytes(StandardCharsets.UTF_8));
    } catch (IOException ie) {
        throw new GradleException("Failed to write pom file for " + packageInfo.getIdentifier(), ie);
    }
}
Also used : PackageInfo(com.typelead.gradle.utils.PackageInfo) GradleException(org.gradle.api.GradleException) IOException(java.io.IOException) File(java.io.File)

Example 2 with PackageInfo

use of com.typelead.gradle.utils.PackageInfo 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 '" + parentConfiguration.getIncoming().getPath() + "'");
        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) ExtensionHelper(com.typelead.gradle.utils.ExtensionHelper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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)

Aggregations

PackageInfo (com.typelead.gradle.utils.PackageInfo)2 File (java.io.File)2 GradleException (org.gradle.api.GradleException)2 EtaConfiguration (com.typelead.gradle.eta.api.EtaConfiguration)1 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)1 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)1 HasPackageName (com.typelead.gradle.eta.api.HasPackageName)1 ConfigurationUtils (com.typelead.gradle.eta.internal.ConfigurationUtils)1 EtlasMavenRepository (com.typelead.gradle.eta.internal.EtlasMavenRepository)1 EtaBasePlugin (com.typelead.gradle.eta.plugins.EtaBasePlugin)1 ExtensionHelper (com.typelead.gradle.utils.ExtensionHelper)1 ImmutableDAG (com.typelead.gradle.utils.ImmutableDAG)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1