diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java index e28bba5bd27..1d6fe7b9fc5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 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. diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java index fc167cf5016..a53a66c545b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.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. @@ -128,9 +128,8 @@ public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration { } private boolean runningOnWebSphere() { - return ClassUtils.isPresent( - "com.ibm.websphere.jtaextensions.ExtendedJTATransaction", getClass() - .getClassLoader()); + return ClassUtils.isPresent("com.ibm.websphere.jtaextensions." + + "ExtendedJTATransaction", getClass().getClassLoader()); } private void configureWebSphereTransactionPlatform( @@ -142,18 +141,6 @@ public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration { return getJtaPlatformManager(WEBSHERE_JTA_PLATFORM_CLASSES); } - private Object getJtaPlatformManager(String[] candidates) { - for (String candidate : candidates) { - try { - return Class.forName(candidate).newInstance(); - } - catch (Exception ex) { - // Continue searching - } - } - throw new IllegalStateException("Could not configure JTA platform"); - } - private void configureSpringJtaPlatform(Map vendorProperties, JtaTransactionManager jtaTransactionManager) { try { @@ -162,18 +149,15 @@ public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration { } catch (NoClassDefFoundError ex) { // Can happen if Hibernate 4.2 is used - if (isUsingJndi()) { - // Assume that Hibernate will use JNDI - if (logger.isDebugEnabled()) { - logger.debug("Unable to set Hibernate JTA platform : " - + ex.getMessage()); - } - } - else { + if (!isUsingJndi()) { throw new IllegalStateException("Unable to set Hibernate JTA " + "platform, are you using the correct " + "version of Hibernate?", ex); } + // Assume that Hibernate will use JNDI + if (logger.isDebugEnabled()) { + logger.debug("Unable to set Hibernate JTA platform : " + ex.getMessage()); + } } } @@ -190,6 +174,18 @@ public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration { return getJtaPlatformManager(NO_JTA_PLATFORM_CLASSES); } + private Object getJtaPlatformManager(String[] candidates) { + for (String candidate : candidates) { + try { + return Class.forName(candidate).newInstance(); + } + catch (Exception ex) { + // Continue searching + } + } + throw new IllegalStateException("Could not configure JTA platform"); + } + @Order(Ordered.HIGHEST_PRECEDENCE + 20) static class HibernateEntityManagerCondition extends SpringBootCondition { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java index 66afd544992..8aa36063cce 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.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. @@ -144,7 +144,8 @@ public class HttpMessageConvertersAutoConfiguration { @Bean @ConditionalOnMissingBean public StringHttpMessageConverter stringHttpMessageConverter() { - StringHttpMessageConverter converter = new StringHttpMessageConverter(this.encodingProperties.getCharset()); + StringHttpMessageConverter converter = new StringHttpMessageConverter( + this.encodingProperties.getCharset()); converter.setWriteAcceptCharset(false); return converter; } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java index 7319f77f3fc..ede747251ea 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.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. diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index e0223c06c08..4e2854f03b9 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -2211,7 +2211,6 @@ functionality. [[howto-use-java-6-embedded-container]] ==== Embedded servlet container compatibility - If you are using one of Boot's embedded Servlet containers you will have to use a Java 6-compatible container. Both Tomcat 7 and Jetty 8 are Java 6 compatible. See <> and <> for details. @@ -2220,7 +2219,6 @@ Java 6-compatible container. Both Tomcat 7 and Jetty 8 are Java 6 compatible. Se [[how-to-use-java-6-jta-api]] ==== JTA API compatibility - While the Java Transaction API itself doesn't require Java 7 the official API jar contains classes that have been built to require Java 7. If you are using JTA then you will need to replace the official JTA 1.2 API jar with one that has been built @@ -2522,4 +2520,4 @@ but the rest of it is normal for a Spring application in Servlet 2.5. Example: In this example we are using a single application context (the one created by the context listener) and attaching it to the `DispatcherServlet` using an init parameter. This is -normal in a Spring Boot application (you normally only have one application context). \ No newline at end of file +normal in a Spring Boot application (you normally only have one application context). diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/BuildHandler.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/BuildHandler.java deleted file mode 100644 index cae8bdfbdec..00000000000 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/BuildHandler.java +++ /dev/null @@ -1,42 +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.configurationprocessor; - -import javax.annotation.processing.RoundEnvironment; - -import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; - -/** - * A {@code BuildTracker} tracks a build in which configuration processing has been - * performed and is responsible for managing the associated state including the resulting - * metadata. - * - * @author Andy Wilkinson - */ -public interface BuildHandler { - - void addGroup(String name, String type, String sourceType, String sourceMethod); - - void addProperty(String prefix, String name, String type, String sourceType, - String sourceMethod, String description, Object defaultValue, - boolean deprecated); - - void processing(RoundEnvironment environment); - - ConfigurationMetadata produceMetadata(); - -} diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java index 32830eae998..dfc7c2947c4 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java @@ -47,6 +47,7 @@ import javax.tools.Diagnostic.Kind; import org.springframework.boot.configurationprocessor.fieldvalues.FieldValuesParser; import org.springframework.boot.configurationprocessor.fieldvalues.javac.JavaCompilerFieldValuesParser; import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; +import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; /** * Annotation {@link Processor} that writes meta-data file for @@ -74,7 +75,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor private MetadataStore metadataStore; - private BuildHandler buildHandler; + private MetadataCollector metadataCollector; private TypeUtils typeUtils; @@ -100,7 +101,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor super.init(env); this.typeUtils = new TypeUtils(env); this.metadataStore = new MetadataStore(env); - this.buildHandler = createBuildHandler(env, this.metadataStore); + this.metadataCollector = new MetadataCollector(env, this.metadataStore.readMetadata()); try { this.fieldValuesParser = new JavaCompilerFieldValuesParser(env); } @@ -111,21 +112,10 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor } } - private BuildHandler createBuildHandler(ProcessingEnvironment env, - MetadataStore metadataStore) { - ConfigurationMetadata existingMetadata = metadataStore.readMetadata(); - if (existingMetadata != null) { - return new IncrementalBuildHandler(env, existingMetadata); - } - else { - return new StandardBuildHandler(); - } - } - @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { - this.buildHandler.processing(roundEnv); + this.metadataCollector.processing(roundEnv); Elements elementUtils = this.processingEnv.getElementUtils(); for (Element element : roundEnv.getElementsAnnotatedWith(elementUtils .getTypeElement(configurationPropertiesAnnotation()))) { @@ -153,7 +143,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor private void processAnnotatedTypeElement(String prefix, TypeElement element) { String type = this.typeUtils.getType(element); - this.buildHandler.addGroup(prefix, type, type, null); + this.metadataCollector.add(ItemMetadata.newGroup(prefix, type, type, null)); processTypeElement(prefix, element); } @@ -163,9 +153,10 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor Element returns = this.processingEnv.getTypeUtils().asElement( element.getReturnType()); if (returns instanceof TypeElement) { - this.buildHandler.addGroup(prefix, this.typeUtils.getType(returns), + this.metadataCollector.add(ItemMetadata.newGroup(prefix, + this.typeUtils.getType(returns), this.typeUtils.getType(element.getEnclosingElement()), - element.toString()); + element.toString())); processTypeElement(prefix, (TypeElement) returns); } } @@ -210,8 +201,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor boolean deprecated = hasDeprecateAnnotation(getter) || hasDeprecateAnnotation(setter) || hasDeprecateAnnotation(element); - this.buildHandler.addProperty(prefix, name, dataType, sourceType, null, - description, defaultValue, deprecated); + this.metadataCollector.add(ItemMetadata + .newProperty(prefix, name, dataType, sourceType, null, + description, defaultValue, deprecated)); } } } @@ -238,8 +230,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor Object defaultValue = fieldValues.get(name); boolean deprecated = hasDeprecateAnnotation(field) || hasDeprecateAnnotation(element); - this.buildHandler.addProperty(prefix, name, dataType, sourceType, null, - description, defaultValue, deprecated); + this.metadataCollector.add(ItemMetadata + .newProperty(prefix, name, dataType, sourceType, null, + description, defaultValue, deprecated)); } } } @@ -272,9 +265,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor if (returnType != null && returnType instanceof TypeElement && annotation == null && isNested) { String nestedPrefix = ConfigurationMetadata.nestedPrefix(prefix, name); - this.buildHandler.addGroup(nestedPrefix, + this.metadataCollector.add(ItemMetadata.newGroup(nestedPrefix, this.typeUtils.getType(returnType), - this.typeUtils.getType(element), getter.toString()); + this.typeUtils.getType(element), getter.toString())); processTypeElement(nestedPrefix, (TypeElement) returnType); } } @@ -332,7 +325,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor } protected ConfigurationMetadata writeMetaData() { - ConfigurationMetadata metadata = this.buildHandler.produceMetadata(); + ConfigurationMetadata metadata = this.metadataCollector.getMetadata(); metadata = mergeAdditionalMetadata(metadata); if (!metadata.getItems().isEmpty()) { try { diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/IncrementalBuildHandler.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataCollector.java similarity index 61% rename from spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/IncrementalBuildHandler.java rename to spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataCollector.java index e480a667bcc..6623e604059 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/IncrementalBuildHandler.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataCollector.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. @@ -16,6 +16,7 @@ package org.springframework.boot.configurationprocessor; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -29,73 +30,72 @@ import org.springframework.boot.configurationprocessor.metadata.ConfigurationMet import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; /** - * {@code BuildHandler} that provides incremental build support by merging the metadata - * from the current incremental build with any existing metadata. + * Used by {@link ConfigurationMetadataAnnotationProcessor} to collect + * {@link ConfigurationMetadata}. * * @author Andy Wilkinson * @author Kris De Volder * @since 1.2.2 */ -public class IncrementalBuildHandler extends StandardBuildHandler { +public class MetadataCollector { - private final Set processedSourceTypes = new HashSet(); + private final List metadataItems = new ArrayList(); private final ProcessingEnvironment processingEnvironment; - private final ConfigurationMetadata existingMetadata; + private final ConfigurationMetadata previousMetadata; private final TypeUtils typeUtils; + private final Set processedSourceTypes = new HashSet(); + /** - * Creates a new {@code IncrementalBuildTracker} that will merge the metadata produced - * by an incremental build with the given {@code existingMetadata}. - * + * Creates a new {@code MetadataProcessor} instance. * @param processingEnvironment The processing environment of the build - * @param existingMetadata The existing metadata + * @param previousMetadata Any previous metadata or {@code null} */ - public IncrementalBuildHandler(ProcessingEnvironment processingEnvironment, - ConfigurationMetadata existingMetadata) { - this.existingMetadata = existingMetadata; + public MetadataCollector(ProcessingEnvironment processingEnvironment, + ConfigurationMetadata previousMetadata) { this.processingEnvironment = processingEnvironment; + this.previousMetadata = previousMetadata; this.typeUtils = new TypeUtils(processingEnvironment); } - @Override - public void processing(RoundEnvironment environment) { - for (Element element : environment.getRootElements()) { + public void processing(RoundEnvironment roundEnv) { + for (Element element : roundEnv.getRootElements()) { markAsProcessed(element); } } - @Override - public ConfigurationMetadata produceMetadata() { - ConfigurationMetadata metadata = super.produceMetadata(); - mergeExistingMetadata(metadata); - return metadata; - } - private void markAsProcessed(Element element) { if (element instanceof TypeElement) { this.processedSourceTypes.add(this.typeUtils.getType(element)); } } - private void mergeExistingMetadata(ConfigurationMetadata metadata) { - List items = this.existingMetadata.getItems(); - for (ItemMetadata oldItem : items) { - if (shouldBeMerged(oldItem)) { - metadata.add(oldItem); + public void add(ItemMetadata metadata) { + this.metadataItems.add(metadata); + } + + public ConfigurationMetadata getMetadata() { + ConfigurationMetadata metadata = new ConfigurationMetadata(); + for (ItemMetadata item : this.metadataItems) { + metadata.add(item); + } + if (this.previousMetadata != null) { + List items = this.previousMetadata.getItems(); + for (ItemMetadata item : items) { + if (shouldBeMerged(item)) { + metadata.add(item); + } } } + return metadata; } private boolean shouldBeMerged(ItemMetadata itemMetadata) { String sourceType = itemMetadata.getSourceType(); - if (sourceType == null || deletedInCurrentBuild(sourceType) - || processedInCurrentBuild(sourceType)) { - return false; - } - return true; + return (sourceType != null && !deletedInCurrentBuild(sourceType) && !processedInCurrentBuild(sourceType)); } private boolean deletedInCurrentBuild(String sourceType) { diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/StandardBuildHandler.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/StandardBuildHandler.java deleted file mode 100644 index 7e60315b76c..00000000000 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/StandardBuildHandler.java +++ /dev/null @@ -1,58 +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.configurationprocessor; - -import javax.annotation.processing.RoundEnvironment; - -import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; -import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; - -/** - * Standard implementation of {@code BuildHandler} that handles the state of a single - * build. - * - * @author Andy Wilkinson - * @since 1.2.2 - */ -public class StandardBuildHandler implements BuildHandler { - - private final ConfigurationMetadata metadata = new ConfigurationMetadata(); - - @Override - public void addGroup(String name, String type, String sourceType, String sourceMethod) { - this.metadata.add(ItemMetadata.newGroup(name, type, sourceType, sourceMethod)); - } - - @Override - public void addProperty(String prefix, String name, String type, String sourceType, - String sourceMethod, String description, Object defaultValue, - boolean deprecated) { - this.metadata.add(ItemMetadata.newProperty(prefix, name, type, sourceType, - sourceMethod, description, defaultValue, deprecated)); - } - - @Override - public void processing(RoundEnvironment environment) { - - } - - @Override - public ConfigurationMetadata produceMetadata() { - return this.metadata; - } - -} diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index 1d7cb617861..b617ba73439 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.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. diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletContextInitializerBeans.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletContextInitializerBeans.java index ca50491a003..a9e1ffe7859 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletContextInitializerBeans.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletContextInitializerBeans.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. diff --git a/spring-boot/src/test/java/org/springframework/boot/context/web/SpringBootServletInitializerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/web/SpringBootServletInitializerTests.java index 34a0f525ac4..595b2aac5e5 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/web/SpringBootServletInitializerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/web/SpringBootServletInitializerTests.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.