Skip to content

Commit

Permalink
Merge branch '5.4.x' into 6.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
melix committed Mar 6, 2023
2 parents a455dd1 + cab1462 commit a7403c2
Show file tree
Hide file tree
Showing 16 changed files with 517 additions and 71 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
env:
GH_TOKEN_PUBLIC_REPOS_READONLY: ${{ secrets.GH_TOKEN_PUBLIC_REPOS_READONLY }}
GH_USERNAME: ${{ secrets.GH_USERNAME }}
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
- name: Publish Test Report
if: ${{ always() }}
uses: mikepenz/[email protected]
Expand All @@ -43,6 +46,9 @@ jobs:
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
GPG_FILE: ${{ secrets.GPG_FILE }}
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
run: |
echo $GPG_FILE | base64 -d > secring.gpg
./gradlew publish
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
GPG_FILE: ${{ secrets.GPG_FILE }}
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
run: |
echo $GPG_FILE | base64 -d > secring.gpg
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ dependencies {
}
implementation 'org.jsoup:jsoup:1.15.3'

implementation 'com.gradle:gradle-enterprise-gradle-plugin:3.11.4'
implementation 'com.gradle:gradle-enterprise-gradle-plugin:3.12.4'
implementation 'com.gradle.enterprise:test-distribution-gradle-plugin:2.3.5'
implementation 'org.nosphere.gradle.github:gradle-github-actions-plugin:1.3.2'
implementation 'com.gradle:common-custom-user-data-gradle-plugin:1.8.2'
implementation 'org.gradle:test-retry-gradle-plugin:1.4.1'
Expand All @@ -76,8 +77,8 @@ dependencies {

testImplementation("com.typesafe:config:1.4.2")

functionalTestImplementation("org.mock-server:mockserver-netty:5.14.0")
functionalTestImplementation("org.mock-server:mockserver-client-java:5.14.0")
testImplementation("org.mock-server:mockserver-netty:5.14.0")
testImplementation("org.mock-server:mockserver-client-java:5.14.0")

}

Expand Down
12 changes: 12 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
plugins {
id "com.gradle.enterprise" version "3.12.3"
}

rootProject.name = 'micronaut-build'

