Skip to content

Commit

Permalink
Merge pull request #266 from graalvm/vj-ag/release-overhaul-no-questi…
Browse files Browse the repository at this point in the history
…ons-asked

Final PR for the metadata repo
  • Loading branch information
melix committed Jul 7, 2022
2 parents 3ae7b3f + 9462ee2 commit 0cc70d9
Show file tree
Hide file tree
Showing 23 changed files with 677 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,20 @@ public FileSystemRepository(Path rootDirectory, Logger logger) {
this.rootDirectory = rootDirectory;
}

public static boolean isSupportedArchiveFormat(String path) {
private static final String[] SUPPORTED_FORMATS = {".zip", ".tar.gz", ".tar.bz2"};

public static String getArchiveFormat(String path) {
String normalizedPath = path.toLowerCase();
return normalizedPath.endsWith(".zip") || normalizedPath.endsWith(".tar.gz") || normalizedPath.endsWith(".tar.bz2");
for (String format : SUPPORTED_FORMATS) {
if (normalizedPath.endsWith(format)) {
return format;
}
}
return null;
}

public static boolean isSupportedArchiveFormat(String path) {
return getArchiveFormat(path) != null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@
package org.graalvm.buildtools.utils;

import java.io.IOException;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.zip.ZipEntry;
Expand Down Expand Up @@ -140,4 +145,19 @@ private static Optional<Path> sanitizePath(ZipEntry entry, Path destination) {
return Optional.empty();
}
}

public static String hashFor(URI uri) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] messageDigest = md.digest(md.digest(uri.toString().getBytes(StandardCharsets.UTF_8)));
BigInteger no = new BigInteger(1, messageDigest);
StringBuilder digest = new StringBuilder(no.toString(16));
while (digest.length() < 32) {
digest.insert(0, "0");
}
return digest.toString();
} catch (NoSuchAlgorithmException e) {
throw new UnsupportedOperationException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ public interface SharedConstants {
String AGENT_SESSION_SUBDIR = "session-{pid}-{datetime}";
String AGENT_OUTPUT_DIRECTORY_MARKER = "{output_dir}";
String AGENT_OUTPUT_DIRECTORY_OPTION = "config-output-dir=";
String METADATA_REPO_URL_TEMPLATE = "https://github.com/graalvm/graalvm-reachability-metadata/releases/download/%1$s/graalvm-reachability-metadata-%1$s.zip";
String METADATA_REPO_URL_TEMPLATE = "https://github.com/oracle/graalvm-reachability-metadata/releases/download/%1$s/graalvm-reachability-metadata-%1$s.zip";
String METADATA_REPO_DEFAULT_VERSION = "0.1.0";
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
/*
* Copyright (c) 2022, 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
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.graalvm.buildtools.utils;

import org.junit.jupiter.api.DisplayName;
Expand All @@ -17,7 +57,9 @@
import java.util.Optional;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class FileUtilsTest {

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

assertTrue(Files.exists(tempDir.resolve("org.graalvm.internal/library-with-reflection/1/reflect-config.json")));
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"))));
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"))));
}

@Test
@DisplayName("It is protected against ZIP slip attacks")
void testZipSlip(@TempDir Path tempDir) throws IOException {
Expand Down
35 changes: 2 additions & 33 deletions docs/src/docs/asciidoc/gradle-plugin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -228,37 +228,6 @@ Currently, this feature requires the execution of the tests in the classic "JVM"

NOTE: This plugin requires JUnit Platform 1.8 or higher.

[[mockito-bytebuddy-support]]
=== Mockito / Byte Buddy support

Mockito is supported starting from version 4.5.0 (ByteBuddy >= 1.12.9) with GraalVM >= 22.1.
However, you need to add the following configuration to make it work with GraalVM 22.1:

.Enabling Mockito / Byte Buddy support on GraalVM 22.1
[source,groovy,role="multi-language-sample"]
----
graalvmNative {
binaries {
test {
buildArgs.add("--rerun-class-initialization-at-runtime=net.bytebuddy.ClassFileVersion,net.bytebuddy.utility.dispatcher.JavaDispatcher,net.bytebuddy.utility.Invoker$Dispatcher")
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")
}
}
}
----

[source,kotlin,role="multi-language-sample"]
----
graalvmNative {
binaries {
named("test") {
buildArgs.add("--rerun-class-initialization-at-runtime=net.bytebuddy.ClassFileVersion,net.bytebuddy.utility.dispatcher.JavaDispatcher,net.bytebuddy.utility.Invoker$Dispatcher")
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")
}
}
}
----

[[testing-support-disabling]]
=== Disabling testing support

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

Since release 0.9.11, the plugin adds experimental support for the https://github.com/graalvm/graalvm-reachability-metadata/[GraalVM reachability metadata repository].
This repository provides GraalVM configuration for libraries which do not officially support GraalVM native.
Since release 0.9.11, the plugin adds experimental support for the https://github.com/oracle/graalvm-reachability-metadata/[GraalVM reachability metadata repository].
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.

=== Enabling the metadata repository

Expand Down
54 changes: 23 additions & 31 deletions docs/src/docs/asciidoc/maven-plugin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -349,23 +349,6 @@ with an error similar to the following when attempting to run tests in a native
[ERROR] Test configuration file wasn't found. Make sure that test execution wasn't skipped.
----

[[mockito-bytebuddy-support]]
=== Mockito / Byte Buddy support

Mockito is supported starting from version 4.5.0 (ByteBuddy >= 1.12.9) with GraalVM >= 22.1.
However, you need to add the following configuration to make it work with GraalVM 22.1:

.Enabling Mockito / Byte Buddy support on GraalVM 22.1
[source,xml]
----
<configuration>
<buildArgs>
<arg>--rerun-class-initialization-at-runtime=net.bytebuddy.ClassFileVersion,net.bytebuddy.utility.dispatcher.JavaDispatcher,net.bytebuddy.utility.Invoker$Dispatcher</arg>
<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>
</buildArgs>
</configuration>
----

[[testing-support-disabling]]
=== Disabling testing support

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

WARNING: If the agent is enabled, the `--allow-incomplete-classpath` option is
automatically added to your native build options.

[[agent-support-running-application]]
=== Running your application with the agent

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

WARNING: If the agent is enabled, the `--allow-incomplete-classpath` option is
automatically added to your native build options.

[[metadata-support]]
== GraalVM Reachability Metadata Support

Since release 0.9.12, the plugin adds experimental support for the https://github.com/graalvm/graalvm-reachability-metadata/[GraalVM reachability metadata repository].
This repository provides GraalVM metadata for libraries which do not officially support GraalVM native.

A metadata repository consists of configuration files for GraalVM.
Since release 0.9.12, the plugin adds support for the https://github.com/oracle/graalvm-reachability-metadata/[GraalVM reachability metadata repository].
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.

=== Enabling the metadata repository

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:
Support needs to be enabled explicitly by including the following into the `<configuration>` element:

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

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

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

For debugging purposes you can use a local repository:

.Enabling a local repository
[source,xml,indent=0]
----
include::../../../../samples/native-config-integration/pom.xml[tag=metadata-local]
----
<1> The local path can point to an _exploded_ directory, or to a compressed ZIP file.

=== Configuring the metadata repository

Once activated, for each library included in the native image, the plugin will automatically search for GraalVM reachability metadata in the repository.
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.
In case you want to use another verion of the metadata use:

.Choosing a version for the metadata repository
[source,xml,indent=0]
----
include::../../../../samples/metadata-repo-integration/pom.xml[tag=metadata-versioned]
----


In some cases, you may need to exclude a particular module from the search.
This can be done by configuring that particular dependency:

Expand Down
2 changes: 1 addition & 1 deletion docs/src/docs/snippets/gradle/groovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ graalvmNative {
// tag::specify-metadata-repository-version[]
graalvmNative {
metadataRepository {
version = "1.0.0"
version = "0.1.0"
}
}
// end::specify-metadata-repository-version[]
Expand Down
2 changes: 1 addition & 1 deletion docs/src/docs/snippets/gradle/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ graalvmNative {
// tag::specify-metadata-repository-version[]
graalvmNative {
metadataRepository {
version.set("1.0.0")
version.set("0.1.0")
}
}
// end::specify-metadata-repository-version[]
Expand Down
2 changes: 1 addition & 1 deletion native-gradle-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ End-user documentation about the plugins can be found [here](https://graalvm.git
## Building
Building of plugin itself should be as simple as:
```bash
./gradlew publishToMavenLocal
./gradlew publishToMavenLocal --no-parallel
```

In order to run testing part of this plugin you need to get (or build) corresponding `junit-platform-native` artifact.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2022, 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
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.graalvm.buildtools.gradle

import org.graalvm.buildtools.gradle.fixtures.AbstractFunctionalTest
import org.gradle.api.logging.LogLevel
import spock.lang.Unroll

class OfficialMetadataRepoFunctionalTest extends AbstractFunctionalTest {

def "the application runs when using the official metadata repository"() {
given:
withSample("metadata-repo-integration")

when:
run 'nativeRun', "-D${NativeImagePlugin.CONFIG_REPO_LOGLEVEL}=${LogLevel.LIFECYCLE}"

then:
tasks {
succeeded ':jar', ':nativeCompile', ':nativeRun'
}

and: "finds metadata in the remote repository"
outputContains "[graalvm reachability metadata repository for com.h2database:h2:2.1.210]: Configuration directory is com.h2database/h2/2.1.210"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ private GraalVMExtension registerGraalVMExtension(Project project) {
private void configureNativeConfigurationRepo(ExtensionAware graalvmNative) {
GraalVMReachabilityMetadataRepositoryExtension configurationRepository = graalvmNative.getExtensions().create("metadataRepository", GraalVMReachabilityMetadataRepositoryExtension.class);
configurationRepository.getEnabled().convention(false);
configurationRepository.getVersion().convention(SharedConstants.METADATA_REPO_DEFAULT_VERSION);
configurationRepository.getUri().convention(configurationRepository.getVersion().map(v -> {
try {
return new URI(String.format(METADATA_REPO_URL_TEMPLATE, v));
Expand Down

0 comments on commit 0cc70d9

Please sign in to comment.