diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100755 index 000000000..fa4f7b499 --- /dev/null +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,110 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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. +*/ + +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar old mode 100644 new mode 100755 index 5fd4d5023..01e679973 Binary files a/.mvn/wrapper/maven-wrapper.jar and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties old mode 100644 new mode 100755 index 6637cedb2..00d32aab1 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1 +1 @@ -distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip \ No newline at end of file +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip \ No newline at end of file diff --git a/mvnw b/mvnw index 0a7dac221..5551fde8e 100755 --- a/mvnw +++ b/mvnw @@ -54,38 +54,16 @@ case "`uname`" in CYGWIN*) cygwin=true ;; MINGW*) mingw=true;; Darwin*) darwin=true - # - # Look for the Apple JDKs first to preserve the existing behaviour, and then look - # for the new JDKs provided by Oracle. - # - if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then - # - # Apple JDKs - # - export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home - fi - - if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then - # - # Apple JDKs - # - export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home - fi - - if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then - # - # Oracle JDKs - # - export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home - fi - - if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then - # - # Apple JDKs - # - export JAVA_HOME=`/usr/libexec/java_home` - fi - ;; + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; esac if [ -z "$JAVA_HOME" ] ; then @@ -130,7 +108,7 @@ if $cygwin ; then CLASSPATH=`cygpath --path --unix "$CLASSPATH"` fi -# For Migwn, ensure paths are in UNIX format before anything is touched +# For Mingw, ensure paths are in UNIX format before anything is touched if $mingw ; then [ -n "$M2_HOME" ] && M2_HOME="`(cd "$M2_HOME"; pwd)`" @@ -184,27 +162,28 @@ fi CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` -fi - # traverses directory structure from process work directory to filesystem root # first directory with .mvn subdirectory is considered project base directory find_maven_basedir() { - local basedir=$(pwd) - local wdir=$(pwd) + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" while [ "$wdir" != '/' ] ; do if [ -d "$wdir"/.mvn ] ; then basedir=$wdir break fi - wdir=$(cd "$wdir/.."; pwd) + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround done echo "${basedir}" } @@ -216,30 +195,92 @@ concat_lines() { fi } -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain -echo "Running version check" -VERSION=$( sed '\!//' -e 's!.*$!!' ) -echo "The found version is [${VERSION}]" - -if echo $VERSION | egrep -q 'M|RC'; then - echo Activating \"milestone\" profile for version=\"$VERSION\" - echo $MAVEN_ARGS | grep -q milestone || MAVEN_ARGS="$MAVEN_ARGS -Pmilestone" -else - echo Deactivating \"milestone\" profile for version=\"$VERSION\" - echo $MAVEN_ARGS | grep -q milestone && MAVEN_ARGS=$(echo $MAVEN_ARGS | sed -e 's/-Pmilestone//') -fi - exec "$JAVACMD" \ $MAVEN_OPTS \ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} ${MAVEN_ARGS} "$@" + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd old mode 100644 new mode 100755 index b0dc0e7e9..48363fa60 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -1,145 +1,161 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -set MAVEN_CMD_LINE_ARGS=%* - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" - -set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar"" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index 69428e411..fdc5c2a65 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,11 @@ 2.2.0.BUILD-SNAPSHOT 2.1.2.RELEASE 1.8 + true + true + + true + @@ -99,6 +104,14 @@ + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + spring diff --git a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitAdminException.java b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitAdminException.java index 179064109..2a4456f10 100644 --- a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitAdminException.java +++ b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitAdminException.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2019 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-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitBindingCleaner.java b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitBindingCleaner.java index c5e7449fe..9a34ab04a 100644 --- a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitBindingCleaner.java +++ b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitBindingCleaner.java @@ -44,6 +44,9 @@ public class RabbitBindingCleaner implements BindingCleaner { private static final String PREFIX_DELIMITER = "."; + /** + * Binder prefix. + */ public static final String BINDER_PREFIX = "binder" + PREFIX_DELIMITER; @Override diff --git a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitManagementUtils.java b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitManagementUtils.java index 077663597..09c139479 100644 --- a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitManagementUtils.java +++ b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/admin/RabbitManagementUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2019 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-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/properties/RabbitCommonProperties.java b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/properties/RabbitCommonProperties.java index ebbf8d79c..9a5096317 100644 --- a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/properties/RabbitCommonProperties.java +++ b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/properties/RabbitCommonProperties.java @@ -28,86 +28,89 @@ import org.springframework.amqp.core.ExchangeTypes; */ public abstract class RabbitCommonProperties { + /** + * DLQ name prefix. + */ public static final String DEAD_LETTER_EXCHANGE = "DLX"; /** - * type of exchange to declare (if necessary, and declareExchange is true) + * type of exchange to declare (if necessary, and declareExchange is true). */ private String exchangeType = ExchangeTypes.TOPIC; /** - * whether to declare the exchange + * whether to declare the exchange. */ private boolean declareExchange = true; /** - * whether to declare the exchange as durable + * whether to declare the exchange as durable. */ private boolean exchangeDurable = true; /** - * whether to declare the exchange as auto-delete + * whether to declare the exchange as auto-delete. */ private boolean exchangeAutoDelete = false; /** - * whether a delayed message exchange should be used + * whether a delayed message exchange should be used. */ private boolean delayedExchange = false; /** - * set to true to name the queue with only the group; default is destination.group + * set to true to name the queue with only the group; default is destination.group. */ private boolean queueNameGroupOnly = false; /** - * whether to bind a queue (or queues when partitioned) to the exchange + * whether to bind a queue (or queues when partitioned) to the exchange. */ private boolean bindQueue = true; /** * routing key to bind (default # for non-partitioned, destination-instanceIndex for - * partitioned) + * partitioned). */ private String bindingRoutingKey; /** - * default time to live to apply to the queue when declared (ms) + * default time to live to apply to the queue when declared (ms). */ private Integer ttl; /** - * how long before an unused queue is deleted (ms) + * how long before an unused queue is deleted (ms). */ private Integer expires; /** - * maximum number of messages in the queue + * maximum number of messages in the queue. */ private Integer maxLength; /** - * maximum number of total bytes in the queue from all messages + * maximum number of total bytes in the queue from all messages. */ private Integer maxLengthBytes; /** - * maximum priority of messages in the queue (0-255) + * maximum priority of messages in the queue (0-255). */ private Integer maxPriority; /** - * name of the DLQ - default is prefix+destination.dlq + * name of the DLQ - default is prefix+destination.dlq. */ private String deadLetterQueueName; /** - * a DLX to assign to the queue; if autoBindDlq is true, defaults to 'prefix+DLX' + * a DLX to assign to the queue; if autoBindDlq is true, defaults to 'prefix+DLX'. */ private String deadLetterExchange; /** - * the type of the DLX, if autoBindDlq is true + * the type of the DLX, if autoBindDlq is true. */ private String deadLetterExchangeType = ExchangeTypes.DIRECT; @@ -118,73 +121,73 @@ public abstract class RabbitCommonProperties { /** * a dead letter routing key to assign to that queue; if autoBindDlq is true, defaults - * to destination + * to destination. */ private String deadLetterRoutingKey; /** - * default time to live to apply to the dead letter queue when declared (ms) + * default time to live to apply to the dead letter queue when declared (ms). */ private Integer dlqTtl; /** - * how long before an unused dead letter queue is deleted (ms) + * how long before an unused dead letter queue is deleted (ms). */ private Integer dlqExpires; /** - * maximum number of messages in the dead letter queue + * maximum number of messages in the dead letter queue. */ private Integer dlqMaxLength; /** - * maximum number of total bytes in the dead letter queue from all messages + * maximum number of total bytes in the dead letter queue from all messages. */ private Integer dlqMaxLengthBytes; /** - * maximum priority of messages in the dead letter queue (0-255) + * maximum priority of messages in the dead letter queue (0-255). */ private Integer dlqMaxPriority; /** - * if a DLQ is declared, a DLX to assign to that queue; default none + * if a DLQ is declared, a DLX to assign to that queue; default none. */ private String dlqDeadLetterExchange; /** * if a DLQ is declared, a dead letter routing key to assign to that queue; default - * none + * none. */ private String dlqDeadLetterRoutingKey; /** - * true to automatically bind a dead letter queue to a DLX + * true to automatically bind a dead letter queue to a DLX. */ private boolean autoBindDlq; /** - * prefix for elements declared in RabbitMQ (exchanges, queues) + * prefix for elements declared in RabbitMQ (exchanges, queues). */ private String prefix = ""; /** - * true if the queue is provisioned as a lazy queue + * true if the queue is provisioned as a lazy queue. */ private boolean lazy; /** - * true if the DLQ is provisioned as a lazy queue + * true if the DLQ is provisioned as a lazy queue. */ private boolean dlqLazy; /** - * action when maxLength or maxLengthBytes is exceeded + * action when maxLength or maxLengthBytes is exceeded. */ private String overflowBehavior; /** - * action when maxLength or maxLengthBytes is exceeded + * action when maxLength or maxLengthBytes is exceeded. */ private String dlqOverflowBehavior; diff --git a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/properties/RabbitConsumerProperties.java b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/properties/RabbitConsumerProperties.java index 0724b112a..97398d836 100644 --- a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/properties/RabbitConsumerProperties.java +++ b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/properties/RabbitConsumerProperties.java @@ -30,77 +30,77 @@ import org.springframework.util.Assert; public class RabbitConsumerProperties extends RabbitCommonProperties { /** - * true to use transacted channels + * true to use transacted channels. */ private boolean transacted; /** - * container acknowledge mode + * container acknowledge mode. */ private AcknowledgeMode acknowledgeMode = AcknowledgeMode.AUTO; /** - * maxumum concurrency of this consumer (threads) + * maxumum concurrency of this consumer (threads). */ private int maxConcurrency = 1; /** - * number of prefetched messages pre consumer thread + * number of prefetched messages pre consumer thread. */ private int prefetch = 1; /** - * messages per acknowledgment (and commit when transacted) + * messages per acknowledgment (and commit when transacted). */ private int txSize = 1; /** - * true for a durable subscription + * true for a durable subscription. */ private boolean durableSubscription = true; /** - * republish failures to the DLQ with diagnostic headers + * republish failures to the DLQ with diagnostic headers. */ private boolean republishToDlq; /** - * when republishing to the DLQ, the delivery mode to use + * when republishing to the DLQ, the delivery mode to use. */ private MessageDeliveryMode republishDeliveyMode = MessageDeliveryMode.PERSISTENT; /** - * true to requeue rejected messages, false to discard (or route to DLQ) + * true to requeue rejected messages, false to discard (or route to DLQ). */ private boolean requeueRejected = false; /** - * patterns to match which headers are mapped (inbound) + * patterns to match which headers are mapped (inbound). */ private String[] headerPatterns = new String[] { "*" }; /** - * interval between reconnection attempts + * interval between reconnection attempts. */ private long recoveryInterval = 5000; /** - * true if the consumer is exclusive + * true if the consumer is exclusive. */ private boolean exclusive; /** - * when true, stop the container instead of retrying queue declarations + * when true, stop the container instead of retrying queue declarations. */ private boolean missingQueuesFatal = false; /** - * how many times to attempt passive queue declaration + * how many times to attempt passive queue declaration. */ private Integer queueDeclarationRetries; /** - * interval between attempts to passively declare missing queues + * interval between attempts to passively declare missing queues. */ private Long failedDeclarationRetryInterval; @@ -166,7 +166,7 @@ public class RabbitConsumerProperties extends RabbitCommonProperties { /** * @deprecated - use {@link #setHeaderPatterns(String[])}. - * @param requestHeaderPatterns + * @param requestHeaderPatterns request header patterns */ @Deprecated public void setRequestHeaderPatterns(String[] requestHeaderPatterns) { diff --git a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/properties/RabbitProducerProperties.java b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/properties/RabbitProducerProperties.java index cb1f5a3b5..4e8418ae4 100644 --- a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/properties/RabbitProducerProperties.java +++ b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/properties/RabbitProducerProperties.java @@ -28,61 +28,61 @@ import org.springframework.expression.Expression; public class RabbitProducerProperties extends RabbitCommonProperties { /** - * true to compress messages + * true to compress messages. */ private boolean compress; /** - * true to batch multiple messages into one + * true to batch multiple messages into one. */ private boolean batchingEnabled; /** - * the number of messages to batch, when enabled + * the number of messages to batch, when enabled. */ private int batchSize = 100; /** - * the size limit for batched messages + * the size limit for batched messages. */ private int batchBufferLimit = 10000; /** - * the time after which an incomplete batch will be sent + * the time after which an incomplete batch will be sent. */ private int batchTimeout = 5000; /** - * true to use transacted channels + * true to use transacted channels. */ private boolean transacted; /** - * the delivery mode for published messages + * the delivery mode for published messages. */ private MessageDeliveryMode deliveryMode = MessageDeliveryMode.PERSISTENT; /** - * patterns to match which headers are mapped (inbound) + * patterns to match which headers are mapped (inbound). */ private String[] headerPatterns = new String[] { "*" }; /** * when using a delayed message exchange, a SpEL expression to determine the delay to - * apply to messages + * apply to messages. */ private Expression delayExpression; /** * a custom routing key when publishing messages; default is the destination name; - * suffixed by "-partition" when partitioned + * suffixed by "-partition" when partitioned. */ private Expression routingKeyExpression; /** * the channel name to which to send publisher confirms (acks) if the connection * factory is so configured; default 'nullChannel'; requires - * 'errorChannelEnabled=true' + * 'errorChannelEnabled=true'. */ private String confirmAckChannel; diff --git a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/provisioning/RabbitExchangeQueueProvisioner.java b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/provisioning/RabbitExchangeQueueProvisioner.java index 16796bb35..a0e6a8e0f 100644 --- a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/provisioning/RabbitExchangeQueueProvisioner.java +++ b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/provisioning/RabbitExchangeQueueProvisioner.java @@ -54,16 +54,18 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** - * AMQP implementation for {@link ProvisioningProvider} + * AMQP implementation for {@link ProvisioningProvider}. * * @author Soby Chacko * @author Gary Russell * @author Oleg Zhurakousky */ +// @checkstyle:off public class RabbitExchangeQueueProvisioner implements ApplicationListener, ProvisioningProvider, ExtendedProducerProperties> { + // @checkstyle:on private static final Base64UrlNamingStrategy ANONYMOUS_GROUP_NAME_GENERATOR = new Base64UrlNamingStrategy( "anonymous."); @@ -351,6 +353,7 @@ public class RabbitExchangeQueueProvisioner * For binder implementations that support dead lettering, construct the name of the * dead letter entity for the underlying pipe name. * @param name the name. + * @return constructDLQName */ public static String constructDLQName(String name) { return name + ".dlq"; diff --git a/spring-cloud-stream-binder-rabbit-test-support/src/main/java/org/springframework/cloud/stream/binder/test/junit/rabbit/RabbitTestSupport.java b/spring-cloud-stream-binder-rabbit-test-support/src/main/java/org/springframework/cloud/stream/binder/test/junit/rabbit/RabbitTestSupport.java index c76c97eee..68cb49389 100644 --- a/spring-cloud-stream-binder-rabbit-test-support/src/main/java/org/springframework/cloud/stream/binder/test/junit/rabbit/RabbitTestSupport.java +++ b/spring-cloud-stream-binder-rabbit-test-support/src/main/java/org/springframework/cloud/stream/binder/test/junit/rabbit/RabbitTestSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2019 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-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitExpressionEvaluatingInterceptor.java b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitExpressionEvaluatingInterceptor.java index aa39c617e..96ad2a248 100644 --- a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitExpressionEvaluatingInterceptor.java +++ b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitExpressionEvaluatingInterceptor.java @@ -36,10 +36,19 @@ import org.springframework.util.Assert; */ public class RabbitExpressionEvaluatingInterceptor implements ChannelInterceptor { + /** + * Instance of ExpressionParser. + */ public static final ExpressionParser PARSER = new SpelExpressionParser(); + /** + * Default name for routing key header. + */ public static final String ROUTING_KEY_HEADER = "scst_routingKey"; + /** + * Default name for delay header. + */ public static final String DELAY_HEADER = "scst_delay"; private final Expression routingKeyExpression; diff --git a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java index 5bc7c25bb..f8f29abce 100644 --- a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java +++ b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java @@ -24,6 +24,9 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +import com.rabbitmq.client.AMQP; +import com.rabbitmq.client.Envelope; + import org.springframework.amqp.AmqpRejectAndDontRequeueException; import org.springframework.amqp.ImmediateAcknowledgeAmqpException; import org.springframework.amqp.core.Message; @@ -100,9 +103,6 @@ import org.springframework.scheduling.TaskScheduler; import org.springframework.util.Assert; import org.springframework.util.StringUtils; -import com.rabbitmq.client.AMQP; -import com.rabbitmq.client.Envelope; - /** * A {@link org.springframework.cloud.stream.binder.Binder} implementation backed by * RabbitMQ. @@ -118,6 +118,7 @@ import com.rabbitmq.client.Envelope; * @author Soby Chacko * @author Oleg Zhurakousky */ +// @checkstyle:off public class RabbitMessageChannelBinder extends AbstractMessageChannelBinder, ExtendedProducerProperties, RabbitExchangeQueueProvisioner> implements @@ -129,7 +130,6 @@ public class RabbitMessageChannelBinder extends private static final AmqpMessageHeaderErrorMessageStrategy errorMessageStrategy = new AmqpMessageHeaderErrorMessageStrategy(); private static final MessagePropertiesConverter inboundMessagePropertiesConverter = new DefaultMessagePropertiesConverter() { - @Override public MessageProperties toMessageProperties(AMQP.BasicProperties source, Envelope envelope, String charset) { @@ -138,9 +138,10 @@ public class RabbitMessageChannelBinder extends properties.setDeliveryMode(null); return properties; } - }; + // @checkstyle:on + private final RabbitProperties rabbitProperties; private boolean destroyConnectionFactory; diff --git a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/config/ExtendedBindingHandlerMappingsProviderConfiguration.java b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/config/ExtendedBindingHandlerMappingsProviderConfiguration.java index 7bd9d4a3b..ff500d7c9 100644 --- a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/config/ExtendedBindingHandlerMappingsProviderConfiguration.java +++ b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/config/ExtendedBindingHandlerMappingsProviderConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 the original author or authors. + * 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. @@ -25,6 +25,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** + * Configuration for extended binding metadata. + * * @author Oleg Zhurakousky * */ diff --git a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/config/RabbitServiceAutoConfiguration.java b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/config/RabbitServiceAutoConfiguration.java index 93b7f4e44..1b0cd520b 100644 --- a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/config/RabbitServiceAutoConfiguration.java +++ b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/config/RabbitServiceAutoConfiguration.java @@ -58,7 +58,39 @@ import org.springframework.util.StringUtils; @ConditionalOnMissingBean(Binder.class) @Import({ RabbitMessageChannelBinderConfiguration.class, RabbitServiceAutoConfiguration.RabbitHealthIndicatorConfiguration.class }) -public class RabbitServiceAutoConfiguration { +public abstract class RabbitServiceAutoConfiguration { + + static void configureCachingConnectionFactory( + CachingConnectionFactory connectionFactory, + ConfigurableApplicationContext applicationContext, + RabbitProperties rabbitProperties) throws Exception { + + if (StringUtils.hasText(rabbitProperties.getAddresses())) { + connectionFactory.setAddresses(rabbitProperties.determineAddresses()); + } + + connectionFactory.setPublisherConfirms(rabbitProperties.isPublisherConfirms()); + connectionFactory.setPublisherReturns(rabbitProperties.isPublisherReturns()); + if (rabbitProperties.getCache().getChannel().getSize() != null) { + connectionFactory.setChannelCacheSize( + rabbitProperties.getCache().getChannel().getSize()); + } + if (rabbitProperties.getCache().getConnection().getMode() != null) { + connectionFactory + .setCacheMode(rabbitProperties.getCache().getConnection().getMode()); + } + if (rabbitProperties.getCache().getConnection().getSize() != null) { + connectionFactory.setConnectionCacheSize( + rabbitProperties.getCache().getConnection().getSize()); + } + if (rabbitProperties.getCache().getChannel().getCheckoutTimeout() != null) { + connectionFactory.setChannelCheckoutTimeout(rabbitProperties.getCache() + .getChannel().getCheckoutTimeout().toMillis()); + } + connectionFactory.setApplicationContext(applicationContext); + applicationContext.addApplicationListener(connectionFactory); + connectionFactory.afterPropertiesSet(); + } /** * Configuration to be used when the cloud profile is set. @@ -85,8 +117,10 @@ public class RabbitServiceAutoConfiguration { * Active only if {@code spring.cloud.stream.override-cloud-connectors} is not * set to {@code true}. */ + // @checkstyle:off @Configuration @ConditionalOnProperty(value = "spring.cloud.stream.override-cloud-connectors", havingValue = "false", matchIfMissing = true) + // @checkstyle:on // Required to parse Rabbit properties which are passed to the binder for // clustering. We need to enable it here explicitly as the default Rabbit // configuration is not triggered. @@ -99,7 +133,10 @@ public class RabbitServiceAutoConfiguration { * @param cloud {@link Cloud} instance to be used for accessing services. * @param connectorConfigObjectProvider the {@link ObjectProvider} for the * {@link RabbitConnectionFactoryConfig}. + * @param applicationContext application context instance + * @param rabbitProperties rabbit properties * @return the {@link ConnectionFactory} used by the binder. + * @throws Exception if configuration of connection factory fails */ @Bean @Primary @@ -161,6 +198,10 @@ public class RabbitServiceAutoConfiguration { } + /** + * Configuration for Rabbit health indicator. + * + */ @Configuration @ConditionalOnClass(name = "org.springframework.boot.actuate.health.HealthIndicator") public static class RabbitHealthIndicatorConfiguration { @@ -172,36 +213,4 @@ public class RabbitServiceAutoConfiguration { } - static void configureCachingConnectionFactory( - CachingConnectionFactory connectionFactory, - ConfigurableApplicationContext applicationContext, - RabbitProperties rabbitProperties) throws Exception { - - if (StringUtils.hasText(rabbitProperties.getAddresses())) { - connectionFactory.setAddresses(rabbitProperties.determineAddresses()); - } - - connectionFactory.setPublisherConfirms(rabbitProperties.isPublisherConfirms()); - connectionFactory.setPublisherReturns(rabbitProperties.isPublisherReturns()); - if (rabbitProperties.getCache().getChannel().getSize() != null) { - connectionFactory.setChannelCacheSize( - rabbitProperties.getCache().getChannel().getSize()); - } - if (rabbitProperties.getCache().getConnection().getMode() != null) { - connectionFactory - .setCacheMode(rabbitProperties.getCache().getConnection().getMode()); - } - if (rabbitProperties.getCache().getConnection().getSize() != null) { - connectionFactory.setConnectionCacheSize( - rabbitProperties.getCache().getConnection().getSize()); - } - if (rabbitProperties.getCache().getChannel().getCheckoutTimeout() != null) { - connectionFactory.setChannelCheckoutTimeout(rabbitProperties.getCache() - .getChannel().getCheckoutTimeout().toMillis()); - } - connectionFactory.setApplicationContext(applicationContext); - applicationContext.addApplicationListener(connectionFactory); - connectionFactory.afterPropertiesSet(); - } - } diff --git a/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitBinderTests.java b/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitBinderTests.java index 731d3ee98..025c453fa 100644 --- a/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitBinderTests.java +++ b/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitBinderTests.java @@ -29,6 +29,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.zip.Deflater; +import com.rabbitmq.client.LongString; +import com.rabbitmq.http.client.domain.QueueInfo; import org.apache.commons.logging.Log; import org.junit.Rule; import org.junit.Test; @@ -109,9 +111,6 @@ import org.springframework.retry.support.RetryTemplate; import org.springframework.util.MimeTypeUtils; import org.springframework.util.ReflectionUtils; -import com.rabbitmq.client.LongString; -import com.rabbitmq.http.client.domain.QueueInfo; - import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; @@ -125,6 +124,7 @@ import static org.mockito.Mockito.when; * @author David Turanski * @author Artem Bilan */ +// @checkstyle:off public class RabbitBinderTests extends PartitionCapableBinderTests, ExtendedProducerProperties> { @@ -279,11 +279,11 @@ public class RabbitBinderTests extends "confirmCorrelationExpression.expression")).isEqualTo("#root"); class WrapperAccessor extends AmqpOutboundEndpoint { - public WrapperAccessor(AmqpTemplate amqpTemplate) { + WrapperAccessor(AmqpTemplate amqpTemplate) { super(amqpTemplate); } - public CorrelationDataWrapper getWrapper() throws Exception { + CorrelationDataWrapper getWrapper() throws Exception { Constructor constructor = CorrelationDataWrapper.class .getDeclaredConstructor(String.class, Object.class, Message.class); @@ -1916,5 +1916,6 @@ public class RabbitBinderTests extends } } + // @checkstyle:on } diff --git a/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitTestBinder.java b/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitTestBinder.java index d6bffdbed..86495bbcc 100644 --- a/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitTestBinder.java +++ b/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitTestBinder.java @@ -46,9 +46,11 @@ import org.springframework.util.StringUtils; * @author David Turanski * @author Mark Fisher */ +// @checkstyle:off public class RabbitTestBinder extends AbstractPollableConsumerTestBinder, ExtendedProducerProperties> { + // @checkstyle:on private final RabbitAdmin rabbitAdmin; private final Set prefixes = new HashSet<>(); diff --git a/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/integration/RabbitBinderModuleTests.java b/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/integration/RabbitBinderModuleTests.java index 07a002a8e..3c34a9131 100644 --- a/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/integration/RabbitBinderModuleTests.java +++ b/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/integration/RabbitBinderModuleTests.java @@ -16,6 +16,11 @@ package org.springframework.cloud.stream.binder.rabbit.integration; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + import org.junit.After; import org.junit.ClassRule; import org.junit.Test; @@ -38,7 +43,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.Cloud; import org.springframework.cloud.stream.annotation.EnableBinding; -import org.springframework.cloud.stream.binder.*; +import org.springframework.cloud.stream.binder.Binder; +import org.springframework.cloud.stream.binder.BinderFactory; +import org.springframework.cloud.stream.binder.Binding; +import org.springframework.cloud.stream.binder.ExtendedConsumerProperties; +import org.springframework.cloud.stream.binder.ExtendedProducerProperties; +import org.springframework.cloud.stream.binder.ExtendedPropertiesBinder; import org.springframework.cloud.stream.binder.rabbit.RabbitMessageChannelBinder; import org.springframework.cloud.stream.binder.rabbit.properties.RabbitConsumerProperties; import org.springframework.cloud.stream.binder.rabbit.properties.RabbitProducerProperties; @@ -55,11 +65,6 @@ import org.springframework.retry.backoff.ExponentialBackOffPolicy; import org.springframework.retry.policy.SimpleRetryPolicy; import org.springframework.retry.support.RetryTemplate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.UUID; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.willReturn; import static org.mockito.Mockito.mock; @@ -154,8 +159,10 @@ public class RabbitBinderModuleTests { BindingService bindingService = context.getBean(BindingService.class); DirectFieldAccessor channelBindingServiceAccessor = new DirectFieldAccessor( bindingService); + // @checkstyle:off Map>> consumerBindings = (Map>>) channelBindingServiceAccessor .getPropertyValue("consumerBindings"); + // @checkstyle:on Binding inputBinding = consumerBindings.get("input").get(0); SimpleMessageListenerContainer container = TestUtils.getPropertyValue( inputBinding, "lifecycle.messageListenerContainer", @@ -238,9 +245,11 @@ public class RabbitBinderModuleTests { .web(WebApplicationType.NONE) .run(params.toArray(new String[params.size()])); BinderFactory binderFactory = context.getBean(BinderFactory.class); + // @checkstyle:off @SuppressWarnings("unchecked") Binder, ExtendedProducerProperties> binder = (Binder, ExtendedProducerProperties>) binderFactory .getBinder(null, MessageChannel.class); + // @checkstyle:on assertThat(binder).isInstanceOf(RabbitMessageChannelBinder.class); DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder); ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor @@ -314,18 +323,18 @@ public class RabbitBinderModuleTests { BinderFactory binderFactory = context.getBean(BinderFactory.class); Binder rabbitBinder = binderFactory.getBinder(null, MessageChannel.class); - + // @checkstyle:off RabbitProducerProperties rabbitProducerProperties = (RabbitProducerProperties) ((ExtendedPropertiesBinder) rabbitBinder) .getExtendedProducerProperties("output"); - + // @checkstyle:on assertThat( rabbitProducerProperties.getRoutingKeyExpression().getExpressionString()) .isEqualTo("fooRoutingKey"); assertThat(rabbitProducerProperties.getBatchSize()).isEqualTo(512); - + // @checkstyle:off RabbitConsumerProperties rabbitConsumerProperties = (RabbitConsumerProperties) ((ExtendedPropertiesBinder) rabbitBinder) .getExtendedConsumerProperties("input"); - + // @checkstyle:on assertThat(rabbitConsumerProperties.getExchangeType()) .isEqualTo(ExchangeTypes.FANOUT); assertThat(rabbitConsumerProperties.getMaxConcurrency()).isEqualTo(4);