From e707443edd3e4a7f0f2e9e1d15e0ecadaf8000e0 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 1 Jul 2024 12:04:10 +0200 Subject: [PATCH] feat(java): add maven version resolver (#2871) --- docs/custom-registries.md | 5 +++-- src/cli/install-tool/index.ts | 3 ++- src/cli/tools/java/maven.ts | 16 ++++++++++++++++ test/java/Dockerfile | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/custom-registries.md b/docs/custom-registries.md index 2bd0dddc4..9ed49c1f8 100644 --- a/docs/custom-registries.md +++ b/docs/custom-registries.md @@ -278,8 +278,9 @@ The first url is preferred and the second is used as fallback for older versions Samples: ```txt -https://github.com/containerbase/maven-prebuild/releases/3.0.4/maven-3.0.4.tar.xz.sha512 -https://github.com/containerbase/maven-prebuild/releases/3.0.4/maven-3.0.4.tar.xz +https://github.com/containerbase/maven-prebuild/releases/download/3.0.4/maven-3.0.4.tar.xz.sha512 +https://github.com/containerbase/maven-prebuild/releases/download/3.0.4/maven-3.0.4.tar.xz +https://github.com/containerbase/maven-prebuild/releases/latest/download/version https://archive.apache.org/dist/maven/maven-3/3.0.4/binaries/apache-maven-3.0.4-bin.tar.gz https://archive.apache.org/dist/maven/maven-3/3.0.4/binaries/apache-maven-3.0.4-bin.tar.gz.sha1 https://archive.apache.org/dist/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar diff --git a/src/cli/install-tool/index.ts b/src/cli/install-tool/index.ts index c345d65e2..e1cf29502 100644 --- a/src/cli/install-tool/index.ts +++ b/src/cli/install-tool/index.ts @@ -17,7 +17,7 @@ import { GradleVersionResolver, InstallGradleService, } from '../tools/java/gradle'; -import { InstallMavenService } from '../tools/java/maven'; +import { InstallMavenService, MavenVersionResolver } from '../tools/java/maven'; import { JavaJdkVersionResolver, JavaJreVersionResolver, @@ -97,6 +97,7 @@ function prepareResolveContainer(): Container { container.bind(TOOL_VERSION_RESOLVER).to(JavaVersionResolver); container.bind(TOOL_VERSION_RESOLVER).to(JavaJreVersionResolver); container.bind(TOOL_VERSION_RESOLVER).to(JavaJdkVersionResolver); + container.bind(TOOL_VERSION_RESOLVER).to(MavenVersionResolver); container.bind(TOOL_VERSION_RESOLVER).to(NodeVersionResolver); container.bind(TOOL_VERSION_RESOLVER).to(YarnVersionResolver); diff --git a/src/cli/tools/java/maven.ts b/src/cli/tools/java/maven.ts index 503efc477..2d23880e0 100644 --- a/src/cli/tools/java/maven.ts +++ b/src/cli/tools/java/maven.ts @@ -1,8 +1,10 @@ import fs from 'node:fs/promises'; import { join } from 'node:path'; +import { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is'; import { execa } from 'execa'; import { inject, injectable } from 'inversify'; import { InstallToolBaseService } from '../../install-tool/install-tool-base.service'; +import { ToolVersionResolver } from '../../install-tool/tool-version-resolver'; import { CompressionService, EnvService, @@ -108,3 +110,17 @@ export class InstallMavenService extends InstallToolBaseService { return (await fs.readFile(checksumFile, 'utf-8')).split(' ')[0]?.trim(); } } + +@injectable() +export class MavenVersionResolver extends ToolVersionResolver { + readonly tool = 'maven'; + + async resolve(version: string | undefined): Promise { + if (!isNonEmptyStringAndNotWhitespace(version) || version === 'latest') { + return await this.http.get( + `https://github.com/containerbase/${this.tool}-prebuild/releases/latest/download/version`, + ); + } + return version; + } +} diff --git a/test/java/Dockerfile b/test/java/Dockerfile index e0017bb07..036f0fca7 100644 --- a/test/java/Dockerfile +++ b/test/java/Dockerfile @@ -205,6 +205,7 @@ FROM base as test-latest-version RUN install-tool java-jre RUN install-tool gradle +RUN install-tool maven #--------------------------------------