mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-18 09:44:47 +08:00
Move build properties to dedicated container
See gh-996
This commit is contained in:
@@ -77,7 +77,7 @@ public class DependencyManagementBuildCustomizer implements BuildCustomizer<Buil
|
||||
resolvedBoms.forEach((key, bom) -> {
|
||||
build.boms().add(key, MetadataBuildItemMapper.toBom(bom));
|
||||
if (bom.getVersionProperty() != null) {
|
||||
build.addVersionProperty(bom.getVersionProperty(), bom.getVersion());
|
||||
build.properties().version(bom.getVersionProperty(), bom.getVersion());
|
||||
}
|
||||
});
|
||||
repositories.keySet().forEach((id) -> build.repositories().add(id));
|
||||
|
@@ -20,6 +20,7 @@ import io.spring.initializr.generator.buildsystem.BillOfMaterials;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenBuild;
|
||||
import io.spring.initializr.generator.project.ProjectDescription;
|
||||
import io.spring.initializr.generator.spring.build.BuildCustomizer;
|
||||
import io.spring.initializr.generator.version.VersionProperty;
|
||||
import io.spring.initializr.metadata.InitializrConfiguration.Env.Maven;
|
||||
import io.spring.initializr.metadata.InitializrConfiguration.Env.Maven.ParentPom;
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
@@ -44,7 +45,7 @@ public class DefaultMavenBuildCustomizer implements BuildCustomizer<MavenBuild>
|
||||
@Override
|
||||
public void customize(MavenBuild build) {
|
||||
build.settings().name(this.description.getName()).description(this.description.getDescription());
|
||||
build.setProperty("java.version", this.description.getLanguage().jvmVersion());
|
||||
build.properties().property("java.version", this.description.getLanguage().jvmVersion());
|
||||
build.plugins().add("org.springframework.boot", "spring-boot-maven-plugin");
|
||||
|
||||
Maven maven = this.metadata.getConfiguration().getEnv().getMaven();
|
||||
@@ -55,13 +56,13 @@ public class DefaultMavenBuildCustomizer implements BuildCustomizer<MavenBuild>
|
||||
BillOfMaterials springBootBom = MetadataBuildItemMapper
|
||||
.toBom(this.metadata.createSpringBootBom(springBootVersion, versionProperty));
|
||||
if (!hasBom(build, springBootBom)) {
|
||||
build.addInternalVersionProperty(versionProperty, springBootVersion);
|
||||
build.properties().version(VersionProperty.of(versionProperty, true), springBootVersion);
|
||||
build.boms().add("spring-boot", springBootBom);
|
||||
}
|
||||
}
|
||||
if (!maven.isSpringBootStarterParent(parentPom)) {
|
||||
build.setProperty("project.build.sourceEncoding", "UTF-8");
|
||||
build.setProperty("project.reporting.outputEncoding", "UTF-8");
|
||||
build.properties().property("project.build.sourceEncoding", "UTF-8")
|
||||
.property("project.reporting.outputEncoding", "UTF-8");
|
||||
}
|
||||
build.settings().parent(parentPom.getGroupId(), parentPom.getArtifactId(), parentPom.getVersion());
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ class KotlinMavenBuildCustomizer implements BuildCustomizer<MavenBuild> {
|
||||
|
||||
@Override
|
||||
public void customize(MavenBuild build) {
|
||||
build.setProperty("kotlin.version", this.settings.getVersion());
|
||||
build.properties().version("kotlin.version", this.settings.getVersion());
|
||||
build.settings().sourceDirectory("${project.basedir}/src/main/kotlin")
|
||||
.testSourceDirectory("${project.basedir}/src/test/kotlin");
|
||||
build.plugins().add("org.jetbrains.kotlin", "kotlin-maven-plugin", (kotlinMavenPlugin) -> {
|
||||
|
@@ -35,7 +35,7 @@ class KotlinMavenFullBuildCustomizer implements BuildCustomizer<MavenBuild> {
|
||||
|
||||
@Override
|
||||
public void customize(MavenBuild build) {
|
||||
build.setProperty("kotlin.version", this.settings.getVersion());
|
||||
build.properties().version("kotlin.version", this.settings.getVersion());
|
||||
build.settings().sourceDirectory("${project.basedir}/src/main/kotlin")
|
||||
.testSourceDirectory("${project.basedir}/src/test/kotlin");
|
||||
build.plugins().add("org.jetbrains.kotlin", "kotlin-maven-plugin", (kotlinMavenPlugin) -> {
|
||||
|
@@ -182,11 +182,9 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
||||
ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE",
|
||||
(description) -> description.addDependency("web", MetadataBuildItemMapper.toDependency(WEB)),
|
||||
(projectGenerationContext) -> projectGenerationContext.registerBean(BuildCustomizer.class,
|
||||
() -> (projectBuild) -> {
|
||||
projectBuild.addVersionProperty(VersionProperty.of("spring-foo.version", false),
|
||||
"0.1.0.RELEASE");
|
||||
projectBuild.addVersionProperty(VersionProperty.of("spring-bar.version"), "0.2.0.RELEASE");
|
||||
}));
|
||||
() -> (projectBuild) -> projectBuild.properties()
|
||||
.version(VersionProperty.of("spring-foo.version", false), "0.1.0.RELEASE")
|
||||
.version(VersionProperty.of("spring-bar.version"), "0.2.0.RELEASE")));
|
||||
assertThat(project).textFile(fileName).hasSameContentAs(
|
||||
new ClassPathResource("project/" + build + "/version-override-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
@@ -65,7 +65,7 @@ class DefaultMavenBuildCustomizerTests {
|
||||
MutableProjectDescription description = initializeDescription();
|
||||
description.setLanguage(new JavaLanguage("11"));
|
||||
MavenBuild build = customizeBuild(metadata, description);
|
||||
assertThat(build.getProperties()).contains(entry("java.version", "11"));
|
||||
assertThat(build.properties().values()).contains(entry("java.version", "11"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,7 +90,8 @@ class DefaultMavenBuildCustomizerTests {
|
||||
BomContainer boms = build.boms();
|
||||
assertThat(boms.items()).hasSize(1);
|
||||
assertThat(boms.ids()).contains("spring-boot");
|
||||
assertThat(build.getVersionProperties().get(VersionProperty.of("spring-boot.version"))).isEqualTo("2.0.0");
|
||||
assertThat(build.properties().versions(VersionProperty::toStandardFormat))
|
||||
.contains(entry("spring-boot.version", "2.0.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -23,9 +23,11 @@ import io.spring.initializr.generator.buildsystem.maven.MavenBuild;
|
||||
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.Setting;
|
||||
import io.spring.initializr.generator.version.VersionProperty;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
/**
|
||||
* Tests for {@link KotlinMavenBuildCustomizer}.
|
||||
@@ -38,8 +40,8 @@ class KotlinMavenBuildCustomizerTests {
|
||||
void kotlinVersionPropertyIsConfigured() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
new KotlinMavenBuildCustomizer(new SimpleKotlinProjectSettings("1.2.70")).customize(build);
|
||||
assertThat(build.getProperties()).hasSize(1);
|
||||
assertThat(build.getProperties()).containsEntry("kotlin.version", "1.2.70");
|
||||
assertThat(build.properties().versions(VersionProperty::toStandardFormat))
|
||||
.containsOnly(entry("kotlin.version", "1.2.70"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -21,9 +21,11 @@ import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuratio
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Dependency;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Execution;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting;
|
||||
import io.spring.initializr.generator.version.VersionProperty;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
/**
|
||||
* Tests for {@link KotlinMavenFullBuildCustomizer}.
|
||||
@@ -36,8 +38,8 @@ class KotlinMavenFullBuildCustomizerTests {
|
||||
void kotlinVersionPropertyIsConfigured() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
new KotlinMavenFullBuildCustomizer(new SimpleKotlinProjectSettings("1.2.70")).customize(build);
|
||||
assertThat(build.getProperties()).hasSize(1);
|
||||
assertThat(build.getProperties()).containsEntry("kotlin.version", "1.2.70");
|
||||
assertThat(build.properties().versions(VersionProperty::toStandardFormat))
|
||||
.containsOnly(entry("kotlin.version", "1.2.70"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -16,12 +16,6 @@
|
||||
|
||||
package io.spring.initializr.generator.buildsystem;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import io.spring.initializr.generator.version.VersionProperty;
|
||||
|
||||
/**
|
||||
* Build configuration for a project.
|
||||
*
|
||||
@@ -30,7 +24,7 @@ import io.spring.initializr.generator.version.VersionProperty;
|
||||
*/
|
||||
public abstract class Build {
|
||||
|
||||
private final Map<VersionProperty, String> versionProperties = new TreeMap<>();
|
||||
private final PropertyContainer properties;
|
||||
|
||||
private final DependencyContainer dependencies;
|
||||
|
||||
@@ -42,6 +36,7 @@ public abstract class Build {
|
||||
|
||||
protected Build(BuildItemResolver buildItemResolver) {
|
||||
BuildItemResolver resolver = determineBuildItemResolver(buildItemResolver);
|
||||
this.properties = new PropertyContainer();
|
||||
this.dependencies = new DependencyContainer(resolver::resolveDependency);
|
||||
this.boms = new BomContainer(resolver::resolveBom);
|
||||
this.repositories = new MavenRepositoryContainer(resolver::resolveRepository);
|
||||
@@ -68,20 +63,12 @@ public abstract class Build {
|
||||
*/
|
||||
public abstract BuildSettings getSettings();
|
||||
|
||||
public void addVersionProperty(VersionProperty versionProperty, String version) {
|
||||
this.versionProperties.put(versionProperty, version);
|
||||
}
|
||||
|
||||
public void addExternalVersionProperty(String propertyName, String version) {
|
||||
addVersionProperty(VersionProperty.of(propertyName, false), version);
|
||||
}
|
||||
|
||||
public void addInternalVersionProperty(String propertyName, String version) {
|
||||
addVersionProperty(VersionProperty.of(propertyName, true), version);
|
||||
}
|
||||
|
||||
public Map<VersionProperty, String> getVersionProperties() {
|
||||
return Collections.unmodifiableMap(this.versionProperties);
|
||||
/**
|
||||
* Return the {@link PropertyContainer properties container} of this build.
|
||||
* @return the properties container of this build.
|
||||
*/
|
||||
public PropertyContainer properties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public DependencyContainer dependencies() {
|
||||
|
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import io.spring.initializr.generator.version.VersionProperty;
|
||||
|
||||
/**
|
||||
* A container for properties. Arbitrary properties can be specified as well as ones that
|
||||
* refer to a {@link VersionProperty version}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class PropertyContainer {
|
||||
|
||||
private final Map<String, String> properties = new TreeMap<>();
|
||||
|
||||
private final Map<VersionProperty, String> versions = new TreeMap<>();
|
||||
|
||||
/**
|
||||
* Specify if this container is empty.
|
||||
* @return {@code true} if no property is registered
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return this.properties.isEmpty() && this.versions.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if this container has a property with the specified name.
|
||||
* @param name the name of a property
|
||||
* @return {@code true} if a property with the specified {@code name} is registered
|
||||
*/
|
||||
public boolean has(String name) {
|
||||
return this.properties.containsKey(name)
|
||||
|| this.versions.keySet().stream().anyMatch((ref) -> ref.toStandardFormat().equals(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a property with the specified {@code name} and {@code value}. If a
|
||||
* property with that {@code name} already exists, its value is overridden by the
|
||||
* specified {@code value}.
|
||||
* @param name the name of a property
|
||||
* @param value the value of the property
|
||||
* @return this container
|
||||
* @see #version(String, String) to register a property that refers to a version
|
||||
*/
|
||||
public PropertyContainer property(String name, String value) {
|
||||
this.properties.put(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a property that refers to the specified {@link VersionProperty version}.
|
||||
* If a version with the same {@link VersionProperty} already exists, its value is
|
||||
* overridden by the specified {@code version}.
|
||||
* @param versionProperty the name of a version
|
||||
* @param version the version
|
||||
* @return this container
|
||||
*/
|
||||
public PropertyContainer version(VersionProperty versionProperty, String version) {
|
||||
this.versions.put(versionProperty, version);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a public {@link VersionProperty} with the specified {@code name}. If a
|
||||
* version with the same {@code name} already exists, its value is overridden by the
|
||||
* specified {@code version}.
|
||||
* @param name the public name of a version
|
||||
* @param version the version
|
||||
* @return this container
|
||||
* @see VersionProperty#isInternal()
|
||||
*/
|
||||
public PropertyContainer version(String name, String version) {
|
||||
return version(VersionProperty.of(name, false), version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the registered properties. Does not contain registered versions.
|
||||
* @return the property entries
|
||||
*/
|
||||
public Stream<Entry<String, String>> values() {
|
||||
return this.properties.entrySet().stream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the registered versions using the specified {@code nameFactory}.
|
||||
* @param nameFactory the factory to use to generate a version name based on a
|
||||
* {@link VersionProperty}
|
||||
* @return the version entries.
|
||||
*/
|
||||
public Stream<Entry<String, String>> versions(Function<VersionProperty, String> nameFactory) {
|
||||
return this.versions.entrySet().stream()
|
||||
.map((entry) -> new SimpleEntry<>(nameFactory.apply(entry.getKey()), entry.getValue()));
|
||||
}
|
||||
|
||||
}
|
@@ -25,7 +25,6 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.Build;
|
||||
@@ -45,8 +44,6 @@ public class GradleBuild extends Build {
|
||||
|
||||
private final GradleBuildSettings.Builder settings = new Builder();
|
||||
|
||||
private final Map<String, String> ext = new TreeMap<>();
|
||||
|
||||
private final GradlePluginContainer plugins = new GradlePluginContainer();
|
||||
|
||||
private final List<String> configurations = new ArrayList<>();
|
||||
@@ -79,15 +76,6 @@ public class GradleBuild extends Build {
|
||||
return this.settings.build();
|
||||
}
|
||||
|
||||
public GradleBuild ext(String key, String value) {
|
||||
this.ext.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<String, String> getExt() {
|
||||
return Collections.unmodifiableMap(this.ext);
|
||||
}
|
||||
|
||||
public GradlePluginContainer plugins() {
|
||||
return this.plugins;
|
||||
}
|
||||
|
@@ -24,8 +24,8 @@ import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
@@ -37,6 +37,7 @@ import io.spring.initializr.generator.buildsystem.DependencyComparator;
|
||||
import io.spring.initializr.generator.buildsystem.DependencyContainer;
|
||||
import io.spring.initializr.generator.buildsystem.DependencyScope;
|
||||
import io.spring.initializr.generator.buildsystem.MavenRepository;
|
||||
import io.spring.initializr.generator.buildsystem.PropertyContainer;
|
||||
import io.spring.initializr.generator.buildsystem.gradle.GradleBuild.ConfigurationCustomization;
|
||||
import io.spring.initializr.generator.buildsystem.gradle.GradleBuild.TaskCustomization;
|
||||
import io.spring.initializr.generator.io.IndentingWriter;
|
||||
@@ -64,7 +65,7 @@ public abstract class GradleBuildWriter {
|
||||
writer.println();
|
||||
writeConfigurations(writer, build);
|
||||
writeRepositories(writer, build);
|
||||
writeProperties(writer, build);
|
||||
writeProperties(writer, build.properties());
|
||||
writeDependencies(writer, build);
|
||||
writeBoms(writer, build);
|
||||
writeTasksWithTypeCustomizations(writer, build);
|
||||
@@ -102,20 +103,21 @@ public abstract class GradleBuildWriter {
|
||||
|
||||
protected abstract String repositoryAsString(MavenRepository repository);
|
||||
|
||||
private void writeProperties(IndentingWriter writer, GradleBuild build) {
|
||||
if (build.getExt().isEmpty() && build.getVersionProperties().isEmpty()) {
|
||||
private void writeProperties(IndentingWriter writer, PropertyContainer properties) {
|
||||
if (properties.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Map<String, String> allProperties = new LinkedHashMap<>(build.getExt());
|
||||
build.getVersionProperties().entrySet()
|
||||
.forEach((entry) -> allProperties.put(getVersionPropertyKey(entry), "\"" + entry.getValue() + "\""));
|
||||
Map<String, String> allProperties = new LinkedHashMap<>(properties.values().collect(Collectors
|
||||
.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> newValue, TreeMap::new)));
|
||||
properties.versions(this::getVersionPropertyKey)
|
||||
.forEach((entry) -> allProperties.put(entry.getKey(), "\"" + entry.getValue() + "\""));
|
||||
writeExtraProperties(writer, allProperties);
|
||||
}
|
||||
|
||||
protected abstract void writeExtraProperties(IndentingWriter writer, Map<String, String> allProperties);
|
||||
|
||||
private String getVersionPropertyKey(Entry<VersionProperty, String> entry) {
|
||||
return entry.getKey().isInternal() ? entry.getKey().toCamelCaseFormat() : entry.getKey().toStandardFormat();
|
||||
private String getVersionPropertyKey(VersionProperty versionProperty) {
|
||||
return versionProperty.isInternal() ? versionProperty.toCamelCaseFormat() : versionProperty.toStandardFormat();
|
||||
}
|
||||
|
||||
private void writeDependencies(IndentingWriter writer, GradleBuild build) {
|
||||
|
@@ -16,10 +16,6 @@
|
||||
|
||||
package io.spring.initializr.generator.buildsystem.maven;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.Build;
|
||||
import io.spring.initializr.generator.buildsystem.BuildItemResolver;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSettings.Builder;
|
||||
@@ -34,8 +30,6 @@ public class MavenBuild extends Build {
|
||||
|
||||
private final MavenBuildSettings.Builder settings = new Builder();
|
||||
|
||||
private final Map<String, String> properties = new TreeMap<>();
|
||||
|
||||
private final MavenResourceContainer resources = new MavenResourceContainer();
|
||||
|
||||
private final MavenResourceContainer testResources = new MavenResourceContainer();
|
||||
@@ -60,14 +54,6 @@ public class MavenBuild extends Build {
|
||||
return this.settings.build();
|
||||
}
|
||||
|
||||
public void setProperty(String key, String value) {
|
||||
this.properties.put(key, value);
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return Collections.unmodifiableMap(this.properties);
|
||||
}
|
||||
|
||||
public MavenResourceContainer resources() {
|
||||
return this.resources;
|
||||
}
|
||||
|
@@ -33,10 +33,12 @@ import io.spring.initializr.generator.buildsystem.DependencyComparator;
|
||||
import io.spring.initializr.generator.buildsystem.DependencyContainer;
|
||||
import io.spring.initializr.generator.buildsystem.DependencyScope;
|
||||
import io.spring.initializr.generator.buildsystem.MavenRepository;
|
||||
import io.spring.initializr.generator.buildsystem.PropertyContainer;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuration;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Execution;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting;
|
||||
import io.spring.initializr.generator.io.IndentingWriter;
|
||||
import io.spring.initializr.generator.version.VersionProperty;
|
||||
import io.spring.initializr.generator.version.VersionReference;
|
||||
|
||||
/**
|
||||
@@ -55,7 +57,7 @@ public class MavenBuildWriter {
|
||||
writeProjectCoordinates(writer, settings);
|
||||
writePackaging(writer, settings);
|
||||
writeProjectName(writer, settings);
|
||||
writeProperties(writer, build);
|
||||
writeProperties(writer, build.properties());
|
||||
writeDependencies(writer, build);
|
||||
writeDependencyManagement(writer, build);
|
||||
writeBuild(writer, build);
|
||||
@@ -110,15 +112,15 @@ public class MavenBuildWriter {
|
||||
writeSingleElement(writer, "description", settings.getDescription());
|
||||
}
|
||||
|
||||
private void writeProperties(IndentingWriter writer, MavenBuild build) {
|
||||
if (build.getProperties().isEmpty() && build.getVersionProperties().isEmpty()) {
|
||||
private void writeProperties(IndentingWriter writer, PropertyContainer properties) {
|
||||
if (properties.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
writer.println();
|
||||
writeElement(writer, "properties", () -> {
|
||||
build.getProperties().forEach((key, value) -> writeSingleElement(writer, key, value));
|
||||
build.getVersionProperties()
|
||||
.forEach((key, value) -> writeSingleElement(writer, key.toStandardFormat(), value));
|
||||
properties.values().forEach((entry) -> writeSingleElement(writer, entry.getKey(), entry.getValue()));
|
||||
properties.versions((VersionProperty::toStandardFormat))
|
||||
.forEach((entry) -> writeSingleElement(writer, entry.getKey(), entry.getValue()));
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -205,7 +205,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
@Test
|
||||
void gradleBuildWithExt() throws Exception {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.ext("java.version", "'1.8'").ext("alpha", "file(\"build/example\")");
|
||||
build.properties().property("java.version", "'1.8'").property("alpha", "file(\"build/example\")");
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).containsSequence(" set('alpha', file(\"build/example\"))",
|
||||
" set('java.version', '1.8')");
|
||||
@@ -214,12 +214,11 @@ class GroovyDslGradleBuildWriterTests {
|
||||
@Test
|
||||
void gradleBuildWithVersionProperties() throws IOException {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.addVersionProperty(VersionProperty.of("version.property"), "1.2.3");
|
||||
build.addInternalVersionProperty("internal.property", "4.5.6");
|
||||
build.addExternalVersionProperty("external.property", "7.8.9");
|
||||
build.properties().version(VersionProperty.of("version.property", false), "1.2.3")
|
||||
.version(VersionProperty.of("internal.property", true), "4.5.6").version("external.property", "7.8.9");
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).containsSequence("ext {", " set('external.property', \"7.8.9\")",
|
||||
" set('internalProperty', \"4.5.6\")", " set('versionProperty', \"1.2.3\")", "}");
|
||||
" set('internalProperty', \"4.5.6\")", " set('version.property', \"1.2.3\")", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -248,9 +247,8 @@ class GroovyDslGradleBuildWriterTests {
|
||||
@Test
|
||||
void gradleBuildWithExtAndVersionProperties() throws Exception {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.addInternalVersionProperty("test-version", "1.0");
|
||||
build.addExternalVersionProperty("alpha-version", "0.1");
|
||||
build.ext("myProperty", "'42'");
|
||||
build.properties().version(VersionProperty.of("test-version"), "1.0").version("alpha-version", "0.1")
|
||||
.property("myProperty", "'42'");
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).containsSequence(" set('myProperty', '42')", " set('alpha-version', \"0.1\")",
|
||||
" set('testVersion', \"1.0\")");
|
||||
|
@@ -210,7 +210,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
@Test
|
||||
void gradleBuildWithExt() throws Exception {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.ext("java.version", "\"1.8\"").ext("alpha", "file(\"build/example\")");
|
||||
build.properties().property("java.version", "\"1.8\"").property("alpha", "file(\"build/example\")");
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).containsSequence("extra[\"alpha\"] = file(\"build/example\")",
|
||||
"extra[\"java.version\"] = \"1.8\"");
|
||||
@@ -219,12 +219,11 @@ class KotlinDslGradleBuildWriterTests {
|
||||
@Test
|
||||
void gradleBuildWithVersionProperties() throws IOException {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.addVersionProperty(VersionProperty.of("version.property"), "1.2.3");
|
||||
build.addInternalVersionProperty("internal.property", "4.5.6");
|
||||
build.addExternalVersionProperty("external.property", "7.8.9");
|
||||
build.properties().version(VersionProperty.of("version.property", false), "1.2.3")
|
||||
.version(VersionProperty.of("internal.property", true), "4.5.6").version("external.property", "7.8.9");
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).containsSequence("extra[\"external.property\"] = \"7.8.9\"",
|
||||
"extra[\"internalProperty\"] = \"4.5.6\"", "extra[\"versionProperty\"] = \"1.2.3\"");
|
||||
"extra[\"internalProperty\"] = \"4.5.6\"", "extra[\"version.property\"] = \"1.2.3\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -253,9 +252,8 @@ class KotlinDslGradleBuildWriterTests {
|
||||
@Test
|
||||
void gradleBuildWithExtAndVersionProperties() throws Exception {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.addInternalVersionProperty("test-version", "1.0");
|
||||
build.addExternalVersionProperty("alpha-version", "0.1");
|
||||
build.ext("myProperty", "42");
|
||||
build.properties().version(VersionProperty.of("test-version", true), "1.0").version("alpha-version", "0.1")
|
||||
.property("myProperty", "42");
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).containsSequence("extra[\"myProperty\"] = 42", "extra[\"alpha-version\"] = \"0.1\"",
|
||||
"extra[\"testVersion\"] = \"1.0\"");
|
||||
|
@@ -86,8 +86,7 @@ class MavenBuildWriterTests {
|
||||
void pomWithProperties() throws Exception {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.setProperty("java.version", "1.8");
|
||||
build.setProperty("alpha", "a");
|
||||
build.properties().property("java.version", "1.8").property("alpha", "a");
|
||||
generatePom(build, (pom) -> {
|
||||
assertThat(pom).textAtPath("/project/properties/java.version").isEqualTo("1.8");
|
||||
assertThat(pom).textAtPath("/project/properties/alpha").isEqualTo("a");
|
||||
@@ -97,9 +96,8 @@ class MavenBuildWriterTests {
|
||||
@Test
|
||||
void pomWithVersionProperties() throws Exception {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.addVersionProperty(VersionProperty.of("version.property"), "1.2.3");
|
||||
build.addInternalVersionProperty("internal.property", "4.5.6");
|
||||
build.addExternalVersionProperty("external.property", "7.8.9");
|
||||
build.properties().version(VersionProperty.of("version.property", false), "1.2.3")
|
||||
.version(VersionProperty.of("internal.property", true), "4.5.6").version("external.property", "7.8.9");
|
||||
generatePom(build, (pom) -> {
|
||||
assertThat(pom).textAtPath("/project/properties/version.property").isEqualTo("1.2.3");
|
||||
assertThat(pom).textAtPath("/project/properties/internal.property").isEqualTo("4.5.6");
|
||||
|
Reference in New Issue
Block a user