Skip to content

Commit

Permalink
Ship the GraalVM metadata repository as an artifact alongside NBT (#331)
Browse files Browse the repository at this point in the history
* Bump the metadata repository version

This also moves the constant to the `libs.versions.toml` file so that it
is both easier to upgrade *and* available in build scripts without having
to parse source files. This is going to be useful for repackaging the
repository.

* Download the metadata repository as a publishable artifact

This commit introduces a task which is responsible for downloading the
current metadata repository version and bundle it as a publishable artifact.
This means that the ZIP file of the metadata repository is going to be
downloaded from the GraalVM metadata repository, and published as a
_classified_ artifact on the `graalvm-reachability-metadata` module.

It is possible to check the result by calling:

    ./gradlew graalvm-reachability-metadata:pAPTCR

and checking the contents of the `build/common-repo` directory. A file
named `graalvm-reachability-metadata-<nbt version>-repository.zip` file
should be visible.

This will make it possible to consume the metadata repository as a Maven
artifact.

* Make the Gradle plugin use the metadata repository from Maven

This commit makes it so that if the user doesn't specify any URL for the
repository, nor any specific version, then we would use the repository
artifact which is bundled with the NBT release on Maven Central (or
any repository configured in the build). This makes it possible to
use the Gradle native build tools exclusively with Maven repositories.

* Make the Maven plugin use the metadata repository from Maven Central

Similarly to the Gradle plugin, this commit makes it so that if the user
doesn't specify any URL for the repository, nor any specific version,
then we would use the repository artifact which is bundled with the NBT
release on Maven Central.

* Add release notes

* Add mention about the new metadata collection task
  • Loading branch information
melix committed Oct 12, 2022
1 parent a4592a7 commit a3b5f3f
Show file tree
Hide file tree
Showing 19 changed files with 463 additions and 61 deletions.
54 changes: 54 additions & 0 deletions build-logic/reachability-plugins/build.gradle.kts
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2020, 2021, 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.
*/

plugins {
java
`kotlin-dsl`
}

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation(":common-plugins")
}
52 changes: 52 additions & 0 deletions build-logic/reachability-plugins/settings.gradle.kts
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2020, 2021 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.
*/

rootProject.name = "reachability-plugins"

pluginManagement {
includeBuild("../settings-plugins")
}

includeBuild("../common-plugins")

plugins {
id("org.graalvm.build.common")
}
@@ -0,0 +1,79 @@
/*
* Copyright 2003-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.graalvm.build;

import org.gradle.api.DefaultTask;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileSystemOperations;
import org.gradle.api.file.RegularFile;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction;

import javax.inject.Inject;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URI;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;

@CacheableTask
public abstract class FetchRepositoryMetadata extends DefaultTask {
@Input
public abstract Property<String> getVersion();

@Input
public abstract Property<String> getRepositoryUrlTemplate();

@OutputDirectory
public abstract DirectoryProperty getOutputDirectory();

@Inject
protected abstract FileSystemOperations getFileSystemOperations();

@Internal
public Provider<RegularFile> getOutputFile() {
return getOutputDirectory().file("repository.zip");
}

public FetchRepositoryMetadata() {
getOutputs().doNotCacheIf("Snapshot version", task -> getVersion().get().endsWith("-SNAPSHOT"));
getRepositoryUrlTemplate().convention("https://github.com/oracle/graalvm-reachability-metadata/releases/download/%1$s/graalvm-reachability-metadata-%1$s.zip");
}

@TaskAction
public void fetchMetadataRepository() {
String url = String.format(getRepositoryUrlTemplate().get(), getVersion().get());
File tmpFile = new File(getTemporaryDir(), "repository.zip");
try (ReadableByteChannel channel = Channels.newChannel(new URI(url).toURL().openStream())) {
try (FileChannel outChannel = new FileOutputStream(tmpFile).getChannel()) {
outChannel.transferFrom(channel, 0, Long.MAX_VALUE);
}
} catch (Exception e) {
throw new RuntimeException("Could not download repository metadata from " + url, e);
}
getFileSystemOperations().copy(spec -> {
spec.from(tmpFile);
spec.into(getOutputDirectory());
});
tmpFile.delete();
}
}
@@ -0,0 +1,71 @@
import org.graalvm.build.FetchRepositoryMetadata

/*
* Copyright (c) 2020, 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.
*/

plugins {
checkstyle
id("org.graalvm.build.java")
id("org.graalvm.build.publishing")
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

val fetchRepository = tasks.register<FetchRepositoryMetadata>("fetchMetadataRepository") {
outputDirectory.convention(layout.buildDirectory.dir("repository"))
}

publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
artifact(fetchRepository.flatMap { it.outputFile }) {
classifier = "repository"
}
}
}
}

