Enhance bomr to handle libraries that use a version property
Closes gh-20478
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 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 org.springframework.boot.build.bom.bomr;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.build.bom.Library;
|
||||
import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link UpgradeApplicator}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class UpgradeApplicatorTests {
|
||||
|
||||
@TempDir
|
||||
File temp;
|
||||
|
||||
@Test
|
||||
void whenUpgradeIsAppliedToLibraryWithVersionThenBomIsUpdated() throws IOException {
|
||||
File bom = new File(this.temp, "bom.gradle");
|
||||
FileCopyUtils.copy(new File("src/test/resources/bom.gradle"), bom);
|
||||
File gradleProperties = new File(this.temp, "gradle.properties");
|
||||
FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
|
||||
new UpgradeApplicator(bom.toPath(), gradleProperties.toPath())
|
||||
.apply(new Upgrade(new Library("ActiveMQ", DependencyVersion.parse("5.15.11"), null, null),
|
||||
DependencyVersion.parse("5.16")));
|
||||
String bomContents = new String(Files.readAllBytes(bom.toPath()), StandardCharsets.UTF_8);
|
||||
assertThat(bomContents).contains("library(\"ActiveMQ\", \"5.16\")");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUpgradeIsAppliedToLibraryWithVersionPropertyThenGradlePropertiesIsUpdated() throws IOException {
|
||||
File bom = new File(this.temp, "bom.gradle");
|
||||
FileCopyUtils.copy(new File("src/test/resources/bom.gradle"), bom);
|
||||
File gradleProperties = new File(this.temp, "gradle.properties");
|
||||
FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
|
||||
new UpgradeApplicator(bom.toPath(), gradleProperties.toPath())
|
||||
.apply(new Upgrade(new Library("Kotlin", DependencyVersion.parse("1.3.70"), null, null),
|
||||
DependencyVersion.parse("1.3.71")));
|
||||
Properties properties = new Properties();
|
||||
try (InputStream in = new FileInputStream(gradleProperties)) {
|
||||
properties.load(in);
|
||||
}
|
||||
assertThat(properties).containsEntry("kotlinVersion", "1.3.71");
|
||||
}
|
||||
|
||||
}
|
||||
51
buildSrc/src/test/resources/bom.gradle
Normal file
51
buildSrc/src/test/resources/bom.gradle
Normal file
@@ -0,0 +1,51 @@
|
||||
bom {
|
||||
library("ActiveMQ", "5.15.11") {
|
||||
group("org.apache.activemq") {
|
||||
modules = [
|
||||
"activemq-amqp",
|
||||
"activemq-blueprint",
|
||||
"activemq-broker",
|
||||
"activemq-camel",
|
||||
"activemq-client",
|
||||
"activemq-console" {
|
||||
exclude group: "commons-logging", module: "commons-logging"
|
||||
},
|
||||
"activemq-http",
|
||||
"activemq-jaas",
|
||||
"activemq-jdbc-store",
|
||||
"activemq-jms-pool",
|
||||
"activemq-kahadb-store",
|
||||
"activemq-karaf",
|
||||
"activemq-leveldb-store" {
|
||||
exclude group: "commons-logging", module: "commons-logging"
|
||||
},
|
||||
"activemq-log4j-appender",
|
||||
"activemq-mqtt",
|
||||
"activemq-openwire-generator",
|
||||
"activemq-openwire-legacy",
|
||||
"activemq-osgi",
|
||||
"activemq-partition",
|
||||
"activemq-pool",
|
||||
"activemq-ra",
|
||||
"activemq-run",
|
||||
"activemq-runtime-config",
|
||||
"activemq-shiro",
|
||||
"activemq-spring" {
|
||||
exclude group: "commons-logging", module: "commons-logging"
|
||||
},
|
||||
"activemq-stomp",
|
||||
"activemq-web"
|
||||
]
|
||||
}
|
||||
}
|
||||
library("Kotlin", "${kotlinVersion}") {
|
||||
group("org.jetbrains.kotlin") {
|
||||
imports = [
|
||||
"kotlin-bom"
|
||||
]
|
||||
plugins = [
|
||||
"kotlin-maven-plugin"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
4
buildSrc/src/test/resources/gradle.properties
Normal file
4
buildSrc/src/test/resources/gradle.properties
Normal file
@@ -0,0 +1,4 @@
|
||||
a=alpha
|
||||
b=bravo
|
||||
kotlinVersion=1.3.70
|
||||
t=tango
|
||||
Reference in New Issue
Block a user