diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index 748730c3a..000000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright the Hyperledger Fabric contributors. All rights reserved. -# -# SPDX-License-Identifier: Apache-2.0 - -name: Pull Request Workflow -on: - # push: - # branches: - # - main - # - release-2.5 - pull_request: - branches: - - main - - release-2.5 - workflow_dispatch: - -# If a updated change comes into a PR, then cancel any inflight runs for the PR -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - - pr_build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '11' - cache: 'gradle' - - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v1.0.5 - - name: Dependency Check - uses: gradle/gradle-build-action@v2.3.3 - with: - arguments: | - :fabric-chaincode-shim:dependencyCheckAnalyze - - name: Build and Unit test - uses: gradle/gradle-build-action@v2.3.3 - with: - arguments: | - :fabric-chaincode-shim:build - -xdependencyCheckAnalyze - - # Run the integration tests on the repo - pr_call_intergationtest: - needs: [pr_build] - uses: ./.github/workflows/integrationtest.yml diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 000000000..22777bbd7 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,25 @@ +# Copyright the Hyperledger Fabric contributors. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +name: Pull request + +on: + pull_request: + branches: + - main + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + test: + uses: ./.github/workflows/test.yml + + pull-request: + needs: test + name: Pull request success + runs-on: ubuntu-latest + steps: + - run: "true" diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 000000000..3d2988fc5 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,14 @@ +# Copyright the Hyperledger Fabric contributors. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +name: Push + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + test: + uses: ./.github/workflows/test.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/release.yml similarity index 71% rename from .github/workflows/publish.yml rename to .github/workflows/release.yml index 62ae935d9..a8038c828 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/release.yml @@ -2,46 +2,43 @@ # # SPDX-License-Identifier: Apache-2.0 +name: Release -# Workflow will only run on tag creation. It will run the integration tests first to confirm that the build is sound and then -# and only then do the publishing -name: Publish Workflow on: - create: + push: tags: - - "*" + - 'v[0-9]+.[0-9]+.[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+-*' workflow_dispatch: - + jobs: - - # Run the integration tests on the repo, before moving to the publishing. - # Run the integration tests on the repo - publish_call_intergationtest: - uses: ./.github/workflows/integrationtest.yml + test: + uses: ./.github/workflows/test.yml - # Publishing steps to both the Github Packages and the Sonatype publishjars: strategy: fail-fast: false matrix: - publish_target: ["publishAllPublicationsToGithubPackagesRepository","publishAllPublicationsToReleaseRepository"] + publish_target: + - publishAllPublicationsToGithubPackagesRepository + - publishAllPublicationsToReleaseRepository runs-on: ubuntu-latest - needs: [publish_call_intergationtest] + needs: test steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '11' cache: 'gradle' - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v1.0.5 + uses: gradle/wrapper-validation-action@v1 - name: Push to registry ${{ matrix.publish_target }} run: | set -xev ./gradlew -Psigning.key="${SIGNING_KEY}" -Psigning.password="${SIGNING_PASSWORD}" -PossrhUsername="${OSSRH_USER}" -PossrhPassword="${OSSRH_PASSWORD}" ${TARGET} - env: + env: SIGNING_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} SIGNING_KEY: ${{ secrets.OSSRH_GPG_SECRET_KEY }} OSSRH_USER: ${{ secrets.OSSRH_USERNAME }} @@ -54,30 +51,30 @@ jobs: strategy: fail-fast: false matrix: - DOCKER_REGISTRY: ["docker.io","ghcr.io"] + DOCKER_REGISTRY: + - 'docker.io' + - 'ghcr.io' runs-on: ubuntu-latest - needs: [publish_call_intergationtest] + needs: test permissions: contents: read packages: write steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '11' cache: 'gradle' - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v1.0.5 - - name: Build the depencies needed for the image - uses: gradle/gradle-build-action@v2.3.3 + uses: gradle/wrapper-validation-action@v1 + - name: Build the dependencies needed for the image + uses: gradle/gradle-build-action@v2 with: - arguments: | - :fabric-chaincode-docker:copyAllDeps -x dependencyCheckAnalyze - + arguments: | + :fabric-chaincode-docker:copyAllDeps - name: Set up QEMU uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 with: @@ -85,14 +82,12 @@ jobs: config-inline: | [worker.oci] max-parallelism = 1 - - name: Login to the ${{ matrix.DOCKER_REGISTRY }} Container Registry uses: docker/login-action@v2 with: registry: ${{ matrix.DOCKER_REGISTRY }} username: ${{ matrix.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }} password: ${{ matrix.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }} - - name: Docker meta id: meta uses: docker/metadata-action@v4 @@ -112,4 +107,3 @@ jobs: tags: ${{ steps.meta.outputs.tags }} push: ${{ github.event_name != 'pull_request' }} labels: ${{ steps.meta.outputs.labels }} - diff --git a/.github/workflows/scheduled-scan.yml b/.github/workflows/scheduled-scan.yml new file mode 100644 index 000000000..8e778d33b --- /dev/null +++ b/.github/workflows/scheduled-scan.yml @@ -0,0 +1,21 @@ +name: "Scheduled vulnerability scan" + +on: + schedule: + - cron: "20 3 * * *" + workflow_dispatch: + +permissions: + contents: read + +jobs: + osv-scanner: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: stable + - name: Scan + run: make scan diff --git a/.github/workflows/integrationtest.yml b/.github/workflows/test.yml similarity index 73% rename from .github/workflows/integrationtest.yml rename to .github/workflows/test.yml index 66c882f93..6e6d3f693 100644 --- a/.github/workflows/integrationtest.yml +++ b/.github/workflows/test.yml @@ -2,22 +2,47 @@ # # SPDX-License-Identifier: Apache-2.0 -name: Reusable Integration Test workflow +name: Test on: workflow_call: + inputs: + checkout-ref: + default: '' + required: false + type: string jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.checkout-ref }} + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' + cache: 'gradle' + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v1 + - name: Build and Unit test + uses: gradle/gradle-build-action@v2 + with: + arguments: | + :fabric-chaincode-shim:build + intergationtest: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.checkout-ref }} + - uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '11' cache: 'gradle' - - name: Populate chaincode with latest java-version run: | ./gradlew -I $GITHUB_WORKSPACE/fabric-chaincode-integration-test/chaincodebootstrap.gradle -PchaincodeRepoDir=$GITHUB_WORKSPACE/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/repository publishShimPublicationToFabricRepository @@ -25,7 +50,6 @@ jobs: ./gradlew -I $GITHUB_WORKSPACE/fabric-chaincode-integration-test/chaincodebootstrap.gradle -PchaincodeRepoDir=$GITHUB_WORKSPACE/fabric-chaincode-integration-test/src/contracts/bare-gradle/repository publishShimPublicationToFabricRepository ./gradlew -I $GITHUB_WORKSPACE/fabric-chaincode-integration-test/chaincodebootstrap.gradle -PchaincodeRepoDir=$GITHUB_WORKSPACE/fabric-chaincode-integration-test/src/contracts/bare-maven/repository publishShimPublicationToFabricRepository ./gradlew -I $GITHUB_WORKSPACE/fabric-chaincode-integration-test/chaincodebootstrap.gradle -PchaincodeRepoDir=$GITHUB_WORKSPACE/fabric-chaincode-integration-test/src/contracts/wrapper-maven/repository publishShimPublicationToFabricRepository - - name: Ensure that the Peer/weft tools are available run: | curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- binary @@ -39,8 +63,7 @@ jobs: peer version weft --version - name: Integration Tests - uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 + uses: gradle/gradle-build-action@v2 with: arguments: | - :fabric-chaincode-integration-test:build - -xdependencyCheckAnalyze \ No newline at end of file + :fabric-chaincode-integration-test:build diff --git a/CHANGELOG.md b/CHANGELOG.md index a69d7a1ac..47035ec7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# Changelog + +Notable changes in each release are documented on the project's [GitHub releases](https://github.com/hyperledger/fabric-chaincode-java/releases) page. Change history from previous releases is retained below. + ## v2.5.0 Thu Dec 8 09:02:17 GMT 2022 diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 82ea258be..6c1708b61 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -16,23 +16,23 @@ This table shows the summary of the compatibility of the Java libraries, togethe Testing is performed with - - Java v8: Openjdk version 1.8.0_222 - - Java v11: Eclipse Temurin 11.0.16.1_1-jdk (this has changed from Openjdk version 11.04_11) + - Java v8: OpenJDK + - Java v11: Eclipse Temurin (this has changed from OpenJDK) By default a Fabric Peer v1.4 will create a Java 8 VM, and a Fabric Peer v2.x will create a Java 11 VM. Whilst is the default, the docker image used to host the chaincode and contracts can be altered. Set the environment variable `CORE_CHAINCODE_JAVA_RUNTIME` on the peer to the name of the docker image. For example `CORE_CHAINCODE_JAVA_RUNTIME=example/customJavaRuntime:latest` -The Java Libraries will connect to the peer whilst running; this is referred to as 'Fabric Peer Connectivity' in the table. For example, whilst the Fabric Peer v1.4 will create a Java 8 environment, if a Java 11 environment was configured, the Java Libraries at v2.5.0 still function when connecting to the Fabric Peer v1.4. +The Java Libraries will connect to the peer whilst running; this is referred to as 'Fabric Peer Connectivity' in the table. For example, whilst the Fabric Peer v1.4 will create a Java 8 environment, if a Java 11 environment was configured, the Java Libraries at v2.5 still function when connecting to the Fabric Peer v1.4. ## Compatibility -The key elements are :  +The key elements are: - the version of the Fabric Contract Java libraries used - the version of the JVM used to run the code - When starting a chaincode container to run a Smart Contract the version of the runtime that is used is determined by these factors: -Fabric v1.4.2, and Fabric v2.5.0 will, by default, start up docker image to host the chaincode and contracts. The version of the docker image used is defined by the version of Fabric in use. +Fabric v1.4.2, and Fabric v2.5.x will, by default, start up docker image to host the chaincode and contracts. The version of the docker image used is defined by the version of Fabric in use. With Fabric v2.1.0 and later, the chaincode container can be configured to be started by different chaincode builders, and not the Peer. In this case, the environment used is not in the control of Fabric. @@ -40,30 +40,29 @@ The Java libraries are produced are `group: 'org.hyperledger.fabric-chaincode-ja ### Supported JVMs -v1.4.x and v2.5.0 Java Libraries are supported running in Java 11 with the x86_64 architecture. Later Java 11 versions are supported but are not tested. +v1.4.x and v2.5.x Java Libraries are supported running in Java 11 with the x86_64 architecture. Later Java 11 versions are supported but are not tested. -v1.4.x Java Libraries are supported running in Java 8 with the  x86_64 architecture. Later Java 8 versions are supported but are not tested. +v1.4.x Java Libraries are supported running in Java 8 with the x86_64 architecture. Later Java 8 versions are supported but are not tested. -Architecture Support: all docker images, JVMs, tools are tested under x86_64 ONLY +Architecture Support: all docker images, JVMs, tools are tested under x86_64 ONLY +### Default Peer Runtime selection -### Default Peer Runtime selection +When using Fabric v2.5, the default docker image that is used to run the Java chaincode is *eclipse-temurin:11.0.21_9-jdk* -When using Fabric 2.5.0, the default docker image that is used to run the Java chaincode is *eclipse-temurin:11.0.16.1_1-jdk* - -With the default docker image used by Fabric 2.5.0, if the packaged Java code contains a build script or a wrapper for either Maven or Gradle, it will be built using Gradle 7.0 wrapper , or Maven 3.8.1 wrapper. +With the default docker image used by Fabric v2.5, if the packaged Java code contains a build script or a wrapper for either Maven or Gradle, it will be built using Gradle 7.0 wrapper, or Maven 3.8.1 wrapper. - If both Gradle and Maven files are present Gradle is used. - Gradle build files can be groovy, or kotlin. - If the Gradle or Maven wrappers are present, this will used in preference to the installed wrappers. -Remeber that when using the wrappers, code will be downloaded from the internet. Keep this in mind for any installation with limited or no internet access. +Remember that when using the wrappers, code will be downloaded from the internet. Keep this in mind for any installation with limited or no internet access. Alternatively it is recommended to package prebuilt jar files, including the contract and all dependencies, in which case no build or Internet access is required when installing Java chaincode. Please check the [Dockerfile](./fabric-chaincode-docker/Dockerfile) that is used for the environment to see exactly how these versions are installed. ### Supported Runtime communication with the Peer -  -Subject to a suitable runtime environment, the 1.4 and 2.5 Java Libraries can used to communicate with Fabric Peers at 2.5 and previous LTS versions. The level of functionality that is implied by the Fabric version in use and channel capabilities.  \ No newline at end of file + +Subject to a suitable runtime environment, the 1.4 and 2.5 Java Libraries can used to communicate with Fabric Peers at 2.5 and previous LTS versions. The level of functionality that is implied by the Fabric version in use and channel capabilities. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 37e97553a..8f6248367 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,20 +41,25 @@ Should you have any questions or concerns, please reach out to one of the projec ## How to work with the Codebase -Some useful gradle commands to help with building. You can add or remove the `--no-daemon` and `-x dependencyCheckAnalyze` as you wish; depending on the performance of you local machine. +Some useful gradle commands to help with building. You can add or remove the `--no-daemon` as you wish; depending on the performance of you local machine. -``` -# build everything , but skip the (slow) dependency checks -./gradlew --no-daemon build -x dependencyCheckAnalyze +```shell +# build everything +./gradlew --no-daemon build # clean up to force tests and compile to rerun ./gradlew clean cleanTest -./gradlew --no-daemon :fabric-chaincode-shim:build -x dependencyCheckAnalyze +./gradlew --no-daemon :fabric-chaincode-shim:build # build docker image ./gradlew :fabric-chaincode-docker:buildImage ``` +You can also scan for vulnerabilities in dependencies (requires [Make](https://www.gnu.org/software/make/) and [Go](https://go.dev/) to be installed): +```shell +make scan +``` + ## Hyperledger Fabric See the diff --git a/MAINTAINERS.md b/MAINTAINERS.md index fe6905654..b0c0797fc 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -2,18 +2,18 @@ Maintainers =========== -| Name | GitHub | Chat | email | -|---------------------------|------------------|---------------|---------------------------| -| Artem Barger | c0rwin | c0rwin | bartem@il.ibm.com | -| James Taylor | jt-nti | jtonline | jamest@uk.ibm.com | -| Matthew B White | mbwhite | mbwhite | whitemat@uk.ibm.com | - +| Name | GitHub | Chat | email | +|---------------------------|------------------|-----------------|---------------------------| +| Artem Barger | c0rwin | c0rwin | bartem@il.ibm.com | +| Matthew B White | mbwhite | mbwhite | whitemat@uk.ibm.com | +| Mark Lewis | bestbeforetoday | bestbeforetoday | mark_lewis@uk.ibm.com | Retired Maintainers =================== | Name | GitHub | Chat | email | |---------------------------|------------------|---------------|---------------------------| +| James Taylor | jt-nti | jtonline | jamest@uk.ibm.com | | Gari Singh | mastersingh24 | mastersingh24 | gari.r.singh@gmail.com | | Gennady Laventman | gennadylaventman | gennadyl | gennady@il.ibm.com | | Jim Zhang | jimthematrix | jimthematrix | jim\_the\_matrix@hotmail.com | diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..22285adc3 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +# +# SPDX-License-Identifier: Apache-2.0 +# + +.PHONEY: scan +scan: + go install github.com/google/osv-scanner/cmd/osv-scanner@latest + ./gradlew cyclonedxBom + osv-scanner --sbom='fabric-chaincode-shim/build/reports/bom.json' diff --git a/RELEASING.md b/RELEASING.md index 6ee535904..16288ffc0 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -18,10 +18,6 @@ The following tasks are required before releasing: - Update version numbers in `build.gradle` files to the required version - Update test, sample, and docs files to match the new version - Update the [`COMPATIBILITY.md`](./COMPATIBILITY.md) -- Create a new release notes file -- Update the [`CHANGELOG.md`](./CHANGELOG.md) file - - The `changelog.sh` script in `scripts` will prepopulate the changelog but you must check and edit the file manually afterwards as required See the [[FABCJ-289] release: 2.2.0 LTS](https://github.com/hyperledger/fabric-chaincode-java/pull/124) pull request for an example, although be careful to search for all versions in the codebase as they're easy to miss and things change! diff --git a/build.gradle b/build.gradle index 158dcb0d6..c3a0584c7 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ apply plugin: 'idea' apply plugin: 'eclipse-wtp' -version = '2.5.0' +version = '2.5.1' // If the nightly property is set, then this is the scheduled main @@ -42,7 +42,7 @@ subprojects { targetCompatibility = 1.8 dependencies { - implementation group: 'commons-cli', name: 'commons-cli', version: '1.4' + implementation group: 'commons-cli', name: 'commons-cli', version: '1.6.0' implementation group: 'commons-logging', name: 'commons-logging', version: '1.2' testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.3.1' testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.3.1' diff --git a/examples/fabric-contract-example-as-service/build.gradle b/examples/fabric-contract-example-as-service/build.gradle index 52c3e9336..7c7091532 100644 --- a/examples/fabric-contract-example-as-service/build.gradle +++ b/examples/fabric-contract-example-as-service/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'com.github.johnrengelman.shadow' version '2.0.3' + id 'com.github.johnrengelman.shadow' version '7.1.2' id 'java' } @@ -21,7 +21,7 @@ repositories { dependencies { compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '2.3.+' - compile group: 'org.json', name: 'json', version: '20180813' + compile 'org.json:json:20231013' testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2' testImplementation 'org.assertj:assertj-core:3.11.1' testImplementation 'org.mockito:mockito-core:2.+' @@ -31,6 +31,7 @@ shadowJar { baseName = 'chaincode' version = null classifier = null + mergeServiceFiles() manifest { attributes 'Main-Class': 'org.example.Application' diff --git a/examples/fabric-contract-example-gradle-kotlin/build.gradle.kts b/examples/fabric-contract-example-gradle-kotlin/build.gradle.kts index 667951090..45d20f3e2 100644 --- a/examples/fabric-contract-example-gradle-kotlin/build.gradle.kts +++ b/examples/fabric-contract-example-gradle-kotlin/build.gradle.kts @@ -5,7 +5,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { - id("com.github.johnrengelman.shadow") version "5.2.0" + id("com.github.johnrengelman.shadow") version "7.1.2" id("org.jetbrains.kotlin.jvm") version "1.3.41" } @@ -19,8 +19,8 @@ java { dependencies { - implementation("org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.5.0") - implementation("org.json:json:20180813") + implementation("org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.5.1") + implementation("org.json:json:20231013") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") testImplementation("org.junit.jupiter:junit-jupiter:5.4.2") @@ -44,6 +44,7 @@ tasks { baseName = "chaincode" version = null classifier = null + mergeServiceFiles() manifest { attributes(mapOf("Main-Class" to "org.hyperledger.fabric.contract.ContractRouter")) } diff --git a/examples/fabric-contract-example-gradle-kotlin/gradle/wrapper/gradle-wrapper.jar b/examples/fabric-contract-example-gradle-kotlin/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf01..afba10928 100644 Binary files a/examples/fabric-contract-example-gradle-kotlin/gradle/wrapper/gradle-wrapper.jar and b/examples/fabric-contract-example-gradle-kotlin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/fabric-contract-example-gradle-kotlin/gradle/wrapper/gradle-wrapper.properties b/examples/fabric-contract-example-gradle-kotlin/gradle/wrapper/gradle-wrapper.properties index 7c4388a92..b1624c473 100644 --- a/examples/fabric-contract-example-gradle-kotlin/gradle/wrapper/gradle-wrapper.properties +++ b/examples/fabric-contract-example-gradle-kotlin/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/fabric-contract-example-gradle-kotlin/gradlew b/examples/fabric-contract-example-gradle-kotlin/gradlew index 8e25e6c19..65dcd68d6 100755 --- a/examples/fabric-contract-example-gradle-kotlin/gradlew +++ b/examples/fabric-contract-example-gradle-kotlin/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,78 +17,113 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -97,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -105,84 +140,105 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/examples/fabric-contract-example-gradle-kotlin/gradlew.bat b/examples/fabric-contract-example-gradle-kotlin/gradlew.bat index 24467a141..6689b85be 100644 --- a/examples/fabric-contract-example-gradle-kotlin/gradlew.bat +++ b/examples/fabric-contract-example-gradle-kotlin/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,10 +25,14 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @@ -37,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -51,7 +55,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -61,38 +65,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/examples/fabric-contract-example-gradle/build.gradle b/examples/fabric-contract-example-gradle/build.gradle index 4b2f2553d..1389be1a2 100644 --- a/examples/fabric-contract-example-gradle/build.gradle +++ b/examples/fabric-contract-example-gradle/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'com.github.johnrengelman.shadow' version '2.0.3' + id 'com.github.johnrengelman.shadow' version '7.1.2' id 'java' } @@ -20,8 +20,8 @@ repositories { } dependencies { - compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '2.5.0' - compile group: 'org.json', name: 'json', version: '20180813' + compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '2.5.1' + compile 'org.json:json:20231013' testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2' testImplementation 'org.assertj:assertj-core:3.11.1' testImplementation 'org.mockito:mockito-core:2.+' @@ -31,6 +31,7 @@ shadowJar { baseName = 'chaincode' version = null classifier = null + mergeServiceFiles() manifest { attributes 'Main-Class': 'org.hyperledger.fabric.contract.ContractRouter' diff --git a/examples/fabric-contract-example-maven/pom.xml b/examples/fabric-contract-example-maven/pom.xml index e7016bc2b..15eedfc9a 100644 --- a/examples/fabric-contract-example-maven/pom.xml +++ b/examples/fabric-contract-example-maven/pom.xml @@ -12,10 +12,10 @@ UTF-8 - 2.5.0 + 2.5.1 - 1.2.0 + 1.3.14 1.7.5 @@ -99,7 +99,7 @@ org.json json - 20180813 + 20231013 diff --git a/examples/ledger-api/build.gradle b/examples/ledger-api/build.gradle index d609f2a4e..278cb2b5b 100644 --- a/examples/ledger-api/build.gradle +++ b/examples/ledger-api/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'com.github.johnrengelman.shadow' version '2.0.3' + id 'com.github.johnrengelman.shadow' version '7.1.2' id 'java' } @@ -21,7 +21,7 @@ repositories { dependencies { compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.4.5' - compile group: 'org.json', name: 'json', version: '20180813' + compile 'org.json:json:20231013' testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2' testImplementation 'org.assertj:assertj-core:3.11.1' testImplementation 'org.mockito:mockito-core:2.+' @@ -31,6 +31,7 @@ shadowJar { baseName = 'chaincode' version = null classifier = null + mergeServiceFiles() manifest { attributes 'Main-Class': 'org.hyperledger.fabric.contract.ContractRouter' diff --git a/fabric-chaincode-docker/Dockerfile b/fabric-chaincode-docker/Dockerfile index 9f8b62103..efc09f580 100644 --- a/fabric-chaincode-docker/Dockerfile +++ b/fabric-chaincode-docker/Dockerfile @@ -1,4 +1,4 @@ -FROM eclipse-temurin:11.0.16.1_1-jdk as builder +FROM eclipse-temurin:11.0.21_9-jdk as builder ENV DEBIAN_FRONTEND=noninteractive # Build tools @@ -10,10 +10,10 @@ RUN curl -s "https://get.sdkman.io" | bash SHELL ["/bin/bash", "-c"] -RUN source /root/.sdkman/bin/sdkman-init.sh; sdk install gradle 7.0 -RUN source /root/.sdkman/bin/sdkman-init.sh; sdk install maven 3.8.1 +RUN source /root/.sdkman/bin/sdkman-init.sh; sdk install gradle 7.6.3 +RUN source /root/.sdkman/bin/sdkman-init.sh; sdk install maven 3.9.5 -FROM eclipse-temurin:11.0.16.1_1-jdk as dependencies +FROM eclipse-temurin:11.0.21_9-jdk as dependencies COPY --from=builder /root/.sdkman/candidates/gradle/current /usr/bin/gradle COPY --from=builder /root/.sdkman/candidates/maven/current /usr/bin/maven @@ -41,8 +41,7 @@ RUN gradle \ -x javadoc \ -x test \ -x checkstyleMain \ - -x checkstyleTest \ - -x dependencyCheckAnalyze + -x checkstyleTest WORKDIR /root/chaincode-java # Run the Gradle and Maven commands to generate the wrapper variants @@ -54,7 +53,7 @@ RUN mvn -N io.takari:maven:wrapper # Creating final javaenv image which will include all required # dependencies to build and compile java chaincode -FROM eclipse-temurin:11.0.16.1_1-jdk +FROM eclipse-temurin:11.0.21_9-jdk RUN apt-get update \ && apt-get -y install zip unzip \ diff --git a/fabric-chaincode-docker/build.gradle b/fabric-chaincode-docker/build.gradle index cc7c72c4c..78ae2759b 100644 --- a/fabric-chaincode-docker/build.gradle +++ b/fabric-chaincode-docker/build.gradle @@ -66,6 +66,6 @@ task copyAllDeps(type: Copy) { task buildImage(type: DockerBuildImage) { dependsOn copyAllDeps inputDir = project.file('Dockerfile').parentFile - tags = ['hyperledger/fabric-javaenv', 'hyperledger/fabric-javaenv:amd64-2.5.0', 'hyperledger/fabric-javaenv:amd64-latest'] + tags = ['hyperledger/fabric-javaenv', 'hyperledger/fabric-javaenv:amd64-2.5.1', 'hyperledger/fabric-javaenv:amd64-latest'] } diff --git a/fabric-chaincode-integration-test/build.gradle b/fabric-chaincode-integration-test/build.gradle index 9e6ba9111..9dec7aa0a 100644 --- a/fabric-chaincode-integration-test/build.gradle +++ b/fabric-chaincode-integration-test/build.gradle @@ -1,8 +1,7 @@ dependencies { implementation project(':fabric-chaincode-docker') - testImplementation 'org.hyperledger.fabric-sdk-java:fabric-sdk-java:1.4.4' implementation project(':fabric-chaincode-shim') - implementation group: 'org.json', name: 'json', version: '20180813' + implementation 'org.json:json:20231013' } diff --git a/fabric-chaincode-integration-test/src/contracts/bare-gradle/build.gradle b/fabric-chaincode-integration-test/src/contracts/bare-gradle/build.gradle index 097c68b35..d1a04496a 100644 --- a/fabric-chaincode-integration-test/src/contracts/bare-gradle/build.gradle +++ b/fabric-chaincode-integration-test/src/contracts/bare-gradle/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'com.github.johnrengelman.shadow' version '5.1.0' + id 'com.github.johnrengelman.shadow' version '5.2.0' id 'java' } @@ -18,18 +18,15 @@ repositories { } dependencies { - implementation group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '2.5.0' - implementation group: 'org.hyperledger.fabric', name:'fabric-protos', version:'0.1.3' - testImplementation group: 'junit', name: 'junit', version: '4.12' - implementation group: 'commons-logging', name: 'commons-logging', version: '1.2' - implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6' - implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.4.0' + implementation'org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.5.1' + implementation 'org.hyperledger.fabric:fabric-protos:0.2.+' } shadowJar { baseName = 'chaincode' version = null classifier = null + mergeServiceFiles() manifest { attributes 'Main-Class': 'org.hyperledger.fabric.contract.ContractRouter' diff --git a/fabric-chaincode-integration-test/src/contracts/bare-gradle/src/main/java/org/hyperledger/fabric/example/BareGradle.java b/fabric-chaincode-integration-test/src/contracts/bare-gradle/src/main/java/org/hyperledger/fabric/example/BareGradle.java index 20e80ae73..538e0c2ba 100644 --- a/fabric-chaincode-integration-test/src/contracts/bare-gradle/src/main/java/org/hyperledger/fabric/example/BareGradle.java +++ b/fabric-chaincode-integration-test/src/contracts/bare-gradle/src/main/java/org/hyperledger/fabric/example/BareGradle.java @@ -5,14 +5,12 @@ import org.hyperledger.fabric.contract.Context; import org.hyperledger.fabric.contract.ContractInterface; -import org.hyperledger.fabric.contract.annotation.*; -import org.hyperledger.fabric.metrics.Metrics; -import org.hyperledger.fabric.metrics.MetricsProvider; -import org.hyperledger.fabric.shim.ledger.*; -import org.hyperledger.fabric.shim.*; - -import java.util.*; -import static java.nio.charset.StandardCharsets.UTF_8; +import org.hyperledger.fabric.contract.annotation.Contact; +import org.hyperledger.fabric.contract.annotation.Contract; +import org.hyperledger.fabric.contract.annotation.Default; +import org.hyperledger.fabric.contract.annotation.Info; +import org.hyperledger.fabric.contract.annotation.License; +import org.hyperledger.fabric.contract.annotation.Transaction; @Contract(name = "BareGradle", info = @Info(title = "BareGradle contract", diff --git a/fabric-chaincode-integration-test/src/contracts/bare-maven/pom.xml b/fabric-chaincode-integration-test/src/contracts/bare-maven/pom.xml index 5cd5d4475..51e9df373 100644 --- a/fabric-chaincode-integration-test/src/contracts/bare-maven/pom.xml +++ b/fabric-chaincode-integration-test/src/contracts/bare-maven/pom.xml @@ -12,15 +12,7 @@ UTF-8 - 2.5.0 - - - 1.2.0 - 1.7.5 - - - 5.3.0-RC1 - 1.3.0-RC1 + 2.5.1 @@ -49,75 +41,13 @@ compile - - org.hyperledger.fabric - fabric-protos - 0.1.3 - compile - - - - - - - - org.slf4j - slf4j-api - ${slf4j.version} - compile - - - ch.qos.logback - logback-classic - ${logback.version} - runtime - - - - - org.junit.jupiter - junit-jupiter-api - ${junit.jupiter.version} - compile - - - org.junit.jupiter - junit-jupiter-params - ${junit.jupiter.version} - test - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - - - - org.mockito - mockito-core - 2.10.0 - - - - - org.json - json - 20180813 - - src - - - maven-surefire-plugin - 2.22.0 - maven-compiler-plugin - 3.1 + 3.11.0 ${java.version} ${java.version} @@ -126,7 +56,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.1.0 + 3.5.0 package @@ -136,6 +66,7 @@ chaincode + org.hyperledger.fabric.contract.ContractRouter @@ -158,5 +89,4 @@ - diff --git a/fabric-chaincode-integration-test/src/contracts/bare-maven/src/main/java/org/hyperledger/fabric/example/BareMaven.java b/fabric-chaincode-integration-test/src/contracts/bare-maven/src/main/java/org/hyperledger/fabric/example/BareMaven.java index 6ed910edd..8539bd6a2 100644 --- a/fabric-chaincode-integration-test/src/contracts/bare-maven/src/main/java/org/hyperledger/fabric/example/BareMaven.java +++ b/fabric-chaincode-integration-test/src/contracts/bare-maven/src/main/java/org/hyperledger/fabric/example/BareMaven.java @@ -5,14 +5,12 @@ import org.hyperledger.fabric.contract.Context; import org.hyperledger.fabric.contract.ContractInterface; -import org.hyperledger.fabric.contract.annotation.*; -import org.hyperledger.fabric.metrics.Metrics; -import org.hyperledger.fabric.metrics.MetricsProvider; -import org.hyperledger.fabric.shim.ledger.*; -import org.hyperledger.fabric.shim.*; - -import java.util.*; -import static java.nio.charset.StandardCharsets.UTF_8; +import org.hyperledger.fabric.contract.annotation.Contact; +import org.hyperledger.fabric.contract.annotation.Contract; +import org.hyperledger.fabric.contract.annotation.Default; +import org.hyperledger.fabric.contract.annotation.Info; +import org.hyperledger.fabric.contract.annotation.License; +import org.hyperledger.fabric.contract.annotation.Transaction; @Contract(name = "BareMaven", info = @Info(title = "BareGradle contract", diff --git a/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/build.gradle b/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/build.gradle index 14ebfcc85..8762d6bd2 100644 --- a/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/build.gradle +++ b/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'com.github.johnrengelman.shadow' version '5.1.0' + id 'com.github.johnrengelman.shadow' version '7.1.2' id 'java' } @@ -18,14 +18,15 @@ repositories { } dependencies { - implementation group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '2.5.0' - testImplementation group: 'junit', name: 'junit', version: '4.12' + implementation'org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.5.1' + implementation 'org.hyperledger.fabric:fabric-protos:0.2.+' } shadowJar { baseName = 'chaincode' version = null classifier = null + mergeServiceFiles() manifest { attributes 'Main-Class': 'org.hyperledger.fabric.contract.ContractRouter' diff --git a/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradle/wrapper/gradle-wrapper.jar b/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf01..afba10928 100644 Binary files a/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradle/wrapper/gradle-wrapper.jar and b/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradle/wrapper/gradle-wrapper.jar differ diff --git a/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradle/wrapper/gradle-wrapper.properties b/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradle/wrapper/gradle-wrapper.properties index f371643ee..b1624c473 100644 --- a/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradle/wrapper/gradle-wrapper.properties +++ b/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradlew b/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradlew index 8e25e6c19..65dcd68d6 100755 --- a/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradlew +++ b/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,78 +17,113 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -97,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -105,84 +140,105 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradlew.bat b/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradlew.bat index 24467a141..6689b85be 100644 --- a/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradlew.bat +++ b/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,10 +25,14 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @@ -37,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -51,7 +55,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -61,38 +65,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/src/main/java/org/hyperledger/fabric/example/AllLedgerAPI.java b/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/src/main/java/org/hyperledger/fabric/example/AllLedgerAPI.java index 309bb09ac..c0ea6944a 100644 --- a/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/src/main/java/org/hyperledger/fabric/example/AllLedgerAPI.java +++ b/fabric-chaincode-integration-test/src/contracts/fabric-ledger-api/src/main/java/org/hyperledger/fabric/example/AllLedgerAPI.java @@ -3,17 +3,15 @@ */ package org.hyperledger.fabric.example; - - import org.hyperledger.fabric.contract.Context; import org.hyperledger.fabric.contract.ContractInterface; -import org.hyperledger.fabric.contract.annotation.*; - - -import org.hyperledger.fabric.ledger.*; - -import java.util.*; -import static java.nio.charset.StandardCharsets.UTF_8; +import org.hyperledger.fabric.contract.annotation.Contact; +import org.hyperledger.fabric.contract.annotation.Contract; +import org.hyperledger.fabric.contract.annotation.Default; +import org.hyperledger.fabric.contract.annotation.Info; +import org.hyperledger.fabric.contract.annotation.License; +import org.hyperledger.fabric.contract.annotation.Transaction; +import org.hyperledger.fabric.ledger.Ledger; @Contract(name = "AllLedgerAPI", info = @Info(title = "AllLedgerAPI contract", diff --git a/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/build.gradle b/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/build.gradle index 097c68b35..fa796caf9 100644 --- a/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/build.gradle +++ b/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'com.github.johnrengelman.shadow' version '5.1.0' + id 'com.github.johnrengelman.shadow' version '7.1.2' id 'java' } @@ -18,18 +18,17 @@ repositories { } dependencies { - implementation group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '2.5.0' - implementation group: 'org.hyperledger.fabric', name:'fabric-protos', version:'0.1.3' - testImplementation group: 'junit', name: 'junit', version: '4.12' - implementation group: 'commons-logging', name: 'commons-logging', version: '1.2' - implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6' - implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.4.0' + implementation'org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.5.1' + implementation 'org.hyperledger.fabric:fabric-protos:0.2.+' + implementation 'commons-logging:commons-logging:1.2' + implementation 'com.google.code.gson:gson:2.10.1' } shadowJar { baseName = 'chaincode' version = null classifier = null + mergeServiceFiles() manifest { attributes 'Main-Class': 'org.hyperledger.fabric.contract.ContractRouter' diff --git a/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradle/wrapper/gradle-wrapper.jar b/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf01..afba10928 100644 Binary files a/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradle/wrapper/gradle-wrapper.jar and b/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradle/wrapper/gradle-wrapper.jar differ diff --git a/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradle/wrapper/gradle-wrapper.properties b/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradle/wrapper/gradle-wrapper.properties index f371643ee..b1624c473 100644 --- a/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradle/wrapper/gradle-wrapper.properties +++ b/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradlew b/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradlew index 8e25e6c19..65dcd68d6 100755 --- a/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradlew +++ b/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,78 +17,113 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -97,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -105,84 +140,105 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradlew.bat b/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradlew.bat index 24467a141..6689b85be 100644 --- a/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradlew.bat +++ b/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,10 +25,14 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @@ -37,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -51,7 +55,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -61,38 +65,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/src/main/java/org/hyperledger/fabric/example/AllAPI.java b/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/src/main/java/org/hyperledger/fabric/example/AllAPI.java index 630c584f3..5c58ba140 100644 --- a/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/src/main/java/org/hyperledger/fabric/example/AllAPI.java +++ b/fabric-chaincode-integration-test/src/contracts/fabric-shim-api/src/main/java/org/hyperledger/fabric/example/AllAPI.java @@ -5,12 +5,16 @@ import org.hyperledger.fabric.contract.Context; import org.hyperledger.fabric.contract.ContractInterface; -import org.hyperledger.fabric.contract.annotation.*; +import org.hyperledger.fabric.contract.annotation.Contact; +import org.hyperledger.fabric.contract.annotation.Contract; +import org.hyperledger.fabric.contract.annotation.Default; +import org.hyperledger.fabric.contract.annotation.Info; +import org.hyperledger.fabric.contract.annotation.License; +import org.hyperledger.fabric.contract.annotation.Transaction; import org.hyperledger.fabric.metrics.Metrics; import org.hyperledger.fabric.metrics.MetricsProvider; import org.hyperledger.fabric.shim.ledger.*; import org.hyperledger.fabric.shim.*; -import java.util.*; import static java.nio.charset.StandardCharsets.UTF_8; @Contract(name = "AllAPI", diff --git a/fabric-chaincode-integration-test/src/contracts/wrapper-maven/pom.xml b/fabric-chaincode-integration-test/src/contracts/wrapper-maven/pom.xml index b3f68f869..069665ac4 100644 --- a/fabric-chaincode-integration-test/src/contracts/wrapper-maven/pom.xml +++ b/fabric-chaincode-integration-test/src/contracts/wrapper-maven/pom.xml @@ -12,15 +12,7 @@ UTF-8 - 2.5.0 - - - 1.2.0 - 1.7.5 - - - 5.3.0-RC1 - 1.3.0-RC1 + 2.5.1 @@ -49,75 +41,13 @@ compile - - org.hyperledger.fabric - fabric-protos - 0.1.3 - compile - - - - - - - - org.slf4j - slf4j-api - ${slf4j.version} - compile - - - ch.qos.logback - logback-classic - ${logback.version} - runtime - - - - - org.junit.jupiter - junit-jupiter-api - ${junit.jupiter.version} - compile - - - org.junit.jupiter - junit-jupiter-params - ${junit.jupiter.version} - test - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - - - - org.mockito - mockito-core - 2.10.0 - - - - - org.json - json - 20180813 - - src - - - maven-surefire-plugin - 2.22.0 - maven-compiler-plugin - 3.1 + 3.11.0 ${java.version} ${java.version} @@ -126,7 +56,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.1.0 + 3.5.0 package @@ -136,6 +66,7 @@ chaincode + org.hyperledger.fabric.contract.ContractRouter @@ -158,5 +89,4 @@ - diff --git a/fabric-chaincode-integration-test/src/contracts/wrapper-maven/src/main/java/org/hyperledger/fabric/example/WrapperMaven.java b/fabric-chaincode-integration-test/src/contracts/wrapper-maven/src/main/java/org/hyperledger/fabric/example/WrapperMaven.java index b92be287e..436751ba3 100644 --- a/fabric-chaincode-integration-test/src/contracts/wrapper-maven/src/main/java/org/hyperledger/fabric/example/WrapperMaven.java +++ b/fabric-chaincode-integration-test/src/contracts/wrapper-maven/src/main/java/org/hyperledger/fabric/example/WrapperMaven.java @@ -5,14 +5,12 @@ import org.hyperledger.fabric.contract.Context; import org.hyperledger.fabric.contract.ContractInterface; -import org.hyperledger.fabric.contract.annotation.*; -import org.hyperledger.fabric.metrics.Metrics; -import org.hyperledger.fabric.metrics.MetricsProvider; -import org.hyperledger.fabric.shim.ledger.*; -import org.hyperledger.fabric.shim.*; - -import java.util.*; -import static java.nio.charset.StandardCharsets.UTF_8; +import org.hyperledger.fabric.contract.annotation.Contact; +import org.hyperledger.fabric.contract.annotation.Contract; +import org.hyperledger.fabric.contract.annotation.Default; +import org.hyperledger.fabric.contract.annotation.Info; +import org.hyperledger.fabric.contract.annotation.License; +import org.hyperledger.fabric.contract.annotation.Transaction; @Contract(name = "WrapperMaven", info = @Info(title = "BareGradle contract", diff --git a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/contractinstall/ContractInstallTest.java b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/contractinstall/ContractInstallTest.java index 3c9cd58b1..d8a0c3100 100644 --- a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/contractinstall/ContractInstallTest.java +++ b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/contractinstall/ContractInstallTest.java @@ -28,15 +28,15 @@ public static void setUp() throws Exception { public void TestInstall(){ InvokeHelper helper = InvokeHelper.newHelper("baregradlecc","sachannel"); - String text = helper.invoke("org1",new String[]{"whoami"}); + String text = helper.invoke("org1", "whoami"); assertThat(text, containsString("BareGradle")); helper = InvokeHelper.newHelper("baremaven","sachannel"); - text = helper.invoke("org1",new String[]{"whoami"}); + text = helper.invoke("org1", "whoami"); assertThat(text, containsString("BareMaven")); helper = InvokeHelper.newHelper("wrappermaven","sachannel"); - text = helper.invoke("org1",new String[]{"whoami"}); + text = helper.invoke("org1", "whoami"); assertThat(text, containsString("WrapperMaven")); } diff --git a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/ledgertests/LedgerIntegrationTest.java b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/ledgertests/LedgerIntegrationTest.java index c20bd27a4..6b9ed0020 100644 --- a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/ledgertests/LedgerIntegrationTest.java +++ b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/ledgertests/LedgerIntegrationTest.java @@ -29,7 +29,7 @@ public static void setUp() throws Exception { public void TestLedgers(){ InvokeHelper helper = InvokeHelper.newHelper("ledgercc","sachannel"); - String text = helper.invoke("org1",new String[]{"accessLedgers"}); + String text = helper.invoke("org1", "accessLedgers"); assertThat(text, containsString("success")); } diff --git a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/shimtests/SACCIntegrationTest.java b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/shimtests/SACCIntegrationTest.java index a7e2ca31b..f9cae0c30 100644 --- a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/shimtests/SACCIntegrationTest.java +++ b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/shimtests/SACCIntegrationTest.java @@ -28,17 +28,17 @@ public static void setUp() throws Exception { public void TestLedger(){ InvokeHelper helper = InvokeHelper.newHelper("shimcc", "sachannel"); - String text = helper.invoke("org1",new String[]{"putBulkStates"}); + String text = helper.invoke("org1", "putBulkStates"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[]{"getByRange","key120","key170"}); + text = helper.invoke("org1", "getByRange","key120","key170"); assertThat(text, containsString("50")); - text = helper.invoke("org1",new String[]{"getByRangePaged","key120","key170","10",""}); + text = helper.invoke("org1", "getByRangePaged","key120","key170","10",""); System.out.println(text); assertThat(text, containsString("key130")); - text = helper.invoke("org1",new String[]{"getMetricsProviderName"}); + text = helper.invoke("org1", "getMetricsProviderName"); System.out.println(text); assertThat(text, containsString("org.hyperledger.fabric.metrics.impl.DefaultProvider")); } diff --git a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/shimtests/SBECCIntegrationTest.java b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/shimtests/SBECCIntegrationTest.java index f125d7db2..d93c3fafa 100644 --- a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/shimtests/SBECCIntegrationTest.java +++ b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/shimtests/SBECCIntegrationTest.java @@ -9,15 +9,8 @@ import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertThat; -import java.io.IOException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.spec.InvalidKeySpecException; - import org.hyperleder.fabric.shim.integration.util.FabricState; import org.hyperleder.fabric.shim.integration.util.InvokeHelper; -import org.hyperledger.fabric.sdk.exception.InvalidArgumentException; -import org.hyperledger.fabric.sdk.exception.ProposalException; import org.junit.BeforeClass; import org.junit.Test; @@ -31,134 +24,132 @@ public static void setUp() throws Exception { } @Test - public void RunSBE_pub_setget() throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException, - IOException, ProposalException, InvalidArgumentException { + public void RunSBE_pub_setget() { final String mode = "pub"; final InvokeHelper helper = InvokeHelper.newHelper("shimcc", "sachannel"); String text; - text = helper.invoke("org1",new String[] {"EndorsementCC:setval", mode, "foo"}); + text = helper.invoke("org1", "EndorsementCC:setval", mode, "foo"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:getval", mode}); + text = helper.invoke("org1", "EndorsementCC:getval", mode); assertThat(text, containsString("foo")); - text = helper.invoke("org1",new String[] {"EndorsementCC:addorgs", mode, "org1MSP"}); + text = helper.invoke("org1", "EndorsementCC:addorgs", mode, "org1MSP"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:listorgs", mode}); + text = helper.invoke("org1", "EndorsementCC:listorgs", mode); assertThat(text, containsString("org1MSP")); - text = helper.invoke("org1",new String[] {"EndorsementCC:setval", mode, "val1"}); + text = helper.invoke("org1", "EndorsementCC:setval", mode, "val1"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:getval", mode}); + text = helper.invoke("org1", "EndorsementCC:getval", mode); assertThat(text, containsString("val1")); - text = helper.invoke("org1",new String[] {"EndorsementCC:setval", mode, "val2"}); + text = helper.invoke("org1", "EndorsementCC:setval", mode, "val2"); - text = helper.invoke("org1",new String[] {"EndorsementCC:getval", mode}); + text = helper.invoke("org1", "EndorsementCC:getval", mode); assertThat(text, containsString("val2")); - text = helper.invoke("org1",new String[] {"EndorsementCC:addorgs", mode, "org2MSP"}); + text = helper.invoke("org1", "EndorsementCC:addorgs", mode, "org2MSP"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:listorgs", mode}); + text = helper.invoke("org1", "EndorsementCC:listorgs", mode); assertThat(text, containsString("org2MSP")); assertThat(text, containsString("org1MSP")); - text = helper.invoke("org1",new String[] {"EndorsementCC:setval", mode, "val3"}); + text = helper.invoke("org1", "EndorsementCC:setval", mode, "val3"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:getval", mode}); + text = helper.invoke("org1", "EndorsementCC:getval", mode); assertThat(text, containsString("val3")); - text = helper.invoke("org1",new String[] {"EndorsementCC:setval", mode, "val4"}); + text = helper.invoke("org1", "EndorsementCC:setval", mode, "val4"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:getval", mode}); + text = helper.invoke("org1", "EndorsementCC:getval", mode); assertThat(text, containsString("val4")); - text = helper.invoke("org1",new String[] {"EndorsementCC:delorgs", mode, "org1MSP"}); + text = helper.invoke("org1", "EndorsementCC:delorgs", mode, "org1MSP"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:listorgs", mode}); + text = helper.invoke("org1", "EndorsementCC:listorgs", mode); assertThat(text, containsString("org2MSP")); assertThat(text, not(containsString("org1MSP"))); - text = helper.invoke("org1",new String[] {"EndorsementCC:deleteval", mode}); + text = helper.invoke("org1", "EndorsementCC:deleteval", mode); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:recordExists", mode}); + text = helper.invoke("org1", "EndorsementCC:recordExists", mode); assertThat(text, containsString("false")); } @Test - public void RunSBE_priv() throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException, - IOException, ProposalException, InvalidArgumentException { + public void RunSBE_priv() { final String mode = "priv"; final InvokeHelper helper = InvokeHelper.newHelper("shimcc", "sachannel"); String text; - text = helper.invoke("org1",new String[] {"EndorsementCC:setval", mode, "foo"}); + text = helper.invoke("org1", "EndorsementCC:setval", mode, "foo"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:getval", mode}); + text = helper.invoke("org1", "EndorsementCC:getval", mode); assertThat(text, containsString("foo")); - text = helper.invoke("org1",new String[] {"EndorsementCC:addorgs", mode, "org1MSP"}); + text = helper.invoke("org1", "EndorsementCC:addorgs", mode, "org1MSP"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:listorgs", mode}); + text = helper.invoke("org1", "EndorsementCC:listorgs", mode); assertThat(text, containsString("org1MSP")); - text = helper.invoke("org1",new String[] {"EndorsementCC:setval", mode, "val1"}); + text = helper.invoke("org1", "EndorsementCC:setval", mode, "val1"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:getval", mode}); + text = helper.invoke("org1", "EndorsementCC:getval", mode); assertThat(text, containsString("val1")); - text = helper.invoke("org1",new String[] {"EndorsementCC:setval", mode, "val2"}); + text = helper.invoke("org1", "EndorsementCC:setval", mode, "val2"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:getval", mode}); + text = helper.invoke("org1", "EndorsementCC:getval", mode); assertThat(text, containsString("val2")); - text = helper.invoke("org1",new String[] {"EndorsementCC:addorgs", mode, "org2MSP"}); + text = helper.invoke("org1", "EndorsementCC:addorgs", mode, "org2MSP"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:listorgs", mode}); + text = helper.invoke("org1", "EndorsementCC:listorgs", mode); assertThat(text, containsString("org2MSP")); assertThat(text, containsString("org1MSP")); - text = helper.invoke("org1",new String[] {"EndorsementCC:setval", mode, "val3"}); + text = helper.invoke("org1", "EndorsementCC:setval", mode, "val3"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:getval", mode}); + text = helper.invoke("org1", "EndorsementCC:getval", mode); assertThat(text, containsString("val3")); - text = helper.invoke("org1",new String[] {"EndorsementCC:setval", mode, "val4"}); + text = helper.invoke("org1", "EndorsementCC:setval", mode, "val4"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:getval", mode}); + text = helper.invoke("org1", "EndorsementCC:getval", mode); assertThat(text, containsString("val4")); - text = helper.invoke("org1",new String[] {"EndorsementCC:delorgs", mode, "org1MSP"}); + text = helper.invoke("org1", "EndorsementCC:delorgs", mode, "org1MSP"); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:listorgs", mode}); + text = helper.invoke("org1", "EndorsementCC:listorgs", mode); assertThat(text, containsString("org2MSP")); assertThat(text, not(containsString("org1MSP"))); - text = helper.invoke("org1",new String[] {"EndorsementCC:deleteval", mode}); + text = helper.invoke("org1", "EndorsementCC:deleteval", mode); assertThat(text, containsString("success")); - text = helper.invoke("org1",new String[] {"EndorsementCC:recordExists", mode}); + text = helper.invoke("org1", "EndorsementCC:recordExists", mode); assertThat(text, containsString("false")); } diff --git a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Bash.java b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Bash.java index 1ebc87347..b135a48b5 100644 --- a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Bash.java +++ b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Bash.java @@ -14,7 +14,7 @@ * * */ -public class Bash extends Command { +public final class Bash extends Command { public static BashBuilder newBuilder(){ return new BashBuilder(); diff --git a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Command.java b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Command.java index d6a7d1f5d..a18a282ec 100644 --- a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Command.java +++ b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Command.java @@ -7,13 +7,13 @@ package org.hyperleder.fabric.shim.integration.util; import java.io.BufferedReader; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.lang.ProcessBuilder.Redirect; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -22,25 +22,21 @@ public class Command { - protected List cmd; - protected Map env; + protected final List cmd; + protected final Map env = new HashMap<>(); Command(List cmd, Map additionalEnv){ this.cmd = cmd; - // this.env = new HashMap(System.getenv()); - this.env = new HashMap(); this.env.putAll(additionalEnv); } Command(List cmd) { - this.cmd = cmd; - this.env = new HashMap(); - // this.env = new HashMap(System.getenv()); + this(cmd, Collections.emptyMap()); } - public class Result { - public ArrayList stdout; - public ArrayList stderr; + public static final class Result { + public List stdout; + public List stderr; public int exitcode; } @@ -62,7 +58,7 @@ public Result run(boolean quiet) { processBuilder.environment().putAll(env); final Result result = new Result(); - System.out.println("Running:" + this.toString()); + System.out.println("Running:" + this); try { processBuilder.redirectInput(Redirect.INHERIT); @@ -103,7 +99,7 @@ public Result run(boolean quiet) { CompletableFuture> readOutStream(InputStream is, PrintStream stream) { return CompletableFuture.supplyAsync(() -> { try (InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr);) { - ArrayList res = new ArrayList(); + ArrayList res = new ArrayList<>(); String inputLine; while ((inputLine = br.readLine()) != null) { if (stream!=null) stream.println(inputLine); @@ -121,6 +117,7 @@ public String toString() { } static public class Builder implements Cloneable { + @SuppressWarnings("unchecked") public Builder duplicate() { try { return (Builder) this.clone(); diff --git a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/CommandSingleton.java b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/CommandSingleton.java deleted file mode 100644 index 5adfb2a06..000000000 --- a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/CommandSingleton.java +++ /dev/null @@ -1,57 +0,0 @@ -/* -Copyright 2020 IBM Corp. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ -package org.hyperleder.fabric.shim.integration.util; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.concurrent.Semaphore; - -import org.hyperleder.fabric.shim.integration.util.Docker.DockerBuilder; -import org.hyperleder.fabric.shim.integration.util.DockerCompose.DockerComposeBuilder; - -/** Utility class to run the setup script once */ -public class CommandSingleton { - - private static boolean done = false; - - private static Semaphore flag = new Semaphore(1); - - public static void setup() { - - try { - // things have not been setup up yet - flag.acquire(); - if (done) { - flag.release(); - return; - } - // get current working directory for debug and reference purposes only - Path currentRelativePath = Paths.get(""); - String s = currentRelativePath.toAbsolutePath().toString(); - - // create the docker-compose command - DockerComposeBuilder composebuilder = DockerCompose.newBuilder() - .file("src/test/resources/first-network/docker-compose-cli.yaml"); - - // close down anything running... - composebuilder.duplicate().down().build().run(); - - // ...and bring up - DockerCompose compose = composebuilder.up().detach().build(); - compose.run(); - - // the cli container contains a script that does the channel create, joing - // and chaincode install/instantiate - DockerBuilder dockerBuilder = new Docker.DockerBuilder(); - Docker docker = dockerBuilder.exec().container("cli").script("./scripts/script.sh").build(); - docker.run(); - done = true; - flag.release(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } -} \ No newline at end of file diff --git a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Docker.java b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Docker.java index 769eedcbb..f500d3330 100644 --- a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Docker.java +++ b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Docker.java @@ -12,13 +12,13 @@ * * */ -public class Docker extends Command { +public final class Docker extends Command { public static DockerBuilder newBuilder(){ return new DockerBuilder(); } - static public class DockerBuilder implements Cloneable { + public static final class DockerBuilder implements Cloneable { boolean exec; String container; String script; diff --git a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/DockerCompose.java b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/DockerCompose.java index d841e0150..3beaac556 100644 --- a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/DockerCompose.java +++ b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/DockerCompose.java @@ -12,13 +12,13 @@ * * */ -public class DockerCompose extends Command { +public final class DockerCompose extends Command { public static DockerComposeBuilder newBuilder(){ return new DockerComposeBuilder(); } - static public class DockerComposeBuilder extends Command.Builder{ + public static final class DockerComposeBuilder extends Command.Builder{ String composeFile; boolean up = true; diff --git a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/FabricState.java b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/FabricState.java index 0954ca470..59909a2a1 100644 --- a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/FabricState.java +++ b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/FabricState.java @@ -11,18 +11,16 @@ import java.util.Map; import java.util.concurrent.Semaphore; -import org.hyperleder.fabric.shim.integration.util.Docker.DockerBuilder; -import org.hyperleder.fabric.shim.integration.util.DockerCompose.DockerComposeBuilder; import org.hyperleder.fabric.shim.integration.util.Bash.BashBuilder; -public class FabricState { +public final class FabricState { private static FabricState state; - private static Map channelStarted = new HashMap<>(); + private static final Map channelStarted = new HashMap<>(); // sempaphore to protect access - private static Semaphore flag = new Semaphore(1); + private static final Semaphore flag = new Semaphore(1); public static FabricState getState() { if (state == null) { @@ -49,7 +47,7 @@ public Map orgEnv(String org) { Path currentRelativePath = Paths.get(""); String s = currentRelativePath.toAbsolutePath().toString(); - Map env = new HashMap(); + Map env = new HashMap<>(); env.put("CORE_PEER_MSPCONFIGPATH", Paths.get(s, "src/test/resources/_cfg/_msp/" + org, org + "admin/msp").toString()); diff --git a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/InvokeHelper.java b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/InvokeHelper.java index b8ee128eb..971cb2529 100644 --- a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/InvokeHelper.java +++ b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/InvokeHelper.java @@ -1,11 +1,12 @@ package org.hyperleder.fabric.shim.integration.util; -import java.util.Map; -import java.util.stream.Collectors; - import org.hyperleder.fabric.shim.integration.util.Command.Result; import org.hyperleder.fabric.shim.integration.util.Peer.PeerBuilder; +import java.util.Arrays; +import java.util.Map; +import java.util.stream.Collectors; + public class InvokeHelper { private String ccname; @@ -33,6 +34,8 @@ public String invoke(String org, String... args){ .trim(); if (!text.contains("result: status:200")){ + Command logsCommand = new Command(Arrays.asList("docker", "logs", "microfab"), orgEnv); + logsCommand.run(); throw new RuntimeException(text); } diff --git a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Peer.java b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Peer.java index 59290fbb0..99c19111c 100644 --- a/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Peer.java +++ b/fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/util/Peer.java @@ -17,13 +17,13 @@ * * */ -public class Peer extends Command { +public final class Peer extends Command { public static PeerBuilder newBuilder(){ return new PeerBuilder(); } - static public class PeerBuilder extends Command.Builder { + public static final class PeerBuilder extends Command.Builder { String tlsArgs; String orderer; String channel; @@ -78,7 +78,7 @@ public PeerBuilder argsTx(List args){ return this; } - public PeerBuilder argsTx(String argsArray[]){ + public PeerBuilder argsTx(String[] argsArray){ this.args = Arrays.asList(argsArray); return this; } diff --git a/fabric-chaincode-integration-test/src/test/resources/scripts/mfsetup.sh b/fabric-chaincode-integration-test/src/test/resources/scripts/mfsetup.sh index 6df1a20d4..f2cb4d8f1 100755 --- a/fabric-chaincode-integration-test/src/test/resources/scripts/mfsetup.sh +++ b/fabric-chaincode-integration-test/src/test/resources/scripts/mfsetup.sh @@ -26,7 +26,7 @@ docker run --name microfab \ sleep 10 curl -sSL http://console.localho.st:8080/ak/api/v1/components > $CFG/cfg.json -weft microfab -w $CFG/_wallets -p $CFG/_gateways -m $CFG/_msp -f --config $CFG/cfg.json +npx @hyperledger-labs/weft microfab -w $CFG/_wallets -p $CFG/_gateways -m $CFG/_msp -f --config $CFG/cfg.json # bring in the helper bash scripts . $DIR/scripts/ccutils.sh diff --git a/fabric-chaincode-shim/build.gradle b/fabric-chaincode-shim/build.gradle index 097353485..25d3c1aaf 100644 --- a/fabric-chaincode-shim/build.gradle +++ b/fabric-chaincode-shim/build.gradle @@ -8,7 +8,7 @@ mavenCentral() } dependencies { - classpath 'org.owasp:dependency-check-gradle:7.4.3' + classpath 'org.owasp:dependency-check-gradle:8.4.0' } } @@ -17,12 +17,11 @@ plugins { id 'jacoco' id 'signing' id 'checkstyle' + id 'org.cyclonedx.bom' version '1.8.1' } -apply plugin: 'org.owasp.dependencycheck' - checkstyle { - toolVersion '8.29' + toolVersion '10.12.5' configFile file("../ci/checkstyle/checkstyle.xml") configProperties = [root_dir: file("..") ] } @@ -34,47 +33,51 @@ checkstyleTest { source ='src/test/java' } -check.dependsOn dependencyCheckAnalyze +cyclonedxBom { + includeConfigs = ["runtimeClasspath"] + skipConfigs = ["compileClasspath", "testCompileClasspath"] + projectType = "library" + schemaVersion = "1.5" + destination = file("build/reports") + outputName = "bom" + outputFormat = "json" + includeBomSerialNumber = false + includeLicenseText = false +} tasks.withType(org.gradle.api.tasks.testing.Test) { systemProperty 'CORE_CHAINCODE_LOGGING_LEVEL', 'DEBUG' } dependencies { - implementation group: 'org.hyperledger.fabric', name:'fabric-protos', version:'0.2.0' - implementation 'org.bouncycastle:bcpkix-jdk15on:1.62' - implementation 'org.bouncycastle:bcprov-jdk15on:1.62' - implementation group: 'io.github.classgraph', name: 'classgraph', version: '4.8.146' - implementation group: 'com.github.everit-org.json-schema', name: 'org.everit.json.schema', version: '1.14.1' - implementation 'org.json:json:20220320' - implementation group: 'com.google.protobuf', name: 'protobuf-java-util', version: '3.20.1' + implementation 'org.hyperledger.fabric:fabric-protos:0.2.1' + implementation 'org.bouncycastle:bcpkix-jdk18on:1.77' + implementation 'org.bouncycastle:bcprov-jdk18on:1.77' + implementation 'io.github.classgraph:classgraph:4.8.165' + implementation 'com.github.everit-org.json-schema:org.everit.json.schema:1.14.2' + implementation 'org.json:json:20231013' + implementation 'com.google.protobuf:protobuf-java-util:3.24.4' // Required if using Java 11+ as no longer bundled in the core libraries - testImplementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1' - implementation 'io.grpc:grpc-netty-shaded:1.46.0' - implementation 'io.grpc:grpc-protobuf:1.46.0' - implementation 'io.grpc:grpc-stub:1.46.0' - - implementation platform("io.opentelemetry:opentelemetry-bom:1.6.0") - - implementation "io.opentelemetry:opentelemetry-api" - implementation "io.opentelemetry:opentelemetry-proto:1.6.0-alpha" - implementation "io.opentelemetry:opentelemetry-sdk" - implementation "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:1.6.0-alpha" - implementation "io.opentelemetry:opentelemetry-sdk-trace" - implementation 'io.opentelemetry:opentelemetry-exporter-otlp' - implementation 'io.opentelemetry:opentelemetry-extension-trace-propagators:1.6.0' - implementation "io.opentelemetry.instrumentation:opentelemetry-grpc-1.6:1.5.3-alpha" -} + testImplementation 'javax.xml.bind:jaxb-api:2.3.1' -dependencyCheck { - format='ALL' - analyzers { - assemblyEnabled=false - ossIndex { - enabled=false - } - } + implementation platform('io.grpc:grpc-bom:1.60.0') + implementation 'io.grpc:grpc-netty-shaded' + implementation 'io.grpc:grpc-protobuf' + implementation 'io.grpc:grpc-stub' + + testImplementation 'io.grpc:grpc-inprocess' + + implementation platform("io.opentelemetry:opentelemetry-bom:1.32.0") + + implementation 'io.opentelemetry:opentelemetry-api' + implementation 'io.opentelemetry.proto:opentelemetry-proto:1.0.0-alpha' + implementation 'io.opentelemetry:opentelemetry-sdk' + implementation 'io.opentelemetry:opentelemetry-sdk-extension-autoconfigure' + implementation 'io.opentelemetry:opentelemetry-sdk-trace' + implementation 'io.opentelemetry:opentelemetry-exporter-otlp' + implementation 'io.opentelemetry:opentelemetry-extension-trace-propagators' + implementation 'io.opentelemetry.instrumentation:opentelemetry-grpc-1.6:1.32.0-alpha' } sourceSets { diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Serializer.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Serializer.java index ba0ebb230..10ff45d65 100644 --- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Serializer.java +++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Serializer.java @@ -15,7 +15,7 @@ * Class level annotation that defines the serializer that should be used to * convert objects to and from the wire format. * - * This should annotate a class that implements the Serializer interface + *

