Skip to content

Commit

Permalink
breaking: minor adjustments and Java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Apr 3, 2024
1 parent 48ca1ba commit 8b37318
Show file tree
Hide file tree
Showing 25 changed files with 711 additions and 720 deletions.
18 changes: 13 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ buildscript {
classpath 'se.bjurr.gradle:gradle-scripts:2.+'
}
}

project.ext.buildConfig = [
sourceCompatibility: 17,
targetCompatibility: 17,
]
apply from: project.buildscript.classLoader.getResource('main.gradle').toURI()

dependencies {
api 'com.github.tomakehurst:wiremock:2.27.2'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.15.0'
implementation 'javax:javaee-api:8.0.1'
api 'org.wiremock:wiremock:3.5.2'
compileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.17.0'
compileOnly 'jakarta.ws.rs:jakarta.ws.rs-api:3.1.0'

testImplementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.17.0'
testImplementation 'jakarta.ws.rs:jakarta.ws.rs-api:3.1.0'
testImplementation 'org.glassfish.jaxb:jaxb-runtime:4.0.5'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'io.rest-assured:rest-assured:5.3.0'
testImplementation 'org.assertj:assertj-core:3.25.3'
testImplementation 'io.rest-assured:rest-assured:5.4.0'
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
35 changes: 22 additions & 13 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,11 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
21 changes: 11 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -42,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -56,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Original file line number Diff line number Diff line change
@@ -1,94 +1,93 @@
package com.github.tomakehurst.wiremock.client;

import com.github.tomakehurst.wiremock.http.RequestMethod;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HEAD;
import jakarta.ws.rs.OPTIONS;
import jakarta.ws.rs.PATCH;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HEAD;
import javax.ws.rs.OPTIONS;
import javax.ws.rs.PATCH;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

class JaxrsInvocationHandler implements InvocationHandler {

private RequestMethod requestMethod;
private Class<?> returnType;
private String path;
private List<InvocationParam> queryParams;
private List<InvocationParam> pathParams;
private List<String> requestContentTypeList;
private List<String> responseContentTypeList;
private Object postObject;

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args)
throws Throwable {
this.requestMethod = getRequestMethod(method);
this.requestMethod = this.getRequestMethod(method);

this.returnType = method.getReturnType();
this.queryParams = createQueryParams(method.getParameters(), args);
this.pathParams = createPathParams(method.getParameters(), args);
this.path = substituteParams(createPath(method), queryParams, pathParams);
this.requestContentTypeList = getRequestContentTypeList(method);
this.responseContentTypeList = getResponseContentTypeList(method);
this.postObject = findPostObject(method.getParameters(), args).orElse(null);
this.queryParams = this.createQueryParams(method.getParameters(), args);
final List<InvocationParam> pathParams = this.createPathParams(method.getParameters(), args);
this.path = this.substituteParams(this.createPath(method), pathParams);
this.requestContentTypeList = this.getRequestContentTypeList(method);
this.responseContentTypeList = this.getResponseContentTypeList(method);
this.postObject = this.findPostObject(method.getParameters(), args).orElse(null);
return null;
}

public RequestMethod getRequestMethod() {
return requestMethod;
return this.requestMethod;
}

public String getPath() {
return path;
return this.path;
}

public List<String> getRequestContentTypeList() {
return requestContentTypeList;
return this.requestContentTypeList;
}

public List<String> getResponseContentTypeList() {
return responseContentTypeList;
return this.responseContentTypeList;
}

public Class<?> getReturnType() {
return returnType;
return this.returnType;
}

public List<InvocationParam> getQueryParams() {
return queryParams;
return this.queryParams;
}

public Optional<Object> findPostObject() {
return Optional.ofNullable(postObject);
return Optional.ofNullable(this.postObject);
}

RequestMethod getRequestMethod(final Method method) {
if (findAnnotation(method, GET.class).isPresent()) {
if (this.findAnnotation(method, GET.class).isPresent()) {
return RequestMethod.GET;
} else if (findAnnotation(method, POST.class).isPresent()) {
} else if (this.findAnnotation(method, POST.class).isPresent()) {
return RequestMethod.POST;
} else if (findAnnotation(method, PUT.class).isPresent()) {
} else if (this.findAnnotation(method, PUT.class).isPresent()) {
return RequestMethod.PUT;
} else if (findAnnotation(method, DELETE.class).isPresent()) {
} else if (this.findAnnotation(method, DELETE.class).isPresent()) {
return RequestMethod.DELETE;
} else if (findAnnotation(method, PATCH.class).isPresent()) {
} else if (this.findAnnotation(method, PATCH.class).isPresent()) {
return RequestMethod.PATCH;
} else if (findAnnotation(method, HEAD.class).isPresent()) {
} else if (this.findAnnotation(method, HEAD.class).isPresent()) {
return RequestMethod.HEAD;
} else if (findAnnotation(method, OPTIONS.class).isPresent()) {
} else if (this.findAnnotation(method, OPTIONS.class).isPresent()) {
return RequestMethod.OPTIONS;
}
throw new RuntimeException("Cannot find request method of " + method.getName());
Expand Down Expand Up @@ -116,8 +115,8 @@ private List<String> getResponseContentTypeList(final Method method) {

private String createPath(final Method method) {
final Optional<Path> classPath =
findAnnotation(method.getDeclaringClass().getAnnotations(), Path.class);
final Optional<Path> methodPath = findAnnotation(method, Path.class);
this.findAnnotation(method.getDeclaringClass().getAnnotations(), Path.class);
final Optional<Path> methodPath = this.findAnnotation(method, Path.class);
String str = "";
if (classPath.isPresent()) {
str += classPath.get().value();
Expand All @@ -133,7 +132,7 @@ private String createPath(final Method method) {

private <T> Optional<T> findAnnotation(final Method method, final Class<T> findAnnotation) {
final Annotation[] methodAnnotations = method.getAnnotations();
return findAnnotation(methodAnnotations, findAnnotation);
return this.findAnnotation(methodAnnotations, findAnnotation);
}

@SuppressWarnings("unchecked")
Expand All @@ -148,7 +147,7 @@ private <T> Optional<T> findAnnotation(
}

private List<InvocationParam> createQueryParams(
final Parameter[] parameters, final Object[] args) {
final Parameter[] parameters, final Object... args) {
final List<InvocationParam> queryParams = new ArrayList<>();
if (parameters == null || args == null) {
return queryParams;
Expand All @@ -160,7 +159,7 @@ private List<InvocationParam> createQueryParams(
final Object arg = args[i];
final Parameter param = parameters[i];
final Optional<QueryParam> paramAnnotation =
findAnnotation(param.getAnnotations(), QueryParam.class);
this.findAnnotation(param.getAnnotations(), QueryParam.class);
if (paramAnnotation.isPresent()) {
final String name = paramAnnotation.get().value();
final InvocationParam invocationParam = new InvocationParam(name, arg);
Expand All @@ -170,7 +169,7 @@ private List<InvocationParam> createQueryParams(
return queryParams;
}

private Optional<Object> findPostObject(final Parameter[] parameters, final Object[] args) {
private Optional<Object> findPostObject(final Parameter[] parameters, final Object... args) {
if (parameters == null || args == null) {
return Optional.empty();
}
Expand All @@ -181,16 +180,16 @@ private Optional<Object> findPostObject(final Parameter[] parameters, final Obje
final Object arg = args[i];
final Parameter param = parameters[i];
if ( //
!findAnnotation(param.getAnnotations(), PathParam.class).isPresent() //
&& !findAnnotation(param.getAnnotations(), QueryParam.class).isPresent()) {
!this.findAnnotation(param.getAnnotations(), PathParam.class).isPresent() //
&& !this.findAnnotation(param.getAnnotations(), QueryParam.class).isPresent()) {
return Optional.ofNullable(arg);
}
}
return Optional.empty();
}

private List<InvocationParam> createPathParams(
final Parameter[] parameters, final Object[] args) {
final Parameter[] parameters, final Object... args) {
final List<InvocationParam> pathParams = new ArrayList<>();
if (parameters == null || args == null) {
return pathParams;
Expand All @@ -202,7 +201,7 @@ private List<InvocationParam> createPathParams(
final Object arg = args[i];
final Parameter param = parameters[i];
final Optional<PathParam> paramAnnotation =
findAnnotation(param.getAnnotations(), PathParam.class);
this.findAnnotation(param.getAnnotations(), PathParam.class);
if (paramAnnotation.isPresent()) {
final String name = paramAnnotation.get().value();
final InvocationParam invocationParam = new InvocationParam(name, arg);
Expand All @@ -212,10 +211,7 @@ private List<InvocationParam> createPathParams(
return pathParams;
}

private String substituteParams(
final String createPath,
final List<InvocationParam> queryParams,
final List<InvocationParam> pathParams) {
private String substituteParams(final String createPath, final List<InvocationParam> pathParams) {
String substituted = createPath;
for (final InvocationParam pathParam : pathParams) {
if (pathParam.getValue() == null) {
Expand Down

0 comments on commit 8b37318

Please sign in to comment.