Skip to content

Commit c13cb81

Browse files
committed
chore: simplify
1 parent 3f3d453 commit c13cb81

File tree

11 files changed

+54
-128
lines changed

11 files changed

+54
-128
lines changed

.github/dependabot.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "daily"
7+
open-pull-requests-limit: 3
78
- package-ecosystem: "github-actions"
89
directory: "/"
910
schedule:
1011
interval: "daily"
12+
open-pull-requests-limit: 2

.github/workflows/ci.yml

-12
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,6 @@ jobs:
6464
run: |
6565
bash <(curl -s https://codecov.io/bash)
6666
67-
automerge:
68-
needs:
69-
- test
70-
runs-on: ubuntu-latest
71-
permissions:
72-
pull-requests: write
73-
contents: write
74-
steps:
75-
- uses: fastify/github-action-merge-dependabot@v3.6.0
76-
with:
77-
github-token: ${{ secrets.GITHUB_TOKEN }}
78-
7967
release:
8068
needs:
8169
- test

.github/workflows/codeql-analysis.yml

-42
This file was deleted.

gradle/wrapper/gradle-wrapper.jar

60.2 KB
Binary file not shown.
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-all.zip
4+
networkTimeout=10000
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists

gradlew

+14-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# Darwin, MinGW, and NonStop.
5656
#
5757
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
58+
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5959
# within the Gradle project.
6060
#
6161
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,10 +80,10 @@ do
8080
esac
8181
done
8282

83-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84-
85-
APP_NAME="Gradle"
83+
# This is normally unused
84+
# shellcheck disable=SC2034
8685
APP_BASE_NAME=${0##*/}
86+
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
8787

8888
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
8989
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
@@ -143,12 +143,16 @@ fi
143143
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144144
case $MAX_FD in #(
145145
max*)
146+
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147+
# shellcheck disable=SC3045
146148
MAX_FD=$( ulimit -H -n ) ||
147149
warn "Could not query maximum file descriptor limit"
148150
esac
149151
case $MAX_FD in #(
150152
'' | soft) :;; #(
151153
*)
154+
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155+
# shellcheck disable=SC3045
152156
ulimit -n "$MAX_FD" ||
153157
warn "Could not set maximum file descriptor limit to $MAX_FD"
154158
esac
@@ -205,6 +209,12 @@ set -- \
205209
org.gradle.wrapper.GradleWrapperMain \
206210
"$@"
207211

212+
# Stop when "xargs" is not available.
213+
if ! command -v xargs >/dev/null 2>&1
214+
then
215+
die "xargs is not available"
216+
fi
217+
208218
# Use "xargs" to parse quoted args.
209219
#
210220
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

gradlew.bat

+9-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@rem limitations under the License.
1515
@rem
1616

17-
@if "%DEBUG%" == "" @echo off
17+
@if "%DEBUG%"=="" @echo off
1818
@rem ##########################################################################
1919
@rem
2020
@rem Gradle startup script for Windows
@@ -25,7 +25,8 @@
2525
if "%OS%"=="Windows_NT" setlocal
2626

2727
set DIRNAME=%~dp0
28-
if "%DIRNAME%" == "" set DIRNAME=.
28+
if "%DIRNAME%"=="" set DIRNAME=.
29+
@rem This is normally unused
2930
set APP_BASE_NAME=%~n0
3031
set APP_HOME=%DIRNAME%
3132

@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
4041

4142
set JAVA_EXE=java.exe
4243
%JAVA_EXE% -version >NUL 2>&1
43-
if "%ERRORLEVEL%" == "0" goto execute
44+
if %ERRORLEVEL% equ 0 goto execute
4445

4546
echo.
4647
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
7576

7677
:end
7778
@rem End local scope for the variables with windows NT shell
78-
if "%ERRORLEVEL%"=="0" goto mainEnd
79+
if %ERRORLEVEL% equ 0 goto mainEnd
7980

8081
:fail
8182
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
8283
rem the _cmd.exe /c_ return code!
83-
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84-
exit /b 1
84+
set EXIT_CODE=%ERRORLEVEL%
85+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
86+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87+
exit /b %EXIT_CODE%
8588

8689
:mainEnd
8790
if "%OS%"=="Windows_NT" endlocal

puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/DefaultResourceProvider.java

