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 <[email protected]>
  • Loading branch information
bestbeforetoday committed Oct 22, 2024
1 parent 33f3ba8 commit 306fbde
Show file tree
Hide file tree
Showing 210 changed files with 3,135 additions and 3,646 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"
id "com.diffplug.spotless" version "6.25.0"
}

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: "com.diffplug.spotless"

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
10 changes: 5 additions & 5 deletions fabric-chaincode-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:11-jdk as builder
FROM eclipse-temurin:17-jdk as builder
ENV DEBIAN_FRONTEND=noninteractive

# Build tools
Expand All @@ -10,10 +10,10 @@ RUN curl -s "https://get.sdkman.io" | bash

SHELL ["/bin/bash", "-c"]

RUN source /root/.sdkman/bin/sdkman-init.sh; sdk install gradle 8.6
RUN source /root/.sdkman/bin/sdkman-init.sh; sdk install maven 3.9.6
RUN source /root/.sdkman/bin/sdkman-init.sh; sdk install gradle 8.10.2
RUN source /root/.sdkman/bin/sdkman-init.sh; sdk install maven 3.9.9

FROM eclipse-temurin:11-jdk as dependencies
FROM eclipse-temurin:17-jdk as dependencies

COPY --from=builder /root/.sdkman/candidates/gradle/current /usr/bin/gradle
COPY --from=builder /root/.sdkman/candidates/maven/current /usr/bin/maven
Expand Down Expand Up @@ -53,7 +53,7 @@ RUN mvn -N io.takari:maven:wrapper

# Creating final javaenv image which will include all required
# dependencies to build and compile java chaincode
FROM eclipse-temurin:11-jdk
FROM eclipse-temurin:17-jdk

RUN apt-get update \
&& apt-get -y install zip unzip \
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"));
}

}
Loading

0 comments on commit 306fbde

Please sign in to comment.