Skip to content

Commit

Permalink
Cleanup Module patching (#8561)
Browse files Browse the repository at this point in the history
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
  • Loading branch information
jjohannes authored and imalygin committed Nov 13, 2023
1 parent d6871d9 commit e7604f3
Show file tree
Hide file tree
Showing 26 changed files with 302 additions and 180 deletions.
2 changes: 1 addition & 1 deletion build-logic/project-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
implementation("gradle.plugin.lazy.zoo.gradle:git-data-plugin:1.2.2")
implementation("me.champeau.jmh:jmh-gradle-plugin:0.7.1")
implementation("net.swiftzer.semver:semver:1.3.0")
implementation("org.gradlex:extra-java-module-info:1.4.2")
implementation("org.gradlex:extra-java-module-info:1.5")
implementation("org.gradlex:java-ecosystem-capabilities:1.3.1")
implementation("org.gradlex:java-module-dependencies:1.4.1")
implementation("org.owasp:dependency-check-gradle:8.4.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,25 @@ javaModuleDependencies {
moduleNameToGA.put("com.swirlds.config.api", "com.swirlds:swirlds-config-api")
moduleNameToGA.put("com.swirlds.config.impl", "com.swirlds:swirlds-config-impl")
moduleNameToGA.put("com.swirlds.merkle.test", "com.swirlds:swirlds-merkle-test")
moduleNameToGA.put("com.swirlds.merkledb", "com.swirlds:swirlds-merkledb")
moduleNameToGA.put("com.swirlds.platform.core", "com.swirlds:swirlds-platform-core")
moduleNameToGA.put("com.swirlds.platform.gui", "com.swirlds:swirlds-platform-gui")
moduleNameToGA.put("com.swirlds.test.framework", "com.swirlds:swirlds-test-framework")

moduleNameToGA.put(
"com.hedera.hashgraph.protobuf.java.api",
"com.hedera.hashgraph:hedera-protobuf-java-api"
)
// Other Hedera modules
moduleNameToGA.put("com.hedera.pbj.runtime", "com.hedera.pbj:pbj-runtime")
moduleNameToGA.put("hamcrest.core", "org.hamcrest:hamcrest-core")
moduleNameToGA.put("io.grpc", "io.helidon.grpc:io.grpc")
moduleNameToGA.put("io.helidon.webserver.http2", "io.helidon.webserver:helidon-webserver-http2")
moduleNameToGA.put("io.netty.codec.http", "io.netty:netty-codec-http")
moduleNameToGA.put("io.netty.codec.http2", "io.netty:netty-codec-http2")
moduleNameToGA.put("io.netty.codec.socks", "io.netty:netty-codec-socks")
moduleNameToGA.put("io.netty.handler.proxy", "io.netty:netty-handler-proxy")
moduleNameToGA.put("io.perfmark", "io.perfmark:perfmark-api")
moduleNameToGA.put(
"org.apache.logging.log4j.slf4j",
"org.apache.logging.log4j:log4j-slf4j2-impl"
)
moduleNameToGA.put("org.bouncycastle.util", "org.bouncycastle:bcutil-jdk15on")

// Third-party modules
moduleNameToGA.put(
"org.eclipse.collections.api",
"org.eclipse.collections:eclipse-collections-api"
"io.netty.transport.epoll.linux.x86_64",
"io.netty:netty-transport-native-epoll|io.netty:netty-transport-native-epoll-linux-x86_64"
)
moduleNameToGA.put(
"org.eclipse.collections.impl",
"org.eclipse.collections:eclipse-collections"
"io.netty.transport.epoll.linux.aarch_64",
"io.netty:netty-transport-native-epoll|io.netty:netty-transport-native-epoll-linux-aarch_64"
)
moduleNameToGA.put("org.hamcrest", "org.hamcrest:hamcrest")
moduleNameToGA.put("org.hyperledger.besu.datatypes", "org.hyperledger.besu:besu-datatypes")
moduleNameToGA.put("org.hyperledger.besu.evm", "org.hyperledger.besu:evm")
moduleNameToGA.put("org.hyperledger.besu.secp256k1", "org.hyperledger.besu:secp256k1")
moduleNameToGA.put("org.hyperledger.besu.internal.rlp", "org.hyperledger.besu.internal:rlp")

// Testing only
moduleNameToGA.put("org.mockito.junit.jupiter", "org.mockito:mockito-junit-jupiter")
moduleNameToGA.put("org.objenesis", "org.objenesis:objenesis")
moduleNameToGA.put("org.antlr.antlr4.runtime", "org.antlr:antlr4-runtime")
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ tasks.withType<ShadowJar>().configureEach {
// Defer the resolution of 'runtimeClasspath'. This is an issue in the shadow
// plugin that it automatically accesses the files in 'runtimeClasspath' while
// Gradle is building the task graph. The three lines below work around that.
// See: https://github.com/johnrengelman/shadow/issues/882
inputs.files(project.configurations.runtimeClasspath)
configurations = emptyList()
doFirst { configurations = listOf(project.configurations.runtimeClasspath.get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@

package com.hedera.hashgraph.gradlebuild.rules

import org.gradle.api.artifacts.CacheableRule
import org.gradle.api.artifacts.ComponentMetadataContext
import org.gradle.api.artifacts.ComponentMetadataRule

/**
* Replace all 'grpc' dependencies with a singe dependency to
* 'io.helidon.grpc:io.grpc' which is a re-packaged Modular Jar
* of all the 'grpc' libraries.
*/
@CacheableRule
abstract class IoGrpcDependencyMetadataRule : ComponentMetadataRule {

override fun execute(context: ComponentMetadataContext) {
Expand All @@ -27,6 +34,7 @@ abstract class IoGrpcDependencyMetadataRule : ComponentMetadataRule {
removeAll { it.name == "grpc-api" }
removeAll { it.name == "grpc-context" }
removeAll { it.name == "grpc-core" }
removeAll { it.name == "error_prone_annotations" }
removeAll { it.group == "com.google.code.findbugs" }
add("io.helidon.grpc:io.grpc")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,30 @@

package com.hedera.hashgraph.gradlebuild.rules

import org.gradle.api.artifacts.CacheableRule
import org.gradle.api.artifacts.ComponentMetadataContext
import org.gradle.api.artifacts.ComponentMetadataRule

/**
* Configures native Jars of 'io.netty.native.epoll' so that they can be selected by 'capability'.
* https://docs.gradle.org/current/userguide/component_metadata_rules.html#making_different_flavors_of_a_library_available_through_capabilities
*/
@CacheableRule
abstract class IoNettyNativeEpollMetadataRule : ComponentMetadataRule {

override fun execute(context: ComponentMetadataContext) {
val name = context.details.id.name
val version = context.details.id.version
context.details.allVariants {
withFiles {
// Always pick 'linux-x86_64' and 'linux-aarch_64' by default
removeAllFiles()
addFile("$name-$version-linux-x86_64.jar")
addFile("$name-$version-linux-aarch_64.jar")
listOf("linux-x86_64", "linux-aarch_64").forEach { nativeVariant ->
context.details.addVariant(nativeVariant, "runtime") {
withCapabilities {
removeCapability("io.netty", "netty-transport-native-epoll")
addCapability("io.netty", "netty-transport-native-epoll-$nativeVariant", version)
}
withFiles {
removeAllFiles()
addFile("$name-$version-$nativeVariant.jar")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@

package com.hedera.hashgraph.gradlebuild.rules

import org.gradle.api.artifacts.CacheableRule
import org.gradle.api.artifacts.ComponentMetadataContext
import org.gradle.api.artifacts.ComponentMetadataRule

/**
* Removes unused transitive dependencies of 'io.prometheus:simpleclient'.
*/
@CacheableRule
abstract class IoPrometheusSimpleclientMetadataRule : ComponentMetadataRule {

override fun execute(context: ComponentMetadataContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@

package com.hedera.hashgraph.gradlebuild.rules

import org.gradle.api.artifacts.CacheableRule
import org.gradle.api.artifacts.ComponentMetadataContext
import org.gradle.api.artifacts.ComponentMetadataRule

abstract class RemoveFindbugsAnnotationsMetadataRule : ComponentMetadataRule {
/**
* Removes annotation libraries for annotations that this project does not require
* at runtime or compile time. These are typically annotations used by additional
* code analysis tools that are not used by this project.
*/
@CacheableRule
abstract class RemoveAnnotationLibrariesMetadataRule : ComponentMetadataRule {

override fun execute(context: ComponentMetadataContext) {
context.details.allVariants {
withDependencies {
removeAll { it.name == "animal-sniffer-annotations" }
removeAll { it.name == "checker-qual" }
removeAll { it.name == "error_prone_annotations" }
removeAll { it.name == "j2objc-annotations" }
removeAll { it.name == "listenablefuture" }
removeAll { it.group == "com.google.android" && it.name == "annotations"}
// 'findbugs' annotations are not used and cause split package with 'javax.annotation-api'
removeAll { it.group == "com.google.code.findbugs" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@

package com.hedera.hashgraph.gradlebuild.rules

import org.gradle.api.artifacts.CacheableRule
import org.gradle.api.artifacts.ComponentMetadataContext
import org.gradle.api.artifacts.ComponentMetadataRule

abstract class IoGrpcMetadataRule : ComponentMetadataRule {
/**
* Kotlin 'kotlin-stdlib-common' (which is not a JPMS module) is not required at runtime, if the
* runtime is a JVM. It exists for Kotlins multi-platform aspect (which we do not care for).
*/
@CacheableRule
abstract class RemoveKotlinStdlibCommonMetadataRule : ComponentMetadataRule {

override fun execute(context: ComponentMetadataContext) {
context.details.allVariants {
withDependencies {
removeAll { it.name == "checker-qual" }
removeAll { it.name == "failureaccess" }
removeAll { it.name == "listenablefuture" }
removeAll { it.name == "kotlin-stdlib-common" }
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions hedera-dependency-versions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ val eclipseCollectionsVersion = "10.4.0"
val grpcVersion = "1.54.1"
val helidonVersion = "3.2.1"
val jacksonVersion = "2.13.5"
val log4jVersion = "2.20.0"
val log4jVersion = "2.21.1"
val mockitoVersion = "4.11.0"
val nettyVersion = "4.1.87.Final"
val prometheusVersion = "0.16.0"
val protobufVersion = "3.21.7"
val systemStubsVersion = "2.0.2"
val testContainersVersion = "1.17.2"
val tuweniVersion = "2.3.1"
val tuweniVersion = "2.4.2"

dependencies {
api(enforcedPlatform("io.netty:netty-bom:$nettyVersion"))
Expand All @@ -53,7 +53,6 @@ moduleInfo {
version("com.google.jimfs", "1.2")
version("com.google.protobuf", protobufVersion)
version("com.google.protobuf.util", protobufVersion)
version("com.google.truth", "1.1.3")
version("com.hedera.pbj.runtime", "0.7.4")
version("com.sun.jna", "5.12.1")
version("dagger", daggerVersion)
Expand All @@ -68,12 +67,10 @@ moduleInfo {
version("io.netty.handler", nettyVersion)
version("io.netty.transport", nettyVersion)
version("io.netty.transport.classes.epoll", nettyVersion)
version("io.netty.transport.epoll", nettyVersion)
version("io.perfmark", "0.25.0")
version("io.prometheus.simpleclient", prometheusVersion)
version("io.prometheus.simpleclient.httpserver", prometheusVersion)
version("java.annotation", "1.3.2")
version("javafx.base", "17")
version("javax.inject", "1")
version("lazysodium.java", "5.1.1")
version("net.i2p.crypto.eddsa", "0.3.0")
Expand All @@ -92,7 +89,6 @@ moduleInfo {
version("org.eclipse.collections.api", eclipseCollectionsVersion)
version("org.eclipse.collections.impl", eclipseCollectionsVersion)
version("org.hamcrest", "2.2")
version("org.hyperledger.besu.internal.crypto", besuVersion)
version("org.hyperledger.besu.datatypes", besuVersion)
version("org.hyperledger.besu.evm", besuVersion)
version("org.hyperledger.besu.secp256k1", besuNativeVersion)
Expand All @@ -107,7 +103,6 @@ moduleInfo {
version("org.testcontainers", testContainersVersion)
version("org.testcontainers.junit.jupiter", testContainersVersion)
version("org.yaml.snakeyaml", "1.33")
version("portmapper", "2.0.4")
version("tuweni.bytes", tuweniVersion)
version("tuweni.units", tuweniVersion)
version("uk.org.webcompere.systemstubs.core", systemStubsVersion)
Expand Down
1 change: 1 addition & 0 deletions hedera-node/hapi-fees/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
requires org.apache.commons.lang3;
requires org.apache.logging.log4j;
requires static com.github.spotbugs.annotations;
requires static java.compiler; // javax.annotation.processing.Generated
}
1 change: 1 addition & 0 deletions hedera-node/hapi-utils/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
requires org.bouncycastle.provider;
requires org.hyperledger.besu.secp256k1;
requires static com.github.spotbugs.annotations;
requires static java.compiler; // javax.annotation.processing.Generated
}
32 changes: 27 additions & 5 deletions hedera-node/hedera-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ mainModuleInfo {
annotationProcessor("dagger.compiler")

// This is needed to pick up and include the native libraries for the netty epoll transport
runtimeOnly("io.netty.transport.epoll")
runtimeOnly("io.netty.transport.epoll.linux.x86_64")
runtimeOnly("io.netty.transport.epoll.linux.aarch_64")
}

testModuleInfo {
Expand Down Expand Up @@ -61,12 +62,13 @@ itestModuleInfo {
requires("grpc.netty")
requires("grpc.stub")
requires("io.grpc")
requires("io.netty.transport.epoll")
requires("org.apache.logging.log4j")
requires("org.assertj.core")
requires("org.bouncycastle.provider")
requires("org.junit.jupiter.api")
requires("org.junit.jupiter.params")
runtimeOnly("io.netty.transport.epoll.linux.x86_64")
runtimeOnly("io.netty.transport.epoll.linux.aarch_64")
}

xtestModuleInfo {
Expand Down Expand Up @@ -96,7 +98,6 @@ xtestModuleInfo {
requires("com.swirlds.test.framework")
requires("dagger")
requires("headlong")
requires("io.netty.transport.epoll")
requires("javax.inject")
requires("org.assertj.core")
requires("org.hyperledger.besu.datatypes")
Expand All @@ -105,6 +106,8 @@ xtestModuleInfo {
requires("org.mockito")
requires("org.mockito.junit.jupiter")
requires("tuweni.bytes")
runtimeOnly("io.netty.transport.epoll.linux.x86_64")
runtimeOnly("io.netty.transport.epoll.linux.aarch_64")
}

jmhModuleInfo {
Expand Down Expand Up @@ -140,14 +143,33 @@ tasks.jar {

// Copy dependencies into `data/lib`
val copyLib =
tasks.register<Copy>("copyLib") {
tasks.register<Sync>("copyLib") {
from(project.configurations.getByName("runtimeClasspath"))
into(layout.projectDirectory.dir("../data/lib"))

doLast {
val nonModulalJars =
destinationDir
.listFiles()!!
.mapNotNull { jar ->
if (zipTree(jar).none { it.name == "module-info.class" }) {
jar.name
} else {
null
}
}
.sorted()
if (nonModulalJars.isNotEmpty()) {
throw RuntimeException(
"Jars without 'module-info.class' in 'data/lib'\n${nonModulalJars.joinToString("\n")}"
)
}
}
}

// Copy built jar into `data/apps` and rename HederaNode.jar
val copyApp =
tasks.register<Copy>("copyApp") {
tasks.register<Sync>("copyApp") {
from(tasks.jar)
into(layout.projectDirectory.dir("../data/apps"))
rename { "HederaNode.jar" }
Expand Down
1 change: 1 addition & 0 deletions hedera-node/hedera-app/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
requires org.apache.commons.lang3;
requires org.apache.logging.log4j;
requires static com.github.spotbugs.annotations;
requires static java.compiler; // javax.annotation.processing.Generated

exports com.hedera.node.app to
com.swirlds.platform.core,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
requires com.hedera.node.config;
requires com.swirlds.config.api;
requires static com.github.spotbugs.annotations;
requires static java.compiler; // javax.annotation.processing.Generated

provides com.hedera.node.app.service.consensus.ConsensusService with
ConsensusServiceImpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
requires transitive dagger;
requires transitive javax.inject;
requires static com.github.spotbugs.annotations;
requires static java.compiler; // javax.annotation.processing.Generated

provides com.hedera.node.app.service.file.FileService with
FileServiceImpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,5 @@
requires org.eclipse.collections.impl;
requires org.hyperledger.besu.secp256k1;
requires static com.github.spotbugs.annotations;
requires static java.compiler; // javax.annotation.processing.Generated
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
requires com.swirlds.config.api;
requires org.apache.logging.log4j;
requires static com.github.spotbugs.annotations;
requires static java.compiler; // javax.annotation.processing.Generated

provides com.hedera.node.app.service.networkadmin.FreezeService with
FreezeServiceImpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
requires com.hedera.pbj.runtime;
requires com.swirlds.config.api;
requires static com.github.spotbugs.annotations;
requires static java.compiler; // javax.annotation.processing.Generated

exports com.hedera.node.app.service.schedule.impl;
exports com.hedera.node.app.service.schedule.impl.handlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
requires com.swirlds.common;
requires org.bouncycastle.provider;
requires static com.github.spotbugs.annotations;
requires static java.compiler; // javax.annotation.processing.Generated

exports com.hedera.node.app.service.contract.impl;
exports com.hedera.node.app.service.contract.impl.exec.scope;
Expand Down

0 comments on commit e7604f3

Please sign in to comment.