Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
212c30f6
Commit
212c30f6
authored
May 30, 2014
by
Andy Wilkinson
Committed by
Phillip Webb
May 30, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance DependencyCustomer: allow type and classifier to be specified
Closes #1002
parent
059d504f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
23 deletions
+78
-23
DependencyCustomizer.java
...ringframework/boot/cli/compiler/DependencyCustomizer.java
+30
-6
ArtifactCoordinatesResolver.java
...li/compiler/dependencies/ArtifactCoordinatesResolver.java
+8
-4
DependencyCustomizerTests.java
...ramework/boot/cli/compiler/DependencyCustomizerTests.java
+40
-13
No files found.
spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyCustomizer.java
View file @
212c30f6
...
@@ -32,7 +32,7 @@ import org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesRes
...
@@ -32,7 +32,7 @@ import org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesRes
* <p>
* <p>
* This class provides a fluent API for conditionally adding dependencies. For example:
* This class provides a fluent API for conditionally adding dependencies. For example:
* {@code dependencies.ifMissing("com.corp.SomeClass").add(module)}.
* {@code dependencies.ifMissing("com.corp.SomeClass").add(module)}.
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Andy Wilkinson
* @author Andy Wilkinson
*/
*/
...
@@ -180,20 +180,21 @@ public class DependencyCustomizer {
...
@@ -180,20 +180,21 @@ public class DependencyCustomizer {
/**
/**
* Add dependencies and all of their dependencies. The group ID and version of the
* Add dependencies and all of their dependencies. The group ID and version of the
* dependency are resolves using the customizer's {@link ArtifactCoordinatesResolver}.
* dependencies are resolved from the modules using the customizer's
* {@link ArtifactCoordinatesResolver}.
* @param modules The module IDs
* @param modules The module IDs
* @return this {@link DependencyCustomizer} for continued use
* @return this {@link DependencyCustomizer} for continued use
*/
*/
public
DependencyCustomizer
add
(
String
...
modules
)
{
public
DependencyCustomizer
add
(
String
...
modules
)
{
for
(
String
module
:
modules
)
{
for
(
String
module
:
modules
)
{
add
(
module
,
true
);
add
(
module
,
null
,
null
,
true
);
}
}
return
this
;
return
this
;
}
}
/**
/**
* Add a single dependency and, optionally, all of its dependencies. The group ID and
* Add a single dependency and, optionally, all of its dependencies. The group ID and
* version of the dependency are resolve
s
using the customizer's
* version of the dependency are resolve
d from the module
using the customizer's
* {@link ArtifactCoordinatesResolver}.
* {@link ArtifactCoordinatesResolver}.
* @param module The module ID
* @param module The module ID
* @param transitive {@code true} if the transitive dependencies should also be added,
* @param transitive {@code true} if the transitive dependencies should also be added,
...
@@ -201,23 +202,46 @@ public class DependencyCustomizer {
...
@@ -201,23 +202,46 @@ public class DependencyCustomizer {
* @return this {@link DependencyCustomizer} for continued use
* @return this {@link DependencyCustomizer} for continued use
*/
*/
public
DependencyCustomizer
add
(
String
module
,
boolean
transitive
)
{
public
DependencyCustomizer
add
(
String
module
,
boolean
transitive
)
{
return
add
(
module
,
null
,
null
,
transitive
);
}
/**
* Add a single dependency with the specified classifier and type and, optionally, all
* of its dependencies. The group ID and version of the dependency are resolved from
* the module by using the customizer's {@link ArtifactCoordinatesResolver}.
* @param module The module ID
* @param classifier The classifier, may be {@code null}
* @param type The type, may be {@code null}
* @param transitive {@code true} if the transitive dependencies should also be added,
* otherwise {@code false}.
* @return this {@link DependencyCustomizer} for continued use
*/
public
DependencyCustomizer
add
(
String
module
,
String
classifier
,
String
type
,
boolean
transitive
)
{
if
(
canAdd
())
{
if
(
canAdd
())
{
ArtifactCoordinatesResolver
artifactCoordinatesResolver
=
this
.
dependencyResolutionContext
ArtifactCoordinatesResolver
artifactCoordinatesResolver
=
this
.
dependencyResolutionContext
.
getArtifactCoordinatesResolver
();
.
getArtifactCoordinatesResolver
();
this
.
classNode
.
addAnnotation
(
createGrabAnnotation
(
this
.
classNode
.
addAnnotation
(
createGrabAnnotation
(
artifactCoordinatesResolver
.
getGroupId
(
module
),
artifactCoordinatesResolver
.
getGroupId
(
module
),
artifactCoordinatesResolver
.
getArtifactId
(
module
),
artifactCoordinatesResolver
.
getArtifactId
(
module
),
artifactCoordinatesResolver
.
getVersion
(
module
),
transitive
));
artifactCoordinatesResolver
.
getVersion
(
module
),
classifier
,
type
,
transitive
));
}
}
return
this
;
return
this
;
}
}
private
AnnotationNode
createGrabAnnotation
(
String
group
,
String
module
,
private
AnnotationNode
createGrabAnnotation
(
String
group
,
String
module
,
String
version
,
boolean
transitive
)
{
String
version
,
String
classifier
,
String
type
,
boolean
transitive
)
{
AnnotationNode
annotationNode
=
new
AnnotationNode
(
new
ClassNode
(
Grab
.
class
));
AnnotationNode
annotationNode
=
new
AnnotationNode
(
new
ClassNode
(
Grab
.
class
));
annotationNode
.
addMember
(
"group"
,
new
ConstantExpression
(
group
));
annotationNode
.
addMember
(
"group"
,
new
ConstantExpression
(
group
));
annotationNode
.
addMember
(
"module"
,
new
ConstantExpression
(
module
));
annotationNode
.
addMember
(
"module"
,
new
ConstantExpression
(
module
));
annotationNode
.
addMember
(
"version"
,
new
ConstantExpression
(
version
));
annotationNode
.
addMember
(
"version"
,
new
ConstantExpression
(
version
));
if
(
classifier
!=
null
)
{
annotationNode
.
addMember
(
"classifier"
,
new
ConstantExpression
(
classifier
));
}
if
(
type
!=
null
)
{
annotationNode
.
addMember
(
"type"
,
new
ConstantExpression
(
type
));
}
annotationNode
.
addMember
(
"transitive"
,
new
ConstantExpression
(
transitive
));
annotationNode
.
addMember
(
"transitive"
,
new
ConstantExpression
(
transitive
));
annotationNode
.
addMember
(
"initClass"
,
new
ConstantExpression
(
false
));
annotationNode
.
addMember
(
"initClass"
,
new
ConstantExpression
(
false
));
return
annotationNode
;
return
annotationNode
;
...
...
spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/dependencies/ArtifactCoordinatesResolver.java
View file @
212c30f6
...
@@ -17,9 +17,13 @@
...
@@ -17,9 +17,13 @@
package
org
.
springframework
.
boot
.
cli
.
compiler
.
dependencies
;
package
org
.
springframework
.
boot
.
cli
.
compiler
.
dependencies
;
/**
/**
* A resolver for artifacts' Maven coordinates, allowing a group id or version to be
* A resolver for artifacts' Maven coordinates, allowing group id, artifact id, or version
* obtained from an artifact ID.
* to be obtained from a module identifier. A module identifier may be in the form
*
* {@code groupId:artifactId:version}, in which case coordinate resolution simply extracts
* the relevant piece from the identifier. Alternatively the identifier may be in the form
* {@code artifactId}, in which case coordinate resolution uses implementation-specific
* metadata to resolve the groupId and version.
*
* @author Andy Wilkinson
* @author Andy Wilkinson
*/
*/
public
interface
ArtifactCoordinatesResolver
{
public
interface
ArtifactCoordinatesResolver
{
...
@@ -36,7 +40,7 @@ public interface ArtifactCoordinatesResolver {
...
@@ -36,7 +40,7 @@ public interface ArtifactCoordinatesResolver {
* Gets the artifact id of the artifact identified by the given {@code module}.
* Gets the artifact id of the artifact identified by the given {@code module}.
* Returns {@code null} if the artifact is unknown to the resolver.
* Returns {@code null} if the artifact is unknown to the resolver.
* @param module The id of the module
* @param module The id of the module
* @return The
group
id of the module
* @return The
artifact
id of the module
*/
*/
String
getArtifactId
(
String
module
);
String
getArtifactId
(
String
module
);
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java
View file @
212c30f6
...
@@ -33,6 +33,7 @@ import org.mockito.MockitoAnnotations;
...
@@ -33,6 +33,7 @@ import org.mockito.MockitoAnnotations;
import
org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesResolver
;
import
org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesResolver
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
/**
...
@@ -75,7 +76,30 @@ public class DependencyCustomizerTests {
...
@@ -75,7 +76,30 @@ public class DependencyCustomizerTests {
assertEquals
(
1
,
grabAnnotations
.
size
());
assertEquals
(
1
,
grabAnnotations
.
size
());
AnnotationNode
annotationNode
=
grabAnnotations
.
get
(
0
);
AnnotationNode
annotationNode
=
grabAnnotations
.
get
(
0
);
assertGrabAnnotation
(
annotationNode
,
"org.springframework.boot"
,
assertGrabAnnotation
(
annotationNode
,
"org.springframework.boot"
,
"spring-boot-starter-logging"
,
true
);
"spring-boot-starter-logging"
,
"1.2.3"
,
null
,
null
,
true
);
}
@Test
public
void
nonTransitiveAdd
()
{
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
,
false
);
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
assertEquals
(
1
,
grabAnnotations
.
size
());
AnnotationNode
annotationNode
=
grabAnnotations
.
get
(
0
);
assertGrabAnnotation
(
annotationNode
,
"org.springframework.boot"
,
"spring-boot-starter-logging"
,
"1.2.3"
,
null
,
null
,
false
);
}
@Test
public
void
fullyCustomized
()
{
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
,
"my-classifier"
,
"my-type"
,
false
);
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
assertEquals
(
1
,
grabAnnotations
.
size
());
AnnotationNode
annotationNode
=
grabAnnotations
.
get
(
0
);
assertGrabAnnotation
(
annotationNode
,
"org.springframework.boot"
,
"spring-boot-starter-logging"
,
"1.2.3"
,
"my-classifier"
,
"my-type"
,
false
);
}
}
@Test
@Test
...
@@ -120,21 +144,24 @@ public class DependencyCustomizerTests {
...
@@ -120,21 +144,24 @@ public class DependencyCustomizerTests {
assertEquals
(
1
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
());
assertEquals
(
1
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
());
}
}
@Test
public
void
nonTransitiveAdd
()
{
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
,
false
);
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
assertEquals
(
1
,
grabAnnotations
.
size
());
AnnotationNode
annotationNode
=
grabAnnotations
.
get
(
0
);
assertGrabAnnotation
(
annotationNode
,
"org.springframework.boot"
,
"spring-boot-starter-logging"
,
false
);
}
private
void
assertGrabAnnotation
(
AnnotationNode
annotationNode
,
String
group
,
private
void
assertGrabAnnotation
(
AnnotationNode
annotationNode
,
String
group
,
String
module
,
boolean
transitive
)
{
String
module
,
String
version
,
String
classifier
,
String
type
,
boolean
transitive
)
{
assertEquals
(
group
,
getMemberValue
(
annotationNode
,
"group"
));
assertEquals
(
group
,
getMemberValue
(
annotationNode
,
"group"
));
assertEquals
(
module
,
getMemberValue
(
annotationNode
,
"module"
));
assertEquals
(
module
,
getMemberValue
(
annotationNode
,
"module"
));
assertEquals
(
version
,
getMemberValue
(
annotationNode
,
"version"
));
if
(
type
==
null
)
{
assertNull
(
annotationNode
.
getMember
(
"type"
));
}
else
{
assertEquals
(
type
,
getMemberValue
(
annotationNode
,
"type"
));
}
if
(
classifier
==
null
)
{
assertNull
(
annotationNode
.
getMember
(
"classifier"
));
}
else
{
assertEquals
(
classifier
,
getMemberValue
(
annotationNode
,
"classifier"
));
}
assertEquals
(
transitive
,
getMemberValue
(
annotationNode
,
"transitive"
));
assertEquals
(
transitive
,
getMemberValue
(
annotationNode
,
"transitive"
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment