This commit is contained in:
Phillip Webb
2014-05-20 13:13:39 +01:00
parent e40acd81e4
commit 8bcda1bcbe
91 changed files with 477 additions and 438 deletions

View File

@@ -119,6 +119,7 @@ public class Shell {
private void attachSignalHandler() {
SignalUtils.attachSignalHandler(new Runnable() {
@Override
public void run() {
handleSigInt();
}

View File

@@ -34,7 +34,7 @@ import org.codehaus.groovy.transform.ASTTransformation;
/**
* A base class for {@link ASTTransformation AST transformations} that are solely
* interested in {@link AnnotatedNode AnnotatedNodes}.
*
*
* @author Andy Wilkinson
* @since 1.1.0
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* 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.
@@ -28,7 +28,7 @@ import org.codehaus.groovy.transform.ASTTransformation;
* {@link ASTTransformation} to apply
* {@link CompilerAutoConfiguration#applyDependencies(DependencyCustomizer) dependency
* auto-configuration}.
*
*
* @author Phillip Webb
* @author Dave Syer
* @author Andy Wilkinson

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* 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.
@@ -32,7 +32,7 @@ import org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesRes
* <p>
* This class provides a fluent API for conditionally adding dependencies. For example:
* {@code dependencies.ifMissing("com.corp.SomeClass").add(module)}.
*
*
* @author Phillip Webb
* @author Andy Wilkinson
*/

View File

@@ -26,6 +26,8 @@ import org.springframework.boot.cli.compiler.grape.ManagedDependenciesFactory;
import org.springframework.boot.dependency.tools.ManagedDependencies;
/**
* Context used when resolving dependencies.
*
* @author Andy Wilkinson
* @since 1.1.0
*/

View File

@@ -45,7 +45,7 @@ import org.springframework.boot.groovy.GrabMetadata;
/**
* {@link ASTTransformation} for processing {@link GrabMetadata @GrabMetadata}
*
*
* @author Andy Wilkinson
* @since 1.1.0
*/
@@ -78,7 +78,6 @@ public class GrabMetadataTransformation extends AnnotatedNodeASTTransformation {
private void processGrabMetadataAnnotation(AnnotationNode annotationNode) {
Expression valueExpression = annotationNode.getMember("value");
List<Map<String, String>> metadataDependencies = createDependencyMaps(valueExpression);
updateArtifactCoordinatesResolver(metadataDependencies);
}
@@ -86,32 +85,7 @@ public class GrabMetadataTransformation extends AnnotatedNodeASTTransformation {
private List<Map<String, String>> createDependencyMaps(Expression valueExpression) {
Map<String, String> dependency = null;
List<ConstantExpression> constantExpressions = new ArrayList<ConstantExpression>();
if (valueExpression instanceof ListExpression) {
ListExpression listExpression = (ListExpression) valueExpression;
for (Expression expression : listExpression.getExpressions()) {
if (expression instanceof ConstantExpression
&& ((ConstantExpression) expression).getValue() instanceof String) {
constantExpressions.add((ConstantExpression) expression);
}
else {
reportError(
"Each entry in the array must be an inline string constant",
expression);
}
}
}
else if (valueExpression instanceof ConstantExpression
&& ((ConstantExpression) valueExpression).getValue() instanceof String) {
constantExpressions = Arrays.asList((ConstantExpression) valueExpression);
}
else {
reportError(
"@GrabMetadata requires an inline constant that is a string or a string array",
valueExpression);
}
List<ConstantExpression> constantExpressions = getConstantExpressions(valueExpression);
List<Map<String, String>> dependencies = new ArrayList<Map<String, String>>(
constantExpressions.size());
@@ -125,7 +99,6 @@ public class GrabMetadataTransformation extends AnnotatedNodeASTTransformation {
dependency.put("module", components[1]);
dependency.put("version", components[2]);
dependency.put("type", "properties");
dependencies.add(dependency);
}
else {
@@ -137,6 +110,36 @@ public class GrabMetadataTransformation extends AnnotatedNodeASTTransformation {
return dependencies;
}
private List<ConstantExpression> getConstantExpressions(Expression valueExpression) {
if (valueExpression instanceof ListExpression) {
return getConstantExpressions((ListExpression) valueExpression);
}
if (valueExpression instanceof ConstantExpression
&& ((ConstantExpression) valueExpression).getValue() instanceof String) {
return Arrays.asList((ConstantExpression) valueExpression);
}
reportError("@GrabMetadata requires an inline constant that is a "
+ "string or a string array", valueExpression);
return Collections.emptyList();
}
private List<ConstantExpression> getConstantExpressions(ListExpression valueExpression) {
List<ConstantExpression> expressions = new ArrayList<ConstantExpression>();
for (Expression expression : valueExpression.getExpressions()) {
if (expression instanceof ConstantExpression
&& ((ConstantExpression) expression).getValue() instanceof String) {
expressions.add((ConstantExpression) expression);
}
else {
reportError("Each entry in the array must be an "
+ "inline string constant", expression);
}
}
return expressions;
}
private void handleMalformedDependency(Expression expression) {
Message message = createSyntaxErrorMessage(
"The string must be of the form \"group:module:version\"\n", expression);
@@ -154,7 +157,7 @@ public class GrabMetadataTransformation extends AnnotatedNodeASTTransformation {
managedDependencies.add(new PropertiesFileManagedDependencies(uri.toURL()
.openStream()));
}
catch (IOException e) {
catch (IOException ex) {
throw new IllegalStateException("Failed to parse '" + uris[0]
+ "'. Is it a valid properties file?");
}

View File

@@ -56,13 +56,13 @@ import org.springframework.boot.cli.util.ResourceUtils;
* <li>{@link CompilerAutoConfiguration} strategies will be read from
* <code>META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration</code>
* (per the standard java {@link ServiceLoader} contract) and applied during compilation</li>
*
*
* <li>Multiple classes can be returned if the Groovy source defines more than one Class</li>
*
*
* <li>Generated class files can also be loaded using
* {@link ClassLoader#getResource(String)}</li>
* </ul>
*
*
* @author Phillip Webb
* @author Dave Syer
* @author Andy Wilkinson
@@ -167,7 +167,7 @@ public class GroovyCompiler {
* @throws IOException
*/
public Class<?>[] compile(String... sources) throws CompilationFailedException,
IOException {
IOException {
this.loader.clearCache();
List<Class<?>> classes = new ArrayList<Class<?>>();
@@ -287,9 +287,9 @@ public class GroovyCompiler {
classNode);
}
autoConfiguration
.apply(GroovyCompiler.this.loader,
GroovyCompiler.this.configuration, context, source,
classNode);
.apply(GroovyCompiler.this.loader,
GroovyCompiler.this.configuration, context, source,
classNode);
}
}
importCustomizer.call(source, context, classNode);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* 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.
@@ -31,12 +31,12 @@ import org.codehaus.groovy.transform.ASTTransformation;
/**
* {@link ASTTransformation} to resolve {@link Grab} artifact coordinates.
*
*
* @author Andy Wilkinson
* @author Phillip Webb
*/
public class ResolveDependencyCoordinatesTransformation extends
AnnotatedNodeASTTransformation {
AnnotatedNodeASTTransformation {
private static final Set<String> GRAB_ANNOTATION_NAMES = Collections
.unmodifiableSet(new HashSet<String>(Arrays.asList(Grab.class.getName(),

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* 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.
@@ -30,7 +30,7 @@ import org.springframework.boot.cli.compiler.GroovyCompilerConfiguration;
/**
* {@link CompilerAutoConfiguration} for Spring.
*
*
* @author Dave Syer
* @author Phillip Webb
*/
@@ -39,7 +39,7 @@ public class SpringBootCompilerAutoConfiguration extends CompilerAutoConfigurati
@Override
public void applyDependencies(DependencyCustomizer dependencies) {
dependencies.ifAnyMissingClasses("org.springframework.boot.SpringApplication")
.add("spring-boot-starter");
.add("spring-boot-starter");
}
@Override

View File

@@ -24,7 +24,7 @@ import org.springframework.boot.cli.compiler.DependencyCustomizer;
/**
* {@link CompilerAutoConfiguration} for Spring Integration.
*
*
* @author Dave Syer
* @author Artem Bilan
*/

View File

@@ -22,7 +22,7 @@ import org.springframework.boot.dependency.tools.VersionManagedDependencies;
/**
* {@link ArtifactCoordinatesResolver} backed by {@link ManagedDependencies}.
*
*
* @author Phillip Webb
*/
public class ManagedDependenciesArtifactCoordinatesResolver implements

View File

@@ -49,7 +49,7 @@ import org.springframework.boot.cli.compiler.DependencyResolutionContext;
* A {@link GrapeEngine} implementation that uses <a
* href="http://eclipse.org/aether">Aether</a>, the dependency resolution system used by
* Maven.
*
*
* @author Andy Wilkinson
* @author Phillip Webb
*/

View File

@@ -39,7 +39,7 @@ import org.springframework.boot.cli.compiler.DependencyResolutionContext;
/**
* Utility class to create a pre-configured {@link AetherGrapeEngine}.
*
*
* @author Andy Wilkinson
*/
public abstract class AetherGrapeEngineFactory {
@@ -86,7 +86,7 @@ public abstract class AetherGrapeEngineFactory {
for (RepositoryConfiguration repositoryConfiguration : repositoryConfigurations) {
RemoteRepository.Builder builder = new RemoteRepository.Builder(
repositoryConfiguration.getName(), "default", repositoryConfiguration
.getUri().toASCIIString());
.getUri().toASCIIString());
if (!repositoryConfiguration.getSnapshotsEnabled()) {
builder.setSnapshotPolicy(new RepositoryPolicy(false,

View File

@@ -30,7 +30,7 @@ import org.springframework.boot.dependency.tools.VersionManagedDependencies;
/**
* Factory to create Maven {@link Dependency} objects from Boot
* {@link PomManagedDependencies}.
*
*
* @author Phillip Webb
*/
public class ManagedDependenciesFactory {

View File

@@ -24,12 +24,12 @@ 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.
*
*
* @author Andy Wilkinson
* @since 1.1.0
*/
@Target({ ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE,
ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE })
ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE })
@Retention(RetentionPolicy.SOURCE)
public @interface GrabMetadata {
@@ -39,4 +39,5 @@ public @interface GrabMetadata {
* default metadata.
*/
String[] value();
}