Skip to content

Commit 0cc70d9

Browse files
authored
Merge pull request #266 from graalvm/vj-ag/release-overhaul-no-questions-asked
Final PR for the metadata repo
2 parents 3ae7b3f + 9462ee2 commit 0cc70d9

File tree

23 files changed

+677
-134
lines changed

23 files changed

+677
-134
lines changed

common/graalvm-reachability-metadata/src/main/java/org/graalvm/reachability/internal/FileSystemRepository.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,20 @@ public FileSystemRepository(Path rootDirectory, Logger logger) {
7373
this.rootDirectory = rootDirectory;
7474
}
7575

76-
public static boolean isSupportedArchiveFormat(String path) {
76+
private static final String[] SUPPORTED_FORMATS = {".zip", ".tar.gz", ".tar.bz2"};
77+
78+
public static String getArchiveFormat(String path) {
7779
String normalizedPath = path.toLowerCase();
78-
return normalizedPath.endsWith(".zip") || normalizedPath.endsWith(".tar.gz") || normalizedPath.endsWith(".tar.bz2");
80+
for (String format : SUPPORTED_FORMATS) {
81+
if (normalizedPath.endsWith(format)) {
82+
return format;
83+
}
84+
}
85+
return null;
86+
}
87+
88+
public static boolean isSupportedArchiveFormat(String path) {
89+
return getArchiveFormat(path) != null;
7990
}
8091

8192
@Override

common/utils/src/main/java/org/graalvm/buildtools/utils/FileUtils.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@
4242
package org.graalvm.buildtools.utils;
4343

4444
import java.io.IOException;
45+
import java.math.BigInteger;
4546
import java.net.HttpURLConnection;
47+
import java.net.URI;
4648
import java.net.URL;
49+
import java.nio.charset.StandardCharsets;
4750
import java.nio.file.Files;
4851
import java.nio.file.Path;
4952
import java.nio.file.StandardCopyOption;
53+
import java.security.MessageDigest;
54+
import java.security.NoSuchAlgorithmException;
5055
import java.util.Optional;
5156
import java.util.function.Consumer;
5257
import java.util.zip.ZipEntry;
@@ -140,4 +145,19 @@ private static Optional<Path> sanitizePath(ZipEntry entry, Path destination) {
140145
return Optional.empty();
141146
}
142147
}
148+
149+
public static String hashFor(URI uri) {
150+
try {
151+
MessageDigest md = MessageDigest.getInstance("SHA-1");
152+
byte[] messageDigest = md.digest(md.digest(uri.toString().getBytes(StandardCharsets.UTF_8)));
153+
BigInteger no = new BigInteger(1, messageDigest);
154+
StringBuilder digest = new StringBuilder(no.toString(16));
155+
while (digest.length() < 32) {
156+
digest.insert(0, "0");
157+
}
158+
return digest.toString();
159+
} catch (NoSuchAlgorithmException e) {
160+
throw new UnsupportedOperationException(e);
161+
}
162+
}
143163
}

common/utils/src/main/java/org/graalvm/buildtools/utils/SharedConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,6 @@ public interface SharedConstants {
7575
String AGENT_SESSION_SUBDIR = "session-{pid}-{datetime}";
7676
String AGENT_OUTPUT_DIRECTORY_MARKER = "{output_dir}";
7777
String AGENT_OUTPUT_DIRECTORY_OPTION = "config-output-dir=";
78-
String METADATA_REPO_URL_TEMPLATE = "https://github.com/graalvm/graalvm-reachability-metadata/releases/download/%1$s/graalvm-reachability-metadata-%1$s.zip";
78+
String METADATA_REPO_URL_TEMPLATE = "https://github.com/oracle/graalvm-reachability-metadata/releases/download/%1$s/graalvm-reachability-metadata-%1$s.zip";
79+
String METADATA_REPO_DEFAULT_VERSION = "0.1.0";
7980
}

common/utils/src/test/java/org/graalvm/buildtools/utils/FileUtilsTest.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
141
package org.graalvm.buildtools.utils;
242

