Skip to content

Commit 4895f92

Browse files
Use Spotless for code formatting (#358)
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 updates the Gradle version to 8.10.2. Signed-off-by: Mark S. Lewis <[email protected]>
1 parent 33f3ba8 commit 4895f92

File tree

207 files changed

+3119
-3631
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+3119
-3631
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- uses: actions/setup-java@v4
3434
with:
3535
distribution: 'temurin'
36-
java-version: '11'
36+
java-version: 11
3737
- uses: gradle/actions/setup-gradle@v4
3838
- name: Push to registry ${{ matrix.publish_target }}
3939
run: |
@@ -65,7 +65,7 @@ jobs:
6565
- uses: actions/setup-java@v4
6666
with:
6767
distribution: 'temurin'
68-
java-version: '11'
68+
java-version: 11
6969
- uses: gradle/actions/setup-gradle@v4
7070
- name: Build the dependencies needed for the image
7171
run: ./gradlew :fabric-chaincode-docker:copyAllDeps

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
**/bin/
88
/build/
99
build/*
10+
settings-gradle.lockfile
1011

1112
_cfg
1213
repository

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ We use our own forks and [Github Flow](https://guides.github.com/introduction/fl
2828

2929
## Coding Style
3030

31-
Please to try to be consistent with the rest of the code and conform to checkstyle rules where they are provided.
31+
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.
3232

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

build.gradle

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
plugins {
88
id "com.github.ben-manes.versions" version "0.51.0"
9+
id "com.diffplug.spotless" version "6.25.0"
910
}
1011

1112
version = '2.5.5'
1213

1314

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

2526
allprojects {
27+
apply plugin: "com.diffplug.spotless"
28+
2629
repositories {
2730
mavenCentral()
2831
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
2932
maven { url "https://www.jitpack.io" }
3033
}
34+
35+
spotless {
36+
format 'misc', {
37+
target '*.gradle', '.gitattributes', '.gitignore'
38+
trimTrailingWhitespace()
39+
indentWithSpaces()
40+
endWithNewline()
41+
}
42+
}
3143
}
3244

3345
subprojects {
3446
apply plugin: 'java'
35-
apply plugin: 'maven-publish'
47+
apply plugin: "maven-publish"
3648

3749
group = 'org.hyperledger.fabric-chaincode-java'
3850
version = rootProject.version
@@ -64,6 +76,13 @@ subprojects {
6476
useJUnitPlatform()
6577
}
6678

79+
spotless {
80+
java {
81+
removeUnusedImports()
82+
palantirJavaFormat('2.50.0').formatJavadoc(true)
83+
formatAnnotations()
84+
}
85+
}
6786
}
6887

6988
task printVersionName() {

ci/checkstyle/checkstyle.xml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,8 @@
4141
<module name="AvoidStarImport"/>
4242
<module name="IllegalImport"/>
4343
<module name="RedundantImport"/>
44-
<module name="UnusedImports">
45-
<property name="processJavadoc" value="false"/>
46-
</module>
4744
<module name="MethodLength"/>
4845
<module name="ParameterNumber"/>
49-
<module name="GenericWhitespace"/>
50-
<module name="MethodParamPad"/>
51-
<module name="NoWhitespaceAfter"/>
52-
<module name="NoWhitespaceBefore"/>
53-
<module name="OperatorWrap"/>
54-
<module name="ParenPad"/>
55-
<module name="TypecastParenPad"/>
56-
<module name="WhitespaceAfter"/>
57-
<module name="WhitespaceAround"/>
5846
<module name="ModifierOrder"/>
5947
<module name="RedundantModifier"/>
6048
<module name="AvoidNestedBlocks"/>
@@ -108,11 +96,6 @@
10896
<module name="NewlineAtEndOfFile"/>
10997
<module name="Translation"/>
11098
<module name="FileLength"/>
111-
<module name="LineLength">
112-
<property name="fileExtensions" value="java"/>
113-
<property name="ignorePattern" value="^ +\* +"/>
114-
<property name="max" value="160"/>
115-
</module>
11699
<module name="FileTabCharacter"/>
117100
<module name="RegexpSingleline">
118101
<property name="format" value="\s+$"/>

fabric-chaincode-docker/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,3 @@ task buildImage(type: DockerBuildImage) {
6767
inputDir = project.file('Dockerfile').parentFile
6868
images = ['hyperledger/fabric-javaenv', 'hyperledger/fabric-javaenv:2.5', 'hyperledger/fabric-javaenv:amd64-2.5.5', 'hyperledger/fabric-javaenv:amd64-latest']
6969
}
70-

fabric-chaincode-integration-test/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ dependencies {
88
test {
99
// Always run tests, even when nothing changed.
1010
dependsOn 'cleanTest'
11-
11+
1212
// Show test results.
1313
testLogging {
1414
events "passed", "skipped", "failed"
1515
showExceptions true
1616
showCauses true
1717
showStandardStreams true
1818
exceptionFormat "full"
19-
19+
2020
}
2121
}
2222

fabric-chaincode-integration-test/chaincodebootstrap.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ allprojects {
99
}
1010
}
1111
}
12-
}
12+
}

fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/contractinstall/ContractInstallTest.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,35 @@
55
*/
66
package org.hyperleder.fabric.shim.integration.contractinstall;
77

8-
import static org.hamcrest.core.StringContains.containsString;
98
import static org.hamcrest.MatcherAssert.assertThat;
9+
import static org.hamcrest.core.StringContains.containsString;
1010

1111
import org.hyperleder.fabric.shim.integration.util.FabricState;
1212
import org.hyperleder.fabric.shim.integration.util.InvokeHelper;
1313
import org.junit.jupiter.api.BeforeAll;
1414
import org.junit.jupiter.api.Test;
1515

16-
/**
17-
* Basic Java Chaincode Test
18-
*
19-
*/
16+
/** Basic Java Chaincode Test */
2017
public class ContractInstallTest {
2118

22-
@BeforeAll
19+
@BeforeAll
2320
public static void setUp() throws Exception {
2421
FabricState.getState().start();
25-
2622
}
2723

28-
@Test
29-
public void TestInstall(){
24+
@Test
25+
public void TestInstall() {
3026

31-
InvokeHelper helper = InvokeHelper.newHelper("baregradlecc","sachannel");
27+
InvokeHelper helper = InvokeHelper.newHelper("baregradlecc", "sachannel");
3228
String text = helper.invoke("org1", "whoami");
3329
assertThat(text, containsString("BareGradle"));
34-
35-
helper = InvokeHelper.newHelper("baremaven","sachannel");
30+
31+
helper = InvokeHelper.newHelper("baremaven", "sachannel");
3632
text = helper.invoke("org1", "whoami");
3733
assertThat(text, containsString("BareMaven"));
38-
39-
helper = InvokeHelper.newHelper("wrappermaven","sachannel");
34+
35+
helper = InvokeHelper.newHelper("wrappermaven", "sachannel");
4036
text = helper.invoke("org1", "whoami");
41-
assertThat(text, containsString("WrapperMaven"));
37+
assertThat(text, containsString("WrapperMaven"));
4238
}
43-
44-
}
39+
}

fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/ledgertests/LedgerIntegrationTest.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,29 @@
44
SPDX-License-Identifier: Apache-2.0
55
*/
66
package org.hyperleder.fabric.shim.integration.ledgertests;
7-
import static org.hamcrest.core.StringContains.containsString;
7+
88
import static org.hamcrest.MatcherAssert.assertThat;
9+
import static org.hamcrest.core.StringContains.containsString;
910

1011
import org.hyperleder.fabric.shim.integration.util.FabricState;
1112
import org.hyperleder.fabric.shim.integration.util.InvokeHelper;
1213
import org.junit.jupiter.api.BeforeAll;
1314
import org.junit.jupiter.api.Test;
1415

15-
/**
16-
* Basic Java Chaincode Test
17-
*
18-
*/
16+
/** Basic Java Chaincode Test */
1917
public class LedgerIntegrationTest {
2018

21-
@BeforeAll
19+
@BeforeAll
2220
public static void setUp() throws Exception {
2321

24-
2522
FabricState.getState().start();
2623
}
2724

28-
@Test
29-
public void TestLedgers(){
30-
InvokeHelper helper = InvokeHelper.newHelper("ledgercc","sachannel");
31-
25+
@Test
26+
public void TestLedgers() {
27+
InvokeHelper helper = InvokeHelper.newHelper("ledgercc", "sachannel");
28+
3229
String text = helper.invoke("org1", "accessLedgers");
3330
assertThat(text, containsString("success"));
34-
3531
}
36-
3732
}

0 commit comments

Comments
 (0)