Skip to content

Commit 509bfbf

Browse files
committed
[FAB-13802] Metadata Support
- Added a classes to represent logical aspects of the contracts; these are stored in 2 registries - Metadata Builder uses these classes to create the JSON form of the metadata - As does the router to get access to the code to execute - Added a Contract specific runtime exception to help with explaining to users what went wrong - Found that the Commons logging never picked up on the debug statements; so added a simple wrapper to route via standard java.util.logging. also allowed some extra processing for exceptions - Adjusted a number of the log points to use lambdas to improve performance - White space removal Change-Id: I9752b2e7c2ba62f521abbdbfcc86b3c4f2baa693 Signed-off-by: Matthew B. White <[email protected]>
1 parent 526f36d commit 509bfbf

File tree

57 files changed

+2545
-496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2545
-496
lines changed

build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ allprojects {
1212
mavenLocal()
1313
jcenter()
1414
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
15+
maven { url 'https://jitpack.io' }
16+
mavenCentral()
1517
}
1618
}
1719

@@ -34,4 +36,8 @@ subprojects {
3436
testCompile 'org.mockito:mockito-core:2.23.0'
3537
testCompile 'com.github.stefanbirkner:system-rules:1.17.0'
3638
}
37-
}
39+
40+
tasks.withType(JavaCompile) {
41+
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
42+
}
43+
}

