From d316dbf6c8eb66b8e525bc0486b7334712ac11b5 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 4 Apr 2018 16:41:19 -0400 Subject: [PATCH] Upgrade to SF-5.1, remove deprecations etc. * Upgrade to SF-5.1, Log4J-2.11, Mockito-2.17, Jackson 2.9.5, SonarQube-2.6.1, Checkstyle-8.8 * Remove `spring-io-plugin` since it's not going to exist after Cairo release * Move `log4j-slf4j-impl` to the modules where no `logback-classic` dependency - the `logback` performs expected work for us via `spring-rabbit` infrastructure * `log4j2-test.xml` in the `spring-rabbit-junit` to the `test` scope * Remove some old `@Deprecated` API --- build.gradle | 37 +++------ .../CorrelationAwareMessagePostProcessor.java | 29 ------- .../amqp/core/MessageBuilderSupport.java | 32 ++------ .../amqp/core/MessageProperties.java | 20 ----- .../support/AmqpMessageHeaderAccessor.java | 13 +--- .../support/converter/DefaultClassMapper.java | 23 ++---- .../{main => test}/resources/log4j2-test.xml | 0 .../connection/RabbitResourceHolder.java | 23 ++---- .../amqp/rabbit/connection/RabbitUtils.java | 33 -------- .../amqp/rabbit/support/LogAppenderUtils.java | 75 ------------------- 10 files changed, 29 insertions(+), 256 deletions(-) delete mode 100644 spring-amqp/src/main/java/org/springframework/amqp/core/CorrelationAwareMessagePostProcessor.java rename spring-rabbit-junit/src/{main => test}/resources/log4j2-test.xml (100%) delete mode 100644 spring-rabbit/src/main/java/org/springframework/amqp/rabbit/support/LogAppenderUtils.java diff --git a/build.gradle b/build.gradle index e0ede24b..1e752fba 100644 --- a/build.gradle +++ b/build.gradle @@ -6,13 +6,11 @@ buildscript { classpath 'io.spring.gradle:docbook-reference-plugin:0.3.1' classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.0' classpath 'me.champeau.gradle:gradle-javadoc-hotfix-plugin:0.1' - classpath 'io.spring.gradle:dependency-management-plugin:1.0.2.RELEASE' - classpath 'io.spring.gradle:spring-io-plugin:0.0.8.RELEASE' } } plugins { - id "org.sonarqube" version '2.5' + id "org.sonarqube" version '2.6.1' } description = 'Spring AMQP' @@ -65,39 +63,23 @@ subprojects { subproject -> apply plugin: 'jacoco' apply plugin: 'checkstyle' - if (project.hasProperty('platformVersion')) { - apply plugin: 'spring-io' - - repositories { - maven { url 'https://repo.spring.io/libs-snapshot' } - } - - dependencyManagement { - springIoTestRuntime { - imports { - mavenBom "io.spring.platform:platform-bom:$platformVersion" - } - } - } - } - sourceCompatibility=1.8 targetCompatibility=1.8 ext { hamcrestVersion = '1.3' - jackson2Version = '2.9.1' + jackson2Version = '2.9.5' junit4Version = '4.12' junitJupiterVersion = '5.1.0' junitPlatformVersion = '1.1.0' junitVintageVersion = '5.1.0' - log4jVersion = '2.8.2' + log4jVersion = '2.11.0' logbackVersion = '1.2.3' - mockitoVersion = '2.11.0' + mockitoVersion = '2.17.0' rabbitmqVersion = project.hasProperty('rabbitmqVersion') ? project.rabbitmqVersion : '5.2.0' rabbitmqHttpClientVersion = '2.0.1.RELEASE' - springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.0.4.RELEASE' + springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.1.0.BUILD-SNAPSHOT' springRetryVersion = '1.2.2.RELEASE' } @@ -124,7 +106,6 @@ subprojects { subproject -> } testCompile "org.springframework:spring-test:$springVersion" - testRuntime "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion" testRuntime "org.apache.logging.log4j:log4j-jcl:$log4jVersion" testCompile "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion" @@ -187,7 +168,7 @@ subprojects { subproject -> logging.captureStandardOutput(LogLevel.INFO) dependsOn checkTestConfigs - if (name ==~ /(springIo.*)|(testAll)/) { + if (name ==~ /(testAll)/) { systemProperty 'RUN_LONG_INTEGRATION_TESTS', 'true' } useJUnitPlatform() @@ -205,7 +186,7 @@ subprojects { subproject -> checkstyle { configFile = file("${rootDir}/src/checkstyle/checkstyle.xml") - toolVersion = "8.1" + toolVersion = "8.8" } artifacts { @@ -242,6 +223,8 @@ project('spring-amqp') { compile ("org.springframework:spring-context:$springVersion", optional) compile ("com.fasterxml.jackson.core:jackson-core:$jackson2Version", optional) compile ("com.fasterxml.jackson.core:jackson-databind:$jackson2Version", optional) + + testRuntime "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion" } } @@ -289,6 +272,7 @@ project('spring-rabbit-junit') { compile ("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion", optional) compileOnly 'org.apiguardian:apiguardian-api:1.0.0' + testRuntime "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion" } } @@ -308,7 +292,6 @@ project('spring-rabbit-test') { } testCompile project(":spring-rabbit").sourceSets.test.output testCompile project(":spring-rabbit-junit") - } } diff --git a/spring-amqp/src/main/java/org/springframework/amqp/core/CorrelationAwareMessagePostProcessor.java b/spring-amqp/src/main/java/org/springframework/amqp/core/CorrelationAwareMessagePostProcessor.java deleted file mode 100644 index 3e1d16b8..00000000 --- a/spring-amqp/src/main/java/org/springframework/amqp/core/CorrelationAwareMessagePostProcessor.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2017 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.amqp.core; - -/** - * A message post processor that can also use/manipulate correlation data. - * - * @author Gary Russell - * @since 1.6.7 - * @deprecated in 2.0, the method has been moved to {@link MessagePostProcessor}. - */ -@Deprecated -public interface CorrelationAwareMessagePostProcessor extends MessagePostProcessor { - -} diff --git a/spring-amqp/src/main/java/org/springframework/amqp/core/MessageBuilderSupport.java b/spring-amqp/src/main/java/org/springframework/amqp/core/MessageBuilderSupport.java index 13d73b50..07b457e7 100644 --- a/spring-amqp/src/main/java/org/springframework/amqp/core/MessageBuilderSupport.java +++ b/spring-amqp/src/main/java/org/springframework/amqp/core/MessageBuilderSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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,8 +25,11 @@ import org.springframework.beans.BeanUtils; /** * Support class for building {@link Message} and {@link MessageProperties} * fluent API. + * * @param The message builder type. + * * @author Gary Russell + * * @since 1.3 * */ @@ -85,18 +88,6 @@ public abstract class MessageBuilderSupport { return this; } - /** - * Set the correlation id. - * @param correlationId the id. - * @return the builder. - * @deprecated - use {@link #setCorrelationId(String)} - */ - @Deprecated - public MessageBuilderSupport setCorrelationIdString(String correlationId) { - this.properties.setCorrelationId(correlationId); - return this; - } - public MessageBuilderSupport setReplyTo(String replyTo) { this.properties.setReplyTo(replyTo); return this; @@ -222,20 +213,6 @@ public abstract class MessageBuilderSupport { return this; } - /** - * Set the correlation id if not already present. - * @param correlationId the id. - * @return the builder. - * @deprecated - use {@link #setCorrelationIdIfAbsent(String)} - */ - @Deprecated - public MessageBuilderSupport setCorrelationIdStringIfAbsent(String correlationId) { - if (this.properties.getCorrelationId() == null) { - this.properties.setCorrelationId(correlationId); - } - return this; - } - public MessageBuilderSupport setReplyToIfAbsent(String replyTo) { if (this.properties.getReplyTo() == null) { this.properties.setReplyTo(replyTo); @@ -368,4 +345,5 @@ public abstract class MessageBuilderSupport { } public abstract T build(); + } diff --git a/spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java b/spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java index 01b68712..63bb397b 100644 --- a/spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java +++ b/spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java @@ -225,26 +225,6 @@ public class MessageProperties implements Serializable { return this.correlationId; } - /** - * Get the correlation id. - * @return the correlation id - * @deprecated use {@link #getCorrelationId()}. - */ - @Deprecated - public String getCorrelationIdString() { - return this.correlationId; - } - - /** - * Set the correlation id. - * @param correlationId the id. - * @deprecated - use {@link #setCorrelationId(String)}. - */ - @Deprecated - public void setCorrelationIdString(String correlationId) { - this.correlationId = correlationId; - } - public void setReplyTo(String replyTo) { this.replyTo = replyTo; } diff --git a/spring-amqp/src/main/java/org/springframework/amqp/support/AmqpMessageHeaderAccessor.java b/spring-amqp/src/main/java/org/springframework/amqp/support/AmqpMessageHeaderAccessor.java index b779b975..8778b579 100644 --- a/spring-amqp/src/main/java/org/springframework/amqp/support/AmqpMessageHeaderAccessor.java +++ b/spring-amqp/src/main/java/org/springframework/amqp/support/AmqpMessageHeaderAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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,6 +32,7 @@ import org.springframework.util.MimeType; * * @author Stephane Nicoll * @author Gary Russell + * * @since 1.4 */ public class AmqpMessageHeaderAccessor extends NativeMessageHeaderAccessor { @@ -98,16 +99,6 @@ public class AmqpMessageHeaderAccessor extends NativeMessageHeaderAccessor { return (String) getHeader(AmqpHeaders.CORRELATION_ID); } - /** - * Get the correlation id. - * @return the id. - * @deprecated - use {@link #getCorrelationId()}. - */ - @Deprecated - public String getCorrelationIdString() { - return (String) getHeader(AmqpHeaders.CORRELATION_ID); - } - public MessageDeliveryMode getDeliveryMode() { return (MessageDeliveryMode) getHeader(AmqpHeaders.DELIVERY_MODE); } diff --git a/spring-amqp/src/main/java/org/springframework/amqp/support/converter/DefaultClassMapper.java b/spring-amqp/src/main/java/org/springframework/amqp/support/converter/DefaultClassMapper.java index d9df0ac0..f7371860 100644 --- a/spring-amqp/src/main/java/org/springframework/amqp/support/converter/DefaultClassMapper.java +++ b/spring-amqp/src/main/java/org/springframework/amqp/support/converter/DefaultClassMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -56,11 +56,11 @@ public class DefaultClassMapper implements ClassMapper, InitializingBean { "java.lang" ); - private final Set trustedPackages = new LinkedHashSet(TRUSTED_PACKAGES); + private final Set trustedPackages = new LinkedHashSet<>(TRUSTED_PACKAGES); - private volatile Map> idClassMapping = new HashMap>(); + private volatile Map> idClassMapping = new HashMap<>(); - private volatile Map, String> classIdMapping = new HashMap, String>(); + private volatile Map, String> classIdMapping = new HashMap<>(); private volatile Class defaultMapClass = LinkedHashMap.class; @@ -75,23 +75,10 @@ public class DefaultClassMapper implements ClassMapper, InitializingBean { this.defaultType = defaultType; } - /** - * Set the type of {@link Map} to use. For outbound messages, set the - * {@value #DEFAULT_CLASSID_FIELD_NAME} header to {@code Hashtable}. For inbound messages, - * if the {@value #DEFAULT_CLASSID_FIELD_NAME} header is {@code HashTable} convert to this - * class. - * @param defaultMapClass the map class. - * @deprecated use {@link #setDefaultMapClass(Class)} - */ - @Deprecated - public void setDefaultHashtableClass(Class defaultMapClass) { - this.defaultMapClass = defaultMapClass; - } - /** * Set the type of {@link Map} to use. For outbound messages, set the * {@value #DEFAULT_CLASSID_FIELD_NAME} header to {@code HashTable}. For inbound messages, - * if the {@value #DEFAULT_CLASSID_FIELD_NAME} header is {@code HashTable} convert to this + * if the {@value #DEFAULT_CLASSID_FIELD_NAME} header is {@code Hashtable} convert to this * class. * @param defaultMapClass the map class. * @since 2.0 diff --git a/spring-rabbit-junit/src/main/resources/log4j2-test.xml b/spring-rabbit-junit/src/test/resources/log4j2-test.xml similarity index 100% rename from spring-rabbit-junit/src/main/resources/log4j2-test.xml rename to spring-rabbit-junit/src/test/resources/log4j2-test.xml diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitResourceHolder.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitResourceHolder.java index 6ff8b811..14bb0dd0 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitResourceHolder.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitResourceHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -37,7 +37,8 @@ import org.springframework.util.MultiValueMap; import com.rabbitmq.client.Channel; /** - * Rabbit resource holder, wrapping a RabbitMQ Connection and Channel. RabbitTransactionManager binds instances of this + * Rabbit resource holder, wrapping a RabbitMQ Connection and Channel. + * RabbitTransactionManager binds instances of this * class to the thread, for a given Rabbit ConnectionFactory. * *

@@ -56,13 +57,13 @@ public class RabbitResourceHolder extends ResourceHolderSupport { private final boolean frozen = false; - private final List connections = new LinkedList(); + private final List connections = new LinkedList<>(); - private final List channels = new LinkedList(); + private final List channels = new LinkedList<>(); - private final Map> channelsPerConnection = new HashMap>(); + private final Map> channelsPerConnection = new HashMap<>(); - private final MultiValueMap deliveryTags = new LinkedMultiValueMap(); + private final MultiValueMap deliveryTags = new LinkedMultiValueMap<>(); private final boolean releaseAfterCompletion; @@ -218,14 +219,4 @@ public class RabbitResourceHolder extends ResourceHolderSupport { } } - /** - * Invalid - always returned false. - * @return true if the channels in this holder are transactional - * @deprecated Not used - */ - @Deprecated - public boolean isChannelTransactional() { - return false; - } - } diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitUtils.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitUtils.java index f2505ea5..288da43f 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitUtils.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitUtils.java @@ -23,8 +23,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.amqp.AmqpIOException; -import org.springframework.amqp.AmqpRejectAndDontRequeueException; -import org.springframework.amqp.rabbit.listener.MessageRejectedWhileStoppingException; import org.springframework.amqp.rabbit.support.RabbitExceptionTranslator; import org.springframework.util.Assert; @@ -313,35 +311,4 @@ public abstract class RabbitUtils { } } - /** - * Determine whether a message should be requeued; returns true if the throwable is a - * {@link MessageRejectedWhileStoppingException} or defaultRequeueRejected is true and - * there is not an {@link AmqpRejectAndDontRequeueException} in the cause chain. - * @param defaultRequeueRejected the default requeue rejected. - * @param throwable the throwable. - * @param logger the logger to use for debug. - * @return true to requeue. - * @since 2.0 - * @deprecated in favor of {@code ContainerUtils#shouldRequeue(boolean, Throwable, Log)}. - */ - @Deprecated - public static boolean shouldRequeue(boolean defaultRequeueRejected, Throwable throwable, Log logger) { - logger.warn("Use ContainerUtils.shouldRequeue()"); - // compare class by name to avoid tangle - boolean shouldRequeue = defaultRequeueRejected || - throwable.getClass().getName().equals( - "org.springframework.amqp.rabbit.listener.MessageRejectedWhileStoppingException"); - Throwable t = throwable; - while (shouldRequeue && t != null) { - if (t instanceof AmqpRejectAndDontRequeueException) { - shouldRequeue = false; - } - t = t.getCause(); - } - if (logger.isDebugEnabled()) { - logger.debug("Rejecting messages (requeue=" + shouldRequeue + ")"); - } - return shouldRequeue; - } - } diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/support/LogAppenderUtils.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/support/LogAppenderUtils.java deleted file mode 100644 index dc013db3..00000000 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/support/LogAppenderUtils.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2016-2018 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.amqp.rabbit.support; - -import java.lang.reflect.Method; - -import org.springframework.util.ClassUtils; - -/** - * Utility methods for log appenders. - * - * @author Gary Russell - * @since 1.5.6 - * - * @deprecated in favor of {@code ConnectionFactoryConfigurationUtils}. - * - */ -@Deprecated -public final class LogAppenderUtils { - - private static final Method util; - - static { - Method method; - try { - Class utils = ClassUtils.forName( - "org.springframework.amqp.rabbit.connection.ConnectionFactoryConfigurationUtils", - LogAppenderUtils.class.getClassLoader()); - Class abstractCF = ClassUtils.forName( - "org.springframework.amqp.rabbit.connection.AbstractConnectionFactory", - LogAppenderUtils.class.getClassLoader()); - method = utils.getDeclaredMethod("updateClientConnectionProperties", abstractCF, String.class); - } - catch (Exception e) { - method = null; - } - util = method; - } - - private LogAppenderUtils() { - super(); - } - - /** - * Parse the properties {@code key:value[,key:value]...} and add them to the - * connection factory client properties. - * @param connectionFactory the connection factory. - * @param clientConnectionProperties the properties. - */ - public static void updateClientConnectionProperties(Object connectionFactory, - String clientConnectionProperties) { - - try { - util.invoke(null, connectionFactory, clientConnectionProperties); - } - catch (Exception e) { - throw new RuntimeException("Failed to set properties", e); - } - } - -}