Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace custom required options check with standard PicoCLI features #7738

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions besu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,21 @@ dependencies {
implementation 'com.google.guava:guava'
implementation 'com.google.dagger:dagger'
implementation 'com.graphql-java:graphql-java'
implementation 'commons-net:commons-net'
implementation 'info.picocli:picocli'
implementation 'io.vertx:vertx-core'
implementation 'io.vertx:vertx-web'
implementation 'org.apache.commons:commons-lang3'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'io.tmio:tuweni-bytes'
implementation 'io.tmio:tuweni-config'
implementation 'io.tmio:tuweni-toml'
implementation 'io.tmio:tuweni-units'
implementation 'org.apache.commons:commons-lang3'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.hibernate.validator:hibernate-validator'
implementation 'org.rocksdb:rocksdbjni'
implementation 'org.springframework.security:spring-security-crypto'
implementation 'org.xerial.snappy:snappy-java'
implementation 'tech.pegasys:jc-kzg-4844'
implementation 'org.rocksdb:rocksdbjni'
implementation 'commons-net:commons-net'

runtimeOnly 'org.apache.logging.log4j:log4j-jul'
runtimeOnly 'com.splunk.logging:splunk-library-javalogging'
Expand Down
14 changes: 0 additions & 14 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,6 @@ private void configureNativeLibs() {
}

private void validateOptions() {
validateRequiredOptions();
issueOptionWarnings();
validateP2PInterface(p2PDiscoveryOptions.p2pInterface);
validateMiningParams();
Expand Down Expand Up @@ -1475,19 +1474,6 @@ private void validateDataStorageOptions() {
dataStorageOptions.validate(commandLine);
}

private void validateRequiredOptions() {
commandLine
.getCommandSpec()
.options()
.forEach(
option -> {
if (option.required() && option.stringValues().isEmpty()) {
throw new ParameterException(
this.commandLine, "Missing required option: " + option.longestName());
}
});
}

private void validateMiningParams() {
miningOptions.validate(
commandLine, genesisConfigOptionsSupplier.get(), isMergeEnabled(), logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.PrintWriter;

import jakarta.validation.constraints.NotEmpty;
import org.springframework.security.crypto.bcrypt.BCrypt;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.CommandSpec;
Expand Down Expand Up @@ -75,6 +76,7 @@ public void run() {
static class HashSubCommand implements Runnable {

@SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings.
@NotEmpty
@Option(
names = "--password",
arity = "1..1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.util.function.Supplier;

import io.vertx.core.Vertx;
import jakarta.validation.constraints.NotBlank;
import org.apache.tuweni.bytes.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -335,6 +336,7 @@ static class ExportSubCommand implements Runnable {
arity = "1..1")
private final BlockExportFormat format = BlockExportFormat.RLP;

@NotBlank
@Option(
names = "--to",
required = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

import jakarta.validation.constraints.NotBlank;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.ParentCommand;
Expand All @@ -55,6 +56,7 @@ public BackupState() {}
arity = "1..1")
private final Long block = Long.MAX_VALUE;

@NotBlank
@Option(
names = "--backup-path",
required = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.io.Resources;
import jakarta.validation.constraints.NotBlank;
import org.apache.tuweni.bytes.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -70,6 +71,7 @@ class GenerateBlockchainConfig implements Runnable {
private final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM =
Suppliers.memoize(SignatureAlgorithmFactory::getInstance);

@NotBlank
@Option(
required = true,
names = "--config-file",
Expand All @@ -78,6 +80,7 @@ class GenerateBlockchainConfig implements Runnable {
arity = "1..1")
private final File configurationFile = null;

@NotBlank
@Option(
required = true,
names = "--to",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.List;

import com.fasterxml.jackson.databind.node.ObjectNode;
import jakarta.validation.constraints.NotBlank;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.slf4j.Logger;
Expand All @@ -64,6 +65,7 @@ public class RestoreState implements Runnable {

private static final Logger LOG = LoggerFactory.getLogger(RestoreState.class);

@NotBlank
@Option(
names = "--backup-path",
required = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.json.JsonObject;
import jakarta.validation.constraints.NotEmpty;
import org.apache.commons.net.util.SubnetUtils.SubnetInfo;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.tuweni.bytes.Bytes;
Expand Down Expand Up @@ -621,6 +622,7 @@ public void close() {
@CommandLine.Command
public static class TestBesuCommandWithRequiredOption extends TestBesuCommand {

@NotEmpty
@CommandLine.Option(
names = {"--accept-terms-and-conditions"},
description = "You must explicitly accept terms and conditions",
Expand Down
77 changes: 77 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@
<sha256 value="f1c10522cbc763fd351c790b57c251edcc1efd052da78d150ba07b55337f7b2d" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.fasterxml" name="classmate" version="1.5.1">
<artifact name="classmate-1.5.1.jar">
<sha256 value="aab4de3006808c09d25dd4ff4a3611cfb63c95463cfd99e73d2e1680d229a33b" origin="Generated by Gradle"/>
</artifact>
<artifact name="classmate-1.5.1.pom">
<sha256 value="24de66a0029fddc259594c7bc7c5ae046a222c35bf367c739a07297599b51fae" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.fasterxml" name="oss-parent" version="35">
<artifact name="oss-parent-35.pom">
<sha256 value="afc05ed21064eacac8de3002530cb192208bd114eb248417dad1886cbf54056e" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.fasterxml" name="oss-parent" version="43">
<artifact name="oss-parent-43.pom">
<sha256 value="e5585cc1c37079b2e3817a8997945736f158831844d59d0e4d3a45b27611f926" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -2920,6 +2933,14 @@
<sha256 value="a7702c487026802784b5797b62330a8b8d6592bf0f4737b25c67a5eac82659c0" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="jakarta.validation" name="jakarta.validation-api" version="3.0.2">
<artifact name="jakarta.validation-api-3.0.2.jar">
<sha256 value="291c25e6910cc6a7ebd96d4c6baebf6d7c37676c5482c2d96146e901b62c1fc9" origin="Generated by Gradle"/>
</artifact>
<artifact name="jakarta.validation-api-3.0.2.pom">
<sha256 value="0a7b9c6327968afe0d82f7cf4facbda7e157968c5808d69bcb8019863b298dc4" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="javax.annotation" name="javax.annotation-api" version="1.3.2">
<artifact name="javax.annotation-api-1.3.2.jar">
<sha256 value="e04ba5195bcd555dc95650f7cc614d151e4bcd52d29a10b8aa2197f3ab89ab9b" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -3498,6 +3519,11 @@
<sha256 value="b4c4fb9a594b2b5b2a825eea7b4e2a8e0c0b59807e50dd56f403afe7c63823e8" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.apache.maven" name="maven" version="3.6.3">
<artifact name="maven-3.6.3.pom">
<sha256 value="d2d86245ea66149bc14d2dd72bbb961f964dd658b809a0573252c06531eeec16" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.apache.maven" name="maven" version="3.9.6">
<artifact name="maven-3.9.6.pom">
<sha256 value="ba0bf325c52954058e9a7029e40273a1fe06be4a50530f6a4eba46c558a1e4ac" origin="Generated by Gradle"/>
Expand All @@ -3511,6 +3537,11 @@
<sha256 value="b610a3b025982b98576d7664900ace31362f005827051f3698e649d289f3ffb5" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.apache.maven" name="maven-parent" version="33">
<artifact name="maven-parent-33.pom">
<sha256 value="3856e3fcd169502d5f12fe2452604ebf6c7c025f15656bfa558ea99ed29d73ea" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.apache.maven" name="maven-parent" version="41">
<artifact name="maven-parent-41.pom">
<sha256 value="762fcdd4ce8621c5fa0a2cf6495ad26972a8093eb432aa3e402bc2d4e2500c53" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -4816,6 +4847,19 @@
<sha256 value="6d535f94efb663bdb682c9f27a50335394688009642ba7a9677504bc1be4129b" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.hibernate.validator" name="hibernate-validator" version="8.0.1.Final">
<artifact name="hibernate-validator-8.0.1.Final.jar">
<sha256 value="8c1244a498231091fe723d9666a93444ee9f93607245c6b29829dc5fe57a335c" origin="Generated by Gradle"/>
</artifact>
<artifact name="hibernate-validator-8.0.1.Final.pom">
<sha256 value="f747ead364203a836e2a21eb55b7436716576fbd70faf92c4e0128c23dbc426f" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.hibernate.validator" name="hibernate-validator-parent" version="8.0.1.Final">
<artifact name="hibernate-validator-parent-8.0.1.Final.pom">
<sha256 value="34b596f4f3d2ff52b504123db26faad19a61175a6c0b1012d75a7ff29567e727" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.hyperledger.besu" name="arithmetic" version="0.9.7">
<artifact name="arithmetic-0.9.7.jar">
<sha256 value="54b1f4edbbc06bd974c5b3aad5acc21c85213997c8b91b051fe240f90d674f93" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -4982,6 +5026,39 @@
<sha256 value="000dd616298aebd21a9d5731874df083d7298424b91e037b73cbdd07ebc83e0e" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jboss" name="jboss-parent" version="39">
<artifact name="jboss-parent-39.pom">
<sha256 value="04dff075a00094b63061af407d2816d9cde66795acae376a054bdfe8ba31e664" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jboss.arquillian" name="arquillian-bom" version="1.7.0.Alpha10">
<artifact name="arquillian-bom-1.7.0.Alpha10.pom">
<sha256 value="0bf2ce391957e3ae82305a4ccdcdec047cc3127af94eae8073073bd819ec1e1d" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jboss.logging" name="jboss-logging" version="3.4.3.Final">
<artifact name="jboss-logging-3.4.3.Final.jar">
<sha256 value="0b324cca4d550060e51e70cc0045a6cce62f264278ec1f5082aafeb670fcac49" origin="Generated by Gradle"/>
</artifact>
<artifact name="jboss-logging-3.4.3.Final.pom">
<sha256 value="f7639433422e8bf1f397db7575f2ab954cc20f7d1581b33f6d978db30943afec" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jboss.shrinkwrap" name="shrinkwrap-bom" version="1.2.6">
<artifact name="shrinkwrap-bom-1.2.6.pom">
<sha256 value="1c0ac801aa3125bde5e8816ba878a3243259c396d2f38e676e2852a9cc550036" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jboss.shrinkwrap.descriptors" name="shrinkwrap-descriptors-bom" version="2.0.0">
<artifact name="shrinkwrap-descriptors-bom-2.0.0.pom">
<sha256 value="878eb071ad1f4b0c81568536b2a3a4f7de85a814afc5b196d9a99b5e3c0a6583" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jboss.shrinkwrap.resolver" name="shrinkwrap-resolver-bom" version="3.1.4">
<artifact name="shrinkwrap-resolver-bom-3.1.4.pom">
<sha256 value="53d45df757388b693a37493b74e0d7a938c5734c15f82629d40a29dea9ceb74f" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains" name="annotations" version="13.0">
<artifact name="annotations-13.0.jar">
<sha256 value="ace2a10dc8e2d5fd34925ecac03e4988b2c0f851650c94b8cef49ba1bd111478" origin="Generated by Gradle"/>
Expand Down
2 changes: 2 additions & 0 deletions gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ dependencyManagement {

dependency 'org.fusesource.jansi:jansi:2.4.1'

dependency 'org.hibernate.validator:hibernate-validator:8.0.1.Final'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surprised to see this, can we narrow this dependency down to just jakarta?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jakarta is only the API, we need an implementation and it is provided by hibernate-validator


dependencySet(group: 'org.hyperledger.besu', version: '0.9.7') {
entry 'arithmetic'
entry 'ipa-multipoint'
Expand Down
Loading