Skip to content

Commit

Permalink
Replace checkstyle with PMD
Browse files Browse the repository at this point in the history
Update Java language version to 11, which has been the target runtime
and documented as the required version since v2.1.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
  • Loading branch information
bestbeforetoday committed Nov 19, 2024
1 parent d5aa6c5 commit d0447b7
Show file tree
Hide file tree
Showing 94 changed files with 1,164 additions and 1,274 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ subprojects {
version = rootProject.version

java {
sourceCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

compileJava {
if (javaCompiler.get().metadata.languageVersion.canCompileOrRun(10)) {
options.release = 8
options.release = 11
}
}

Expand Down
108 changes: 0 additions & 108 deletions ci/checkstyle/checkstyle.xml

This file was deleted.

5 changes: 0 additions & 5 deletions ci/checkstyle/java-copyright-header.txt

This file was deleted.

4 changes: 2 additions & 2 deletions fabric-chaincode-docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ RUN gradle \
fabric-chaincode-shim:publishToMavenLocal \
-x javadoc \
-x test \
-x checkstyleMain \
-x checkstyleTest
-x pmdMain \
-x pmdTest

WORKDIR /root/chaincode-java
# Run the Gradle and Maven commands to generate the wrapper variants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ group 'org.hyperledger.fabric-chaincode-java'
version '1.0-SNAPSHOT'

java {
sourceCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

compileJava {
if (javaCompiler.get().metadata.languageVersion.canCompileOrRun(10)) {
options.release = 11
}
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<properties>

<!-- Generic properties -->
<java.version>8</java.version>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ group 'org.hyperledger.fabric-chaincode-java'
version '1.0-SNAPSHOT'

java {
sourceCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

compileJava {
if (javaCompiler.get().metadata.languageVersion.canCompileOrRun(10)) {
options.release = 8
options.release = 11
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ group 'org.hyperledger.fabric-chaincode-java'
version '1.0-SNAPSHOT'

java {
sourceCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

compileJava {
if (javaCompiler.get().metadata.languageVersion.canCompileOrRun(10)) {
options.release = 8
options.release = 11
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void setUp() throws Exception {
}

@Test
public void TestInstall() {
public void testInstall() {

InvokeHelper helper = InvokeHelper.newHelper("baregradlecc", "sachannel");
String text = helper.invoke("org1", "whoami");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void setUp() throws Exception {
}

@Test
public void TestLedgers() {
public void testLedgers() {
InvokeHelper helper = InvokeHelper.newHelper("ledgercc", "sachannel");

String text = helper.invoke("org1", "accessLedgers");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void setUp() throws Exception {
}

@Test
public void TestLedger() {
public void testLedger() {

InvokeHelper helper = InvokeHelper.newHelper("shimcc", "sachannel");
String text = helper.invoke("org1", "putBulkStates");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void setUp() throws Exception {
}

@Test
public void RunSBE_pub_setget() {
public void runSBE_pub_setget() {
final String mode = "pub";

final InvokeHelper helper = InvokeHelper.newHelper("shimcc", "sachannel");
Expand Down Expand Up @@ -85,7 +85,7 @@ public void RunSBE_pub_setget() {
}

@Test
public void RunSBE_priv() {
public void runSBE_priv() {
final String mode = "priv";

final InvokeHelper helper = InvokeHelper.newHelper("shimcc", "sachannel");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Semaphore;
import org.hyperleder.fabric.shim.integration.util.Bash.BashBuilder;

public final class FabricState {

private static FabricState state;

private static final Map<String, Boolean> channelStarted = new HashMap<>();

// sempaphore to protect access
private static final Semaphore flag = new Semaphore(1);

public static FabricState getState() {
public static synchronized FabricState getState() {
if (state == null) {
state = new FabricState();
}
Expand Down
18 changes: 6 additions & 12 deletions fabric-chaincode-shim/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ plugins {
id 'maven-publish'
id 'jacoco'
id 'signing'
id 'checkstyle'
id 'pmd'
}

checkstyle {
toolVersion '10.18.1'
configFile file("../ci/checkstyle/checkstyle.xml")
configProperties = [root_dir: file("..") ]
}
checkstyleMain {
source ='src/main/java'
}
checkstyleMain.exclude("**/ChaincodeServerProperties.**")
checkstyleTest {
source ='src/test/java'
pmd {
toolVersion = '7.7.0'
ruleSetFiles = files('../pmd-ruleset.xml')
ruleSets = [] // explicitly set to empty to avoid using the default configuration
ignoreFailures = false
}

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected Logger(final String name) {
super(name, null);

// ensure that the parent logger is set
this.setParent(java.util.logging.Logger.getLogger("org.hyperledger.fabric"));
super.setParent(java.util.logging.Logger.getLogger("org.hyperledger.fabric"));
}

/**
Expand All @@ -45,9 +45,9 @@ public void debug(final String msg) {
*/
public static Logger getLogger(final Class<?> class1) {
// important to add the logger to the log manager
final Logger l = Logger.getLogger(class1.getName());
LogManager.getLogManager().addLogger(l);
return l;
final Logger result = Logger.getLogger(class1.getName());
LogManager.getLogManager().addLogger(result);
return result;
}

/** @param message */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.LogManager;

Expand Down Expand Up @@ -50,7 +51,7 @@ public static String formatError(final Throwable throwable) {
final Throwable cause = throwable.getCause();
if (cause != null) {
buffer.append(".. caused by ..").append(System.lineSeparator());
buffer.append(Logging.formatError(cause));
buffer.append(formatError(cause));
}

return buffer.toString();
Expand All @@ -67,11 +68,11 @@ public static void setLogLevel(final String newLevel) {
final LogManager logManager = LogManager.getLogManager();
// slightly cumbersome approach - but the loggers don't have a 'get children'
// so find those that have the correct stem.
final ArrayList<String> allLoggers = Collections.list(logManager.getLoggerNames());
final List<String> allLoggers = Collections.list(logManager.getLoggerNames());
allLoggers.add("org.hyperledger");
allLoggers.stream()
.filter(name -> name.startsWith("org.hyperledger"))
.map(name -> logManager.getLogger(name))
.map(logManager::getLogger)
.forEach(logger -> {
if (logger != null) {
logger.setLevel(l);
Expand All @@ -81,7 +82,7 @@ public static void setLogLevel(final String newLevel) {

private static Level mapLevel(final String level) {
if (level != null) {
switch (level.toUpperCase().trim()) {
switch (level.toUpperCase(Locale.getDefault()).trim()) {
case "ERROR":
case "CRITICAL":
return Level.SEVERE;
Expand Down
Loading

0 comments on commit d0447b7

Please sign in to comment.