Skip to content

Commit c5d9dfa

Browse files
authored
Merge pull request #23 from ftsrg/fix-22-aklenikreview
Partially resolves #22
2 parents 0ab918e + 410dd53 commit c5d9dfa

38 files changed

+763
-577
lines changed

smart-contract/hyperledger-fabric/v2/java/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ build/
99
!**/src/test/**/build/
1010

1111
### IntelliJ IDEA ###
12-
.idea/
12+
**/.idea/
13+
*.iws
14+
*.iml
15+
*.ipr
1316
out/
1417
!**/src/main/**/out/
1518
!**/src/test/**/out/

smart-contract/hyperledger-fabric/v2/java/build.gradle.kts

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* Originally based on https://github.com/mingyang91/openjml-template */
22

3-
import com.diffplug.gradle.spotless.SpotlessExtension
43
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
54
import hu.bme.mit.ftsrg.openjmlhelper.*
5+
import org.gradle.api.tasks.testing.logging.TestLogEvent
66

77
val openJMLDir = layout.projectDirectory.dir(".openjml")
88
val openJMLJavaHomeDir = openJMLDir.dir("jdk")
@@ -20,6 +20,8 @@ plugins {
2020
id("com.diffplug.spotless") version "6.19.0"
2121
}
2222

23+
// java { toolchain { languageVersion.set(JavaLanguageVersion.of(17) } }
24+
2325
group = "hu.bme.mit.ftsrg.chaincode.tpcc"
2426

2527
version = "0.1.0"
@@ -59,7 +61,22 @@ tasks.named<ShadowJar>("shadowJar") {
5961
archiveVersion.set("")
6062
}
6163

62-
tasks.named<Test>("test") { useJUnitPlatform() }
64+
tasks.register("initOpenJML") {
65+
val openJMLVersion: String by project
66+
67+
val zipFile: File = downloadDir.get().file("openjml.zip").asFile
68+
downloadOpenJML(openJMLVersion, zipFile, logger)
69+
extractOpenJML(zipFile, openJMLDir, logger)
70+
71+
// `jmlavac' is what we call `javac' that is actually
72+
// OpenJML's javac; likewise, `jmlava' is a wrapper for `java' with
73+
// OpenJML already in the classpath
74+
generateJmlavac(jmlavac.asFile, openJMLJavaHomeDir, logger)
75+
replaceJavac(openJMLJavaHomeDir, jmlavac.asFile, logger)
76+
generateJmlava(jmlava.asFile, openJMLJavaHomeDir, logger)
77+
replaceJava(openJMLJavaHomeDir, jmlava.asFile, logger)
78+
logger.lifecycle("✅ OpenJML successfully initialized in $openJMLDir")
79+
}
6380

6481
if (!noOpenJML) {
6582
tasks.named<ShadowJar>("shadowJar") { dependsOn(tasks.named("initOpenJML")) }
@@ -93,36 +110,29 @@ if (!noOpenJML) {
93110
options.forkOptions.javaHome = openJMLJavaHomeDir.asFile
94111
}
95112
}
113+
}
96114

