Skip to content

Commit

Permalink
[GR-54790] Infer default maven artifact version and output dir.
Browse files Browse the repository at this point in the history
PullRequest: graal/18249
  • Loading branch information
woess committed Jul 27, 2024
2 parents 27c90af + 05dfcf0 commit 3b71314
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
10 changes: 10 additions & 0 deletions sdk/mx.sdk/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -916,6 +925,7 @@ class UniversalDetector {
"mainClass": "org.graalvm.maven.downloader.Main",
"dependencies": [
"org.graalvm.maven.downloader",
"MAVEN_DOWNLOADER_VERSION",
],
"distDependencies": [
"sdk:NATIVEIMAGE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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/";
Expand All @@ -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 {
Expand All @@ -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/<exe>/../../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;
}
}
4 changes: 2 additions & 2 deletions vm/mx.vm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
]
Expand All @@ -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"},
]
Expand Down

0 comments on commit 3b71314

Please sign in to comment.