Support transitive=false in AetherGrapeEngine

@Grab allows a dependency to be declared, but for its transitive
dependencies to be excluded by setting transitive to false. This
commit enhances AetherGrapeEngine to honour this setting by using a
wildcard exclusion on any dependency so declared.
This commit is contained in:
Andy Wilkinson
2013-10-24 13:57:38 +01:00
parent 97cb7f0967
commit 1d5cb7731d
4 changed files with 141 additions and 18 deletions

View File

@@ -100,11 +100,17 @@
<resource>
<directory>src/main/groovy</directory>
</resource>
<resource>
<directory>${project.build.directory}/generated-resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.directory}/generated-resources</additionalClasspathElement>
</additionalClasspathElements>
<classpathDependencyExcludes>
<classpathDependencyExcludes>org.springframework:spring-core</classpathDependencyExcludes>
<classpathDependencyExcludes>org.springframework:spring-beans</classpathDependencyExcludes>
@@ -190,7 +196,7 @@
<property name="dependencies" value="${project.parent}" />
<vppcopy
file="${basedir}/src/main/resources/META-INF/springcli.properties.vpp"
tofile="${project.build.directory}/classes/META-INF/springcli.properties"
tofile="${project.build.directory}/generated-resources/META-INF/springcli.properties"
overwrite="true" />
</target>
</configuration>

View File

@@ -353,30 +353,37 @@ public class GroovyCompiler {
}
private void transformGrabAnnotation(AnnotationNode grabAnnotation) {
grabAnnotation.setMember("initClass", new ConstantExpression(false));
Expression valueExpression = grabAnnotation.getMember("value");
String value = null;
if (valueExpression instanceof ConstantExpression) {
ConstantExpression constantExpression = (ConstantExpression) valueExpression;
Object valueObject = constantExpression.getValue();
if (valueObject instanceof String) {
String value = (String) valueObject;
if (!isConvenienceForm(value)) {
applyGroupAndVersion(grabAnnotation, constantExpression);
value = (String) valueObject;
if (isConvenienceForm(value)) {
return;
}
grabAnnotation.setMember("initClass", new ConstantExpression(false));
}
}
applyGroupAndVersion(grabAnnotation, value);
}
private boolean isConvenienceForm(String value) {
return value.contains(":") || value.contains("#");
}
private void applyGroupAndVersion(AnnotationNode grabAnnotation,
ConstantExpression moduleExpression) {
private void applyGroupAndVersion(AnnotationNode grabAnnotation, String module) {
grabAnnotation.setMember("module", moduleExpression);
String module = (String) moduleExpression.getValue();
if (module != null) {
grabAnnotation.setMember("module", new ConstantExpression(module));
}
else {
module = (String) ((ConstantExpression) grabAnnotation.getMembers().get(
"module")).getValue();
}
if (grabAnnotation.getMember("group") == null) {
ConstantExpression groupIdExpression = new ConstantExpression(
@@ -391,10 +398,6 @@ public class GroovyCompiler {
.getVersion(module));
grabAnnotation.setMember("version", versionExpression);
}
grabAnnotation.setMember("initClass", new ConstantExpression(false));
}
}
}