97-
configure<SpotlessExtension> {
98-
java {
99-
importOrder()
100-
removeUnusedImports()
101-
googleJavaFormat()
102-
formatAnnotations()
103-
toggleOffOn()
104-
}
105-
kotlin {
106-
target("src/*/kotlin/**/*.kt", "buildSrc/src/*/kotlin/**/*.kt")
107-
ktfmt()
108-
}
109-
kotlinGradle { ktfmt() }
115+
tasks.test {
116+
useJUnitPlatform()
117+
testLogging {
118+
showExceptions = true
119+
events = setOf(TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED)
110120
}
121+
}
111122

112-
tasks.register("initOpenJML") {
113-
val openJMLVersion: String by project
114-
115-
val zipFile: File = downloadDir.get().file("openjml.zip").asFile
116-
downloadOpenJML(openJMLVersion, zipFile, logger)
117-
extractOpenJML(zipFile, openJMLDir, logger)
118-
119-
// `jmlavac' is what we call `javac' that is actually
120-
// OpenJML's javac; likewise, `jmlava' is a wrapper for `java' with
121-
// OpenJML already in the classpath
122-
generateJmlavac(jmlavac.asFile, openJMLJavaHomeDir, logger)
123-
replaceJavac(openJMLJavaHomeDir, jmlavac.asFile, logger)
124-
generateJmlava(jmlava.asFile, openJMLJavaHomeDir, logger)
125-
replaceJava(openJMLJavaHomeDir, jmlava.asFile, logger)
126-
logger.lifecycle("✅ OpenJML successfully initialized in $openJMLDir")
123+
spotless {
124+
java {
125+
importOrder()
126+
removeUnusedImports()
127+
googleJavaFormat()
128+
formatAnnotations()
129+
toggleOffOn()
130+
licenseHeader("/* SPDX-License-Identifier: Apache-2.0 */")
131+
}
132+
kotlin {
133+
target("src/*/kotlin/**/*.kt", "buildSrc/src/*/kotlin/**/*.kt")
134+
ktfmt()
135+
licenseHeader("/* SPDX-License-Identifier: Apache-2.0 */")
127136
}
137+
kotlinGradle { ktfmt() }
128138
}

smart-contract/hyperledger-fabric/v2/java/buildSrc/src/main/kotlin/hu/bme/mit/ftsrg/openjmlhelper/OpenJMLHelper.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* SPDX-License-Identifier: Apache-2.0 */
12
package hu.bme.mit.ftsrg.openjmlhelper
23

34
import java.io.File
Binary file not shown.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
44
networkTimeout=10000
5+
validateDistributionUrl=true
56
zipStoreBase=GRADLE_USER_HOME
67
zipStorePath=wrapper/dists

smart-contract/hyperledger-fabric/v2/java/gradlew

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ done
8383
# This is normally unused
8484
# shellcheck disable=SC2034
8585
APP_BASE_NAME=${0##*/}
86-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
87-
88-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89-
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
86+
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87+
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
9088

9189
# Use the maximum available, or set MAX_FD != -1 to use that value.
9290
MAX_FD=maximum
@@ -133,26 +131,29 @@ location of your Java installation."
133131
fi
134132
else
135133
JAVACMD=java
136-
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
134+
if ! command -v java >/dev/null 2>&1
135+
then
136+
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137137
138138
Please set the JAVA_HOME variable in your environment to match the
139139
location of your Java installation."
140+
fi
140141
fi
141142

142143
# Increase the maximum file descriptors if we can.
143144
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144145
case $MAX_FD in #(
145146
max*)
146147
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147-
# shellcheck disable=SC3045
148+
# shellcheck disable=SC2039,SC3045
148149
MAX_FD=$( ulimit -H -n ) ||
149150
warn "Could not query maximum file descriptor limit"
150151
esac
151152
case $MAX_FD in #(
152153
'' | soft) :;; #(
153154
*)
154155
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155-
# shellcheck disable=SC3045
156+
# shellcheck disable=SC2039,SC3045
156157
ulimit -n "$MAX_FD" ||
157158
warn "Could not set maximum file descriptor limit to $MAX_FD"
158159
esac
@@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
197198
done
198199
fi
199200

200-
# Collect all arguments for the java command;
201-
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
202-
# shell script including quotes and variable substitutions, so put them in
203-
# double quotes to make sure that they get re-expanded; and
204-
# * put everything else in single quotes, so that it's not re-expanded.
201+
202+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204+
205+
# Collect all arguments for the java command:
206+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207+
# and any embedded shellness will be escaped.
208+
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209+
# treated as '${Hostname}' itself on the command line.
205210

