Allow meta-data driven version overrides in Gradle

Add a `versionManagement` gradle configuration which can be used to
provide alternative version meta-data. Primarily added so that the
Spring IO platform can provide version overrides without causing a
cyclic build dependency.

Fixes gh-750
This commit is contained in:
Phillip Webb
2014-05-06 16:31:49 +01:00
parent 38fb8e6874
commit 506c0f50b9
23 changed files with 760 additions and 211 deletions

View File

@@ -0,0 +1,102 @@
/*
* Copyright 2012-2014 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
*
* http://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.dependency.tools;
import java.io.InputStream;
import java.util.Iterator;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/**
* Tests for {@link PomManagedDependencies}.
*
* @author Phillip Webb
*/
public class PomManagedDependenciesTests {
private PomManagedDependencies dependencies;
@Before
public void setup() {
InputStream x = getResource("test-effective-pom.xml");
InputStream y = getResource("test-dependencies-pom.xml");
this.dependencies = new PomManagedDependencies(x, y);
}
private InputStream getResource(String name) {
InputStream inputStream = getClass().getResourceAsStream(name);
assertNotNull("Unable to read " + name, inputStream);
return inputStream;
}
@Test
public void springBootVersion() throws Exception {
assertThat(this.dependencies.getSpringBootVersion(),
equalTo("1.0.0.BUILD-SNAPSHOT"));
}
@Test
public void iterate() throws Exception {
Iterator<Dependency> iterator = this.dependencies.iterator();
assertThat(iterator.next().toString(), equalTo("org.sample:sample01:1.0.0"));
assertThat(iterator.next().toString(), equalTo("org.sample:sample02:1.0.0"));
assertThat(iterator.next().toString(),
equalTo("org.springframework.boot:spring-boot:1.0.0.BUILD-SNAPSHOT"));
assertThat(iterator.hasNext(), equalTo(false));
}
@Test
public void findByArtifactAndGroupId() throws Exception {
assertThat(this.dependencies.find("org.sample", "sample02").toString(),
equalTo("org.sample:sample02:1.0.0"));
}
@Test
public void findByArtifactAndGroupIdMissing() throws Exception {
assertThat(this.dependencies.find("org.sample", "missing"), nullValue());
}
@Test
public void findByArtifactAndGroupIdOnlyInEffectivePom() throws Exception {
assertThat(this.dependencies.find("org.extra", "extra01"), nullValue());
}
@Test
public void findByArtifactId() throws Exception {
assertThat(this.dependencies.find("sample02").toString(),
equalTo("org.sample:sample02:1.0.0"));
}
@Test
public void findByArtifactIdMissing() throws Exception {
assertThat(this.dependencies.find("missing"), nullValue());
}
@Test
public void exludes() throws Exception {
Dependency dependency = this.dependencies.find("org.sample", "sample01");
assertThat(dependency.getExclusions().toString(),
equalTo("[org.exclude:exclude01]"));
}
}

View File

