Skip to content

Commit

Permalink
4.6.0.3 release (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
burtbeckwith authored Oct 14, 2024
1 parent db84bd7 commit 3e53582
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 31 deletions.
4 changes: 4 additions & 0 deletions gdk/buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ gradlePlugin {
id = 'gdk.version-catalog-updates'
implementationClass = 'cloud.graal.gdk.dependencies.GdkVersionCatalogUpdatePlugin'
}
gdkParentPlugin {
id = 'gdk.parent'
implementationClass = 'cloud.graal.gdk.pom.GdkParentPlugin'
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ abstract class VersionCatalogUpdate extends DefaultTask {
'io.micronaut.build',
'io.micronaut.build.internal.bom',
'io.micronaut.gradle',
'io.micronaut.platform',
'io.micronaut.starter',
'io.micronaut.maven',
'io.micronaut.testresources'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/*
* Copyright 2024 Oracle and/or its affiliates
*
* 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 cloud.graal.gdk.pom

import groovy.namespace.QName
import groovy.transform.CompileStatic
import io.micronaut.build.catalogs.internal.VersionCatalogTomlModel
import io.micronaut.build.pom.VersionCatalogConverter
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.DependencyConstraint
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency
import org.gradle.api.plugins.JavaPlatformExtension
import org.gradle.api.plugins.JavaPlatformPlugin
import org.gradle.api.plugins.PluginManager
import org.gradle.api.plugins.catalog.CatalogPluginExtension
import org.gradle.api.plugins.catalog.VersionCatalogPlugin
import org.gradle.api.provider.Provider
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.TaskContainer

import static org.gradle.api.plugins.JavaPlatformPlugin.API_CONFIGURATION_NAME


@CompileStatic
@CacheableTask
abstract class GdkParentPlugin implements Plugin<Project> {

Map<String, String> pluginsMap = Map.of(
"exclude-io-micronaut-maven-plugin", "micronaut-maven-plugin.version",
"exclude-io-micronaut-maven-test-resources-plugin", "micronaut.test.resources.version",
)

@Override
void apply(Project project) {
PluginManager plugins = project.pluginManager
plugins.apply(MavenPublishPlugin)
plugins.apply(JavaPlatformPlugin)
plugins.apply(VersionCatalogPlugin)
project.extensions.add(DependencyExclusion.NAME, DependencyExclusion)
configureParent(project)
}

private void configureParent(Project project) {
project.extensions.getByType(JavaPlatformExtension).allowDependencies()
PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
DependencyExclusion dependencyExclusion = project.extensions.getByType(DependencyExclusion)
project.afterEvaluate { unused -> configureLate(project, publishing, dependencyExclusion, project.tasks) }
}


private void configureLate(Project project, PublishingExtension publishing, DependencyExclusion dependencyExclusion, TaskContainer tasks) {

final VersionCatalogConverter modelConverter = new VersionCatalogConverter(
project.rootProject.file("gradle/templates.versions.toml"),
project.extensions.findByType(CatalogPluginExtension)
)

VersionCatalog versionCatalog = project.extensions.findByType(VersionCatalogsExtension).find("templateLibs").get()
VersionCatalogTomlModel modelProvider = project.provider(modelConverter::getModel).get()

Configuration api = project.configurations.named(API_CONFIGURATION_NAME).get()

Map<String, String> mapAliasToVersion = new HashMap<>()
publishing.publications.named("maven", MavenPublication, pub -> {
pub.artifactId = "gdk-parent"
pub.groupId = "cloud.graal.gdk"
pub.from(project.components.named("javaPlatform").get())
pub.pom(pom -> {
pom.packaging = "pom"
def lib = modelProvider.librariesTable.find(l -> {l.alias == "exclude-io-micronaut-platform-micronaut-parent"})
def platformVersion = modelProvider.versionsTable.find(x -> x.reference == lib.version.reference).version

modelProvider.librariesTable.forEach(library -> {
if (!library.alias.startsWith("exclude-")) {
String alias = Optional.ofNullable(library.version.reference).map(a -> a.replace('-', '.')).orElse("")
String bomPropertyName = bomPropertyName(library.alias, alias)
def version = modelProvider.versionsTable.find(x -> x.reference == library.version.reference).version
mapAliasToVersion[library.alias] = '\${' + bomPropertyName + '}'
pom.properties.put(bomPropertyName, version.require)
}
})

pom.withXml { xml ->
Node parent = xml.asNode().appendNode('parent')
xml.asNode().children().remove(parent)
// add it after packaging
xml.asNode().children().add(5, parent)

new Node(parent, "groupId", "io.micronaut.platform")
new Node(parent, "artifactId", "micronaut-parent")
new Node(parent, "version", platformVersion.require)
}

pom.packaging = "pom"
pom.properties.put("micronaut.version", platformVersion.require)

modelProvider.librariesTable.forEach(library -> {
if (!library.alias.startsWith("exclude-") || pluginsMap.containsKey(library.alias) ) {
String alias = Optional.ofNullable(library.version.reference).map(a -> a.replace('-', '.')).orElse("")
String bomPropertyName = pluginsMap.containsKey(library.alias) ? pluginsMap.get(library.alias) : bomPropertyName(library.alias, alias)
def version = modelProvider.versionsTable.find(x -> x.reference == library.version.reference).version
pom.properties.put(bomPropertyName, version.require)
}
})

pom.withXml { xml ->
Node dependencies = childOf(childOf(xml.asNode(), "dependencyManagement"), "dependencies")
Node dependency = new Node(dependencies, "dependency", "")
new Node(dependency, "groupId", "cloud.graal.gdk")
new Node(dependency, "artifactId", "gdk-bom")
new Node(dependency, "version", project.version)
new Node(dependency, "type", "pom")
new Node(dependency, "scope", "import")
}
})
})



publishing.repositories(repositories -> {
Provider<String> externalRepoUri = project.providers.environmentVariable("PUBLISH_REPO")
if (externalRepoUri.isPresent()) {
repositories.maven(maven -> {
MavenArtifactRepository repository = (MavenArtifactRepository) maven
repository.name = "External"
repository.url = externalRepoUri
Provider<String> externalRepoUsername = project.providers.environmentVariable("PUBLISH_USERNAME")
Provider<String> externalRepoPassword = project.providers.environmentVariable("PUBLISH_PASSWORD")
if (externalRepoUsername.isPresent() && externalRepoPassword.isPresent()) {
repository.credentials(credentials -> {
credentials.username = externalRepoUsername.get()
credentials.password = externalRepoPassword.get()
})
}
})
}
repositories.maven(maven -> {
MavenArtifactRepository repository = (MavenArtifactRepository) maven
repository.name = "Build"
repository.url = project.rootProject.layout.buildDirectory.dir("repo")
})
})

versionCatalog.libraryAliases.sort { alias -> versionCatalog.findLibrary(alias).get().get().module.toString() }.forEach(alias -> {
MinimalExternalModuleDependency lib = versionCatalog.findLibrary(alias).map(Provider::get)
.orElseThrow(() -> new RuntimeException("Unexpected missing alias in catalog: " + alias)) as MinimalExternalModuleDependency
DefaultExternalModuleDependency existingDep = api.dependencies.find(x -> x.name == lib.name) as DefaultExternalModuleDependency

if (existingDep != null) {
existingDep.version { it.strictly(mapAliasToVersion.get(alias.replace(".", "-"))) }
} else if (!alias.startsWith("exclude.") && !alias.endsWith(".bom")) {
DependencyConstraint dependencyConstraint = project.dependencies.constraints.create(lib)
dependencyConstraint.version { it.strictly(mapAliasToVersion.get(alias.replace(".", "-"))) }
api.dependencyConstraints.add(dependencyConstraint)
}
})

}

private static String bomPropertyName(String alias, String version) {
version = version.replaceFirst(/^boms\./, '')
String baseName = toPropertyName(version)
if (baseName.endsWith(".version")) {
return baseName
}
if (alias.contains("bom")) {
return baseName + '.version'
} else {
return baseName + ".gdk.version"
}
}

private static String toPropertyName(String alias) {
return alias.split("(?=[A-Z])")
.collect { it.toLowerCase(Locale.US) }
.join("-")
.replace('-', '.')
}

private static Node childOf(Node node, String name) {
List<Node> children = (List<Node>) node.children()
return children.stream().findAll(n -> n instanceof Node).find(n -> nameOf(n as Node) == name) as Node
}

private static String nameOf(Node n) {
def name = n.name()
if (name instanceof String) {
return (String) name
}
return ((QName) n.name()).localPart
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,12 @@ public GdkGeneratorContext(Project project,
cloudFeatures = splitFeatures(features, featureContext, this);
generateExampleCode = featureContext.getOptions().get(EXAMPLE_CODE, Boolean.class).orElse(true);

String key = featureContext.getOptions().getBuildTool().isGradle() ? "micronautVersion" : "micronaut.version";
clouds = new HashSet<>(cloudFeatures.keySet());
clouds.add(NONE); // for lib module
buildProperties = new GdkBuildProperties(this, clouds);
buildProperties.put(key, GdkUtils.getMicronautVersion() + GdkUtils.BOM_VERSION_SUFFIX);

if (!featureContext.getBuildTool().isGradle()) {
buildProperties.put("micronaut-maven-plugin.version", GdkDependencies.MICRONAUT_MAVEN_PLUGIN.getVersion());
buildProperties.put("micronaut.test.resources.version", GdkDependencies.MICRONAUT_TEST_RESOURCES_CORE.getVersion());
buildProperties.put("kotlin.version", GdkDependencies.KOTLIN_STDLIB.getVersion());
buildProperties.put("micronaut.core.version", GdkDependencies.MICRONAUT_CORE.getVersion());
if (featureContext.getOptions().getBuildTool().isGradle()) {
buildProperties.put("micronautVersion", GdkUtils.getMicronautVersion() + GdkUtils.BOM_VERSION_SUFFIX);
}

INSTANCE.set(this);
}

Expand Down
2 changes: 1 addition & 1 deletion gdk/gdk-core/src/main/java/cloud/graal/gdk/GdkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static String getVersion() {
* @return the version of Micronaut Platform
*/
public static String getMicronautVersion() {
return GdkDependencies.MICRONAUT_PARENT.getVersion();
return GdkDependencies.MICRONAUT_PARENT.getVersion().replaceAll("-oracle-\\d+", "");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ public class GdkBom implements DefaultFeature, RequiresRepository {

@Override
public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(BOM);

if (generatorContext.getBuildTool().isGradle()) {
generatorContext.addDependency(BOM);
generatorContext.addBuildPlugin(BOM_PLUGIN);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public final class GdkTestedFeatures {
"mysql",
"flyway",
"validation",
"oracle",
// DATABASE OCI
"oracle-cloud-atp",
// EMAIL AWS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import io.micronaut.starter.feature.database.DatabaseDriverFeature;
import io.micronaut.starter.feature.database.H2;
import io.micronaut.starter.feature.database.MySQL;
import io.micronaut.starter.feature.database.Oracle;
import io.micronaut.starter.feature.database.jdbc.JdbcFeature;
import io.micronaut.starter.feature.migration.Flyway;
import io.micronaut.starter.feature.oraclecloud.OracleCloudAutonomousDatabase;
Expand Down Expand Up @@ -149,9 +150,7 @@ public final void apply(GdkGeneratorContext generatorContext) {
"flyway.datasources.default.enabled", true,
"datasources.default.dialect", driverFeature.getDataDialect()
));

jdbcFeature.applyDefaultConfig(generatorContext, driverFeature, jdbcConfig);

if (driverFeature instanceof OracleCloudAutonomousDatabase) {
generatorContext.getTestConfiguration().addNested(Map.of(
"datasources.default.url", "jdbc:tc:oracle:thin:@/xe",
Expand All @@ -163,6 +162,18 @@ public final void apply(GdkGeneratorContext generatorContext) {
"flyway.datasources.default.baseline-version", "0",
"flyway.datasources.default.baseline-on-migrate", "true"));
generatorContext.addDependency(TESTCONTAINERS_ORACLE_XE);
} else if (driverFeature instanceof Oracle) {
generatorContext.getTestConfiguration().addNested(Map.of(
"datasources.default.url", "jdbc:tc:oracle:thin:@/xe",
"datasources.default.driverClassName", "org.testcontainers.jdbc.ContainerDatabaseDriver",
"datasources.default.username", "system",
"datasources.default.password", "oracle",
"datasources.default.connectionTimeout", "60000",
"flyway.datasources.default.locations", "classpath:db/migration",
"flyway.datasources.default.baseline-version", "0",
"flyway.datasources.default.baseline-on-migrate", "true",
"flyway.datasources.default.enabled", "true"));
generatorContext.addDependency(TESTCONTAINERS_ORACLE_XE);
} else {
generatorContext.getTestConfiguration().addNested(jdbcConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import java.util.regex.Pattern;

import static cloud.graal.gdk.GdkUtils.BOM_VERSION_SUFFIX;

/**
* Fixes parent element in platform independent pom.xml and multi-module root pom.xml.
*/
Expand All @@ -34,12 +32,23 @@ public class MavenPlatformPostProcessor implements TemplatePostProcessor {
@NonNull
@Override
public String process(@NonNull String pom) {
return fixParent(pom);

}

@NonNull
private String fixParent(@NonNull String pom) {
int start = pom.indexOf(PARENT_START);
int end = pom.indexOf(PARENT_END, start) + PARENT_END.length();

String top = pom.substring(0, start);
String bottom = pom.substring(end);
String parent = pom.substring(start, end);
parent = VERSION_PATTERN.matcher(parent).replaceAll(String.format("<version>%s</version>", GdkUtils.getMicronautVersion() + BOM_VERSION_SUFFIX));

parent = parent.replace("<groupId>io.micronaut.platform</groupId>", "<groupId>cloud.graal.gdk</groupId>");
parent = parent.replace("<artifactId>micronaut-parent</artifactId>", "<artifactId>gdk-parent</artifactId>");
parent = VERSION_PATTERN.matcher(parent).replaceAll(String.format("<version>%s</version>", GdkUtils.getGdkBomVersion()));

return top + parent + bottom;
}
}
2 changes: 1 addition & 1 deletion gdk/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org.gradle.parallel=true
org.gradle.caching=true
version=4.6.0.1
version=4.6.0.3
Loading

0 comments on commit 3e53582

Please sign in to comment.