206211
set -- \
207212
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,92 @@
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-
17-
@if "%DEBUG%"=="" @echo off
18-
@rem ##########################################################################
19-
@rem
20-
@rem Gradle startup script for Windows
21-
@rem
22-
@rem ##########################################################################
23-
24-
@rem Set local scope for the variables with windows NT shell
25-
if "%OS%"=="Windows_NT" setlocal
26-
27-
set DIRNAME=%~dp0
28-
if "%DIRNAME%"=="" set DIRNAME=.
29-
@rem This is normally unused
30-
set APP_BASE_NAME=%~n0
31-
set APP_HOME=%DIRNAME%
32-
33-
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
34-
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35-
36-
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37-
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38-
39-
@rem Find java.exe
40-
if defined JAVA_HOME goto findJavaFromJavaHome
41-
42-
set JAVA_EXE=java.exe
43-
%JAVA_EXE% -version >NUL 2>&1
44-
if %ERRORLEVEL% equ 0 goto execute
45-
46-
echo.
47-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48-
echo.
49-
echo Please set the JAVA_HOME variable in your environment to match the
50-
echo location of your Java installation.
51-
52-
goto fail
53-
54-
:findJavaFromJavaHome
55-
set JAVA_HOME=%JAVA_HOME:"=%
56-
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57-
58-
if exist "%JAVA_EXE%" goto execute
59-
60-
echo.
61-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62-
echo.
63-
echo Please set the JAVA_HOME variable in your environment to match the
64-
echo location of your Java installation.
65-
66-
goto fail
67-
68-
:execute
69-
@rem Setup the command line
70-
71-
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72-
73-
74-
@rem Execute Gradle
75-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76-
77-
:end
78-
@rem End local scope for the variables with windows NT shell
79-
if %ERRORLEVEL% equ 0 goto mainEnd
80-
81-
:fail
82-
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83-
rem the _cmd.exe /c_ return code!
84-
set EXIT_CODE=%ERRORLEVEL%
85-
if %EXIT_CODE% equ 0 set EXIT_CODE=1
86-
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87-
exit /b %EXIT_CODE%
88-
89-
:mainEnd
90-
if "%OS%"=="Windows_NT" endlocal
91-
92-
:omega
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+
17+
@if "%DEBUG%"=="" @echo off
18+
@rem ##########################################################################
19+
@rem
20+
@rem Gradle startup script for Windows
21+
@rem
22+
@rem ##########################################################################
23+
24+
@rem Set local scope for the variables with windows NT shell
25+
if "%OS%"=="Windows_NT" setlocal
26+
27+
set DIRNAME=%~dp0
28+
if "%DIRNAME%"=="" set DIRNAME=.
29+
@rem This is normally unused
30+
set APP_BASE_NAME=%~n0
31+
set APP_HOME=%DIRNAME%
32+
33+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
34+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35+
36+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38+
39+
@rem Find java.exe
40+
if defined JAVA_HOME goto findJavaFromJavaHome
41+
42+
set JAVA_EXE=java.exe
43+
%JAVA_EXE% -version >NUL 2>&1
44+
if %ERRORLEVEL% equ 0 goto execute
45+
46+
echo. 1>&2
47+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
48+
echo. 1>&2
49+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
50+
echo location of your Java installation. 1>&2
51+
52+
goto fail
53+
54+
:findJavaFromJavaHome
55+
set JAVA_HOME=%JAVA_HOME:"=%
56+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57+
58+
if exist "%JAVA_EXE%" goto execute
59+
60+
echo. 1>&2
61+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
62+
echo. 1>&2
63+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
64+
echo location of your Java installation. 1>&2
65+
66+
goto fail
67+
68+
:execute
69+
@rem Setup the command line
70+
71+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72+
73+
74+
@rem Execute Gradle
75+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76+
77+
:end
78+
@rem End local scope for the variables with windows NT shell
79+
if %ERRORLEVEL% equ 0 goto mainEnd
80+
81+
:fail
82+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83+
rem the _cmd.exe /c_ return code!
84+
set EXIT_CODE=%ERRORLEVEL%
85+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
86+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87+
exit /b %EXIT_CODE%
88+
89+
:mainEnd
90+
if "%OS%"=="Windows_NT" endlocal
91+
92+
:omega

smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/MethodLogger.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* SPDX-License-Identifier: Apache-2.0 */
12
package hu.bme.mit.ftsrg.chaincode;
23

34
import hu.bme.mit.ftsrg.hypernate.entity.Entity;
@@ -28,7 +29,9 @@ public String generateParamsString(final String... params) {
2829

2930
public String generateParamsString(final int... params) {
3031
final List<String> strings = new ArrayList<>();
31-
for (final int i : params) strings.add(String.valueOf(i));
32+
for (final int i : params) {
33+
strings.add(String.valueOf(i));
34+
}
3235
return generateParamsString(strings.toArray(new String[0]));
3336
}
3437

0 commit comments

Comments
 (0)