Skip to content

Ship the GraalVM metadata repository as an artifact alongside NBT #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
melix committed Oct 11, 2022
commit 1d60187669fc92b3a3a720fb21c6e36ccb71e47b
54 changes: 54 additions & 0 deletions build-logic/reachability-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
22 changes: 5 additions & 17 deletions common/graalvm-reachability-metadata/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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