Skip to content

Commit f2939e2

Browse files
author
Simon Stone
committed
[FAB-6415] Java 11 support for Commercial Paper sample
Signed-off-by: Simon Stone <sstone1@uk.ibm.com> Change-Id: I3de1927a67723044899dce7ec22d4e46e4c6b944
1 parent 3d19014 commit f2939e2

File tree

17 files changed

+126
-86
lines changed

17 files changed

+126
-86
lines changed

commercial-paper/README.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ This `README.md` file is in the the `commercial-paper` directory, the source cod
5151

5252
## Running the Infrastructure
5353

54-
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.
54+
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.
5555

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

5858
### Install and Instantiate the contract
5959

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

6464
`./roles/magnetocorp.sh`
6565

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

6868
**For a JavaScript Contract:**
6969

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

7878
```
79-
docker exec cliMagnetoCorp peer chaincode install -n papercontract -v 0 -p /opt/gopath/src/github.com/contract-java -l java
79+
pushd ./organization/magnetocorp/contract-java
80+
81+
./gradlew installDist
82+
83+
popd
84+
85+
docker exec cliMagnetoCorp peer chaincode install -n papercontract -v 0 -p /opt/gopath/src/github.com/contract-java/build/install/papercontract -l java
8086
8187
docker exec cliMagnetoCorp peer chaincode instantiate -n papercontract -v 0 -l java -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' -C mychannel -P "AND ('Org1MSP.member')"
8288
```
83-
84-
> If you want to try both a Java and JavaScript Contract, then you will need to restart the infrastructure and deploy the other contract.
89+
90+
> If you want to try both a Java and JavaScript Contract, then you will need to restart the infrastructure and deploy the other contract.
8591
8692
## Client Applications
8793

@@ -100,42 +106,42 @@ npm install
100106

101107
> Note that there is NO dependency between the langauge of any one client application and any contract. Mix and match as you wish!
102108
103-
### Issue the paper
109+
### Issue the paper
104110

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

108114
*Add the Identity to be used*
109115

110116
```
111117
node addToWallet.js
112-
# or
118+
# or
113119
java -cp target/commercial-paper-0.0.1-SNAPSHOT.jar org.magnetocorp.AddToWallet
114120
```
115121

116122
*Issue the Commercial Paper*
117123

118124
```
119125
node issue.js
120-
# or
126+
# or
121127
java -cp target/commercial-paper-0.0.1-SNAPSHOT.jar org.magnetocorp.Issue
122128
```
123129

124130
### Buy and Redeem the paper
125131

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

129-
`./roles/digibank.sh`
135+
`./roles/digibank.sh`
130136

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

134140
*Add the Identity to be used*
135141

136142
```
137143
node addToWallet.js
138-
# or
144+
# or
139145
java -cp target/commercial-paper-0.0.1-SNAPSHOT.jar org.digibank.AddToWallet
140146
```
141147

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

152158
```
153159
node redeem.js
154-
# or
160+
# or
155161
java -cp target/commercial-paper-0.0.1-SNAPSHOT.jar org.digibank.Redeem
156162
```
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
.gradle/
2-
build/
3-
bin/
1+
#
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
5+
/.classpath
6+
/.gradle/
7+
/.project
8+
/.settings/
9+
/bin/
10+
/build/
Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
plugins {
2-
id 'com.github.johnrengelman.shadow' version '2.0.3'
3-
id 'java'
2+
id 'java-library-distribution'
43
}
54

65
version '0.0.1'
76

87
sourceCompatibility = 1.8
98

