diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000..c32394f --- /dev/null +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,117 @@ +/* + * Copyright 2007-present 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. + */ +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + private static final String WRAPPER_VERSION = "0.5.5"; + /** + * 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/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".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 directory '" + 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 { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + 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.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..fa87ad7 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.1/apache-maven-3.6.1-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar diff --git a/.travis.yml b/.travis.yml index 4a51f83..a484505 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,16 @@ language: java -script: mvn clean install --fail-at-end -notifications: - email: - on_failure: true +sudo: false +dist: xenial +script: ./mvnw -V clean verify --fail-at-end -U -Prelease-checks matrix: - include: - - jdk: openjdk6 - env: JACOCO=true - - jdk: openjdk7 - env: JACOCO=true COVERALLS=true - - jdk: oraclejdk7 - env: JACOCO=true - - jdk: oraclejdk8 - env: JACOCO=true - - jdk: openjdk7 - env: JACOCO=true SONAR=publish - script: mvn clean install sonar:sonar --fail-at-end + include: + - jdk: openjdk8 + env: JACOCO=true COVERALLS=true + - jdk: openjdk11 + env: JACOCO=true + - jdk: openjdk8 + env: JACOCO=true SONAR=publish + script: ./mvnw -V clean verify sonar:sonar --fail-at-end -U +notifications: + email: + on_failure: change diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..d2f0ea3 --- /dev/null +++ b/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # 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 + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + 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 + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +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 + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + fi + 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 $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + 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" + +# 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 + +# 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 + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..b26ab24 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,182 @@ +@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 by 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.5.5/maven-wrapper-0.5.5.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% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%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 8b2e250..8d333de 100644 --- a/pom.xml +++ b/pom.xml @@ -1,9 +1,25 @@ + + 4.0.0 pl.wavesoftware jmh-junit-utilities - 1.0.1-SNAPSHOT + 2.0.0-SNAPSHOT jar JMH Utils for JUnit @@ -74,11 +90,11 @@ ${project.build.directory}/sonar https://sonar.wavesoftware.pl jacoco - 6 + 8 ${java.source.version} 1.${java.source.version} ${maven.compiler.source} - 0.7.6.201602180812 + 0.8.4 ${skipTests} @@ -93,62 +109,44 @@ 3.0.1 - com.google.guava - guava - 19.0 - - - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter-api + 5.3.2 pl.wavesoftware eid-exceptions - 1.2.0 + 2.0.0 - org.assertj - assertj-core - - 1.7.1 - test - - - org.mockito - mockito-core - 1.10.19 - test - - - org.hamcrest - hamcrest-all - 1.3 + pl.wavesoftware.testing + junit5-starter + 1.0.0 + pom test commons-io commons-io - 2.4 + 2.6 test - - org.codehaus.mojo + org.sonarsource.scanner.maven sonar-maven-plugin - 3.0.1 + 3.6.0.1398 - external.atlassian.jgitflow + com.manamind.jgitflow jgitflow-maven-plugin - 1.0-m5.1 + 1.0.0 true @@ -185,10 +183,10 @@ maven-compiler-plugin - 3.5.1 + 3.8.1 + true - -Werror -Xlint:all @@ -196,15 +194,12 @@ maven-jar-plugin - 2.6 - - true - + 3.1.2 maven-surefire-plugin - 2.19.1 + 2.22.2 false @@ -212,7 +207,7 @@ maven-failsafe-plugin - 2.19.1 + 2.22.2 false @@ -233,7 +228,7 @@ maven-source-plugin - 3.0.0 + 3.1.0 attach-sources @@ -245,7 +240,7 @@ maven-javadoc-plugin - 2.10.3 + 3.1.0 attach-javadocs @@ -270,7 +265,7 @@ maven-clean-plugin - 3.0.0 + 3.1.0 maven-install-plugin @@ -278,29 +273,15 @@ maven-resources-plugin - 2.7 + 3.1.0 maven-site-plugin - 3.5 + 3.7.1 - - - - maven-compiler-plugin - - - - maven-jar-plugin - - - - maven-surefire-plugin - - maven-failsafe-plugin @@ -326,6 +307,106 @@ + + sonar-publish + + + env.SONAR + publish + + + + + + org.jacoco + jacoco-maven-plugin + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + + + default + post-integration-test + + sonar + + + + + + + + + + sonar-for-developer + + + + env.GDMSESSION + + + + preview + true + true + issues.json + + + + + org.jacoco + jacoco-maven-plugin + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + + + default + post-integration-test + + sonar + + + + + + + org.codehaus.gmaven + groovy-maven-plugin + 2.0 + + + org.codehaus.groovy + groovy-all + 2.4.6 + + + + + ${sonar.working.directory}/${sonar.report.export.path} + + ${sonar.skip} + + https://raw.githubusercontent.com/wavesoftware/java-eid-exceptions/develop/src/test/groovy/verify-sonar-issues.groovy + + + + verify-sonar-issues + verify + + execute + + + + + + + + coveralls @@ -339,7 +420,7 @@ org.eluder.coveralls coveralls-maven-plugin - 3.1.0 + 4.3.0 coveralls-default @@ -376,6 +457,20 @@ + + + release-checks + + + + maven-source-plugin + + + maven-javadoc-plugin + + + + diff --git a/src/main/java/pl/wavesoftware/jmh/junit/utilities/JavaAgentSkip.java b/src/main/java/pl/wavesoftware/jmh/junit/utilities/JavaAgentSkip.java index c7f1ed2..1a603ad 100644 --- a/src/main/java/pl/wavesoftware/jmh/junit/utilities/JavaAgentSkip.java +++ b/src/main/java/pl/wavesoftware/jmh/junit/utilities/JavaAgentSkip.java @@ -1,32 +1,51 @@ +/* + * Copyright 2016-2019 Wave Software + * + * 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 pl.wavesoftware.jmh.junit.utilities; -import com.google.common.annotations.VisibleForTesting; -import org.junit.Assume; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.util.List; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + /** - * A rule that can be used to automatically skip test if some javaagent is being used for ex.: debugger, - * profiler, code coverage or other. It can be useful if you are running performance critical tests like JMH. + * A rule that can be used to automatically skip test if some javaagent is being used + * for ex.: debugger, profiler, code coverage or other. It can be useful if you are + * running performance critical tests like JMH. *

* Example: *

- * @ClassRule
- * public static JavaAgentSkip javaAgentSkip = JavaAgentSkip.ifPresent();
+ * @RegisterExtension
+ * static JavaAgentSkip javaAgentSkip = JavaAgentSkip.ifPresent();
  * 
- * @author Krzysztof Suszynski + * @author Krzysztof Suszynski * @since 29.03.16 */ -public final class JavaAgentSkip implements TestRule { +public final class JavaAgentSkip implements BeforeEachCallback { - public static final String JAVAAGENT = "-javaagent:"; - public static final String DEFAULT_MESSAGE_FORMAT = "Skipping test due to JavaAgentSkip rule set to %s"; - private static final RuntimeMXBean DEFAULT_RUNTIME_MXBEAN = ManagementFactory.getRuntimeMXBean(); + private static final String JAVAAGENT = "-javaagent:"; + static final String DEFAULT_MESSAGE_FORMAT = + "Skipping test due to JavaAgentSkip set to %s"; + + private static final RuntimeMXBean DEFAULT_RUNTIME_MXBEAN = + ManagementFactory.getRuntimeMXBean(); private final boolean isActive; private final String messageFormat; private final RuntimeMXBean runtimeMxBean; @@ -35,13 +54,17 @@ private JavaAgentSkip(boolean isActive) { this(isActive, DEFAULT_MESSAGE_FORMAT, DEFAULT_RUNTIME_MXBEAN); } - @VisibleForTesting protected JavaAgentSkip(boolean isActive, String messageFormat, RuntimeMXBean runtimeMxBean) { this.isActive = isActive; this.messageFormat = messageFormat; this.runtimeMxBean = runtimeMxBean; } + @Override + public void beforeEach(ExtensionContext context) { + assumeTrue(assumeValue(), () -> String.format(messageFormat, isActive)); + } + /** * Creates a JavaAgentSkip rule that is set to skip if agent is present * @return a JavaAgentSkip rule @@ -80,18 +103,6 @@ public static JavaAgentSkip ifAbsent(String messageFormat) { return new JavaAgentSkip(false, messageFormat, DEFAULT_RUNTIME_MXBEAN); } - @Override - public Statement apply(final Statement base, Description description) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - String message = String.format(messageFormat, isActive); - Assume.assumeTrue(message, assumeValue()); - base.evaluate(); - } - }; - } - private boolean assumeValue() { return isAgentThere() != isActive; } diff --git a/src/main/java/pl/wavesoftware/jmh/junit/utilities/JmhCleaner.java b/src/main/java/pl/wavesoftware/jmh/junit/utilities/JmhCleaner.java index b69eb51..e6b9a9a 100644 --- a/src/main/java/pl/wavesoftware/jmh/junit/utilities/JmhCleaner.java +++ b/src/main/java/pl/wavesoftware/jmh/junit/utilities/JmhCleaner.java @@ -1,9 +1,24 @@ +/* + * Copyright 2016-2019 Wave Software + * + * 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 pl.wavesoftware.jmh.junit.utilities; -import com.google.common.annotations.VisibleForTesting; -import org.junit.Test; -import org.junit.rules.ExternalResource; -import pl.wavesoftware.eid.utils.EidPreconditions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import javax.annotation.Nullable; import java.io.File; @@ -11,9 +26,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.URISyntaxException; - -import static pl.wavesoftware.eid.utils.EidPreconditions.checkState; -import static pl.wavesoftware.eid.utils.EidPreconditions.tryToExecute; +import java.nio.file.Files; /** * This class handles cleaning JMH test annotation that are being produced by JMH library. @@ -22,13 +35,13 @@ *

* Example: *

- * @ClassRule
- * public static JmhCleaner cleaner = new JmhCleaner(MyClassTest.class);
+ * @RegisterExtension
+ * static JmhCleaner cleaner = new JmhCleaner(MyClassTest.class);
  * 
- * @author Krzysztof Suszynski + * @author Krzysztof Suszynski * @since 25.03.16 */ -public final class JmhCleaner extends ExternalResource { +public final class JmhCleaner implements AfterEachCallback { private static final String GENERATED_TEST_SOURCES = "generated-test-sources"; private static final String TEST_ANNOTATIONS = "test-annotations"; private static final File[] EMPTY_FILES = new File[0]; @@ -43,16 +56,10 @@ public JmhCleaner(Class testClass) { } @Override - protected void after() { - tryToExecute(new EidPreconditions.UnsafeProcedure() { - @Override - public void execute() throws IOException, URISyntaxException { - cleanup(); - } - }, "20160331:151210"); + public void afterEach(ExtensionContext context) throws IOException, URISyntaxException { + cleanup(); } - @VisibleForTesting File getGeneratedTestAnnotationsDir() throws URISyntaxException, IOException { String location = testClass.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(); File file = new File(location).getCanonicalFile().getParentFile(); @@ -63,13 +70,15 @@ private static Class validateTestClass(Class testClass) { boolean hasTests = false; for (Method method : testClass.getDeclaredMethods()) { Test annot = method.getAnnotation(Test.class); - if (Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers()) && annot != null) { + if (!Modifier.isStatic(method.getModifiers()) && annot != null) { hasTests = true; break; } } if (!hasTests) { - throw new IllegalArgumentException("You need to pass a test class to constructor of JmhCleaner!!"); + throw new IllegalArgumentException( + "You need to pass a test class to constructor of JmhCleaner!!" + ); } return testClass; } @@ -89,8 +98,7 @@ private static void deleteRecursive(final File file) throws IOException { } } //call delete to delete files and empty directory - boolean deleted = file.delete(); - checkState(deleted, "20160331:151306", "Couldn't remove file: %s", file); + Files.delete(file.toPath()); } private static File[] ensureFileArray(@Nullable File[] files) { diff --git a/src/main/java/pl/wavesoftware/jmh/junit/utilities/package-info.java b/src/main/java/pl/wavesoftware/jmh/junit/utilities/package-info.java index 9e7314c..637e3eb 100644 --- a/src/main/java/pl/wavesoftware/jmh/junit/utilities/package-info.java +++ b/src/main/java/pl/wavesoftware/jmh/junit/utilities/package-info.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016-2019 Wave Software + * + * 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. + */ + /** * @author Krzysztof Suszynski * @since 31.03.16 diff --git a/src/test/java/pl/wavesoftware/jmh/junit/utilities/JavaAgentSkipTest.java b/src/test/java/pl/wavesoftware/jmh/junit/utilities/JavaAgentSkipTest.java index 6c13c00..806043b 100644 --- a/src/test/java/pl/wavesoftware/jmh/junit/utilities/JavaAgentSkipTest.java +++ b/src/test/java/pl/wavesoftware/jmh/junit/utilities/JavaAgentSkipTest.java @@ -1,30 +1,44 @@ +/* + * Copyright 2016-2019 Wave Software + * + * 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 pl.wavesoftware.jmh.junit.utilities; -import org.junit.AssumptionViolatedException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.opentest4j.TestAbortedException; import java.lang.management.RuntimeMXBean; import java.util.Arrays; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** * @author Krzysztof Suszynski * @since 31.03.16 */ -public class JavaAgentSkipTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); +class JavaAgentSkipTest { @Test - public void testIfPresent() { + void testIfPresent() { // when JavaAgentSkip skip = JavaAgentSkip.ifPresent(); // then @@ -32,7 +46,7 @@ public void testIfPresent() { } @Test - public void testIfPresent_String() { + void testIfPresent_String() { // when JavaAgentSkip skip = JavaAgentSkip.ifPresent("A message format"); // then @@ -40,7 +54,7 @@ public void testIfPresent_String() { } @Test - public void testIfAbsent() { + void testIfAbsent() { // when JavaAgentSkip skip = JavaAgentSkip.ifAbsent(); // then @@ -48,7 +62,7 @@ public void testIfAbsent() { } @Test - public void testIfAbsent_String() { + void testIfAbsent_String() { // when JavaAgentSkip skip = JavaAgentSkip.ifAbsent("A other message format"); // then @@ -56,41 +70,42 @@ public void testIfAbsent_String() { } @Test - public void testApply() throws Throwable { + void testApply() { // given RuntimeMXBean mxbean = mock(RuntimeMXBean.class); - List args = Arrays.asList("-ea", "-server", "-Xmx128m", "-javaagent:jacoco", "-Xms32m"); + List args = Arrays.asList( + "-ea", "-server", "-Xmx128m", "-javaagent:jacoco", "-Xms32m" + ); when(mxbean.getInputArguments()).thenReturn(args); - Statement statement = mock(Statement.class); - Description description = mock(Description.class); - JavaAgentSkip skip = new JavaAgentSkip(true, JavaAgentSkip.DEFAULT_MESSAGE_FORMAT, mxbean); - - // then - thrown.expect(AssumptionViolatedException.class); - thrown.expectMessage("Skipping test due to JavaAgentSkip rule set to true"); + JavaAgentSkip skip = new JavaAgentSkip( + true, JavaAgentSkip.DEFAULT_MESSAGE_FORMAT, mxbean + ); + ExtensionContext ctx = mock(ExtensionContext.class); // when - Statement newStatement = skip.apply(statement, description); - assertThat(newStatement).isNotNull(); - newStatement.evaluate(); + ThrowingCallable throwingCallable = () -> skip.beforeEach(ctx); + + // then + assertThatCode(throwingCallable) + .isInstanceOf(TestAbortedException.class) + .hasMessage("Assumption failed: Skipping test due to JavaAgentSkip set to true"); } @Test - public void testApply_Possitive() throws Throwable { + void testApply_Possitive() { // given List args = Arrays.asList("-ea", "-server", "-Xmx128m", "-Xms32m"); RuntimeMXBean mxbean = mock(RuntimeMXBean.class); when(mxbean.getInputArguments()).thenReturn(args); - Statement statement = mock(Statement.class); - Description description = mock(Description.class); - JavaAgentSkip skip = new JavaAgentSkip(true, JavaAgentSkip.DEFAULT_MESSAGE_FORMAT, mxbean); + JavaAgentSkip skip = new JavaAgentSkip( + true, JavaAgentSkip.DEFAULT_MESSAGE_FORMAT, mxbean + ); + ExtensionContext ctx = mock(ExtensionContext.class); // when - Statement newStatement = skip.apply(statement, description); - assertThat(newStatement).isNotNull(); - newStatement.evaluate(); + skip.beforeEach(ctx); // then - verify(statement).evaluate(); + verify(mxbean).getInputArguments(); } } diff --git a/src/test/java/pl/wavesoftware/jmh/junit/utilities/JmhCleanerTest.java b/src/test/java/pl/wavesoftware/jmh/junit/utilities/JmhCleanerTest.java index 7dd20ca..f5d5b49 100644 --- a/src/test/java/pl/wavesoftware/jmh/junit/utilities/JmhCleanerTest.java +++ b/src/test/java/pl/wavesoftware/jmh/junit/utilities/JmhCleanerTest.java @@ -1,39 +1,65 @@ +/* + * Copyright 2016-2019 Wave Software + * + * 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 pl.wavesoftware.jmh.junit.utilities; import org.apache.commons.io.FileUtils; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.ExternalResource; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; /** * @author Krzysztof Suszynski * @since 31.03.16 */ -public class JmhCleanerTest { +@ExtendWith(MockitoExtension.class) +class JmhCleanerTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Rule - public TestDirectoryExternalResource testDirectory = new TestDirectoryExternalResource(); + @RegisterExtension + static TestDirectory testDirectory = new TestDirectory(); + @Mock + private ExtensionContext extensionContext; @Test - public void testConstruct_InvalidClass() { - // then - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("You need to pass a test class to constructor of JmhCleaner!!"); + void testConstruct_InvalidClass() { // when - new JmhCleaner(String.class); + ThrowingCallable throwingCallable = () -> new JmhCleaner(String.class); + + // then + assertThatCode(throwingCallable) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("You need to pass a test class to constructor of JmhCleaner!!"); } @Test - public void testConstruct() { + void testConstruct() { // when JmhCleaner cleaner = new JmhCleaner(JmhCleanerTest.class); // then @@ -41,31 +67,31 @@ public void testConstruct() { } @Test - public void testAfter() { + void testAfter() throws IOException, URISyntaxException { // when JmhCleaner cleaner = new JmhCleaner(JmhCleanerTest.class); assertThat(testDirectory.getTestFile()).exists() .canRead(); // when - cleaner.after(); - cleaner.after(); + cleaner.afterEach(extensionContext); + cleaner.afterEach(extensionContext); // then assertThat(cleaner).isNotNull(); assertThat(testDirectory.getTestFile()).doesNotExist(); } - private static class TestDirectoryExternalResource extends ExternalResource { + private static class TestDirectory implements BeforeEachCallback, AfterEachCallback { private static final String TEST_FILE = "test.txt"; private static final String TEST_CONTENT = "QAZWSX"; - public File dir; - public JmhCleaner instance; + File dir; + JmhCleaner instance; private File testFile; @Override - protected void before() throws Throwable { + public void beforeEach(ExtensionContext context) throws IOException, URISyntaxException { instance = new JmhCleaner(JmhCleanerTest.class); dir = instance.getGeneratedTestAnnotationsDir(); FileUtils.deleteDirectory(dir); @@ -73,22 +99,18 @@ protected void before() throws Throwable { assertThat(dir.mkdirs()).isTrue(); assertThat(dir.exists()).isTrue(); testFile = new File(dir.toString() + File.separator + TEST_FILE); - FileUtils.write(testFile, TEST_CONTENT); + FileUtils.write(testFile, TEST_CONTENT, StandardCharsets.UTF_8); assertThat(testFile).canRead(); } @Override - protected void after() { - try { - FileUtils.deleteDirectory(dir); - } catch (IOException e) { - throw new RuntimeException(e); - } + public void afterEach(ExtensionContext context) throws IOException { + FileUtils.deleteDirectory(dir); assertThat(dir.exists()).isFalse(); assertThat(testFile).doesNotExist(); } - public File getTestFile() { + File getTestFile() { return testFile; } }