Skip to content

Commit

Permalink
Use Spotless for code formatting
Browse files Browse the repository at this point in the history
Spotless is widely used opinionated Java code formatter. It will also
fix incorrect formatting using `./gradlew spotlessApply`, avoiding the
need for contributors to manually correct any formatting violations
flagged by Checkstyle. Formatting rules defined by Checkstyle that would
otherwise cause conflicts with the formatting applied by Spotless are
removed.

This change also:

- Fixes one deprecation warning in OpenTelementryTracesProvider.
- Updates the Gradle wrapper version to 8.10.2.
- Uses Java 17 in the build, since support for running Gradle with
  earlier Java versions is now deprecated with plans to remove support
  in Gradle v9.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
  • Loading branch information
bestbeforetoday committed Oct 22, 2024
1 parent 33f3ba8 commit 1f47b31
Show file tree
Hide file tree
Showing 210 changed files with 3,135 additions and 3,641 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
java-version: 17
- uses: gradle/actions/setup-gradle@v4
- name: Push to registry ${{ matrix.publish_target }}
run: |
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
java-version: 17
- uses: gradle/actions/setup-gradle@v4
- name: Build the dependencies needed for the image
run: ./gradlew :fabric-chaincode-docker:copyAllDeps
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
java-version: 17
- uses: gradle/actions/setup-gradle@v4
- name: Set up Go
uses: actions/setup-go@v5
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
java-version: 17
- uses: gradle/actions/setup-gradle@v4
- name: Build and Unit test
run: ./gradlew :fabric-chaincode-shim:build
Expand All @@ -36,7 +36,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
java-version: 17
- uses: gradle/actions/setup-gradle@v4
- name: Populate chaincode with latest java-version
run: |
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
java-version: 17
- uses: gradle/actions/setup-gradle@v4
- name: Build Docker image
run: ./gradlew :fabric-chaincode-docker:buildImage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
**/bin/
/build/
build/*
settings-gradle.lockfile

_cfg
repository
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ We use our own forks and [Github Flow](https://guides.github.com/introduction/fl

## Coding Style

Please to try to be consistent with the rest of the code and conform to checkstyle rules where they are provided.
Please to try to be consistent with the rest of the code and conform to checkstyle rules where they are provided. [Spotless](https://github.com/diffplug/spotless) is used to enforce code formatting. You can run `./gradlew spotlessApply` to apply the mandated code formatting to the codebase before submitting changes to avoid failing the build with formatting violations.

## Code of Conduct Guidelines <a name="conduct"></a>

Expand Down
23 changes: 21 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

plugins {
id "com.github.ben-manes.versions" version "0.51.0"
alias libs.plugins.spotless
}

version = '2.5.5'


// If the nightly property is set, then this is the scheduled main
// If the nightly property is set, then this is the scheduled main
// build - and we should publish this to artifactory
//
// Use the .dev.<number> format to match Maven convention
Expand All @@ -23,16 +24,27 @@ if (properties.containsKey('NIGHTLY')) {
}

allprojects {
apply plugin: libs.plugins.spotless.get().pluginId

repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url "https://www.jitpack.io" }
}

spotless {
format 'misc', {
target '*.gradle', '.gitattributes', '.gitignore'
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
}
}

subprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: "maven-publish"

group = 'org.hyperledger.fabric-chaincode-java'
version = rootProject.version
Expand Down Expand Up @@ -64,6 +76,13 @@ subprojects {
useJUnitPlatform()
}

spotless {
java {
removeUnusedImports()
palantirJavaFormat('2.50.0').formatJavadoc(true)
formatAnnotations()
}
}
}

task printVersionName() {
Expand Down
17 changes: 0 additions & 17 deletions ci/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,8 @@
<module name="AvoidStarImport"/>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="false"/>
</module>
<module name="MethodLength"/>
<module name="ParameterNumber"/>
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<module name="AvoidNestedBlocks"/>
Expand Down Expand Up @@ -108,11 +96,6 @@
<module name="NewlineAtEndOfFile"/>
<module name="Translation"/>
<module name="FileLength"/>
<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="ignorePattern" value="^ +\* +"/>
<property name="max" value="160"/>
</module>
<module name="FileTabCharacter"/>
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
Expand Down
1 change: 0 additions & 1 deletion fabric-chaincode-docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ task buildImage(type: DockerBuildImage) {
inputDir = project.file('Dockerfile').parentFile
images = ['hyperledger/fabric-javaenv', 'hyperledger/fabric-javaenv:2.5', 'hyperledger/fabric-javaenv:amd64-2.5.5', 'hyperledger/fabric-javaenv:amd64-latest']
}

4 changes: 2 additions & 2 deletions fabric-chaincode-integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ dependencies {
test {
// Always run tests, even when nothing changed.
dependsOn 'cleanTest'

// Show test results.
testLogging {
events "passed", "skipped", "failed"
showExceptions true
showCauses true
showStandardStreams true
exceptionFormat "full"

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ allprojects {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,35 @@
*/
package org.hyperleder.fabric.shim.integration.contractinstall;

