Skip to content

Commit 9f814fe

Browse files
Refactor build configuration and improve Dockerfile
1 parent e605f2b commit 9f814fe

File tree

9 files changed

+62
-46
lines changed

9 files changed

+62
-46
lines changed

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ ARG LIBWEBP_FILE="libwebp-$LIBWEBP_VERSION-linux-x86-64.tar.gz"
88
ARG LIBWEBP_URL="https://storage.googleapis.com/downloads.webmproject.org/releases/webp/$LIBWEBP_FILE"
99

1010
WORKDIR /app
11-
RUN apk --no-cache add binutils curl tar
12-
RUN curl -L --fail --retry 3 --retry-delay 5 "$LIBWEBP_URL" -O && \
13-
echo "$LIBWEBP_SHA256 $LIBWEBP_FILE" | sha256sum -c - && \
14-
tar -xzf "$LIBWEBP_FILE" --one-top-level=libwebp --strip-components=1 && \
15-
rm "$LIBWEBP_FILE"
11+
ADD --checksum=sha256:$LIBWEBP_SHA256 $LIBWEBP_URL $LIBWEBP_FILE
12+
RUN apk --no-cache --update add binutils tar
13+
RUN tar -xzf $LIBWEBP_FILE --one-top-level=libwebp --strip-components=1 && rm $LIBWEBP_FILE
1614

1715
COPY . .
1816
RUN --mount=type=cache,target=/root/.gradle ./gradlew jlink shadowJar
1917

20-
FROM alpine AS bot
18+
# bump: alpine /FROM alpine:([\d.]+)/ docker:alpine|^3
19+
# bump: alpine link "Release notes" https://alpinelinux.org/posts/Alpine-$LATEST-released.html
20+
FROM alpine:3.22.1 AS bot
2121

2222
# bump: ffmpeg /static-ffmpeg:([\d.]+)/ docker:mwader/static-ffmpeg|~7.0
2323
COPY --from=mwader/static-ffmpeg:7.0.2 /ffmpeg /usr/local/bin/

build.gradle

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import com.github.stickerifier.stickerify.JlinkJavaLauncher
22
import com.github.stickerifier.stickerify.JlinkTask
3+
import org.gradle.api.plugins.jvm.JvmTestSuite
4+
import org.gradle.buildconfiguration.tasks.UpdateDaemonJvm
35

46
plugins {
5-
alias(libs.plugins.shadow)
67
id 'application'
78
id 'java'
89
id 'jacoco'
10+
alias(libs.plugins.shadow)
911
}
1012