tasks.withType<Checkstyle>().configureEach {
setConfigFile(layout.projectDirectory.dir("../../config/checkstyle.xml").asFile)
}
Expand Up @@ -58,6 +58,8 @@ extensions.findByType<VersionCatalogsExtension>()?.also { catalogs ->
val libs = catalogs.named("libs")
val generateVersionInfo = tasks.register("generateVersionInfo", org.graalvm.build.GenerateVersionClass::class.java) {
versions.put("junitPlatformNative", libs.findVersion("nativeBuildTools").get().requiredVersion)
versions.put("metadataRepo", libs.findVersion("metadataRepository").get().requiredVersion)
versions.put("nbt", libs.findVersion("nativeBuildTools").get().requiredVersion)
outputDirectory.set(layout.buildDirectory.dir("generated/sources/versions"))
}

Expand Down
22 changes: 5 additions & 17 deletions common/graalvm-reachability-metadata/build.gradle.kts
@@ -1,3 +1,5 @@
import org.graalvm.build.FetchRepositoryMetadata

/*
* Copyright (c) 2020, 2022 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
Expand Down Expand Up @@ -40,9 +42,7 @@
*/

plugins {
checkstyle
id("org.graalvm.build.java")
id("org.graalvm.build.publishing")
id("org.graalvm.build.reachability-module")
}

maven {
Expand All @@ -56,18 +56,6 @@ dependencies {
testImplementation(libs.test.junit.jupiter.core)
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
}

tasks.withType<Checkstyle>().configureEach {
setConfigFile(layout.projectDirectory.dir("../../config/checkstyle.xml").asFile)
tasks.withType<FetchRepositoryMetadata>().configureEach {
version.set(libs.versions.metadataRepository)
}
1 change: 1 addition & 0 deletions common/graalvm-reachability-metadata/settings.gradle.kts
Expand Up @@ -42,6 +42,7 @@
pluginManagement {
includeBuild("../../build-logic/settings-plugins")
includeBuild("../../build-logic/common-plugins")
includeBuild("../../build-logic/reachability-plugins")
}

plugins {
Expand Down
Expand Up @@ -45,6 +45,7 @@
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -67,6 +68,13 @@ public static String normalizePathSeparators(String path) {
}

public static Optional<Path> download(URL url, Path destination, Consumer<String> errorLogger) {
if ("file".equals(url.getProtocol())) {
try {
return Optional.of(new java.io.File(url.toURI()).toPath());
} catch (URISyntaxException e) {
return Optional.empty();
}
}
try {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
Expand Down
Expand Up @@ -41,6 +41,8 @@

package org.graalvm.buildtools.utils;

import org.graalvm.buildtools.VersionInfo;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -76,5 +78,11 @@ public interface SharedConstants {
String AGENT_OUTPUT_DIRECTORY_MARKER = "{output_dir}";
String AGENT_OUTPUT_DIRECTORY_OPTION = "config-output-dir=";
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.2.1";
/**
* The default metadata repository version. Maintained for backwards
* compatibility.
* @deprecated Please use {@link VersionInfo#METADATA_REPO_VERSION} instead
*/
@Deprecated
String METADATA_REPO_DEFAULT_VERSION = VersionInfo.METADATA_REPO_VERSION;
}
3 changes: 2 additions & 1 deletion docs/build.gradle.kts
Expand Up @@ -70,7 +70,8 @@ asciidoctorj {
"highlightjsdir" to "highlight",
"gradle-plugin-version" to libs.versions.nativeBuildTools.get(),
"gradle-plugin-version" to libs.versions.nativeBuildTools.get(),
"maven-plugin-version" to libs.versions.nativeBuildTools.get()
"maven-plugin-version" to libs.versions.nativeBuildTools.get(),
"metadata-repository-version" to libs.versions.metadataRepository.get(),
))
}

Expand Down
4 changes: 3 additions & 1 deletion docs/src/docs/asciidoc/gradle-plugin.adoc
Expand Up @@ -338,6 +338,8 @@ See <<configuration-options>> for the full list of available options.
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.

NOTE: This version of the plugin defaults to the using the metadata repository in version {metadata-repository-version}. There is nothing for you to configure if you are fine with this version. The repository is also published on Maven Central at the following coordinates: `org.graalvm.buildtools:graalvm-reachability-metadata:graalvm-reachability-metadata` with the `repository` classifier and `zip` extension, e.g. `graalvm-reachability-metadata-{gradle-plugin-version}-repository.zip`.

=== Enabling the metadata repository

Support needs to be enabled explicitly:
Expand All @@ -356,7 +358,7 @@ include::../snippets/gradle/kotlin/build.gradle.kts[tags=enable-metadata-reposit
A metadata repository consists of configuration files for GraalVM.
The plugin will automatically download the configuration metadata from the official repository if you supply the version of the repository you want to use:

.Enabling the metadata repository
.Overriding the repository version
[source, groovy, role="multi-language-sample"]
----
include::../snippets/gradle/groovy/build.gradle[tags=specify-metadata-repository-version]
Expand Down

0 comments on commit a3b5f3f

Please sign in to comment.