343
import org.junit.jupiter.api.DisplayName;
@@ -17,7 +57,9 @@
1757
import java.util.Optional;
1858
import java.util.stream.Stream;
1959

20-
import static org.junit.jupiter.api.Assertions.*;
60+
import static org.junit.jupiter.api.Assertions.assertEquals;
61+
import static org.junit.jupiter.api.Assertions.assertFalse;
62+
import static org.junit.jupiter.api.Assertions.assertTrue;
2163

2264
class FileUtilsTest {
2365

@@ -97,8 +139,10 @@ void testExtract(@TempDir Path tempDir) throws IOException {
97139
assertTrue(Files.isDirectory(tempDir.resolve("org.graalvm.internal/library-with-reflection/1")));
98140

99141
assertTrue(Files.exists(tempDir.resolve("org.graalvm.internal/library-with-reflection/1/reflect-config.json")));
100-
assertEquals("[ { \"name\": \"org.graalvm.internal.reflect.Message\", \"allDeclaredFields\": true, \"allDeclaredMethods\": true }]", String.join("", Files.readAllLines(tempDir.resolve("org.graalvm.internal/library-with-reflection/1/reflect-config.json"))));
142+
assertEquals("[ { \"name\": \"org.graalvm.internal.reflect.Message\", \"allDeclaredFields\": true, \"allDeclaredMethods\": true }]",
143+
String.join("", Files.readAllLines(tempDir.resolve("org.graalvm.internal/library-with-reflection/1/reflect-config.json"))));
101144
}
145+
102146
@Test
103147
@DisplayName("It is protected against ZIP slip attacks")
104148
void testZipSlip(@TempDir Path tempDir) throws IOException {

docs/src/docs/asciidoc/gradle-plugin.adoc

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -228,37 +228,6 @@ Currently, this feature requires the execution of the tests in the classic "JVM"
228228

229229
NOTE: This plugin requires JUnit Platform 1.8 or higher.
230230

231-
[[mockito-bytebuddy-support]]
232-
=== Mockito / Byte Buddy support
233-
234-
Mockito is supported starting from version 4.5.0 (ByteBuddy >= 1.12.9) with GraalVM >= 22.1.
235-
However, you need to add the following configuration to make it work with GraalVM 22.1:
236-
237-
.Enabling Mockito / Byte Buddy support on GraalVM 22.1
238-
[source,groovy,role="multi-language-sample"]
239-
----
240-
graalvmNative {
241-
binaries {
242-
test {
243-
buildArgs.add("--rerun-class-initialization-at-runtime=net.bytebuddy.ClassFileVersion,net.bytebuddy.utility.dispatcher.JavaDispatcher,net.bytebuddy.utility.Invoker$Dispatcher")
244-
buildArgs.add("--initialize-at-build-time=net.bytebuddy.description.method.MethodDescription$InDefinedShape$AbstractBase$ForLoadedExecutable,net.bytebuddy.description.type.TypeDescription$AbstractBase,net.bytebuddy.description.type.TypeDescription$ForLoadedType,net.bytebuddy.description.method.MethodDescription$ForLoadedMethod,net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic,net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$1,net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$2,net.bytebuddy.implementation.bind.annotation.Super$Instantiation$2")
245-
}
246-
}
247-
}
248-
----
249-
250-
[source,kotlin,role="multi-language-sample"]
251-
----
252-
graalvmNative {
253-
binaries {
254-
named("test") {
255-
buildArgs.add("--rerun-class-initialization-at-runtime=net.bytebuddy.ClassFileVersion,net.bytebuddy.utility.dispatcher.JavaDispatcher,net.bytebuddy.utility.Invoker$Dispatcher")
256-
buildArgs.add("--initialize-at-build-time=net.bytebuddy.description.method.MethodDescription$InDefinedShape$AbstractBase$ForLoadedExecutable,net.bytebuddy.description.type.TypeDescription$AbstractBase,net.bytebuddy.description.type.TypeDescription$ForLoadedType,net.bytebuddy.description.method.MethodDescription$ForLoadedMethod,net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic,net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$1,net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$2,net.bytebuddy.implementation.bind.annotation.Super$Instantiation$2")
257-
}
258-
}
259-
}
260-
----
261-
262231
[[testing-support-disabling]]
263232
=== Disabling testing support
264233

@@ -358,8 +327,8 @@ See <<configuration-options>> for the full list of available options.
358327
[[metadata-support]]
359328
== GraalVM Reachability Metadata Support
360329

361-
Since release 0.9.11, the plugin adds experimental support for the https://github.com/graalvm/graalvm-reachability-metadata/[GraalVM reachability metadata repository].
362-
This repository provides GraalVM configuration for libraries which do not officially support GraalVM native.
330+
Since release 0.9.11, the plugin adds experimental support for the https://github.com/oracle/graalvm-reachability-metadata/[GraalVM reachability metadata repository].
331+
This repository provides https://www.graalvm.org/22.2/reference-manual/native-image/ReachabilityMetadata/[reachability metadata] for libraries that do not support GraalVM Native Image.
363332

364333
=== Enabling the metadata repository
365334

docs/src/docs/asciidoc/maven-plugin.adoc

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -349,23 +349,6 @@ with an error similar to the following when attempting to run tests in a native
349349
[ERROR] Test configuration file wasn't found. Make sure that test execution wasn't skipped.
350350
----
351351

352-
[[mockito-bytebuddy-support]]
353-
=== Mockito / Byte Buddy support
354-
355-
Mockito is supported starting from version 4.5.0 (ByteBuddy >= 1.12.9) with GraalVM >= 22.1.
356-
However, you need to add the following configuration to make it work with GraalVM 22.1:
357-
358-
.Enabling Mockito / Byte Buddy support on GraalVM 22.1
359-
[source,xml]
360-
----
361-
<configuration>
362-
<buildArgs>
363-
<arg>--rerun-class-initialization-at-runtime=net.bytebuddy.ClassFileVersion,net.bytebuddy.utility.dispatcher.JavaDispatcher,net.bytebuddy.utility.Invoker$Dispatcher</arg>
364-
<arg>--initialize-at-build-time=net.bytebuddy.description.method.MethodDescription$InDefinedShape$AbstractBase$ForLoadedExecutable,net.bytebuddy.description.type.TypeDescription$AbstractBase,net.bytebuddy.description.type.TypeDescription$ForLoadedType,net.bytebuddy.description.method.MethodDescription$ForLoadedMethod,net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic,net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$1,net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$2,net.bytebuddy.implementation.bind.annotation.Super$Instantiation$2 </arg>
365-
</buildArgs>
366-
</configuration>
367-
----
368-
369352
[[testing-support-disabling]]
370353
=== Disabling testing support
371354

@@ -573,9 +556,6 @@ command-line argument to Maven as follows. See the documentation for
573556
mvn -Pnative -Dagent=true -DagentOptions=periodic-config test
574557
```
575558

576-
WARNING: If the agent is enabled, the `--allow-incomplete-classpath` option is
577-
automatically added to your native build options.
578-
579559
[[agent-support-running-application]]
580560
=== Running your application with the agent
581561

@@ -609,27 +589,21 @@ with those configuration files, you then need to execute the following command:
609589
mvn -Pnative -Dagent=true -DskipTests package exec:exec@native
610590
```
611591

612-
WARNING: If the agent is enabled, the `--allow-incomplete-classpath` option is
613-
automatically added to your native build options.
614-
615592
[[metadata-support]]
616593
== GraalVM Reachability Metadata Support
617594

618-
Since release 0.9.12, the plugin adds experimental support for the https://github.com/graalvm/graalvm-reachability-metadata/[GraalVM reachability metadata repository].
619-
This repository provides GraalVM metadata for libraries which do not officially support GraalVM native.
620-
621-
A metadata repository consists of configuration files for GraalVM.
595+
Since release 0.9.12, the plugin adds support for the https://github.com/oracle/graalvm-reachability-metadata/[GraalVM reachability metadata repository].
596+
This repository provides https://www.graalvm.org/22.2/reference-manual/native-image/ReachabilityMetadata/[reachability metadata] for libraries that do not support GraalVM Native Image.
622597

623598
=== Enabling the metadata repository
624599

625-
Support needs to be enabled explicitly:. It is possible to use a _local repository_, in which case you can specify the path to the repository:
600+
Support needs to be enabled explicitly by including the following into the `<configuration>` element:
626601

627602
.Enabling the metadata repository
628603
[source,xml,indent=0]
629604
----
630-
include::../../../../samples/native-config-integration/pom.xml[tag=metadata-local]
605+
include::../../../../samples/metadata-repo-integration/pom.xml[tag=metadata-default]
631606
----
632-
<1> The local path can point to an _exploded_ directory, or to a compressed ZIP file.
633607

634608
Alternatively, you can use a _remote repository_, in which case you can specify the URL of the ZIP file:
635609

@@ -639,9 +613,27 @@ Alternatively, you can use a _remote repository_, in which case you can specify
639613
include::../../../../samples/native-config-integration/pom.xml[tag=metadata-url]
640614
----
641615

616+
For debugging purposes you can use a local repository:
617+
618+
.Enabling a local repository
619+
[source,xml,indent=0]
620+
----
621+
include::../../../../samples/native-config-integration/pom.xml[tag=metadata-local]
622+
----
623+
<1> The local path can point to an _exploded_ directory, or to a compressed ZIP file.
624+
642625
=== Configuring the metadata repository
643626

644-
Once activated, for each library included in the native image, the plugin will automatically search for GraalVM reachability metadata in the repository.
627+
Once activated, for each library included in the native image, the plugin will automatically search for GraalVM reachability metadata in the repository that was released together with the plugin.
628+
In case you want to use another verion of the metadata use:
629+
630+
.Choosing a version for the metadata repository
631+
[source,xml,indent=0]
632+
----
633+
include::../../../../samples/metadata-repo-integration/pom.xml[tag=metadata-versioned]
634+
----
635+
636+
645637
In some cases, you may need to exclude a particular module from the search.
646638
This can be done by configuring that particular dependency:
647639

docs/src/docs/snippets/gradle/groovy/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ graalvmNative {
176176
// tag::specify-metadata-repository-version[]
177177
graalvmNative {
178178
metadataRepository {
179-
version = "1.0.0"
179+
version = "0.1.0"
180180
}
181181
}
182182
// end::specify-metadata-repository-version[]

docs/src/docs/snippets/gradle/kotlin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ graalvmNative {
189189
// tag::specify-metadata-repository-version[]
190190
graalvmNative {
191191
metadataRepository {
192-
version.set("1.0.0")
192+
version.set("0.1.0")
193193
}
194194
}
195195
// end::specify-metadata-repository-version[]

native-gradle-plugin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ End-user documentation about the plugins can be found [here](https://graalvm.git
77
## Building
88
Building of plugin itself should be as simple as:
99
```bash
10-
./gradlew publishToMavenLocal
10+
./gradlew publishToMavenLocal --no-parallel
1111
```
1212

1313
In order to run testing part of this plugin you need to get (or build) corresponding `junit-platform-native` artifact.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
42+
package org.graalvm.buildtools.gradle
43+
44+
import org.graalvm.buildtools.gradle.fixtures.AbstractFunctionalTest
45+
import org.gradle.api.logging.LogLevel
46+
import spock.lang.Unroll
47+
48+
class OfficialMetadataRepoFunctionalTest extends AbstractFunctionalTest {
49+
50+
def "the application runs when using the official metadata repository"() {
51+
given:
52+
withSample("metadata-repo-integration")
53+
54+
when:
55+
run 'nativeRun', "-D${NativeImagePlugin.CONFIG_REPO_LOGLEVEL}=${LogLevel.LIFECYCLE}"
56+
57+
then:
58+
tasks {
59+
succeeded ':jar', ':nativeCompile', ':nativeRun'
60+
}
61+
62+
and: "finds metadata in the remote repository"
63+
outputContains "[graalvm reachability metadata repository for com.h2database:h2:2.1.210]: Configuration directory is com.h2database/h2/2.1.210"
64+
}
65+
66+
}

0 commit comments

Comments
 (0)