Skip to content

Commit

Permalink
Cleanup Module patching
Browse files Browse the repository at this point in the history
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
  • Loading branch information
jjohannes committed Sep 13, 2023
1 parent 56c3d74 commit d695cfa
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +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-slf4j-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.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' to 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 @@ -20,7 +20,7 @@ plugins {

val besuNativeVersion = "0.6.1"
val besuVersion = "23.7.2"
val bouncycastleVersion = "1.70"
val bouncycastleVersion = "1.76"
val daggerVersion = "2.42"
val eclipseCollectionsVersion = "10.4.0"
val grpcVersion = "1.54.1"
Expand All @@ -33,7 +33,7 @@ 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 @@ -50,7 +50,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 @@ -65,12 +64,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 @@ -89,7 +86,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 @@ -105,7 +101,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
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 @@ -95,11 +97,12 @@ xtestModuleInfo {
requires("com.swirlds.test.framework")
requires("dagger")
requires("headlong")
requires("io.netty.transport.epoll")
requires("javax.inject")
requires("org.junit.jupiter.api")
requires("org.mockito")
requires("org.mockito.junit.jupiter")
runtimeOnly("io.netty.transport.epoll.linux.x86_64")
runtimeOnly("io.netty.transport.epoll.linux.aarch_64")
}

jmhModuleInfo {
Expand Down Expand Up @@ -135,14 +138,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
2 changes: 1 addition & 1 deletion hedera-node/test-clients/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
requires org.apache.commons.lang3;
requires org.apache.logging.log4j.core;
requires org.bouncycastle.provider;
requires org.hyperledger.besu.internal.crypto;
requires org.hyperledger.besu.datatypes;
requires org.hyperledger.besu.evm;
requires org.hyperledger.besu.internal.algorithms;
requires org.json;
requires org.opentest4j;
requires tuweni.units;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
requires java.management;
requires java.scripting;
requires java.sql;
requires javafx.base;
requires jdk.management;
requires jdk.net;
requires org.bouncycastle.pkix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ testModuleInfo {
requires("com.swirlds.common.test.fixtures")
requires("com.swirlds.config.api")
requires("com.swirlds.test.framework")
requires("com.google.truth")
requires("org.assertj.core")
requires("org.junit.jupiter.params")
requires("org.mockito")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.swirlds.common.test.threading;

import static com.google.common.truth.Truth.assertThat;
import static com.swirlds.common.threading.manager.AdHocThreadManager.getStaticThreadManager;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

Expand Down Expand Up @@ -92,24 +92,24 @@ void testException() {
ParallelExecutionException ex;

ex = assertThrows(ParallelExecutionException.class, () -> executor.doParallel(task1, task2));
assertThat(ex).hasCauseThat().isSameInstanceAs(exception1);
assertThat(ex.getSuppressed()).hasLength(1);
assertThat(ex.getSuppressed()[0]).hasCauseThat().isSameInstanceAs(exception2);
assertThat(ex).hasCause(exception1);
assertThat(ex.getSuppressed()).hasSize(1);
assertThat(ex.getSuppressed()[0]).hasCause(exception2);

ex = assertThrows(ParallelExecutionException.class, () -> executor.doParallel(task1, noEx));
assertThat(ex).hasCauseThat().isSameInstanceAs(exception1);
assertThat(ex).hasCause(exception1);
assertThat(ex.getSuppressed()).isEmpty();

ex = assertThrows(ParallelExecutionException.class, () -> executor.doParallel(noEx, task2));
assertThat(ex).hasCauseThat().hasCauseThat().isSameInstanceAs(exception2);
assertThat(ex.getCause()).hasCause(exception2);
assertThat(ex.getSuppressed()).isEmpty();

ex = assertThrows(ParallelExecutionException.class, () -> executor.doParallel(task3, noEx));
assertThat(ex).hasCauseThat().isSameInstanceAs(error1);
assertThat(ex).hasCause(error1);
assertThat(ex.getSuppressed()).isEmpty();

ex = assertThrows(ParallelExecutionException.class, () -> executor.doParallel(noEx, task3));
assertThat(ex).hasCauseThat().hasCauseThat().isSameInstanceAs(error1);
assertThat(ex.getCause()).hasCause(error1);
assertThat(ex.getSuppressed()).isEmpty();
}
}

0 comments on commit d695cfa

Please sign in to comment.