From cbea89910f59de13a35a6c034165802887d8156d Mon Sep 17 00:00:00 2001 From: Daniel Pelaez Date: Sat, 25 Jan 2020 09:22:17 -0500 Subject: [PATCH 1/2] Add support for Maven profiles See gh-1057 --- .../GroovyMavenBuildCustomizerTests.java | 4 +- .../KotlinJpaMavenBuildCustomizerTests.java | 3 +- .../KotlinMavenBuildCustomizerTests.java | 8 +- .../KotlinMavenFullBuildCustomizerTests.java | 6 +- .../generator/buildsystem/BomContainer.java | 2 +- .../generator/buildsystem/Build.java | 7 +- .../buildsystem/DependencyContainer.java | 2 +- .../buildsystem/MavenRepositoryContainer.java | 2 +- .../buildsystem/maven/MavenBuild.java | 8 + .../buildsystem/maven/MavenBuildWriter.java | 199 ++++++- .../buildsystem/maven/MavenConfiguration.java | 146 +++++ .../buildsystem/maven/MavenPlugin.java | 143 +---- .../maven/MavenPluginManagement.java | 51 ++ .../buildsystem/maven/MavenProfile.java | 223 ++++++++ .../maven/MavenProfileActivation.java | 119 ++++ .../maven/MavenProfileActivationFile.java | 64 +++ .../maven/MavenProfileActivationOS.java | 92 +++ .../maven/MavenProfileActivationProperty.java | 64 +++ .../buildsystem/maven/MavenProfileBuild.java | 163 ++++++ .../maven/MavenProfileContainer.java | 106 ++++ .../buildsystem/maven/MavenReportPlugin.java | 119 ++++ .../maven/MavenReportPluginContainer.java | 65 +++ .../buildsystem/maven/MavenReportSet.java | 100 ++++ .../maven/MavenReportSetContainer.java | 66 +++ .../buildsystem/maven/MavenReporting.java | 80 +++ .../buildsystem/maven/MavenBuildTests.java | 21 + .../maven/MavenBuildWriterTests.java | 532 ++++++++++++++++++ .../buildsystem/maven/MavenPluginTests.java | 31 +- .../MavenProfileActivationFileTests.java | 41 ++ .../maven/MavenProfileActivationOSTests.java | 45 ++ .../MavenProfileActivationPropertyTests.java | 41 ++ .../maven/MavenProfileActivationTests.java | 51 ++ .../maven/MavenProfileBuildTests.java | 65 +++ .../maven/MavenProfileContainerTests.java | 168 ++++++ .../buildsystem/maven/MavenProfileTests.java | 96 ++++ .../MavenReportPluginContainerTests.java | 119 ++++ .../maven/MavenReportPluginTests.java | 55 ++ .../maven/MavenReportSetContainerTests.java | 112 ++++ .../maven/MavenReportSetTests.java | 51 ++ .../maven/MavenReportingTests.java | 45 ++ 40 files changed, 3131 insertions(+), 184 deletions(-) create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenConfiguration.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginManagement.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfile.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivation.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFile.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOS.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationProperty.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuild.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainer.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPlugin.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainer.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSet.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainer.java create mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReporting.java create mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFileTests.java create mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOSTests.java create mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationPropertyTests.java create mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationTests.java create mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuildTests.java create mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainerTests.java create mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileTests.java create mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainerTests.java create mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginTests.java create mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainerTests.java create mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetTests.java create mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportingTests.java diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/groovy/GroovyMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/groovy/GroovyMavenBuildCustomizerTests.java index d9f8a37e..ca9ba9e9 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/groovy/GroovyMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/groovy/GroovyMavenBuildCustomizerTests.java @@ -17,7 +17,7 @@ package io.spring.initializr.generator.spring.code.groovy; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; -import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuration; +import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Execution; import org.junit.jupiter.api.Test; @@ -38,7 +38,7 @@ class GroovyMavenBuildCustomizerTests { assertThat(groovyPlugin.getGroupId()).isEqualTo("org.codehaus.gmavenplus"); assertThat(groovyPlugin.getArtifactId()).isEqualTo("gmavenplus-plugin"); assertThat(groovyPlugin.getVersion()).isEqualTo("1.11.0"); - Configuration configuration = groovyPlugin.getConfiguration(); + MavenConfiguration configuration = groovyPlugin.getConfiguration(); assertThat(configuration).isNull(); assertThat(groovyPlugin.getExecutions()).hasSize(1); Execution execution = groovyPlugin.getExecutions().get(0); diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java index d2649df2..d54089b9 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java @@ -18,6 +18,7 @@ package io.spring.initializr.generator.spring.code.kotlin; import java.util.Collections; +import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin; import io.spring.initializr.generator.test.InitializrMetadataTestBuilder; @@ -45,7 +46,7 @@ class KotlinJpaMavenBuildCustomizerTests { assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { assertThat(plugin.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(plugin.getArtifactId()).isEqualTo("kotlin-maven-plugin"); - MavenPlugin.Setting settings = plugin.getConfiguration().getSettings().get(0); + MavenConfiguration.Setting settings = plugin.getConfiguration().getSettings().get(0); assertThat(settings.getValue()).asList().element(0).hasFieldOrPropertyWithValue("name", "plugin") .hasFieldOrPropertyWithValue("value", "jpa"); assertThat(plugin.getDependencies()).hasSize(1); diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java index acd3a94f..8a929a30 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java @@ -20,9 +20,9 @@ import java.util.Arrays; import java.util.List; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; -import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuration; +import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Dependency; -import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting; +import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration.Setting; import io.spring.initializr.generator.version.VersionProperty; import org.junit.jupiter.api.Test; @@ -60,7 +60,7 @@ class KotlinMavenBuildCustomizerTests { assertThat(kotlinPlugin.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(kotlinPlugin.getArtifactId()).isEqualTo("kotlin-maven-plugin"); assertThat(kotlinPlugin.getVersion()).isNull(); - Configuration configuration = kotlinPlugin.getConfiguration(); + MavenConfiguration configuration = kotlinPlugin.getConfiguration(); assertThat(configuration).isNotNull(); assertThat(configuration.getSettings()).hasSize(2); Setting args = configuration.getSettings().get(0); @@ -87,7 +87,7 @@ class KotlinMavenBuildCustomizerTests { MavenBuild build = new MavenBuild(); new KotlinMavenBuildCustomizer(new TestKotlinProjectSettings()).customize(build); assertThat(build.plugins().values()).singleElement().satisfies((kotlinPlugin) -> { - Configuration configuration = kotlinPlugin.getConfiguration(); + MavenConfiguration configuration = kotlinPlugin.getConfiguration(); Setting args = configuration.getSettings().get(0); assertThat(args.getName()).isEqualTo("args"); assertThat(args.getValue()).asList().hasSize(2); diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizerTests.java index 2da168d0..64124e9e 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizerTests.java @@ -17,10 +17,10 @@ package io.spring.initializr.generator.spring.code.kotlin; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; -import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuration; +import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Dependency; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Execution; -import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting; +import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration.Setting; import io.spring.initializr.generator.version.VersionProperty; import org.junit.jupiter.api.Test; @@ -58,7 +58,7 @@ class KotlinMavenFullBuildCustomizerTests { assertThat(kotlinPlugin.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(kotlinPlugin.getArtifactId()).isEqualTo("kotlin-maven-plugin"); assertThat(kotlinPlugin.getVersion()).isEqualTo("${kotlin.version}"); - Configuration configuration = kotlinPlugin.getConfiguration(); + MavenConfiguration configuration = kotlinPlugin.getConfiguration(); assertThat(configuration).isNotNull(); assertThat(configuration.getSettings()).hasSize(3); Setting args = configuration.getSettings().get(0); diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/BomContainer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/BomContainer.java index 452ccb60..d172b92d 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/BomContainer.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/BomContainer.java @@ -26,7 +26,7 @@ import java.util.function.Function; */ public class BomContainer extends BuildItemContainer { - BomContainer(Function itemResolver) { + public BomContainer(Function itemResolver) { super(new LinkedHashMap<>(), itemResolver); } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/Build.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/Build.java index b5b95a57..eb702419 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/Build.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/Build.java @@ -34,8 +34,10 @@ public abstract class Build { private final MavenRepositoryContainer pluginRepositories; + private final BuildItemResolver resolver; + protected Build(BuildItemResolver buildItemResolver) { - BuildItemResolver resolver = determineBuildItemResolver(buildItemResolver); + this.resolver = determineBuildItemResolver(buildItemResolver); this.properties = new PropertyContainer(); this.dependencies = new DependencyContainer(resolver::resolveDependency); this.boms = new BomContainer(resolver::resolveBom); @@ -108,4 +110,7 @@ public abstract class Build { return this.pluginRepositories; } + public BuildItemResolver getResolver() { + return resolver; + } } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/DependencyContainer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/DependencyContainer.java index 2636ee19..e538331c 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/DependencyContainer.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/DependencyContainer.java @@ -26,7 +26,7 @@ import java.util.function.Function; */ public class DependencyContainer extends BuildItemContainer { - DependencyContainer(Function itemResolver) { + public DependencyContainer(Function itemResolver) { super(new LinkedHashMap<>(), itemResolver); } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/MavenRepositoryContainer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/MavenRepositoryContainer.java index cf544916..97a74fba 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/MavenRepositoryContainer.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/MavenRepositoryContainer.java @@ -27,7 +27,7 @@ import java.util.function.Function; */ public class MavenRepositoryContainer extends BuildItemContainer { - MavenRepositoryContainer(Function itemResolver) { + public MavenRepositoryContainer(Function itemResolver) { super(new LinkedHashMap<>(), itemResolver); } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuild.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuild.java index d98b6f0f..261b474d 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuild.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuild.java @@ -39,8 +39,12 @@ public class MavenBuild extends Build { private final MavenDistributionManagement.Builder distributionManagement = new MavenDistributionManagement.Builder(); + private final MavenProfileContainer profiles; + public MavenBuild(BuildItemResolver buildItemResolver) { super(buildItemResolver); + + this.profiles = new MavenProfileContainer(super.getResolver()); } public MavenBuild() { @@ -102,4 +106,8 @@ public class MavenBuild extends Build { return this.plugins; } + public MavenProfileContainer profiles() { + return this.profiles; + } + } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriter.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriter.java index 24d77003..a58b4816 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriter.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriter.java @@ -28,19 +28,20 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import io.spring.initializr.generator.buildsystem.BillOfMaterials; +import io.spring.initializr.generator.buildsystem.BomContainer; import io.spring.initializr.generator.buildsystem.Dependency; import io.spring.initializr.generator.buildsystem.Dependency.Exclusion; import io.spring.initializr.generator.buildsystem.DependencyComparator; import io.spring.initializr.generator.buildsystem.DependencyContainer; import io.spring.initializr.generator.buildsystem.DependencyScope; import io.spring.initializr.generator.buildsystem.MavenRepository; +import io.spring.initializr.generator.buildsystem.MavenRepositoryContainer; import io.spring.initializr.generator.buildsystem.PropertyContainer; import io.spring.initializr.generator.buildsystem.maven.MavenDistributionManagement.DeploymentRepository; import io.spring.initializr.generator.buildsystem.maven.MavenDistributionManagement.Relocation; import io.spring.initializr.generator.buildsystem.maven.MavenDistributionManagement.Site; -import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuration; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Execution; -import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting; +import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration.Setting; import io.spring.initializr.generator.io.IndentingWriter; import io.spring.initializr.generator.version.VersionProperty; import io.spring.initializr.generator.version.VersionReference; @@ -75,11 +76,12 @@ public class MavenBuildWriter { writeCollectionElement(writer, "developers", settings.getDevelopers(), this::writeDeveloper); writeScm(writer, settings.getScm()); writeProperties(writer, build.properties()); - writeDependencies(writer, build); - writeDependencyManagement(writer, build); + writeDependencies(writer, build.dependencies()); + writeDependencyManagement(writer, build.boms()); writeBuild(writer, build); - writeRepositories(writer, build); - writeDistributionManagement(writer, build); + writeProfiles(writer, build); + writeRepositories(writer, build.repositories(), build.pluginRepositories()); + writeDistributionManagement(writer, build.getDistributionManagement()); }); } @@ -194,11 +196,10 @@ public class MavenBuildWriter { } } - private void writeDependencies(IndentingWriter writer, MavenBuild build) { - if (build.dependencies().isEmpty()) { + private void writeDependencies(IndentingWriter writer, DependencyContainer dependencies) { + if (dependencies.isEmpty()) { return; } - DependencyContainer dependencies = build.dependencies(); writer.println(); writeElement(writer, "dependencies", () -> { Collection compiledDependencies = writeDependencies(writer, dependencies, @@ -281,11 +282,11 @@ public class MavenBuildWriter { || dependency.getScope() == DependencyScope.COMPILE_ONLY); } - private void writeDependencyManagement(IndentingWriter writer, MavenBuild build) { - if (build.boms().isEmpty()) { + private void writeDependencyManagement(IndentingWriter writer, BomContainer bomsContainer) { + if (bomsContainer.isEmpty()) { return; } - List boms = build.boms().items().sorted(Comparator.comparing(BillOfMaterials::getOrder)) + List boms = bomsContainer.items().sorted(Comparator.comparing(BillOfMaterials::getOrder)) .collect(Collectors.toList()); writer.println(); writeElement(writer, "dependencyManagement", @@ -323,15 +324,16 @@ public class MavenBuildWriter { writeSingleElement(writer, "finalName", settings.getFinalName()); writeSingleElement(writer, "sourceDirectory", settings.getSourceDirectory()); writeSingleElement(writer, "testSourceDirectory", settings.getTestSourceDirectory()); - writeResources(writer, build); + writeResources(writer, build.resources(), build.testResources()); writeCollectionElement(writer, "plugins", build.plugins().values(), this::writePlugin); }); } - private void writeResources(IndentingWriter writer, MavenBuild build) { - writeCollectionElement(writer, "resources", build.resources().values(), this::writeResource); - writeCollectionElement(writer, "testResources", build.testResources().values(), this::writeTestResource); + private void writeResources(IndentingWriter writer, MavenResourceContainer resources, + MavenResourceContainer testResources) { + writeCollectionElement(writer, "resources", resources.values(), this::writeResource); + writeCollectionElement(writer, "testResources", testResources.values(), this::writeTestResource); } private void writeResource(IndentingWriter writer, MavenResource resource) { @@ -370,17 +372,17 @@ public class MavenBuildWriter { if (plugin.isExtensions()) { writeSingleElement(writer, "extensions", "true"); } - writePluginConfiguration(writer, plugin.getConfiguration()); + writeConfiguration(writer, "configuration", plugin.getConfiguration()); writeCollectionElement(writer, "executions", plugin.getExecutions(), this::writePluginExecution); writeCollectionElement(writer, "dependencies", plugin.getDependencies(), this::writePluginDependency); }); } - private void writePluginConfiguration(IndentingWriter writer, Configuration configuration) { + private void writeConfiguration(IndentingWriter writer, String tag, MavenConfiguration configuration) { if (configuration == null || configuration.getSettings().isEmpty()) { return; } - writeCollectionElement(writer, "configuration", configuration.getSettings(), this::writeSetting); + writeCollectionElement(writer, tag, configuration.getSettings(), this::writeSetting); } @SuppressWarnings("unchecked") @@ -401,7 +403,7 @@ public class MavenBuildWriter { if (!goals.isEmpty()) { writeElement(writer, "goals", () -> goals.forEach((goal) -> writeSingleElement(writer, "goal", goal))); } - writePluginConfiguration(writer, execution.getConfiguration()); + writeConfiguration(writer, "configuration", execution.getConfiguration()); }); } @@ -413,9 +415,10 @@ public class MavenBuildWriter { }); } - private void writeRepositories(IndentingWriter writer, MavenBuild build) { - List repositories = filterRepositories(build.repositories().items()); - List pluginRepositories = filterRepositories(build.pluginRepositories().items()); + private void writeRepositories(IndentingWriter writer, MavenRepositoryContainer buildRepositories, + MavenRepositoryContainer buildPluginRepositories) { + List repositories = filterRepositories(buildRepositories.items()); + List pluginRepositories = filterRepositories(buildPluginRepositories.items()); if (repositories.isEmpty() && pluginRepositories.isEmpty()) { return; } @@ -448,8 +451,8 @@ public class MavenBuildWriter { }); } - private void writeDistributionManagement(IndentingWriter writer, MavenBuild build) { - MavenDistributionManagement distributionManagement = build.getDistributionManagement(); + private void writeDistributionManagement(IndentingWriter writer, + MavenDistributionManagement distributionManagement) { if (distributionManagement.isEmpty()) { return; } @@ -491,6 +494,152 @@ public class MavenBuildWriter { } } + private void writeProfiles(IndentingWriter writer, MavenBuild build) { + MavenProfileContainer profilesContainer = build.profiles(); + if (profilesContainer.isEmpty()) { + return; + } + Stream profiles = profilesContainer.values(); + writer.println(); + writeElement(writer, "profiles", () -> { + profiles.forEach((profile) -> { + writeElement(writer, "profile", () -> { + writeSingleElement(writer, "id", profile.getId()); + writeProfileActivation(writer, profile.getActivation()); + writeProfileBuild(writer, profile.getBuild()); + writeCollectionElement(writer, "modules", profile.getModules(), (IndentingWriter writerInner, + String module) -> writeSingleElement(writerInner, "module", module)); + writeRepositories(writer, profile.getRepositories(), profile.getPluginRepositories()); + writeDependencies(writer, profile.getDependencies()); + writeReporting(writer, profile.getReporting()); + writeDependencyManagement(writer, profile.getDependencyManagement()); + writeDistributionManagement(writer, profile.getDistributionManagement()); + writeConfiguration(writer, "properties", profile.getProperties()); + }); + }); + }); + } + + private void writeProfileActivation(IndentingWriter writer, MavenProfileActivation activation) { + if (activation == null) { + return; + } + + writer.println(); + writeElement(writer, "activation", () -> { + writeSingleElement(writer, "activeByDefault", String.valueOf(activation.getActiveByDefault())); + writeSingleElement(writer, "jdk", activation.getJdk()); + + MavenProfileActivationOS os = activation.getOs(); + if (os != null) { + writeElement(writer, "os", () -> { + writeSingleElement(writer, "name", os.getName()); + writeSingleElement(writer, "arch", os.getArch()); + writeSingleElement(writer, "family", os.getFamily()); + writeSingleElement(writer, "version", os.getVersion()); + }); + } + + MavenProfileActivationProperty property = activation.getProperty(); + if (property != null) { + writeElement(writer, "property", () -> { + writeSingleElement(writer, "name", property.getName()); + writeSingleElement(writer, "value", property.getValue()); + }); + } + + MavenProfileActivationFile file = activation.getFile(); + if (file != null) { + writeElement(writer, "file", () -> { + writeSingleElement(writer, "exists", file.getExists()); + writeSingleElement(writer, "missing", file.getMissing()); + }); + } + }); + } + + private void writeProfileBuild(IndentingWriter writer, MavenProfileBuild build) { + if (build == null) { + return; + } + + writer.println(); + writeElement(writer, "build", () -> { + writeSingleElement(writer, "defaultGoal", build.getDefaultGoal()); + writeSingleElement(writer, "directory", build.getDirectory()); + writeSingleElement(writer, "fileName", build.getFinalName()); + writeCollectionElement(writer, "filters", build.getFilters(), + (IndentingWriter writerInner, String filter) -> writeSingleElement(writerInner, "filter", filter)); + writeResources(writer, build.getResources(), build.getTestResources()); + writePluginManagement(writer, build.getPluginManagement()); + writeCollectionElement(writer, "plugins", build.getPlugins().values(), this::writePlugin); + }); + } + + private void writePluginManagement(IndentingWriter writer, MavenPluginManagement pluginManagement) { + if (pluginManagement == null) { + return; + } + + writer.println(); + writeElement(writer, "pluginManagement", () -> writeCollectionElement(writer, "plugins", + pluginManagement.getPlugins().values(), this::writePlugin)); + } + + private void writeReporting(IndentingWriter writer, MavenReporting reporting) { + if (reporting == null) { + return; + } + + writer.println(); + writeElement(writer, "reporting", () -> { + writeSingleElement(writer, "excludeDefaults", String.valueOf(reporting.isExcludeDefaults())); + writeSingleElement(writer, "outputDirectory", reporting.getOutputDirectory()); + writeReportPlugins(writer, reporting.getReportPlugins()); + }); + } + + private void writeReportPlugins(IndentingWriter writer, MavenReportPluginContainer reportPlugins) { + if (reportPlugins.isEmpty()) { + return; + } + + Stream reportPluginStream = reportPlugins.values(); + writer.println(); + writeElement(writer, "plugins", () -> { + reportPluginStream.forEach((plugin) -> { + writeElement(writer, "plugin", () -> { + writeSingleElement(writer, "groupId", plugin.getGroupId()); + writeSingleElement(writer, "artifactId", plugin.getArtifactId()); + writeSingleElement(writer, "version", plugin.getVersion()); + writeSingleElement(writer, "inherited", plugin.getInherited()); + writeConfiguration(writer, "configuration", plugin.getConfiguration()); + writeReportSets(writer, plugin.getReportSets()); + }); + }); + }); + } + + private void writeReportSets(IndentingWriter writer, MavenReportSetContainer reportSets) { + if (reportSets.isEmpty()) { + return; + } + + Stream reportSetStream = reportSets.values(); + writer.println(); + writeElement(writer, "reportSets", () -> { + reportSetStream.forEach((reportSet) -> { + writeElement(writer, "reportSet", () -> { + writeSingleElement(writer, "id", reportSet.getId()); + writeSingleElement(writer, "inherited", reportSet.getInherited()); + writeConfiguration(writer, "configuration", reportSet.getConfiguration()); + writeCollectionElement(writer, "reports", reportSet.getReports(), (IndentingWriter writerInner, + String report) -> writeSingleElement(writerInner, "report", report)); + }); + }); + }); + } + private void writeSingleElement(IndentingWriter writer, String name, String text) { if (text != null) { writer.print(String.format("<%s>", name)); diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenConfiguration.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenConfiguration.java new file mode 100644 index 00000000..d58e5dcc --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenConfiguration.java @@ -0,0 +1,146 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +/** + * A {@code } or {@code } that allow every xml structure on a + * different parts of the pom like {@link MavenPlugin.Execution}, {@link MavenPlugin}. + * TODO + * + * @author Andy Wilkinson + * @author Olga Maciaszek-Sharma + * @author Daniel Andres Pelaez Lopez + */ +public final class MavenConfiguration { + + private final List settings; + + MavenConfiguration(List settings) { + this.settings = Collections.unmodifiableList(settings); + } + + /** + * Return the {@linkplain Setting settings} of the configuration. + * @return the settings + */ + public List getSettings() { + return this.settings; + } + + /** + * A setting in a {@link MavenConfiguration}. + */ + public static final class Setting { + + private final String name; + + private final Object value; + + private Setting(String name, Object value) { + this.name = name; + this.value = value; + } + + /** + * Return the name of the configuration item. + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * Return the value. Can be a nested {@link MavenConfiguration}. + * @return a simple value or a nested configuration + */ + public Object getValue() { + return this.value; + } + + } + + /** + * Builder for a {@link MavenConfiguration}. + */ + public static class Builder { + + private final List settings = new ArrayList<>(); + + /** + * Add the specified parameter with a single value. + * @param name the name of the parameter + * @param value the single value of the parameter + * @return this for method chaining + */ + public Builder add(String name, String value) { + this.settings.add(new Setting(name, value)); + return this; + } + + /** + * Configure the parameter with the specified {@code name}. + * @param name the name of the parameter + * @param consumer a consumer to further configure the parameter + * @return this for method chaining + * @throws IllegalArgumentException if a parameter with the same name is + * registered with a single value + */ + public Builder configure(String name, Consumer consumer) { + Object value = this.settings.stream().filter((candidate) -> candidate.getName().equals(name)).findFirst() + .orElseGet(() -> { + Setting nestedSetting = new Setting(name, new Builder()); + this.settings.add(nestedSetting); + return nestedSetting; + }).getValue(); + if (!(value instanceof Builder)) { + throw new IllegalArgumentException(String.format( + "Could not customize parameter '%s', a single value %s is already registered", name, value)); + } + Builder nestedConfiguration = (Builder) value; + consumer.accept(nestedConfiguration); + return this; + } + + /** + * Build a {@link MavenConfiguration} with the current state of this builder. + * @return a {@link MavenConfiguration} + */ + MavenConfiguration build() { + return new MavenConfiguration(this.settings.stream() + .map((entry) -> resolve(entry.getName(), entry.getValue())).collect(Collectors.toList())); + } + + private Setting resolve(String key, Object value) { + if (value instanceof Builder) { + List values = ((Builder) value).settings.stream() + .map((entry) -> resolve(entry.getName(), entry.getValue())).collect(Collectors.toList()); + return new Setting(key, values); + } + else { + return new Setting(key, value); + } + } + + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPlugin.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPlugin.java index f7e3a8d2..99adee3b 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPlugin.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPlugin.java @@ -44,7 +44,7 @@ public class MavenPlugin { private final List dependencies; - private final Configuration configuration; + private final MavenConfiguration configuration; protected MavenPlugin(Builder builder) { this.groupId = builder.groupId; @@ -107,10 +107,10 @@ public class MavenPlugin { } /** - * Return the {@linkplain Configuration configuration} of the plugin. + * Return the {@linkplain MavenConfiguration configuration} of the plugin. * @return the configuration */ - public Configuration getConfiguration() { + public MavenConfiguration getConfiguration() { return this.configuration; } @@ -131,7 +131,7 @@ public class MavenPlugin { private final List dependencies = new ArrayList<>(); - private ConfigurationBuilder configurationBuilder; + private MavenConfiguration.Builder configurationBuilder; protected Builder(String groupId, String artifactId) { this.groupId = groupId; @@ -164,9 +164,9 @@ public class MavenPlugin { * @param configuration a consumer of the current configuration * @return this for method chaining */ - public Builder configuration(Consumer configuration) { + public Builder configuration(Consumer configuration) { if (this.configurationBuilder == null) { - this.configurationBuilder = new ConfigurationBuilder(); + this.configurationBuilder = new MavenConfiguration.Builder(); } configuration.accept(this.configurationBuilder); return this; @@ -218,7 +218,7 @@ public class MavenPlugin { private final List goals = new ArrayList<>(); - private ConfigurationBuilder configurationCustomization = null; + private MavenConfiguration.Builder configurationCustomization = null; public ExecutionBuilder(String id) { this.id = id; @@ -255,9 +255,9 @@ public class MavenPlugin { * @param configuration a consumer of the current configuration * @return this for method chaining */ - public ExecutionBuilder configuration(Consumer configuration) { + public ExecutionBuilder configuration(Consumer configuration) { if (this.configurationCustomization == null) { - this.configurationCustomization = new ConfigurationBuilder(); + this.configurationCustomization = new MavenConfiguration.Builder(); } configuration.accept(this.configurationCustomization); return this; @@ -265,123 +265,6 @@ public class MavenPlugin { } - /** - * Builder for a {@link Configuration}. - */ - public static class ConfigurationBuilder { - - private final List settings = new ArrayList<>(); - - /** - * Add the specified parameter with a single value. - * @param name the name of the parameter - * @param value the single value of the parameter - * @return this for method chaining - */ - public ConfigurationBuilder add(String name, String value) { - this.settings.add(new Setting(name, value)); - return this; - } - - /** - * Configure the parameter with the specified {@code name}. - * @param name the name of the parameter - * @param consumer a consumer to further configure the parameter - * @return this for method chaining - * @throws IllegalArgumentException if a parameter with the same name is - * registered with a single value - */ - public ConfigurationBuilder configure(String name, Consumer consumer) { - Object value = this.settings.stream().filter((candidate) -> candidate.getName().equals(name)).findFirst() - .orElseGet(() -> { - Setting nestedSetting = new Setting(name, new ConfigurationBuilder()); - this.settings.add(nestedSetting); - return nestedSetting; - }).getValue(); - if (!(value instanceof ConfigurationBuilder)) { - throw new IllegalArgumentException(String.format( - "Could not customize parameter '%s', a single value %s is already registered", name, value)); - } - ConfigurationBuilder nestedConfiguration = (ConfigurationBuilder) value; - consumer.accept(nestedConfiguration); - return this; - } - - /** - * Build a {@link Configuration} with the current state of this builder. - * @return a {@link Configuration} - */ - Configuration build() { - return new Configuration(this.settings.stream().map((entry) -> resolve(entry.getName(), entry.getValue())) - .collect(Collectors.toList())); - } - - private Setting resolve(String key, Object value) { - if (value instanceof ConfigurationBuilder) { - List values = ((ConfigurationBuilder) value).settings.stream() - .map((entry) -> resolve(entry.getName(), entry.getValue())).collect(Collectors.toList()); - return new Setting(key, values); - } - else { - return new Setting(key, value); - } - } - - } - - /** - * A {@code } on an {@link Execution} or {@link MavenPlugin}. - */ - public static final class Configuration { - - private final List settings; - - private Configuration(List settings) { - this.settings = Collections.unmodifiableList(settings); - } - - /** - * Return the {@linkplain Setting settings} of the configuration. - * @return the settings - */ - public List getSettings() { - return this.settings; - } - - } - - /** - * A setting in a {@link Configuration}. - */ - public static final class Setting { - - private final String name; - - private final Object value; - - private Setting(String name, Object value) { - this.name = name; - this.value = value; - } - - /** - * Return the name of the configuration item. - * @return the name - */ - public String getName() { - return this.name; - } - - /** - * Return the value. Can be a nested {@link Configuration}. - * @return a simple value or a nested configuration - */ - public Object getValue() { - return this.value; - } - - } - /** * An {@code } of a {@link MavenPlugin}. */ @@ -393,9 +276,9 @@ public class MavenPlugin { private final List goals; - private final Configuration configuration; + private final MavenConfiguration configuration; - private Execution(String id, String phase, List goals, Configuration configuration) { + private Execution(String id, String phase, List goals, MavenConfiguration configuration) { this.id = id; this.phase = phase; this.goals = Collections.unmodifiableList(goals); @@ -427,10 +310,10 @@ public class MavenPlugin { } /** - * Return the {@linkplain Configuration configuration} of the execution. + * Return the {@linkplain MavenConfiguration configuration} of the execution. * @return the configuration */ - public Configuration getConfiguration() { + public MavenConfiguration getConfiguration() { return this.configuration; } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginManagement.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginManagement.java new file mode 100644 index 00000000..96efa804 --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginManagement.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import java.util.function.Consumer; + +public class MavenPluginManagement { + + private final MavenPluginContainer plugins; + + protected MavenPluginManagement(Builder builder) { + this.plugins = builder.plugins; + } + + public MavenPluginContainer getPlugins() { + return this.plugins; + } + + public static class Builder { + + private MavenPluginContainer plugins = new MavenPluginContainer(); + + protected Builder() { + } + + public MavenPluginManagement.Builder plugins(Consumer plugins) { + plugins.accept(this.plugins); + return this; + } + + public MavenPluginManagement build() { + return new MavenPluginManagement(this); + } + + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfile.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfile.java new file mode 100644 index 00000000..0a354e24 --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfile.java @@ -0,0 +1,223 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; + +import io.spring.initializr.generator.buildsystem.BomContainer; +import io.spring.initializr.generator.buildsystem.BuildItemResolver; +import io.spring.initializr.generator.buildsystem.DependencyContainer; +import io.spring.initializr.generator.buildsystem.MavenRepositoryContainer; + +public class MavenProfile { + + private final String id; + + private final MavenProfileActivation activation; + + private final MavenProfileBuild build; + + private final List modules; + + private final MavenRepositoryContainer repositories; + + private final MavenRepositoryContainer pluginRepositories; + + private final DependencyContainer dependencies; + + private final MavenReporting reporting; + + private final BomContainer dependencyManagement; + + private final MavenDistributionManagement distributionManagement; + + private final MavenConfiguration properties; + + protected MavenProfile(Builder builder) { + this.id = builder.id; + this.activation = Optional.ofNullable(builder.activationBuilder).map(MavenProfileActivation.Builder::build) + .orElse(null); + this.build = Optional.ofNullable(builder.buildBuilder).map(MavenProfileBuild.Builder::build).orElse(null); + this.modules = builder.modules; + this.repositories = builder.repositories; + this.pluginRepositories = builder.pluginRepositories; + this.dependencies = builder.dependencies; + this.reporting = Optional.ofNullable(builder.reportingBuilder).map(MavenReporting.Builder::build).orElse(null); + this.dependencyManagement = builder.dependencyManagement; + this.distributionManagement = Optional.ofNullable(builder.distributionManagementBuilder) + .map(MavenDistributionManagement.Builder::build).orElse(new MavenDistributionManagement.Builder().build()); + this.properties = Optional.ofNullable(builder.properties).map(MavenConfiguration.Builder::build).orElse(null); + } + + public String getId() { + return this.id; + } + + public MavenProfileActivation getActivation() { + return this.activation; + } + + public MavenProfileBuild getBuild() { + return this.build; + } + + public List getModules() { + return this.modules; + } + + public MavenRepositoryContainer getRepositories() { + return this.repositories; + } + + public MavenRepositoryContainer getPluginRepositories() { + return this.pluginRepositories; + } + + public DependencyContainer getDependencies() { + return this.dependencies; + } + + public MavenReporting getReporting() { + return this.reporting; + } + + public BomContainer getDependencyManagement() { + return this.dependencyManagement; + } + + public MavenDistributionManagement getDistributionManagement() { + return this.distributionManagement; + } + + public MavenConfiguration getProperties() { + return this.properties; + } + + public static class Builder { + + private final String id; + + private final BuildItemResolver buildItemResolver; + + private MavenProfileActivation.Builder activationBuilder; + + private MavenProfileBuild.Builder buildBuilder; + + private List modules; + + private MavenRepositoryContainer repositories; + + private MavenRepositoryContainer pluginRepositories; + + private DependencyContainer dependencies; + + private MavenReporting.Builder reportingBuilder; + + private BomContainer dependencyManagement; + + private MavenDistributionManagement.Builder distributionManagementBuilder; + + private MavenConfiguration.Builder properties; + + protected Builder(String id, BuildItemResolver buildItemResolver) { + this.id = id; + this.buildItemResolver = buildItemResolver; + this.dependencyManagement = new BomContainer(this.buildItemResolver::resolveBom); + this.repositories = new MavenRepositoryContainer(this.buildItemResolver::resolveRepository); + this.pluginRepositories = new MavenRepositoryContainer(this.buildItemResolver::resolveRepository); + this.dependencies = new DependencyContainer(this.buildItemResolver::resolveDependency); + } + + public Builder activation(Consumer activation) { + if (this.activationBuilder == null) { + this.activationBuilder = new MavenProfileActivation.Builder(); + } + activation.accept(this.activationBuilder); + return this; + } + + public Builder build(Consumer build) { + if (this.buildBuilder == null) { + this.buildBuilder = new MavenProfileBuild.Builder(); + } + build.accept(this.buildBuilder); + return this; + } + + public Builder module(String module) { + if (this.modules == null) { + this.modules = new LinkedList<>(); + } + this.modules.add(module); + return this; + } + + public Builder repositories(Consumer repositories) { + repositories.accept(this.repositories); + return this; + } + + public Builder pluginRepositories(Consumer pluginRepositories) { + pluginRepositories.accept(this.pluginRepositories); + return this; + } + + public Builder reporting(Consumer reporting) { + if (this.reportingBuilder == null) { + this.reportingBuilder = new MavenReporting.Builder(); + } + reporting.accept(this.reportingBuilder); + return this; + } + + public Builder dependencies(Consumer dependencies) { + dependencies.accept(this.dependencies); + return this; + } + + public Builder dependencyManagement(Consumer dependencyManagement) { + dependencyManagement.accept(this.dependencyManagement); + return this; + } + + public Builder distributionManagement( + Consumer distributionManagementBuilder) { + if (this.distributionManagementBuilder == null) { + this.distributionManagementBuilder = new MavenDistributionManagement.Builder(); + } + distributionManagementBuilder.accept(this.distributionManagementBuilder); + return this; + } + + public Builder properties(Consumer properties) { + if (this.properties == null) { + this.properties = new MavenConfiguration.Builder(); + } + properties.accept(this.properties); + return this; + } + + public MavenProfile build() { + return new MavenProfile(this); + } + + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivation.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivation.java new file mode 100644 index 00000000..d4e546bd --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivation.java @@ -0,0 +1,119 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import java.util.Optional; +import java.util.function.Consumer; + +public class MavenProfileActivation { + + private final Boolean activeByDefault; + + private final String jdk; + + private final MavenProfileActivationOS os; + + private final MavenProfileActivationProperty property; + + private final MavenProfileActivationFile file; + + protected MavenProfileActivation(Builder builder) { + this.activeByDefault = builder.activeByDefault; + this.jdk = builder.jdk; + this.os = Optional.ofNullable(builder.osBuilder).map(MavenProfileActivationOS.Builder::build).orElse(null); + this.property = Optional.ofNullable(builder.propertyBuilder).map(MavenProfileActivationProperty.Builder::build) + .orElse(null); + this.file = Optional.ofNullable(builder.fileBuilder).map(MavenProfileActivationFile.Builder::build) + .orElse(null); + } + + public Boolean getActiveByDefault() { + return this.activeByDefault; + } + + public String getJdk() { + return this.jdk; + } + + public MavenProfileActivationOS getOs() { + return this.os; + } + + public MavenProfileActivationProperty getProperty() { + return this.property; + } + + public MavenProfileActivationFile getFile() { + return this.file; + } + + public static class Builder { + + private Boolean activeByDefault; + + private String jdk; + + private MavenProfileActivationOS.Builder osBuilder; + + private MavenProfileActivationProperty.Builder propertyBuilder; + + private MavenProfileActivationFile.Builder fileBuilder; + + protected Builder() { + } + + public MavenProfileActivation.Builder activeByDefault(boolean activeByDefault) { + this.activeByDefault = activeByDefault; + return this; + } + + public MavenProfileActivation.Builder jdk(String jdk) { + this.jdk = jdk; + return this; + } + + public MavenProfileActivation.Builder os(Consumer os) { + if (this.osBuilder == null) { + this.osBuilder = new MavenProfileActivationOS.Builder(); + } + os.accept(this.osBuilder); + return this; + } + + public MavenProfileActivation.Builder property(Consumer property) { + if (this.propertyBuilder == null) { + this.propertyBuilder = new MavenProfileActivationProperty.Builder(); + } + property.accept(this.propertyBuilder); + return this; + } + + public MavenProfileActivation.Builder file(Consumer file) { + if (this.fileBuilder == null) { + this.fileBuilder = new MavenProfileActivationFile.Builder(); + } + file.accept(this.fileBuilder); + return this; + } + + public MavenProfileActivation build() { + return new MavenProfileActivation(this); + } + + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFile.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFile.java new file mode 100644 index 00000000..4074f2f0 --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFile.java @@ -0,0 +1,64 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +public class MavenProfileActivationFile { + + private final String missing; + + private final String exists; + + protected MavenProfileActivationFile(Builder builder) { + this.missing = builder.missing; + this.exists = builder.exists; + } + + public String getMissing() { + return this.missing; + } + + public String getExists() { + return this.exists; + } + + public static class Builder { + + private String missing; + + private String exists; + + protected Builder() { + + } + + public MavenProfileActivationFile.Builder missing(String missing) { + this.missing = missing; + return this; + } + + public MavenProfileActivationFile.Builder exists(String exists) { + this.exists = exists; + return this; + } + + public MavenProfileActivationFile build() { + return new MavenProfileActivationFile(this); + } + + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOS.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOS.java new file mode 100644 index 00000000..3290b59c --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOS.java @@ -0,0 +1,92 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +public class MavenProfileActivationOS { + + private final String name; + + private final String family; + + private final String arch; + + private final String version; + + public MavenProfileActivationOS(Builder builder) { + this.name = builder.name; + this.family = builder.family; + this.arch = builder.arch; + this.version = builder.version; + } + + public String getName() { + return this.name; + } + + public String getFamily() { + return this.family; + } + + public String getArch() { + return this.arch; + } + + public String getVersion() { + return this.version; + } + + public static class Builder { + + private String name; + + private String family; + + private String arch; + + private String version; + + protected Builder() { + + } + + public MavenProfileActivationOS.Builder name(String name) { + this.name = name; + return this; + } + + public MavenProfileActivationOS.Builder family(String family) { + this.family = family; + return this; + } + + public MavenProfileActivationOS.Builder arch(String arch) { + this.arch = arch; + return this; + } + + public MavenProfileActivationOS.Builder version(String version) { + this.version = version; + return this; + } + + public MavenProfileActivationOS build() { + return new MavenProfileActivationOS(this); + } + + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationProperty.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationProperty.java new file mode 100644 index 00000000..e0359a19 --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationProperty.java @@ -0,0 +1,64 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +public class MavenProfileActivationProperty { + + private final String name; + + private final String value; + + protected MavenProfileActivationProperty(Builder builder) { + this.name = builder.name; + this.value = builder.value; + } + + public String getName() { + return this.name; + } + + public String getValue() { + return this.value; + } + + public static class Builder { + + private String name; + + private String value; + + protected Builder() { + + } + + public MavenProfileActivationProperty.Builder name(String name) { + this.name = name; + return this; + } + + public MavenProfileActivationProperty.Builder value(String value) { + this.value = value; + return this; + } + + public MavenProfileActivationProperty build() { + return new MavenProfileActivationProperty(this); + } + + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuild.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuild.java new file mode 100644 index 00000000..ef4be22f --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuild.java @@ -0,0 +1,163 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; + +public class MavenProfileBuild { + + private final String defaultGoal; + + private final String directory; + + private final String finalName; + + private final List filters; + + private final MavenResourceContainer resources; + + private final MavenResourceContainer testResources; + + private final MavenPluginManagement pluginManagement; + + private final MavenPluginContainer plugins; + + protected MavenProfileBuild(Builder builder) { + this.defaultGoal = builder.defaultGoal; + this.directory = builder.directory; + this.finalName = builder.finalName; + this.filters = Optional.ofNullable(builder.filters).map(Collections::unmodifiableList).orElse(null); + this.resources = builder.resources; + this.testResources = builder.testResources; + this.pluginManagement = Optional.ofNullable(builder.pluginManagementBuilder) + .map(MavenPluginManagement.Builder::build).orElse(null); + this.plugins = builder.plugins; + } + + public String getDefaultGoal() { + return this.defaultGoal; + } + + public String getDirectory() { + return this.directory; + } + + public String getFinalName() { + return this.finalName; + } + + public List getFilters() { + return this.filters; + } + + public MavenResourceContainer getResources() { + return this.resources; + } + + public MavenResourceContainer getTestResources() { + return this.testResources; + } + + public MavenPluginManagement getPluginManagement() { + return this.pluginManagement; + } + + public MavenPluginContainer getPlugins() { + return this.plugins; + } + + public static class Builder { + + private String defaultGoal; + + private String directory; + + private String finalName; + + private List filters; + + private MavenResourceContainer resources; + + private MavenResourceContainer testResources; + + private MavenPluginManagement.Builder pluginManagementBuilder; + + private MavenPluginContainer plugins; + + protected Builder() { + this.resources = new MavenResourceContainer(); + this.testResources = new MavenResourceContainer(); + this.plugins = new MavenPluginContainer(); + } + + public MavenProfileBuild.Builder defaultGoal(String defaultGoal) { + this.defaultGoal = defaultGoal; + return this; + } + + public MavenProfileBuild.Builder directory(String directory) { + this.directory = directory; + return this; + } + + public MavenProfileBuild.Builder finalName(String finalName) { + this.finalName = finalName; + return this; + } + + public MavenProfileBuild.Builder filter(String filter) { + if (this.filters == null) { + this.filters = new LinkedList<>(); + } + this.filters.add(filter); + return this; + } + + public MavenProfileBuild.Builder resources(Consumer resources) { + resources.accept(this.resources); + return this; + } + + public MavenProfileBuild.Builder testResources(Consumer testResources) { + testResources.accept(this.testResources); + return this; + } + + public MavenProfileBuild.Builder pluginManagement(Consumer pluginManagement) { + if (this.pluginManagementBuilder == null) { + this.pluginManagementBuilder = new MavenPluginManagement.Builder(); + } + pluginManagement.accept(this.pluginManagementBuilder); + return this; + } + + public MavenProfileBuild.Builder plugins(Consumer plugins) { + plugins.accept(this.plugins); + return this; + } + + public MavenProfileBuild build() { + return new MavenProfileBuild(this); + } + + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainer.java new file mode 100644 index 00000000..f7a4715b --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainer.java @@ -0,0 +1,106 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Stream; + +import io.spring.initializr.generator.buildsystem.BuildItemResolver; + +public class MavenProfileContainer { + + private final Map profiles = new LinkedHashMap<>(); + + private final BuildItemResolver buildItemResolver; + + public MavenProfileContainer(BuildItemResolver buildItemResolver) { + this.buildItemResolver = buildItemResolver; + } + + /** + * Specify if this container is empty. + * @return {@code true} if no {@link MavenProfile} is added + */ + public boolean isEmpty() { + return this.profiles.isEmpty(); + } + + /** + * Returns a {@link Stream} of registered {@link MavenProfile}s. + * @return a stream of {@link MavenProfile}s + */ + public Stream values() { + return this.profiles.values().stream().map(MavenProfile.Builder::build); + } + + /** + * Add a {@link MavenProfile} with the specified {@code id} and + * {@code activateByDefault}. + * @param id the id of the profile + */ + public void add(String id) { + createProfileBuilder(id); + } + + /** + * Specify if this container has a plugin with the specified {@code groupId} and + * {@code artifactId}. + * @param id the groupId of the plugin + * @return {@code true} if an item with the specified {@code groupId} and + * {@code artifactId} exists + */ + public boolean has(String id) { + return this.profiles.containsKey(id); + } + + /** + * Add a {@link MavenProfile} with the specified {@code id} and + * {@code activateByDefault} and {@link MavenProfile.Builder} to customize the + * profile. If the profile has already been added, the profileBuilder can be used to + * further tune the existing profile configuration. + * @param id the id of the profile + * @param profileBuilder a {@link MavenProfile.Builder} to customize the + * {@link MavenProfile} + */ + public void add(String id, Consumer profileBuilder) { + profileBuilder.accept(createProfileBuilder(id)); + } + + /** + * Remove the plugin with the specified {@code groupId} and {@code artifactId}. + * @param id the groupId of the plugin to remove + * @return {@code true} if such a plugin was registered, {@code false} otherwise + */ + public boolean remove(String id) { + return this.profiles.remove(id) != null; + } + + private MavenProfile.Builder createProfileBuilder(String id) { + MavenProfile.Builder profileBuilder = this.profiles.get(id); + if (profileBuilder == null) { + MavenProfile.Builder builder = new MavenProfile.Builder(id, this.buildItemResolver); + this.profiles.put(id, builder); + return builder; + } + else { + return profileBuilder; + } + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPlugin.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPlugin.java new file mode 100644 index 00000000..7a54ade2 --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPlugin.java @@ -0,0 +1,119 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import java.util.Optional; +import java.util.function.Consumer; + +public class MavenReportPlugin { + + private final String groupId; + + private final String artifactId; + + private final String version; + + private final String inherited; + + private final MavenConfiguration configuration; + + private final MavenReportSetContainer reportSets; + + protected MavenReportPlugin(Builder builder) { + this.groupId = builder.groupId; + this.artifactId = builder.artifactId; + this.version = builder.version; + this.inherited = builder.inherited; + this.configuration = Optional.ofNullable(builder.configuration).map(MavenConfiguration.Builder::build) + .orElse(null); + this.reportSets = builder.reportSets; + } + + public String getGroupId() { + return this.groupId; + } + + public String getArtifactId() { + return this.artifactId; + } + + public String getVersion() { + return this.version; + } + + public String getInherited() { + return this.inherited; + } + + public MavenConfiguration getConfiguration() { + return this.configuration; + } + + public MavenReportSetContainer getReportSets() { + return this.reportSets; + } + + public static class Builder { + + private final String groupId; + + private final String artifactId; + + private String version; + + private String inherited; + + private MavenConfiguration.Builder configuration; + + private MavenReportSetContainer reportSets; + + protected Builder(String groupId, String artifactId) { + this.groupId = groupId; + this.artifactId = artifactId; + this.reportSets = new MavenReportSetContainer(); + } + + public MavenReportPlugin.Builder inherited(String inherited) { + this.inherited = inherited; + return this; + } + + public MavenReportPlugin.Builder version(String version) { + this.version = version; + return this; + } + + public MavenReportPlugin.Builder configuration(Consumer configuration) { + if (this.configuration == null) { + this.configuration = new MavenConfiguration.Builder(); + } + configuration.accept(this.configuration); + return this; + } + + public MavenReportPlugin.Builder reportSets(Consumer reportSets) { + reportSets.accept(this.reportSets); + return this; + } + + public MavenReportPlugin build() { + return new MavenReportPlugin(this); + } + + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainer.java new file mode 100644 index 00000000..581721be --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainer.java @@ -0,0 +1,65 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Stream; + +import io.spring.initializr.generator.buildsystem.maven.MavenReportPlugin.Builder; + +public class MavenReportPluginContainer { + + private final Map reportPlugins = new LinkedHashMap<>(); + + public boolean isEmpty() { + return this.reportPlugins.isEmpty(); + } + + public boolean has(String groupId, String artifactId) { + return this.reportPlugins.containsKey(pluginKey(groupId, artifactId)); + } + + public Stream values() { + return this.reportPlugins.values().stream().map(Builder::build); + } + + public MavenReportPluginContainer add(String groupId, String artifactId) { + addReportPlugin(groupId, artifactId); + return this; + } + + public MavenReportPluginContainer add(String groupId, String artifactId, Consumer plugin) { + plugin.accept(addReportPlugin(groupId, artifactId)); + return this; + } + + private Builder addReportPlugin(String groupId, String artifactId) { + return this.reportPlugins.computeIfAbsent(pluginKey(groupId, artifactId), + (pluginId) -> new Builder(groupId, artifactId)); + } + + public boolean remove(String groupId, String artifactId) { + return this.reportPlugins.remove(pluginKey(groupId, artifactId)) != null; + } + + private String pluginKey(String groupId, String artifactId) { + return String.format("%s:%s", groupId, artifactId); + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSet.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSet.java new file mode 100644 index 00000000..747ee002 --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSet.java @@ -0,0 +1,100 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; + +public class MavenReportSet { + + private final String id; + + private final MavenConfiguration configuration; + + private final String inherited; + + private final List reports; + + public MavenReportSet(Builder builder) { + this.id = builder.id; + this.configuration = Optional.ofNullable(builder.configuration).map(MavenConfiguration.Builder::build) + .orElse(null); + this.inherited = builder.inherited; + this.reports = Optional.ofNullable(builder.reports).map(Collections::unmodifiableList).orElse(null); + } + + public String getId() { + return this.id; + } + + public MavenConfiguration getConfiguration() { + return this.configuration; + } + + public String getInherited() { + return this.inherited; + } + + public List getReports() { + return this.reports; + } + + public static class Builder { + + private final String id; + + private MavenConfiguration.Builder configuration; + + private String inherited; + + private List reports; + + protected Builder(String id) { + this.id = id; + } + + public MavenReportSet.Builder configuration(Consumer configuration) { + if (this.configuration == null) { + this.configuration = new MavenConfiguration.Builder(); + } + configuration.accept(this.configuration); + return this; + } + + public MavenReportSet.Builder inherited(String inherited) { + this.inherited = inherited; + return this; + } + + public MavenReportSet.Builder report(String report) { + if (this.reports == null) { + this.reports = new LinkedList<>(); + } + this.reports.add(report); + return this; + } + + public MavenReportSet build() { + return new MavenReportSet(this); + } + + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainer.java new file mode 100644 index 00000000..13463914 --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainer.java @@ -0,0 +1,66 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Stream; + +public class MavenReportSetContainer { + + private final Map reportSets = new LinkedHashMap<>(); + + public boolean isEmpty() { + return this.reportSets.isEmpty(); + } + + public Stream values() { + return this.reportSets.values().stream().map(MavenReportSet.Builder::build); + } + + public MavenReportSetContainer add(String id) { + createReportSetBuilder(id); + return this; + } + + public boolean has(String id) { + return this.reportSets.containsKey(id); + } + + public MavenReportSetContainer add(String id, Consumer profileBuilder) { + profileBuilder.accept(createReportSetBuilder(id)); + return this; + } + + public boolean remove(String id) { + return this.reportSets.remove(id) != null; + } + + private MavenReportSet.Builder createReportSetBuilder(String id) { + MavenReportSet.Builder reportSetBuilder = this.reportSets.get(id); + if (reportSetBuilder == null) { + MavenReportSet.Builder builder = new MavenReportSet.Builder(id); + this.reportSets.put(id, builder); + return builder; + } + else { + return reportSetBuilder; + } + } + +} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReporting.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReporting.java new file mode 100644 index 00000000..bedc0174 --- /dev/null +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReporting.java @@ -0,0 +1,80 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import java.util.function.Consumer; + +public class MavenReporting { + + private final Boolean excludeDefaults; + + private final String outputDirectory; + + private final MavenReportPluginContainer reportPlugins; + + protected MavenReporting(Builder builder) { + this.excludeDefaults = builder.excludeDefaults; + this.outputDirectory = builder.outputDirectory; + this.reportPlugins = builder.reportPlugins; + } + + public Boolean isExcludeDefaults() { + return this.excludeDefaults; + } + + public String getOutputDirectory() { + return this.outputDirectory; + } + + public MavenReportPluginContainer getReportPlugins() { + return this.reportPlugins; + } + + public static class Builder { + + private Boolean excludeDefaults; + + private String outputDirectory; + + private MavenReportPluginContainer reportPlugins; + + protected Builder() { + this.reportPlugins = new MavenReportPluginContainer(); + } + + public MavenReporting.Builder excludeDefaults(boolean excludeDefaults) { + this.excludeDefaults = excludeDefaults; + return this; + } + + public MavenReporting.Builder outputDirectory(String outputDirectory) { + this.outputDirectory = outputDirectory; + return this; + } + + public MavenReporting.Builder reportPlugins(Consumer reportPlugins) { + reportPlugins.accept(this.reportPlugins); + return this; + } + + public MavenReporting build() { + return new MavenReporting(this); + } + + } + +} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildTests.java index 97ebcb7f..b602be84 100644 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildTests.java @@ -139,4 +139,25 @@ class MavenBuildTests { .satisfies((testPlugin) -> assertThat(testPlugin.isExtensions()).isTrue()); } + @Test + void mavenProfilesCanBeConfigured() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", + (profile) -> profile.activation((activation) -> activation.activeByDefault(true))); + assertThat(build.profiles().values()).hasOnlyOneElementSatisfying((profile) -> { + assertThat(profile.getId()).isEqualTo("profile1"); + assertThat(profile.getActivation()).isNotNull(); + assertThat(profile.getActivation().getActiveByDefault()).isTrue(); + assertThat(profile.getBuild()).isNull(); + assertThat(profile.getModules()).isNull(); + assertThat(profile.getRepositories().isEmpty()).isTrue(); + assertThat(profile.getPluginRepositories().isEmpty()).isTrue(); + assertThat(profile.getDependencies().isEmpty()).isTrue(); + assertThat(profile.getReporting()).isNull(); + assertThat(profile.getDependencyManagement().isEmpty()).isTrue(); + assertThat(profile.getDistributionManagement().isEmpty()).isTrue(); + assertThat(profile.getProperties()).isNull(); + }); + } + } diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriterTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriterTests.java index 118cd938..f41c1f41 100644 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriterTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriterTests.java @@ -861,6 +861,538 @@ class MavenBuildWriterTests { "A "demo" project for 'developers' & 'testers'"); } + @Test + void powWithProfile() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1"); + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileActivationActiveByDefaultJDK() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", + (profile) -> profile.activation((activation) -> activation.activeByDefault(true).jdk("11"))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + assertThat(profile).textAtPath("activation/activeByDefault").isEqualTo("true"); + assertThat(profile).textAtPath("activation/jdk").isEqualTo("11"); + assertThat(profile).nodeAtPath("activation/os").isNull(); + assertThat(profile).nodeAtPath("activation/property").isNull(); + assertThat(profile).nodeAtPath("activation/file").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileActivationOS() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", (profile) -> profile.activation( + (activation) -> activation.os((os) -> os.version("1.0").name("linux").arch("x68").family("intel")))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + assertThat(profile).textAtPath("activation/os/version").isEqualTo("1.0"); + assertThat(profile).textAtPath("activation/os/name").isEqualTo("linux"); + assertThat(profile).textAtPath("activation/os/arch").isEqualTo("x68"); + assertThat(profile).textAtPath("activation/os/family").isEqualTo("intel"); + assertThat(profile).nodeAtPath("activation/property").isNull(); + assertThat(profile).nodeAtPath("activation/file").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileActivationProperty() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", (profile) -> profile + .activation((activation) -> activation.property((property) -> property.name("name1").value("value1")))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + assertThat(profile).textAtPath("activation/property/value").isEqualTo("value1"); + assertThat(profile).textAtPath("activation/property/name").isEqualTo("name1"); + assertThat(profile).nodeAtPath("activation/os").isNull(); + assertThat(profile).nodeAtPath("activation/file").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileActivationFile() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", (profile) -> profile + .activation((activation) -> activation.file((file) -> file.exists("true").missing("false")))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + assertThat(profile).textAtPath("activation/file/exists").isEqualTo("true"); + assertThat(profile).textAtPath("activation/file/missing").isEqualTo("false"); + assertThat(profile).nodeAtPath("activation/os").isNull(); + assertThat(profile).nodeAtPath("activation/property").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileBuild() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", profile -> profile.build( + (profileBuild) -> profileBuild.defaultGoal("compile").directory("/directory").finalName("build.txt"))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + assertThat(profile).textAtPath("build/defaultGoal").isEqualTo("compile"); + assertThat(profile).textAtPath("build/directory").isEqualTo("/directory"); + assertThat(profile).textAtPath("build/fileName").isEqualTo("build.txt"); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileBuildFilters() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", + profile -> profile.build((profileBuild) -> profileBuild.filter("filter1").filter("filter2"))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + NodeAssert filters = profile.nodeAtPath("build/filters"); + filters.nodesAtPath("filter").hasSize(2); + assertThat(filters).textAtPath("filter[1]").isEqualTo("filter1"); + assertThat(filters).textAtPath("filter[2]").isEqualTo("filter2"); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileBuildResources() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", profile -> profile.build((profileBuild) -> profileBuild.resources( + (resources) -> resources.add("src/main/custom", (resource) -> resource.includes("**/*.properties"))))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + assertThat(profile).textAtPath("build/resources/resource/directory").isEqualTo("src/main/custom"); + assertThat(profile).textAtPath("build/resources/resource/targetPath").isNullOrEmpty(); + assertThat(profile).textAtPath("build/resources/resource/filtering").isNullOrEmpty(); + assertThat(profile).textAtPath("build/resources/resource/includes/include").isEqualTo("**/*.properties"); + assertThat(profile).textAtPath("build/resources/resource/excludes").isNullOrEmpty(); + assertThat(profile).textAtPath("build/testResources").isNullOrEmpty(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileBuildTestResources() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", + profile -> profile.build( + (profileBuild) -> profileBuild.testResources((resources) -> resources.add("src/test/custom", + (resource) -> resource.excludes("**/*.gen").filtering(true).targetPath("test"))))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + assertThat(profile).textAtPath("build/resources").isNullOrEmpty(); + assertThat(profile).textAtPath("build/testResources/testResource/directory").isEqualTo("src/test/custom"); + assertThat(profile).textAtPath("build/testResources/testResource/targetPath").isEqualTo("test"); + assertThat(profile).textAtPath("build/testResources/testResource/filtering").isEqualTo("true"); + assertThat(profile).textAtPath("build/testResources/testResource/includes").isNullOrEmpty(); + assertThat(profile).textAtPath("build/testResources/testResource/excludes/exclude").isEqualTo("**/*.gen"); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileBuildPluginManagement() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", profile -> profile + .build((profileBuild) -> profileBuild.pluginManagement((pluginManagement) -> pluginManagement + .plugins((plugins) -> plugins.add("org.springframework.boot", "spring-boot-maven-plugin"))))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + NodeAssert plugin = profile.nodeAtPath("build/pluginManagement/plugins/plugin"); + assertThat(plugin).textAtPath("groupId").isEqualTo("org.springframework.boot"); + assertThat(plugin).textAtPath("artifactId").isEqualTo("spring-boot-maven-plugin"); + assertThat(plugin).textAtPath("version").isNullOrEmpty(); + assertThat(plugin).textAtPath("extensions").isNullOrEmpty(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileBuildPlugin() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", profile -> profile.build((profileBuild) -> profileBuild + .plugins((plugins) -> plugins.add("org.springframework.boot", "spring-boot-maven-plugin")))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + NodeAssert plugin = profile.nodeAtPath("build/plugins/plugin"); + assertThat(plugin).textAtPath("groupId").isEqualTo("org.springframework.boot"); + assertThat(plugin).textAtPath("artifactId").isEqualTo("spring-boot-maven-plugin"); + assertThat(plugin).textAtPath("version").isNullOrEmpty(); + assertThat(plugin).textAtPath("extensions").isNullOrEmpty(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileModules() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", profile -> profile.module("module1").module("module2")); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + NodeAssert filters = profile.nodeAtPath("modules"); + filters.nodesAtPath("module").hasSize(2); + assertThat(filters).textAtPath("module[1]").isEqualTo("module1"); + assertThat(filters).textAtPath("module[2]").isEqualTo("module2"); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileRepositories() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", + profile -> profile.repositories((repositories) -> repositories + .add(MavenRepository.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone") + .name("Spring Milestones")))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + assertThat(profile).textAtPath("repositories/repository/id").isEqualTo("spring-milestones"); + assertThat(profile).textAtPath("repositories/repository/name").isEqualTo("Spring Milestones"); + assertThat(profile).textAtPath("repositories/repository/url").isEqualTo("https://repo.spring.io/milestone"); + assertThat(profile).nodeAtPath("repositories/repository/snapshots").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfilePluginRepositories() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", + profile -> profile.pluginRepositories((repositories) -> repositories + .add(MavenRepository.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone") + .name("Spring Milestones")))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + assertThat(profile).textAtPath("pluginRepositories/pluginRepository/id").isEqualTo("spring-milestones"); + assertThat(profile).textAtPath("pluginRepositories/pluginRepository/name").isEqualTo("Spring Milestones"); + assertThat(profile).textAtPath("pluginRepositories/pluginRepository/url") + .isEqualTo("https://repo.spring.io/milestone"); + assertThat(profile).nodeAtPath("repositories/repository/snapshots").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("dependencies").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileDependencies() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", profile -> profile.dependencies((dependencies) -> dependencies.add("root", + "org.springframework.boot", "spring-boot-starter", DependencyScope.COMPILE))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + NodeAssert dependency = profile.nodeAtPath("dependencies/dependency"); + assertThat(dependency).textAtPath("groupId").isEqualTo("org.springframework.boot"); + assertThat(dependency).textAtPath("artifactId").isEqualTo("spring-boot-starter"); + assertThat(dependency).textAtPath("version").isNullOrEmpty(); + assertThat(dependency).textAtPath("scope").isNullOrEmpty(); + assertThat(dependency).textAtPath("optional").isNullOrEmpty(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileReporting() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", + profile -> profile.reporting((reporting) -> reporting.excludeDefaults(true).outputDirectory("/here"))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + assertThat(profile).textAtPath("reporting/excludeDefaults").isEqualTo("true"); + assertThat(profile).textAtPath("reporting/outputDirectory").isEqualTo("/here"); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileReportingPlugin() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", profile -> profile.reporting( + (reporting) -> reporting.reportPlugins((reportPlugins) -> reportPlugins.add("org.apache.maven.plugins", + "maven-project-info-reports-plugin", (plugin) -> plugin.version("2.6").inherited("true") + .configuration((configuration) -> configuration.add("config1", "value1")))))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + NodeAssert plugin = profile.nodeAtPath("reporting/plugins/plugin"); + assertThat(plugin).textAtPath("groupId").isEqualTo("org.apache.maven.plugins"); + assertThat(plugin).textAtPath("artifactId").isEqualTo("maven-project-info-reports-plugin"); + assertThat(plugin).textAtPath("version").isEqualTo("2.6"); + assertThat(plugin).textAtPath("inherited").isEqualTo("true"); + assertThat(plugin).textAtPath("configuration/config1").isEqualTo("value1"); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileReportingPluginReportSets() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", profile -> profile.reporting((reporting) -> reporting.reportPlugins( + (reportPlugins) -> reportPlugins.add("org.apache.maven.plugins", "maven-project-info-reports-plugin", + (plugin) -> plugin.reportSets((reportSets -> reportSets.add("reportSet1", + (reportSet) -> reportSet.inherited("true").report("reportA").configuration( + (configuration) -> configuration.add("config1", "value1"))))))))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + NodeAssert reportSet = profile.nodeAtPath("reporting/plugins/plugin/reportSets/reportSet"); + assertThat(reportSet).textAtPath("id").isEqualTo("reportSet1"); + assertThat(reportSet).textAtPath("inherited").isEqualTo("true"); + assertThat(reportSet).textAtPath("reports/report").isEqualTo("reportA"); + assertThat(reportSet).textAtPath("configuration/config1").isEqualTo("value1"); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("dependencyManagement").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileDependencyManagement() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", + profile -> profile.dependencyManagement((dependencyManagement) -> dependencyManagement.add("test", + BillOfMaterials.withCoordinates("com.example", "my-project-dependencies") + .version(VersionReference.ofValue("1.0.0.RELEASE"))))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + NodeAssert dependency = profile.nodeAtPath("dependencyManagement/dependencies/dependency"); + assertBom(dependency, "com.example", "my-project-dependencies", "1.0.0.RELEASE"); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileDistributionManagement() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", profile -> profile + .distributionManagement((distribution) -> distribution.downloadUrl("https://example.com/download"))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + NodeAssert distributionManagement = profile.nodeAtPath("distributionManagement"); + assertThat(distributionManagement).textAtPath("downloadUrl").isEqualTo("https://example.com/download"); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("properties").isNull(); + }); + } + + @Test + void powWithProfileProperties() { + MavenBuild build = new MavenBuild(); + build.profiles().add("profile1", + profile -> profile.properties((properties) -> properties.add("prop1", "prop2"))); + + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + NodeAssert properties = profile.nodeAtPath("properties"); + assertThat(properties).textAtPath("prop1").isEqualTo("prop2"); + assertThat(profile).nodeAtPath("reporting").isNull(); + assertThat(profile).nodeAtPath("repositories").isNull(); + assertThat(profile).nodeAtPath("build").isNull(); + assertThat(profile).nodeAtPath("activation").isNull(); + assertThat(profile).nodeAtPath("modules").isNull(); + assertThat(profile).nodeAtPath("pluginRepositories").isNull(); + assertThat(profile).nodeAtPath("distributionManagement").isNull(); + }); + } + private void generatePom(MavenBuild mavenBuild, Consumer consumer) { consumer.accept(new NodeAssert(writePom(new MavenBuildWriter(), mavenBuild))); } diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginTests.java index 823c3d79..d1b60cb7 100644 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginTests.java @@ -19,7 +19,7 @@ package io.spring.initializr.generator.buildsystem.maven; import java.util.List; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Builder; -import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting; +import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration.Setting; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -37,10 +37,10 @@ class MavenPluginTests { MavenPlugin plugin = plugin("com.example", "test-plugin") .configuration((configuration) -> configuration.add("enabled", "false").add("skip", "true")) .configuration((configuration) -> configuration.add("another", "test")).build(); - assertThat(plugin.getConfiguration().getSettings().stream().map(Setting::getName)).containsExactly("enabled", - "skip", "another"); - assertThat(plugin.getConfiguration().getSettings().stream().map(Setting::getValue)).containsExactly("false", - "true", "test"); + assertThat(plugin.getConfiguration().getSettings().stream().map(MavenConfiguration.Setting::getName)) + .containsExactly("enabled", "skip", "another"); + assertThat(plugin.getConfiguration().getSettings().stream().map(MavenConfiguration.Setting::getValue)) + .containsExactly("false", "true", "test"); } @Test @@ -48,10 +48,10 @@ class MavenPluginTests { MavenPlugin plugin = plugin("com.example", "test-plugin") .configuration((configuration) -> configuration.add("enabled", "true")) .configuration((configuration) -> configuration.add("skip", "false")).build(); - assertThat(plugin.getConfiguration().getSettings().stream().map(Setting::getName)).containsExactly("enabled", - "skip"); - assertThat(plugin.getConfiguration().getSettings().stream().map(Setting::getValue)).containsExactly("true", - "false"); + assertThat(plugin.getConfiguration().getSettings().stream().map(MavenConfiguration.Setting::getName)) + .containsExactly("enabled", "skip"); + assertThat(plugin.getConfiguration().getSettings().stream().map(MavenConfiguration.Setting::getValue)) + .containsExactly("true", "false"); } @Test @@ -66,8 +66,8 @@ class MavenPluginTests { assertThat(setting.getName()).isEqualTo("items"); assertThat(setting.getValue()).isInstanceOf(List.class); List values = (List) setting.getValue(); - assertThat(values.stream().map(Setting::getName)).containsExactly("item", "item"); - assertThat(values.stream().map(Setting::getValue)).containsExactly("one", "two"); + assertThat(values.stream().map(MavenConfiguration.Setting::getName)).containsExactly("item", "item"); + assertThat(values.stream().map(MavenConfiguration.Setting::getValue)).containsExactly("one", "two"); } @Test @@ -92,8 +92,9 @@ class MavenPluginTests { assertThat(item.getName()).isEqualTo("item"); assertThat(item.getValue()).isInstanceOf(List.class); List subItems = (List) item.getValue(); - assertThat(subItems.stream().map(Setting::getName)).containsExactly("subItem", "subItem", "subItem"); - assertThat(subItems.stream().map(Setting::getValue)).containsExactly("one", "two", "three"); + assertThat(subItems.stream().map(MavenConfiguration.Setting::getName)).containsExactly("subItem", "subItem", + "subItem"); + assertThat(subItems.stream().map(MavenConfiguration.Setting::getValue)).containsExactly("one", "two", "three"); } @Test @@ -132,8 +133,8 @@ class MavenPluginTests { .build(); assertThat(plugin.getExecutions()).hasSize(1); List settings = plugin.getExecutions().get(0).getConfiguration().getSettings(); - assertThat(settings.stream().map(Setting::getName)).containsExactly("enabled", "another"); - assertThat(settings.stream().map(Setting::getValue)).containsExactly("true", "test"); + assertThat(settings.stream().map(MavenConfiguration.Setting::getName)).containsExactly("enabled", "another"); + assertThat(settings.stream().map(MavenConfiguration.Setting::getValue)).containsExactly("true", "test"); } private MavenPlugin.Builder plugin(String groupId, String artifactId) { diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFileTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFileTests.java new file mode 100644 index 00000000..4545251f --- /dev/null +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFileTests.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class MavenProfileActivationFileTests { + + @Test + void profileActivationFileEmpty() { + MavenProfileActivationFile profileActivationFile = new MavenProfileActivationFile.Builder().build(); + assertThat(profileActivationFile.getExists()).isNull(); + assertThat(profileActivationFile.getMissing()).isNull(); + } + + @Test + void profileActivationFileWithFullData() { + MavenProfileActivationFile profileActivationFile = new MavenProfileActivationFile.Builder().exists("exists1") + .missing("missing1").build(); + + assertThat(profileActivationFile.getExists()).isEqualTo("exists1"); + assertThat(profileActivationFile.getMissing()).isEqualTo("missing1"); + } + +} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOSTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOSTests.java new file mode 100644 index 00000000..56a89360 --- /dev/null +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOSTests.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class MavenProfileActivationOSTests { + + @Test + void profileActivationOSEmpty() { + MavenProfileActivationOS profileActivationOS = new MavenProfileActivationOS.Builder().build(); + assertThat(profileActivationOS.getName()).isNull(); + assertThat(profileActivationOS.getFamily()).isNull(); + assertThat(profileActivationOS.getArch()).isNull(); + assertThat(profileActivationOS.getVersion()).isNull(); + } + + @Test + void profileActivationOSWithFullData() { + MavenProfileActivationOS profileActivationOS = new MavenProfileActivationOS.Builder().name("name1") + .family("family1").arch("arch1").version("version1").build(); + + assertThat(profileActivationOS.getName()).isEqualTo("name1"); + assertThat(profileActivationOS.getFamily()).isEqualTo("family1"); + assertThat(profileActivationOS.getArch()).isEqualTo("arch1"); + assertThat(profileActivationOS.getVersion()).isEqualTo("version1"); + } + +} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationPropertyTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationPropertyTests.java new file mode 100644 index 00000000..f823c4f8 --- /dev/null +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationPropertyTests.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class MavenProfileActivationPropertyTests { + + @Test + void profileActivationPropertyEmpty() { + MavenProfileActivationProperty profileActivationProperty = new MavenProfileActivationProperty.Builder().build(); + assertThat(profileActivationProperty.getName()).isNull(); + assertThat(profileActivationProperty.getValue()).isNull(); + } + + @Test + void profileActivationPropertyWithFullData() { + MavenProfileActivationProperty profileActivationProperty = new MavenProfileActivationProperty.Builder() + .name("name1").value("value1").build(); + + assertThat(profileActivationProperty.getName()).isEqualTo("name1"); + assertThat(profileActivationProperty.getValue()).isEqualTo("value1"); + } + +} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationTests.java new file mode 100644 index 00000000..9a48dfc5 --- /dev/null +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class MavenProfileActivationTests { + + @Test + void profileActivationEmpty() { + MavenProfileActivation profileActivation = new MavenProfileActivation.Builder().build(); + assertThat(profileActivation.getActiveByDefault()).isNull(); + assertThat(profileActivation.getJdk()).isNull(); + assertThat(profileActivation.getOs()).isNull(); + assertThat(profileActivation.getProperty()).isNull(); + assertThat(profileActivation.getFile()).isNull(); + } + + @Test + void profileActivationWithFullData() { + MavenProfileActivation profileActivation = new MavenProfileActivation.Builder().jdk("jdk1") + .activeByDefault(true).os((os) -> os.name("name1")).file((file) -> file.exists("yes")) + .property((property) -> property.name("name1")).build(); + + assertThat(profileActivation.getActiveByDefault()).isTrue(); + assertThat(profileActivation.getJdk()).isEqualTo("jdk1"); + assertThat(profileActivation.getOs()).isNotNull(); + assertThat(profileActivation.getOs().getName()).isEqualTo("name1"); + assertThat(profileActivation.getProperty()).isNotNull(); + assertThat(profileActivation.getProperty().getName()).isEqualTo("name1"); + assertThat(profileActivation.getFile()).isNotNull(); + assertThat(profileActivation.getFile().getExists()).isEqualTo("yes"); + } + +} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuildTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuildTests.java new file mode 100644 index 00000000..0fe89ec0 --- /dev/null +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuildTests.java @@ -0,0 +1,65 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +class MavenProfileBuildTests { + + @Test + void profileBuildEmpty() { + MavenProfileBuild profileBuild = new MavenProfileBuild.Builder().build(); + assertThat(profileBuild.getDefaultGoal()).isNull(); + assertThat(profileBuild.getDirectory()).isNull(); + assertThat(profileBuild.getFinalName()).isNull(); + assertThat(profileBuild.getFilters()).isNull(); + assertThat(profileBuild.getResources().isEmpty()).isTrue(); + assertThat(profileBuild.getTestResources().isEmpty()).isTrue(); + assertThat(profileBuild.getPluginManagement()).isNull(); + assertThat(profileBuild.getPlugins().isEmpty()).isTrue(); + } + + @Test + void profileBuildWithFullData() { + MavenProfileBuild profileBuild = new MavenProfileBuild.Builder().defaultGoal("goal1").directory("directory1") + .finalName("file1").filter("filter1").filter("filter2") + .resources((resources) -> resources.add("resource1")) + .testResources((testResources) -> testResources.add("testResources1")) + .pluginManagement( + (pluginManagement) -> pluginManagement.plugins((plugins) -> plugins.add("com.example", "demo"))) + .plugins((plugins) -> plugins.add("com.example1", "demo1")).build(); + + assertThat(profileBuild.getDefaultGoal()).isEqualTo("goal1"); + assertThat(profileBuild.getDirectory()).isEqualTo("directory1"); + assertThat(profileBuild.getFinalName()).isEqualTo("file1"); + assertThat(profileBuild.getFilters()).isEqualTo(Arrays.asList("filter1", "filter2")); + assertThat(profileBuild.getResources()).isNotNull(); + assertThat(profileBuild.getResources().has("resource1")).isTrue(); + assertThat(profileBuild.getTestResources()).isNotNull(); + assertThat(profileBuild.getTestResources().has("testResources1")).isTrue(); + assertThat(profileBuild.getPluginManagement()).isNotNull(); + assertThat(profileBuild.getPluginManagement().getPlugins()).isNotNull(); + assertThat(profileBuild.getPluginManagement().getPlugins().has("com.example", "demo")).isTrue(); + assertThat(profileBuild.getPlugins()).isNotNull(); + assertThat(profileBuild.getPlugins().has("com.example1", "demo1")).isTrue(); + } + +} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainerTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainerTests.java new file mode 100644 index 00000000..1ff5acfe --- /dev/null +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainerTests.java @@ -0,0 +1,168 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.spring.initializr.generator.buildsystem.BillOfMaterials; +import io.spring.initializr.generator.buildsystem.BuildItemResolver; +import io.spring.initializr.generator.buildsystem.Dependency; +import io.spring.initializr.generator.buildsystem.MavenRepository; + +@ExtendWith(MockitoExtension.class) +class MavenProfileContainerTests { + + @Mock + private BuildItemResolver buildItemResolver; + + @Test + void addProfile() { + MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); + profileContainer.add("profile1"); + assertThat(profileContainer.values()).hasOnlyOneElementSatisfying((profile) -> { + assertThat(profile.getId()).isEqualTo("profile1"); + assertThat(profile.getActivation()).isNull(); + assertThat(profile.getBuild()).isNull(); + assertThat(profile.getModules()).isNull(); + assertThat(profile.getRepositories().isEmpty()).isTrue(); + assertThat(profile.getPluginRepositories().isEmpty()).isTrue(); + assertThat(profile.getDependencies().isEmpty()).isTrue(); + assertThat(profile.getReporting()).isNull(); + assertThat(profile.getDependencyManagement().isEmpty()).isTrue(); + assertThat(profile.getDistributionManagement().isEmpty()).isTrue(); + assertThat(profile.getProperties()).isNull(); + }); + } + + @Test + void addProfileWithConsumer() { + MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); + profileContainer.add("profile1", (profile) -> profile + .activation((activation) -> activation.activeByDefault(true)) + .build((build) -> build.defaultGoal("goal1")).module("module1").module("module2") + .repositories((repositories) -> repositories.add("repository1", + MavenRepository.withIdAndUrl("repository1", "url").build())) + .pluginRepositories((pluginRepositories) -> pluginRepositories.add("pluginRepository1", + MavenRepository.withIdAndUrl("pluginRepository1", "url2").build())) + .dependencies((dependencies) -> dependencies.add("dependency1", + Dependency.withCoordinates("com.example", "demo").build())) + .reporting((reporting) -> reporting.outputDirectory("directory1")) + .dependencyManagement((dependencyManagement) -> dependencyManagement.add("dependencyManagement1", + BillOfMaterials.withCoordinates("com.example1", "demo1").build())) + .distributionManagement((distributionManagement) -> distributionManagement.downloadUrl("url")) + .properties((properties) -> properties.add("name1", "value1"))); + + assertThat(profileContainer.values()).hasOnlyOneElementSatisfying((profile) -> { + assertThat(profile.getId()).isEqualTo("profile1"); + assertThat(profile.getActivation()).isNotNull(); + assertThat(profile.getActivation().getActiveByDefault()).isTrue(); + assertThat(profile.getBuild()).isNotNull(); + assertThat(profile.getBuild().getDefaultGoal()).isEqualTo("goal1"); + assertThat(profile.getModules()).isNotNull(); + assertThat(profile.getModules()).isEqualTo(Arrays.asList("module1", "module2")); + assertThat(profile.getRepositories()).isNotNull(); + assertThat(profile.getRepositories().has("repository1")).isTrue(); + assertThat(profile.getPluginRepositories()).isNotNull(); + assertThat(profile.getPluginRepositories().has("pluginRepository1")).isTrue(); + assertThat(profile.getDependencies()).isNotNull(); + assertThat(profile.getDependencies().has("dependency1")).isTrue(); + assertThat(profile.getReporting()).isNotNull(); + assertThat(profile.getReporting().getOutputDirectory()).isEqualTo("directory1"); + assertThat(profile.getDependencyManagement()).isNotNull(); + assertThat(profile.getDependencyManagement().has("dependencyManagement1")).isTrue(); + assertThat(profile.getProperties()).isNotNull(); + assertThat(profile.getProperties().getSettings()).hasOnlyOneElementSatisfying((settings) -> { + assertThat(settings.getName()).isEqualTo("name1"); + assertThat(settings.getValue()).isEqualTo("value1"); + }); + }); + } + + @Test + void addProfileSeveralTimeReuseConfiguration() { + MavenProfileContainer profileContainer = new MavenProfileContainer(buildItemResolver); + profileContainer.add("profile1", + (profile) -> profile.activation((activation) -> activation.activeByDefault(true))); + profileContainer.add("profile1", + (profile) -> profile.activation((activation) -> activation.activeByDefault(false))); + assertThat(profileContainer.values()).hasOnlyOneElementSatisfying((profile) -> { + assertThat(profile.getId()).isEqualTo("profile1"); + assertThat(profile.getActivation()).isNotNull(); + assertThat(profile.getActivation().getActiveByDefault()).isFalse(); + assertThat(profile.getBuild()).isNull(); + assertThat(profile.getModules()).isNull(); + assertThat(profile.getRepositories().isEmpty()).isTrue(); + assertThat(profile.getPluginRepositories().isEmpty()).isTrue(); + assertThat(profile.getDependencies().isEmpty()).isTrue(); + assertThat(profile.getReporting()).isNull(); + assertThat(profile.getDependencyManagement().isEmpty()).isTrue(); + assertThat(profile.getDistributionManagement().isEmpty()).isTrue(); + assertThat(profile.getProperties()).isNull(); + }); + } + + @Test + void isEmptyWithEmptyContainer() { + MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); + assertThat(profileContainer.isEmpty()).isTrue(); + } + + @Test + void isEmptyWithRegisteredProfile() { + MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); + profileContainer.add("profile1"); + assertThat(profileContainer.isEmpty()).isFalse(); + } + + @Test + void hasProfileWithMatchingProfile() { + MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); + profileContainer.add("profile1"); + assertThat(profileContainer.has("profile1")).isTrue(); + } + + @Test + void hasProfileWithNonMatchingProfile() { + MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); + profileContainer.add("profile1"); + assertThat(profileContainer.has("profile2")).isFalse(); + } + + @Test + void removeWithMatchingProfile() { + MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); + profileContainer.add("profile1"); + assertThat(profileContainer.remove("profile1")).isTrue(); + assertThat(profileContainer.isEmpty()).isTrue(); + } + + @Test + void removeWithNonMatchingProfile() { + MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); + profileContainer.add("profile1"); + assertThat(profileContainer.remove("profile2")).isFalse(); + assertThat(profileContainer.isEmpty()).isFalse(); + } + +} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileTests.java new file mode 100644 index 00000000..30fb82e2 --- /dev/null +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileTests.java @@ -0,0 +1,96 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import java.util.Arrays; + +import io.spring.initializr.generator.buildsystem.BillOfMaterials; +import io.spring.initializr.generator.buildsystem.BuildItemResolver; +import io.spring.initializr.generator.buildsystem.Dependency; +import io.spring.initializr.generator.buildsystem.MavenRepository; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(MockitoExtension.class) +class MavenProfileTests { + + @Mock + private BuildItemResolver buildItemResolver; + + @Test + void profileEmpty() { + MavenProfile profile = new MavenProfile.Builder("profile1", this.buildItemResolver).build(); + assertThat(profile.getId()).isEqualTo("profile1"); + assertThat(profile.getActivation()).isNull(); + assertThat(profile.getBuild()).isNull(); + assertThat(profile.getModules()).isNull(); + assertThat(profile.getRepositories().isEmpty()).isTrue(); + assertThat(profile.getPluginRepositories().isEmpty()).isTrue(); + assertThat(profile.getDependencies().isEmpty()).isTrue(); + assertThat(profile.getReporting()).isNull(); + assertThat(profile.getDependencyManagement().isEmpty()).isTrue(); + assertThat(profile.getDistributionManagement().isEmpty()).isTrue(); + assertThat(profile.getProperties()).isNull(); + } + + @Test + void profileWithFullData() { + MavenProfile profile = new MavenProfile.Builder("profile1", this.buildItemResolver) + .activation((activation) -> activation.activeByDefault(true)) + .build((build) -> build.defaultGoal("goal1")).module("module1").module("module2") + .repositories((repositories) -> repositories.add("repository1", + MavenRepository.withIdAndUrl("repository1", "url").build())) + .pluginRepositories((pluginRepositories) -> pluginRepositories.add("pluginRepository1", + MavenRepository.withIdAndUrl("pluginRepository1", "url2").build())) + .dependencies((dependencies) -> dependencies.add("dependency1", + Dependency.withCoordinates("com.example", "demo").build())) + .reporting((reporting) -> reporting.outputDirectory("directory1")) + .dependencyManagement((dependencyManagement) -> dependencyManagement.add("dependencyManagement1", + BillOfMaterials.withCoordinates("com.example1", "demo1").build())) + .distributionManagement((distributionManagement) -> distributionManagement.downloadUrl("url")) + .properties((properties) -> properties.add("name1", "value1")).build(); + + assertThat(profile.getId()).isEqualTo("profile1"); + assertThat(profile.getActivation()).isNotNull(); + assertThat(profile.getActivation().getActiveByDefault()).isTrue(); + assertThat(profile.getBuild()).isNotNull(); + assertThat(profile.getBuild().getDefaultGoal()).isEqualTo("goal1"); + assertThat(profile.getModules()).isNotNull(); + assertThat(profile.getModules()).isEqualTo(Arrays.asList("module1", "module2")); + assertThat(profile.getRepositories()).isNotNull(); + assertThat(profile.getRepositories().has("repository1")).isTrue(); + assertThat(profile.getPluginRepositories()).isNotNull(); + assertThat(profile.getPluginRepositories().has("pluginRepository1")).isTrue(); + assertThat(profile.getDependencies()).isNotNull(); + assertThat(profile.getDependencies().has("dependency1")).isTrue(); + assertThat(profile.getReporting()).isNotNull(); + assertThat(profile.getReporting().getOutputDirectory()).isEqualTo("directory1"); + assertThat(profile.getDependencyManagement()).isNotNull(); + assertThat(profile.getDependencyManagement().has("dependencyManagement1")).isTrue(); + assertThat(profile.getProperties()).isNotNull(); + assertThat(profile.getProperties().getSettings()).hasOnlyOneElementSatisfying((settings) -> { + assertThat(settings.getName()).isEqualTo("name1"); + assertThat(settings.getValue()).isEqualTo("value1"); + }); + } + +} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainerTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainerTests.java new file mode 100644 index 00000000..ba38c3e4 --- /dev/null +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainerTests.java @@ -0,0 +1,119 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class MavenReportPluginContainerTests { + + @Test + void addReportPlugin() { + MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); + reportPluginContainer.add("com.example", "demo"); + assertThat(reportPluginContainer.values()).hasOnlyOneElementSatisfying((reportPlugin) -> { + assertThat(reportPlugin.getGroupId()).isEqualTo("com.example"); + assertThat(reportPlugin.getArtifactId()).isEqualTo("demo"); + assertThat(reportPlugin.getConfiguration()).isNull(); + assertThat(reportPlugin.getInherited()).isNull(); + assertThat(reportPlugin.getVersion()).isNull(); + assertThat(reportPlugin.getReportSets().isEmpty()).isTrue(); + }); + } + + @Test + void addReportPluginWithConsumer() { + MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); + reportPluginContainer.add("com.example", "demo", + (reportPlugin) -> reportPlugin.configuration((conf) -> conf.add("property1", "value1")) + .inherited("inherited1").version("version1") + .reportSets((reportSets) -> reportSets.add("reportSet1").add("reportSet2"))); + + assertThat(reportPluginContainer.values()).hasOnlyOneElementSatisfying((reportPlugin) -> { + assertThat(reportPlugin.getGroupId()).isEqualTo("com.example"); + assertThat(reportPlugin.getArtifactId()).isEqualTo("demo"); + assertThat(reportPlugin.getConfiguration().getSettings()).hasOnlyOneElementSatisfying((settings) -> { + assertThat(settings.getName()).isEqualTo("property1"); + assertThat(settings.getValue()).isEqualTo("value1"); + }); + assertThat(reportPlugin.getInherited()).isEqualTo("inherited1"); + assertThat(reportPlugin.getVersion()).isEqualTo("version1"); + assertThat(reportPlugin.getReportSets().has("reportSet1")).isTrue(); + assertThat(reportPlugin.getReportSets().has("reportSet2")).isTrue(); + }); + } + + @Test + void addReportPluginSeveralTimeReuseConfiguration() { + MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); + reportPluginContainer.add("com.example", "demo", (reportPlugin) -> reportPlugin.inherited("inherited1")); + reportPluginContainer.add("com.example", "demo", (reportPlugin) -> reportPlugin.inherited("inherited2")); + assertThat(reportPluginContainer.values()).hasOnlyOneElementSatisfying((reportPlugin) -> { + assertThat(reportPlugin.getGroupId()).isEqualTo("com.example"); + assertThat(reportPlugin.getArtifactId()).isEqualTo("demo"); + assertThat(reportPlugin.getConfiguration()).isNull(); + assertThat(reportPlugin.getInherited()).isEqualTo("inherited2"); + assertThat(reportPlugin.getVersion()).isNull(); + assertThat(reportPlugin.getReportSets().isEmpty()).isTrue(); + }); + } + + @Test + void isEmptyWithEmptyContainer() { + MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); + assertThat(reportPluginContainer.isEmpty()).isTrue(); + } + + @Test + void isEmptyWithRegisteredReportPlugin() { + MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); + reportPluginContainer.add("com.example", "demo"); + assertThat(reportPluginContainer.isEmpty()).isFalse(); + } + + @Test + void hasReportPluginWithMatchingReportPlugin() { + MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); + reportPluginContainer.add("com.example", "demo"); + assertThat(reportPluginContainer.has("com.example", "demo")).isTrue(); + } + + @Test + void hasReportPluginWithNonMatchingReportPlugin() { + MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); + reportPluginContainer.add("com.example", "demo"); + assertThat(reportPluginContainer.has("com.example", "demo1")).isFalse(); + } + + @Test + void removeWithMatchingReportPlugin() { + MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); + reportPluginContainer.add("com.example", "demo"); + assertThat(reportPluginContainer.remove("com.example", "demo")).isTrue(); + assertThat(reportPluginContainer.isEmpty()).isTrue(); + } + + @Test + void removeWithNonMatchingReportPlugin() { + MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); + reportPluginContainer.add("com.example", "demo"); + assertThat(reportPluginContainer.remove("com.example", "demo2")).isFalse(); + assertThat(reportPluginContainer.isEmpty()).isFalse(); + } + +} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginTests.java new file mode 100644 index 00000000..6882c556 --- /dev/null +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginTests.java @@ -0,0 +1,55 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class MavenReportPluginTests { + + @Test + void reportPluginWithGroupIdArtifactIdOnly() { + MavenReportPlugin reportPlugin = new MavenReportPlugin.Builder("com.example", "demo").build(); + + assertThat(reportPlugin.getGroupId()).isEqualTo("com.example"); + assertThat(reportPlugin.getArtifactId()).isEqualTo("demo"); + assertThat(reportPlugin.getConfiguration()).isNull(); + assertThat(reportPlugin.getInherited()).isNull(); + assertThat(reportPlugin.getVersion()).isNull(); + assertThat(reportPlugin.getReportSets().isEmpty()).isTrue(); + } + + @Test + void reportPluginWithFullData() { + MavenReportPlugin reportPlugin = new MavenReportPlugin.Builder("com.example", "demo") + .configuration((conf) -> conf.add("property1", "value1")).inherited("inherited1").version("version1") + .reportSets((reportSets) -> reportSets.add("reportSet1").add("reportSet2")).build(); + + assertThat(reportPlugin.getGroupId()).isEqualTo("com.example"); + assertThat(reportPlugin.getArtifactId()).isEqualTo("demo"); + assertThat(reportPlugin.getConfiguration().getSettings()).hasOnlyOneElementSatisfying((settings) -> { + assertThat(settings.getName()).isEqualTo("property1"); + assertThat(settings.getValue()).isEqualTo("value1"); + }); + assertThat(reportPlugin.getInherited()).isEqualTo("inherited1"); + assertThat(reportPlugin.getVersion()).isEqualTo("version1"); + assertThat(reportPlugin.getReportSets().has("reportSet1")).isTrue(); + assertThat(reportPlugin.getReportSets().has("reportSet2")).isTrue(); + } + +} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainerTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainerTests.java new file mode 100644 index 00000000..b9028c0c --- /dev/null +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainerTests.java @@ -0,0 +1,112 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +class MavenReportSetContainerTests { + + @Test + void addReportSet() { + MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); + reportSetContainer.add("reportSet1"); + assertThat(reportSetContainer.values()).hasOnlyOneElementSatisfying((reportSet) -> { + assertThat(reportSet.getId()).isEqualTo("reportSet1"); + assertThat(reportSet.getInherited()).isNull(); + assertThat(reportSet.getReports()).isNull(); + assertThat(reportSet.getConfiguration()).isNull(); + }); + } + + @Test + void addReportSetWithConsumer() { + MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); + reportSetContainer.add("reportSet1", (reportSet) -> reportSet.inherited("inherited1").report("report1") + .report("report2").configuration((conf) -> conf.add("property1", "value1"))); + + assertThat(reportSetContainer.values()).hasOnlyOneElementSatisfying((reportSet) -> { + assertThat(reportSet.getId()).isEqualTo("reportSet1"); + assertThat(reportSet.getConfiguration().getSettings()).hasOnlyOneElementSatisfying((settings) -> { + assertThat(settings.getName()).isEqualTo("property1"); + assertThat(settings.getValue()).isEqualTo("value1"); + }); + assertThat(reportSet.getInherited()).isEqualTo("inherited1"); + assertThat(reportSet.getReports()).isEqualTo(Arrays.asList("report1", "report2")); + }); + } + + @Test + void addReportSetSeveralTimeReuseConfiguration() { + MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); + reportSetContainer.add("reportSet1", (reportSet) -> reportSet.inherited("inherited1")); + reportSetContainer.add("reportSet1", (reportSet) -> reportSet.inherited("inherited2")); + assertThat(reportSetContainer.values()).hasOnlyOneElementSatisfying((reportSet) -> { + assertThat(reportSet.getId()).isEqualTo("reportSet1"); + assertThat(reportSet.getInherited()).isEqualTo("inherited2"); + assertThat(reportSet.getReports()).isNull(); + assertThat(reportSet.getConfiguration()).isNull(); + }); + } + + @Test + void isEmptyWithEmptyContainer() { + MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); + assertThat(reportSetContainer.isEmpty()).isTrue(); + } + + @Test + void isEmptyWithRegisteredReportSet() { + MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); + reportSetContainer.add("reportSet1"); + assertThat(reportSetContainer.isEmpty()).isFalse(); + } + + @Test + void hasReportSetWithMatchingReportSet() { + MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); + reportSetContainer.add("reportSet1"); + assertThat(reportSetContainer.has("reportSet1")).isTrue(); + } + + @Test + void hasReportSetWithNonMatchingReportSet() { + MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); + reportSetContainer.add("reportSet1"); + assertThat(reportSetContainer.has("reportSet2")).isFalse(); + } + + @Test + void removeWithMatchingReportSet() { + MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); + reportSetContainer.add("reportSet1"); + assertThat(reportSetContainer.remove("reportSet1")).isTrue(); + assertThat(reportSetContainer.isEmpty()).isTrue(); + } + + @Test + void removeWithNonMatchingReportSet() { + MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); + reportSetContainer.add("reportSet1"); + assertThat(reportSetContainer.remove("reportSet2")).isFalse(); + assertThat(reportSetContainer.isEmpty()).isFalse(); + } + +} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetTests.java new file mode 100644 index 00000000..5be03f7b --- /dev/null +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; + +class MavenReportSetTests { + + @Test + void reportSetWithIdOnly() { + MavenReportSet reportSet = new MavenReportSet.Builder("id").build(); + assertThat(reportSet.getId()).isEqualTo("id"); + assertThat(reportSet.getConfiguration()).isNull(); + assertThat(reportSet.getInherited()).isNull(); + assertThat(reportSet.getReports()).isNull(); + } + + @Test + void reportSetWithFullData() { + MavenReportSet reportSet = new MavenReportSet.Builder("id") + .configuration((conf) -> conf.add("property1", "value1")).inherited("inherited1").report("report1") + .report("report2").build(); + + assertThat(reportSet.getId()).isEqualTo("id"); + assertThat(reportSet.getConfiguration().getSettings()).hasOnlyOneElementSatisfying((settings) -> { + assertThat(settings.getName()).isEqualTo("property1"); + assertThat(settings.getValue()).isEqualTo("value1"); + }); + assertThat(reportSet.getInherited()).isEqualTo("inherited1"); + assertThat(reportSet.getReports()).isEqualTo(Arrays.asList("report1", "report2")); + } + +} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportingTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportingTests.java new file mode 100644 index 00000000..a5a24b17 --- /dev/null +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportingTests.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.generator.buildsystem.maven; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class MavenReportingTests { + + @Test + void reportingEmpty() { + MavenReporting reporting = new MavenReporting.Builder().build(); + assertThat(reporting.getOutputDirectory()).isNull(); + assertThat(reporting.isExcludeDefaults()).isNull(); + assertThat(reporting.getReportPlugins().isEmpty()).isTrue(); + } + + @Test + void reportingWithFullData() { + MavenReporting reporting = new MavenReporting.Builder().excludeDefaults(true).outputDirectory("output") + .reportPlugins((reportPlugins) -> reportPlugins.add("com.example", "demo").add("com.example", "demo2")) + .build(); + + assertThat(reporting.isExcludeDefaults()).isTrue(); + assertThat(reporting.getOutputDirectory()).isEqualTo("output"); + assertThat(reporting.getReportPlugins().has("com.example", "demo")).isTrue(); + assertThat(reporting.getReportPlugins().has("com.example", "demo2")).isTrue(); + } + +} From d22f820dd45204f9746a97edc1112d0c72cec1e6 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 19 Nov 2020 16:56:48 +0100 Subject: [PATCH 2/2] Polish "Add support for Maven profiles" See gh-1057 --- .../GroovyMavenBuildCustomizerTests.java | 4 +- .../KotlinJpaMavenBuildCustomizerTests.java | 3 +- .../KotlinMavenBuildCustomizerTests.java | 8 +- .../KotlinMavenFullBuildCustomizerTests.java | 6 +- .../generator/buildsystem/BomContainer.java | 7 +- .../generator/buildsystem/Build.java | 11 +- .../buildsystem/BuildItemResolver.java | 5 + .../buildsystem/DependencyContainer.java | 7 +- .../buildsystem/MavenRepositoryContainer.java | 7 +- .../buildsystem/maven/MavenBuild.java | 10 +- .../buildsystem/maven/MavenBuildWriter.java | 203 +++----- .../buildsystem/maven/MavenConfiguration.java | 146 ------ .../buildsystem/maven/MavenPlugin.java | 143 +++++- .../maven/MavenPluginManagement.java | 51 -- .../buildsystem/maven/MavenProfile.java | 327 ++++++------ .../maven/MavenProfileActivation.java | 269 ++++++++-- .../maven/MavenProfileActivationFile.java | 64 --- .../maven/MavenProfileActivationOS.java | 92 ---- .../maven/MavenProfileActivationProperty.java | 64 --- .../buildsystem/maven/MavenProfileBuild.java | 163 ------ .../maven/MavenProfileContainer.java | 87 ++-- .../buildsystem/maven/MavenReportPlugin.java | 119 ----- .../maven/MavenReportPluginContainer.java | 65 --- .../buildsystem/maven/MavenReportSet.java | 100 ---- .../maven/MavenReportSetContainer.java | 66 --- .../buildsystem/maven/MavenReporting.java | 80 --- .../buildsystem/maven/MavenBuildTests.java | 53 +- .../maven/MavenBuildWriterTests.java | 466 +++--------------- .../buildsystem/maven/MavenPluginTests.java | 31 +- .../MavenProfileActivationFileTests.java | 41 -- .../maven/MavenProfileActivationOSTests.java | 45 -- .../MavenProfileActivationPropertyTests.java | 41 -- .../maven/MavenProfileActivationTests.java | 103 +++- .../maven/MavenProfileBuildTests.java | 65 --- .../maven/MavenProfileContainerTests.java | 160 ++---- .../buildsystem/maven/MavenProfileTests.java | 119 +++-- .../MavenReportPluginContainerTests.java | 119 ----- .../maven/MavenReportPluginTests.java | 55 --- .../maven/MavenReportSetContainerTests.java | 112 ----- .../maven/MavenReportSetTests.java | 51 -- .../maven/MavenReportingTests.java | 45 -- 41 files changed, 991 insertions(+), 2622 deletions(-) delete mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenConfiguration.java delete mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginManagement.java delete mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFile.java delete mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOS.java delete mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationProperty.java delete mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuild.java delete mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPlugin.java delete mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainer.java delete mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSet.java delete mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainer.java delete mode 100644 initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReporting.java delete mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFileTests.java delete mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOSTests.java delete mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationPropertyTests.java delete mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuildTests.java delete mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainerTests.java delete mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginTests.java delete mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainerTests.java delete mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetTests.java delete mode 100644 initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportingTests.java diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/groovy/GroovyMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/groovy/GroovyMavenBuildCustomizerTests.java index ca9ba9e9..d9f8a37e 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/groovy/GroovyMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/groovy/GroovyMavenBuildCustomizerTests.java @@ -17,7 +17,7 @@ package io.spring.initializr.generator.spring.code.groovy; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; -import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration; +import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuration; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Execution; import org.junit.jupiter.api.Test; @@ -38,7 +38,7 @@ class GroovyMavenBuildCustomizerTests { assertThat(groovyPlugin.getGroupId()).isEqualTo("org.codehaus.gmavenplus"); assertThat(groovyPlugin.getArtifactId()).isEqualTo("gmavenplus-plugin"); assertThat(groovyPlugin.getVersion()).isEqualTo("1.11.0"); - MavenConfiguration configuration = groovyPlugin.getConfiguration(); + Configuration configuration = groovyPlugin.getConfiguration(); assertThat(configuration).isNull(); assertThat(groovyPlugin.getExecutions()).hasSize(1); Execution execution = groovyPlugin.getExecutions().get(0); diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java index d54089b9..d2649df2 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java @@ -18,7 +18,6 @@ package io.spring.initializr.generator.spring.code.kotlin; import java.util.Collections; -import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin; import io.spring.initializr.generator.test.InitializrMetadataTestBuilder; @@ -46,7 +45,7 @@ class KotlinJpaMavenBuildCustomizerTests { assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { assertThat(plugin.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(plugin.getArtifactId()).isEqualTo("kotlin-maven-plugin"); - MavenConfiguration.Setting settings = plugin.getConfiguration().getSettings().get(0); + MavenPlugin.Setting settings = plugin.getConfiguration().getSettings().get(0); assertThat(settings.getValue()).asList().element(0).hasFieldOrPropertyWithValue("name", "plugin") .hasFieldOrPropertyWithValue("value", "jpa"); assertThat(plugin.getDependencies()).hasSize(1); diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java index 8a929a30..acd3a94f 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java @@ -20,9 +20,9 @@ import java.util.Arrays; import java.util.List; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; -import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration; +import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuration; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Dependency; -import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration.Setting; +import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting; import io.spring.initializr.generator.version.VersionProperty; import org.junit.jupiter.api.Test; @@ -60,7 +60,7 @@ class KotlinMavenBuildCustomizerTests { assertThat(kotlinPlugin.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(kotlinPlugin.getArtifactId()).isEqualTo("kotlin-maven-plugin"); assertThat(kotlinPlugin.getVersion()).isNull(); - MavenConfiguration configuration = kotlinPlugin.getConfiguration(); + Configuration configuration = kotlinPlugin.getConfiguration(); assertThat(configuration).isNotNull(); assertThat(configuration.getSettings()).hasSize(2); Setting args = configuration.getSettings().get(0); @@ -87,7 +87,7 @@ class KotlinMavenBuildCustomizerTests { MavenBuild build = new MavenBuild(); new KotlinMavenBuildCustomizer(new TestKotlinProjectSettings()).customize(build); assertThat(build.plugins().values()).singleElement().satisfies((kotlinPlugin) -> { - MavenConfiguration configuration = kotlinPlugin.getConfiguration(); + Configuration configuration = kotlinPlugin.getConfiguration(); Setting args = configuration.getSettings().get(0); assertThat(args.getName()).isEqualTo("args"); assertThat(args.getValue()).asList().hasSize(2); diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizerTests.java index 64124e9e..2da168d0 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizerTests.java @@ -17,10 +17,10 @@ package io.spring.initializr.generator.spring.code.kotlin; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; -import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration; +import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuration; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Dependency; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Execution; -import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration.Setting; +import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting; import io.spring.initializr.generator.version.VersionProperty; import org.junit.jupiter.api.Test; @@ -58,7 +58,7 @@ class KotlinMavenFullBuildCustomizerTests { assertThat(kotlinPlugin.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(kotlinPlugin.getArtifactId()).isEqualTo("kotlin-maven-plugin"); assertThat(kotlinPlugin.getVersion()).isEqualTo("${kotlin.version}"); - MavenConfiguration configuration = kotlinPlugin.getConfiguration(); + Configuration configuration = kotlinPlugin.getConfiguration(); assertThat(configuration).isNotNull(); assertThat(configuration.getSettings()).hasSize(3); Setting args = configuration.getSettings().get(0); diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/BomContainer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/BomContainer.java index d172b92d..e43ee95a 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/BomContainer.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/BomContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,11 @@ import java.util.function.Function; */ public class BomContainer extends BuildItemContainer { + /** + * Create an instance with the specified {@code itemResolver}. + * @param itemResolver the function that returns a {@link BillOfMaterials} based on an + * identifier. + */ public BomContainer(Function itemResolver) { super(new LinkedHashMap<>(), itemResolver); } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/Build.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/Build.java index eb702419..789398cc 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/Build.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/Build.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,10 +34,8 @@ public abstract class Build { private final MavenRepositoryContainer pluginRepositories; - private final BuildItemResolver resolver; - protected Build(BuildItemResolver buildItemResolver) { - this.resolver = determineBuildItemResolver(buildItemResolver); + BuildItemResolver resolver = determineBuildItemResolver(buildItemResolver); this.properties = new PropertyContainer(); this.dependencies = new DependencyContainer(resolver::resolveDependency); this.boms = new BomContainer(resolver::resolveBom); @@ -45,7 +43,7 @@ public abstract class Build { this.pluginRepositories = new MavenRepositoryContainer(resolver::resolveRepository); } - private static BuildItemResolver determineBuildItemResolver(BuildItemResolver buildItemResolver) { + protected static BuildItemResolver determineBuildItemResolver(BuildItemResolver buildItemResolver) { if (buildItemResolver != null) { return buildItemResolver; } @@ -110,7 +108,4 @@ public abstract class Build { return this.pluginRepositories; } - public BuildItemResolver getResolver() { - return resolver; - } } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/BuildItemResolver.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/BuildItemResolver.java index 23b8a391..d631171a 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/BuildItemResolver.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/BuildItemResolver.java @@ -23,6 +23,11 @@ package io.spring.initializr.generator.buildsystem; */ public interface BuildItemResolver { + /** + * A default {@link BuildItemResolver} that bypass resolution. + */ + SimpleBuildItemResolver NO_OP = new SimpleBuildItemResolver((id) -> null, (id) -> null, (id) -> null); + /** * Resolve the {@link Dependency} with the specified {@code id}. * @param id the id of the dependency diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/DependencyContainer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/DependencyContainer.java index e538331c..a897b6c8 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/DependencyContainer.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/DependencyContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,11 @@ import java.util.function.Function; */ public class DependencyContainer extends BuildItemContainer { + /** + * Create an instance with the specified {@code itemResolver}. + * @param itemResolver the function that returns a {@link Dependency} based on an + * identifier. + */ public DependencyContainer(Function itemResolver) { super(new LinkedHashMap<>(), itemResolver); } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/MavenRepositoryContainer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/MavenRepositoryContainer.java index 97a74fba..5c82ca7e 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/MavenRepositoryContainer.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/MavenRepositoryContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,11 @@ import java.util.function.Function; */ public class MavenRepositoryContainer extends BuildItemContainer { + /** + * Create an instance with the specified {@code itemResolver}. + * @param itemResolver the function that returns a {@link MavenRepository} based on an + * identifier. + */ public MavenRepositoryContainer(Function itemResolver) { super(new LinkedHashMap<>(), itemResolver); } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuild.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuild.java index 261b474d..643fe28f 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuild.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuild.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,8 +43,7 @@ public class MavenBuild extends Build { public MavenBuild(BuildItemResolver buildItemResolver) { super(buildItemResolver); - - this.profiles = new MavenProfileContainer(super.getResolver()); + this.profiles = new MavenProfileContainer(determineBuildItemResolver(buildItemResolver)); } public MavenBuild() { @@ -106,6 +105,11 @@ public class MavenBuild extends Build { return this.plugins; } + /** + * Return the {@linkplain MavenProfileContainer profile container} to use to configure + * profiles. + * @return the {@link MavenProfileContainer} + */ public MavenProfileContainer profiles() { return this.profiles; } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriter.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriter.java index a58b4816..3967d51e 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriter.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriter.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -40,8 +41,9 @@ import io.spring.initializr.generator.buildsystem.PropertyContainer; import io.spring.initializr.generator.buildsystem.maven.MavenDistributionManagement.DeploymentRepository; import io.spring.initializr.generator.buildsystem.maven.MavenDistributionManagement.Relocation; import io.spring.initializr.generator.buildsystem.maven.MavenDistributionManagement.Site; +import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuration; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Execution; -import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration.Setting; +import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting; import io.spring.initializr.generator.io.IndentingWriter; import io.spring.initializr.generator.version.VersionProperty; import io.spring.initializr.generator.version.VersionReference; @@ -79,9 +81,9 @@ public class MavenBuildWriter { writeDependencies(writer, build.dependencies()); writeDependencyManagement(writer, build.boms()); writeBuild(writer, build); - writeProfiles(writer, build); writeRepositories(writer, build.repositories(), build.pluginRepositories()); writeDistributionManagement(writer, build.getDistributionManagement()); + writeProfiles(writer, build); }); } @@ -282,15 +284,15 @@ public class MavenBuildWriter { || dependency.getScope() == DependencyScope.COMPILE_ONLY); } - private void writeDependencyManagement(IndentingWriter writer, BomContainer bomsContainer) { - if (bomsContainer.isEmpty()) { + private void writeDependencyManagement(IndentingWriter writer, BomContainer boms) { + if (boms.isEmpty()) { return; } - List boms = bomsContainer.items().sorted(Comparator.comparing(BillOfMaterials::getOrder)) - .collect(Collectors.toList()); writer.println(); writeElement(writer, "dependencyManagement", - () -> writeCollectionElement(writer, "dependencies", boms, this::writeBom)); + () -> writeCollectionElement(writer, "dependencies", boms.items() + .sorted(Comparator.comparing(BillOfMaterials::getOrder)).collect(Collectors.toList()), + this::writeBom)); } private void writeBom(IndentingWriter writer, BillOfMaterials bom) { @@ -326,7 +328,6 @@ public class MavenBuildWriter { writeSingleElement(writer, "testSourceDirectory", settings.getTestSourceDirectory()); writeResources(writer, build.resources(), build.testResources()); writeCollectionElement(writer, "plugins", build.plugins().values(), this::writePlugin); - }); } @@ -372,23 +373,23 @@ public class MavenBuildWriter { if (plugin.isExtensions()) { writeSingleElement(writer, "extensions", "true"); } - writeConfiguration(writer, "configuration", plugin.getConfiguration()); + writePluginConfiguration(writer, plugin.getConfiguration()); writeCollectionElement(writer, "executions", plugin.getExecutions(), this::writePluginExecution); writeCollectionElement(writer, "dependencies", plugin.getDependencies(), this::writePluginDependency); }); } - private void writeConfiguration(IndentingWriter writer, String tag, MavenConfiguration configuration) { + private void writePluginConfiguration(IndentingWriter writer, Configuration configuration) { if (configuration == null || configuration.getSettings().isEmpty()) { return; } - writeCollectionElement(writer, tag, configuration.getSettings(), this::writeSetting); + writeCollectionElement(writer, "configuration", configuration.getSettings(), this::writeSetting); } @SuppressWarnings("unchecked") private void writeSetting(IndentingWriter writer, Setting setting) { if (setting.getValue() instanceof String) { - writeSingleElement(writer, setting.getName(), (String) setting.getValue()); + writeSingleElement(writer, setting.getName(), setting.getValue()); } else if (setting.getValue() instanceof List) { writeCollectionElement(writer, setting.getName(), (List) setting.getValue(), this::writeSetting); @@ -403,7 +404,7 @@ public class MavenBuildWriter { if (!goals.isEmpty()) { writeElement(writer, "goals", () -> goals.forEach((goal) -> writeSingleElement(writer, "goal", goal))); } - writeConfiguration(writer, "configuration", execution.getConfiguration()); + writePluginConfiguration(writer, execution.getConfiguration()); }); } @@ -495,153 +496,69 @@ public class MavenBuildWriter { } private void writeProfiles(IndentingWriter writer, MavenBuild build) { - MavenProfileContainer profilesContainer = build.profiles(); - if (profilesContainer.isEmpty()) { + MavenProfileContainer profiles = build.profiles(); + if (profiles.isEmpty()) { return; } - Stream profiles = profilesContainer.values(); writer.println(); - writeElement(writer, "profiles", () -> { - profiles.forEach((profile) -> { - writeElement(writer, "profile", () -> { - writeSingleElement(writer, "id", profile.getId()); - writeProfileActivation(writer, profile.getActivation()); - writeProfileBuild(writer, profile.getBuild()); - writeCollectionElement(writer, "modules", profile.getModules(), (IndentingWriter writerInner, - String module) -> writeSingleElement(writerInner, "module", module)); - writeRepositories(writer, profile.getRepositories(), profile.getPluginRepositories()); - writeDependencies(writer, profile.getDependencies()); - writeReporting(writer, profile.getReporting()); - writeDependencyManagement(writer, profile.getDependencyManagement()); - writeDistributionManagement(writer, profile.getDistributionManagement()); - writeConfiguration(writer, "properties", profile.getProperties()); - }); - }); + writeElement(writer, "profiles", () -> profiles.values().forEach((profile) -> writeProfile(writer, profile))); + } + + private void writeProfile(IndentingWriter writer, MavenProfile profile) { + writeElement(writer, "profile", () -> { + writeSingleElement(writer, "id", profile.getId()); + writeProfileActivation(writer, profile.getActivation()); + writeProperties(writer, profile.properties()); + writeDependencies(writer, profile.dependencies()); + writeDependencyManagement(writer, profile.boms()); + writeProfileBuild(writer, profile); + writeRepositories(writer, profile.repositories(), profile.pluginRepositories()); + writeDistributionManagement(writer, profile.getDistributionManagement()); }); } private void writeProfileActivation(IndentingWriter writer, MavenProfileActivation activation) { - if (activation == null) { + if (activation.isEmpty()) { return; } - - writer.println(); writeElement(writer, "activation", () -> { - writeSingleElement(writer, "activeByDefault", String.valueOf(activation.getActiveByDefault())); + writeSingleElement(writer, "activeByDefault", activation.getActiveByDefault()); writeSingleElement(writer, "jdk", activation.getJdk()); - - MavenProfileActivationOS os = activation.getOs(); - if (os != null) { - writeElement(writer, "os", () -> { - writeSingleElement(writer, "name", os.getName()); - writeSingleElement(writer, "arch", os.getArch()); - writeSingleElement(writer, "family", os.getFamily()); - writeSingleElement(writer, "version", os.getVersion()); - }); - } - - MavenProfileActivationProperty property = activation.getProperty(); - if (property != null) { - writeElement(writer, "property", () -> { - writeSingleElement(writer, "name", property.getName()); - writeSingleElement(writer, "value", property.getValue()); - }); - } - - MavenProfileActivationFile file = activation.getFile(); - if (file != null) { - writeElement(writer, "file", () -> { - writeSingleElement(writer, "exists", file.getExists()); - writeSingleElement(writer, "missing", file.getMissing()); - }); - } + ifNotNull(activation.getOs(), (os) -> writeElement(writer, "os", () -> { + writeSingleElement(writer, "name", os.getName()); + writeSingleElement(writer, "arch", os.getArch()); + writeSingleElement(writer, "family", os.getFamily()); + writeSingleElement(writer, "version", os.getVersion()); + })); + ifNotNull(activation.getProperty(), (property) -> writeElement(writer, "property", () -> { + writeSingleElement(writer, "name", property.getName()); + writeSingleElement(writer, "value", property.getValue()); + })); + ifNotNull(activation.getFile(), (file) -> writeElement(writer, "file", () -> { + writeSingleElement(writer, "exists", file.getExists()); + writeSingleElement(writer, "missing", file.getMissing()); + })); }); } - private void writeProfileBuild(IndentingWriter writer, MavenProfileBuild build) { - if (build == null) { + private void writeProfileBuild(IndentingWriter writer, MavenProfile profile) { + MavenProfile.Settings settings = profile.getSettings(); + if (settings.getDefaultGoal() == null && settings.getFinalName() == null && profile.resources().isEmpty() + && profile.testResources().isEmpty() && profile.plugins().isEmpty()) { return; } - writer.println(); writeElement(writer, "build", () -> { - writeSingleElement(writer, "defaultGoal", build.getDefaultGoal()); - writeSingleElement(writer, "directory", build.getDirectory()); - writeSingleElement(writer, "fileName", build.getFinalName()); - writeCollectionElement(writer, "filters", build.getFilters(), - (IndentingWriter writerInner, String filter) -> writeSingleElement(writerInner, "filter", filter)); - writeResources(writer, build.getResources(), build.getTestResources()); - writePluginManagement(writer, build.getPluginManagement()); - writeCollectionElement(writer, "plugins", build.getPlugins().values(), this::writePlugin); + writeSingleElement(writer, "defaultGoal", settings.getDefaultGoal()); + writeSingleElement(writer, "finalName", settings.getFinalName()); + writeResources(writer, profile.resources(), profile.testResources()); + writeCollectionElement(writer, "plugins", profile.plugins().values(), this::writePlugin); }); } - private void writePluginManagement(IndentingWriter writer, MavenPluginManagement pluginManagement) { - if (pluginManagement == null) { - return; - } - - writer.println(); - writeElement(writer, "pluginManagement", () -> writeCollectionElement(writer, "plugins", - pluginManagement.getPlugins().values(), this::writePlugin)); - } - - private void writeReporting(IndentingWriter writer, MavenReporting reporting) { - if (reporting == null) { - return; - } - - writer.println(); - writeElement(writer, "reporting", () -> { - writeSingleElement(writer, "excludeDefaults", String.valueOf(reporting.isExcludeDefaults())); - writeSingleElement(writer, "outputDirectory", reporting.getOutputDirectory()); - writeReportPlugins(writer, reporting.getReportPlugins()); - }); - } - - private void writeReportPlugins(IndentingWriter writer, MavenReportPluginContainer reportPlugins) { - if (reportPlugins.isEmpty()) { - return; - } - - Stream reportPluginStream = reportPlugins.values(); - writer.println(); - writeElement(writer, "plugins", () -> { - reportPluginStream.forEach((plugin) -> { - writeElement(writer, "plugin", () -> { - writeSingleElement(writer, "groupId", plugin.getGroupId()); - writeSingleElement(writer, "artifactId", plugin.getArtifactId()); - writeSingleElement(writer, "version", plugin.getVersion()); - writeSingleElement(writer, "inherited", plugin.getInherited()); - writeConfiguration(writer, "configuration", plugin.getConfiguration()); - writeReportSets(writer, plugin.getReportSets()); - }); - }); - }); - } - - private void writeReportSets(IndentingWriter writer, MavenReportSetContainer reportSets) { - if (reportSets.isEmpty()) { - return; - } - - Stream reportSetStream = reportSets.values(); - writer.println(); - writeElement(writer, "reportSets", () -> { - reportSetStream.forEach((reportSet) -> { - writeElement(writer, "reportSet", () -> { - writeSingleElement(writer, "id", reportSet.getId()); - writeSingleElement(writer, "inherited", reportSet.getInherited()); - writeConfiguration(writer, "configuration", reportSet.getConfiguration()); - writeCollectionElement(writer, "reports", reportSet.getReports(), (IndentingWriter writerInner, - String report) -> writeSingleElement(writerInner, "report", report)); - }); - }); - }); - } - - private void writeSingleElement(IndentingWriter writer, String name, String text) { - if (text != null) { + private void writeSingleElement(IndentingWriter writer, String name, Object value) { + if (value != null) { + CharSequence text = (value instanceof CharSequence) ? (CharSequence) value : value.toString(); writer.print(String.format("<%s>", name)); writer.print(encodeText(text)); writer.println(String.format("", name)); @@ -673,7 +590,13 @@ public class MavenBuildWriter { } } - private String encodeText(String text) { + private void ifNotNull(T value, Consumer elementWriter) { + if (value != null) { + elementWriter.accept(value); + } + } + + private String encodeText(CharSequence text) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < text.length(); i++) { char character = text.charAt(i); diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenConfiguration.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenConfiguration.java deleted file mode 100644 index d58e5dcc..00000000 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenConfiguration.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -/** - * A {@code } or {@code } that allow every xml structure on a - * different parts of the pom like {@link MavenPlugin.Execution}, {@link MavenPlugin}. - * TODO - * - * @author Andy Wilkinson - * @author Olga Maciaszek-Sharma - * @author Daniel Andres Pelaez Lopez - */ -public final class MavenConfiguration { - - private final List settings; - - MavenConfiguration(List settings) { - this.settings = Collections.unmodifiableList(settings); - } - - /** - * Return the {@linkplain Setting settings} of the configuration. - * @return the settings - */ - public List getSettings() { - return this.settings; - } - - /** - * A setting in a {@link MavenConfiguration}. - */ - public static final class Setting { - - private final String name; - - private final Object value; - - private Setting(String name, Object value) { - this.name = name; - this.value = value; - } - - /** - * Return the name of the configuration item. - * @return the name - */ - public String getName() { - return this.name; - } - - /** - * Return the value. Can be a nested {@link MavenConfiguration}. - * @return a simple value or a nested configuration - */ - public Object getValue() { - return this.value; - } - - } - - /** - * Builder for a {@link MavenConfiguration}. - */ - public static class Builder { - - private final List settings = new ArrayList<>(); - - /** - * Add the specified parameter with a single value. - * @param name the name of the parameter - * @param value the single value of the parameter - * @return this for method chaining - */ - public Builder add(String name, String value) { - this.settings.add(new Setting(name, value)); - return this; - } - - /** - * Configure the parameter with the specified {@code name}. - * @param name the name of the parameter - * @param consumer a consumer to further configure the parameter - * @return this for method chaining - * @throws IllegalArgumentException if a parameter with the same name is - * registered with a single value - */ - public Builder configure(String name, Consumer consumer) { - Object value = this.settings.stream().filter((candidate) -> candidate.getName().equals(name)).findFirst() - .orElseGet(() -> { - Setting nestedSetting = new Setting(name, new Builder()); - this.settings.add(nestedSetting); - return nestedSetting; - }).getValue(); - if (!(value instanceof Builder)) { - throw new IllegalArgumentException(String.format( - "Could not customize parameter '%s', a single value %s is already registered", name, value)); - } - Builder nestedConfiguration = (Builder) value; - consumer.accept(nestedConfiguration); - return this; - } - - /** - * Build a {@link MavenConfiguration} with the current state of this builder. - * @return a {@link MavenConfiguration} - */ - MavenConfiguration build() { - return new MavenConfiguration(this.settings.stream() - .map((entry) -> resolve(entry.getName(), entry.getValue())).collect(Collectors.toList())); - } - - private Setting resolve(String key, Object value) { - if (value instanceof Builder) { - List values = ((Builder) value).settings.stream() - .map((entry) -> resolve(entry.getName(), entry.getValue())).collect(Collectors.toList()); - return new Setting(key, values); - } - else { - return new Setting(key, value); - } - } - - } - -} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPlugin.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPlugin.java index 99adee3b..f7e3a8d2 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPlugin.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPlugin.java @@ -44,7 +44,7 @@ public class MavenPlugin { private final List dependencies; - private final MavenConfiguration configuration; + private final Configuration configuration; protected MavenPlugin(Builder builder) { this.groupId = builder.groupId; @@ -107,10 +107,10 @@ public class MavenPlugin { } /** - * Return the {@linkplain MavenConfiguration configuration} of the plugin. + * Return the {@linkplain Configuration configuration} of the plugin. * @return the configuration */ - public MavenConfiguration getConfiguration() { + public Configuration getConfiguration() { return this.configuration; } @@ -131,7 +131,7 @@ public class MavenPlugin { private final List dependencies = new ArrayList<>(); - private MavenConfiguration.Builder configurationBuilder; + private ConfigurationBuilder configurationBuilder; protected Builder(String groupId, String artifactId) { this.groupId = groupId; @@ -164,9 +164,9 @@ public class MavenPlugin { * @param configuration a consumer of the current configuration * @return this for method chaining */ - public Builder configuration(Consumer configuration) { + public Builder configuration(Consumer configuration) { if (this.configurationBuilder == null) { - this.configurationBuilder = new MavenConfiguration.Builder(); + this.configurationBuilder = new ConfigurationBuilder(); } configuration.accept(this.configurationBuilder); return this; @@ -218,7 +218,7 @@ public class MavenPlugin { private final List goals = new ArrayList<>(); - private MavenConfiguration.Builder configurationCustomization = null; + private ConfigurationBuilder configurationCustomization = null; public ExecutionBuilder(String id) { this.id = id; @@ -255,9 +255,9 @@ public class MavenPlugin { * @param configuration a consumer of the current configuration * @return this for method chaining */ - public ExecutionBuilder configuration(Consumer configuration) { + public ExecutionBuilder configuration(Consumer configuration) { if (this.configurationCustomization == null) { - this.configurationCustomization = new MavenConfiguration.Builder(); + this.configurationCustomization = new ConfigurationBuilder(); } configuration.accept(this.configurationCustomization); return this; @@ -265,6 +265,123 @@ public class MavenPlugin { } + /** + * Builder for a {@link Configuration}. + */ + public static class ConfigurationBuilder { + + private final List settings = new ArrayList<>(); + + /** + * Add the specified parameter with a single value. + * @param name the name of the parameter + * @param value the single value of the parameter + * @return this for method chaining + */ + public ConfigurationBuilder add(String name, String value) { + this.settings.add(new Setting(name, value)); + return this; + } + + /** + * Configure the parameter with the specified {@code name}. + * @param name the name of the parameter + * @param consumer a consumer to further configure the parameter + * @return this for method chaining + * @throws IllegalArgumentException if a parameter with the same name is + * registered with a single value + */ + public ConfigurationBuilder configure(String name, Consumer consumer) { + Object value = this.settings.stream().filter((candidate) -> candidate.getName().equals(name)).findFirst() + .orElseGet(() -> { + Setting nestedSetting = new Setting(name, new ConfigurationBuilder()); + this.settings.add(nestedSetting); + return nestedSetting; + }).getValue(); + if (!(value instanceof ConfigurationBuilder)) { + throw new IllegalArgumentException(String.format( + "Could not customize parameter '%s', a single value %s is already registered", name, value)); + } + ConfigurationBuilder nestedConfiguration = (ConfigurationBuilder) value; + consumer.accept(nestedConfiguration); + return this; + } + + /** + * Build a {@link Configuration} with the current state of this builder. + * @return a {@link Configuration} + */ + Configuration build() { + return new Configuration(this.settings.stream().map((entry) -> resolve(entry.getName(), entry.getValue())) + .collect(Collectors.toList())); + } + + private Setting resolve(String key, Object value) { + if (value instanceof ConfigurationBuilder) { + List values = ((ConfigurationBuilder) value).settings.stream() + .map((entry) -> resolve(entry.getName(), entry.getValue())).collect(Collectors.toList()); + return new Setting(key, values); + } + else { + return new Setting(key, value); + } + } + + } + + /** + * A {@code } on an {@link Execution} or {@link MavenPlugin}. + */ + public static final class Configuration { + + private final List settings; + + private Configuration(List settings) { + this.settings = Collections.unmodifiableList(settings); + } + + /** + * Return the {@linkplain Setting settings} of the configuration. + * @return the settings + */ + public List getSettings() { + return this.settings; + } + + } + + /** + * A setting in a {@link Configuration}. + */ + public static final class Setting { + + private final String name; + + private final Object value; + + private Setting(String name, Object value) { + this.name = name; + this.value = value; + } + + /** + * Return the name of the configuration item. + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * Return the value. Can be a nested {@link Configuration}. + * @return a simple value or a nested configuration + */ + public Object getValue() { + return this.value; + } + + } + /** * An {@code } of a {@link MavenPlugin}. */ @@ -276,9 +393,9 @@ public class MavenPlugin { private final List goals; - private final MavenConfiguration configuration; + private final Configuration configuration; - private Execution(String id, String phase, List goals, MavenConfiguration configuration) { + private Execution(String id, String phase, List goals, Configuration configuration) { this.id = id; this.phase = phase; this.goals = Collections.unmodifiableList(goals); @@ -310,10 +427,10 @@ public class MavenPlugin { } /** - * Return the {@linkplain MavenConfiguration configuration} of the execution. + * Return the {@linkplain Configuration configuration} of the execution. * @return the configuration */ - public MavenConfiguration getConfiguration() { + public Configuration getConfiguration() { return this.configuration; } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginManagement.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginManagement.java deleted file mode 100644 index 96efa804..00000000 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginManagement.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import java.util.function.Consumer; - -public class MavenPluginManagement { - - private final MavenPluginContainer plugins; - - protected MavenPluginManagement(Builder builder) { - this.plugins = builder.plugins; - } - - public MavenPluginContainer getPlugins() { - return this.plugins; - } - - public static class Builder { - - private MavenPluginContainer plugins = new MavenPluginContainer(); - - protected Builder() { - } - - public MavenPluginManagement.Builder plugins(Consumer plugins) { - plugins.accept(this.plugins); - return this; - } - - public MavenPluginManagement build() { - return new MavenPluginManagement(this); - } - - } - -} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfile.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfile.java index 0a354e24..d3c54f41 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfile.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfile.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,206 +16,253 @@ package io.spring.initializr.generator.buildsystem.maven; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.function.Consumer; - import io.spring.initializr.generator.buildsystem.BomContainer; import io.spring.initializr.generator.buildsystem.BuildItemResolver; import io.spring.initializr.generator.buildsystem.DependencyContainer; import io.spring.initializr.generator.buildsystem.MavenRepositoryContainer; +import io.spring.initializr.generator.buildsystem.PropertyContainer; +/** + * A profile in a {@link MavenBuild}. + * + * @author Daniel Andres Pelaez Lopez + * @author Stephane Nicoll + */ public class MavenProfile { private final String id; - private final MavenProfileActivation activation; + private final MavenProfileActivation.Builder activation = new MavenProfileActivation.Builder(); - private final MavenProfileBuild build; + private final SettingsBuilder settings = new SettingsBuilder(); - private final List modules; + private final PropertyContainer properties = new PropertyContainer(); + + private final DependencyContainer dependencies; + + private final MavenResourceContainer resources = new MavenResourceContainer(); + + private final MavenResourceContainer testResources = new MavenResourceContainer(); + + private final MavenPluginContainer plugins = new MavenPluginContainer(); + + private final BomContainer boms; private final MavenRepositoryContainer repositories; private final MavenRepositoryContainer pluginRepositories; - private final DependencyContainer dependencies; + private final MavenDistributionManagement.Builder distributionManagement = new MavenDistributionManagement.Builder(); - private final MavenReporting reporting; - - private final BomContainer dependencyManagement; - - private final MavenDistributionManagement distributionManagement; - - private final MavenConfiguration properties; - - protected MavenProfile(Builder builder) { - this.id = builder.id; - this.activation = Optional.ofNullable(builder.activationBuilder).map(MavenProfileActivation.Builder::build) - .orElse(null); - this.build = Optional.ofNullable(builder.buildBuilder).map(MavenProfileBuild.Builder::build).orElse(null); - this.modules = builder.modules; - this.repositories = builder.repositories; - this.pluginRepositories = builder.pluginRepositories; - this.dependencies = builder.dependencies; - this.reporting = Optional.ofNullable(builder.reportingBuilder).map(MavenReporting.Builder::build).orElse(null); - this.dependencyManagement = builder.dependencyManagement; - this.distributionManagement = Optional.ofNullable(builder.distributionManagementBuilder) - .map(MavenDistributionManagement.Builder::build).orElse(new MavenDistributionManagement.Builder().build()); - this.properties = Optional.ofNullable(builder.properties).map(MavenConfiguration.Builder::build).orElse(null); + protected MavenProfile(String id, BuildItemResolver buildItemResolver) { + this.id = id; + this.dependencies = new DependencyContainer(buildItemResolver::resolveDependency); + this.boms = new BomContainer(buildItemResolver::resolveBom); + this.repositories = new MavenRepositoryContainer(buildItemResolver::resolveRepository); + this.pluginRepositories = new MavenRepositoryContainer(buildItemResolver::resolveRepository); } + /** + * Return the identifier of the profile. + * @return the profile id + */ public String getId() { return this.id; } - public MavenProfileActivation getActivation() { + /** + * Return a builder to configure how this profile should be + * {@link MavenProfileActivation activated}. + * @return a builder for {@link MavenProfileActivation}. + */ + public MavenProfileActivation.Builder activation() { return this.activation; } - public MavenProfileBuild getBuild() { - return this.build; + /** + * Return the {@link MavenProfileActivation} of this profile. + * @return the {@link MavenProfileActivation} + */ + public MavenProfileActivation getActivation() { + return this.activation.build(); } - public List getModules() { - return this.modules; + /** + * Return a builder to configure the general settings of this profile. + * @return a builder for {@link SettingsBuilder}. + */ + public SettingsBuilder settings() { + return this.settings; } - public MavenRepositoryContainer getRepositories() { - return this.repositories; + /** + * Return the settings of this profile. + * @return a {@link Settings} + */ + public Settings getSettings() { + return this.settings.build(); } - public MavenRepositoryContainer getPluginRepositories() { - return this.pluginRepositories; - } - - public DependencyContainer getDependencies() { - return this.dependencies; - } - - public MavenReporting getReporting() { - return this.reporting; - } - - public BomContainer getDependencyManagement() { - return this.dependencyManagement; - } - - public MavenDistributionManagement getDistributionManagement() { - return this.distributionManagement; - } - - public MavenConfiguration getProperties() { + /** + * Return the {@linkplain PropertyContainer property container} to use to configure + * properties. + * @return the {@link PropertyContainer} + */ + public PropertyContainer properties() { return this.properties; } - public static class Builder { + /** + * Return the {@linkplain DependencyContainer dependency container} to use to + * configure dependencies. + * @return the {@link DependencyContainer} + */ + public DependencyContainer dependencies() { + return this.dependencies; + } - private final String id; + /** + * Return the {@linkplain BomContainer bom container} to use to configure Bill of + * Materials. + * @return the {@link BomContainer} + */ + public BomContainer boms() { + return this.boms; + } - private final BuildItemResolver buildItemResolver; + /** + * Return the {@linkplain MavenRepositoryContainer repository container} to use to + * configure repositories. + * @return the {@link MavenRepositoryContainer} for repositories + */ + public MavenRepositoryContainer repositories() { + return this.repositories; + } - private MavenProfileActivation.Builder activationBuilder; + /** + * Return the {@linkplain MavenRepositoryContainer repository container} to use to + * configure plugin repositories. + * @return the {@link MavenRepositoryContainer} for plugin repositories + */ + public MavenRepositoryContainer pluginRepositories() { + return this.pluginRepositories; + } - private MavenProfileBuild.Builder buildBuilder; + /** + * Return a builder to configure the {@linkplain MavenDistributionManagement + * distribution management} of this profile. + * @return a builder for {@link MavenDistributionManagement} + */ + public MavenDistributionManagement.Builder distributionManagement() { + return this.distributionManagement; + } - private List modules; + /** + * Return the {@linkplain MavenDistributionManagement distribution management} of this + * profile. + * @return the {@link MavenDistributionManagement} + */ + public MavenDistributionManagement getDistributionManagement() { + return this.distributionManagement.build(); + } - private MavenRepositoryContainer repositories; + /** + * Return the {@linkplain MavenResource resource container} to use to configure main + * resources. + * @return the {@link MavenRepositoryContainer} for main resources + */ + public MavenResourceContainer resources() { + return this.resources; + } - private MavenRepositoryContainer pluginRepositories; + /** + * Return the {@linkplain MavenResource resource container} to use to configure test + * resources. + * @return the {@link MavenRepositoryContainer} for test resources + */ + public MavenResourceContainer testResources() { + return this.testResources; + } - private DependencyContainer dependencies; + /** + * Return the {@linkplain MavenPluginContainer plugin container} to use to configure + * plugins. + * @return the {@link MavenPluginContainer} + */ + public MavenPluginContainer plugins() { + return this.plugins; + } - private MavenReporting.Builder reportingBuilder; + /** + * Builder for {@link Settings}. + */ + public static class SettingsBuilder { - private BomContainer dependencyManagement; + private String defaultGoal; - private MavenDistributionManagement.Builder distributionManagementBuilder; + private String finalName; - private MavenConfiguration.Builder properties; - - protected Builder(String id, BuildItemResolver buildItemResolver) { - this.id = id; - this.buildItemResolver = buildItemResolver; - this.dependencyManagement = new BomContainer(this.buildItemResolver::resolveBom); - this.repositories = new MavenRepositoryContainer(this.buildItemResolver::resolveRepository); - this.pluginRepositories = new MavenRepositoryContainer(this.buildItemResolver::resolveRepository); - this.dependencies = new DependencyContainer(this.buildItemResolver::resolveDependency); + protected SettingsBuilder() { } - public Builder activation(Consumer activation) { - if (this.activationBuilder == null) { - this.activationBuilder = new MavenProfileActivation.Builder(); - } - activation.accept(this.activationBuilder); + /** + * Set the default goal or phase to execute if none is given when this profile is + * active. + * @param defaultGoal the default goal or {@code null} to use the value in the + * build + * @return this for method chaining + */ + public SettingsBuilder defaultGoal(String defaultGoal) { + this.defaultGoal = defaultGoal; return this; } - public Builder build(Consumer build) { - if (this.buildBuilder == null) { - this.buildBuilder = new MavenProfileBuild.Builder(); - } - build.accept(this.buildBuilder); + /** + * Set the name of the bundled project when it is finally built when this profile + * is active. + * @param finalName the final name of the artifact or {@code null} to use the + * value in the build. + * @return this for method chaining + */ + public SettingsBuilder finalName(String finalName) { + this.finalName = finalName; return this; } - public Builder module(String module) { - if (this.modules == null) { - this.modules = new LinkedList<>(); - } - this.modules.add(module); - return this; + public Settings build() { + return new Settings(this); } - public Builder repositories(Consumer repositories) { - repositories.accept(this.repositories); - return this; + } + + /** + * Maven profile settings. + */ + public static final class Settings { + + private final String defaultGoal; + + private final String finalName; + + protected Settings(SettingsBuilder builder) { + this.defaultGoal = builder.defaultGoal; + this.finalName = builder.finalName; } - public Builder pluginRepositories(Consumer pluginRepositories) { - pluginRepositories.accept(this.pluginRepositories); - return this; + /** + * Return the default goal or phase to execute if none is given. + * @return the default goal or {@code null} to use the default + */ + public String getDefaultGoal() { + return this.defaultGoal; } - public Builder reporting(Consumer reporting) { - if (this.reportingBuilder == null) { - this.reportingBuilder = new MavenReporting.Builder(); - } - reporting.accept(this.reportingBuilder); - return this; - } - - public Builder dependencies(Consumer dependencies) { - dependencies.accept(this.dependencies); - return this; - } - - public Builder dependencyManagement(Consumer dependencyManagement) { - dependencyManagement.accept(this.dependencyManagement); - return this; - } - - public Builder distributionManagement( - Consumer distributionManagementBuilder) { - if (this.distributionManagementBuilder == null) { - this.distributionManagementBuilder = new MavenDistributionManagement.Builder(); - } - distributionManagementBuilder.accept(this.distributionManagementBuilder); - return this; - } - - public Builder properties(Consumer properties) { - if (this.properties == null) { - this.properties = new MavenConfiguration.Builder(); - } - properties.accept(this.properties); - return this; - } - - public MavenProfile build() { - return new MavenProfile(this); + /** + * Return the final name of the artifact. + * @return the final name or {@code null} to use the default + */ + public String getFinalName() { + return this.finalName; } } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivation.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivation.java index d4e546bd..ba5fe344 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivation.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivation.java @@ -16,100 +16,305 @@ package io.spring.initializr.generator.buildsystem.maven; -import java.util.Optional; -import java.util.function.Consumer; - +/** + * A {@link MavenProfile profile} activation in a {@link MavenBuild}. + * + * @author Stephane Nicoll + */ public class MavenProfileActivation { private final Boolean activeByDefault; private final String jdk; - private final MavenProfileActivationOS os; + private final Os os; - private final MavenProfileActivationProperty property; + private final Property property; - private final MavenProfileActivationFile file; + private final File file; protected MavenProfileActivation(Builder builder) { this.activeByDefault = builder.activeByDefault; this.jdk = builder.jdk; - this.os = Optional.ofNullable(builder.osBuilder).map(MavenProfileActivationOS.Builder::build).orElse(null); - this.property = Optional.ofNullable(builder.propertyBuilder).map(MavenProfileActivationProperty.Builder::build) - .orElse(null); - this.file = Optional.ofNullable(builder.fileBuilder).map(MavenProfileActivationFile.Builder::build) - .orElse(null); + this.os = builder.os; + this.property = builder.property; + this.file = (builder.fileExists != null || builder.fileMissing != null) + ? new File(builder.fileExists, builder.fileMissing) : null; } + /** + * Specify if this activation has any non-default value. + * @return {@code true} if there are no non-default values + */ + public boolean isEmpty() { + return (this.activeByDefault == null && this.jdk == null && this.os == null && this.property == null + && this.file == null); + } + + /** + * Specify if the profile should be activated by default, or {@code null} to use the + * default value. + * @return {@code true} to active the profile if no other profile is active + */ public Boolean getActiveByDefault() { return this.activeByDefault; } + /** + * Specify the JDK(s) that should match for the profile to be activated, or + * {@code null} to not enable the profile based on the JDK. + * @return the jdk (or jdks range) that should match or {@code null} + */ public String getJdk() { return this.jdk; } - public MavenProfileActivationOS getOs() { + /** + * Return the operating system activation settings, or {@code null} to not enable the + * profile based on the OS. + * @return the operating system activation settings or {@code null} + */ + public Os getOs() { return this.os; } - public MavenProfileActivationProperty getProperty() { + /** + * Return the property to match to enable the profile, or {@code null} to not enable + * the profile based on a property. + * @return the property to match or {@code null} + */ + public Property getProperty() { return this.property; } - public MavenProfileActivationFile getFile() { + /** + * Return the file activation settings, or {@code null} to not enable the profile + * based on the presence or absence of a file. + * @return the file activation settings or {@code null} + */ + public File getFile() { return this.file; } + /** + * Operating System activation settings. + */ + public static final class Os { + + private final String name; + + private final String family; + + private final String arch; + + private final String version; + + Os(String name, String family, String arch, String version) { + this.name = name; + this.family = family; + this.arch = arch; + this.version = version; + } + + /** + * Return the name of the OS to match or {@code null}. + * @return the name of the OS + */ + public String getName() { + return this.name; + } + + /** + * Return the family of OS to match or {@code null}. Can be for instance + * {@code mac}, {@code windows}, {@code unix}, {@code os/400}, etc. + * @return the family of OS + */ + public String getFamily() { + return this.family; + } + + /** + * Return the cpu architecture of the OS to match or {@code null}. + * @return the cpu architecture of the OS + */ + public String getArch() { + return this.arch; + } + + /** + * Return the version of the OS to match or {@code null}. + * @return the version of the OS + */ + public String getVersion() { + return this.version; + } + + } + + /** + * Property activation settings. + */ + public static final class Property { + + private final String name; + + private final String value; + + Property(String name, String value) { + this.name = name; + this.value = value; + } + + /** + * Return the name of the property. + * @return the property name + */ + public String getName() { + return this.name; + } + + /** + * Return the value of the property. + * @return the property value + */ + public String getValue() { + return this.value; + } + + } + + /** + * File activation settings. + */ + public static final class File { + + private final String exists; + + private final String missing; + + File(String exists, String missing) { + this.missing = missing; + this.exists = exists; + } + + /** + * Return the file that should exists for the profile to match or {@code null}. + * @return the file that should exist + */ + public String getExists() { + return this.exists; + } + + /** + * Return the file that should be missing for the profile to match or + * {@code null}. + * @return the file that should be missing + */ + public String getMissing() { + return this.missing; + } + + } + + /** + * Builder for {@link MavenProfileActivation}. + */ public static class Builder { private Boolean activeByDefault; private String jdk; - private MavenProfileActivationOS.Builder osBuilder; + private Os os; - private MavenProfileActivationProperty.Builder propertyBuilder; + private Property property; - private MavenProfileActivationFile.Builder fileBuilder; + private String fileExists; + + private String fileMissing; protected Builder() { } - public MavenProfileActivation.Builder activeByDefault(boolean activeByDefault) { + /** + * Specify if the profile should be enabled if no profile is active. + * @param activeByDefault whether to enable the profile is no profile is active + * @return this for method chaining + */ + public Builder activeByDefault(Boolean activeByDefault) { this.activeByDefault = activeByDefault; return this; } - public MavenProfileActivation.Builder jdk(String jdk) { + /** + * Specify the JDK(s) to match to enable the profile. Can be a JDK value or an + * OSGi range. + * @param jdk the jdk (or JDKs range) to match + * @return this for method chaining + */ + public Builder jdk(String jdk) { this.jdk = jdk; return this; } - public MavenProfileActivation.Builder os(Consumer os) { - if (this.osBuilder == null) { - this.osBuilder = new MavenProfileActivationOS.Builder(); + /** + * Specify the OS to match to enable the profile. + * @param name the name of the OS + * @param family the family os OS + * @param arch the cpu architecture + * @param version the version of the OS + * @return this for method chaining + */ + public Builder os(String name, String family, String arch, String version) { + if (name == null && family == null && arch == null && version == null) { + this.os = null; + } + else { + this.os = new Os(name, family, arch, version); } - os.accept(this.osBuilder); return this; } - public MavenProfileActivation.Builder property(Consumer property) { - if (this.propertyBuilder == null) { - this.propertyBuilder = new MavenProfileActivationProperty.Builder(); + /** + * Specify the property to match to enable the profile. + * @param name the name of the property + * @param value the value of the property + * @return this for method chaining + */ + public Builder property(String name, String value) { + if (name == null) { + this.property = null; + } + else { + this.property = new Property(name, value); } - property.accept(this.propertyBuilder); return this; } - public MavenProfileActivation.Builder file(Consumer file) { - if (this.fileBuilder == null) { - this.fileBuilder = new MavenProfileActivationFile.Builder(); - } - file.accept(this.fileBuilder); + /** + * Specify the file that should exist to enable the profile. + * @param existingFile the file that should exist + * @return this for method chaining + */ + public Builder fileExists(String existingFile) { + this.fileExists = existingFile; return this; } + /** + * Specify the file that should be missing to enable the profile. + * @param missingFile the file that should be missing + * @return this for method chaining + */ + public Builder fileMissing(String missingFile) { + this.fileMissing = missingFile; + return this; + } + + /** + * Create a {@link MavenProfileActivation} with the current state of this builder. + * @return a {@link MavenProfileActivation}. + */ public MavenProfileActivation build() { return new MavenProfileActivation(this); } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFile.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFile.java deleted file mode 100644 index 4074f2f0..00000000 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFile.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -public class MavenProfileActivationFile { - - private final String missing; - - private final String exists; - - protected MavenProfileActivationFile(Builder builder) { - this.missing = builder.missing; - this.exists = builder.exists; - } - - public String getMissing() { - return this.missing; - } - - public String getExists() { - return this.exists; - } - - public static class Builder { - - private String missing; - - private String exists; - - protected Builder() { - - } - - public MavenProfileActivationFile.Builder missing(String missing) { - this.missing = missing; - return this; - } - - public MavenProfileActivationFile.Builder exists(String exists) { - this.exists = exists; - return this; - } - - public MavenProfileActivationFile build() { - return new MavenProfileActivationFile(this); - } - - } - -} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOS.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOS.java deleted file mode 100644 index 3290b59c..00000000 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOS.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -public class MavenProfileActivationOS { - - private final String name; - - private final String family; - - private final String arch; - - private final String version; - - public MavenProfileActivationOS(Builder builder) { - this.name = builder.name; - this.family = builder.family; - this.arch = builder.arch; - this.version = builder.version; - } - - public String getName() { - return this.name; - } - - public String getFamily() { - return this.family; - } - - public String getArch() { - return this.arch; - } - - public String getVersion() { - return this.version; - } - - public static class Builder { - - private String name; - - private String family; - - private String arch; - - private String version; - - protected Builder() { - - } - - public MavenProfileActivationOS.Builder name(String name) { - this.name = name; - return this; - } - - public MavenProfileActivationOS.Builder family(String family) { - this.family = family; - return this; - } - - public MavenProfileActivationOS.Builder arch(String arch) { - this.arch = arch; - return this; - } - - public MavenProfileActivationOS.Builder version(String version) { - this.version = version; - return this; - } - - public MavenProfileActivationOS build() { - return new MavenProfileActivationOS(this); - } - - } - -} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationProperty.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationProperty.java deleted file mode 100644 index e0359a19..00000000 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationProperty.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -public class MavenProfileActivationProperty { - - private final String name; - - private final String value; - - protected MavenProfileActivationProperty(Builder builder) { - this.name = builder.name; - this.value = builder.value; - } - - public String getName() { - return this.name; - } - - public String getValue() { - return this.value; - } - - public static class Builder { - - private String name; - - private String value; - - protected Builder() { - - } - - public MavenProfileActivationProperty.Builder name(String name) { - this.name = name; - return this; - } - - public MavenProfileActivationProperty.Builder value(String value) { - this.value = value; - return this; - } - - public MavenProfileActivationProperty build() { - return new MavenProfileActivationProperty(this); - } - - } - -} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuild.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuild.java deleted file mode 100644 index ef4be22f..00000000 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuild.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.function.Consumer; - -public class MavenProfileBuild { - - private final String defaultGoal; - - private final String directory; - - private final String finalName; - - private final List filters; - - private final MavenResourceContainer resources; - - private final MavenResourceContainer testResources; - - private final MavenPluginManagement pluginManagement; - - private final MavenPluginContainer plugins; - - protected MavenProfileBuild(Builder builder) { - this.defaultGoal = builder.defaultGoal; - this.directory = builder.directory; - this.finalName = builder.finalName; - this.filters = Optional.ofNullable(builder.filters).map(Collections::unmodifiableList).orElse(null); - this.resources = builder.resources; - this.testResources = builder.testResources; - this.pluginManagement = Optional.ofNullable(builder.pluginManagementBuilder) - .map(MavenPluginManagement.Builder::build).orElse(null); - this.plugins = builder.plugins; - } - - public String getDefaultGoal() { - return this.defaultGoal; - } - - public String getDirectory() { - return this.directory; - } - - public String getFinalName() { - return this.finalName; - } - - public List getFilters() { - return this.filters; - } - - public MavenResourceContainer getResources() { - return this.resources; - } - - public MavenResourceContainer getTestResources() { - return this.testResources; - } - - public MavenPluginManagement getPluginManagement() { - return this.pluginManagement; - } - - public MavenPluginContainer getPlugins() { - return this.plugins; - } - - public static class Builder { - - private String defaultGoal; - - private String directory; - - private String finalName; - - private List filters; - - private MavenResourceContainer resources; - - private MavenResourceContainer testResources; - - private MavenPluginManagement.Builder pluginManagementBuilder; - - private MavenPluginContainer plugins; - - protected Builder() { - this.resources = new MavenResourceContainer(); - this.testResources = new MavenResourceContainer(); - this.plugins = new MavenPluginContainer(); - } - - public MavenProfileBuild.Builder defaultGoal(String defaultGoal) { - this.defaultGoal = defaultGoal; - return this; - } - - public MavenProfileBuild.Builder directory(String directory) { - this.directory = directory; - return this; - } - - public MavenProfileBuild.Builder finalName(String finalName) { - this.finalName = finalName; - return this; - } - - public MavenProfileBuild.Builder filter(String filter) { - if (this.filters == null) { - this.filters = new LinkedList<>(); - } - this.filters.add(filter); - return this; - } - - public MavenProfileBuild.Builder resources(Consumer resources) { - resources.accept(this.resources); - return this; - } - - public MavenProfileBuild.Builder testResources(Consumer testResources) { - testResources.accept(this.testResources); - return this; - } - - public MavenProfileBuild.Builder pluginManagement(Consumer pluginManagement) { - if (this.pluginManagementBuilder == null) { - this.pluginManagementBuilder = new MavenPluginManagement.Builder(); - } - pluginManagement.accept(this.pluginManagementBuilder); - return this; - } - - public MavenProfileBuild.Builder plugins(Consumer plugins) { - plugins.accept(this.plugins); - return this; - } - - public MavenProfileBuild build() { - return new MavenProfileBuild(this); - } - - } - -} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainer.java index f7a4715b..7b86edbd 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainer.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,17 +18,26 @@ package io.spring.initializr.generator.buildsystem.maven; import java.util.LinkedHashMap; import java.util.Map; -import java.util.function.Consumer; import java.util.stream.Stream; import io.spring.initializr.generator.buildsystem.BuildItemResolver; +/** + * A container for {@link MavenProfile maven profiles}. + * + * @author Stephane Nicoll + * @author Daniel Andres Pelaez Lopez + */ public class MavenProfileContainer { - private final Map profiles = new LinkedHashMap<>(); + private final Map profiles = new LinkedHashMap<>(); private final BuildItemResolver buildItemResolver; + /** + * Create an instance with the {@link BuildItemResolver} to use. + * @param buildItemResolver the build item resolver to use + */ public MavenProfileContainer(BuildItemResolver buildItemResolver) { this.buildItemResolver = buildItemResolver; } @@ -42,65 +51,47 @@ public class MavenProfileContainer { } /** - * Returns a {@link Stream} of registered {@link MavenProfile}s. - * @return a stream of {@link MavenProfile}s - */ - public Stream values() { - return this.profiles.values().stream().map(MavenProfile.Builder::build); - } - - /** - * Add a {@link MavenProfile} with the specified {@code id} and - * {@code activateByDefault}. + * Specify if this container has a profile with the specified {@code id}. * @param id the id of the profile - */ - public void add(String id) { - createProfileBuilder(id); - } - - /** - * Specify if this container has a plugin with the specified {@code groupId} and - * {@code artifactId}. - * @param id the groupId of the plugin - * @return {@code true} if an item with the specified {@code groupId} and - * {@code artifactId} exists + * @return {@code true} if a profile with the specified {@code id} exists */ public boolean has(String id) { return this.profiles.containsKey(id); } /** - * Add a {@link MavenProfile} with the specified {@code id} and - * {@code activateByDefault} and {@link MavenProfile.Builder} to customize the - * profile. If the profile has already been added, the profileBuilder can be used to - * further tune the existing profile configuration. - * @param id the id of the profile - * @param profileBuilder a {@link MavenProfile.Builder} to customize the - * {@link MavenProfile} + * Return a {@link Stream} of registered profile identifiers. + * @return a stream of profile ids */ - public void add(String id, Consumer profileBuilder) { - profileBuilder.accept(createProfileBuilder(id)); + public Stream ids() { + return this.profiles.keySet().stream(); } /** - * Remove the plugin with the specified {@code groupId} and {@code artifactId}. - * @param id the groupId of the plugin to remove - * @return {@code true} if such a plugin was registered, {@code false} otherwise + * Returns a {@link Stream} of registered {@link MavenProfile}s. + * @return a stream of {@link MavenProfile}s + */ + public Stream values() { + return this.profiles.values().stream(); + } + + /** + * Return the profile with the specified {@code id}. If no such profile exists a new + * profile is created. + * @param id the id of the profile + * @return the {@link MavenProfile} for that id + */ + public MavenProfile id(String id) { + return this.profiles.computeIfAbsent(id, (key) -> new MavenProfile(id, this.buildItemResolver)); + } + + /** + * Remove the profile with the specified {@code id}. + * @param id the id of the profile + * @return {@code true} if such a profile was registered, {@code false} otherwise */ public boolean remove(String id) { return this.profiles.remove(id) != null; } - private MavenProfile.Builder createProfileBuilder(String id) { - MavenProfile.Builder profileBuilder = this.profiles.get(id); - if (profileBuilder == null) { - MavenProfile.Builder builder = new MavenProfile.Builder(id, this.buildItemResolver); - this.profiles.put(id, builder); - return builder; - } - else { - return profileBuilder; - } - } - } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPlugin.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPlugin.java deleted file mode 100644 index 7a54ade2..00000000 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPlugin.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import java.util.Optional; -import java.util.function.Consumer; - -public class MavenReportPlugin { - - private final String groupId; - - private final String artifactId; - - private final String version; - - private final String inherited; - - private final MavenConfiguration configuration; - - private final MavenReportSetContainer reportSets; - - protected MavenReportPlugin(Builder builder) { - this.groupId = builder.groupId; - this.artifactId = builder.artifactId; - this.version = builder.version; - this.inherited = builder.inherited; - this.configuration = Optional.ofNullable(builder.configuration).map(MavenConfiguration.Builder::build) - .orElse(null); - this.reportSets = builder.reportSets; - } - - public String getGroupId() { - return this.groupId; - } - - public String getArtifactId() { - return this.artifactId; - } - - public String getVersion() { - return this.version; - } - - public String getInherited() { - return this.inherited; - } - - public MavenConfiguration getConfiguration() { - return this.configuration; - } - - public MavenReportSetContainer getReportSets() { - return this.reportSets; - } - - public static class Builder { - - private final String groupId; - - private final String artifactId; - - private String version; - - private String inherited; - - private MavenConfiguration.Builder configuration; - - private MavenReportSetContainer reportSets; - - protected Builder(String groupId, String artifactId) { - this.groupId = groupId; - this.artifactId = artifactId; - this.reportSets = new MavenReportSetContainer(); - } - - public MavenReportPlugin.Builder inherited(String inherited) { - this.inherited = inherited; - return this; - } - - public MavenReportPlugin.Builder version(String version) { - this.version = version; - return this; - } - - public MavenReportPlugin.Builder configuration(Consumer configuration) { - if (this.configuration == null) { - this.configuration = new MavenConfiguration.Builder(); - } - configuration.accept(this.configuration); - return this; - } - - public MavenReportPlugin.Builder reportSets(Consumer reportSets) { - reportSets.accept(this.reportSets); - return this; - } - - public MavenReportPlugin build() { - return new MavenReportPlugin(this); - } - - } - -} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainer.java deleted file mode 100644 index 581721be..00000000 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainer.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.Consumer; -import java.util.stream.Stream; - -import io.spring.initializr.generator.buildsystem.maven.MavenReportPlugin.Builder; - -public class MavenReportPluginContainer { - - private final Map reportPlugins = new LinkedHashMap<>(); - - public boolean isEmpty() { - return this.reportPlugins.isEmpty(); - } - - public boolean has(String groupId, String artifactId) { - return this.reportPlugins.containsKey(pluginKey(groupId, artifactId)); - } - - public Stream values() { - return this.reportPlugins.values().stream().map(Builder::build); - } - - public MavenReportPluginContainer add(String groupId, String artifactId) { - addReportPlugin(groupId, artifactId); - return this; - } - - public MavenReportPluginContainer add(String groupId, String artifactId, Consumer plugin) { - plugin.accept(addReportPlugin(groupId, artifactId)); - return this; - } - - private Builder addReportPlugin(String groupId, String artifactId) { - return this.reportPlugins.computeIfAbsent(pluginKey(groupId, artifactId), - (pluginId) -> new Builder(groupId, artifactId)); - } - - public boolean remove(String groupId, String artifactId) { - return this.reportPlugins.remove(pluginKey(groupId, artifactId)) != null; - } - - private String pluginKey(String groupId, String artifactId) { - return String.format("%s:%s", groupId, artifactId); - } - -} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSet.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSet.java deleted file mode 100644 index 747ee002..00000000 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSet.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.function.Consumer; - -public class MavenReportSet { - - private final String id; - - private final MavenConfiguration configuration; - - private final String inherited; - - private final List reports; - - public MavenReportSet(Builder builder) { - this.id = builder.id; - this.configuration = Optional.ofNullable(builder.configuration).map(MavenConfiguration.Builder::build) - .orElse(null); - this.inherited = builder.inherited; - this.reports = Optional.ofNullable(builder.reports).map(Collections::unmodifiableList).orElse(null); - } - - public String getId() { - return this.id; - } - - public MavenConfiguration getConfiguration() { - return this.configuration; - } - - public String getInherited() { - return this.inherited; - } - - public List getReports() { - return this.reports; - } - - public static class Builder { - - private final String id; - - private MavenConfiguration.Builder configuration; - - private String inherited; - - private List reports; - - protected Builder(String id) { - this.id = id; - } - - public MavenReportSet.Builder configuration(Consumer configuration) { - if (this.configuration == null) { - this.configuration = new MavenConfiguration.Builder(); - } - configuration.accept(this.configuration); - return this; - } - - public MavenReportSet.Builder inherited(String inherited) { - this.inherited = inherited; - return this; - } - - public MavenReportSet.Builder report(String report) { - if (this.reports == null) { - this.reports = new LinkedList<>(); - } - this.reports.add(report); - return this; - } - - public MavenReportSet build() { - return new MavenReportSet(this); - } - - } - -} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainer.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainer.java deleted file mode 100644 index 13463914..00000000 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainer.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.Consumer; -import java.util.stream.Stream; - -public class MavenReportSetContainer { - - private final Map reportSets = new LinkedHashMap<>(); - - public boolean isEmpty() { - return this.reportSets.isEmpty(); - } - - public Stream values() { - return this.reportSets.values().stream().map(MavenReportSet.Builder::build); - } - - public MavenReportSetContainer add(String id) { - createReportSetBuilder(id); - return this; - } - - public boolean has(String id) { - return this.reportSets.containsKey(id); - } - - public MavenReportSetContainer add(String id, Consumer profileBuilder) { - profileBuilder.accept(createReportSetBuilder(id)); - return this; - } - - public boolean remove(String id) { - return this.reportSets.remove(id) != null; - } - - private MavenReportSet.Builder createReportSetBuilder(String id) { - MavenReportSet.Builder reportSetBuilder = this.reportSets.get(id); - if (reportSetBuilder == null) { - MavenReportSet.Builder builder = new MavenReportSet.Builder(id); - this.reportSets.put(id, builder); - return builder; - } - else { - return reportSetBuilder; - } - } - -} diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReporting.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReporting.java deleted file mode 100644 index bedc0174..00000000 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenReporting.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import java.util.function.Consumer; - -public class MavenReporting { - - private final Boolean excludeDefaults; - - private final String outputDirectory; - - private final MavenReportPluginContainer reportPlugins; - - protected MavenReporting(Builder builder) { - this.excludeDefaults = builder.excludeDefaults; - this.outputDirectory = builder.outputDirectory; - this.reportPlugins = builder.reportPlugins; - } - - public Boolean isExcludeDefaults() { - return this.excludeDefaults; - } - - public String getOutputDirectory() { - return this.outputDirectory; - } - - public MavenReportPluginContainer getReportPlugins() { - return this.reportPlugins; - } - - public static class Builder { - - private Boolean excludeDefaults; - - private String outputDirectory; - - private MavenReportPluginContainer reportPlugins; - - protected Builder() { - this.reportPlugins = new MavenReportPluginContainer(); - } - - public MavenReporting.Builder excludeDefaults(boolean excludeDefaults) { - this.excludeDefaults = excludeDefaults; - return this; - } - - public MavenReporting.Builder outputDirectory(String outputDirectory) { - this.outputDirectory = outputDirectory; - return this; - } - - public MavenReporting.Builder reportPlugins(Consumer reportPlugins) { - reportPlugins.accept(this.reportPlugins); - return this; - } - - public MavenReporting build() { - return new MavenReporting(this); - } - - } - -} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildTests.java index b602be84..20a8eee6 100644 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildTests.java @@ -140,24 +140,45 @@ class MavenBuildTests { } @Test - void mavenProfilesCanBeConfigured() { + void mavenProfileCanBeConfigured() { MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", - (profile) -> profile.activation((activation) -> activation.activeByDefault(true))); - assertThat(build.profiles().values()).hasOnlyOneElementSatisfying((profile) -> { - assertThat(profile.getId()).isEqualTo("profile1"); - assertThat(profile.getActivation()).isNotNull(); - assertThat(profile.getActivation().getActiveByDefault()).isTrue(); - assertThat(profile.getBuild()).isNull(); - assertThat(profile.getModules()).isNull(); - assertThat(profile.getRepositories().isEmpty()).isTrue(); - assertThat(profile.getPluginRepositories().isEmpty()).isTrue(); - assertThat(profile.getDependencies().isEmpty()).isTrue(); - assertThat(profile.getReporting()).isNull(); - assertThat(profile.getDependencyManagement().isEmpty()).isTrue(); - assertThat(profile.getDistributionManagement().isEmpty()).isTrue(); - assertThat(profile.getProperties()).isNull(); + build.profiles().id("test").activation().jdk("15"); + build.profiles().id("test").properties().property("test", "value"); + assertThat(build.profiles().values()).singleElement().satisfies((profile) -> { + assertThat(profile.getActivation().getActiveByDefault()).isNull(); + assertThat(profile.getActivation().getJdk()).isEqualTo("15"); + assertThat(profile.getActivation().getOs()).isNull(); + assertThat(profile.getActivation().getProperty()).isNull(); + assertThat(profile.getActivation().getFile()).isNull(); + assertThat(profile.properties().values()).singleElement().satisfies((property) -> { + assertThat(property.getKey()).isEqualTo("test"); + assertThat(property.getValue()).isEqualTo("value"); + }); }); } + @Test + void mavenProfileActivationCanBeAmended() { + MavenBuild build = new MavenBuild(); + build.profiles().id("test").activation().jdk("15"); + build.profiles().id("test").activation().jdk(null).activeByDefault(true); + assertThat(build.profiles().values()).singleElement().satisfies((profile) -> { + assertThat(profile.getActivation().getActiveByDefault()).isTrue(); + assertThat(profile.getActivation().getJdk()).isNull(); + assertThat(profile.getActivation().getOs()).isNull(); + assertThat(profile.getActivation().getProperty()).isNull(); + assertThat(profile.getActivation().getFile()).isNull(); + }); + } + + @Test + void mavenProfileCanBeRemoved() { + MavenBuild build = new MavenBuild(); + build.profiles().id("test").activation().jdk("15"); + assertThat(build.profiles().ids()).containsOnly("test"); + build.profiles().remove("test"); + assertThat(build.profiles().ids()).isEmpty(); + assertThat(build.profiles().values()).isEmpty(); + } + } diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriterTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriterTests.java index f41c1f41..3ffb6c3e 100644 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriterTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriterTests.java @@ -862,31 +862,33 @@ class MavenBuildWriterTests { } @Test - void powWithProfile() { + void pomWithNoProfile() { MavenBuild build = new MavenBuild(); - build.profiles().add("profile1"); + build.settings().coordinates("com.example.demo", "demo"); + generatePom(build, (pom) -> assertThat(pom).textAtPath("/project/profiles/").isNullOrEmpty()); + } + + @Test + void powWithEmptyProfile() { + MavenBuild build = new MavenBuild(); + build.profiles().id("profile1"); generatePom(build, (pom) -> { NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); assertThat(profile).textAtPath("id").isEqualTo("profile1"); assertThat(profile).nodeAtPath("activation").isNull(); assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); assertThat(profile).nodeAtPath("repositories").isNull(); assertThat(profile).nodeAtPath("pluginRepositories").isNull(); assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); assertThat(profile).nodeAtPath("dependencyManagement").isNull(); assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); }); } @Test - void powWithProfileActivationActiveByDefaultJDK() { + void powWithProfileActivationActiveByDefaultAndJdk() { MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", - (profile) -> profile.activation((activation) -> activation.activeByDefault(true).jdk("11"))); - + build.profiles().id("profile1").activation().activeByDefault(true).jdk("11"); generatePom(build, (pom) -> { NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); assertThat(profile).textAtPath("id").isEqualTo("profile1"); @@ -895,150 +897,88 @@ class MavenBuildWriterTests { assertThat(profile).nodeAtPath("activation/os").isNull(); assertThat(profile).nodeAtPath("activation/property").isNull(); assertThat(profile).nodeAtPath("activation/file").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); }); } @Test - void powWithProfileActivationOS() { + void powWithProfileActivationOs() { MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", (profile) -> profile.activation( - (activation) -> activation.os((os) -> os.version("1.0").name("linux").arch("x68").family("intel")))); - + build.profiles().id("profile1").activation().os("linux", "intel", "x68", "1.0"); generatePom(build, (pom) -> { NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); assertThat(profile).textAtPath("id").isEqualTo("profile1"); - assertThat(profile).textAtPath("activation/os/version").isEqualTo("1.0"); + assertThat(profile).nodeAtPath("activation/jdk").isNull(); assertThat(profile).textAtPath("activation/os/name").isEqualTo("linux"); - assertThat(profile).textAtPath("activation/os/arch").isEqualTo("x68"); assertThat(profile).textAtPath("activation/os/family").isEqualTo("intel"); + assertThat(profile).textAtPath("activation/os/arch").isEqualTo("x68"); + assertThat(profile).textAtPath("activation/os/version").isEqualTo("1.0"); assertThat(profile).nodeAtPath("activation/property").isNull(); assertThat(profile).nodeAtPath("activation/file").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); }); } @Test void powWithProfileActivationProperty() { MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", (profile) -> profile - .activation((activation) -> activation.property((property) -> property.name("name1").value("value1")))); - + build.profiles().id("profile1").activation().property("name1", "value1"); generatePom(build, (pom) -> { NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); assertThat(profile).textAtPath("id").isEqualTo("profile1"); - assertThat(profile).textAtPath("activation/property/value").isEqualTo("value1"); - assertThat(profile).textAtPath("activation/property/name").isEqualTo("name1"); + assertThat(profile).nodeAtPath("activation/jdk").isNull(); assertThat(profile).nodeAtPath("activation/os").isNull(); + assertThat(profile).textAtPath("activation/property/name").isEqualTo("name1"); + assertThat(profile).textAtPath("activation/property/value").isEqualTo("value1"); assertThat(profile).nodeAtPath("activation/file").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); }); } @Test - void powWithProfileActivationFile() { + void powWithProfileActivationFileExists() { MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", (profile) -> profile - .activation((activation) -> activation.file((file) -> file.exists("true").missing("false")))); - + build.profiles().id("profile1").activation().fileExists("test.txt"); generatePom(build, (pom) -> { NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); assertThat(profile).textAtPath("id").isEqualTo("profile1"); - assertThat(profile).textAtPath("activation/file/exists").isEqualTo("true"); - assertThat(profile).textAtPath("activation/file/missing").isEqualTo("false"); + assertThat(profile).nodeAtPath("activation/jdk").isNull(); assertThat(profile).nodeAtPath("activation/os").isNull(); assertThat(profile).nodeAtPath("activation/property").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); + assertThat(profile).textAtPath("activation/file/exists").isEqualTo("test.txt"); + assertThat(profile).nodeAtPath("activation/file/missing").isNull(); }); } @Test - void powWithProfileBuild() { + void powWithProfileActivationFileMissing() { MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", profile -> profile.build( - (profileBuild) -> profileBuild.defaultGoal("compile").directory("/directory").finalName("build.txt"))); + build.profiles().id("profile1").activation().fileMissing("test.txt"); + generatePom(build, (pom) -> { + NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); + assertThat(profile).textAtPath("id").isEqualTo("profile1"); + assertThat(profile).nodeAtPath("activation/jdk").isNull(); + assertThat(profile).nodeAtPath("activation/os").isNull(); + assertThat(profile).nodeAtPath("activation/property").isNull(); + assertThat(profile).nodeAtPath("activation/file/exists").isNull(); + assertThat(profile).textAtPath("activation/file/missing").isEqualTo("test.txt"); + }); + } + @Test + void powWithProfileSettings() { + MavenBuild build = new MavenBuild(); + build.profiles().id("profile1").settings().defaultGoal("compile").finalName("app"); generatePom(build, (pom) -> { NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); assertThat(profile).textAtPath("id").isEqualTo("profile1"); assertThat(profile).textAtPath("build/defaultGoal").isEqualTo("compile"); - assertThat(profile).textAtPath("build/directory").isEqualTo("/directory"); - assertThat(profile).textAtPath("build/fileName").isEqualTo("build.txt"); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); + assertThat(profile).textAtPath("build/finalName").isEqualTo("app"); }); } @Test - void powWithProfileBuildFilters() { + void pomWithProfileResources() { MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", - profile -> profile.build((profileBuild) -> profileBuild.filter("filter1").filter("filter2"))); - - generatePom(build, (pom) -> { - NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); - assertThat(profile).textAtPath("id").isEqualTo("profile1"); - NodeAssert filters = profile.nodeAtPath("build/filters"); - filters.nodesAtPath("filter").hasSize(2); - assertThat(filters).textAtPath("filter[1]").isEqualTo("filter1"); - assertThat(filters).textAtPath("filter[2]").isEqualTo("filter2"); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); - }); - } - - @Test - void powWithProfileBuildResources() { - MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", profile -> profile.build((profileBuild) -> profileBuild.resources( - (resources) -> resources.add("src/main/custom", (resource) -> resource.includes("**/*.properties"))))); - + build.profiles().id("profile1").resources().add("src/main/custom", + (resource) -> resource.includes("**/*.properties")); generatePom(build, (pom) -> { NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); assertThat(profile).textAtPath("id").isEqualTo("profile1"); @@ -1048,26 +988,14 @@ class MavenBuildWriterTests { assertThat(profile).textAtPath("build/resources/resource/includes/include").isEqualTo("**/*.properties"); assertThat(profile).textAtPath("build/resources/resource/excludes").isNullOrEmpty(); assertThat(profile).textAtPath("build/testResources").isNullOrEmpty(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); }); } @Test - void powWithProfileBuildTestResources() { + void pomWithProfileTestResources() { MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", - profile -> profile.build( - (profileBuild) -> profileBuild.testResources((resources) -> resources.add("src/test/custom", - (resource) -> resource.excludes("**/*.gen").filtering(true).targetPath("test"))))); - + build.profiles().id("profile1").testResources().add("src/test/custom", + (resource) -> resource.excludes("**/*.gen").filtering(true).targetPath("test")); generatePom(build, (pom) -> { NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); assertThat(profile).textAtPath("id").isEqualTo("profile1"); @@ -1077,51 +1005,13 @@ class MavenBuildWriterTests { assertThat(profile).textAtPath("build/testResources/testResource/filtering").isEqualTo("true"); assertThat(profile).textAtPath("build/testResources/testResource/includes").isNullOrEmpty(); assertThat(profile).textAtPath("build/testResources/testResource/excludes/exclude").isEqualTo("**/*.gen"); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); }); } @Test - void powWithProfileBuildPluginManagement() { + void pomWithProfilePlugin() { MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", profile -> profile - .build((profileBuild) -> profileBuild.pluginManagement((pluginManagement) -> pluginManagement - .plugins((plugins) -> plugins.add("org.springframework.boot", "spring-boot-maven-plugin"))))); - - generatePom(build, (pom) -> { - NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); - assertThat(profile).textAtPath("id").isEqualTo("profile1"); - NodeAssert plugin = profile.nodeAtPath("build/pluginManagement/plugins/plugin"); - assertThat(plugin).textAtPath("groupId").isEqualTo("org.springframework.boot"); - assertThat(plugin).textAtPath("artifactId").isEqualTo("spring-boot-maven-plugin"); - assertThat(plugin).textAtPath("version").isNullOrEmpty(); - assertThat(plugin).textAtPath("extensions").isNullOrEmpty(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); - }); - } - - @Test - void powWithProfileBuildPlugin() { - MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", profile -> profile.build((profileBuild) -> profileBuild - .plugins((plugins) -> plugins.add("org.springframework.boot", "spring-boot-maven-plugin")))); - + build.profiles().id("profile1").plugins().add("org.springframework.boot", "spring-boot-maven-plugin"); generatePom(build, (pom) -> { NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); assertThat(profile).textAtPath("id").isEqualTo("profile1"); @@ -1130,266 +1020,22 @@ class MavenBuildWriterTests { assertThat(plugin).textAtPath("artifactId").isEqualTo("spring-boot-maven-plugin"); assertThat(plugin).textAtPath("version").isNullOrEmpty(); assertThat(plugin).textAtPath("extensions").isNullOrEmpty(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); }); } @Test - void powWithProfileModules() { + void pomWithProfileDistributionManagement() { MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", profile -> profile.module("module1").module("module2")); - - generatePom(build, (pom) -> { - NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); - assertThat(profile).textAtPath("id").isEqualTo("profile1"); - NodeAssert filters = profile.nodeAtPath("modules"); - filters.nodesAtPath("module").hasSize(2); - assertThat(filters).textAtPath("module[1]").isEqualTo("module1"); - assertThat(filters).textAtPath("module[2]").isEqualTo("module2"); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); - }); - } - - @Test - void powWithProfileRepositories() { - MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", - profile -> profile.repositories((repositories) -> repositories - .add(MavenRepository.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone") - .name("Spring Milestones")))); - - generatePom(build, (pom) -> { - NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); - assertThat(profile).textAtPath("id").isEqualTo("profile1"); - assertThat(profile).textAtPath("repositories/repository/id").isEqualTo("spring-milestones"); - assertThat(profile).textAtPath("repositories/repository/name").isEqualTo("Spring Milestones"); - assertThat(profile).textAtPath("repositories/repository/url").isEqualTo("https://repo.spring.io/milestone"); - assertThat(profile).nodeAtPath("repositories/repository/snapshots").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); - }); - } - - @Test - void powWithProfilePluginRepositories() { - MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", - profile -> profile.pluginRepositories((repositories) -> repositories - .add(MavenRepository.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone") - .name("Spring Milestones")))); - - generatePom(build, (pom) -> { - NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); - assertThat(profile).textAtPath("id").isEqualTo("profile1"); - assertThat(profile).textAtPath("pluginRepositories/pluginRepository/id").isEqualTo("spring-milestones"); - assertThat(profile).textAtPath("pluginRepositories/pluginRepository/name").isEqualTo("Spring Milestones"); - assertThat(profile).textAtPath("pluginRepositories/pluginRepository/url") - .isEqualTo("https://repo.spring.io/milestone"); - assertThat(profile).nodeAtPath("repositories/repository/snapshots").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("dependencies").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); - }); - } - - @Test - void powWithProfileDependencies() { - MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", profile -> profile.dependencies((dependencies) -> dependencies.add("root", - "org.springframework.boot", "spring-boot-starter", DependencyScope.COMPILE))); - - generatePom(build, (pom) -> { - NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); - assertThat(profile).textAtPath("id").isEqualTo("profile1"); - NodeAssert dependency = profile.nodeAtPath("dependencies/dependency"); - assertThat(dependency).textAtPath("groupId").isEqualTo("org.springframework.boot"); - assertThat(dependency).textAtPath("artifactId").isEqualTo("spring-boot-starter"); - assertThat(dependency).textAtPath("version").isNullOrEmpty(); - assertThat(dependency).textAtPath("scope").isNullOrEmpty(); - assertThat(dependency).textAtPath("optional").isNullOrEmpty(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); - }); - } - - @Test - void powWithProfileReporting() { - MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", - profile -> profile.reporting((reporting) -> reporting.excludeDefaults(true).outputDirectory("/here"))); - - generatePom(build, (pom) -> { - NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); - assertThat(profile).textAtPath("id").isEqualTo("profile1"); - assertThat(profile).textAtPath("reporting/excludeDefaults").isEqualTo("true"); - assertThat(profile).textAtPath("reporting/outputDirectory").isEqualTo("/here"); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); - }); - } - - @Test - void powWithProfileReportingPlugin() { - MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", profile -> profile.reporting( - (reporting) -> reporting.reportPlugins((reportPlugins) -> reportPlugins.add("org.apache.maven.plugins", - "maven-project-info-reports-plugin", (plugin) -> plugin.version("2.6").inherited("true") - .configuration((configuration) -> configuration.add("config1", "value1")))))); - - generatePom(build, (pom) -> { - NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); - assertThat(profile).textAtPath("id").isEqualTo("profile1"); - NodeAssert plugin = profile.nodeAtPath("reporting/plugins/plugin"); - assertThat(plugin).textAtPath("groupId").isEqualTo("org.apache.maven.plugins"); - assertThat(plugin).textAtPath("artifactId").isEqualTo("maven-project-info-reports-plugin"); - assertThat(plugin).textAtPath("version").isEqualTo("2.6"); - assertThat(plugin).textAtPath("inherited").isEqualTo("true"); - assertThat(plugin).textAtPath("configuration/config1").isEqualTo("value1"); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); - }); - } - - @Test - void powWithProfileReportingPluginReportSets() { - MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", profile -> profile.reporting((reporting) -> reporting.reportPlugins( - (reportPlugins) -> reportPlugins.add("org.apache.maven.plugins", "maven-project-info-reports-plugin", - (plugin) -> plugin.reportSets((reportSets -> reportSets.add("reportSet1", - (reportSet) -> reportSet.inherited("true").report("reportA").configuration( - (configuration) -> configuration.add("config1", "value1"))))))))); - - generatePom(build, (pom) -> { - NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); - assertThat(profile).textAtPath("id").isEqualTo("profile1"); - NodeAssert reportSet = profile.nodeAtPath("reporting/plugins/plugin/reportSets/reportSet"); - assertThat(reportSet).textAtPath("id").isEqualTo("reportSet1"); - assertThat(reportSet).textAtPath("inherited").isEqualTo("true"); - assertThat(reportSet).textAtPath("reports/report").isEqualTo("reportA"); - assertThat(reportSet).textAtPath("configuration/config1").isEqualTo("value1"); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("dependencyManagement").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); - }); - } - - @Test - void powWithProfileDependencyManagement() { - MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", - profile -> profile.dependencyManagement((dependencyManagement) -> dependencyManagement.add("test", - BillOfMaterials.withCoordinates("com.example", "my-project-dependencies") - .version(VersionReference.ofValue("1.0.0.RELEASE"))))); - - generatePom(build, (pom) -> { - NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); - assertThat(profile).textAtPath("id").isEqualTo("profile1"); - NodeAssert dependency = profile.nodeAtPath("dependencyManagement/dependencies/dependency"); - assertBom(dependency, "com.example", "my-project-dependencies", "1.0.0.RELEASE"); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); - }); - } - - @Test - void powWithProfileDistributionManagement() { - MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", profile -> profile - .distributionManagement((distribution) -> distribution.downloadUrl("https://example.com/download"))); - + build.profiles().id("profile1").distributionManagement().downloadUrl("https://example.com/download"); generatePom(build, (pom) -> { NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); assertThat(profile).textAtPath("id").isEqualTo("profile1"); NodeAssert distributionManagement = profile.nodeAtPath("distributionManagement"); assertThat(distributionManagement).textAtPath("downloadUrl").isEqualTo("https://example.com/download"); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("properties").isNull(); - }); - } - - @Test - void powWithProfileProperties() { - MavenBuild build = new MavenBuild(); - build.profiles().add("profile1", - profile -> profile.properties((properties) -> properties.add("prop1", "prop2"))); - - generatePom(build, (pom) -> { - NodeAssert profile = pom.nodeAtPath("/project/profiles/profile"); - assertThat(profile).textAtPath("id").isEqualTo("profile1"); - NodeAssert properties = profile.nodeAtPath("properties"); - assertThat(properties).textAtPath("prop1").isEqualTo("prop2"); - assertThat(profile).nodeAtPath("reporting").isNull(); - assertThat(profile).nodeAtPath("repositories").isNull(); - assertThat(profile).nodeAtPath("build").isNull(); - assertThat(profile).nodeAtPath("activation").isNull(); - assertThat(profile).nodeAtPath("modules").isNull(); - assertThat(profile).nodeAtPath("pluginRepositories").isNull(); - assertThat(profile).nodeAtPath("distributionManagement").isNull(); + assertThat(distributionManagement).nodeAtPath("repository").isNull(); + assertThat(distributionManagement).nodeAtPath("snapshotRepository").isNull(); + assertThat(distributionManagement).nodeAtPath("site").isNull(); + assertThat(distributionManagement).nodeAtPath("relocation").isNull(); }); } diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginTests.java index d1b60cb7..823c3d79 100644 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginTests.java @@ -19,7 +19,7 @@ package io.spring.initializr.generator.buildsystem.maven; import java.util.List; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Builder; -import io.spring.initializr.generator.buildsystem.maven.MavenConfiguration.Setting; +import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -37,10 +37,10 @@ class MavenPluginTests { MavenPlugin plugin = plugin("com.example", "test-plugin") .configuration((configuration) -> configuration.add("enabled", "false").add("skip", "true")) .configuration((configuration) -> configuration.add("another", "test")).build(); - assertThat(plugin.getConfiguration().getSettings().stream().map(MavenConfiguration.Setting::getName)) - .containsExactly("enabled", "skip", "another"); - assertThat(plugin.getConfiguration().getSettings().stream().map(MavenConfiguration.Setting::getValue)) - .containsExactly("false", "true", "test"); + assertThat(plugin.getConfiguration().getSettings().stream().map(Setting::getName)).containsExactly("enabled", + "skip", "another"); + assertThat(plugin.getConfiguration().getSettings().stream().map(Setting::getValue)).containsExactly("false", + "true", "test"); } @Test @@ -48,10 +48,10 @@ class MavenPluginTests { MavenPlugin plugin = plugin("com.example", "test-plugin") .configuration((configuration) -> configuration.add("enabled", "true")) .configuration((configuration) -> configuration.add("skip", "false")).build(); - assertThat(plugin.getConfiguration().getSettings().stream().map(MavenConfiguration.Setting::getName)) - .containsExactly("enabled", "skip"); - assertThat(plugin.getConfiguration().getSettings().stream().map(MavenConfiguration.Setting::getValue)) - .containsExactly("true", "false"); + assertThat(plugin.getConfiguration().getSettings().stream().map(Setting::getName)).containsExactly("enabled", + "skip"); + assertThat(plugin.getConfiguration().getSettings().stream().map(Setting::getValue)).containsExactly("true", + "false"); } @Test @@ -66,8 +66,8 @@ class MavenPluginTests { assertThat(setting.getName()).isEqualTo("items"); assertThat(setting.getValue()).isInstanceOf(List.class); List values = (List) setting.getValue(); - assertThat(values.stream().map(MavenConfiguration.Setting::getName)).containsExactly("item", "item"); - assertThat(values.stream().map(MavenConfiguration.Setting::getValue)).containsExactly("one", "two"); + assertThat(values.stream().map(Setting::getName)).containsExactly("item", "item"); + assertThat(values.stream().map(Setting::getValue)).containsExactly("one", "two"); } @Test @@ -92,9 +92,8 @@ class MavenPluginTests { assertThat(item.getName()).isEqualTo("item"); assertThat(item.getValue()).isInstanceOf(List.class); List subItems = (List) item.getValue(); - assertThat(subItems.stream().map(MavenConfiguration.Setting::getName)).containsExactly("subItem", "subItem", - "subItem"); - assertThat(subItems.stream().map(MavenConfiguration.Setting::getValue)).containsExactly("one", "two", "three"); + assertThat(subItems.stream().map(Setting::getName)).containsExactly("subItem", "subItem", "subItem"); + assertThat(subItems.stream().map(Setting::getValue)).containsExactly("one", "two", "three"); } @Test @@ -133,8 +132,8 @@ class MavenPluginTests { .build(); assertThat(plugin.getExecutions()).hasSize(1); List settings = plugin.getExecutions().get(0).getConfiguration().getSettings(); - assertThat(settings.stream().map(MavenConfiguration.Setting::getName)).containsExactly("enabled", "another"); - assertThat(settings.stream().map(MavenConfiguration.Setting::getValue)).containsExactly("true", "test"); + assertThat(settings.stream().map(Setting::getName)).containsExactly("enabled", "another"); + assertThat(settings.stream().map(Setting::getValue)).containsExactly("true", "test"); } private MavenPlugin.Builder plugin(String groupId, String artifactId) { diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFileTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFileTests.java deleted file mode 100644 index 4545251f..00000000 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationFileTests.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class MavenProfileActivationFileTests { - - @Test - void profileActivationFileEmpty() { - MavenProfileActivationFile profileActivationFile = new MavenProfileActivationFile.Builder().build(); - assertThat(profileActivationFile.getExists()).isNull(); - assertThat(profileActivationFile.getMissing()).isNull(); - } - - @Test - void profileActivationFileWithFullData() { - MavenProfileActivationFile profileActivationFile = new MavenProfileActivationFile.Builder().exists("exists1") - .missing("missing1").build(); - - assertThat(profileActivationFile.getExists()).isEqualTo("exists1"); - assertThat(profileActivationFile.getMissing()).isEqualTo("missing1"); - } - -} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOSTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOSTests.java deleted file mode 100644 index 56a89360..00000000 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationOSTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class MavenProfileActivationOSTests { - - @Test - void profileActivationOSEmpty() { - MavenProfileActivationOS profileActivationOS = new MavenProfileActivationOS.Builder().build(); - assertThat(profileActivationOS.getName()).isNull(); - assertThat(profileActivationOS.getFamily()).isNull(); - assertThat(profileActivationOS.getArch()).isNull(); - assertThat(profileActivationOS.getVersion()).isNull(); - } - - @Test - void profileActivationOSWithFullData() { - MavenProfileActivationOS profileActivationOS = new MavenProfileActivationOS.Builder().name("name1") - .family("family1").arch("arch1").version("version1").build(); - - assertThat(profileActivationOS.getName()).isEqualTo("name1"); - assertThat(profileActivationOS.getFamily()).isEqualTo("family1"); - assertThat(profileActivationOS.getArch()).isEqualTo("arch1"); - assertThat(profileActivationOS.getVersion()).isEqualTo("version1"); - } - -} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationPropertyTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationPropertyTests.java deleted file mode 100644 index f823c4f8..00000000 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationPropertyTests.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class MavenProfileActivationPropertyTests { - - @Test - void profileActivationPropertyEmpty() { - MavenProfileActivationProperty profileActivationProperty = new MavenProfileActivationProperty.Builder().build(); - assertThat(profileActivationProperty.getName()).isNull(); - assertThat(profileActivationProperty.getValue()).isNull(); - } - - @Test - void profileActivationPropertyWithFullData() { - MavenProfileActivationProperty profileActivationProperty = new MavenProfileActivationProperty.Builder() - .name("name1").value("value1").build(); - - assertThat(profileActivationProperty.getName()).isEqualTo("name1"); - assertThat(profileActivationProperty.getValue()).isEqualTo("value1"); - } - -} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationTests.java index 9a48dfc5..e87d05ba 100644 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileActivationTests.java @@ -16,36 +16,99 @@ package io.spring.initializr.generator.buildsystem.maven; +import io.spring.initializr.generator.buildsystem.maven.MavenProfileActivation.Builder; +import io.spring.initializr.generator.buildsystem.maven.MavenProfileActivation.Os; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -class MavenProfileActivationTests { +/** + * Tests for {@link MavenProfileActivation}. + */ +public class MavenProfileActivationTests { @Test - void profileActivationEmpty() { - MavenProfileActivation profileActivation = new MavenProfileActivation.Builder().build(); - assertThat(profileActivation.getActiveByDefault()).isNull(); - assertThat(profileActivation.getJdk()).isNull(); - assertThat(profileActivation.getOs()).isNull(); - assertThat(profileActivation.getProperty()).isNull(); - assertThat(profileActivation.getFile()).isNull(); + void profileWithNoActivation() { + assertThat(createProfileActivation().build().isEmpty()).isTrue(); } @Test - void profileActivationWithFullData() { - MavenProfileActivation profileActivation = new MavenProfileActivation.Builder().jdk("jdk1") - .activeByDefault(true).os((os) -> os.name("name1")).file((file) -> file.exists("yes")) - .property((property) -> property.name("name1")).build(); + void profileActiveByDefault() { + assertThat(createProfileActivation().activeByDefault(true).build().getActiveByDefault()).isTrue(); + } - assertThat(profileActivation.getActiveByDefault()).isTrue(); - assertThat(profileActivation.getJdk()).isEqualTo("jdk1"); - assertThat(profileActivation.getOs()).isNotNull(); - assertThat(profileActivation.getOs().getName()).isEqualTo("name1"); - assertThat(profileActivation.getProperty()).isNotNull(); - assertThat(profileActivation.getProperty().getName()).isEqualTo("name1"); - assertThat(profileActivation.getFile()).isNotNull(); - assertThat(profileActivation.getFile().getExists()).isEqualTo("yes"); + @Test + void profileActiveByDefaultCanBeAmended() { + assertThat(createProfileActivation().activeByDefault(true).activeByDefault(null).build().getActiveByDefault()) + .isNull(); + } + + @Test + void profileActivationJdk() { + assertThat(createProfileActivation().jdk("15").build().getJdk()).isEqualTo("15"); + } + + @Test + void profileActivationCanBeAmended() { + assertThat(createProfileActivation().jdk("15").jdk(null).build().getJdk()).isNull(); + } + + @Test + void profileActivationOs() { + Os os = createProfileActivation().os("test-name", null, "arm64", null).build().getOs(); + assertThat(os).isNotNull(); + assertThat(os.getName()).isEqualTo("test-name"); + assertThat(os.getFamily()).isNull(); + assertThat(os.getArch()).isEqualTo("arm64"); + assertThat(os.getVersion()).isNull(); + } + + @Test + void profileActivationOsCanBeDisabled() { + assertThat( + createProfileActivation().os("test-name", null, null, null).os(null, null, null, null).build().getOs()) + .isNull(); + } + + @Test + void profileActivationProperty() { + assertThat(createProfileActivation().property("test", "1").build().getProperty()).satisfies((property) -> { + assertThat(property).isNotNull(); + assertThat(property.getName()).isEqualTo("test"); + assertThat(property.getValue()).isEqualTo("1"); + }); + } + + @Test + void profileActivationPropertyCanBeDisabled() { + assertThat(createProfileActivation().property("test", "1").property(null, null).build().getProperty()).isNull(); + } + + @Test + void profileActivationFileExisting() { + assertThat(createProfileActivation().fileExists("test.txt").build().getFile()).satisfies((file) -> { + assertThat(file).isNotNull(); + assertThat(file.getExists()).isEqualTo("test.txt"); + assertThat(file.getMissing()).isNull(); + }); + } + + @Test + void profileActivationFileMissing() { + assertThat(createProfileActivation().fileMissing("test.txt").build().getFile()).satisfies((file) -> { + assertThat(file).isNotNull(); + assertThat(file.getExists()).isNull(); + assertThat(file.getMissing()).isEqualTo("test.txt"); + }); + } + + @Test + void profileActivationFileCanBeDisabled() { + assertThat(createProfileActivation().fileMissing("test.txt").fileMissing(null).build().getFile()).isNull(); + } + + private MavenProfileActivation.Builder createProfileActivation() { + return new Builder(); } } diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuildTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuildTests.java deleted file mode 100644 index 0fe89ec0..00000000 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileBuildTests.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.Test; - -import java.util.Arrays; - -class MavenProfileBuildTests { - - @Test - void profileBuildEmpty() { - MavenProfileBuild profileBuild = new MavenProfileBuild.Builder().build(); - assertThat(profileBuild.getDefaultGoal()).isNull(); - assertThat(profileBuild.getDirectory()).isNull(); - assertThat(profileBuild.getFinalName()).isNull(); - assertThat(profileBuild.getFilters()).isNull(); - assertThat(profileBuild.getResources().isEmpty()).isTrue(); - assertThat(profileBuild.getTestResources().isEmpty()).isTrue(); - assertThat(profileBuild.getPluginManagement()).isNull(); - assertThat(profileBuild.getPlugins().isEmpty()).isTrue(); - } - - @Test - void profileBuildWithFullData() { - MavenProfileBuild profileBuild = new MavenProfileBuild.Builder().defaultGoal("goal1").directory("directory1") - .finalName("file1").filter("filter1").filter("filter2") - .resources((resources) -> resources.add("resource1")) - .testResources((testResources) -> testResources.add("testResources1")) - .pluginManagement( - (pluginManagement) -> pluginManagement.plugins((plugins) -> plugins.add("com.example", "demo"))) - .plugins((plugins) -> plugins.add("com.example1", "demo1")).build(); - - assertThat(profileBuild.getDefaultGoal()).isEqualTo("goal1"); - assertThat(profileBuild.getDirectory()).isEqualTo("directory1"); - assertThat(profileBuild.getFinalName()).isEqualTo("file1"); - assertThat(profileBuild.getFilters()).isEqualTo(Arrays.asList("filter1", "filter2")); - assertThat(profileBuild.getResources()).isNotNull(); - assertThat(profileBuild.getResources().has("resource1")).isTrue(); - assertThat(profileBuild.getTestResources()).isNotNull(); - assertThat(profileBuild.getTestResources().has("testResources1")).isTrue(); - assertThat(profileBuild.getPluginManagement()).isNotNull(); - assertThat(profileBuild.getPluginManagement().getPlugins()).isNotNull(); - assertThat(profileBuild.getPluginManagement().getPlugins().has("com.example", "demo")).isTrue(); - assertThat(profileBuild.getPlugins()).isNotNull(); - assertThat(profileBuild.getPlugins().has("com.example1", "demo1")).isTrue(); - } - -} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainerTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainerTests.java index 1ff5acfe..39e5733b 100644 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainerTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileContainerTests.java @@ -16,153 +16,81 @@ package io.spring.initializr.generator.buildsystem.maven; +import io.spring.initializr.generator.buildsystem.BuildItemResolver; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.Arrays; import static org.assertj.core.api.Assertions.assertThat; -import io.spring.initializr.generator.buildsystem.BillOfMaterials; -import io.spring.initializr.generator.buildsystem.BuildItemResolver; -import io.spring.initializr.generator.buildsystem.Dependency; -import io.spring.initializr.generator.buildsystem.MavenRepository; - -@ExtendWith(MockitoExtension.class) +/** + * Tests for {@link MavenProfileContainer}. + */ class MavenProfileContainerTests { - @Mock - private BuildItemResolver buildItemResolver; - @Test - void addProfile() { - MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); - profileContainer.add("profile1"); - assertThat(profileContainer.values()).hasOnlyOneElementSatisfying((profile) -> { - assertThat(profile.getId()).isEqualTo("profile1"); - assertThat(profile.getActivation()).isNull(); - assertThat(profile.getBuild()).isNull(); - assertThat(profile.getModules()).isNull(); - assertThat(profile.getRepositories().isEmpty()).isTrue(); - assertThat(profile.getPluginRepositories().isEmpty()).isTrue(); - assertThat(profile.getDependencies().isEmpty()).isTrue(); - assertThat(profile.getReporting()).isNull(); - assertThat(profile.getDependencyManagement().isEmpty()).isTrue(); - assertThat(profile.getDistributionManagement().isEmpty()).isTrue(); - assertThat(profile.getProperties()).isNull(); - }); - } - - @Test - void addProfileWithConsumer() { - MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); - profileContainer.add("profile1", (profile) -> profile - .activation((activation) -> activation.activeByDefault(true)) - .build((build) -> build.defaultGoal("goal1")).module("module1").module("module2") - .repositories((repositories) -> repositories.add("repository1", - MavenRepository.withIdAndUrl("repository1", "url").build())) - .pluginRepositories((pluginRepositories) -> pluginRepositories.add("pluginRepository1", - MavenRepository.withIdAndUrl("pluginRepository1", "url2").build())) - .dependencies((dependencies) -> dependencies.add("dependency1", - Dependency.withCoordinates("com.example", "demo").build())) - .reporting((reporting) -> reporting.outputDirectory("directory1")) - .dependencyManagement((dependencyManagement) -> dependencyManagement.add("dependencyManagement1", - BillOfMaterials.withCoordinates("com.example1", "demo1").build())) - .distributionManagement((distributionManagement) -> distributionManagement.downloadUrl("url")) - .properties((properties) -> properties.add("name1", "value1"))); - - assertThat(profileContainer.values()).hasOnlyOneElementSatisfying((profile) -> { - assertThat(profile.getId()).isEqualTo("profile1"); - assertThat(profile.getActivation()).isNotNull(); - assertThat(profile.getActivation().getActiveByDefault()).isTrue(); - assertThat(profile.getBuild()).isNotNull(); - assertThat(profile.getBuild().getDefaultGoal()).isEqualTo("goal1"); - assertThat(profile.getModules()).isNotNull(); - assertThat(profile.getModules()).isEqualTo(Arrays.asList("module1", "module2")); - assertThat(profile.getRepositories()).isNotNull(); - assertThat(profile.getRepositories().has("repository1")).isTrue(); - assertThat(profile.getPluginRepositories()).isNotNull(); - assertThat(profile.getPluginRepositories().has("pluginRepository1")).isTrue(); - assertThat(profile.getDependencies()).isNotNull(); - assertThat(profile.getDependencies().has("dependency1")).isTrue(); - assertThat(profile.getReporting()).isNotNull(); - assertThat(profile.getReporting().getOutputDirectory()).isEqualTo("directory1"); - assertThat(profile.getDependencyManagement()).isNotNull(); - assertThat(profile.getDependencyManagement().has("dependencyManagement1")).isTrue(); - assertThat(profile.getProperties()).isNotNull(); - assertThat(profile.getProperties().getSettings()).hasOnlyOneElementSatisfying((settings) -> { - assertThat(settings.getName()).isEqualTo("name1"); - assertThat(settings.getValue()).isEqualTo("value1"); - }); - }); - } - - @Test - void addProfileSeveralTimeReuseConfiguration() { - MavenProfileContainer profileContainer = new MavenProfileContainer(buildItemResolver); - profileContainer.add("profile1", - (profile) -> profile.activation((activation) -> activation.activeByDefault(true))); - profileContainer.add("profile1", - (profile) -> profile.activation((activation) -> activation.activeByDefault(false))); - assertThat(profileContainer.values()).hasOnlyOneElementSatisfying((profile) -> { - assertThat(profile.getId()).isEqualTo("profile1"); - assertThat(profile.getActivation()).isNotNull(); - assertThat(profile.getActivation().getActiveByDefault()).isFalse(); - assertThat(profile.getBuild()).isNull(); - assertThat(profile.getModules()).isNull(); - assertThat(profile.getRepositories().isEmpty()).isTrue(); - assertThat(profile.getPluginRepositories().isEmpty()).isTrue(); - assertThat(profile.getDependencies().isEmpty()).isTrue(); - assertThat(profile.getReporting()).isNull(); - assertThat(profile.getDependencyManagement().isEmpty()).isTrue(); - assertThat(profile.getDistributionManagement().isEmpty()).isTrue(); - assertThat(profile.getProperties()).isNull(); - }); + void profileWithSameIdReturnSameInstance() { + MavenProfileContainer container = createTestContainer(); + MavenProfile profile = container.id("profile1"); + assertThat(container.id("profile1")).isSameAs(profile); } @Test void isEmptyWithEmptyContainer() { - MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); - assertThat(profileContainer.isEmpty()).isTrue(); + MavenProfileContainer container = createTestContainer(); + assertThat(container.isEmpty()).isTrue(); } @Test void isEmptyWithRegisteredProfile() { - MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); - profileContainer.add("profile1"); - assertThat(profileContainer.isEmpty()).isFalse(); + MavenProfileContainer container = createTestContainer(); + container.id("profile1"); + assertThat(container.isEmpty()).isFalse(); + } + + @Test + void idsWithEmptyContainer() { + MavenProfileContainer container = createTestContainer(); + assertThat(container.ids()).isEmpty(); + } + + @Test + void idsWithRegisteredProfile() { + MavenProfileContainer container = createTestContainer(); + container.id("profile1"); + assertThat(container.ids()).containsOnly("profile1"); } @Test void hasProfileWithMatchingProfile() { - MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); - profileContainer.add("profile1"); - assertThat(profileContainer.has("profile1")).isTrue(); + MavenProfileContainer container = createTestContainer(); + container.id("profile1"); + assertThat(container.has("profile1")).isTrue(); } @Test void hasProfileWithNonMatchingProfile() { - MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); - profileContainer.add("profile1"); - assertThat(profileContainer.has("profile2")).isFalse(); + MavenProfileContainer container = createTestContainer(); + container.id("profile1"); + assertThat(container.has("profile2")).isFalse(); } @Test void removeWithMatchingProfile() { - MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); - profileContainer.add("profile1"); - assertThat(profileContainer.remove("profile1")).isTrue(); - assertThat(profileContainer.isEmpty()).isTrue(); + MavenProfileContainer container = createTestContainer(); + container.id("profile1"); + assertThat(container.remove("profile1")).isTrue(); + assertThat(container.isEmpty()).isTrue(); } @Test void removeWithNonMatchingProfile() { - MavenProfileContainer profileContainer = new MavenProfileContainer(this.buildItemResolver); - profileContainer.add("profile1"); - assertThat(profileContainer.remove("profile2")).isFalse(); - assertThat(profileContainer.isEmpty()).isFalse(); + MavenProfileContainer container = createTestContainer(); + container.id("profile1"); + assertThat(container.remove("profile2")).isFalse(); + assertThat(container.isEmpty()).isFalse(); + } + + private MavenProfileContainer createTestContainer() { + return new MavenProfileContainer(BuildItemResolver.NO_OP); } } diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileTests.java index 30fb82e2..57dcbb4f 100644 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenProfileTests.java @@ -16,81 +16,76 @@ package io.spring.initializr.generator.buildsystem.maven; -import java.util.Arrays; - -import io.spring.initializr.generator.buildsystem.BillOfMaterials; import io.spring.initializr.generator.buildsystem.BuildItemResolver; -import io.spring.initializr.generator.buildsystem.Dependency; -import io.spring.initializr.generator.buildsystem.MavenRepository; - +import io.spring.initializr.generator.buildsystem.maven.MavenProfile.Settings; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; -@ExtendWith(MockitoExtension.class) +/** + * Tests for {@link MavenProfile}. + */ class MavenProfileTests { - @Mock - private BuildItemResolver buildItemResolver; - @Test - void profileEmpty() { - MavenProfile profile = new MavenProfile.Builder("profile1", this.buildItemResolver).build(); - assertThat(profile.getId()).isEqualTo("profile1"); - assertThat(profile.getActivation()).isNull(); - assertThat(profile.getBuild()).isNull(); - assertThat(profile.getModules()).isNull(); - assertThat(profile.getRepositories().isEmpty()).isTrue(); - assertThat(profile.getPluginRepositories().isEmpty()).isTrue(); - assertThat(profile.getDependencies().isEmpty()).isTrue(); - assertThat(profile.getReporting()).isNull(); - assertThat(profile.getDependencyManagement().isEmpty()).isTrue(); + void profileWithNoCustomization() { + MavenProfile profile = createProfile("test"); + assertThat(profile.getId()).isEqualTo("test"); + assertThat(profile.getActivation().isEmpty()).isTrue(); + assertThat(profile.properties().isEmpty()).isTrue(); + assertThat(profile.dependencies().isEmpty()).isTrue(); + assertThat(profile.resources().isEmpty()).isTrue(); + assertThat(profile.testResources().isEmpty()).isTrue(); + assertThat(profile.plugins().isEmpty()).isTrue(); + assertThat(profile.boms().isEmpty()).isTrue(); + assertThat(profile.repositories().isEmpty()).isTrue(); + assertThat(profile.pluginRepositories().isEmpty()).isTrue(); assertThat(profile.getDistributionManagement().isEmpty()).isTrue(); - assertThat(profile.getProperties()).isNull(); } @Test - void profileWithFullData() { - MavenProfile profile = new MavenProfile.Builder("profile1", this.buildItemResolver) - .activation((activation) -> activation.activeByDefault(true)) - .build((build) -> build.defaultGoal("goal1")).module("module1").module("module2") - .repositories((repositories) -> repositories.add("repository1", - MavenRepository.withIdAndUrl("repository1", "url").build())) - .pluginRepositories((pluginRepositories) -> pluginRepositories.add("pluginRepository1", - MavenRepository.withIdAndUrl("pluginRepository1", "url2").build())) - .dependencies((dependencies) -> dependencies.add("dependency1", - Dependency.withCoordinates("com.example", "demo").build())) - .reporting((reporting) -> reporting.outputDirectory("directory1")) - .dependencyManagement((dependencyManagement) -> dependencyManagement.add("dependencyManagement1", - BillOfMaterials.withCoordinates("com.example1", "demo1").build())) - .distributionManagement((distributionManagement) -> distributionManagement.downloadUrl("url")) - .properties((properties) -> properties.add("name1", "value1")).build(); - - assertThat(profile.getId()).isEqualTo("profile1"); - assertThat(profile.getActivation()).isNotNull(); - assertThat(profile.getActivation().getActiveByDefault()).isTrue(); - assertThat(profile.getBuild()).isNotNull(); - assertThat(profile.getBuild().getDefaultGoal()).isEqualTo("goal1"); - assertThat(profile.getModules()).isNotNull(); - assertThat(profile.getModules()).isEqualTo(Arrays.asList("module1", "module2")); - assertThat(profile.getRepositories()).isNotNull(); - assertThat(profile.getRepositories().has("repository1")).isTrue(); - assertThat(profile.getPluginRepositories()).isNotNull(); - assertThat(profile.getPluginRepositories().has("pluginRepository1")).isTrue(); - assertThat(profile.getDependencies()).isNotNull(); - assertThat(profile.getDependencies().has("dependency1")).isTrue(); - assertThat(profile.getReporting()).isNotNull(); - assertThat(profile.getReporting().getOutputDirectory()).isEqualTo("directory1"); - assertThat(profile.getDependencyManagement()).isNotNull(); - assertThat(profile.getDependencyManagement().has("dependencyManagement1")).isTrue(); - assertThat(profile.getProperties()).isNotNull(); - assertThat(profile.getProperties().getSettings()).hasOnlyOneElementSatisfying((settings) -> { - assertThat(settings.getName()).isEqualTo("name1"); - assertThat(settings.getValue()).isEqualTo("value1"); + void profileWithActivation() { + MavenProfile profile = createProfile("test"); + profile.activation().jdk("15").property("test", "value").jdk(null); + assertThat(profile.getActivation().getProperty()).satisfies((property) -> { + assertThat(property.getName()).isEqualTo("test"); + assertThat(property.getValue()).isEqualTo("value"); }); + assertThat(profile.getActivation().getJdk()).isNull(); + } + + @Test + void profileWithDefaultGoal() { + MavenProfile profile = createProfile("test"); + profile.settings().defaultGoal("verify"); + Settings settings = profile.getSettings(); + assertThat(settings.getDefaultGoal()).isEqualTo("verify"); + assertThat(settings.getFinalName()).isNull(); + } + + @Test + void profileWithFinalName() { + MavenProfile profile = createProfile("test"); + profile.settings().finalName("test-app"); + Settings settings = profile.getSettings(); + assertThat(settings.getDefaultGoal()).isNull(); + assertThat(settings.getFinalName()).isEqualTo("test-app"); + } + + @Test + void profileWithDistributionManagement() { + MavenProfile profile = createProfile("test"); + profile.distributionManagement().downloadUrl("https://example.com/download"); + MavenDistributionManagement dm = profile.getDistributionManagement(); + assertThat(dm.getDownloadUrl()).isEqualTo("https://example.com/download"); + assertThat(dm.getRepository().isEmpty()).isTrue(); + assertThat(dm.getSnapshotRepository().isEmpty()).isTrue(); + assertThat(dm.getSite().isEmpty()).isTrue(); + assertThat(dm.getRepository().isEmpty()).isTrue(); + } + + private MavenProfile createProfile(String id) { + return new MavenProfile(id, BuildItemResolver.NO_OP); } } diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainerTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainerTests.java deleted file mode 100644 index ba38c3e4..00000000 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginContainerTests.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class MavenReportPluginContainerTests { - - @Test - void addReportPlugin() { - MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); - reportPluginContainer.add("com.example", "demo"); - assertThat(reportPluginContainer.values()).hasOnlyOneElementSatisfying((reportPlugin) -> { - assertThat(reportPlugin.getGroupId()).isEqualTo("com.example"); - assertThat(reportPlugin.getArtifactId()).isEqualTo("demo"); - assertThat(reportPlugin.getConfiguration()).isNull(); - assertThat(reportPlugin.getInherited()).isNull(); - assertThat(reportPlugin.getVersion()).isNull(); - assertThat(reportPlugin.getReportSets().isEmpty()).isTrue(); - }); - } - - @Test - void addReportPluginWithConsumer() { - MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); - reportPluginContainer.add("com.example", "demo", - (reportPlugin) -> reportPlugin.configuration((conf) -> conf.add("property1", "value1")) - .inherited("inherited1").version("version1") - .reportSets((reportSets) -> reportSets.add("reportSet1").add("reportSet2"))); - - assertThat(reportPluginContainer.values()).hasOnlyOneElementSatisfying((reportPlugin) -> { - assertThat(reportPlugin.getGroupId()).isEqualTo("com.example"); - assertThat(reportPlugin.getArtifactId()).isEqualTo("demo"); - assertThat(reportPlugin.getConfiguration().getSettings()).hasOnlyOneElementSatisfying((settings) -> { - assertThat(settings.getName()).isEqualTo("property1"); - assertThat(settings.getValue()).isEqualTo("value1"); - }); - assertThat(reportPlugin.getInherited()).isEqualTo("inherited1"); - assertThat(reportPlugin.getVersion()).isEqualTo("version1"); - assertThat(reportPlugin.getReportSets().has("reportSet1")).isTrue(); - assertThat(reportPlugin.getReportSets().has("reportSet2")).isTrue(); - }); - } - - @Test - void addReportPluginSeveralTimeReuseConfiguration() { - MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); - reportPluginContainer.add("com.example", "demo", (reportPlugin) -> reportPlugin.inherited("inherited1")); - reportPluginContainer.add("com.example", "demo", (reportPlugin) -> reportPlugin.inherited("inherited2")); - assertThat(reportPluginContainer.values()).hasOnlyOneElementSatisfying((reportPlugin) -> { - assertThat(reportPlugin.getGroupId()).isEqualTo("com.example"); - assertThat(reportPlugin.getArtifactId()).isEqualTo("demo"); - assertThat(reportPlugin.getConfiguration()).isNull(); - assertThat(reportPlugin.getInherited()).isEqualTo("inherited2"); - assertThat(reportPlugin.getVersion()).isNull(); - assertThat(reportPlugin.getReportSets().isEmpty()).isTrue(); - }); - } - - @Test - void isEmptyWithEmptyContainer() { - MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); - assertThat(reportPluginContainer.isEmpty()).isTrue(); - } - - @Test - void isEmptyWithRegisteredReportPlugin() { - MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); - reportPluginContainer.add("com.example", "demo"); - assertThat(reportPluginContainer.isEmpty()).isFalse(); - } - - @Test - void hasReportPluginWithMatchingReportPlugin() { - MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); - reportPluginContainer.add("com.example", "demo"); - assertThat(reportPluginContainer.has("com.example", "demo")).isTrue(); - } - - @Test - void hasReportPluginWithNonMatchingReportPlugin() { - MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); - reportPluginContainer.add("com.example", "demo"); - assertThat(reportPluginContainer.has("com.example", "demo1")).isFalse(); - } - - @Test - void removeWithMatchingReportPlugin() { - MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); - reportPluginContainer.add("com.example", "demo"); - assertThat(reportPluginContainer.remove("com.example", "demo")).isTrue(); - assertThat(reportPluginContainer.isEmpty()).isTrue(); - } - - @Test - void removeWithNonMatchingReportPlugin() { - MavenReportPluginContainer reportPluginContainer = new MavenReportPluginContainer(); - reportPluginContainer.add("com.example", "demo"); - assertThat(reportPluginContainer.remove("com.example", "demo2")).isFalse(); - assertThat(reportPluginContainer.isEmpty()).isFalse(); - } - -} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginTests.java deleted file mode 100644 index 6882c556..00000000 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportPluginTests.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class MavenReportPluginTests { - - @Test - void reportPluginWithGroupIdArtifactIdOnly() { - MavenReportPlugin reportPlugin = new MavenReportPlugin.Builder("com.example", "demo").build(); - - assertThat(reportPlugin.getGroupId()).isEqualTo("com.example"); - assertThat(reportPlugin.getArtifactId()).isEqualTo("demo"); - assertThat(reportPlugin.getConfiguration()).isNull(); - assertThat(reportPlugin.getInherited()).isNull(); - assertThat(reportPlugin.getVersion()).isNull(); - assertThat(reportPlugin.getReportSets().isEmpty()).isTrue(); - } - - @Test - void reportPluginWithFullData() { - MavenReportPlugin reportPlugin = new MavenReportPlugin.Builder("com.example", "demo") - .configuration((conf) -> conf.add("property1", "value1")).inherited("inherited1").version("version1") - .reportSets((reportSets) -> reportSets.add("reportSet1").add("reportSet2")).build(); - - assertThat(reportPlugin.getGroupId()).isEqualTo("com.example"); - assertThat(reportPlugin.getArtifactId()).isEqualTo("demo"); - assertThat(reportPlugin.getConfiguration().getSettings()).hasOnlyOneElementSatisfying((settings) -> { - assertThat(settings.getName()).isEqualTo("property1"); - assertThat(settings.getValue()).isEqualTo("value1"); - }); - assertThat(reportPlugin.getInherited()).isEqualTo("inherited1"); - assertThat(reportPlugin.getVersion()).isEqualTo("version1"); - assertThat(reportPlugin.getReportSets().has("reportSet1")).isTrue(); - assertThat(reportPlugin.getReportSets().has("reportSet2")).isTrue(); - } - -} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainerTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainerTests.java deleted file mode 100644 index b9028c0c..00000000 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetContainerTests.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.Test; - -import java.util.Arrays; - -class MavenReportSetContainerTests { - - @Test - void addReportSet() { - MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); - reportSetContainer.add("reportSet1"); - assertThat(reportSetContainer.values()).hasOnlyOneElementSatisfying((reportSet) -> { - assertThat(reportSet.getId()).isEqualTo("reportSet1"); - assertThat(reportSet.getInherited()).isNull(); - assertThat(reportSet.getReports()).isNull(); - assertThat(reportSet.getConfiguration()).isNull(); - }); - } - - @Test - void addReportSetWithConsumer() { - MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); - reportSetContainer.add("reportSet1", (reportSet) -> reportSet.inherited("inherited1").report("report1") - .report("report2").configuration((conf) -> conf.add("property1", "value1"))); - - assertThat(reportSetContainer.values()).hasOnlyOneElementSatisfying((reportSet) -> { - assertThat(reportSet.getId()).isEqualTo("reportSet1"); - assertThat(reportSet.getConfiguration().getSettings()).hasOnlyOneElementSatisfying((settings) -> { - assertThat(settings.getName()).isEqualTo("property1"); - assertThat(settings.getValue()).isEqualTo("value1"); - }); - assertThat(reportSet.getInherited()).isEqualTo("inherited1"); - assertThat(reportSet.getReports()).isEqualTo(Arrays.asList("report1", "report2")); - }); - } - - @Test - void addReportSetSeveralTimeReuseConfiguration() { - MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); - reportSetContainer.add("reportSet1", (reportSet) -> reportSet.inherited("inherited1")); - reportSetContainer.add("reportSet1", (reportSet) -> reportSet.inherited("inherited2")); - assertThat(reportSetContainer.values()).hasOnlyOneElementSatisfying((reportSet) -> { - assertThat(reportSet.getId()).isEqualTo("reportSet1"); - assertThat(reportSet.getInherited()).isEqualTo("inherited2"); - assertThat(reportSet.getReports()).isNull(); - assertThat(reportSet.getConfiguration()).isNull(); - }); - } - - @Test - void isEmptyWithEmptyContainer() { - MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); - assertThat(reportSetContainer.isEmpty()).isTrue(); - } - - @Test - void isEmptyWithRegisteredReportSet() { - MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); - reportSetContainer.add("reportSet1"); - assertThat(reportSetContainer.isEmpty()).isFalse(); - } - - @Test - void hasReportSetWithMatchingReportSet() { - MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); - reportSetContainer.add("reportSet1"); - assertThat(reportSetContainer.has("reportSet1")).isTrue(); - } - - @Test - void hasReportSetWithNonMatchingReportSet() { - MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); - reportSetContainer.add("reportSet1"); - assertThat(reportSetContainer.has("reportSet2")).isFalse(); - } - - @Test - void removeWithMatchingReportSet() { - MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); - reportSetContainer.add("reportSet1"); - assertThat(reportSetContainer.remove("reportSet1")).isTrue(); - assertThat(reportSetContainer.isEmpty()).isTrue(); - } - - @Test - void removeWithNonMatchingReportSet() { - MavenReportSetContainer reportSetContainer = new MavenReportSetContainer(); - reportSetContainer.add("reportSet1"); - assertThat(reportSetContainer.remove("reportSet2")).isFalse(); - assertThat(reportSetContainer.isEmpty()).isFalse(); - } - -} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetTests.java deleted file mode 100644 index 5be03f7b..00000000 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportSetTests.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Arrays; - -class MavenReportSetTests { - - @Test - void reportSetWithIdOnly() { - MavenReportSet reportSet = new MavenReportSet.Builder("id").build(); - assertThat(reportSet.getId()).isEqualTo("id"); - assertThat(reportSet.getConfiguration()).isNull(); - assertThat(reportSet.getInherited()).isNull(); - assertThat(reportSet.getReports()).isNull(); - } - - @Test - void reportSetWithFullData() { - MavenReportSet reportSet = new MavenReportSet.Builder("id") - .configuration((conf) -> conf.add("property1", "value1")).inherited("inherited1").report("report1") - .report("report2").build(); - - assertThat(reportSet.getId()).isEqualTo("id"); - assertThat(reportSet.getConfiguration().getSettings()).hasOnlyOneElementSatisfying((settings) -> { - assertThat(settings.getName()).isEqualTo("property1"); - assertThat(settings.getValue()).isEqualTo("value1"); - }); - assertThat(reportSet.getInherited()).isEqualTo("inherited1"); - assertThat(reportSet.getReports()).isEqualTo(Arrays.asList("report1", "report2")); - } - -} diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportingTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportingTests.java deleted file mode 100644 index a5a24b17..00000000 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenReportingTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.initializr.generator.buildsystem.maven; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class MavenReportingTests { - - @Test - void reportingEmpty() { - MavenReporting reporting = new MavenReporting.Builder().build(); - assertThat(reporting.getOutputDirectory()).isNull(); - assertThat(reporting.isExcludeDefaults()).isNull(); - assertThat(reporting.getReportPlugins().isEmpty()).isTrue(); - } - - @Test - void reportingWithFullData() { - MavenReporting reporting = new MavenReporting.Builder().excludeDefaults(true).outputDirectory("output") - .reportPlugins((reportPlugins) -> reportPlugins.add("com.example", "demo").add("com.example", "demo2")) - .build(); - - assertThat(reporting.isExcludeDefaults()).isTrue(); - assertThat(reporting.getOutputDirectory()).isEqualTo("output"); - assertThat(reporting.getReportPlugins().has("com.example", "demo")).isTrue(); - assertThat(reporting.getReportPlugins().has("com.example", "demo2")).isTrue(); - } - -}