diff --git a/pom.xml b/pom.xml index 1b9e8eb6c9..7e81674973 100644 --- a/pom.xml +++ b/pom.xml @@ -80,7 +80,6 @@ spring-boot-dependencies spring-boot-parent - spring-boot-versions spring-boot-tools spring-boot spring-boot-autoconfigure @@ -110,7 +109,6 @@ spring-boot-dependencies spring-boot-parent - spring-boot-versions spring-boot-tools diff --git a/spring-boot-cli/pom.xml b/spring-boot-cli/pom.xml index 460876b13a..0c32eac363 100644 --- a/spring-boot-cli/pom.xml +++ b/spring-boot-cli/pom.xml @@ -19,6 +19,7 @@ ${basedir}/.. org.springframework.boot.cli.SpringCli default + ${project.build.directory}/generated-resources/org/springframework/boot/cli/compiler/dependencies @@ -33,10 +34,6 @@ - - org.springframework.boot - spring-boot-dependency-tools - org.springframework.boot spring-boot-loader-tools @@ -132,6 +129,14 @@ + + + ${project.build.directory}/generated-resources + + + ${basedir}/src/main/resources + + org.apache.maven.plugins @@ -155,6 +160,26 @@ org.apache.maven.plugins maven-dependency-plugin + + copy-effective-pom + generate-resources + + copy + + + + + org.springframework.boot + spring-boot-dependencies + ${project.version} + effective-pom + true + ${generated.pom.dir} + effective-pom.xml + + + + unpack prepare-package diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AnnotatedNodeASTTransformation.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AnnotatedNodeASTTransformation.java index 37a8a2e35e..9b1356359a 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AnnotatedNodeASTTransformation.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AnnotatedNodeASTTransformation.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -17,6 +17,7 @@ package org.springframework.boot.cli.compiler; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -42,12 +43,16 @@ public abstract class AnnotatedNodeASTTransformation implements ASTTransformatio private final Set interestingAnnotationNames; + private final boolean removeAnnotations; + private List annotationNodes = new ArrayList(); private SourceUnit sourceUnit; - protected AnnotatedNodeASTTransformation(Set interestingAnnotationNames) { + protected AnnotatedNodeASTTransformation(Set interestingAnnotationNames, + boolean removeAnnotations) { this.interestingAnnotationNames = interestingAnnotationNames; + this.removeAnnotations = removeAnnotations; } @Override @@ -94,10 +99,16 @@ public abstract class AnnotatedNodeASTTransformation implements ASTTransformatio private void visitAnnotatedNode(AnnotatedNode annotatedNode) { if (annotatedNode != null) { - for (AnnotationNode annotationNode : annotatedNode.getAnnotations()) { + Iterator annotationNodes = annotatedNode.getAnnotations() + .iterator(); + while (annotationNodes.hasNext()) { + AnnotationNode annotationNode = annotationNodes.next(); if (this.interestingAnnotationNames.contains(annotationNode .getClassNode().getName())) { this.annotationNodes.add(annotationNode); + if (this.removeAnnotations) { + annotationNodes.remove(); + } } } } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyAutoConfigurationTransformation.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyAutoConfigurationTransformation.java index 44d8df4bb2..678823b2b4 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyAutoConfigurationTransformation.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyAutoConfigurationTransformation.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -38,7 +38,7 @@ import org.springframework.core.annotation.Order; @Order(DependencyAutoConfigurationTransformation.ORDER) public class DependencyAutoConfigurationTransformation implements ASTTransformation { - public static final int ORDER = GrabMetadataTransformation.ORDER + 100; + public static final int ORDER = DependencyManagementBomTransformation.ORDER + 100; private final GroovyClassLoader loader; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GrabMetadataTransformation.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyManagementBomTransformation.java similarity index 57% rename from spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GrabMetadataTransformation.java rename to spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyManagementBomTransformation.java index a2680ca569..0b93e567db 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GrabMetadataTransformation.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyManagementBomTransformation.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -18,7 +18,7 @@ package org.springframework.boot.cli.compiler; import groovy.grape.Grape; -import java.io.IOException; +import java.net.MalformedURLException; import java.net.URI; import java.util.ArrayList; import java.util.Arrays; @@ -29,6 +29,16 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.maven.model.Model; +import org.apache.maven.model.Repository; +import org.apache.maven.model.building.DefaultModelBuilder; +import org.apache.maven.model.building.DefaultModelBuilderFactory; +import org.apache.maven.model.building.DefaultModelBuildingRequest; +import org.apache.maven.model.building.ModelSource; +import org.apache.maven.model.building.UrlModelSource; +import org.apache.maven.model.resolution.InvalidRepositoryException; +import org.apache.maven.model.resolution.ModelResolver; +import org.apache.maven.model.resolution.UnresolvableModelException; import org.codehaus.groovy.ast.ASTNode; import org.codehaus.groovy.ast.AnnotationNode; import org.codehaus.groovy.ast.expr.ConstantExpression; @@ -38,33 +48,33 @@ import org.codehaus.groovy.control.messages.Message; import org.codehaus.groovy.control.messages.SyntaxErrorMessage; import org.codehaus.groovy.syntax.SyntaxException; import org.codehaus.groovy.transform.ASTTransformation; +import org.springframework.boot.cli.compiler.dependencies.MavenModelDependencyManagement; import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext; -import org.springframework.boot.dependency.tools.Dependencies; -import org.springframework.boot.dependency.tools.ManagedDependencies; -import org.springframework.boot.dependency.tools.PropertiesFileDependencies; -import org.springframework.boot.groovy.GrabMetadata; +import org.springframework.boot.groovy.DependencyManagementBom; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; /** - * {@link ASTTransformation} for processing {@link GrabMetadata @GrabMetadata} + * {@link ASTTransformation} for processing {@link DependencyManagementBom} annotations * * @author Andy Wilkinson - * @since 1.1.0 + * @since 1.3.0 */ -@Order(GrabMetadataTransformation.ORDER) -public class GrabMetadataTransformation extends AnnotatedNodeASTTransformation { +@Order(DependencyManagementBomTransformation.ORDER) +public class DependencyManagementBomTransformation extends AnnotatedNodeASTTransformation { public static final int ORDER = Ordered.HIGHEST_PRECEDENCE; - private static final Set GRAB_METADATA_ANNOTATION_NAMES = Collections + private static final Set DEPENDENCY_MANAGEMENT_BOM_ANNOTATION_NAMES = Collections .unmodifiableSet(new HashSet(Arrays.asList( - GrabMetadata.class.getName(), GrabMetadata.class.getSimpleName()))); + DependencyManagementBom.class.getName(), + DependencyManagementBom.class.getSimpleName()))); private final DependencyResolutionContext resolutionContext; - public GrabMetadataTransformation(DependencyResolutionContext resolutionContext) { - super(GRAB_METADATA_ANNOTATION_NAMES); + public DependencyManagementBomTransformation( + DependencyResolutionContext resolutionContext) { + super(DEPENDENCY_MANAGEMENT_BOM_ANNOTATION_NAMES, true); this.resolutionContext = resolutionContext; } @@ -73,19 +83,19 @@ public class GrabMetadataTransformation extends AnnotatedNodeASTTransformation { if (!annotationNodes.isEmpty()) { if (annotationNodes.size() > 1) { for (AnnotationNode annotationNode : annotationNodes) { - handleDuplicateGrabMetadataAnnotation(annotationNode); + handleDuplicateDependencyManagementBomAnnotation(annotationNode); } } else { - processGrabMetadataAnnotation(annotationNodes.get(0)); + processDependencyManagementBomAnnotation(annotationNodes.get(0)); } } } - private void processGrabMetadataAnnotation(AnnotationNode annotationNode) { + private void processDependencyManagementBomAnnotation(AnnotationNode annotationNode) { Expression valueExpression = annotationNode.getMember("value"); - List> metadataDependencies = createDependencyMaps(valueExpression); - updateArtifactCoordinatesResolver(metadataDependencies); + List> bomDependencies = createDependencyMaps(valueExpression); + updateDependencyResolutionContext(bomDependencies); } private List> createDependencyMaps(Expression valueExpression) { @@ -104,7 +114,7 @@ public class GrabMetadataTransformation extends AnnotatedNodeASTTransformation { dependency.put("group", components[0]); dependency.put("module", components[1]); dependency.put("version", components[2]); - dependency.put("type", "properties"); + dependency.put("type", "pom"); dependencies.add(dependency); } else { @@ -126,7 +136,7 @@ public class GrabMetadataTransformation extends AnnotatedNodeASTTransformation { return Arrays.asList((ConstantExpression) valueExpression); } - reportError("@GrabMetadata requires an inline constant that is a " + reportError("@DependencyManagementBom requires an inline constant that is a " + "string or a string array", valueExpression); return Collections.emptyList(); } @@ -152,29 +162,34 @@ public class GrabMetadataTransformation extends AnnotatedNodeASTTransformation { getSourceUnit().getErrorCollector().addErrorAndContinue(message); } - private void updateArtifactCoordinatesResolver( - List> metadataDependencies) { + private void updateDependencyResolutionContext( + List> bomDependencies) { URI[] uris = Grape.getInstance().resolve(null, - metadataDependencies.toArray(new Map[metadataDependencies.size()])); - List managedDependencies = new ArrayList(uris.length); + bomDependencies.toArray(new Map[bomDependencies.size()])); + + DefaultModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance(); + for (URI uri : uris) { try { - managedDependencies.add(new PropertiesFileDependencies(uri.toURL() - .openStream())); + DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); + request.setModelResolver(new GrapeModelResolver()); + request.setModelSource(new UrlModelSource(uri.toURL())); + Model model = modelBuilder.build(request).getEffectiveModel(); + + this.resolutionContext + .addDependencyManagement(new MavenModelDependencyManagement(model)); } - catch (IOException ex) { - throw new IllegalStateException("Failed to parse '" + uris[0] - + "'. Is it a valid properties file?"); + catch (Exception ex) { + throw new IllegalStateException("Failed to build model for '" + uri + + "'. Is it a valid Maven bom?", ex); } } - - this.resolutionContext.setManagedDependencies(ManagedDependencies - .get(managedDependencies)); } - private void handleDuplicateGrabMetadataAnnotation(AnnotationNode annotationNode) { + private void handleDuplicateDependencyManagementBomAnnotation( + AnnotationNode annotationNode) { Message message = createSyntaxErrorMessage( - "Duplicate @GrabMetadata annotation. It must be declared at most once.", + "Duplicate @DependencyManagementBom annotation. It must be declared at most once.", annotationNode); getSourceUnit().getErrorCollector().addErrorAndContinue(message); } @@ -189,4 +204,36 @@ public class GrabMetadataTransformation extends AnnotatedNodeASTTransformation { node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), getSourceUnit()); } + + private static class GrapeModelResolver implements ModelResolver { + + @Override + public ModelSource resolveModel(String groupId, String artifactId, String version) + throws UnresolvableModelException { + Map dependency = new HashMap(); + dependency.put("group", groupId); + dependency.put("module", artifactId); + dependency.put("version", version); + dependency.put("type", "pom"); + try { + return new UrlModelSource( + Grape.getInstance().resolve(null, dependency)[0].toURL()); + } + catch (MalformedURLException e) { + throw new UnresolvableModelException(e.getMessage(), groupId, artifactId, + version); + } + } + + @Override + public void addRepository(Repository repository) + throws InvalidRepositoryException { + } + + @Override + public ModelResolver newCopy() { + return this; + } + + } } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyBeansTransformation.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyBeansTransformation.java index abe81475db..a4f5e69f4b 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyBeansTransformation.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyBeansTransformation.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -42,7 +42,7 @@ import org.springframework.core.annotation.Order; @Order(GroovyBeansTransformation.ORDER) public class GroovyBeansTransformation implements ASTTransformation { - public static final int ORDER = GrabMetadataTransformation.ORDER + 200; + public static final int ORDER = DependencyManagementBomTransformation.ORDER + 200; @Override public void visit(ASTNode[] nodes, SourceUnit source) { diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java index 31713973d9..88d63bbbf2 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java @@ -105,7 +105,7 @@ public class GroovyCompiler { } this.transformations = new ArrayList(); - this.transformations.add(new GrabMetadataTransformation(resolutionContext)); + this.transformations.add(new DependencyManagementBomTransformation(resolutionContext)); this.transformations.add(new DependencyAutoConfigurationTransformation( this.loader, resolutionContext, this.compilerAutoConfigurations)); this.transformations.add(new GroovyBeansTransformation()); diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformation.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformation.java index 5d2265c4f7..e2a6fcd6f9 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformation.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformation.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -41,7 +41,7 @@ import org.springframework.core.annotation.Order; public class ResolveDependencyCoordinatesTransformation extends AnnotatedNodeASTTransformation { - public static final int ORDER = GrabMetadataTransformation.ORDER + 300; + public static final int ORDER = DependencyManagementBomTransformation.ORDER + 300; private static final Set GRAB_ANNOTATION_NAMES = Collections .unmodifiableSet(new HashSet(Arrays.asList(Grab.class.getName(), @@ -51,7 +51,7 @@ public class ResolveDependencyCoordinatesTransformation extends public ResolveDependencyCoordinatesTransformation( DependencyResolutionContext resolutionContext) { - super(GRAB_ANNOTATION_NAMES); + super(GRAB_ANNOTATION_NAMES, false); this.resolutionContext = resolutionContext; } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringBootCompilerAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringBootCompilerAutoConfiguration.java index 1696eaaf2b..6801bfe840 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringBootCompilerAutoConfiguration.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringBootCompilerAutoConfiguration.java @@ -70,8 +70,7 @@ public class SpringBootCompilerAutoConfiguration extends CompilerAutoConfigurati "org.springframework.boot.context.properties.EnableConfigurationProperties", "org.springframework.boot.autoconfigure.EnableAutoConfiguration", "org.springframework.boot.context.properties.ConfigurationProperties", - "org.springframework.boot.context.properties.EnableConfigurationProperties", - "org.springframework.boot.groovy.GrabMetadata"); + "org.springframework.boot.context.properties.EnableConfigurationProperties"); imports.addStarImports("org.springframework.stereotype", "org.springframework.scheduling.annotation"); } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/CompositeDependencyManagement.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/CompositeDependencyManagement.java new file mode 100644 index 0000000000..7e11cead54 --- /dev/null +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/CompositeDependencyManagement.java @@ -0,0 +1,70 @@ +/* + * Copyright 2012-2015 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.cli.compiler.dependencies; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * {@link DependencyManagement} that delegates to one or more {@link DependencyManagement} + * instances + * + * @author Andy Wilkinson + * @since 1.3.0 + */ +public class CompositeDependencyManagement implements DependencyManagement { + + private final List delegates; + + private final List dependencies = new ArrayList(); + + public CompositeDependencyManagement(DependencyManagement... delegates) { + this.delegates = Arrays.asList(delegates); + for (DependencyManagement delegate : delegates) { + this.dependencies.addAll(delegate.getDependencies()); + } + } + + @Override + public List getDependencies() { + return this.dependencies; + } + + @Override + public String getSpringBootVersion() { + for (DependencyManagement delegate : this.delegates) { + String version = delegate.getSpringBootVersion(); + if (version != null) { + return version; + } + } + return null; + } + + @Override + public Dependency find(String artifactId) { + for (DependencyManagement delegate : this.delegates) { + Dependency found = delegate.find(artifactId); + if (found != null) { + return found; + } + } + return null; + } + +} diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/Dependency.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/Dependency.java similarity index 97% rename from spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/Dependency.java rename to spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/Dependency.java index 34c8ed386e..2267778b9a 100644 --- a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/Dependency.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/Dependency.java @@ -14,16 +14,18 @@ * limitations under the License. */ -package org.springframework.boot.dependency.tools; +package org.springframework.boot.cli.compiler.dependencies; import java.util.Collections; import java.util.List; +import org.springframework.util.Assert; + /** * A single dependency. * * @author Phillip Webb - * @see Dependencies + * @since 1.3.0 */ public final class Dependency { diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagement.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagement.java new file mode 100644 index 0000000000..adda0bd3d8 --- /dev/null +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagement.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-2015 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.cli.compiler.dependencies; + +import java.util.List; + +/** + * An encapsulation of dependency management information + * + * @author Andy Wilkinson + * @since 1.3.0 + */ +public interface DependencyManagement { + + /** + * Returns the managed dependencies. + * + * @return the managed dependencies + */ + List getDependencies(); + + /** + * Returns the managed version of Spring Boot. May be {@code null}. + * + * @return the Spring Boot version, or {@code null} + */ + String getSpringBootVersion(); + + /** + * Finds the managed dependency with the given {@code artifactId}. + * + * @param artifactId The artifact ID of the dependency to find + * @return the dependency, or {@code null} + */ + Dependency find(String artifactId); +} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagementArtifactCoordinatesResolver.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagementArtifactCoordinatesResolver.java new file mode 100644 index 0000000000..fce32d57ea --- /dev/null +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagementArtifactCoordinatesResolver.java @@ -0,0 +1,73 @@ +/* + * Copyright 2012-2015 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.cli.compiler.dependencies; + +import org.springframework.util.StringUtils; + +/** + * {@link ArtifactCoordinatesResolver} backed by {@link SpringBootDependenciesDependencyManagement}. + * + * @author Phillip Webb + * @author Andy Wilkinson + */ +public class DependencyManagementArtifactCoordinatesResolver implements + ArtifactCoordinatesResolver { + + private final DependencyManagement dependencyManagement; + + public DependencyManagementArtifactCoordinatesResolver() { + this(new SpringBootDependenciesDependencyManagement()); + } + + public DependencyManagementArtifactCoordinatesResolver( + DependencyManagement dependencyManagement) { + this.dependencyManagement = dependencyManagement; + } + + @Override + public String getGroupId(String artifactId) { + Dependency dependency = find(artifactId); + return (dependency == null ? null : dependency.getGroupId()); + } + + @Override + public String getArtifactId(String id) { + Dependency dependency = find(id); + return dependency == null ? null : dependency.getArtifactId(); + } + + private Dependency find(String id) { + if (StringUtils.countOccurrencesOf(id, ":") == 2) { + String[] tokens = id.split(":"); + return new Dependency(tokens[0], tokens[1], tokens[2]); + } + if (id != null) { + if (id.startsWith("spring-boot")) { + return new Dependency("org.springframework.boot", id, + this.dependencyManagement.getSpringBootVersion()); + } + return this.dependencyManagement.find(id); + } + return null; + } + + @Override + public String getVersion(String module) { + Dependency dependency = find(module); + return dependency == null ? null : dependency.getVersion(); + } +} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/ManagedDependenciesArtifactCoordinatesResolver.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/ManagedDependenciesArtifactCoordinatesResolver.java deleted file mode 100644 index 7c8f0ee55c..0000000000 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/ManagedDependenciesArtifactCoordinatesResolver.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.cli.compiler.dependencies; - -import org.springframework.boot.dependency.tools.Dependencies; -import org.springframework.boot.dependency.tools.Dependency; -import org.springframework.boot.dependency.tools.ManagedDependencies; -import org.springframework.util.StringUtils; - -/** - * {@link ArtifactCoordinatesResolver} backed by {@link Dependencies}. - * - * @author Phillip Webb - */ -public class ManagedDependenciesArtifactCoordinatesResolver implements - ArtifactCoordinatesResolver { - - private final ManagedDependencies dependencies; - - public ManagedDependenciesArtifactCoordinatesResolver() { - this(ManagedDependencies.get()); - } - - public ManagedDependenciesArtifactCoordinatesResolver(ManagedDependencies dependencies) { - this.dependencies = dependencies; - } - - @Override - public String getGroupId(String artifactId) { - Dependency dependency = find(artifactId); - return (dependency == null ? null : dependency.getGroupId()); - } - - @Override - public String getVersion(String artifactId) { - Dependency dependency = find(artifactId); - return (dependency == null ? null : dependency.getVersion()); - } - - @Override - public String getArtifactId(String artifactId) { - Dependency dependency = find(artifactId); - return (dependency == null ? null : dependency.getArtifactId()); - } - - private Dependency find(String artifactId) { - if (StringUtils.countOccurrencesOf(artifactId, ":") == 2) { - String[] tokens = artifactId.split(":"); - return new Dependency(tokens[0], tokens[1], tokens[2]); - } - if (artifactId != null) { - if (artifactId.startsWith("spring-boot")) { - return new Dependency("org.springframework.boot", artifactId, - this.dependencies.getSpringBootVersion()); - } - return this.dependencies.find(artifactId); - } - return null; - } -} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/MavenModelDependencyManagement.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/MavenModelDependencyManagement.java new file mode 100644 index 0000000000..26feb3595c --- /dev/null +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/MavenModelDependencyManagement.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2015 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.cli.compiler.dependencies; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.maven.model.Model; +import org.springframework.boot.cli.compiler.dependencies.Dependency.Exclusion; + +/** + * {@link DependencyManagement} derived from a Maven {@link Model} + * + * @author Andy Wilkinson + * @since 1.3.0 + */ +public class MavenModelDependencyManagement implements DependencyManagement { + + private final List dependencies; + + private final Map byArtifactId = new LinkedHashMap(); + + public MavenModelDependencyManagement(Model model) { + this.dependencies = extractDependenciesFromModel(model); + for (Dependency dependency : this.dependencies) { + this.byArtifactId.put(dependency.getArtifactId(), dependency); + } + } + + private static List extractDependenciesFromModel(Model model) { + List dependencies = new ArrayList(); + for (org.apache.maven.model.Dependency mavenDependency : model + .getDependencyManagement().getDependencies()) { + List exclusions = new ArrayList(); + for (org.apache.maven.model.Exclusion mavenExclusion : mavenDependency + .getExclusions()) { + exclusions.add(new Exclusion(mavenExclusion.getGroupId(), mavenExclusion + .getArtifactId())); + } + Dependency dependency = new Dependency(mavenDependency.getGroupId(), + mavenDependency.getArtifactId(), mavenDependency.getVersion(), + exclusions); + dependencies.add(dependency); + } + return dependencies; + } + + @Override + public List getDependencies() { + return this.dependencies; + } + + @Override + public String getSpringBootVersion() { + return find("spring-boot").getVersion(); + } + + @Override + public Dependency find(String artifactId) { + return this.byArtifactId.get(artifactId); + } +} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/SpringBootDependenciesDependencyManagement.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/SpringBootDependenciesDependencyManagement.java new file mode 100644 index 0000000000..8992d3fab6 --- /dev/null +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/SpringBootDependenciesDependencyManagement.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-2015 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.cli.compiler.dependencies; + +import java.io.IOException; + +import org.apache.maven.model.Model; +import org.apache.maven.model.building.DefaultModelProcessor; +import org.apache.maven.model.io.DefaultModelReader; +import org.apache.maven.model.locator.DefaultModelLocator; + +/** + * {@link DependencyManagement} derived from the effective pom of spring-boot-dependencies + * + * @author Andy Wilkinson + * @since 1.3.0 + */ +public class SpringBootDependenciesDependencyManagement extends + MavenModelDependencyManagement { + + public SpringBootDependenciesDependencyManagement() { + super(readModel()); + } + + private static Model readModel() { + DefaultModelProcessor modelProcessor = new DefaultModelProcessor(); + modelProcessor.setModelLocator(new DefaultModelLocator()); + modelProcessor.setModelReader(new DefaultModelReader()); + + try { + return modelProcessor.read(SpringBootDependenciesDependencyManagement.class + .getResourceAsStream("effective-pom.xml"), null); + } + catch (IOException ex) { + throw new IllegalStateException("Failed to build model from effective pom", + ex); + } + } + +} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java index 4cc25fbf2d..9f9f93759c 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -167,6 +167,9 @@ public class AetherGrapeEngine implements GrapeEngine { String group = (String) dependencyMap.get("group"); String module = (String) dependencyMap.get("module"); String version = (String) dependencyMap.get("version"); + if (version == null) { + version = this.resolutionContext.getManagedVersion(group, module); + } String classifier = (String) dependencyMap.get("classifier"); String type = determineType(dependencyMap); return new DefaultArtifact(group, module, classifier, type, version); @@ -324,7 +327,7 @@ public class AetherGrapeEngine implements GrapeEngine { } private void addManagedDependencies(DependencyResult result) { - this.resolutionContext.getManagedDependencies().addAll(getDependencies(result)); + this.resolutionContext.addManagedDependencies(getDependencies(result)); } @Override 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 41828cf06a..fe1f0beb74 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -17,12 +17,20 @@ package org.springframework.boot.cli.compiler.grape; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.graph.Dependency; +import org.eclipse.aether.graph.Exclusion; +import org.eclipse.aether.util.artifact.JavaScopes; import org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesResolver; -import org.springframework.boot.cli.compiler.dependencies.ManagedDependenciesArtifactCoordinatesResolver; -import org.springframework.boot.dependency.tools.ManagedDependencies; +import org.springframework.boot.cli.compiler.dependencies.CompositeDependencyManagement; +import org.springframework.boot.cli.compiler.dependencies.DependencyManagement; +import org.springframework.boot.cli.compiler.dependencies.DependencyManagementArtifactCoordinatesResolver; +import org.springframework.boot.cli.compiler.dependencies.SpringBootDependenciesDependencyManagement; /** * Context used when resolving dependencies. @@ -32,34 +40,77 @@ import org.springframework.boot.dependency.tools.ManagedDependencies; */ public class DependencyResolutionContext { - private ArtifactCoordinatesResolver artifactCoordinatesResolver; + private final Map managedDependencyByGroupAndArtifact = new HashMap(); - private List managedDependencies = new ArrayList(); + private final List managedDependencies = new ArrayList(); + + private DependencyManagement dependencyManagement = new SpringBootDependenciesDependencyManagement(); + + private ArtifactCoordinatesResolver artifactCoordinatesResolver = new DependencyManagementArtifactCoordinatesResolver( + this.dependencyManagement); public DependencyResolutionContext() { - this(new ManagedDependenciesArtifactCoordinatesResolver()); + addDependencyManagement(this.dependencyManagement); } - public DependencyResolutionContext( - ArtifactCoordinatesResolver artifactCoordinatesResolver) { - this.artifactCoordinatesResolver = artifactCoordinatesResolver; - this.managedDependencies = new ManagedDependenciesFactory() - .getManagedDependencies(); + private String getIdentifier(Dependency dependency) { + return getIdentifier(dependency.getArtifact().getGroupId(), dependency + .getArtifact().getArtifactId()); } - public void setManagedDependencies(ManagedDependencies managedDependencies) { - this.artifactCoordinatesResolver = new ManagedDependenciesArtifactCoordinatesResolver( - managedDependencies); - this.managedDependencies = new ArrayList( - new ManagedDependenciesFactory(managedDependencies) - .getManagedDependencies()); + private String getIdentifier(String groupId, String artifactId) { + return groupId + ":" + artifactId; } public ArtifactCoordinatesResolver getArtifactCoordinatesResolver() { return this.artifactCoordinatesResolver; } + public String getManagedVersion(String groupId, String artifactId) { + Dependency dependency = getManagedDependency(groupId, artifactId); + if (dependency == null) { + dependency = this.managedDependencyByGroupAndArtifact.get(getIdentifier( + groupId, artifactId)); + } + return dependency != null ? dependency.getArtifact().getVersion() : null; + } + public List getManagedDependencies() { - return this.managedDependencies; + return Collections.unmodifiableList(this.managedDependencies); + } + + private Dependency getManagedDependency(String group, String artifact) { + return this.managedDependencyByGroupAndArtifact + .get(getIdentifier(group, artifact)); } + + void addManagedDependencies(List dependencies) { + this.managedDependencies.addAll(dependencies); + for (Dependency dependency : dependencies) { + this.managedDependencyByGroupAndArtifact.put(getIdentifier(dependency), + dependency); + } + } + + public void addDependencyManagement(DependencyManagement dependencyManagement) { + for (org.springframework.boot.cli.compiler.dependencies.Dependency dependency : dependencyManagement + .getDependencies()) { + List aetherExclusions = new ArrayList(); + for (org.springframework.boot.cli.compiler.dependencies.Dependency.Exclusion exclusion : dependency + .getExclusions()) { + aetherExclusions.add(new Exclusion(exclusion.getGroupId(), exclusion + .getArtifactId(), "*", "*")); + } + Dependency aetherDependency = new Dependency(new DefaultArtifact( + dependency.getGroupId(), dependency.getArtifactId(), "jar", + dependency.getVersion()), JavaScopes.COMPILE, false, aetherExclusions); + this.managedDependencies.add(0, aetherDependency); + this.managedDependencyByGroupAndArtifact.put(getIdentifier(aetherDependency), + aetherDependency); + } + this.artifactCoordinatesResolver = new DependencyManagementArtifactCoordinatesResolver( + new CompositeDependencyManagement(dependencyManagement, + this.dependencyManagement)); + } + } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/ManagedDependenciesFactory.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/ManagedDependenciesFactory.java deleted file mode 100644 index da776ee5d9..0000000000 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/ManagedDependenciesFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2012-2015 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.cli.compiler.grape; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.util.artifact.JavaScopes; -import org.springframework.boot.dependency.tools.ManagedDependencies; -import org.springframework.boot.dependency.tools.PomDependencies; - -/** - * Factory to create Maven {@link Dependency} objects from Boot {@link PomDependencies}. - * - * @author Phillip Webb - */ -public class ManagedDependenciesFactory { - - private final ManagedDependencies dependencies; - - ManagedDependenciesFactory() { - this(ManagedDependencies.get()); - } - - public ManagedDependenciesFactory(ManagedDependencies dependencies) { - this.dependencies = dependencies; - } - - /** - * Return a list of the managed dependencies. - * @return the managed dependencies - */ - public List getManagedDependencies() { - List result = new ArrayList(); - for (org.springframework.boot.dependency.tools.Dependency dependency : this.dependencies) { - Artifact artifact = asArtifact(dependency); - result.add(new Dependency(artifact, JavaScopes.COMPILE)); - } - return result; - } - - private Artifact asArtifact( - org.springframework.boot.dependency.tools.Dependency dependency) { - return new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), - "jar", dependency.getVersion()); - } -} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/groovy/GrabMetadata.java b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/DependencyManagementBom.java similarity index 75% rename from spring-boot-cli/src/main/java/org/springframework/boot/groovy/GrabMetadata.java rename to spring-boot-cli/src/main/java/org/springframework/boot/groovy/DependencyManagementBom.java index 9e0157bcc3..a5d6445bb6 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/groovy/GrabMetadata.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/DependencyManagementBom.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -22,21 +22,21 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Used to provide an alternative source of dependency metadata that is used to deduce - * groups and versions when processing {@code @Grab} dependencies. + * Provides one or more additional sources of dependency management that is used when + * resolving {@code @Grab} dependencies. * * @author Andy Wilkinson - * @since 1.1.0 + * @since 1.3.0 */ @Target({ ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE }) @Retention(RetentionPolicy.SOURCE) -public @interface GrabMetadata { +public @interface DependencyManagementBom { /** * One or more sets of colon-separated coordinates ({@code group:module:version}) of a - * properties file that contains dependency metadata that will add to and override the - * default metadata. + * Maven bom that contains dependency management that will add to and override the + * default dependency management. */ String[] value(); diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/GrabCommandIntegrationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/GrabCommandIntegrationTests.java index 17e7f88cc5..66fe9f873c 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/GrabCommandIntegrationTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/GrabCommandIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -17,8 +17,6 @@ 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; @@ -65,31 +63,25 @@ public class GrabCommandIntegrationTests { } @Test - public void duplicateGrabMetadataAnnotationsProducesAnError() throws Exception { + public void duplicateDependencyManagementBomAnnotationsProducesAnError() + throws Exception { try { - this.cli.grab("duplicateGrabMetadata.groovy"); + this.cli.grab("duplicateDependencyManagementBom.groovy"); fail(); } catch (Exception ex) { assertThat(ex.getMessage(), - containsString("Duplicate @GrabMetadata annotation")); + containsString("Duplicate @DependencyManagementBom 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"); + FileSystemUtils.copyRecursively(new File( + "src/test/resources/grab-samples/repository"), new File( + "target/repository")); + this.cli.grab("customDependencyManagement.groovy", "--autoconfigure=false"); assertTrue(new File("target/repository/javax/ejb/ejb-api/3.0").isDirectory()); } } diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java index 7f915799ae..88e68d8f76 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -60,12 +60,17 @@ public class DependencyCustomizerTests { "org.springframework.boot"); given(this.resolver.getArtifactId("spring-boot-starter-logging")).willReturn( "spring-boot-starter-logging"); - given(this.resolver.getVersion("spring-boot-starter-logging")) - .willReturn("1.2.3"); this.moduleNode.addClass(this.classNode); this.dependencyCustomizer = new DependencyCustomizer(new GroovyClassLoader( getClass().getClassLoader()), this.moduleNode, - new DependencyResolutionContext(this.resolver)); + new DependencyResolutionContext() { + + @Override + public ArtifactCoordinatesResolver getArtifactCoordinatesResolver() { + return DependencyCustomizerTests.this.resolver; + } + + }); } @Test @@ -149,7 +154,6 @@ public class DependencyCustomizerTests { boolean transitive) { assertEquals(group, getMemberValue(annotationNode, "group")); assertEquals(module, getMemberValue(annotationNode, "module")); - assertEquals(version, getMemberValue(annotationNode, "version")); if (type == null) { assertNull(annotationNode.getMember("type")); } diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformationTests.java index 919ff4eba5..06f38d65a5 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformationTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -65,8 +65,14 @@ public final class ResolveDependencyCoordinatesTransformationTests { private final ArtifactCoordinatesResolver coordinatesResolver = mock(ArtifactCoordinatesResolver.class); - private final DependencyResolutionContext resolutionContext = new DependencyResolutionContext( - this.coordinatesResolver); + private final DependencyResolutionContext resolutionContext = new DependencyResolutionContext() { + + @Override + public ArtifactCoordinatesResolver getArtifactCoordinatesResolver() { + return ResolveDependencyCoordinatesTransformationTests.this.coordinatesResolver; + } + + }; private final ASTTransformation transformation = new ResolveDependencyCoordinatesTransformation( this.resolutionContext); @@ -75,13 +81,12 @@ public final class ResolveDependencyCoordinatesTransformationTests { public void setupExpectations() { given(this.coordinatesResolver.getGroupId("spring-core")).willReturn( "org.springframework"); - given(this.coordinatesResolver.getVersion("spring-core")).willReturn("4.0.0.RC1"); } @Test public void transformationOfAnnotationOnImport() { this.moduleNode.addImport(null, null, Arrays.asList(this.grabAnnotation)); - assertGrabAnnotationHasBeenTransformation(); + assertGrabAnnotationHasBeenTransformed(); } @Test @@ -89,7 +94,7 @@ public final class ResolveDependencyCoordinatesTransformationTests { this.moduleNode.addStarImport("org.springframework.util", Arrays.asList(this.grabAnnotation)); - assertGrabAnnotationHasBeenTransformation(); + assertGrabAnnotationHasBeenTransformed(); } @Test @@ -97,7 +102,7 @@ public final class ResolveDependencyCoordinatesTransformationTests { this.moduleNode.addStaticImport(null, null, null, Arrays.asList(this.grabAnnotation)); - assertGrabAnnotationHasBeenTransformation(); + assertGrabAnnotationHasBeenTransformed(); } @Test @@ -105,7 +110,7 @@ public final class ResolveDependencyCoordinatesTransformationTests { this.moduleNode.addStaticStarImport(null, null, Arrays.asList(this.grabAnnotation)); - assertGrabAnnotationHasBeenTransformation(); + assertGrabAnnotationHasBeenTransformed(); } @Test @@ -114,7 +119,7 @@ public final class ResolveDependencyCoordinatesTransformationTests { packageNode.addAnnotation(this.grabAnnotation); this.moduleNode.setPackage(packageNode); - assertGrabAnnotationHasBeenTransformation(); + assertGrabAnnotationHasBeenTransformed(); } @Test @@ -123,7 +128,7 @@ public final class ResolveDependencyCoordinatesTransformationTests { classNode.addAnnotation(this.grabAnnotation); this.moduleNode.addClass(classNode); - assertGrabAnnotationHasBeenTransformation(); + assertGrabAnnotationHasBeenTransformed(); } @Test @@ -141,7 +146,7 @@ public final class ResolveDependencyCoordinatesTransformationTests { fieldNode.addAnnotation(this.grabAnnotation); - assertGrabAnnotationHasBeenTransformation(); + assertGrabAnnotationHasBeenTransformed(); } @Test @@ -153,7 +158,7 @@ public final class ResolveDependencyCoordinatesTransformationTests { constructorNode.addAnnotation(this.grabAnnotation); classNode.addMethod(constructorNode); - assertGrabAnnotationHasBeenTransformation(); + assertGrabAnnotationHasBeenTransformed(); } @Test @@ -166,7 +171,7 @@ public final class ResolveDependencyCoordinatesTransformationTests { methodNode.addAnnotation(this.grabAnnotation); classNode.addMethod(methodNode); - assertGrabAnnotationHasBeenTransformation(); + assertGrabAnnotationHasBeenTransformed(); } @Test @@ -181,7 +186,7 @@ public final class ResolveDependencyCoordinatesTransformationTests { new Parameter[] { parameter }, new ClassNode[0], null); classNode.addMethod(methodNode); - assertGrabAnnotationHasBeenTransformation(); + assertGrabAnnotationHasBeenTransformed(); } @Test @@ -202,7 +207,7 @@ public final class ResolveDependencyCoordinatesTransformationTests { classNode.addMethod(methodNode); - assertGrabAnnotationHasBeenTransformation(); + assertGrabAnnotationHasBeenTransformed(); } private AnnotationNode createGrabAnnotation() { @@ -212,12 +217,11 @@ public final class ResolveDependencyCoordinatesTransformationTests { return annotationNode; } - private void assertGrabAnnotationHasBeenTransformation() { + private void assertGrabAnnotationHasBeenTransformed() { this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit); assertEquals("org.springframework", getGrabAnnotationMemberAsString("group")); assertEquals("spring-core", getGrabAnnotationMemberAsString("module")); - assertEquals("4.0.0.RC1", getGrabAnnotationMemberAsString("version")); } private Object getGrabAnnotationMemberAsString(String memberName) { diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/CompositeDependencyManagementTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/CompositeDependencyManagementTests.java new file mode 100644 index 0000000000..bb578b24cb --- /dev/null +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/CompositeDependencyManagementTests.java @@ -0,0 +1,98 @@ +/* + * Copyright 2012-2015 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.cli.compiler.dependencies; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.given; + +/** + * Tests for {@link CompositeDependencyManagement} + * + * @author Andy Wilkinson + */ +@RunWith(MockitoJUnitRunner.class) +public class CompositeDependencyManagementTests { + + @Mock + private DependencyManagement dependencyManagement1; + + @Mock + private DependencyManagement dependencyManagement2; + + @Test + public void unknownSpringBootVersion() { + given(this.dependencyManagement1.getSpringBootVersion()).willReturn(null); + given(this.dependencyManagement2.getSpringBootVersion()).willReturn(null); + + assertThat(new CompositeDependencyManagement(this.dependencyManagement1, + this.dependencyManagement2).getSpringBootVersion(), is(nullValue())); + } + + @Test + public void knownSpringBootVersion() { + given(this.dependencyManagement1.getSpringBootVersion()).willReturn("1.2.3"); + given(this.dependencyManagement2.getSpringBootVersion()).willReturn("1.2.4"); + + assertThat(new CompositeDependencyManagement(this.dependencyManagement1, + this.dependencyManagement2).getSpringBootVersion(), is("1.2.3")); + } + + @Test + public void unknownDependency() { + given(this.dependencyManagement1.find("artifact")).willReturn(null); + given(this.dependencyManagement2.find("artifact")).willReturn(null); + + assertThat(new CompositeDependencyManagement(this.dependencyManagement1, + this.dependencyManagement2).find("artifact"), is(nullValue())); + } + + @Test + public void knownDependency() { + given(this.dependencyManagement1.find("artifact")).willReturn( + new Dependency("test", "artifact", "1.2.3")); + given(this.dependencyManagement2.find("artifact")).willReturn( + new Dependency("test", "artifact", "1.2.4")); + + assertThat(new CompositeDependencyManagement(this.dependencyManagement1, + this.dependencyManagement2).find("artifact"), is(new Dependency("test", + "artifact", "1.2.3"))); + } + + @Test + public void getDependencies() { + given(this.dependencyManagement1.getDependencies()).willReturn( + Arrays.asList(new Dependency("test", "artifact", "1.2.3"))); + given(this.dependencyManagement2.getDependencies()).willReturn( + Arrays.asList(new Dependency("test", "artifact", "1.2.4"))); + + assertThat( + new CompositeDependencyManagement(this.dependencyManagement1, + this.dependencyManagement2).getDependencies(), + contains(new Dependency("test", "artifact", "1.2.3"), new Dependency( + "test", "artifact", "1.2.4"))); + } +} diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/ManagedDependenciesArtifactCoordinatesResolverTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagementArtifactCoordinatesResolverTests.java similarity index 55% rename from spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/ManagedDependenciesArtifactCoordinatesResolverTests.java rename to spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagementArtifactCoordinatesResolverTests.java index 734fd5edac..51d9f9a128 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/ManagedDependenciesArtifactCoordinatesResolverTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagementArtifactCoordinatesResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -18,8 +18,6 @@ package org.springframework.boot.cli.compiler.dependencies; import org.junit.Before; import org.junit.Test; -import org.springframework.boot.dependency.tools.Dependency; -import org.springframework.boot.dependency.tools.ManagedDependencies; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; @@ -31,30 +29,32 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; /** - * Tests for {@link ManagedDependenciesArtifactCoordinatesResolver}. + * Tests for {@link DependencyManagementArtifactCoordinatesResolver}. * * @author Phillip Webb + * @author Andy Wilkinson */ -public class ManagedDependenciesArtifactCoordinatesResolverTests { +public class DependencyManagementArtifactCoordinatesResolverTests { - private ManagedDependencies dependencies; + private DependencyManagement dependencyManagement; - private ManagedDependenciesArtifactCoordinatesResolver resolver; + private DependencyManagementArtifactCoordinatesResolver resolver; @Before public void setup() { - this.dependencies = mock(ManagedDependencies.class); - given(this.dependencies.find("a1")).willReturn(new Dependency("g1", "a1", "0")); - given(this.dependencies.getSpringBootVersion()).willReturn("1"); - this.resolver = new ManagedDependenciesArtifactCoordinatesResolver( - this.dependencies); + this.dependencyManagement = mock(DependencyManagement.class); + given(this.dependencyManagement.find("a1")).willReturn( + new Dependency("g1", "a1", "0")); + given(this.dependencyManagement.getSpringBootVersion()).willReturn("1"); + this.resolver = new DependencyManagementArtifactCoordinatesResolver( + this.dependencyManagement); } @Test public void getGroupIdForBootArtifact() throws Exception { assertThat(this.resolver.getGroupId("spring-boot-something"), equalTo("org.springframework.boot")); - verify(this.dependencies, never()).find(anyString()); + verify(this.dependencyManagement, never()).find(anyString()); } @Test @@ -67,20 +67,4 @@ public class ManagedDependenciesArtifactCoordinatesResolverTests { assertThat(this.resolver.getGroupId("a2"), nullValue()); } - @Test - public void getVersionForBootArtifact() throws Exception { - assertThat(this.resolver.getVersion("spring-boot-something"), equalTo("1")); - verify(this.dependencies, never()).find(anyString()); - } - - @Test - public void getVersionFound() throws Exception { - assertThat(this.resolver.getVersion("a1"), equalTo("0")); - } - - @Test - public void getVersionNotFound() throws Exception { - assertThat(this.resolver.getVersion("a2"), nullValue()); - } - } diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/SpringBootDependenciesDependencyManagementTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/SpringBootDependenciesDependencyManagementTests.java new file mode 100644 index 0000000000..ccd5a906f2 --- /dev/null +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/SpringBootDependenciesDependencyManagementTests.java @@ -0,0 +1,55 @@ +/* + * Copyright 2012-2015 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.cli.compiler.dependencies; + +import org.junit.Test; + +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThat; + +/** + * Tests for {@link SpringBootDependenciesDependencyManagement} + * + * @author Andy Wilkinson + */ +public class SpringBootDependenciesDependencyManagementTests { + + private final DependencyManagement dependencyManagement = new SpringBootDependenciesDependencyManagement(); + + @Test + public void springBootVersion() { + assertThat(this.dependencyManagement.getSpringBootVersion(), is(notNullValue())); + } + + @Test + public void find() { + Dependency dependency = this.dependencyManagement.find("spring-boot"); + assertThat(dependency, is(notNullValue())); + assertThat(dependency.getGroupId(), is(equalTo("org.springframework.boot"))); + assertThat(dependency.getArtifactId(), is(equalTo("spring-boot"))); + } + + @Test + public void getDependencies() { + assertThat(this.dependencyManagement.getDependencies(), is(not(empty()))); + } + +} diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/ManagedDependenciesFactoryTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/ManagedDependenciesFactoryTests.java deleted file mode 100644 index 02e2036834..0000000000 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/ManagedDependenciesFactoryTests.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.cli.compiler.grape; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; -import org.springframework.boot.dependency.tools.Dependency; -import org.springframework.boot.dependency.tools.ManagedDependencies; - -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link ManagedDependenciesFactory}. - * - * @author Phillip Webb - */ -public class ManagedDependenciesFactoryTests { - - @Test - public void getManagedDependencies() { - List dependencyList = new ArrayList(); - dependencyList.add(new Dependency("g1", "a1", "1")); - dependencyList.add(new Dependency("g1", "a2", "1")); - ManagedDependencies dependencies = mock(ManagedDependencies.class); - given(dependencies.iterator()).willReturn(dependencyList.iterator()); - ManagedDependenciesFactory factory = new ManagedDependenciesFactory(dependencies); - List result = factory - .getManagedDependencies(); - assertThat(result.size(), equalTo(2)); - assertThat(result.get(0).toString(), equalTo("g1:a1:jar:1 (compile)")); - assertThat(result.get(1).toString(), equalTo("g1:a2:jar:1 (compile)")); - } - -} diff --git a/spring-boot-cli/src/test/resources/grab-samples/customDependencyManagement.groovy b/spring-boot-cli/src/test/resources/grab-samples/customDependencyManagement.groovy new file mode 100644 index 0000000000..c50878b57a --- /dev/null +++ b/spring-boot-cli/src/test/resources/grab-samples/customDependencyManagement.groovy @@ -0,0 +1,5 @@ +@DependencyManagementBom('test:child:1.0.0') +@Grab('ejb-api') +class CustomDependencyManagement { + +} \ No newline at end of file diff --git a/spring-boot-cli/src/test/resources/grab-samples/customGrabMetadata.groovy b/spring-boot-cli/src/test/resources/grab-samples/customGrabMetadata.groovy deleted file mode 100644 index 2b22c50c99..0000000000 --- a/spring-boot-cli/src/test/resources/grab-samples/customGrabMetadata.groovy +++ /dev/null @@ -1,5 +0,0 @@ -@org.springframework.boot.groovy.GrabMetadata('test:test:1.0.0') -@Grab('ejb-api') -class CustomGrabMetadata { - -} \ No newline at end of file diff --git a/spring-boot-cli/src/test/resources/grab-samples/duplicateDependencyManagementBom.groovy b/spring-boot-cli/src/test/resources/grab-samples/duplicateDependencyManagementBom.groovy new file mode 100644 index 0000000000..4d6b1decaa --- /dev/null +++ b/spring-boot-cli/src/test/resources/grab-samples/duplicateDependencyManagementBom.groovy @@ -0,0 +1,5 @@ +@DependencyManagementBom("foo:bar:1.0") +@DependencyManagementBom("alpha:bravo:2.0") +class DuplicateDependencyManagement { + +} \ No newline at end of file diff --git a/spring-boot-cli/src/test/resources/grab-samples/duplicateGrabMetadata.groovy b/spring-boot-cli/src/test/resources/grab-samples/duplicateGrabMetadata.groovy deleted file mode 100644 index cc4a7d6e73..0000000000 --- a/spring-boot-cli/src/test/resources/grab-samples/duplicateGrabMetadata.groovy +++ /dev/null @@ -1,5 +0,0 @@ -@GrabMetadata("foo:bar:1.0") -@GrabMetadata("alpha:bravo:2.0") -class DuplicateGrabMetadata { - -} \ No newline at end of file diff --git a/spring-boot-cli/src/test/resources/grab-samples/repository/test/child/1.0.0/child-1.0.0.pom b/spring-boot-cli/src/test/resources/grab-samples/repository/test/child/1.0.0/child-1.0.0.pom new file mode 100644 index 0000000000..84a58ec619 --- /dev/null +++ b/spring-boot-cli/src/test/resources/grab-samples/repository/test/child/1.0.0/child-1.0.0.pom @@ -0,0 +1,13 @@ + + + test + parent + 1.0.0 + + + child + 1.0.0 + pom + + 4.0.0 + \ No newline at end of file diff --git a/spring-boot-cli/src/test/resources/grab-samples/repository/test/parent/1.0.0/parent-1.0.0.pom b/spring-boot-cli/src/test/resources/grab-samples/repository/test/parent/1.0.0/parent-1.0.0.pom new file mode 100644 index 0000000000..25f32e7a50 --- /dev/null +++ b/spring-boot-cli/src/test/resources/grab-samples/repository/test/parent/1.0.0/parent-1.0.0.pom @@ -0,0 +1,18 @@ + + test + parent + 1.0.0 + pom + + 4.0.0 + + + + + javax.ejb + ejb-api + 3.0 + + + + \ No newline at end of file diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index 2290b1423e..1b0df2fd90 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -181,11 +181,6 @@ spring-boot-configuration-processor 1.3.0.BUILD-SNAPSHOT - - org.springframework.boot - spring-boot-dependency-tools - 1.3.0.BUILD-SNAPSHOT - org.springframework.boot spring-boot-loader @@ -1739,6 +1734,68 @@ + + + maven-help-plugin + false + + + generate-effective-dependencies-pom + generate-resources + + effective-pom + + + ${project.build.directory}/effective-pom/spring-boot-dependencies.xml + + + + + + org.codehaus.mojo + xml-maven-plugin + 1.0 + false + + + + transform + + + + + + + ${project.build.directory}/effective-pom + src/main/xslt/single-project.xsl + ${project.build.directory}/effective-pom + + + + + + org.codehaus.mojo + build-helper-maven-plugin + false + + + attach-artifacts + package + + attach-artifact + + + + + ${project.build.directory}/effective-pom/spring-boot-dependencies.xml + effective-pom + + + + + + + diff --git a/spring-boot-dependencies/src/main/xslt/single-project.xsl b/spring-boot-dependencies/src/main/xslt/single-project.xsl new file mode 100644 index 0000000000..895d255cad --- /dev/null +++ b/spring-boot-dependencies/src/main/xslt/single-project.xsl @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/spring-boot-docs/pom.xml b/spring-boot-docs/pom.xml index 28c414f964..36d4a5ccb2 100644 --- a/spring-boot-docs/pom.xml +++ b/spring-boot-docs/pom.xml @@ -392,7 +392,7 @@ org.springframework.boot - spring-boot-versions + spring-boot-dependencies ${project.version} effective-pom true diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-cli.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-cli.adoc index 14ba668db5..9473a3221f 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-cli.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-cli.adoc @@ -213,40 +213,42 @@ Unlike the equivalent Java application, you do not need to include a -[[cli-default-grab-deduced-coordinates-custom-metadata]] -==== Custom "`grab`" metadata -Spring Boot provides a new `@GrabMetadata` annotation that can be used to provide custom -dependency metadata that overrides Spring Boot's defaults. This metadata is specified by -using the annotation to provide coordinates of one or more properties files (deployed -to a Maven repository with a "`type`" identifier of `properties`). Each entry in each -properties file must be in the form `group:module=version`. +[[cli-default-grab-deduced-coordinates-custom-dependency-management]] +==== Custom dependency management +By default, the CLI uses the dependency management declared in `spring-boot-dependencies` +when resolving `@Grab` dependencies. Additional dependency management, that will override +the default dependency management, can be configured using the `@DependencyManagementBom` +annotation. The annotation's value should specify the coordinates +(`groupId:artifactId:version`) of one or more Maven boms. For example, the following declaration: -[source,java,indent=0] +[source,groovy,indent=0] ---- - `@GrabMetadata("com.example.custom-versions:1.0.0")` + `@DependencyManagementBom("com.example.custom-bom:1.0.0")` ---- -Will pick up `custom-versions-1.0.0.properties` in a Maven repository under +Will pick up `custom-bom-1.0.0.pom` in a Maven repository under `com/example/custom-versions/1.0.0/`. -Multiple properties files can be specified from the annotation, they will be applied in -the order that they're declared. For example: +When multiple boms are specified they are applied in the order that they're declared. +For example: [source,java,indent=0] ---- - `@GrabMetadata(["com.example.custom-versions:1.0.0", - "com.example.more-versions:1.0.0"])` + `@DependencyManagementBom(["com.example.custom-bom:1.0.0", + "com.example.another-bom:1.0.0"])` ---- -indicates that properties in `more-versions` will override properties in `custom-versions`. +indicates that dependency management in `another-bom` will override the dependency +management in `custom-bom`. -You can use `@GrabMetadata` anywhere that you can use `@Grab`, however, to ensure -consistent ordering of the metadata, you can only use `@GrabMetadata` at most once in your -application. A useful source of dependency metadata (a superset of Spring Boot) is the +You can use `@DependencyManagementBom` anywhere that you can use `@Grab`, however, to +ensure consistent ordering of the dependency management, you can only use +`@DependencyManagementBom` at most once in your application. A useful source of +dependency management (that is a superset of Spring Boot's dependency management) is the http://platform.spring.io/[Spring IO Platform], e.g. -`@GrabMetadata('io.spring.platform:platform-versions:1.0.4.RELEASE')`. +`@DepenedencyManagementBom('io.spring.platform:platform-bom:1.1.2.RELEASE')`. diff --git a/spring-boot-full-build/pom.xml b/spring-boot-full-build/pom.xml index 0d66fc54f9..87cf54a2b0 100644 --- a/spring-boot-full-build/pom.xml +++ b/spring-boot-full-build/pom.xml @@ -45,7 +45,6 @@ ../ - ../spring-boot-versions ../spring-boot-dependencies ../spring-boot-parent ../spring-boot-tools diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/pom.xml b/spring-boot-integration-tests/spring-boot-gradle-tests/pom.xml index 3fc1b3496b..6595e5a05d 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/pom.xml +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/pom.xml @@ -27,15 +27,46 @@ org.springframework.boot - spring-boot-dependency-tools + spring-boot test - org.springframework.boot - spring-boot + org.apache.maven + maven-model-builder + 3.2.1 test + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-effective-pom + generate-test-resources + + copy + + + + + org.springframework.boot + spring-boot-dependencies + ${project.version} + effective-pom + true + ${project.build.directory} + dependencies-pom.xml + + + + + + + + gradle diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/BootRunResourceTests.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/BootRunResourceTests.java index 82cfb9ba27..30a3063412 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/BootRunResourceTests.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/BootRunResourceTests.java @@ -22,7 +22,6 @@ import org.gradle.tooling.ProjectConnection; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; -import org.springframework.boot.dependency.tools.ManagedDependencies; import org.springframework.boot.test.OutputCapture; import static org.hamcrest.Matchers.containsString; @@ -35,8 +34,7 @@ import static org.junit.Assert.assertThat; */ public class BootRunResourceTests { - private static final String BOOT_VERSION = ManagedDependencies.get() - .find("spring-boot").getVersion(); + private static final String BOOT_VERSION = Versions.getBootVersion(); private static ProjectConnection project; diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/ClassifierTests.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/ClassifierTests.java index 717967e18c..257beb76e3 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/ClassifierTests.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/ClassifierTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -20,7 +20,6 @@ import java.util.jar.JarFile; import org.gradle.tooling.ProjectConnection; import org.junit.Test; -import org.springframework.boot.dependency.tools.ManagedDependencies; import static org.junit.Assert.assertNotNull; @@ -33,8 +32,7 @@ public class ClassifierTests { private ProjectConnection project; - private static final String BOOT_VERSION = ManagedDependencies.get() - .find("spring-boot").getVersion(); + private static final String BOOT_VERSION = Versions.getBootVersion(); @Test public void classifierInBootTask() throws Exception { diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/FlatdirTests.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/FlatdirTests.java index b27770776f..281deaa654 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/FlatdirTests.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/FlatdirTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -21,7 +21,6 @@ import java.io.File; import org.gradle.tooling.ProjectConnection; import org.junit.Before; import org.junit.Test; -import org.springframework.boot.dependency.tools.ManagedDependencies; import org.springframework.util.FileCopyUtils; import org.springframework.util.FileSystemUtils; @@ -36,8 +35,7 @@ public class FlatdirTests { private File libs = new File("target/flatdir/lib"); - private static final String BOOT_VERSION = ManagedDependencies.get() - .find("spring-boot").getVersion(); + private static final String BOOT_VERSION = Versions.getBootVersion(); @Before public void init() { diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/InstallTests.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/InstallTests.java index ed23c3671d..6ab58ae0ea 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/InstallTests.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/InstallTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -18,7 +18,6 @@ package org.springframework.boot.gradle; import org.gradle.tooling.ProjectConnection; import org.junit.Test; -import org.springframework.boot.dependency.tools.ManagedDependencies; /** * Tests for using the Gradle plugin's support for installing artifacts @@ -29,8 +28,7 @@ public class InstallTests { private ProjectConnection project; - private static final String BOOT_VERSION = ManagedDependencies.get() - .find("spring-boot").getVersion(); + private static final String BOOT_VERSION = Versions.getBootVersion(); @Test public void cleanInstall() throws Exception { diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/MainClassTests.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/MainClassTests.java index b61a5ddf3f..c006e871b7 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/MainClassTests.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/MainClassTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -21,7 +21,6 @@ import java.io.IOException; import org.gradle.tooling.ProjectConnection; import org.junit.BeforeClass; import org.junit.Test; -import org.springframework.boot.dependency.tools.ManagedDependencies; /** * Tests for using the Gradle plugin's support for installing artifacts @@ -32,8 +31,7 @@ public class MainClassTests { private static ProjectConnection project; - private static final String BOOT_VERSION = ManagedDependencies.get() - .find("spring-boot").getVersion(); + private static final String BOOT_VERSION = Versions.getBootVersion(); @BeforeClass public static void createProject() throws IOException { diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/MultiProjectRepackagingTests.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/MultiProjectRepackagingTests.java index 21cc2d660b..2f060b41bb 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/MultiProjectRepackagingTests.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/MultiProjectRepackagingTests.java @@ -21,7 +21,6 @@ import java.util.jar.JarFile; import org.gradle.tooling.ProjectConnection; import org.junit.Test; -import org.springframework.boot.dependency.tools.ManagedDependencies; import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertThat; @@ -33,8 +32,7 @@ import static org.junit.Assert.assertThat; */ public class MultiProjectRepackagingTests { - private static final String BOOT_VERSION = ManagedDependencies.get() - .find("spring-boot").getVersion(); + private static final String BOOT_VERSION = Versions.getBootVersion(); @Test public void repackageWithTransitiveFileDependency() throws Exception { diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/NoJarTests.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/NoJarTests.java index 0ece066f3f..26fb8f1eaf 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/NoJarTests.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/NoJarTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -20,7 +20,6 @@ import java.io.File; import org.gradle.tooling.ProjectConnection; import org.junit.Test; -import org.springframework.boot.dependency.tools.ManagedDependencies; import static org.junit.Assert.assertFalse; @@ -33,8 +32,7 @@ public class NoJarTests { private ProjectConnection project; - private static final String BOOT_VERSION = ManagedDependencies.get() - .find("spring-boot").getVersion(); + private static final String BOOT_VERSION = Versions.getBootVersion(); @Test public void nojar() throws Exception { diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/RepackagingTests.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/RepackagingTests.java index 0010d2188f..c0f830e461 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/RepackagingTests.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/RepackagingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -23,7 +23,6 @@ import java.util.jar.JarFile; import org.gradle.tooling.ProjectConnection; import org.junit.BeforeClass; import org.junit.Test; -import org.springframework.boot.dependency.tools.ManagedDependencies; import org.springframework.util.FileCopyUtils; import static org.hamcrest.Matchers.notNullValue; @@ -38,8 +37,7 @@ import static org.junit.Assert.assertTrue; */ public class RepackagingTests { - private static final String BOOT_VERSION = ManagedDependencies.get() - .find("spring-boot").getVersion(); + private static final String BOOT_VERSION = Versions.getBootVersion(); private static ProjectConnection project; diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/SpringLoadedTests.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/SpringLoadedTests.java index 5cd2f78ab4..9b18e02e13 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/SpringLoadedTests.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/SpringLoadedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -25,7 +25,6 @@ import java.util.List; import org.gradle.tooling.ProjectConnection; import org.junit.Test; -import org.springframework.boot.dependency.tools.ManagedDependencies; import static org.junit.Assert.fail; @@ -36,11 +35,9 @@ import static org.junit.Assert.fail; */ public class SpringLoadedTests { - private static final String BOOT_VERSION = ManagedDependencies.get() - .find("spring-boot").getVersion(); + private static final String BOOT_VERSION = Versions.getBootVersion(); - private static final String SPRING_LOADED_VERSION = ManagedDependencies.get() - .find("springloaded").getVersion(); + private static final String SPRING_LOADED_VERSION = Versions.getSpringLoadedVersion(); @Test public void defaultJvmArgsArePreservedWhenLoadedAgentIsConfigured() diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/Versions.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/Versions.java new file mode 100644 index 0000000000..f6f07800ee --- /dev/null +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/Versions.java @@ -0,0 +1,60 @@ +/* + * Copyright 2012-2015 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.gradle; + +import java.io.FileReader; + +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathFactory; + +import org.xml.sax.InputSource; + +/** + * @author Andy Wilkinson + */ +public class Versions { + + public static String getBootVersion() { + return evaluateExpression("/*[local-name()='project']/*[local-name()='version']" + + "/text()"); + } + + public static String getSpringLoadedVersion() { + return evaluateExpression("/*[local-name()='project']/*[local-name()='properties']" + + "/*[local-name()='spring-loaded.version']/text()"); + } + + public static String getSpringVersion() { + return evaluateExpression("/*[local-name()='project']/*[local-name()='properties']" + + "/*[local-name()='spring.version']/text()"); + } + + private static String evaluateExpression(String expression) { + try { + XPathFactory xPathfactory = XPathFactory.newInstance(); + XPath xpath = xPathfactory.newXPath(); + XPathExpression expr = xpath.compile(expression); + String version = expr.evaluate(new InputSource(new FileReader( + "target/dependencies-pom.xml"))); + return version; + } + catch (Exception ex) { + throw new IllegalStateException("Failed to evaluate expression", ex); + } + } +} diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/WarPackagingTests.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/WarPackagingTests.java index 274453e924..78d30e2b9e 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/WarPackagingTests.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/WarPackagingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -29,7 +29,6 @@ import java.util.jar.JarFile; import org.gradle.tooling.ProjectConnection; import org.junit.BeforeClass; import org.junit.Test; -import org.springframework.boot.dependency.tools.ManagedDependencies; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -62,8 +61,7 @@ public class WarPackagingTests { "websocket-server-", "jetty-jndi-", "jetty-xml-", "websocket-servlet-")); - private static final String BOOT_VERSION = ManagedDependencies.get() - .find("spring-boot").getVersion(); + private static final String BOOT_VERSION = Versions.getBootVersion(); private static ProjectConnection project; diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/starter/StarterDependenciesIntegrationTests.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/starter/StarterDependenciesIntegrationTests.java index 26245cd2f2..7f05c36995 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/starter/StarterDependenciesIntegrationTests.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/starter/StarterDependenciesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. @@ -30,8 +30,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import org.springframework.boot.dependency.tools.ManagedDependencies; import org.springframework.boot.gradle.ProjectCreator; +import org.springframework.boot.gradle.Versions; import static org.junit.Assert.fail; @@ -79,8 +79,8 @@ public class StarterDependenciesIntegrationTests { @BeforeClass public static void determineVersions() throws Exception { - springVersion = ManagedDependencies.get().find("spring-core").getVersion(); - bootVersion = ManagedDependencies.get().find("spring-boot").getVersion(); + springVersion = Versions.getSpringVersion(); + bootVersion = Versions.getBootVersion(); } @AfterClass diff --git a/spring-boot-parent/pom.xml b/spring-boot-parent/pom.xml index ebe5d989ba..05e26787b6 100644 --- a/spring-boot-parent/pom.xml +++ b/spring-boot-parent/pom.xml @@ -19,7 +19,7 @@ .. 1.6 - 0.9.1.v20140329 + 1.0.2.v20150114 20140107 UTF-8 UTF-8 diff --git a/spring-boot-tools/pom.xml b/spring-boot-tools/pom.xml index 3016b39a9b..dbd6e76065 100644 --- a/spring-boot-tools/pom.xml +++ b/spring-boot-tools/pom.xml @@ -21,7 +21,6 @@ spring-boot-configuration-processor - spring-boot-dependency-tools spring-boot-loader spring-boot-loader-tools spring-boot-maven-plugin diff --git a/spring-boot-tools/spring-boot-dependency-tools/pom.xml b/spring-boot-tools/spring-boot-dependency-tools/pom.xml deleted file mode 100644 index 0fcf41351f..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-tools - 1.3.0.BUILD-SNAPSHOT - - spring-boot-dependency-tools - Spring Boot Dependency Tools - Spring Boot Dependency Tools - http://projects.spring.io/spring-boot/ - - Pivotal Software, Inc. - http://www.spring.io - - - ${basedir}/../.. - ${project.build.directory}/generated-resources/org/springframework/boot/dependency/tools - - - - - ${project.build.directory}/generated-resources - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-effective-pom - generate-resources - - copy - - - - - org.springframework.boot - spring-boot-versions - ${project.version} - effective-pom - true - ${generated.pom.dir} - effective-pom.xml - - - - - - - - - diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/AbstractDependencies.java b/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/AbstractDependencies.java deleted file mode 100644 index 069c92e498..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/AbstractDependencies.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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.ArrayList; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -import org.springframework.boot.dependency.tools.Dependency.Exclusion; - -/** - * Abstract base implementation for {@link Dependencies}. - * - * @author Phillip Webb - * @author Andy Wilkinson - * @since 1.1.0 - */ -abstract class AbstractDependencies implements Dependencies { - - private final Map byArtifactAndGroupId; - - private final Map byArtifactId; - - public AbstractDependencies() { - this.byArtifactAndGroupId = new LinkedHashMap(); - this.byArtifactId = new LinkedHashMap(); - } - - @Override - public Dependency find(String groupId, String artifactId) { - return this.byArtifactAndGroupId.get(new ArtifactAndGroupId(groupId, artifactId)); - } - - @Override - public Dependency find(String artifactId) { - return this.byArtifactId.get(artifactId); - } - - @Override - public Iterator iterator() { - return this.byArtifactAndGroupId.values().iterator(); - } - - protected void add(ArtifactAndGroupId artifactAndGroupId, Dependency dependency) { - Dependency existing = this.byArtifactAndGroupId.get(artifactAndGroupId); - if (existing != null) { - dependency = mergeDependencies(existing, dependency); - } - this.byArtifactAndGroupId.put(artifactAndGroupId, dependency); - this.byArtifactId.put(dependency.getArtifactId(), dependency); - } - - private Dependency mergeDependencies(Dependency existingDependency, - Dependency newDependency) { - Set combinedExclusions = new LinkedHashSet(); - combinedExclusions.addAll(existingDependency.getExclusions()); - combinedExclusions.addAll(newDependency.getExclusions()); - return new Dependency(newDependency.getGroupId(), newDependency.getArtifactId(), - newDependency.getVersion(), new ArrayList(combinedExclusions)); - } - - /** - * Simple holder for an artifact+group ID. - */ - protected static class ArtifactAndGroupId { - - private final String groupId; - - private final String artifactId; - - public ArtifactAndGroupId(Dependency dependency) { - this(dependency.getGroupId(), dependency.getArtifactId()); - } - - public ArtifactAndGroupId(String groupId, String artifactId) { - Assert.notNull(groupId, "GroupId must not be null"); - Assert.notNull(artifactId, "ArtifactId must not be null"); - this.groupId = groupId; - this.artifactId = artifactId; - } - - public Dependency newDependency(String version) { - return new Dependency(this.groupId, this.artifactId, version); - } - - @Override - public int hashCode() { - return this.groupId.hashCode() * 31 + this.artifactId.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() == obj.getClass()) { - ArtifactAndGroupId other = (ArtifactAndGroupId) obj; - boolean result = true; - result &= this.groupId.equals(other.groupId); - result &= this.artifactId.equals(other.artifactId); - return result; - } - return false; - } - - } - -} diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/Assert.java b/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/Assert.java deleted file mode 100644 index e31db7efa1..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/Assert.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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; - -/** - * Simple subset of the Spring Assert utility. - * - * @author Phillip Webb - */ -class Assert { - - public static void notNull(Object object, String message) { - if (object == null) { - throw new IllegalArgumentException(message); - } - } - -} diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/Dependencies.java b/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/Dependencies.java deleted file mode 100644 index 6b406b387e..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/Dependencies.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.Iterator; - -/** - * Interface for accessing a known set of dependencies. - * - * @author Phillip Webb - * @see Dependency - * @since 1.1.0 - */ -public interface Dependencies extends Iterable { - - /** - * Find a single dependency for the given group and artifact IDs. - * @param groupId the group ID - * @param artifactId the artifact ID - * @return a {@link Dependency} or {@code null} - */ - public Dependency find(String groupId, String artifactId); - - /** - * Find a single dependency for the artifact IDs. - * @param artifactId the artifact ID - * @return a {@link Dependency} or {@code null} - */ - public Dependency find(String artifactId); - - /** - * Provide an {@link Iterator} over all managed {@link Dependency Dependencies}. - */ - @Override - public Iterator iterator(); - -} diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/ManagedDependencies.java b/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/ManagedDependencies.java deleted file mode 100644 index 3602a9521c..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/ManagedDependencies.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.Collection; -import java.util.Collections; -import java.util.Iterator; - -/** - * {@link Dependencies} used by various spring boot tools. Provides programmatic access to - * 'spring-boot-dependencies' and can also support user defined version managed - * dependencies. - * - * @author Phillip Webb - * @see Dependency - */ -public abstract class ManagedDependencies implements Dependencies { - - // NOTE: Take care if changing the API of this class, it is used by the third-party - // Gretty tool (https://github.com/akhikhl/gretty) - - private final Dependencies delegate; - - ManagedDependencies(Dependencies delegate) { - this.delegate = delegate; - } - - /** - * Return the 'spring-boot-dependencies' POM version. - * @return the version - * @deprecated since 1.1.0 in favor of {@link #getSpringBootVersion()} - */ - @Deprecated - public String getVersion() { - return getSpringBootVersion(); - } - - /** - * Return the 'spring-boot-dependencies' POM version. - * @return the spring boot version - */ - public String getSpringBootVersion() { - Dependency dependency = find("org.springframework.boot", "spring-boot"); - return (dependency == null ? null : dependency.getVersion()); - } - - /** - * Find a single dependency for the given group and artifact IDs. - * @param groupId the group ID - * @param artifactId the artifact ID - * @return a {@link Dependency} or {@code null} - */ - @Override - public Dependency find(String groupId, String artifactId) { - return this.delegate.find(groupId, artifactId); - } - - /** - * Find a single dependency for the artifact IDs. - * @param artifactId the artifact ID - * @return a {@link Dependency} or {@code null} - */ - @Override - public Dependency find(String artifactId) { - return this.delegate.find(artifactId); - } - - /** - * Provide an {@link Iterator} over all managed {@link Dependency Dependencies}. - */ - @Override - public Iterator iterator() { - return this.delegate.iterator(); - } - - /** - * Return spring-boot managed dependencies. - * @return The dependencies. - * @see #get(Collection) - */ - public static ManagedDependencies get() { - return get(Collections. emptySet()); - } - - /** - * Return spring-boot managed dependencies with optional version managed dependencies. - * @param versionManagedDependencies a collection of {@link Dependencies} that take - * precedence over the {@literal spring-boot-dependencies}. - * @return the dependencies - * @since 1.1.0 - */ - public static ManagedDependencies get( - Collection versionManagedDependencies) { - return new ManagedDependencies(new ManagedDependenciesDelegate( - versionManagedDependencies)) { - }; - } - -} diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/ManagedDependenciesDelegate.java b/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/ManagedDependenciesDelegate.java deleted file mode 100644 index 212ac2967f..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/ManagedDependenciesDelegate.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.Collection; - -/** - * {@link Dependencies} delegate used internally by {@link ManagedDependencies}. - * - * @author Phillip Webb - * @since 1.1.0 - */ -class ManagedDependenciesDelegate extends AbstractDependencies { - - private static Dependencies springBootDependencies; - - /** - * Create a new {@link ManagedDependenciesDelegate} instance with optional version - * managed dependencies. - * @param versionManagedDependencies a collection of {@link Dependencies} that take - * precedence over the `spring-boot-dependencies`. - */ - public ManagedDependenciesDelegate(Collection versionManagedDependencies) { - this(getSpringBootDependencies(), versionManagedDependencies); - } - - ManagedDependenciesDelegate(Dependencies rootDependencies, - Collection versionManagedDependencies) { - addAll(rootDependencies); - if (versionManagedDependencies != null) { - for (Dependencies managedDependencies : versionManagedDependencies) { - addAll(managedDependencies); - } - } - } - - private void addAll(Dependencies dependencies) { - for (Dependency dependency : dependencies) { - add(new ArtifactAndGroupId(dependency), dependency); - } - } - - private static Dependencies getSpringBootDependencies() { - if (springBootDependencies == null) { - springBootDependencies = new PomDependencies(getResource("effective-pom.xml")); - } - return springBootDependencies; - } - - private static InputStream getResource(String name) { - InputStream inputStream = ManagedDependenciesDelegate.class - .getResourceAsStream(name); - Assert.notNull(inputStream, "Unable to load " + name); - return inputStream; - } - -} diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/PomDependencies.java b/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/PomDependencies.java deleted file mode 100644 index 32bc855601..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/PomDependencies.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.springframework.boot.dependency.tools.Dependency.Exclusion; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * {@link Dependencies} implementation backed a maven POM. - * - * @author Phillip Webb - * @author Andy Wilkinson - * @since 1.1.0 - */ -public class PomDependencies extends AbstractDependencies { - - /** - * Create a new {@link PomDependencies} instance. - * @param effectivePomInputStream the effective POM containing resolved versions. The - * input stream will be closed once content has been loaded. - */ - public PomDependencies(InputStream effectivePomInputStream) { - try { - Document effectivePom = readDocument(effectivePomInputStream); - for (Dependency dependency : readDependencies(effectivePom)) { - add(new ArtifactAndGroupId(dependency), dependency); - } - } - catch (Exception ex) { - throw new IllegalStateException(ex); - } - } - - private Document readDocument(InputStream inputStream) throws Exception { - if (inputStream == null) { - return null; - } - try { - DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = builderFactory.newDocumentBuilder(); - Document document = builder.parse(inputStream); - document.getDocumentElement().normalize(); - return document; - } - finally { - inputStream.close(); - } - } - - private List readDependencies(Document document) throws Exception { - Element element = (Element) document.getElementsByTagName("project").item(0); - element = (Element) element.getElementsByTagName("dependencyManagement").item(0); - element = (Element) element.getElementsByTagName("dependencies").item(0); - NodeList nodes = element.getChildNodes(); - List dependencies = new ArrayList(); - for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - if (node instanceof Element) { - dependencies.add(createDependency((Element) node)); - } - } - return dependencies; - } - - private Dependency createDependency(Element element) throws Exception { - String groupId = getTextContent(element, "groupId"); - String artifactId = getTextContent(element, "artifactId"); - String version = getTextContent(element, "version"); - List exclusions = createExclusions(element - .getElementsByTagName("exclusions")); - return new Dependency(groupId, artifactId, version, exclusions); - } - - private List createExclusions(NodeList exclusion) { - if (exclusion == null || exclusion.getLength() == 0) { - return Collections.emptyList(); - } - return createExclusions(exclusion.item(0)); - } - - private List createExclusions(Node item) { - List exclusions = new ArrayList(); - NodeList children = item.getChildNodes(); - for (int i = 0; i < children.getLength(); i++) { - Node child = children.item(i); - if (child instanceof Element) { - exclusions.add(createExclusion((Element) child)); - } - } - return exclusions; - } - - private Exclusion createExclusion(Element element) { - String groupId = getTextContent(element, "groupId"); - String artifactId = getTextContent(element, "artifactId"); - return new Exclusion(groupId, artifactId); - } - - private String getTextContent(Element element, String tagName) { - return element.getElementsByTagName(tagName).item(0).getTextContent(); - } - -} diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/PropertiesFileDependencies.java b/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/PropertiesFileDependencies.java deleted file mode 100644 index 2142e25dfd..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/PropertiesFileDependencies.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.IOException; -import java.io.InputStream; -import java.util.Map; -import java.util.Properties; -import java.util.TreeMap; - -/** - * {@link Dependencies} backed by an external properties file (of the form created by the - * Spring IO platform). The property key should be the groupId and artifactId (in the form - * {@literal groupId:artifactId}) and the value should be the version. - * - * @author Phillip Webb - * @since 1.1.0 - */ -public class PropertiesFileDependencies extends AbstractDependencies { - - /** - * Create a new {@link PropertiesFileDependencies} instance from the specified input - * stream. - * @param inputStream source input stream (will be closed when properties have been - * loaded) - * @throws IOException - */ - public PropertiesFileDependencies(InputStream inputStream) throws IOException { - try { - Properties properties = new Properties(); - properties.load(inputStream); - initialize(properties); - } - finally { - inputStream.close(); - } - } - - private void initialize(Properties properties) { - Map sortedMap = new TreeMap(); - for (Map.Entry entry : properties.entrySet()) { - sortedMap.put(entry.getKey().toString(), entry.getValue().toString()); - } - for (Map.Entry entry : sortedMap.entrySet()) { - ArtifactAndGroupId artifactAndGroupId = parse(entry.getKey()); - Dependency dependency = artifactAndGroupId.newDependency(entry.getValue()); - add(artifactAndGroupId, dependency); - } - } - - private ArtifactAndGroupId parse(String value) { - String[] parts = value.split("\\:"); - if (parts.length != 2) { - throw new IllegalStateException("Unable to parse " + value); - } - return new ArtifactAndGroupId(parts[0], parts[1]); - } - -} diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/package-info.java b/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/package-info.java deleted file mode 100644 index 9271ab60ae..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/main/java/org/springframework/boot/dependency/tools/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ - -/** - * Utilities for working with the managed dependencies declared in the - * {@literal spring-boot-dependencies} project. - * - * @see org.springframework.boot.dependency.tools.ManagedDependencies - */ -package org.springframework.boot.dependency.tools; - diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/test/java/org/springframework/boot/dependency/tools/ManagedDependenciesDelegateTests.java b/spring-boot-tools/spring-boot-dependency-tools/src/test/java/org/springframework/boot/dependency/tools/ManagedDependenciesDelegateTests.java deleted file mode 100644 index ee1d1d5bed..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/test/java/org/springframework/boot/dependency/tools/ManagedDependenciesDelegateTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 ManagedDependenciesDelegate}. - * - * @author Phillip Webb - */ -public class ManagedDependenciesDelegateTests { - - private ManagedDependenciesDelegate dependencies; - - @Before - public void setup() throws Exception { - PropertiesFileDependencies root = new PropertiesFileDependencies(getClass() - .getResourceAsStream("external.properties")); - PropertiesFileDependencies extra = new PropertiesFileDependencies(getClass() - .getResourceAsStream("additional-external.properties")); - this.dependencies = new ManagedDependenciesDelegate(root, - Collections. 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 iterator() throws Exception { - Iterator 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)); - } - -} diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/test/java/org/springframework/boot/dependency/tools/ManagedDependenciesTests.java b/spring-boot-tools/spring-boot-dependency-tools/src/test/java/org/springframework/boot/dependency/tools/ManagedDependenciesTests.java deleted file mode 100644 index 3a4794901d..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/test/java/org/springframework/boot/dependency/tools/ManagedDependenciesTests.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 org.junit.Before; -import org.junit.Test; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -/** - * Tests for {@link ManagedDependencies}. - * - * @author Phillip Webb - */ -public class ManagedDependenciesTests { - - private ManagedDependencies managedDependencies; - - private Dependencies delegate; - - @Before - public void setup() { - this.delegate = mock(Dependencies.class); - this.managedDependencies = new ManagedDependencies(this.delegate) { - }; - } - - @Test - @Deprecated - public void getVersion() throws Exception { - this.managedDependencies.getVersion(); - verify(this.delegate).find("org.springframework.boot", "spring-boot"); - } - - @Test - public void getSpringBootVersion() throws Exception { - this.managedDependencies.getSpringBootVersion(); - verify(this.delegate).find("org.springframework.boot", "spring-boot"); - } - - @Test - public void findGroupIdArtifactId() throws Exception { - this.managedDependencies.find("groupId", "artifactId"); - verify(this.delegate).find("groupId", "artifactId"); - } - - @Test - public void findArtifactId() throws Exception { - this.managedDependencies.find("artifactId"); - verify(this.delegate).find("artifactId"); - } - - @Test - public void iterator() throws Exception { - this.managedDependencies.iterator(); - verify(this.delegate).iterator(); - } - -} diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/test/java/org/springframework/boot/dependency/tools/PomDependenciesTests.java b/spring-boot-tools/spring-boot-dependency-tools/src/test/java/org/springframework/boot/dependency/tools/PomDependenciesTests.java deleted file mode 100644 index 51e60f9f43..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/test/java/org/springframework/boot/dependency/tools/PomDependenciesTests.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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 PomDependencies}. - * - * @author Phillip Webb - */ -public class PomDependenciesTests { - - private PomDependencies dependencies; - - @Before - public void setup() { - InputStream x = getResource("test-effective-pom.xml"); - this.dependencies = new PomDependencies(x); - } - - private InputStream getResource(String name) { - InputStream inputStream = getClass().getResourceAsStream(name); - assertNotNull("Unable to read " + name, inputStream); - return inputStream; - } - - @Test - public void iterate() throws Exception { - Iterator 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 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]")); - } - -} diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/test/java/org/springframework/boot/dependency/tools/PropertiesFileDependenciesTests.java b/spring-boot-tools/spring-boot-dependency-tools/src/test/java/org/springframework/boot/dependency/tools/PropertiesFileDependenciesTests.java deleted file mode 100644 index ea53aa63ca..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/test/java/org/springframework/boot/dependency/tools/PropertiesFileDependenciesTests.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.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.assertThat; - -/** - * Tests for {@link PropertiesFileDependencies}. - * - * @author Phillip Webb - */ -public class PropertiesFileDependenciesTests { - - private PropertiesFileDependencies dependencies; - - @Before - public void setup() throws Exception { - this.dependencies = new PropertiesFileDependencies(getClass() - .getResourceAsStream("external.properties")); - } - - @Test - public void iterate() throws Exception { - Iterator 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 { - // No Support for exclusion - Dependency dependency = this.dependencies.find("org.sample", "sample01"); - assertThat(dependency.getExclusions().size(), equalTo(0)); - } - -} diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/test/resources/org/springframework/boot/dependency/tools/additional-external.properties b/spring-boot-tools/spring-boot-dependency-tools/src/test/resources/org/springframework/boot/dependency/tools/additional-external.properties deleted file mode 100644 index a16bf51a33..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/test/resources/org/springframework/boot/dependency/tools/additional-external.properties +++ /dev/null @@ -1,2 +0,0 @@ -org.sample\:sample03=2.0.0 -org.sample\:sample02=2.0.0 diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/test/resources/org/springframework/boot/dependency/tools/external.properties b/spring-boot-tools/spring-boot-dependency-tools/src/test/resources/org/springframework/boot/dependency/tools/external.properties deleted file mode 100644 index b31616844c..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/test/resources/org/springframework/boot/dependency/tools/external.properties +++ /dev/null @@ -1,3 +0,0 @@ -org.sample\:sample01=1.0.0 -org.sample\:sample02=1.0.0 -org.springframework.boot\:spring-boot=1.0.0.BUILD-SNAPSHOT diff --git a/spring-boot-tools/spring-boot-dependency-tools/src/test/resources/org/springframework/boot/dependency/tools/test-effective-pom.xml b/spring-boot-tools/spring-boot-dependency-tools/src/test/resources/org/springframework/boot/dependency/tools/test-effective-pom.xml deleted file mode 100644 index 0343fd2054..0000000000 --- a/spring-boot-tools/spring-boot-dependency-tools/src/test/resources/org/springframework/boot/dependency/tools/test-effective-pom.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - 4.0.0 - 1.0.0.BUILD-SNAPSHOT - - 1.0.0 - - - - - org.sample - sample01 - 1.0.0 - - - org.exclude - exclude01 - - - - - org.sample - sample02 - 1.0.0 - - - org.springframework.boot - spring-boot - 1.0.0.BUILD-SNAPSHOT - - - - diff --git a/spring-boot-tools/spring-boot-gradle-plugin/pom.xml b/spring-boot-tools/spring-boot-gradle-plugin/pom.xml index af4d91380f..2c5a505b1a 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/pom.xml +++ b/spring-boot-tools/spring-boot-gradle-plugin/pom.xml @@ -23,10 +23,6 @@ org.springframework.boot spring-boot-loader-tools - - org.springframework.boot - spring-boot-dependency-tools - io.spring.gradle dependency-management-plugin diff --git a/spring-boot-versions/pom.xml b/spring-boot-versions/pom.xml deleted file mode 100644 index 7945831f88..0000000000 --- a/spring-boot-versions/pom.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-dependencies - 1.3.0.BUILD-SNAPSHOT - ../spring-boot-dependencies - - spring-boot-versions - pom - Spring Boot Versions - Spring Boot Versions Property File - http://projects.spring.io/spring-boot/ - - Pivotal Software, Inc. - http://www.spring.io - - - ${basedir}/../.. - - - - - ${project.build.directory}/generated-resources - - - - - maven-help-plugin - - - generate-effective-dependencies-pom - generate-resources - - effective-pom - - - ${project.build.directory}/effective-pom/spring-boot-versions.xml - - - - - - org.codehaus.mojo - xml-maven-plugin - 1.0 - - - - transform - - - - - - - ${project.build.directory}/effective-pom - src/main/xslt/dependency-management-to-versions.xsl - - - .properties - - - ${project.build.directory}/generated-resources - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-artifacts - package - - attach-artifact - - - - - ${project.build.directory}/generated-resources/spring-boot-versions.properties - properties - - - ${project.build.directory}/effective-pom/spring-boot-versions.xml - effective-pom - - - - - - - - - diff --git a/spring-boot-versions/src/dependency-tree/settings.xml b/spring-boot-versions/src/dependency-tree/settings.xml deleted file mode 100644 index e1e0ace341..0000000000 --- a/spring-boot-versions/src/dependency-tree/settings.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - it-repo - - true - - - - local.central - @localRepositoryUrl@ - - true - - - true - - - - - - local.central - @localRepositoryUrl@ - - true - - - true - - - - - - diff --git a/spring-boot-versions/src/main/xslt/dependency-management-to-versions.xsl b/spring-boot-versions/src/main/xslt/dependency-management-to-versions.xsl deleted file mode 100644 index 905c15a57f..0000000000 --- a/spring-boot-versions/src/main/xslt/dependency-management-to-versions.xsl +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - \: - - = - - - - - - \ No newline at end of file