This should annotate a class that implements the Serializer interface

*/ @Retention(RUNTIME) @Target({ElementType.TYPE, ElementType.TYPE_USE}) @@ -25,7 +25,14 @@ * */ enum TARGET { - TRANSACTION, ALL + /** + * Target transaction functions. + */ + TRANSACTION, + /** + * Target all elements. + */ + ALL } /** diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Transaction.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Transaction.java index 5bdf8c95a..c9180ca46 100644 --- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Transaction.java +++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Transaction.java @@ -29,20 +29,27 @@ public @interface Transaction { /** - * SUBMIT or EVALUATE semantics. + * The intended invocation style for a transaction function. */ enum TYPE { - SUBMIT, EVALUATE + /** + * Transaction is used to submit updates to the ledger. + */ + SUBMIT, + /** + * Transaction is evaluated to query information from the ledger. + */ + EVALUATE } /** * Submit semantics. * - * TRUE indicates that this function is intended to be called with the 'submit' - * semantics + *

TRUE indicates that this function is intended to be called with the 'submit' + * semantics

* - * FALSE indicates that this is intended to be called with the evaluate - * semantics + *

FALSE indicates that this is intended to be called with the evaluate + * semantics

* * @return boolean, default is true * @deprecated Please use intent @@ -52,11 +59,12 @@ enum TYPE { /** * What are submit semantics for this transaction. - * - * SUBMIT - indicates that this function is intended to be called with the - * 'submit' semantics EVALUATE - indicates that this is intended to be called - * with the 'evaluate' semantics - * + *
+ *
SUBMIT
indicates that this function is intended to be called with the + * 'submit' semantics
+ *
EVALUATE
indicates that this is intended to be called + * with the 'evaluate' semantics
+ *
* @return submit semantics */ TYPE intent() default Transaction.TYPE.SUBMIT; diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/routing/TxFunction.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/routing/TxFunction.java index b2df42030..860e22783 100644 --- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/routing/TxFunction.java +++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/routing/TxFunction.java @@ -15,13 +15,32 @@ public interface TxFunction { interface Routing { - + /** + * Method to route calls to the transaction function. + * @return a method. + */ Method getMethod(); + /** + * The associated contract class. + * @return a contract class. + */ Class getContractClass(); + /** + * The associated contract instance. + * @return a contract. + * @throws IllegalAccessException + * @throws InstantiationException + * @throws InvocationTargetException + * @throws NoSuchMethodException + */ ContractInterface getContractInstance() throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException; + /** + * Name of the serializer used for the transaction function. + * @return a serializer name. + */ String getSerializerName(); } @@ -31,7 +50,7 @@ interface Routing { boolean isUnknownTx(); /** - * @param unknown + * @param unknown true if the transaction is to be called when the request fn is unknown; otherwise false. */ void setUnknownTx(boolean unknown); diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/ledger/impl/package-info.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/ledger/impl/package-info.java new file mode 100644 index 000000000..96b288ea9 --- /dev/null +++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/ledger/impl/package-info.java @@ -0,0 +1,6 @@ +/* + * Copyright 2023 IBM All Rights Reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.fabric.ledger.impl; diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/Chaincode.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/Chaincode.java index 8209c6660..046595df3 100644 --- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/Chaincode.java +++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/Chaincode.java @@ -39,23 +39,38 @@ public interface Chaincode { * and{@link #invoke(ChaincodeStub)} */ class Response { - private final int statusCode; private final String message; private final byte[] payload; + /** + * Constructor. + * @param status a status object. + * @param message a response message. + * @param payload a response payload. + */ public Response(final Status status, final String message, final byte[] payload) { this.statusCode = status.getCode(); this.message = message; this.payload = payload; } + /** + * Constructor. + * @param statusCode a status code. + * @param message a response message. + * @param payload a response payload. + */ public Response(final int statusCode, final String message, final byte[] payload) { this.statusCode = statusCode; this.message = message; this.payload = payload; } + /** + * Get the response status. + * @return status. + */ public Status getStatus() { if (Status.hasStatusForCode(statusCode)) { return Status.forCode(statusCode); @@ -64,18 +79,34 @@ public Status getStatus() { } } + /** + * Get the response status code. + * @return status code. + */ public int getStatusCode() { return statusCode; } + /** + * Get the response message. + * @return a message. + */ public String getMessage() { return message; } + /** + * Get the response payload. + * @return payload bytes. + */ public byte[] getPayload() { return payload; } + /** + * Get the response payload as a UTF-8 string. + * @return a string. + */ public String getStringPayload() { return (payload == null) ? null : new String(payload, UTF_8); } @@ -84,7 +115,18 @@ public String getStringPayload() { * {@link Response} status enum. */ public enum Status { - SUCCESS(200), ERROR_THRESHOLD(400), INTERNAL_SERVER_ERROR(500); + /** + * Successful response status. + */ + SUCCESS(200), + /** + * Minimum threshold for as error status code. + */ + ERROR_THRESHOLD(400), + /** + * Server-side error status. + */ + INTERNAL_SERVER_ERROR(500); private static final Map CODETOSTATUS = new HashMap<>(); private final int code; @@ -93,10 +135,19 @@ public enum Status { this.code = code; } + /** + * Get the status code associated with this status object. + * @return a status code. + */ public int getCode() { return code; } + /** + * Get a status object for a given status code. + * @param code a status code. + * @return a status object. + */ public static Status forCode(final int code) { final Status result = CODETOSTATUS.get(code); if (result == null) { @@ -105,6 +156,11 @@ public static Status forCode(final int code) { return result; } + /** + * Whether a status exists for a given status code. + * @param code a status code. + * @return True if a status for the code exists; otherwise false. + */ public static boolean hasStatusForCode(final int code) { return CODETOSTATUS.containsKey(code); } diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeServerProperties.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeServerProperties.java index 6e9f01922..27c842572 100644 --- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeServerProperties.java +++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeServerProperties.java @@ -8,14 +8,13 @@ import java.net.SocketAddress; public final class ChaincodeServerProperties { - private SocketAddress serverAddress; - private int maxInboundMetadataSize = 100 * 1024 * 1024; - private int maxInboundMessageSize = 100 * 1024 * 1024; - private int maxConnectionAgeSeconds = 5; - private int keepAliveTimeoutSeconds = 20; - private int permitKeepAliveTimeMinutes = 1; - private int keepAliveTimeMinutes = 1; + private int maxInboundMetadataSize = 100 * 1024 * 1024; // checkstyle:ignore-line:MagicNumber + private int maxInboundMessageSize = 100 * 1024 * 1024; // checkstyle:ignore-line:MagicNumber + private int maxConnectionAgeSeconds = 5; // checkstyle:ignore-line:MagicNumber + private int keepAliveTimeoutSeconds = 20; // checkstyle:ignore-line:MagicNumber + private int permitKeepAliveTimeMinutes = 1; // checkstyle:ignore-line:MagicNumber + private int keepAliveTimeMinutes = 1; // checkstyle:ignore-line:MagicNumber private boolean permitKeepAliveWithoutCalls = true; private String keyPassword; private String keyCertChainFile; @@ -23,9 +22,24 @@ public final class ChaincodeServerProperties { private String trustCertCollectionFile; private boolean tlsEnabled = false; + /** + * Constructor using default configuration. + */ public ChaincodeServerProperties() { } + /** + * Constructor. + * @param portChaincodeServer ignored. + * @param maxInboundMetadataSize the maximum metadata size allowed to be received by the server. + * @param maxInboundMessageSize the maximum message size allowed to be received by the server. + * @param maxConnectionAgeSeconds the maximum connection age in seconds. + * @param keepAliveTimeoutSeconds timeout for a keep-alive ping request in seconds. + * @param permitKeepAliveTimeMinutes the most aggressive keep-alive time clients are permitted to configure in minutes. + * @param keepAliveTimeMinutes delay before server sends a keep-alive in minutes. + * @param permitKeepAliveWithoutCalls whether clients are allowed to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection. + */ + // checkstyle:ignore-next-line:ParameterNumber public ChaincodeServerProperties( final int portChaincodeServer, final int maxInboundMetadataSize, final int maxInboundMessageSize, final int maxConnectionAgeSeconds, final int keepAliveTimeoutSeconds, final int permitKeepAliveTimeMinutes, @@ -41,114 +55,226 @@ public ChaincodeServerProperties( this.permitKeepAliveWithoutCalls = permitKeepAliveWithoutCalls; } + /** + * The maximum size of metadata allowed to be received. + * @return The maximum metadata size allowed. + */ public int getMaxInboundMetadataSize() { return maxInboundMetadataSize; } + /** + * Sets the maximum metadata size allowed to be received by the server. + * @param maxInboundMetadataSize The new maximum size allowed for incoming metadata. + */ public void setMaxInboundMetadataSize(final int maxInboundMetadataSize) { this.maxInboundMetadataSize = maxInboundMetadataSize; } + /** + * The maximum message size allowed to be received by the server. + * @return the maximum message size allowed. + */ public int getMaxInboundMessageSize() { return maxInboundMessageSize; } + /** + * Sets the maximum message size allowed to be received by the server. + * @param maxInboundMessageSize The new maximum size allowed for incoming messages. + */ public void setMaxInboundMessageSize(final int maxInboundMessageSize) { this.maxInboundMessageSize = maxInboundMessageSize; } + /** + * The maximum connection age. + * @return The maximum connection age in seconds. + */ public int getMaxConnectionAgeSeconds() { return maxConnectionAgeSeconds; } + /** + * Specify a maximum connection age. + * @param maxConnectionAgeSeconds The maximum connection age in seconds. + */ public void setMaxConnectionAgeSeconds(final int maxConnectionAgeSeconds) { this.maxConnectionAgeSeconds = maxConnectionAgeSeconds; } + /** + * The timeout for a keep-alive ping requests. + * @return timeout in seconds. + */ public int getKeepAliveTimeoutSeconds() { return keepAliveTimeoutSeconds; } + /** + * Set the timeout for keep-alive ping requests. + * @param keepAliveTimeoutSeconds timeout in seconds. + */ public void setKeepAliveTimeoutSeconds(final int keepAliveTimeoutSeconds) { this.keepAliveTimeoutSeconds = keepAliveTimeoutSeconds; } + /** + * The most aggressive keep-alive time clients are permitted to configure. + * @return time in minutes. + */ public int getPermitKeepAliveTimeMinutes() { return permitKeepAliveTimeMinutes; } + /** + * Specify the most aggressive keep-alive time clients are permitted to configure. + * @param permitKeepAliveTimeMinutes time in minutes. + */ public void setPermitKeepAliveTimeMinutes(final int permitKeepAliveTimeMinutes) { this.permitKeepAliveTimeMinutes = permitKeepAliveTimeMinutes; } + /** + * The delay before the server sends a keep-alive. + * @return delay in minutes. + */ public int getKeepAliveTimeMinutes() { return keepAliveTimeMinutes; } + /** + * Set the delay before the server sends a keep-alive. + * @param keepAliveTimeMinutes delay in minutes. + */ public void setKeepAliveTimeMinutes(final int keepAliveTimeMinutes) { this.keepAliveTimeMinutes = keepAliveTimeMinutes; } + /** + * Whether clients are allowed to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection. + * @return true if clients are allowed to send keep-alive requests without calls; otherwise false. + */ public boolean getPermitKeepAliveWithoutCalls() { return permitKeepAliveWithoutCalls; } + /** + * Get the server socket address. + * @return a socket address. + */ public SocketAddress getServerAddress() { return serverAddress; } + /** + * Set the server socket address. + * @param address a socket address. + */ public void setServerAddress(final SocketAddress address) { this.serverAddress = address; } + /** + * Whether clients are allowed to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection. + * @return true if clients are allowed to send keep-alive requests without calls; otherwise false. + */ public boolean isPermitKeepAliveWithoutCalls() { return permitKeepAliveWithoutCalls; } + /** + * Specify whether clients are allowed to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection. + * @param permitKeepAliveWithoutCalls Whether to allow clients to send keep-alive requests without calls. + */ public void setPermitKeepAliveWithoutCalls(final boolean permitKeepAliveWithoutCalls) { this.permitKeepAliveWithoutCalls = permitKeepAliveWithoutCalls; } + /** + * Password used to access the server key. + * @return a password. + */ public String getKeyPassword() { return keyPassword; } + /** + * Set the password used to access the server key. + * @param keyPassword a password. + */ public void setKeyPassword(final String keyPassword) { this.keyPassword = keyPassword; } + /** + * Server keychain file name. + * @return a file name. + */ public String getKeyCertChainFile() { return keyCertChainFile; } + /** + * Set the server keychain file name. + * @param keyCertChainFile a file name. + */ public void setKeyCertChainFile(final String keyCertChainFile) { this.keyCertChainFile = keyCertChainFile; } + /** + * Server key file name. + * @return a file name. + */ public String getKeyFile() { return keyFile; } + /** + * Set the server key file name. + * @param keyFile a file name. + */ public void setKeyFile(final String keyFile) { this.keyFile = keyFile; } + /** + * Server trust certificate collection file name. + * @return a file name. + */ public String getTrustCertCollectionFile() { return trustCertCollectionFile; } + /** + * Set the server trust certificate collection file name. + * @param trustCertCollectionFile a file name. + */ public void setTrustCertCollectionFile(final String trustCertCollectionFile) { this.trustCertCollectionFile = trustCertCollectionFile; } + /** + * Whether TLS is enabled for the server. + * @return true if TLS is enabled; otherwise false. + */ public boolean isTlsEnabled() { return tlsEnabled; } + /** + * Set whether TLS is enabled for the server. + * @param tlsEnabled true to enable TLS; otherwise false. + */ public void setTlsEnabled(final boolean tlsEnabled) { this.tlsEnabled = tlsEnabled; } + /** + * Check that all the server property values are valid. + * @throws IllegalArgumentException if any properties are not valid. + */ public void validate() { if (this.getServerAddress() == null) { throw new IllegalArgumentException("chaincodeServerProperties.getServerAddress() must be set"); diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeStub.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeStub.java index f049dbb58..7c77f5daa 100644 --- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeStub.java +++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeStub.java @@ -572,8 +572,15 @@ public interface ChaincodeStub { QueryResultsIterator getPrivateDataQueryResult(String collection, String query); /** - * Defines the CHAINCODE type event that will be posted to interested clients - * when the chaincode's result is committed to the ledger. + * Allows the chaincode to propose an event on the transaction proposal response. + * When the transaction is included in a block and the block is successfully committed to the ledger, + * the block event (including transaction level chaincode events) + * will be delivered to the current client application event listeners that have been registered with the peer's event producer. + * Consult each SDK's documentation for details. + * Only a single chaincode event can be included in a transaction. + * If setEvent() is called multiple times only the last event will be included in the transaction. + * The event must originate from the outer-most invoked chaincode in chaincode-to-chaincode scenarios. + * The marshaled ChaincodeEvent will be available in the transaction's ChaincodeAction.events field. * * @param name Name of event. Cannot be null or empty string. * @param payload Optional event payload. diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ext/sbe/impl/package-info.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ext/sbe/impl/package-info.java new file mode 100644 index 000000000..f4f3bb511 --- /dev/null +++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ext/sbe/impl/package-info.java @@ -0,0 +1,6 @@ +/* + * Copyright 2023 IBM All Rights Reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.fabric.shim.ext.sbe.impl; diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProvider.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProvider.java index 5610985b1..696aececb 100644 --- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProvider.java +++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProvider.java @@ -11,12 +11,15 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.grpc.v1_6.GrpcTracing; -import io.opentelemetry.sdk.autoconfigure.OpenTelemetrySdkAutoConfiguration; -import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; +import io.opentelemetry.instrumentation.grpc.v1_6.GrpcTelemetry; +import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; +import io.opentelemetry.semconv.ResourceAttributes; + import org.hyperledger.fabric.shim.ChaincodeStub; import org.hyperledger.fabric.traces.TracesProvider; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; public final class OpenTelemetryTracesProvider implements TracesProvider { @@ -26,17 +29,31 @@ public final class OpenTelemetryTracesProvider implements TracesProvider { private static final String CORE_CHAINCODE_ID_NAME = "CORE_CHAINCODE_ID_NAME"; private Tracer tracer; - private GrpcTracing grpcTracer; + private GrpcTelemetry grpcTracer; @Override public void initialize(final Properties props) { String serviceName = props.getProperty(CORE_CHAINCODE_ID_NAME, "unknown"); props.setProperty(ResourceAttributes.SERVICE_NAME.getKey(), serviceName); - OpenTelemetry openTelemetry = OpenTelemetrySdkAutoConfiguration.initialize(false, - new OpenTelemetryProperties(System.getenv(), System.getProperties(), props)); + OpenTelemetry openTelemetry = AutoConfiguredOpenTelemetrySdk.builder() + .addPropertiesSupplier(() -> getOpenTelemetryProperties(props)) + .build() + .getOpenTelemetrySdk(); + tracer = openTelemetry.getTracerProvider().get("org.hyperledger.traces"); - grpcTracer = GrpcTracing.newBuilder(openTelemetry).build(); + grpcTracer = GrpcTelemetry.create(openTelemetry); + } + + private Map getOpenTelemetryProperties(final Properties props) { + Map results = new HashMap<>(System.getenv()); + + Properties systemProps = System.getProperties(); + systemProps.stringPropertyNames().forEach(key -> results.put(key, systemProps.getProperty(key))); + + props.stringPropertyNames().forEach(key -> results.put(key, props.getProperty(key))); + + return results; } @Override diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/package-info.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/package-info.java new file mode 100644 index 000000000..b8aef10b1 --- /dev/null +++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/package-info.java @@ -0,0 +1,6 @@ +/* + * Copyright 2023 IBM All Rights Reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.fabric.traces.impl; diff --git a/fabric-chaincode-shim/src/test/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProviderTest.java b/fabric-chaincode-shim/src/test/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProviderTest.java index 3b900b360..7b03a3f2d 100644 --- a/fabric-chaincode-shim/src/test/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProviderTest.java +++ b/fabric-chaincode-shim/src/test/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProviderTest.java @@ -40,7 +40,7 @@ public final class OpenTelemetryTracesProviderTest { - private class ContextGetterChaincode extends ChaincodeBase { + private final class ContextGetterChaincode extends ChaincodeBase { @Override public Response init(final ChaincodeStub stub) { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c02..afba10928 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 05679dc3c..b1624c473 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0c8..65dcd68d6 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,101 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -106,80 +140,105 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index ac1b06f93..6689b85be 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal