Allow custom dependency metadata to be used with the CLI

Add support for a new annotation, @GrabMetadata, that can be used
to provide the coordinates of one or more properties files, such as
the one published by Spring IO Platform, as a source of dependency
metadata. For example:

@GrabMetadata("com.example:metadata:1.0.0")

The referenced properties files must be in the format
group:module=version.

Limitations:

 - Only a single @GrabMetadata annotation is supported
 - The referenced properties file must be accessible in one of the
   default repositories, i.e. it cannot be accessed in a repository
   that's added using @GrabResolver

Closes #814
This commit is contained in:
Andy Wilkinson
2014-05-19 15:58:42 +01:00
parent 3f498a4803
commit d2fc80b818
19 changed files with 589 additions and 143 deletions

View File

@@ -17,6 +17,8 @@
package org.springframework.boot.cli;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import org.junit.After;
import org.junit.Before;
@@ -26,10 +28,11 @@ import org.springframework.boot.cli.command.grab.GrabCommand;
import org.springframework.util.FileSystemUtils;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Integration tests for {@link GrabCommand}
*
*
* @author Andy Wilkinson
* @author Dave Syer
*/
@@ -58,4 +61,32 @@ public class GrabCommandIntegrationTests {
// Should be resolved from local repository cache
assertTrue(output.contains("Downloading: file:"));
}
@Test
public void duplicateGrabMetadataAnnotationsProducesAnError() throws Exception {
try {
this.cli.grab("duplicateGrabMetadata.groovy");
fail();
}
catch (Exception e) {
assertTrue(e.getMessage().contains("Duplicate @GrabMetadata annotation"));
}
}
@Test
public void customMetadata() throws Exception {
System.setProperty("grape.root", "target");
File testArtifactDir = new File("target/repository/test/test/1.0.0");
testArtifactDir.mkdirs();
File testArtifact = new File(testArtifactDir, "test-1.0.0.properties");
testArtifact.createNewFile();
PrintWriter writer = new PrintWriter(new FileWriter(testArtifact));
writer.println("javax.ejb\\:ejb-api=3.0");
writer.close();
this.cli.grab("customGrabMetadata.groovy", "--autoconfigure=false");
assertTrue(new File("target/repository/javax/ejb/ejb-api/3.0").isDirectory());
}
}

View File

@@ -50,7 +50,7 @@ import static org.mockito.Mockito.when;
/**
* Tests for {@link ResolveDependencyCoordinatesTransformation}
*
*
* @author Andy Wilkinson
*/
public final class ResolveDependencyCoordinatesTransformationTests {
@@ -64,9 +64,12 @@ public final class ResolveDependencyCoordinatesTransformationTests {
private final ArtifactCoordinatesResolver coordinatesResolver = mock(ArtifactCoordinatesResolver.class);
private final ASTTransformation transformation = new ResolveDependencyCoordinatesTransformation(
private final DependencyResolutionContext resolutionContext = new DependencyResolutionContext(
this.coordinatesResolver);
private final ASTTransformation transformation = new ResolveDependencyCoordinatesTransformation(
this.resolutionContext);
@Before
public void setupExpectations() {
when(this.coordinatesResolver.getGroupId("spring-core")).thenReturn(

View File

@@ -24,12 +24,13 @@ import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.boot.cli.compiler.DependencyResolutionContext;
import static org.junit.Assert.assertEquals;
/**
* Tests for {@link AetherGrapeEngine}.
*
*
* @author Andy Wilkinson
*/
public class AetherGrapeEngineTests {
@@ -38,7 +39,8 @@ public class AetherGrapeEngineTests {
private final AetherGrapeEngine grapeEngine = AetherGrapeEngineFactory.create(
this.groovyClassLoader, Arrays.asList(new RepositoryConfiguration("central",
URI.create("http://repo1.maven.org/maven2"), false)));
URI.create("http://repo1.maven.org/maven2"), false)),
new DependencyResolutionContext());
@Test
public void dependencyResolution() {
@@ -47,7 +49,7 @@ public class AetherGrapeEngineTests {
this.grapeEngine.grab(args,
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"));
assertEquals(5, this.groovyClassLoader.getURLs().length);
assertEquals(6, this.groovyClassLoader.getURLs().length);
}
@SuppressWarnings("unchecked")
@@ -61,7 +63,7 @@ public class AetherGrapeEngineTests {
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"),
createDependency("org.springframework", "spring-beans", "3.2.4.RELEASE"));
assertEquals(3, this.groovyClassLoader.getURLs().length);
assertEquals(4, this.groovyClassLoader.getURLs().length);
}
@Test
@@ -86,7 +88,7 @@ public class AetherGrapeEngineTests {
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"));
assertEquals(0, this.groovyClassLoader.getURLs().length);
assertEquals(5, customClassLoader.getURLs().length);
assertEquals(6, customClassLoader.getURLs().length);
}
@Test