1113
repositories {
@@ -27,11 +29,6 @@ dependencies {
2729
implementation libs.telegram.bot.api
2830
implementation libs.tika
2931

30-
testRuntimeOnly libs.junit.platform
31-
testImplementation libs.hamcrest
32-
testImplementation libs.junit
33-
testImplementation libs.mockwebserver
34-
3532
constraints {
3633
implementation(libs.okio) {
3734
because 'CVE-2023-3635: Okio Signed to Unsigned Conversion Error vulnerability'
@@ -43,11 +40,14 @@ group = 'com.github.stickerifier'
4340
version = '1.0'
4441
description = 'Telegram bot to convert medias in the format required to be used as Telegram stickers'
4542

46-
java {
47-
toolchain {
48-
languageVersion = JavaLanguageVersion.of(24)
49-
vendor = JvmVendorSpec.AZUL
50-
}
43+
java.toolchain {
44+
languageVersion = JavaLanguageVersion.of(24)
45+
vendor = JvmVendorSpec.AZUL
46+
}
47+
48+
tasks.named('updateDaemonJvm', UpdateDaemonJvm) {
49+
languageVersion = JavaLanguageVersion.of(24)
50+
vendor = JvmVendorSpec.AZUL
5151
}
5252

5353
def jlink = tasks.register('jlink', JlinkTask) {
@@ -58,12 +58,28 @@ def jlink = tasks.register('jlink', JlinkTask) {
5858
description = 'Generates a minimal JRE for the project.'
5959
}
6060

61-
test {
62-
inputs.dir jlink.get().outputDirectory
63-
javaLauncher = new JlinkJavaLauncher(jlink.get())
64-
65-
useJUnitPlatform()
66-
finalizedBy jacocoTestReport
61+
testing {
62+
suites {
63+
named('test', JvmTestSuite) {
64+
useJUnitJupiter(libs.versions.junit)
65+
66+
dependencies {
67+
implementation libs.hamcrest
68+
implementation libs.mockwebserver
69+
}
70+
71+
targets {
72+
configureEach {
73+
testTask.configure { Test test ->
74+
test.inputs.dir jlink.get().outputDirectory
75+
test.javaLauncher = new JlinkJavaLauncher(jlink.get())
76+
77+
test.finalizedBy jacocoTestReport
78+
}
79+
}
80+
}
81+
}
82+
}
6783
}
6884

6985
jacocoTestReport {

buildSrc/src/main/java/com/github/stickerifier/stickerify/JlinkJavaLauncher.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@
77
import org.gradle.jvm.toolchain.JavaLauncher;
88
import org.jetbrains.annotations.NotNull;
99

10-
public record JlinkJavaLauncher(
11-
Provider<JavaInstallationMetadata> metadata,
12-
Provider<RegularFile> executablePath
13-
) implements JavaLauncher {
10+
public record JlinkJavaLauncher(Provider<JavaInstallationMetadata> metadata, Provider<RegularFile> executablePath) implements JavaLauncher {
1411
public JlinkJavaLauncher(JlinkTask task) {
15-
this(
16-
task.getJavaCompiler().map(JavaCompiler::getMetadata),
17-
task.getOutputDirectory().file("jre/bin/java")
18-
);
12+
this(task.getJavaCompiler().map(JavaCompiler::getMetadata), task.getOutputDirectory().file("jre/bin/java"));
1913
}
2014

2115
@Override

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
org.gradle.cache = true
2-
org.gradle.configuration-cache = true
1+
org.gradle.cache=true
2+
org.gradle.configuration-cache=true
33
org.gradle.jvmargs=-Dfile.encoding=UTF-8
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#This file is generated by updateDaemonJvm
2+
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/d898567da69cac7b9b75d8d74e577e7a/redirect
3+
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/902ef81bafffcd1670604d74b6c7a6b0/redirect
4+
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/d898567da69cac7b9b75d8d74e577e7a/redirect
5+
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/902ef81bafffcd1670604d74b6c7a6b0/redirect
6+
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/4175090548a4792cf1cef411becfba0f/redirect
7+
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/50df1a9c218487a6519e22a0d29e6215/redirect
8+
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/d898567da69cac7b9b75d8d74e577e7a/redirect
9+
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/902ef81bafffcd1670604d74b6c7a6b0/redirect
10+
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/f55af862790b0c395d3f70e23016df3d/redirect
11+
toolchainVendor=AZUL
12+
toolchainVersion=24

gradle/libs.versions.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
logback = "1.5.18"
33
scrimage = "4.3.3"
44
twelvemonkeys = "3.12.0"
5+
junit = "5.13.4"
56

67
[libraries]
78
batik = "org.apache.xmlgraphics:batik-transcoder:1.19"
@@ -10,8 +11,6 @@ hamcrest = "org.hamcrest:hamcrest-core:3.0"
1011
imageio-batik = { module = "com.twelvemonkeys.imageio:imageio-batik", version.ref = "twelvemonkeys" }
1112
imageio-psd = { module = "com.twelvemonkeys.imageio:imageio-psd", version.ref = "twelvemonkeys" }
1213
jave = "ws.schild:jave-core:3.5.0"
13-
junit = "org.junit.jupiter:junit-jupiter:5.13.4"
14-
junit-platform = "org.junit.platform:junit-platform-launcher:1.13.4"
1514
logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
1615
logback-core = { module = "ch.qos.logback:logback-core", version.ref = "logback" }
1716
mockwebserver = "com.squareup.okhttp3:mockwebserver3-junit5:5.1.0"

src/main/java/com/github/stickerifier/stickerify/logger/HighlightHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ static String retrieveMimeType(final String message) {
3737
static String replaceFirst(String message, String textToReplace, String replacement) {
3838
return message.replaceFirst(Pattern.quote(textToReplace), replacement);
3939
}
40+
41+
private HighlightHelper() {
42+
throw new UnsupportedOperationException();
43+
}
4044
}

src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,8 @@ private static boolean isFileSizeLowerThan(File file, long threshold) throws Fil
200200
*
201201
* @param file the file to read
202202
* @return the image, if supported by {@link ImageIO}
203-
* @throws FileOperationException if an error occurred processing passed-in file
204203
*/
205-
private static ImmutableImage toImage(File file) throws FileOperationException {
204+
private static ImmutableImage toImage(File file) {
206205
try {
207206
return ImmutableImage.loader().fromFile(file);
208207
} catch (IOException _) {

src/test/java/com/github/stickerifier/stickerify/media/MediaHelperTest.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
class MediaHelperTest {
3838

3939
@Test
40-
void resizeImage() throws Exception {
40+
void resizeRectangularImage() throws Exception {
4141
var jpgImage = loadResource("big.jpg");
4242
var result = MediaHelper.convert(jpgImage);
4343

@@ -60,14 +60,6 @@ private static String getExtension(File file) {
6060
return file.getName().substring(file.getName().lastIndexOf('.'));
6161
}
6262

63-
@Test
64-
void resizeRectangularImage() throws Exception {
65-
var jpgImage = loadResource("big.jpg");
66-
var result = MediaHelper.convert(jpgImage);
67-
68-
assertImageConsistency(result, 512, 341);
69-
}
70-
7163
@Test
7264
void resizeSmallImage() throws Exception {
7365
var pngImage = loadResource("small_image.png");

0 commit comments

Comments
 (0)