Skip to content

Commit

Permalink
[FAB-6415] Java 11 support for Commercial Paper sample
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Stone <sstone1@uk.ibm.com>
Change-Id: I3de1927a67723044899dce7ec22d4e46e4c6b944
  • Loading branch information
Simon Stone committed Sep 24, 2019
1 parent 3d19014 commit f2939e2
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 86 deletions.
36 changes: 21 additions & 15 deletions commercial-paper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ This `README.md` file is in the the `commercial-paper` directory, the source cod

## Running the Infrastructure

In one console window, run the `./roles/network-starter.sh` script; this will start the basic infrastructure and also start monitoring all the docker containers.
In one console window, run the `./roles/network-starter.sh` script; this will start the basic infrastructure and also start monitoring all the docker containers.

You can cancel this if you wish to reuse the terminal, but it's best left open.
You can cancel this if you wish to reuse the terminal, but it's best left open.

### Install and Instantiate the contract

Expand All @@ -63,7 +63,7 @@ In your 'MagnetoCorp' window run the following command

`./roles/magnetocorp.sh`

This will start a docker container for Fabric CLI commands, and put you in the correct directory for the source code.
This will start a docker container for Fabric CLI commands, and put you in the correct directory for the source code.

**For a JavaScript Contract:**

Expand All @@ -76,12 +76,18 @@ docker exec cliMagnetoCorp peer chaincode instantiate -n papercontract -v 0 -l n
**For a Java Contract:**

```
docker exec cliMagnetoCorp peer chaincode install -n papercontract -v 0 -p /opt/gopath/src/github.com/contract-java -l java
pushd ./organization/magnetocorp/contract-java
./gradlew installDist
popd
docker exec cliMagnetoCorp peer chaincode install -n papercontract -v 0 -p /opt/gopath/src/github.com/contract-java/build/install/papercontract -l java
docker exec cliMagnetoCorp peer chaincode instantiate -n papercontract -v 0 -l java -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' -C mychannel -P "AND ('Org1MSP.member')"
```
> If you want to try both a Java and JavaScript Contract, then you will need to restart the infrastructure and deploy the other contract.

> If you want to try both a Java and JavaScript Contract, then you will need to restart the infrastructure and deploy the other contract.
## Client Applications

Expand All @@ -100,42 +106,42 @@ npm install

> Note that there is NO dependency between the langauge of any one client application and any contract. Mix and match as you wish!
### Issue the paper
### Issue the paper

This is running as *MagnetoCorp* so you can stay in the same window. These commands are to be run in the
This is running as *MagnetoCorp* so you can stay in the same window. These commands are to be run in the
`commercial-paper/organization/magnetocorp/application` directory or the `commercial-paper/organization/magnetocorp/application-java`

*Add the Identity to be used*

```
node addToWallet.js
# or
# or
java -cp target/commercial-paper-0.0.1-SNAPSHOT.jar org.magnetocorp.AddToWallet
```

*Issue the Commercial Paper*

```
node issue.js
# or
# or
java -cp target/commercial-paper-0.0.1-SNAPSHOT.jar org.magnetocorp.Issue
```

### Buy and Redeem the paper

This is running as *Digibank*; you've not acted as this organization before so in your 'Digibank' window run the following command in the
This is running as *Digibank*; you've not acted as this organization before so in your 'Digibank' window run the following command in the
`fabric-samples/commercial-paper/` directory

`./roles/digibank.sh`
`./roles/digibank.sh`

You can now run the applications to buy and redeem the paper. Change to either the
You can now run the applications to buy and redeem the paper. Change to either the
`commercial-paper/organization/digibank/application` directory or `commercial-paper/organization/digibank/application-java`

*Add the Identity to be used*

```
node addToWallet.js
# or
# or
java -cp target/commercial-paper-0.0.1-SNAPSHOT.jar org.digibank.AddToWallet
```

Expand All @@ -151,6 +157,6 @@ java -cp target/commercial-paper-0.0.1-SNAPSHOT.jar org.digibank.Buy

```
node redeem.js
# or
# or
java -cp target/commercial-paper-0.0.1-SNAPSHOT.jar org.digibank.Redeem
```
13 changes: 10 additions & 3 deletions commercial-paper/organization/digibank/contract-java/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.gradle/
build/
bin/
#
# SPDX-License-Identifier: Apache-2.0
#

/.classpath
/.gradle/
/.project
/.settings/
/bin/
/build/
21 changes: 4 additions & 17 deletions commercial-paper/organization/digibank/contract-java/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
plugins {
id 'com.github.johnrengelman.shadow' version '2.0.3'
id 'java'
id 'java-library-distribution'
}

version '0.0.1'

sourceCompatibility = 1.8

repositories {

mavenLocal()
mavenCentral()
maven {
url 'https://jitpack.io'
maven {
url 'https://jitpack.io'
}
maven {
url "https://nexus.hyperledger.org/content/repositories/snapshots/"
Expand All @@ -21,31 +19,20 @@ repositories {
}

dependencies {
compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.4.2'
compileOnly group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.4.2'
compile group: 'org.json', name: 'json', version: '20180813'
testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2'
testImplementation 'org.assertj:assertj-core:3.11.1'
testImplementation 'org.mockito:mockito-core:2.+'
}

shadowJar {
baseName = 'chaincode'
version = null
classifier = null

manifest {
attributes 'Main-Class': 'org.hyperledger.fabric.contract.ContractRouter'
}
}

test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}


tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-parameters"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 19 additions & 3 deletions commercial-paper/organization/digibank/contract-java/gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -109,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# 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"`
Expand Down
18 changes: 17 additions & 1 deletion commercial-paper/organization/digibank/contract-java/gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
Expand All @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@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=
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'java-contractcontract'
rootProject.name = 'papercontract'

Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public CommercialPaper issue(CommercialPaperContext ctx, String issuer, String p

// create an instance of the paper
CommercialPaper paper = CommercialPaper.createInstance(issuer, paperNumber, issueDateTime, maturityDateTime,
faceValue,"");
faceValue,issuer,"");

// Smart contract, rather than paper, moves paper into ISSUED state
paper.setIssued();
Expand Down
18 changes: 0 additions & 18 deletions commercial-paper/organization/magnetocorp/contract-java/.classpath

This file was deleted.

13 changes: 10 additions & 3 deletions commercial-paper/organization/magnetocorp/contract-java/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.gradle/
build/
bin/
#
# SPDX-License-Identifier: Apache-2.0
#

/.classpath
/.gradle/
/.project
/.settings/
/bin/
/build/
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
plugins {
id 'com.github.johnrengelman.shadow' version '2.0.3'
id 'java'
id 'java-library-distribution'
}

version '0.0.1'

sourceCompatibility = 1.8

repositories {

mavenLocal()
mavenCentral()
maven {
url 'https://jitpack.io'
maven {
url 'https://jitpack.io'
}
maven {
url "https://nexus.hyperledger.org/content/repositories/snapshots/"
Expand All @@ -21,31 +19,20 @@ repositories {
}

dependencies {
compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.4.2'
compileOnly group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.4.2'
compile group: 'org.json', name: 'json', version: '20180813'
testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2'
testImplementation 'org.assertj:assertj-core:3.11.1'
testImplementation 'org.mockito:mockito-core:2.+'
}

shadowJar {
baseName = 'chaincode'
version = null
classifier = null

manifest {
attributes 'Main-Class': 'org.hyperledger.fabric.contract.ContractRouter'
}
}

test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}


tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-parameters"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit f2939e2

Please sign in to comment.