Skip to content

Commit 750f937

Browse files
jt-ntiSimon Stone
authored and
Simon Stone
committed
[FAB-15213] Add Java FabCar sample contract
Change-Id: I0ae40c2a02aea8293a348038e3e1bd02f7030509 Signed-off-by: James Taylor <jamest@uk.ibm.com>
1 parent abbda95 commit 750f937

File tree

15 files changed

+1217
-0
lines changed

15 files changed

+1217
-0
lines changed

chaincode/fabcar/java/.gitignore

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
# Compiled class file
7+
*.class
8+
9+
# Log file
10+
*.log
11+
12+
# BlueJ files
13+
*.ctxt
14+
15+
# Mobile Tools for Java (J2ME)
16+
.mtj.tmp/
17+
18+
# Package Files
19+
*.jar
20+
*.war
21+
*.nar
22+
*.ear
23+
*.zip
24+
*.tar.gz
25+
*.rar
26+
27+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
28+
hs_err_pid*
29+
30+
# Gradle
31+
.gradle
32+
/build/
33+
34+
# Ignore Gradle GUI config
35+
gradle-app.setting
36+
37+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
38+
!gradle-wrapper.jar
39+
40+
# Cache of project
41+
.gradletasknamecache
42+
43+
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
44+
# gradle/wrapper/gradle-wrapper.properties
45+
46+
# Eclipse files
47+
.project
48+
.classpath
49+
.metadata
50+
bin/
51+
tmp/
52+
*.tmp
53+
*.bak
54+
*.swp
55+
*~.nib
56+
local.properties
57+
.settings/
58+
.loadpath
59+
.recommenders
60+
.externalToolBuilders/
61+
*.launch