import static org.hamcrest.core.StringContains.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringContains.containsString;

import org.hyperleder.fabric.shim.integration.util.FabricState;
import org.hyperleder.fabric.shim.integration.util.InvokeHelper;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

/**
* Basic Java Chaincode Test
*
*/
/** Basic Java Chaincode Test */
public class ContractInstallTest {

@BeforeAll
@BeforeAll
public static void setUp() throws Exception {
FabricState.getState().start();

}

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

InvokeHelper helper = InvokeHelper.newHelper("baregradlecc","sachannel");
InvokeHelper helper = InvokeHelper.newHelper("baregradlecc", "sachannel");
String text = helper.invoke("org1", "whoami");
assertThat(text, containsString("BareGradle"));
helper = InvokeHelper.newHelper("baremaven","sachannel");

helper = InvokeHelper.newHelper("baremaven", "sachannel");
text = helper.invoke("org1", "whoami");
assertThat(text, containsString("BareMaven"));
helper = InvokeHelper.newHelper("wrappermaven","sachannel");

helper = InvokeHelper.newHelper("wrappermaven", "sachannel");
text = helper.invoke("org1", "whoami");
assertThat(text, containsString("WrapperMaven"));
assertThat(text, containsString("WrapperMaven"));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,29 @@
SPDX-License-Identifier: Apache-2.0
*/
package org.hyperleder.fabric.shim.integration.ledgertests;
import static org.hamcrest.core.StringContains.containsString;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringContains.containsString;

import org.hyperleder.fabric.shim.integration.util.FabricState;
import org.hyperleder.fabric.shim.integration.util.InvokeHelper;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

/**
* Basic Java Chaincode Test
*
*/
/** Basic Java Chaincode Test */
public class LedgerIntegrationTest {

@BeforeAll
@BeforeAll
public static void setUp() throws Exception {


FabricState.getState().start();
}

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

String text = helper.invoke("org1", "accessLedgers");
assertThat(text, containsString("success"));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,39 @@
SPDX-License-Identifier: Apache-2.0
*/
package org.hyperleder.fabric.shim.integration.shimtests;
import static org.hamcrest.core.StringContains.containsString;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringContains.containsString;

import org.hyperleder.fabric.shim.integration.util.FabricState;
import org.hyperleder.fabric.shim.integration.util.InvokeHelper;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

/**
* Basic Java Chaincode Test
*
*/
/** Basic Java Chaincode Test */
public class SACCIntegrationTest {

@BeforeAll
public static void setUp() throws Exception {
FabricState.getState().start();

FabricState.getState().start();
}

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

InvokeHelper helper = InvokeHelper.newHelper("shimcc", "sachannel");
String text = helper.invoke("org1", "putBulkStates");
assertThat(text, containsString("success"));
text = helper.invoke("org1", "getByRange","key120","key170");

text = helper.invoke("org1", "getByRange", "key120", "key170");
assertThat(text, containsString("50"));

text = helper.invoke("org1", "getByRangePaged","key120","key170","10","");
text = helper.invoke("org1", "getByRangePaged", "key120", "key170", "10", "");
System.out.println(text);
assertThat(text, containsString("key130"));

text = helper.invoke("org1", "getMetricsProviderName");
System.out.println(text);
assertThat(text, containsString("org.hyperledger.fabric.metrics.impl.DefaultProvider"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/
package org.hyperleder.fabric.shim.integration.shimtests;

import static org.hamcrest.core.StringContains.containsString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.StringContains.containsString;

import org.hyperleder.fabric.shim.integration.util.FabricState;
import org.hyperleder.fabric.shim.integration.util.InvokeHelper;
Expand All @@ -19,8 +19,6 @@ public class SBECCIntegrationTest {
@BeforeAll
public static void setUp() throws Exception {
FabricState.getState().start();


}

@Test
Expand Down Expand Up @@ -61,7 +59,6 @@ public void RunSBE_pub_setget() {
assertThat(text, containsString("org2MSP"));
assertThat(text, containsString("org1MSP"));


text = helper.invoke("org1", "EndorsementCC:setval", mode, "val3");
assertThat(text, containsString("success"));

Expand All @@ -85,10 +82,9 @@ public void RunSBE_pub_setget() {
assertThat(text, containsString("success"));
text = helper.invoke("org1", "EndorsementCC:recordExists", mode);
assertThat(text, containsString("false"));

}

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

Expand Down Expand Up @@ -126,7 +122,6 @@ public void RunSBE_priv() {
text = helper.invoke("org1", "EndorsementCC:listorgs", mode);
assertThat(text, containsString("org2MSP"));
assertThat(text, containsString("org1MSP"));


text = helper.invoke("org1", "EndorsementCC:setval", mode, "val3");
assertThat(text, containsString("success"));
Expand All @@ -151,7 +146,5 @@ public void RunSBE_priv() {
assertThat(text, containsString("success"));
text = helper.invoke("org1", "EndorsementCC:recordExists", mode);
assertThat(text, containsString("false"));

}

}
Loading

0 comments on commit 1f47b31

Please sign in to comment.