Skip to content

Commit

Permalink
Upgrade to Gradle 7.2 and add feature variants for Jakarta XML parsin…
Browse files Browse the repository at this point in the history
…g support (Fixes ehcache#2946)
  • Loading branch information
chrisdennis committed Nov 24, 2021
1 parent 43141f0 commit 499e486
Show file tree
Hide file tree
Showing 1,565 changed files with 6,145 additions and 1,985 deletions.
24 changes: 3 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
*/target/

build/
*/src/generated/
# Gradle
.gradle/

.project
.classpath
.settings/org.eclipse.m2e.core.prefs
*/.classpath
*.prefs

*.iml
.idea
out/

.nb-gradle
.nb-gradle-properties

/classes

**/*.*~
**/build/
!**/src/**/build/
2 changes: 0 additions & 2 deletions 107/gradle.properties

This file was deleted.

18 changes: 0 additions & 18 deletions api/gradle.properties

This file was deleted.

67 changes: 67 additions & 0 deletions build-logic/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
plugins {
id 'java-gradle-plugin'
}

repositories {
gradlePluginPortal()
mavenCentral()
}

gradlePlugin {
plugins {
internalModule {
id = 'org.ehcache.build.internal-module'
implementationClass = 'org.ehcache.build.InternalEhcacheModule'
}
publicModule {
id = 'org.ehcache.build.public-module'
implementationClass = 'org.ehcache.build.PublicEhcacheModule'
}
clusteredModule {
id = 'org.ehcache.build.clustered-module'
implementationClass = 'org.ehcache.build.ClusteredEhcacheModule'
}
serverModule {
id = 'org.ehcache.build.clustered-server-module'
implementationClass = 'org.ehcache.build.ClusteredServerModule'
}
distribution {
id = 'org.ehcache.build.package'
implementationClass = 'org.ehcache.build.EhcachePackage'
}

variant {
id = 'org.ehcache.build.plugins.variant'
implementationClass = 'org.ehcache.build.plugins.VariantPlugin'
}

base {
id = 'org.ehcache.build.conventions.base'
implementationClass = 'org.ehcache.build.conventions.BaseConvention'
}
java {
id = 'org.ehcache.build.conventions.java'
implementationClass = 'org.ehcache.build.conventions.JavaConvention'
}
javaLibrary {
id = 'org.ehcache.build.conventions.java-library'
implementationClass = 'org.ehcache.build.conventions.JavaLibraryConvention'
}
war {
id = 'org.ehcache.build.conventions.war'
implementationClass = 'org.ehcache.build.conventions.WarConvention'
}
}
}

dependencies {
api gradleApi()
api 'biz.aQute.bnd:biz.aQute.bnd.gradle:6.0.0'
api 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0'
api 'org.unbroken-dome.gradle-plugins:gradle-xjc-plugin:2.0.0'
api 'com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.9'
implementation 'biz.aQute.bnd:biz.aQute.bndlib:6.0.0'
implementation 'org.osgi:org.osgi.service.component.annotations:1.5.0'
implementation 'org.apache.felix:org.apache.felix.scr.generator:1.18.4'
implementation 'org.apache.felix:org.apache.felix.scr.ds-annotations:1.2.10'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.ehcache.build;

import org.gradle.api.Project;

public class ClusteredEhcacheModule extends EhcacheModule {

@Override
public void apply(Project project) {
project.setGroup("org.ehcache.modules.clustered");
super.apply(project);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.ehcache.build;

import org.ehcache.build.conventions.DeployConvention;
import org.ehcache.build.plugins.VoltronPlugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;

public class ClusteredServerModule implements Plugin<Project> {

@Override
public void apply(Project project) {
project.setGroup("org.ehcache.modules.clustered");

project.getPlugins().apply(DeployConvention.class);
project.getPlugins().apply(VoltronPlugin.class);
}
}
17 changes: 17 additions & 0 deletions build-logic/src/main/java/org/ehcache/build/EhcacheModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.ehcache.build;

import org.ehcache.build.conventions.BndConvention;
import org.ehcache.build.conventions.JavaLibraryConvention;
import org.ehcache.build.conventions.DeployConvention;
import org.gradle.api.Plugin;
import org.gradle.api.Project;

public abstract class EhcacheModule implements Plugin<Project> {

@Override
public void apply(Project project) {
project.getPlugins().apply(JavaLibraryConvention.class);
project.getPlugins().apply(DeployConvention.class);
project.getPlugins().apply(BndConvention.class);
}
}
16 changes: 16 additions & 0 deletions build-logic/src/main/java/org/ehcache/build/EhcachePackage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.ehcache.build;

import org.ehcache.build.conventions.DeployConvention;
import org.ehcache.build.plugins.PackagePlugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;

public class EhcachePackage implements Plugin<Project> {

@Override
public void apply(Project project) {
project.setGroup("org.ehcache");
project.getPlugins().apply(PackagePlugin.class);
project.getPlugins().apply(DeployConvention.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.ehcache.build;

import org.gradle.api.Project;

public class InternalEhcacheModule extends EhcacheModule {

@Override
public void apply(Project project) {
project.setGroup("org.ehcache.modules");
super.apply(project);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.ehcache.build;

import org.gradle.api.Project;

public class PublicEhcacheModule extends EhcacheModule {
@Override
public void apply(Project project) {
project.setGroup("org.ehcache");
super.apply(project);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.ehcache.build.conventions;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ResolutionStrategy;
import org.gradle.api.plugins.BasePlugin;

import java.net.URI;

public class BaseConvention implements Plugin<Project> {

@Override
public void apply(Project project) {
project.getPlugins().apply(BasePlugin.class);

project.getRepositories().mavenCentral();
project.getRepositories().maven(repo -> repo.setUrl(URI.create("https://repo.terracotta.org/maven2")));

project.getConfigurations().configureEach(
config -> config.resolutionStrategy(ResolutionStrategy::failOnVersionConflict)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.ehcache.build.conventions;

import aQute.bnd.gradle.BndBuilderPlugin;
import aQute.bnd.gradle.BundleTaskExtension;
import aQute.bnd.osgi.Constants;
import org.ehcache.build.plugins.osgids.OsgiDsPlugin;
import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ExternalDependency;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.publish.plugins.PublishingPlugin;
import org.gradle.api.tasks.bundling.Jar;

import static java.lang.System.lineSeparator;
import static java.util.stream.Collectors.joining;

public class BndConvention implements Plugin<Project> {

@Override
public void apply(Project project) {
project.getPlugins().apply(BndBuilderPlugin.class);
project.getPlugins().apply(OsgiDsPlugin.class);
project.getPlugins().apply(DeployConvention.class);

project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class, jar -> {
jar.getExtensions().configure(BundleTaskExtension.class, bundle -> configureBundleDefaults(project, bundle));
});

project.getConfigurations().named("baseline", config -> {
config.getResolutionStrategy().getComponentSelection().all(selection -> {
if (!selection.getCandidate().getVersion().matches("^\\d+(?:\\.\\d+)*$")) {
selection.reject("Only full releases can be used as OSGi baselines");
}
});
});

String dependencyNotation = project.getGroup() + ":" + project.getName() + ":(," + project.getVersion() + "[";
Dependency baseline = project.getDependencies().add("baseline", dependencyNotation);
if (baseline instanceof ProjectDependency) {
throw new GradleException("Baseline should not be a project dependency");
} else if (baseline instanceof ExternalDependency) {
((ExternalDependency) baseline).setForce(true);
((ExternalDependency) baseline).setTransitive(false);
} else {
throw new IllegalArgumentException("Unexpected dependency type: " + baseline);
}
}

public static void configureBundleDefaults(Project project, BundleTaskExtension bundle) {
MapProperty<String, String> defaultInstructions = project.getObjects().mapProperty(String.class, String.class);
bundleDefaults(project).execute(defaultInstructions);
bundle.bnd(defaultInstructions.map(kv -> kv.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(joining(lineSeparator()))));
}

public static Action<MapProperty<String, String>> bundleDefaults(Project project) {
return properties -> {
project.getPlugins().withType(PublishingPlugin.class, publishingPlugin -> {
project.getExtensions().getByType(PublishingExtension.class).getPublications().withType(MavenPublication.class).stream().findAny().ifPresent(publication -> {
properties.put(Constants.BUNDLE_NAME, publication.getPom().getName());
properties.put(Constants.BUNDLE_DESCRIPTION, publication.getPom().getDescription());
});
});
properties.put(Constants.BUNDLE_SYMBOLICNAME, project.getGroup() + "." + project.getName());
properties.put(Constants.BUNDLE_DOCURL, "http://ehcache.org");
properties.put(Constants.BUNDLE_LICENSE, "LICENSE");
properties.put(Constants.BUNDLE_VENDOR, "Terracotta Inc., a wholly-owned subsidiary of Software AG USA, Inc.");
properties.put(Constants.BUNDLE_VERSION, osgiFixedVersion(project.getVersion().toString()));
properties.put(Constants.SERVICE_COMPONENT, "OSGI-INF/*.xml");
};
}

public static String osgiFixedVersion(String version) {
/*
* The bnd gradle plugin does not handle our 2-digit snapshot versioning scheme very well. It maps `x.y-SNAPSHOT`
* to `x.y.0.SNAPSHOT`. This is bad since `x.y.0.SNAPSHOT` is considered to be less than *all* `x.y.z`. This means
* the baseline version range expression `(,x.y.0.SNAPSHOT[` will always pick the last release from the previous
* minor line. To fix this we manually map to a 3-digit snapshot version where the 3rd digit is a number chosen
* to be higher than we would ever release ('All the worlds a VAX').
*/
return version.replaceAll("^(\\d+.\\d+)-SNAPSHOT$", "$1.999-SNAPSHOT");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.ehcache.build.conventions;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.quality.CheckstyleExtension;
import org.gradle.api.plugins.quality.CheckstylePlugin;

import java.util.Map;

public class CheckstyleConvention implements Plugin<Project> {
@Override
public void apply(Project project) {
project.getPlugins().apply(CheckstylePlugin.class);

project.getExtensions().configure(CheckstyleExtension.class, checkstyle -> {
checkstyle.setConfigFile(project.getRootProject().file("config/checkstyle.xml"));
Map<String, Object> properties = checkstyle.getConfigProperties();
properties.put("projectDir", project.getProjectDir());
properties.put("rootDir", project.getRootDir());
});
}
}
Loading

0 comments on commit 499e486

Please sign in to comment.