chaincode/fabcar/java/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Java FabCar contract sample
2+
3+
The directions for using this sample are documented in the Hyperledger Fabric
4+
[Writing Your First Application](https://hyperledger-fabric.readthedocs.io/en/latest/write_first_app.html) tutorial.
5+
6+
The tutorial is based on JavaScript, however the same concepts are applicable when using Java.
7+
8+
To install and instantiate the Java version of `FabCar`, use the following command instead of the command shown in the [Launch the network](https://hyperledger-fabric.readthedocs.io/en/release-1.4/write_first_app.html#launch-the-network) section of the tutorial:
9+
10+
```
11+
./startFabric.sh javascript
12+
```
13+
14+
*NOTE:* After navigating to the documentation, choose the documentation version that matches your version of Fabric

chaincode/fabcar/java/build.gradle

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
plugins {
6+
id 'checkstyle'
7+
id 'com.github.johnrengelman.shadow' version '2.0.4'
8+
id 'java-library'
9+
id 'jacoco'
10+
}
11+
12+
group 'org.hyperledger.fabric.samples'
13+
version '1.0-SNAPSHOT'
14+
15+
dependencies {
16+
implementation 'org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.0.0-SNAPSHOT'
17+
implementation 'com.owlike:genson:1.5'
18+
testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2'
19+
testImplementation 'org.assertj:assertj-core:3.11.1'
20+
testImplementation 'org.mockito:mockito-core:2.+'
21+
}
22+
23+
repositories {
24+
maven {
25+
url "https://nexus.hyperledger.org/content/repositories/snapshots/"
26+
}
27+
jcenter()
28+
maven {
29+
url 'https://jitpack.io'
30+
}
31+
}
32+
33+
checkstyle {
34+
toolVersion '8.21'
35+
configFile file("config/checkstyle/checkstyle.xml")
36+
}
37+
38+
checkstyleMain {
39+
source ='src/main/java'
40+
}
41+
42+
checkstyleTest {
43+
source ='src/test/java'
44+
}
45+
46+
shadowJar {
47+
baseName = 'chaincode'
48+
version = null
49+
classifier = null
50+
manifest {
51+
attributes 'Main-Class': 'org.hyperledger.fabric.contract.ContractRouter'
52+
}
53+
}
54+
55+
jacocoTestCoverageVerification {
56+
afterEvaluate {
57+
classDirectories = files(classDirectories.files.collect {
58+
fileTree(dir: it, exclude: [
59+
'org/hyperledger/fabric/samples/fabcar/Start.*'
60+
])
61+
})
62+
}
63+
violationRules {
64+
rule {
65+
limit {
66+
minimum = 1.0
67+
}
68+
}
69+
}
70+
71+
finalizedBy jacocoTestReport
72+
}
73+
74+
test {
75+
useJUnitPlatform()
76+
testLogging {
77+
events "passed", "skipped", "failed"
78+
}
79+
}
80+
81+
check.dependsOn jacocoTestCoverageVerification
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
5+
6+
<!--
7+
8+
Checkstyle configuration that matches the Eclipse formatter
9+
10+
Checkstyle is very configurable. Be sure to read the documentation at
11+
http://checkstyle.sourceforge.net (or in your downloaded distribution).
12+
13+
Most Checks are configurable, be sure to consult the documentation.
14+
15+
To completely disable a check, just comment it out or delete it from the file.
16+
17+
Finally, it is worth reading the documentation.
18+
19+
-->
20+
21+
<module name="Checker">
22+
<!--
23+
If you set the basedir property below, then all reported file
24+
names will be relative to the specified directory. See
25+
https://checkstyle.org/5.x/config.html#Checker
26+
27+
<property name="basedir" value="${basedir}"/>
28+
-->
29+
30+
<property name="fileExtensions" value="java, properties, xml"/>
31+
32+
<module name="SuppressionFilter">
33+
<property name="file" value="config/checkstyle/suppressions.xml"/>
34+
<property name="optional" value="false"/>
35+
</module>
36+
37+
<!-- Excludes all 'module-info.java' files -->
38+
<!-- See https://checkstyle.org/config_filefilters.html -->
39+
<module name="BeforeExecutionExclusionFileFilter">
40+
<property name="fileNamePattern" value="module\-info\.java$"/>
41+
</module>
42+
43+
<!-- Checks that a package-info.java file exists for each package. -->
44+
<!-- See http://checkstyle.sourceforge.net/config_javadoc.html#JavadocPackage -->
45+
<!-- <module name="JavadocPackage"/> -->
46+
47+
<!-- Checks whether files end with a new line. -->
48+
<!-- See http://checkstyle.sourceforge.net/config_misc.html#NewlineAtEndOfFile -->
49+
<module name="NewlineAtEndOfFile"/>
50+
51+
<!-- Checks that property files contain the same keys. -->
52+
<!-- See http://checkstyle.sourceforge.net/config_misc.html#Translation -->
53+
<module name="Translation"/>
54+
55+
<!-- Checks for Size Violations. -->
56+
<!-- See http://checkstyle.sourceforge.net/config_sizes.html -->
57+
<module name="FileLength"/>
58+
59+
<!-- Checks for whitespace -->
60+
<!-- See http://checkstyle.sourceforge.net/config_whitespace.html -->
61+
<module name="FileTabCharacter"/>
62+
63+
<!-- Miscellaneous other checks. -->
64+
<!-- See http://checkstyle.sourceforge.net/config_misc.html -->
65+
<module name="RegexpSingleline">
66+
<property name="format" value="\s+$"/>
67+
<property name="minimum" value="0"/>
68+
<property name="maximum" value="0"/>
69+
<property name="message" value="Line has trailing spaces."/>
70+
</module>
71+
72+
<!-- Checks for Headers -->
73+
<!-- See http://checkstyle.sourceforge.net/config_header.html -->
74+
<!-- <module name="Header"> -->
75+
<!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
76+
<!-- <property name="fileExtensions" value="java"/> -->
77+
<!-- </module> -->
78+
79+
<module name="TreeWalker">
80+
81+
<!-- Checks for Javadoc comments. -->
82+
<!-- See http://checkstyle.sourceforge.net/config_javadoc.html -->
83+
<!-- <module name="JavadocMethod"/> -->
84+
<!-- <module name="JavadocType"/> -->
85+
<!-- <module name="JavadocVariable"/> -->
86+
<!-- <module name="JavadocStyle"/> -->
87+
<!-- <module name="MissingJavadocMethod"/> -->
88+
89+
<!-- Checks for Naming Conventions. -->
90+
<!-- See http://checkstyle.sourceforge.net/config_naming.html -->
91+
<module name="ConstantName"/>
92+
<module name="LocalFinalVariableName"/>
93+
<module name="LocalVariableName"/>
94+
<module name="MemberName"/>
95+
<module name="MethodName"/>
96+
<module name="PackageName"/>
97+
<module name="ParameterName"/>
98+
<module name="StaticVariableName"/>
99+
<module name="TypeName"/>
100+
101+
<!-- Checks for imports -->
102+
<!-- See http://checkstyle.sourceforge.net/config_import.html -->
103+
<module name="AvoidStarImport"/>
104+
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
105+
<module name="RedundantImport"/>
106+
<module name="UnusedImports">
107+
<property name="processJavadoc" value="false"/>
108+
</module>
109+
110+
<!-- Checks for Size Violations. -->
111+
<!-- See http://checkstyle.sourceforge.net/config_sizes.html -->
112+
<module name="LineLength">
113+
<property name="max" value="120"/>
114+
</module>
115+
<module name="MethodLength"/>
116+
<module name="ParameterNumber"/>
117+
118+
<!-- Checks for whitespace -->
119+
<!-- See http://checkstyle.sourceforge.net/config_whitespace.html -->
120+
<module name="EmptyForIteratorPad"/>
121+
<module name="GenericWhitespace"/>
122+
<module name="MethodParamPad"/>
123+
<module name="NoWhitespaceAfter"/>
124+
<module name="NoWhitespaceBefore"/>
125+
<module name="OperatorWrap"/>
126+
<module name="ParenPad"/>
127+
<module name="TypecastParenPad"/>
128+
<module name="WhitespaceAfter"/>
129+
<module name="WhitespaceAround"/>
130+
131+
<!-- Modifier Checks -->
132+
<!-- See http://checkstyle.sourceforge.net/config_modifiers.html -->
133+
<module name="ModifierOrder"/>
134+
<module name="RedundantModifier"/>
135+
136+
<!-- Checks for blocks. You know, those {}'s -->
137+
<!-- See http://checkstyle.sourceforge.net/config_blocks.html -->
138+
<module name="AvoidNestedBlocks"/>
139+
<module name="EmptyBlock"/>
140+
<module name="LeftCurly"/>
141+
<module name="NeedBraces"/>
142+
<module name="RightCurly"/>
143+
144+
<!-- Checks for common coding problems -->
145+
<!-- See http://checkstyle.sourceforge.net/config_coding.html -->
146+
<module name="EmptyStatement"/>
147+
<module name="EqualsHashCode"/>
148+
<module name="HiddenField">
149+
<property name="ignoreConstructorParameter" value="true"/>
150+
</module>
151+
<module name="IllegalInstantiation"/>
152+
<module name="InnerAssignment"/>
153+
<module name="MagicNumber"/>
154+
<module name="MissingSwitchDefault"/>
155+
<module name="MultipleVariableDeclarations"/>
156+
<module name="SimplifyBooleanExpression"/>
157+
<module name="SimplifyBooleanReturn"/>
158+
159+
<!-- Checks for class design -->
160+
<!-- See http://checkstyle.sourceforge.net/config_design.html -->
161+
<module name="DesignForExtension"/>
162+
<module name="FinalClass"/>
163+
<module name="HideUtilityClassConstructor"/>
164+
<module name="InterfaceIsType"/>
165+
<module name="VisibilityModifier">
166+
<property name="allowPublicFinalFields" value="true"/>
167+
</module>
168+
169+
<!-- Miscellaneous other checks. -->
170+
<!-- See http://checkstyle.sourceforge.net/config_misc.html -->
171+
<module name="ArrayTypeStyle"/>
172+
<module name="FinalParameters"/>
173+
<module name="TodoComment"/>
174+
<module name="UpperEll"/>
175+
176+
</module>
177+
178+
</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
3+
<!DOCTYPE suppressions PUBLIC
4+
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
5+
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
6+
7+
<suppressions>
8+
<suppress files="ChaincodeTest.java" checks="ParameterNumber" />
9+
</suppressions>
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)