+16-50
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@ class DefaultResourceProvider implements Provider {
1818
public Object provide(final Args args) {
1919
requireNonNull(args);
2020

21-
final String resourceName = args
22-
.getResourceFilename()
23-
.orElse("");
21+
final String resourceName = args.getResourceFilename().orElse("");
2422
final String filename;
2523

2624
if (resourceName.isEmpty()) {
27-
final Res res = args
28-
.getTargetElement()
29-
.getAnnotation(Res.class);
25+
final Res res = args.getTargetElement().getAnnotation(Res.class);
3026
filename = res.value();
3127
} else {
3228
filename = resourceName;
@@ -38,73 +34,43 @@ public Object provide(final Args args) {
3834
final Class<?> type = args.getTargetElementClass();
3935
final Unmarshaller<?> unmarshaller;
4036

41-
final Optional<Use> optUse =
42-
lookForAnnotation(Use.class, args.getTargetElement(),
43-
args.getTestClass());
37+
final Optional<Use> optUse = lookForAnnotation(Use.class, args.getTargetElement(), args.getTestClass());
4438

4539
if (optUse.isPresent()) {
4640
final Use use = optUse.get();
4741

4842
try {
49-
unmarshaller = use
50-
.value()
51-
.getDeclaredConstructor()
52-
.newInstance();
43+
unmarshaller = use.value().getDeclaredConstructor().newInstance();
5344
} catch (final Exception ex) {
54-
throw new InvalidMarshallerClassException(use
55-
.value()
56-
.getSimpleName(), ex);
45+
throw new InvalidMarshallerClassException(use.value().getSimpleName(), ex);
5746
}
5847
} else {
5948
if (type.isAssignableFrom(String.class)) {
60-
unmarshaller = Puma4j
61-
.instance()
62-
.textMarshaller();
49+
unmarshaller = Puma4j.instance().textMarshaller();
6350
} else if (type.isAssignableFrom(byte[].class) || type.isAssignableFrom(Byte[].class)) {
64-
unmarshaller = Puma4j
65-
.instance()
66-
.binaryMarshaller();
51+
unmarshaller = Puma4j.instance().binaryMarshaller();
6752
} else if (type.isAssignableFrom(Properties.class)) {
68-
unmarshaller = Puma4j
69-
.instance()
70-
.propertiesMarshaller();
53+
unmarshaller = Puma4j.instance().propertiesMarshaller();
7154
} else {
7255
if (hasExtension) {
73-
unmarshaller =
74-
Puma4j
75-
.instance()
76-
.getMarshallerByExtension(extension)
77-
.orElseThrow(() -> newExtNotSupportedException(args, filename, extension));
56+
unmarshaller = Puma4j.instance()
57+
.getMarshallerByExtension(extension)
58+
.orElseThrow(() -> newExtNotSupportedException(args, filename, extension));
7859
} else {
7960
throw new NoMarshallerException(
80-
buildErrorMessage(
81-
"Unable to find a properly marshaller for specified resource.",
82-
args, filename));
61+
buildErrorMessage("Unable to find a properly marshaller for specified resource.", args, filename));
8362
}
8463
}
8564
}
8665

87-
final String path = Paths
88-
.get(args
89-
.getContext()
90-
.getBasePath(), filename)
91-
.toString();
66+
final String path = Paths.get(args.getContext().getBasePath(), filename).toString();
9267

93-
try (final InputStream input = args
94-
.getTestClass()
95-
.getResourceAsStream(path)) {
68+
try (final InputStream input = args.getTestClass().getResourceAsStream(path)) {
9669
return unmarshaller.unmarshal(
97-
new Unmarshaller.Args(
98-
input,
99-
args.getTargetElementType(),
100-
args.getTestClass(),
101-
args.getTargetElement()));
70+
new Unmarshaller.Args(input, args.getTargetElementType(), args.getTestClass(), args.getTargetElement()));
10271
} catch (final Exception ex) {
10372
throw new UnmarshallingException(
104-
buildErrorMessage(
105-
"Error unmarshalling resource to specified type.",
106-
args,
107-
filename), ex);
73+
buildErrorMessage("Error unmarshalling resource to specified type.", args, filename), ex);
10874
}
10975
}
11076
}

puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/BinaryUnmarshaller.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ public class BinaryUnmarshaller implements Unmarshaller<byte[]> {
1212
public byte[] unmarshal(final Args args) throws IOException {
1313
requireNonNull(args);
1414

15-
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
16-
int reading;
17-
final byte[] data = new byte[args
18-
.getInput()
19-
.available()];
15+
final int size = args.getInput().available();
16+
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(size);
17+
final byte[] data = new byte[size];
2018

21-
while ((reading = args
22-
.getInput()
23-
.read(data, 0, data.length)) != -1) {
19+
int reading;
20+
while ((reading = args.getInput().read(data, 0, data.length)) != -1) {
2421
buffer.write(data, 0, reading);
2522
}
2623

puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/PropertiesUnmarshaller.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import io.github.vitorsalgado.puma4j.core.Unmarshaller;
66
import java.io.IOException;
7+
import java.io.InputStream;
78
import java.util.Properties;
89

910
public class PropertiesUnmarshaller implements Unmarshaller<Properties> {
@@ -12,8 +13,10 @@ public class PropertiesUnmarshaller implements Unmarshaller<Properties> {
1213
public Properties unmarshal(final Args args) throws IOException {
1314
requireNonNull(args);
1415

15-
final Properties properties = new Properties();
16-
properties.load(args.getInput());
16+
final InputStream in = args.getInput();
17+
final Properties properties = new Properties(in.available());
18+
19+
properties.load(in);
1720

1821
return properties;
1922
}

puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/YamlUnmarshaller.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ public Object unmarshal(final Args args) throws IOException {
1919
requireNonNull(args);
2020

2121
return objectMapper.readValue(
22-
args.getInput(), objectMapper
23-
.getTypeFactory()
24-
.constructType(args.getType()));
22+
args.getInput(), objectMapper.getTypeFactory().constructType(args.getType()));
2523
}
2624
}

0 commit comments

Comments
 (0)