diff --git a/sdk/mx.sdk/suite.py b/sdk/mx.sdk/suite.py index c52c82e31ef4..7cc0a5cddff7 100644 --- a/sdk/mx.sdk/suite.py +++ b/sdk/mx.sdk/suite.py @@ -906,6 +906,15 @@ class UniversalDetector { }, }, + "MAVEN_DOWNLOADER_VERSION": { + "type": "dir", + "platformDependent": False, + "layout": { + "META-INF/graalvm/org.graalvm.maven.downloader/version": "dependency:sdk:VERSION/version", + }, + "description": "Maven downloader version.", + "maven": False, + }, "MAVEN_DOWNLOADER": { "moduleInfo" : { "name" : "org.graalvm.maven.downloader", @@ -916,6 +925,7 @@ class UniversalDetector { "mainClass": "org.graalvm.maven.downloader.Main", "dependencies": [ "org.graalvm.maven.downloader", + "MAVEN_DOWNLOADER_VERSION", ], "distDependencies": [ "sdk:NATIVEIMAGE", diff --git a/sdk/src/org.graalvm.maven.downloader/src/org/graalvm/maven/downloader/Main.java b/sdk/src/org.graalvm.maven.downloader/src/org/graalvm/maven/downloader/Main.java index 21a287c4162d..8c31219d0e75 100644 --- a/sdk/src/org.graalvm.maven.downloader/src/org/graalvm/maven/downloader/Main.java +++ b/sdk/src/org.graalvm.maven.downloader/src/org/graalvm/maven/downloader/Main.java @@ -87,7 +87,7 @@ static Arguments parseArguments(String... args) { String version = null; for (int i = 0; i < args.length; i++) { - if ('-' == args[i].charAt(0)) { + if (args[i].startsWith("-")) { if (args[i].length() < 2) { exitErr("Invalid argument: " + args[i]); } diff --git a/sdk/src/org.graalvm.maven.downloader/src/org/graalvm/maven/downloader/OptionProperties.java b/sdk/src/org.graalvm.maven.downloader/src/org/graalvm/maven/downloader/OptionProperties.java index 99fbe3b73c9d..426b68886886 100644 --- a/sdk/src/org.graalvm.maven.downloader/src/org/graalvm/maven/downloader/OptionProperties.java +++ b/sdk/src/org.graalvm.maven.downloader/src/org/graalvm/maven/downloader/OptionProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -40,13 +40,21 @@ */ package org.graalvm.maven.downloader; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import org.graalvm.nativeimage.ImageInfo; import org.graalvm.nativeimage.ProcessProperties; class OptionProperties { - static final String RELATIVE_OUTPUT_DIR = System.getProperty("org.graalvm.maven.downloader.relative_output_dir"); + static final String DEFAULT_RELATIVE_OUTPUT_DIR = "modules"; + static final String RELATIVE_OUTPUT_DIR = System.getProperty("org.graalvm.maven.downloader.relative_output_dir", DEFAULT_RELATIVE_OUTPUT_DIR); static final String DEFAULT_VERSION = System.getProperty("org.graalvm.maven.downloader.default_version"); static final String VERSION_PROP = "org.graalvm.maven.downloader.version"; static final String DEFAULT_MAVEN_REPO = "https://repo1.maven.org/maven2/"; @@ -72,6 +80,16 @@ public static String getDefaultVersion() { if (DEFAULT_VERSION != null) { return DEFAULT_VERSION; } else { + InputStream in = OptionProperties.class.getResourceAsStream("/META-INF/graalvm/org.graalvm.maven.downloader/version"); + if (in != null) { + try (BufferedReader r = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) { + String version = r.readLine(); + if (version != null) { + return version; + } + } catch (IOException ioe) { + } + } return "not specified"; } } else { @@ -89,12 +107,27 @@ public static String getExeName() { } public static String getDefaultOutputDir() { - if (RELATIVE_OUTPUT_DIR != null) { - if (ImageInfo.inImageRuntimeCode()) { - String progName = ProcessProperties.getExecutableName(); - return Paths.get(progName).resolve("..").resolve(RELATIVE_OUTPUT_DIR).normalize().toString(); + if (ImageInfo.inImageRuntimeCode()) { + String progName = ProcessProperties.getExecutableName(); + if (progName != null) { + // $STANDALONE_HOME/bin//../../modules = $STANDALONE_HOME/modules + Path standaloneHome = Paths.get(progName).resolve("..").resolve(".."); + return standaloneHome.resolve(RELATIVE_OUTPUT_DIR).normalize().toString(); + } + } else { + String javaHomeProperty = System.getProperty("java.home"); + if (javaHomeProperty != null) { + Path javaHome = Paths.get(javaHomeProperty); + if (Files.isDirectory(javaHome) && Files.exists(javaHome.resolve("lib").resolve("modules"))) { + // Resolve standalone home relative to java.home. + Path standaloneHome = javaHome.resolve(".."); + Path modules = standaloneHome.resolve(RELATIVE_OUTPUT_DIR).normalize(); + if (Files.isDirectory(modules)) { + return modules.toString(); + } + } } } - return "maven downloader output"; + return DEFAULT_RELATIVE_OUTPUT_DIR; } } diff --git a/vm/mx.vm/suite.py b/vm/mx.vm/suite.py index 2d01e01b18c8..d3b5fe677f31 100644 --- a/vm/mx.vm/suite.py +++ b/vm/mx.vm/suite.py @@ -33,7 +33,7 @@ "name": "graal-nodejs", "subdir": True, "dynamic": True, - "version": "2353190673d09a0481b97e1d9901b14943a5bead", + "version": "a63c018c399790b8dcd04991527012e941a67244", "urls" : [ {"url" : "https://github.com/graalvm/graaljs.git", "kind" : "git"}, ] @@ -42,7 +42,7 @@ "name": "graal-js", "subdir": True, "dynamic": True, - "version": "2353190673d09a0481b97e1d9901b14943a5bead", + "version": "a63c018c399790b8dcd04991527012e941a67244", "urls": [ {"url": "https://github.com/graalvm/graaljs.git", "kind" : "git"}, ]