-
Notifications
You must be signed in to change notification settings - Fork 26
feat: JVM release file parsing #723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { ExtractedLayers } from "../../extractor/types"; | ||
| import { BaseRuntime } from "../../facts"; | ||
| import { getJavaRuntimeReleaseContent } from "../../inputs/base-runtimes/static"; | ||
| import { parseJavaRuntimeRelease } from "./parser"; | ||
|
|
||
| export function detectJavaRuntime( | ||
| extractedLayers: ExtractedLayers, | ||
| ): BaseRuntime | null { | ||
| const releaseContent = getJavaRuntimeReleaseContent(extractedLayers); | ||
| return releaseContent ? parseJavaRuntimeRelease(releaseContent) : null; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { BaseRuntime } from "../../facts"; | ||
|
|
||
| const VALID_VERSION_PATTERN = | ||
| /^(?!.*\.\.)[0-9]+(?:[._+a-zA-Z0-9-]*[a-zA-Z0-9])?$/; | ||
|
|
||
| const regex = /^\s*JAVA_VERSION\s*=\s*(?:(["'])(.*?)\1|([^#\r\n]+))/gm; | ||
|
|
||
| function isValidJavaVersion(version: string): boolean { | ||
| if (!version || version.length === 0) { | ||
| return false; | ||
| } | ||
| return VALID_VERSION_PATTERN.test(version); | ||
| } | ||
|
|
||
| export function parseJavaRuntimeRelease(content: string): BaseRuntime | null { | ||
| if (!content || content.trim().length === 0) { | ||
| return null; | ||
| } | ||
| try { | ||
| const matches = [...content.matchAll(regex)]; | ||
|
|
||
| if (matches.length !== 1) { | ||
| return null; | ||
| } | ||
| const version = (matches[0][2] || matches[0][3] || "").trim(); | ||
|
|
||
| if (!isValidJavaVersion(version)) { | ||
| return null; | ||
| } | ||
| return { type: "java", version }; | ||
| } catch (error) { | ||
| return null; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,3 +152,13 @@ export interface PluginWarningsFact { | |
| parameterChecks?: string[]; | ||
| }; | ||
| } | ||
|
|
||
| export interface BaseRuntime { | ||
| type: string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the only current value is "java" would narrowing this to a literal type (or a discriminated union) provides compile-time safety: export interface BaseRuntime {
type: "java";
version: string;
} |
||
| version: string; | ||
| } | ||
|
|
||
| export interface BaseRuntimesFact { | ||
| type: "baseRuntimes"; | ||
| data: BaseRuntime[]; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { normalize as normalizePath } from "path"; | ||
| import { getContentAsString } from "../../extractor"; | ||
| import { ExtractAction, ExtractedLayers } from "../../extractor/types"; | ||
| import { streamToString } from "../../stream-utils"; | ||
|
|
||
| export const getJavaRuntimeReleaseAction: ExtractAction = { | ||
| actionName: "java-runtime-release", | ||
| filePathMatches: (filePath) => | ||
| filePath === normalizePath("/opt/java/openjdk/release"), | ||
kateeselius marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude suggests that: /opt/java/openjdk/release is the Eclipse Adoptium/Temurin convention. Many widely-used JVM base images use different paths:
Should we at least expand to a few common other release file locations: |
||
| callback: streamToString, | ||
| }; | ||
|
|
||
| export function getJavaRuntimeReleaseContent( | ||
| extractedLayers: ExtractedLayers, | ||
| ): string { | ||
| const content = getContentAsString( | ||
| extractedLayers, | ||
| getJavaRuntimeReleaseAction, | ||
| ); | ||
| return content || ""; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.