gradleEnterprise {
server = "https://ge.micronaut.io"
buildScan {
publishAlways()
publishIfAuthenticated()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class MicronautBuildCommonPlugin implements Plugin<Project> {
private void configureJavaPlugin(Project project, MicronautBuildExtension micronautBuildExtension) {
project.apply plugin: "groovy"
project.apply plugin: "java-library"
project.pluginManager.apply('org.gradle.test-retry')

def javaPluginExtension = project.extensions.findByType(JavaPluginExtension)
javaPluginExtension.toolchain.languageVersion.convention(micronautBuildExtension.javaVersion.map(JavaLanguageVersion::of))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.micronaut.build.MicronautBuildExtensionPlugin;
import io.micronaut.build.MicronautPublishingPlugin;
import io.micronaut.build.pom.MicronautBomExtension;
import io.micronaut.build.utils.GitHubApiService;
import io.micronaut.build.utils.ExternalURLService;
import me.champeau.gradle.japicmp.JapicmpTask;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
Expand Down Expand Up @@ -127,10 +127,14 @@ private Provider<String> createBaselineProvider(BinaryCompatibibilityExtension b
}

private TaskProvider<FindBaselineTask> registerFindBaselineTask(Project project, BinaryCompatibibilityExtension binaryCompatibility, TaskContainer tasks, ProviderFactory providers) {
Provider<ExternalURLService> downloader = ExternalURLService.registerOn(project);
return tasks.register("findBaseline", FindBaselineTask.class, task -> {
task.onlyIf(t -> binaryCompatibility.getEnabled().getOrElse(true));
task.getGitHubApi().set(GitHubApiService.registerOn(project));
task.getGithubSlug().convention(providers.gradleProperty("githubSlug"));
task.usesService(downloader);
task.getDownloader().set(downloader);
task.getBaseRepository().convention("https://repo.maven.org/maven2");
task.getGroupId().convention(providers.provider(() -> project.getGroup().toString()));
task.getArtifactId().convention(providers.provider(() -> artifactIdOf(project)));
task.getCurrentVersion().convention(providers.provider(() -> project.getVersion().toString()));
task.getPreviousVersion().convention(project.getLayout().getBuildDirectory().file("baseline.txt"));
});
Expand All @@ -144,4 +148,12 @@ private static String readBaseline(String baselineText) {
}
return "+";
}

private static String artifactIdOf(Project project) {
String name = project.getName();
if (name.startsWith("micronaut-")) {
return name;
}
return "micronaut-" + name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension;
import com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin;
import com.gradle.scan.plugin.BuildScanExtension;
import org.gradle.api.JavaVersion;
import org.gradle.api.Plugin;
import org.gradle.api.initialization.Settings;
import org.gradle.api.invocation.Gradle;
Expand Down Expand Up @@ -60,6 +61,7 @@ private void configureGradleEnterprise(Settings settings,
boolean isCI = ProviderUtils.guessCI(providers);
configureBuildScansPublishing(ge, isCI, publishScanOnDemand);
settings.getGradle().projectsLoaded(MicronautGradleEnterprisePlugin::applyGitHubActionsPlugin);
tagWithJavaDetails(ge, providers);
if (providers.gradleProperty("org.gradle.caching").map(Boolean::parseBoolean).orElse(true).get()) {
settings.getGradle().settingsEvaluated(lateSettings -> {
BuildCacheConfiguration buildCache = settings.getBuildCache();
Expand Down Expand Up @@ -100,6 +102,14 @@ private void configureGradleEnterprise(Settings settings,
}
}

private void tagWithJavaDetails(GradleEnterpriseExtension ge, ProviderFactory providers) {
Provider<String> vendor = providers.systemProperty("java.vendor");
if (vendor.isPresent()) {
ge.getBuildScan().tag("vendor:" + vendor.get().toLowerCase().replaceAll("\\W+", "_"));
}
ge.getBuildScan().tag("jdk:" + JavaVersion.current().getMajorVersion());
}

private void captureSafeEnvironmentVariables(GradleEnterpriseExtension ge) {
for (String variable : SAFE_TO_LOG_ENV_VARIABLES) {
String value = System.getenv(variable);
Expand Down
54 changes: 26 additions & 28 deletions src/main/java/io/micronaut/build/compat/FindBaselineTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package io.micronaut.build.compat;

import groovy.json.JsonSlurper;
import io.micronaut.build.utils.GitHubApiService;
import io.micronaut.build.utils.ExternalURLService;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
Expand All @@ -30,20 +30,25 @@

import javax.inject.Inject;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

@CacheableTask
public abstract class FindBaselineTask extends DefaultTask {

private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
public static final int CACHE_IN_SECONDS = 3600;

@Input
public abstract Property<String> getGithubSlug();
public abstract Property<String> getBaseRepository();

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

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

@Input
public abstract Property<String> getCurrentVersion();
Expand All @@ -58,12 +63,20 @@ protected Provider<Long> getTimestamp() {
}

@Internal
protected Provider<byte[]> getJson() {
return getGithubSlug().map(slug -> getGitHubApi().get().fetchReleasesFromGitHub(slug));
protected Provider<byte[]> getMavenMetadata() {
Provider<String> artifactPath = getGroupId().zip(getArtifactId(), (groupId, artifactId) -> groupId.replace('.', '/') + "/" + artifactId + "/maven-metadata.xml");
return getBaseRepository().zip(artifactPath, (baseUrl, path) -> {
String url = baseUrl + "/" + path ;
try {
return getDownloader().get().fetchFromURL(new URI(url)).orElse(EMPTY_BYTE_ARRAY);
} catch (URISyntaxException e) {
throw new GradleException("Invalid URI: " + url, e);
}
});
}

@Internal
abstract Property<GitHubApiService> getGitHubApi();
abstract Property<ExternalURLService> getDownloader();

@Inject
protected abstract ProviderFactory getProviders();
Expand All @@ -73,25 +86,10 @@ protected Provider<byte[]> getJson() {

@TaskAction
public void execute() throws IOException {
byte[] jsonBytes = getJson().get();
JsonSlurper slurper = new JsonSlurper();
List<Map<String, Object>> json = (List<Map<String, Object>>) slurper.parse(jsonBytes);
List<VersionModel> releases = json.stream()
.filter(release -> !Objects.equals(release.get("draft"), true) && !Objects.equals(release.get("prerelease"), true))
.map(release -> (String) release.get("tag_name"))
.map(tag -> {
if (tag.startsWith("v")) {
return tag.substring(1);
}
return tag;
}).filter(v -> !v.contains("-"))
.map(VersionModel::of)
.sorted()
.collect(Collectors.toList());
byte[] metadata = getMavenMetadata().get();
List<VersionModel> releases = MavenMetadataVersionHelper.findReleasesFrom(metadata);
VersionModel current = VersionModel.of(trimVersion());
Optional<VersionModel> previous = releases.stream()
.filter(v -> v.compareTo(current) < 0)
.reduce((a, b) -> b);
Optional<VersionModel> previous = MavenMetadataVersionHelper.findPreviousReleaseFor(current, releases);
if (!previous.isPresent()) {
throw new IllegalStateException("Could not find a previous version for " + current);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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 io.micronaut.build.compat;

import org.gradle.api.GradleException;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public abstract class MavenMetadataVersionHelper {
private static final Pattern VERSION_PATTERN = Pattern.compile("^(\\d+\\.\\d+\\.\\d+)([.-]\\w+)?$");
private static final String VERSION_OPEN_TAG = "<version>";
private static final String VERSION_CLOSE_TAG = "</version>";

private MavenMetadataVersionHelper() {

}

public static List<VersionModel> findReleasesFrom(byte[] mavenMetadata) {
List<String> allVersions = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new StringReader(new String(mavenMetadata, StandardCharsets.UTF_8)))) {
String line;
while ((line = reader.readLine()) != null) {
if (line.contains(VERSION_OPEN_TAG)) {
String version = line.substring(line.indexOf(VERSION_OPEN_TAG) + VERSION_OPEN_TAG.length(), line.indexOf(VERSION_CLOSE_TAG));
allVersions.add(version);
}
}
return allVersions.stream()
.map(version -> {
Matcher m = VERSION_PATTERN.matcher(version);
if (m.find()) {
if (m.group(2) != null) {
// discard non release versions like M2, RC1, etc
return null;
}
return m.group(1);
}
return null;
})
.filter(Objects::nonNull)
.map(VersionModel::of)
.sorted()
.collect(Collectors.toList());

} catch (IOException e) {
throw new GradleException("Error parsing maven-metadata.xml", e);
}
}

public static Optional<VersionModel> findPreviousReleaseFor(VersionModel version, List<VersionModel> releases) {
return releases.stream()
.filter(v -> v.compareTo(version) < 0)
.reduce((a, b) -> b);
}
}
Loading

0 comments on commit a7403c2

Please sign in to comment.