@@ -22,28 +22,28 @@ import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
/**
* Tests for {@link ManagedDependencies}.
* Tests for {@link PropertiesFileManagedDependencies}.
*
* @author Phillip Webb
*/
public class ManagedDependenciesTests {
public class PropertiesFileManagedDependenciesTests {
private ManagedDependencies dependencies;
private PropertiesFileManagedDependencies dependencies;
@Before
public void setup() {
this.dependencies = new ManagedDependencies("test-dependencies-pom.xml",
"test-effective-pom.xml");
public void setup() throws Exception {
this.dependencies = new PropertiesFileManagedDependencies(getClass()
.getResourceAsStream("external.properties"));
}
@Test
public void version() throws Exception {
assertThat(this.dependencies.getVersion(), equalTo("1.0.0.BUILD-SNAPSHOT"));
public void springBootVersion() throws Exception {
assertThat(this.dependencies.getSpringBootVersion(),
equalTo("1.0.0.BUILD-SNAPSHOT"));
}
@Test
@@ -51,6 +51,8 @@ public class ManagedDependenciesTests {
Iterator<Dependency> iterator = this.dependencies.iterator();
assertThat(iterator.next().toString(), equalTo("org.sample:sample01:1.0.0"));
assertThat(iterator.next().toString(), equalTo("org.sample:sample02:1.0.0"));
assertThat(iterator.next().toString(),
equalTo("org.springframework.boot:spring-boot:1.0.0.BUILD-SNAPSHOT"));
assertThat(iterator.hasNext(), equalTo(false));
}
@@ -83,17 +85,9 @@ public class ManagedDependenciesTests {
@Test
public void exludes() throws Exception {
// No Support for exclusion
Dependency dependency = this.dependencies.find("org.sample", "sample01");
assertThat(dependency.getExclusions().toString(),
equalTo("[org.exclude:exclude01]"));
}
@Test
public void get() throws Exception {
ManagedDependencies dependencies = ManagedDependencies.get();
assertThat(dependencies.iterator().hasNext(), equalTo(true));
assertThat(dependencies.find("org.springframework", "spring-core"),
notNullValue());
assertThat(dependency.getExclusions().size(), equalTo(0));
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright 2012-2014 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
*
* http://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.dependency.tools;
import java.util.Collections;
import java.util.Iterator;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
/**
* Tests for {@link VersionManagedDependencies}.
*
* @author Phillip Webb
*/
public class VersionManagedDependenciesTests {
private VersionManagedDependencies dependencies;
@Before
public void setup() throws Exception {
PropertiesFileManagedDependencies root = new PropertiesFileManagedDependencies(
getClass().getResourceAsStream("external.properties"));
PropertiesFileManagedDependencies extra = new PropertiesFileManagedDependencies(
getClass().getResourceAsStream("additional-external.properties"));
this.dependencies = new VersionManagedDependencies(root,
Collections.<ManagedDependencies> singleton(extra));
}
@Test
public void extra() throws Exception {
assertThat(this.dependencies.find("org.sample", "sample03").toString(),
equalTo("org.sample:sample03:2.0.0"));
}
@Test
public void override() throws Exception {
assertThat(this.dependencies.find("org.sample", "sample02").toString(),
equalTo("org.sample:sample02:2.0.0"));
}
@Test
public void getSpringBootVersion() throws Exception {
assertThat(this.dependencies.getSpringBootVersion(),
equalTo("1.0.0.BUILD-SNAPSHOT"));
}
@Test
public void iterator() throws Exception {
Iterator<Dependency> iterator = this.dependencies.iterator();
assertThat(iterator.next().toString(), equalTo("org.sample:sample01:1.0.0"));
assertThat(iterator.next().toString(), equalTo("org.sample:sample02:2.0.0"));
assertThat(iterator.next().toString(),
equalTo("org.springframework.boot:spring-boot:1.0.0.BUILD-SNAPSHOT"));
assertThat(iterator.next().toString(), equalTo("org.sample:sample03:2.0.0"));
assertThat(iterator.hasNext(), equalTo(false));
}
}

View File

@@ -0,0 +1,2 @@
org.sample\:sample03=2.0.0
org.sample\:sample02=2.0.0

View File

@@ -0,0 +1,3 @@
org.sample\:sample01=1.0.0
org.sample\:sample02=1.0.0
org.springframework.boot\:spring-boot=1.0.0.BUILD-SNAPSHOT

View File

@@ -15,10 +15,10 @@
<artifactId>sample01</artifactId>
<version>${sample.version}</version>
<exclusions>
<exclusion>
<groupId>org.exclude</groupId>
<artifactId>exclude01</artifactId>
</exclusion>
<exclusion>
<groupId>org.exclude</groupId>
<artifactId>exclude01</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
@@ -26,6 +26,11 @@
<artifactId>sample02</artifactId>
<version>${sample.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

View File

@@ -24,6 +24,11 @@
<artifactId>sample02</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.extra</groupId>
<artifactId>extra01</artifactId>