Skip to content

Commit

Permalink
feat(java): add maven version resolver (#2871)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored Jul 1, 2024
1 parent 04c8295 commit e707443
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/custom-registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/cli/install-tool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
16 changes: 16 additions & 0 deletions src/cli/tools/java/maven.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<string | undefined> {
if (!isNonEmptyStringAndNotWhitespace(version) || version === 'latest') {
return await this.http.get(
`https://github.com/containerbase/${this.tool}-prebuild/releases/latest/download/version`,
);
}
return version;
}
}
1 change: 1 addition & 0 deletions test/java/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ FROM base as test-latest-version

RUN install-tool java-jre
RUN install-tool gradle
RUN install-tool maven


#--------------------------------------
Expand Down

0 comments on commit e707443

Please sign in to comment.