From 156dadaebe774733010fcfef741109925be61d46 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 3 Jun 2014 15:57:36 +0100 Subject: [PATCH] Initialize DependencyResolutionContext with default dependency mgmt In the absence of a @GrabMetadata annotation, DependencyResolutionContext provided no dependency management. This was leading to incorrect dependency versions being pulled in. This commit intializes the context with default dependency management that will be replaced should @GrabMetadata be encountered. Fixes #1021 --- .../compiler/grape/DependencyResolutionContext.java | 6 ++++-- .../boot/cli/ReproIntegrationTests.java | 9 ++++++++- .../cli/compiler/grape/AetherGrapeEngineTests.java | 8 ++++---- .../src/test/resources/repro-samples/data-jpa.groovy | 12 ++++++++++++ 4 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 spring-boot-cli/src/test/resources/repro-samples/data-jpa.groovy diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DependencyResolutionContext.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DependencyResolutionContext.java index a0037e7c6d..0490ba145a 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DependencyResolutionContext.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DependencyResolutionContext.java @@ -26,7 +26,7 @@ import org.springframework.boot.dependency.tools.ManagedDependencies; /** * Context used when resolving dependencies. - * + * * @author Andy Wilkinson * @since 1.1.0 */ @@ -43,6 +43,8 @@ public class DependencyResolutionContext { public DependencyResolutionContext( ArtifactCoordinatesResolver artifactCoordinatesResolver) { this.artifactCoordinatesResolver = artifactCoordinatesResolver; + this.managedDependencies = new ManagedDependenciesFactory() + .getManagedDependencies(); } public void setManagedDependencies(ManagedDependencies managedDependencies) { @@ -50,7 +52,7 @@ public class DependencyResolutionContext { managedDependencies); this.managedDependencies = new ArrayList( new ManagedDependenciesFactory(managedDependencies) - .getManagedDependencies()); + .getManagedDependencies()); } public ArtifactCoordinatesResolver getArtifactCoordinatesResolver() { diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/ReproIntegrationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/ReproIntegrationTests.java index 7dbceb958f..971ddcb5da 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/ReproIntegrationTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/ReproIntegrationTests.java @@ -25,8 +25,9 @@ import static org.junit.Assert.assertThat; /** * Integration tests to exercise and reproduce specific issues. - * + * * @author Phillip Webb + * @author Andy Wilkinson */ public class ReproIntegrationTests { @@ -58,6 +59,12 @@ public class ReproIntegrationTests { containsString("{\"message\":\"Hello World\"}")); } + @Test + public void dataJpaDependencies() throws Exception { + this.cli.run("data-jpa.groovy"); + assertThat(this.cli.getOutput(), containsString("Hello World")); + } + @Test public void jarFileExtensionNeeded() throws Exception { this.thrown.expect(IllegalStateException.class); diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java index bd502a5ba9..93e4407a63 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java @@ -45,7 +45,7 @@ public class AetherGrapeEngineTests { private final AetherGrapeEngine grapeEngine = AetherGrapeEngineFactory.create( this.groovyClassLoader, Arrays.asList(new RepositoryConfiguration("central", URI.create("http://repo1.maven.org/maven2"), false)), - new DependencyResolutionContext()); + new DependencyResolutionContext()); @Test public void dependencyResolution() { @@ -54,7 +54,7 @@ public class AetherGrapeEngineTests { this.grapeEngine.grab(args, createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE")); - assertEquals(6, this.groovyClassLoader.getURLs().length); + assertEquals(5, this.groovyClassLoader.getURLs().length); } @Test @@ -76,7 +76,7 @@ public class AetherGrapeEngineTests { createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"), createDependency("org.springframework", "spring-beans", "3.2.4.RELEASE")); - assertEquals(4, this.groovyClassLoader.getURLs().length); + assertEquals(3, this.groovyClassLoader.getURLs().length); } @Test @@ -101,7 +101,7 @@ public class AetherGrapeEngineTests { createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE")); assertEquals(0, this.groovyClassLoader.getURLs().length); - assertEquals(6, customClassLoader.getURLs().length); + assertEquals(5, customClassLoader.getURLs().length); } @Test diff --git a/spring-boot-cli/src/test/resources/repro-samples/data-jpa.groovy b/spring-boot-cli/src/test/resources/repro-samples/data-jpa.groovy new file mode 100644 index 0000000000..8470df8826 --- /dev/null +++ b/spring-boot-cli/src/test/resources/repro-samples/data-jpa.groovy @@ -0,0 +1,12 @@ +@Grab('spring-boot-starter-data-jpa') +@Grab('h2') +class Sample implements CommandLineRunner { + + // No Data JPA-based logic. We just want to check that the dependencies are + // resolved correctly and that the app runs + + @Override + void run(String... args) { + println "Hello World" + } +} \ No newline at end of file