Skip to content

Commit

Permalink
Merge pull request #23 from ftsrg/fix-22-aklenikreview
Browse files Browse the repository at this point in the history
Partially resolves #22
  • Loading branch information
bzp99 authored May 14, 2024
2 parents 0ab918e + 410dd53 commit c5d9dfa
Show file tree
Hide file tree
Showing 38 changed files with 763 additions and 577 deletions.
5 changes: 4 additions & 1 deletion smart-contract/hyperledger-fabric/v2/java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/
**/.idea/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/
Expand Down
70 changes: 40 additions & 30 deletions smart-contract/hyperledger-fabric/v2/java/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Originally based on https://github.com/mingyang91/openjml-template */

import com.diffplug.gradle.spotless.SpotlessExtension
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import hu.bme.mit.ftsrg.openjmlhelper.*
import org.gradle.api.tasks.testing.logging.TestLogEvent

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

// java { toolchain { languageVersion.set(JavaLanguageVersion.of(17) } }

group = "hu.bme.mit.ftsrg.chaincode.tpcc"

version = "0.1.0"
Expand Down Expand Up @@ -59,7 +61,22 @@ tasks.named<ShadowJar>("shadowJar") {
archiveVersion.set("")
}

tasks.named<Test>("test") { useJUnitPlatform() }
tasks.register("initOpenJML") {
val openJMLVersion: String by project

val zipFile: File = downloadDir.get().file("openjml.zip").asFile
downloadOpenJML(openJMLVersion, zipFile, logger)
extractOpenJML(zipFile, openJMLDir, logger)

// `jmlavac' is what we call `javac' that is actually
// OpenJML's javac; likewise, `jmlava' is a wrapper for `java' with
// OpenJML already in the classpath
generateJmlavac(jmlavac.asFile, openJMLJavaHomeDir, logger)
replaceJavac(openJMLJavaHomeDir, jmlavac.asFile, logger)
generateJmlava(jmlava.asFile, openJMLJavaHomeDir, logger)
replaceJava(openJMLJavaHomeDir, jmlava.asFile, logger)
logger.lifecycle("✅ OpenJML successfully initialized in $openJMLDir")
}

if (!noOpenJML) {
tasks.named<ShadowJar>("shadowJar") { dependsOn(tasks.named("initOpenJML")) }
Expand Down Expand Up @@ -93,36 +110,29 @@ if (!noOpenJML) {
options.forkOptions.javaHome = openJMLJavaHomeDir.asFile
}
}
}

configure<SpotlessExtension> {
java {
importOrder()
removeUnusedImports()
googleJavaFormat()
formatAnnotations()
toggleOffOn()
}
kotlin {
target("src/*/kotlin/**/*.kt", "buildSrc/src/*/kotlin/**/*.kt")
ktfmt()
}
kotlinGradle { ktfmt() }
tasks.test {
useJUnitPlatform()
testLogging {
showExceptions = true
events = setOf(TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED)
}
}

tasks.register("initOpenJML") {
val openJMLVersion: String by project

val zipFile: File = downloadDir.get().file("openjml.zip").asFile
downloadOpenJML(openJMLVersion, zipFile, logger)
extractOpenJML(zipFile, openJMLDir, logger)

// `jmlavac' is what we call `javac' that is actually
// OpenJML's javac; likewise, `jmlava' is a wrapper for `java' with
// OpenJML already in the classpath
generateJmlavac(jmlavac.asFile, openJMLJavaHomeDir, logger)
replaceJavac(openJMLJavaHomeDir, jmlavac.asFile, logger)
generateJmlava(jmlava.asFile, openJMLJavaHomeDir, logger)
replaceJava(openJMLJavaHomeDir, jmlava.asFile, logger)
logger.lifecycle("✅ OpenJML successfully initialized in $openJMLDir")
spotless {
java {
importOrder()
removeUnusedImports()
googleJavaFormat()
formatAnnotations()
toggleOffOn()
licenseHeader("/* SPDX-License-Identifier: Apache-2.0 */")
}
kotlin {
target("src/*/kotlin/**/*.kt", "buildSrc/src/*/kotlin/**/*.kt")
ktfmt()
licenseHeader("/* SPDX-License-Identifier: Apache-2.0 */")
}
kotlinGradle { ktfmt() }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* SPDX-License-Identifier: Apache-2.0 */
package hu.bme.mit.ftsrg.openjmlhelper

import java.io.File
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
29 changes: 17 additions & 12 deletions smart-contract/hyperledger-fabric/v2/java/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,26 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

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

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
184 changes: 92 additions & 92 deletions smart-contract/hyperledger-fabric/v2/java/gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
@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
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

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

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
@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
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

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

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* SPDX-License-Identifier: Apache-2.0 */
package hu.bme.mit.ftsrg.chaincode;

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

public String generateParamsString(final int... params) {
final List<String> strings = new ArrayList<>();
for (final int i : params) strings.add(String.valueOf(i));
for (final int i : params) {
strings.add(String.valueOf(i));
}
return generateParamsString(strings.toArray(new String[0]));
}

Expand Down
Loading

0 comments on commit c5d9dfa

Please sign in to comment.