Skip to content

Commit

Permalink
feat(jdk): compatible with 8 and 17
Browse files Browse the repository at this point in the history
  • Loading branch information
halibobo1205 committed Sep 9, 2024
1 parent 7ce4fd9 commit ed431bb
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 203 deletions.
17 changes: 0 additions & 17 deletions actuator/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
plugins {
id("org.kordamp.gradle.jdeps")
id("org.kordamp.gradle.jdeprscan")
}
description = "actuator – a series of transactions for blockchain."

dependencies {
Expand All @@ -10,19 +6,6 @@ dependencies {
api project(":crypto")
}

jdepsReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
consoleOutput = false
}

jdeprscanReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
forRemoval = true
release = JavaVersion.VERSION_17.getMajorVersion()
}

test {

testLogging {
Expand Down
19 changes: 3 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
plugins {
id("org.kordamp.gradle.jdeps") version "0.20.0" apply false
id("org.kordamp.gradle.jdeprscan") version "0.11.0" apply false
}

allprojects {
version = "1.0.0"
apply plugin: "java-library"
}

if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
throw new GradleException("Java 17 or later is required to build Java-tron.\n" +
" Detected version ${JavaVersion.current()}")
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
languageVersion = JavaLanguageVersion.of(8)
vendor = JvmVendorSpec.ADOPTIUM
}
}
Expand All @@ -24,9 +14,6 @@ subprojects {
apply plugin: "jacoco"
apply plugin: "maven-publish"

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

jacoco {
Expand Down Expand Up @@ -56,7 +43,7 @@ subprojects {
dependencies {
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
implementation group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.25'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.6'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.9'
implementation group: 'com.google.guava', name: 'guava', version: '33.2.1-jre'
implementation "com.google.code.findbugs:jsr305:3.0.2"
implementation group: 'org.springframework', name: 'spring-context', version: '5.3.37'
Expand Down Expand Up @@ -92,7 +79,7 @@ subprojects {


testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation "org.mockito:mockito-core:5.8.0"
testImplementation "org.mockito:mockito-core:2.13.0"
}

tasks.register('sourcesJar', Jar) {
Expand Down
16 changes: 0 additions & 16 deletions chainbase/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
plugins {
id("org.kordamp.gradle.jdeps")
id("org.kordamp.gradle.jdeprscan")
}
description = "chainbase – a decentralized database for blockchain."

// Dependency versions
Expand All @@ -18,18 +14,6 @@ dependencies {
api 'org.reflections:reflections:0.9.11'
}

jdepsReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
consoleOutput = false
}

jdeprscanReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
forRemoval = true
release = JavaVersion.VERSION_17.getMajorVersion()
}

test {

Expand Down
3 changes: 2 additions & 1 deletion chainbase/src/main/java/org/tron/common/math/Maths.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ private enum Op {
public static double pow(double a, double b) {
double result = Math.pow(a, b);
double strictResult = StrictMath.pow(a, b);
boolean isJre8 = System.getProperty("java.specification.version").startsWith("1.8");
final boolean isNoStrict = Double.compare(result, strictResult) != 0;
Optional<Long> header = GlobalContext.getHeader();
header.ifPresent(h -> {
Expand All @@ -416,7 +417,7 @@ public static double pow(double a, double b) {
mathStore.ifPresent(s -> s.put(key, doubleToBytes(result)));
strictMathStore.ifPresent(s -> s.put(key, doubleToBytes(strictResult)));
});
return powData.getOrDefault(new PowData(a, b), strictResult);
return powData.getOrDefault(new PowData(a, b), isJre8 ? result : strictResult);
}

static String doubleToHex(double input) {
Expand Down
17 changes: 0 additions & 17 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
plugins {
id 'java'
id("org.kordamp.gradle.jdeps")
id("org.kordamp.gradle.jdeprscan")
}

version '1.0.0'

sourceCompatibility = 1.8

// Dependency versions
// ---------------------------------------
def leveldbVersion = "1.8"
Expand Down Expand Up @@ -66,19 +62,6 @@ dependencies {
api project(":protocol")
}

jdepsReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
consoleOutput = false
}

jdeprscanReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
forRemoval = true
release = JavaVersion.VERSION_17.getMajorVersion()
}

jacocoTestReport {
reports {
xml.enabled = true
Expand Down
9 changes: 5 additions & 4 deletions config/checkstyle/checkStyleAll.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="LineLength">
<property name="max" value="100"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>

<module name="TreeWalker">
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
Expand All @@ -42,6 +39,10 @@
<property name="allowByTailComment" value="true"/>
<property name="allowNonPrintableEscapes" value="true"/>
</module>
<module name="LineLength">
<property name="max" value="100"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<module name="AvoidStarImport"/>
<module name="OneTopLevelClass"/>
<module name="NoLineWrap"/>
Expand Down
17 changes: 0 additions & 17 deletions consensus/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
plugins {
id("org.kordamp.gradle.jdeps")
id("org.kordamp.gradle.jdeprscan")
}
description = "consensus – a distributed consensus arithmetic for blockchain."

dependencies {
Expand Down Expand Up @@ -34,19 +30,6 @@ test {
}
}

jdepsReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
consoleOutput = false
}

jdeprscanReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
forRemoval = true
release = JavaVersion.VERSION_17.getMajorVersion()
}

jacocoTestReport {
reports {
xml.enabled = true
Expand Down
17 changes: 0 additions & 17 deletions crypto/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
plugins {
id 'java'
id("org.kordamp.gradle.jdeps")
id("org.kordamp.gradle.jdeprscan")
}

version '1.0.0'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}
Expand All @@ -16,19 +12,6 @@ dependencies {
api project(":common")
}

jdepsReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
consoleOutput = false
}

jdeprscanReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
forRemoval = true
release = JavaVersion.VERSION_17.getMajorVersion()
}

jacocoTestReport {
reports {
xml.enabled = true
Expand Down
17 changes: 0 additions & 17 deletions example/actuator-example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
plugins {
id("org.kordamp.gradle.jdeps")
id("org.kordamp.gradle.jdeprscan")
}
description = "actuator-example – a example of actuator."

dependencies {
api project(":actuator")
}

jdepsReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
consoleOutput = false
}

jdeprscanReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
forRemoval = true
release = JavaVersion.VERSION_17.getMajorVersion()
}

19 changes: 3 additions & 16 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ plugins {
id "org.gradle.test-retry" version "1.5.9"
id "org.sonarqube" version "2.6"
id "com.gorylenko.gradle-git-properties" version "2.4.1"
id("org.kordamp.gradle.jdeps")
id("org.kordamp.gradle.jdeprscan")
}

gitProperties.failOnNoGitDirectory = false;
Expand All @@ -15,21 +13,10 @@ apply plugin: 'com.github.johnrengelman.shadow'
mainClassName = 'org.tron.program.FullNode'

def versions = [
checkstyle: '10.14.2', // see https://github.com/checkstyle/checkstyle/issues/14123
checkstyle: '8.7',
]

jdepsReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
consoleOutput = false
}

jdeprscanReport {
sourceSets = ['main', 'test']
configurations = ['testRuntimeClasspath']
forRemoval = true
release = JavaVersion.VERSION_17.getMajorVersion()
}

configurations {
checkstyleConfig
Expand Down Expand Up @@ -89,7 +76,7 @@ check.dependsOn 'lint'

checkstyle {
toolVersion = "${versions.checkstyle}"
configFile = file("config/checkstyle/checkStyleAll.xml")
configFile = file("${project.rootDir}/config/checkstyle/checkStyleAll.xml")
}


Expand Down Expand Up @@ -188,7 +175,7 @@ def createScript(project, mainClass, name) {
}
}

applicationDistribution.from("../gradle/java-tron.vmoptions") {
applicationDistribution.from("${project.rootDir}/gradle/java-tron.vmoptions") {
into "bin"
}
//distZip {
Expand Down
22 changes: 11 additions & 11 deletions framework/src/test/java/org/tron/keystroe/CredentialsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ public class CredentialsTest {

@Test
public void test_equality() {
var aObject = new Object();
var si = Mockito.mock(SignInterface.class);
var si2 = Mockito.mock(SignInterface.class);
var si3 = Mockito.mock(SignInterface.class);
var address = "TQhZ7W1RudxFdzJMw6FvMnujPxrS6sFfmj".getBytes();
var address2 = "TNCmcTdyrYKMtmE1KU2itzeCX76jGm5Not".getBytes();
Object aObject = new Object();
SignInterface si = Mockito.mock(SignInterface.class);
SignInterface si2 = Mockito.mock(SignInterface.class);
SignInterface si3 = Mockito.mock(SignInterface.class);
byte[] address = "TQhZ7W1RudxFdzJMw6FvMnujPxrS6sFfmj".getBytes();
byte[] address2 = "TNCmcTdyrYKMtmE1KU2itzeCX76jGm5Not".getBytes();
Mockito.when(si.getAddress()).thenReturn(address);
Mockito.when(si2.getAddress()).thenReturn(address);
Mockito.when(si3.getAddress()).thenReturn(address2);
var aCredential = Credentials.create(si);
Credentials aCredential = Credentials.create(si);
Assert.assertFalse(aObject.equals(aCredential));
Assert.assertFalse(aCredential.equals(aObject));
Assert.assertFalse(aCredential.equals(null));
var anotherCredential = Credentials.create(si);
Assert.assertTrue(aCredential.equals(anotherCredential));
var aCredential2 = Credentials.create(si2);
Credentials anotherCredential = Credentials.create(si);
Assert.assertTrue(aCredential.equals(anotherCredential));
var aCredential3 = Credentials.create(si3);
Credentials aCredential2 = Credentials.create(si2);
Assert.assertTrue(aCredential.equals(anotherCredential));
Credentials aCredential3 = Credentials.create(si3);
Assert.assertFalse(aCredential.equals(aCredential3));
}
}
14 changes: 6 additions & 8 deletions gradle/java-tron.vmoptions
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
-Xmx9G
-XX:+UseZGC
-Xlog:gc*:file=gc-%t.log:time,uptime,level,tags:filecount=50,filesize=100M
-XX:+UseConcMarkSweepGC
-XX:+PrintGCDetails
-Xloggc:./gc.log
-XX:+PrintGCDateStamps
-XX:+CMSParallelRemarkEnabled
-XX:ReservedCodeCacheSize=256m
-XX:+UseCodeCacheFlushing
-XX:MetaspaceSize=256m
-XX:MaxMetaspaceSize=512m
-XX:MaxDirectMemorySize=1g
-XX:+HeapDumpOnOutOfMemoryError
-XX:+CMSScavengeBeforeRemark
Loading

0 comments on commit ed431bb

Please sign in to comment.