109
repositories {
11-
1210
mavenLocal()
1311
mavenCentral()
14-
maven {
15-
url 'https://jitpack.io'
12+
maven {
13+
url 'https://jitpack.io'
1614
}
1715
maven {
1816
url "https://nexus.hyperledger.org/content/repositories/snapshots/"
@@ -21,31 +19,20 @@ repositories {
2119
}
2220

2321
dependencies {
24-
compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.4.2'
22+
compileOnly group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.4.2'
2523
compile group: 'org.json', name: 'json', version: '20180813'
2624
testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2'
2725
testImplementation 'org.assertj:assertj-core:3.11.1'
2826
testImplementation 'org.mockito:mockito-core:2.+'
2927
}
3028

31-
shadowJar {
32-
baseName = 'chaincode'
33-
version = null
34-
classifier = null
35-
36-
manifest {
37-
attributes 'Main-Class': 'org.hyperledger.fabric.contract.ContractRouter'
38-
}
39-
}
40-
4129
test {
4230
useJUnitPlatform()
4331
testLogging {
4432
events "passed", "skipped", "failed"
4533
}
4634
}
4735

48-
4936
tasks.withType(JavaCompile) {
5037
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-parameters"
5138
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

commercial-paper/organization/digibank/contract-java/gradlew

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/usr/bin/env sh
22

3+
#
4+
# Copyright 2015 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
319
##############################################################################
420
##
521
## Gradle start up script for UN*X
@@ -28,7 +44,7 @@ APP_NAME="Gradle"
2844
APP_BASE_NAME=`basename "$0"`
2945

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

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

112-
# For Cygwin, switch paths to Windows format before running java
113-
if $cygwin ; then
128+
# For Cygwin or MSYS, switch paths to Windows format before running java
129+
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
114130
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115131
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116132
JAVACMD=`cygpath --unix "$JAVACMD"`

commercial-paper/organization/digibank/contract-java/gradlew.bat

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
@rem
2+
@rem Copyright 2015 the original author or authors.
3+
@rem
4+
@rem Licensed under the Apache License, Version 2.0 (the "License");
5+
@rem you may not use this file except in compliance with the License.
6+
@rem You may obtain a copy of the License at
7+
@rem
8+
@rem https://www.apache.org/licenses/LICENSE-2.0
9+
@rem
10+
@rem Unless required by applicable law or agreed to in writing, software
11+
@rem distributed under the License is distributed on an "AS IS" BASIS,
12+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
@rem See the License for the specific language governing permissions and
14+
@rem limitations under the License.
15+
@rem
16+
117
@if "%DEBUG%" == "" @echo off
218
@rem ##########################################################################
319
@rem
@@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
1430
set APP_HOME=%DIRNAME%
1531

1632
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17-
set DEFAULT_JVM_OPTS=
33+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
1834

1935
@rem Find java.exe
2036
if defined JAVA_HOME goto findJavaFromJavaHome
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
rootProject.name = 'java-contractcontract'
1+
rootProject.name = 'papercontract'
22

commercial-paper/organization/digibank/contract-java/src/main/java/org/example/CommercialPaperContract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public CommercialPaper issue(CommercialPaperContext ctx, String issuer, String p
7474

7575
// create an instance of the paper
7676
CommercialPaper paper = CommercialPaper.createInstance(issuer, paperNumber, issueDateTime, maturityDateTime,
77-
faceValue,"");
77+
faceValue,issuer,"");
7878

7979
// Smart contract, rather than paper, moves paper into ISSUED state
8080
paper.setIssued();

commercial-paper/organization/magnetocorp/contract-java/.classpath

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
.gradle/
2-
build/
3-
bin/
1+
#
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
5+
/.classpath
6+
/.gradle/
7+
/.project
8+
/.settings/
9+
/bin/
10+
/build/
Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
plugins {
2-
id 'com.github.johnrengelman.shadow' version '2.0.3'
3-
id 'java'
2+
id 'java-library-distribution'
43
}
54

65
version '0.0.1'
76

87
sourceCompatibility = 1.8
98

109
repositories {
11-
1210
mavenLocal()
1311
mavenCentral()
14-
maven {
15-
url 'https://jitpack.io'
12+
maven {
13+
url 'https://jitpack.io'
1614
}
1715
maven {
1816
url "https://nexus.hyperledger.org/content/repositories/snapshots/"
@@ -21,31 +19,20 @@ repositories {
2119
}
2220

2321
dependencies {
24-
compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.4.2'
22+
compileOnly group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.4.2'
2523
compile group: 'org.json', name: 'json', version: '20180813'
2624
testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2'
2725
testImplementation 'org.assertj:assertj-core:3.11.1'
2826
testImplementation 'org.mockito:mockito-core:2.+'
2927
}
3028

31-
shadowJar {
32-
baseName = 'chaincode'
33-
version = null
34-
classifier = null
35-
36-
manifest {
37-
attributes 'Main-Class': 'org.hyperledger.fabric.contract.ContractRouter'
38-
}
39-
}
40-
4129
test {
4230
useJUnitPlatform()
4331
testLogging {
4432
events "passed", "skipped", "failed"
4533
}
4634
}
4735

48-
4936
tasks.withType(JavaCompile) {
5037
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-parameters"
5138
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)