Skip to content

Commit a3b5f3f

Browse files
authored
Ship the GraalVM metadata repository as an artifact alongside NBT (#331)
* 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
1 parent a4592a7 commit a3b5f3f

File tree

19 files changed

+463
-61
lines changed

19 files changed

+463
-61
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2020, 2021, 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+
plugins {
43+
java
44+
`kotlin-dsl`
45+
}
46+
47+
repositories {
48+
mavenCentral()
49+
gradlePluginPortal()
50+
}
51+
52+
dependencies {
53+
implementation(":common-plugins")
54+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2020, 2021 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+
rootProject.name = "reachability-plugins"
43+
44+
pluginManagement {
45+
includeBuild("../settings-plugins")
46+
}
47+
48+
includeBuild("../common-plugins")
49+
50+
plugins {
51+
id("org.graalvm.build.common")
52+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2003-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.graalvm.build;
17+
18+
import org.gradle.api.DefaultTask;
19+
import org.gradle.api.file.DirectoryProperty;
20+
import org.gradle.api.file.FileSystemOperations;
21+
import org.gradle.api.file.RegularFile;
22+
import org.gradle.api.provider.Property;
23+
import org.gradle.api.provider.Provider;
24+
import org.gradle.api.tasks.CacheableTask;
25+
import org.gradle.api.tasks.Input;
26+
import org.gradle.api.tasks.Internal;
27+
import org.gradle.api.tasks.OutputDirectory;
28+
import org.gradle.api.tasks.TaskAction;
29+
30+
import javax.inject.Inject;
31+
import java.io.File;
32+
import java.io.FileOutputStream;
33+
import java.net.URI;
34+
import java.nio.channels.Channels;
35+
import java.nio.channels.FileChannel;
36+
import java.nio.channels.ReadableByteChannel;
37+
38+
@CacheableTask
39+
public abstract class FetchRepositoryMetadata extends DefaultTask {
40+
@Input
41+
public abstract Property<String> getVersion();
42+
43+
@Input
44+
public abstract Property<String> getRepositoryUrlTemplate();
45+
46+
@OutputDirectory
47+
public abstract DirectoryProperty getOutputDirectory();
48+
49+
@Inject
50+
protected abstract FileSystemOperations getFileSystemOperations();
51+
52+
@Internal
53+
public Provider<RegularFile> getOutputFile() {
54+
return getOutputDirectory().file("repository.zip");
55+
}
56+
57+
public FetchRepositoryMetadata() {
58+
getOutputs().doNotCacheIf("Snapshot version", task -> getVersion().get().endsWith("-SNAPSHOT"));
59+
getRepositoryUrlTemplate().convention("https://github.com/oracle/graalvm-reachability-metadata/releases/download/%1$s/graalvm-reachability-metadata-%1$s.zip");
60+
}
61+
62+
@TaskAction
63+
public void fetchMetadataRepository() {
64+
String url = String.format(getRepositoryUrlTemplate().get(), getVersion().get());
65+
File tmpFile = new File(getTemporaryDir(), "repository.zip");
66+
try (ReadableByteChannel channel = Channels.newChannel(new URI(url).toURL().openStream())) {
67+
try (FileChannel outChannel = new FileOutputStream(tmpFile).getChannel()) {
68+
outChannel.transferFrom(channel, 0, Long.MAX_VALUE);
69+
}
70+
} catch (Exception e) {
71+
throw new RuntimeException("Could not download repository metadata from " + url, e);
72+
}
73+
getFileSystemOperations().copy(spec -> {
74+
spec.from(tmpFile);
75+
spec.into(getOutputDirectory());
76+
});
77+
tmpFile.delete();
78+
}
79+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import org.graalvm.build.FetchRepositoryMetadata
2+
3+
/*
4+
* Copyright (c) 2020, 2022 Oracle and/or its affiliates. All rights reserved.
5+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6+
*
7+
* The Universal Permissive License (UPL), Version 1.0
8+
*
9+
* Subject to the condition set forth below, permission is hereby granted to any
10+
* person obtaining a copy of this software, associated documentation and/or
11+
* data (collectively the "Software"), free of charge and under any and all
12+
* copyright rights in the Software, and any and all patent rights owned or
13+
* freely licensable by each licensor hereunder covering either (i) the
14+
* unmodified Software as contributed to or provided by such licensor, or (ii)
15+
* the Larger Works (as defined below), to deal in both
16+
*
17+
* (a) the Software, and
18+
*
19+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
20+
* one is included with the Software each a "Larger Work" to which the Software
21+
* is contributed by such licensors),
22+
*
23+
* without restriction, including without limitation the rights to copy, create
24+
* derivative works of, display, perform, and distribute the Software and make,
25+
* use, sell, offer for sale, import, export, have made, and have sold the
26+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
27+
* either these or other terms.
28+
*
29+
* This license is subject to the following condition:
30+
*
31+
* The above copyright notice and either this complete permission notice or at a
32+
* minimum a reference to the UPL must be included in all copies or substantial
33+
* portions of the Software.
34+
*
35+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41+
* SOFTWARE.
42+
*/
43+
44+
plugins {
45+
checkstyle
46+
id("org.graalvm.build.java")
47+
id("org.graalvm.build.publishing")
48+
}
49+
50+
tasks.withType<Test>().configureEach {
51+
useJUnitPlatform()
52+
}
53+
54+
val fetchRepository = tasks.register<FetchRepositoryMetadata>("fetchMetadataRepository") {
55+
outputDirectory.convention(layout.buildDirectory.dir("repository"))
56+
}
57+
58+
publishing {
59+
publications {
60+
create<MavenPublication>("maven") {
61+
from(components["java"])
62+
artifact(fetchRepository.flatMap { it.outputFile }) {
63+
classifier = "repository"
64+
}
65+
}
66+
}
67+
}
68+
69+
tasks.withType<Checkstyle>().configureEach {
70+
setConfigFile(layout.projectDirectory.dir("../../config/checkstyle.xml").asFile)
71+
}

‎build-logic/utils-plugins/src/main/kotlin/org.graalvm.build.utils-module.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ extensions.findByType<VersionCatalogsExtension>()?.also { catalogs ->
5858
val libs = catalogs.named("libs")
5959
val generateVersionInfo = tasks.register("generateVersionInfo", org.graalvm.build.GenerateVersionClass::class.java) {
6060
versions.put("junitPlatformNative", libs.findVersion("nativeBuildTools").get().requiredVersion)
61+
versions.put("metadataRepo", libs.findVersion("metadataRepository").get().requiredVersion)
62+
versions.put("nbt", libs.findVersion("nativeBuildTools").get().requiredVersion)
6163
outputDirectory.set(layout.buildDirectory.dir("generated/sources/versions"))
6264
}
6365

‎common/graalvm-reachability-metadata/build.gradle.kts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.graalvm.build.FetchRepositoryMetadata
2+
13
/*
24
* Copyright (c) 2020, 2022 Oracle and/or its affiliates. All rights reserved.
35
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -40,9 +42,7 @@
4042
*/
4143

4244
plugins {
43-
checkstyle
44-
id("org.graalvm.build.java")
45-
id("org.graalvm.build.publishing")
45+
id("org.graalvm.build.reachability-module")
4646
}
4747

4848
maven {
@@ -56,18 +56,6 @@ dependencies {
5656
testImplementation(libs.test.junit.jupiter.core)
5757
}
5858

59-
tasks.withType<Test>().configureEach {
60-
useJUnitPlatform()
61-
}
62-
63-
publishing {
64-
publications {
65-
create<MavenPublication>("maven") {
66-
from(components["java"])
67-
}
68-
}
69-
}
70-
71-
tasks.withType<Checkstyle>().configureEach {
72-
setConfigFile(layout.projectDirectory.dir("../../config/checkstyle.xml").asFile)
59+
tasks.withType<FetchRepositoryMetadata>().configureEach {
60+
version.set(libs.versions.metadataRepository)
7361
}

‎common/graalvm-reachability-metadata/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
pluginManagement {
4343
includeBuild("../../build-logic/settings-plugins")
4444
includeBuild("../../build-logic/common-plugins")
45+
includeBuild("../../build-logic/reachability-plugins")
4546
}
4647

4748
plugins {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.math.BigInteger;
4646
import java.net.HttpURLConnection;
4747
import java.net.URI;
48+
import java.net.URISyntaxException;
4849
import java.net.URL;
4950
import java.nio.charset.StandardCharsets;
5051
import java.nio.file.Files;
@@ -67,6 +68,13 @@ public static String normalizePathSeparators(String path) {
6768
}
6869

6970
public static Optional<Path> download(URL url, Path destination, Consumer<String> errorLogger) {
71+
if ("file".equals(url.getProtocol())) {
72+
try {
73+
return Optional.of(new java.io.File(url.toURI()).toPath());
74+
} catch (URISyntaxException e) {
75+
return Optional.empty();
76+
}
77+
}
7078
try {
7179
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
7280
connection.setRequestMethod("GET");

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
package org.graalvm.buildtools.utils;
4343

44+
import org.graalvm.buildtools.VersionInfo;
45+
4446
import java.util.Arrays;
4547
import java.util.Collections;
4648
import java.util.List;
@@ -76,5 +78,11 @@ public interface SharedConstants {
7678
String AGENT_OUTPUT_DIRECTORY_MARKER = "{output_dir}";
7779
String AGENT_OUTPUT_DIRECTORY_OPTION = "config-output-dir=";
7880
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.2.1";
81+
/**
82+
* The default metadata repository version. Maintained for backwards
83+
* compatibility.
84+
* @deprecated Please use {@link VersionInfo#METADATA_REPO_VERSION} instead
85+
*/
86+
@Deprecated
87+
String METADATA_REPO_DEFAULT_VERSION = VersionInfo.METADATA_REPO_VERSION;
8088
}

‎docs/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ asciidoctorj {
7070
"highlightjsdir" to "highlight",
7171
"gradle-plugin-version" to libs.versions.nativeBuildTools.get(),
7272
"gradle-plugin-version" to libs.versions.nativeBuildTools.get(),
73-
"maven-plugin-version" to libs.versions.nativeBuildTools.get()
73+
"maven-plugin-version" to libs.versions.nativeBuildTools.get(),
74+
"metadata-repository-version" to libs.versions.metadataRepository.get(),
7475
))
7576
}
7677

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ See <<configuration-options>> for the full list of available options.
338338
Since release 0.9.11, the plugin adds experimental support for the https://github.com/oracle/graalvm-reachability-metadata/[GraalVM reachability metadata repository].
339339
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.
340340

341+
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`.
342+
341343
=== Enabling the metadata repository
342344

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

359-
.Enabling the metadata repository
361+
.Overriding the repository version
360362
[source, groovy, role="multi-language-sample"]
361363
----
362364
include::../snippets/gradle/groovy/build.gradle[tags=specify-metadata-repository-version]

0 commit comments

Comments
 (0)