fabric-chaincode-docker/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
buildscript {
88
repositories {
9+
mavenLocal()
910
jcenter()
11+
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
12+
maven { url 'https://jitpack.io' }
1013
mavenCentral()
1114
}
1215
dependencies {

fabric-chaincode-example-gradle/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ sourceCompatibility = 1.8
1111
repositories {
1212
mavenLocal()
1313
mavenCentral()
14+
maven { url 'https://jitpack.io' }
1415
}
1516

1617
dependencies {

fabric-chaincode-example-maven/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
<java.version>1.8</java.version>
1010
</properties>
1111

12+
<repositories>
13+
<repository>
14+
<id>jitpack.io</id>
15+
<url>https://jitpack.io</url>
16+
</repository>
17+
</repositories>
18+
1219
<dependencies>
1320

1421
<dependency>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/test/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/main/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/test/
2+
/main/
3+
/default/

fabric-chaincode-shim/build.gradle

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ plugins {
1111
id 'signing'
1212
}
1313

14+
tasks.withType(org.gradle.api.tasks.testing.Test) {
15+
systemProperty 'CORE_CHAINCODE_LOGGING_LEVEL', 'DEBUG'
16+
}
17+
18+
1419
dependencies {
1520
compile project(':fabric-chaincode-protos')
1621
compile 'io.netty:netty-tcnative-boringssl-static:2.0.7.Final'
@@ -19,6 +24,8 @@ dependencies {
1924
compile 'org.bouncycastle:bcprov-jdk15on:1.60'
2025
compile 'org.reflections:reflections:0.9.11'
2126
compile group: 'cglib', name: 'cglib', version: '3.2.10'
27+
implementation 'com.github.everit-org.json-schema:org.everit.json.schema:1.11.1'
28+
implementation group: 'org.json', name: 'json', version: '20180813'
2229
}
2330

2431
sourceSets {
@@ -27,6 +34,7 @@ sourceSets {
2734
srcDirs 'src/main/java'
2835
}
2936

37+
3038
}
3139

3240
test {
@@ -67,6 +75,9 @@ jacocoTestCoverageVerification {
6775
'org.hyperledger.fabric.shim.impl.Handler',
6876
'org.hyperledger.fabric.shim.impl.ChaincodeSupportStream.1',
6977
'org.hyperledger.fabric.contract.ContractRouter',
78+
'org.hyperledger.fabric.contract.routing.impl.ContractDefinitionImpl',
79+
'org.hyperledger.fabric.contract.routing.RoutingRegistry',
80+
'org.hyperledger.fabric.contract.execution.impl.ContractInvocationRequest',
7081
'org.hyperledger.fabric.contract.routing.TransactionType']
7182
limit {
7283
minimum = 0.86
@@ -77,9 +88,12 @@ jacocoTestCoverageVerification {
7788
element = 'CLASS'
7889
includes = ['org.hyperledger.fabric.shim.helper.Channel',
7990
'org.hyperledger.fabric.contract.ContractRouter',
91+
'org.hyperledger.fabric.contract.execution.impl.ContractInvocationRequest',
92+
'org.hyperledger.fabric.contract.routing.impl.ContractDefinitionImpl',
93+
'org.hyperledger.fabric.contract.routing.RoutingRegistry',
8094
'org.hyperledger.fabric.shim.impl.Handler']
8195
limit {
82-
minimum = 0.79
96+
minimum = 0.71
8397
}
8498
}
8599
}
@@ -99,6 +113,7 @@ task licenseCheck {
99113
sourceSet ->
100114
sourceSet.allSource.findAll { !it.path.contains("build") && !it.path.contains("test/resources")}.each {
101115
file ->
116+
if (!file.name.contains("json")){
102117
BufferedReader r = new BufferedReader(new FileReader(file))
103118
def line, hasSPDX = false, hasTraditional = false
104119
while ((line = r.readLine()) != null) {
@@ -118,6 +133,7 @@ task licenseCheck {
118133
missing.add(file)
119134
}
120135
}
136+
}
121137
}
122138
}
123139

@@ -238,3 +254,43 @@ artifacts {
238254

239255

240256
build.dependsOn licenseCheck
257+
258+
// setup more detailed test output formats
259+
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
260+
import org.gradle.api.tasks.testing.logging.TestLogEvent
261+
262+
tasks.withType(Test) {
263+
testLogging {
264+
// set options for log level LIFECYCLE
265+
events TestLogEvent.FAILED,
266+
TestLogEvent.PASSED,
267+
TestLogEvent.SKIPPED,
268+
TestLogEvent.STANDARD_OUT
269+
exceptionFormat TestExceptionFormat.FULL
270+
showExceptions true
271+
showCauses true
272+
showStackTraces true
273+
274+
// set options for log level DEBUG and INFO
275+
debug {
276+
events TestLogEvent.STARTED,
277+
TestLogEvent.FAILED,
278+
TestLogEvent.PASSED,
279+
TestLogEvent.SKIPPED,
280+
TestLogEvent.STANDARD_ERROR,
281+
TestLogEvent.STANDARD_OUT
282+
exceptionFormat TestExceptionFormat.FULL
283+
}
284+
info.events = debug.events
285+
info.exceptionFormat = debug.exceptionFormat
286+
287+
afterSuite { desc, result ->
288+
if (!desc.parent) { // will match the outermost suite
289+
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
290+
def startItem = '| ', endItem = ' |'
291+
def repeatLength = startItem.length() + output.length() + endItem.length()
292+
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
293+
}
294+
}
295+
}
296+
}

fabric-chaincode-shim/src/main/java/commons-logging.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@ java.util.logging.FileHandler.limit=50000
3030
# Optional - The number of files to cycle through, by
3131
# appending an integer to the base file name:
3232
java.util.logging.FileHandler.count=10
33-
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
package org.hyperledger.fabric;
7+
8+
import java.io.PrintWriter;
9+
import java.io.StringWriter;
10+
import java.util.function.Supplier;
11+
import java.util.logging.Level;
12+
13+
public class Logger extends java.util.logging.Logger{
14+
15+
protected Logger(String name) {
16+
super(name, null);
17+
}
18+
19+
public static Logger getLogger(String name) {
20+
return new Logger(name);
21+
}
22+
23+
public void debug(Supplier<String> msgSupplier) {
24+
log(Level.FINEST, msgSupplier);
25+
}
26+
27+
public void debug(String msg) {
28+
log(Level.FINEST, msg);
29+
}
30+
31+
public static Logger getLogger(Class<?> class1) {
32+
return Logger.getLogger(class1.getName());
33+
}
34+
35+
public void error(String message) {
36+
log(Level.SEVERE,message);
37+
}
38+
39+
public void error(Supplier<String> msgSupplier) {
40+
log(Level.SEVERE, msgSupplier);
41+
}
42+
43+
public String formatError(Throwable throwable) {
44+
if (throwable == null) return null;
45+
final StringWriter buffer = new StringWriter();
46+
buffer.append(throwable.getMessage());
47+
throwable.printStackTrace(new PrintWriter(buffer));
48+
49+
Throwable cause = throwable.getCause();
50+
if (cause != null) {
51+
buffer.append(".. caused by ..");
52+
buffer.append(this.formatError(cause));
53+
}
54+
55+
return buffer.toString();
56+
}
57+
58+
}

0 commit comments

Comments
 (0)