Polish "Add support for Maven profiles"

See gh-1057
This commit is contained in:
Stephane Nicoll 2020-11-19 16:56:48 +01:00
parent cbea89910f
commit d22f820dd4
41 changed files with 991 additions and 2622 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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<String, BillOfMaterials> {
/**
* Create an instance with the specified {@code itemResolver}.
* @param itemResolver the function that returns a {@link BillOfMaterials} based on an
* identifier.
*/
public BomContainer(Function<String, BillOfMaterials> itemResolver) {
super(new LinkedHashMap<>(), itemResolver);
}

View File

@ -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;
}
}

View File

@ -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

View File

@ -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<String, Dependency> {
/**
* Create an instance with the specified {@code itemResolver}.
* @param itemResolver the function that returns a {@link Dependency} based on an
* identifier.
*/
public DependencyContainer(Function<String, Dependency> itemResolver) {
super(new LinkedHashMap<>(), itemResolver);
}

View File

@ -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<String, MavenRepository> {
/**
* Create an instance with the specified {@code itemResolver}.
* @param itemResolver the function that returns a {@link MavenRepository} based on an
* identifier.
*/
public MavenRepositoryContainer(Function<String, MavenRepository> itemResolver) {
super(new LinkedHashMap<>(), itemResolver);
}

View File

@ -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;
}

View File

@ -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<BillOfMaterials> 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>) 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<MavenProfile> 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<MavenReportPlugin> 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<MavenReportSet> 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("</%s>", name));
@ -673,7 +590,13 @@ public class MavenBuildWriter {
}
}
private String encodeText(String text) {
private <T> void ifNotNull(T value, Consumer<T> 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);

View File

@ -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 <configuration>} or {@code <properties>} 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<Setting> settings;
MavenConfiguration(List<Setting> settings) {
this.settings = Collections.unmodifiableList(settings);
}
/**
* Return the {@linkplain Setting settings} of the configuration.
* @return the settings
*/
public List<Setting> 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<Setting> 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<Builder> 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<Setting> 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);
}
}
}
}

View File

@ -44,7 +44,7 @@ public class MavenPlugin {
private final List<Dependency> 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<Dependency> 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<MavenConfiguration.Builder> configuration) {
public Builder configuration(Consumer<ConfigurationBuilder> 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<String> 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<MavenConfiguration.Builder> configuration) {
public ExecutionBuilder configuration(Consumer<ConfigurationBuilder> 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<Setting> 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<ConfigurationBuilder> 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<Setting> 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 <configuration>} on an {@link Execution} or {@link MavenPlugin}.
*/
public static final class Configuration {
private final List<Setting> settings;
private Configuration(List<Setting> settings) {
this.settings = Collections.unmodifiableList(settings);
}
/**
* Return the {@linkplain Setting settings} of the configuration.
* @return the settings
*/
public List<Setting> 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 <execution>} of a {@link MavenPlugin}.
*/
@ -276,9 +393,9 @@ public class MavenPlugin {
private final List<String> goals;
private final MavenConfiguration configuration;
private final Configuration configuration;
private Execution(String id, String phase, List<String> goals, MavenConfiguration configuration) {
private Execution(String id, String phase, List<String> 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;
}

View File

@ -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<MavenPluginContainer> plugins) {
plugins.accept(this.plugins);
return this;
}
public MavenPluginManagement build() {
return new MavenPluginManagement(this);
}
}
}

View File

@ -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<String> 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<String> 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<String> 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<MavenProfileActivation.Builder> 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<MavenProfileBuild.Builder> 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<MavenRepositoryContainer> 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<MavenRepositoryContainer> 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<MavenReporting.Builder> reporting) {
if (this.reportingBuilder == null) {
this.reportingBuilder = new MavenReporting.Builder();
}
reporting.accept(this.reportingBuilder);
return this;
}
public Builder dependencies(Consumer<DependencyContainer> dependencies) {
dependencies.accept(this.dependencies);
return this;
}
public Builder dependencyManagement(Consumer<BomContainer> dependencyManagement) {
dependencyManagement.accept(this.dependencyManagement);
return this;
}
public Builder distributionManagement(
Consumer<MavenDistributionManagement.Builder> distributionManagementBuilder) {
if (this.distributionManagementBuilder == null) {
this.distributionManagementBuilder = new MavenDistributionManagement.Builder();
}
distributionManagementBuilder.accept(this.distributionManagementBuilder);
return this;
}
public Builder properties(Consumer<MavenConfiguration.Builder> 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;
}
}

View File

@ -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<MavenProfileActivationOS.Builder> 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<MavenProfileActivationProperty.Builder> 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<MavenProfileActivationFile.Builder> 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);
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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<String> 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<String> 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<String> 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<MavenResourceContainer> resources) {
resources.accept(this.resources);
return this;
}
public MavenProfileBuild.Builder testResources(Consumer<MavenResourceContainer> testResources) {
testResources.accept(this.testResources);
return this;
}
public MavenProfileBuild.Builder pluginManagement(Consumer<MavenPluginManagement.Builder> pluginManagement) {
if (this.pluginManagementBuilder == null) {
this.pluginManagementBuilder = new MavenPluginManagement.Builder();
}
pluginManagement.accept(this.pluginManagementBuilder);
return this;
}
public MavenProfileBuild.Builder plugins(Consumer<MavenPluginContainer> plugins) {
plugins.accept(this.plugins);
return this;
}
public MavenProfileBuild build() {
return new MavenProfileBuild(this);
}
}
}

View File

@ -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<String, MavenProfile.Builder> profiles = new LinkedHashMap<>();
private final Map<String, MavenProfile> 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<MavenProfile> 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<MavenProfile.Builder> profileBuilder) {
profileBuilder.accept(createProfileBuilder(id));
public Stream<String> 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<MavenProfile> 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;
}
}
}

View File

@ -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<MavenConfiguration.Builder> configuration) {
if (this.configuration == null) {
this.configuration = new MavenConfiguration.Builder();
}
configuration.accept(this.configuration);
return this;
}
public MavenReportPlugin.Builder reportSets(Consumer<MavenReportSetContainer> reportSets) {
reportSets.accept(this.reportSets);
return this;
}
public MavenReportPlugin build() {
return new MavenReportPlugin(this);
}
}
}

View File

@ -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<String, Builder> 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<MavenReportPlugin> 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<Builder> 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);
}
}

View File

@ -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<String> 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<String> getReports() {
return this.reports;
}
public static class Builder {
private final String id;
private MavenConfiguration.Builder configuration;
private String inherited;
private List<String> reports;
protected Builder(String id) {
this.id = id;
}
public MavenReportSet.Builder configuration(Consumer<MavenConfiguration.Builder> 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);
}
}
}

View File

@ -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<String, MavenReportSet.Builder> reportSets = new LinkedHashMap<>();
public boolean isEmpty() {
return this.reportSets.isEmpty();
}
public Stream<MavenReportSet> 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<MavenReportSet.Builder> 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;
}
}
}

View File

@ -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<MavenReportPluginContainer> reportPlugins) {
reportPlugins.accept(this.reportPlugins);
return this;
}
public MavenReporting build() {
return new MavenReporting(this);
}
}
}

View File

@ -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();
}
}

View File

@ -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();
});
}

View File

@ -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<Setting> values = (List<Setting>) 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<Setting> subItems = (List<Setting>) 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<Setting> 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) {

View File

@ -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");
}
}

View File

@ -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");
}
}

View File

@ -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");
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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"));
}
}

View File

@ -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();
}
}