Skip to content

Commit

Permalink
Merge pull request #54 from sashirestela/53-improve-code-quality-and-…
Browse files Browse the repository at this point in the history
…formatting

Improve code quality and formatting
  • Loading branch information
sashirestela authored Mar 19, 2024
2 parents 035db4d + 30e76fb commit cf6a6e4
Show file tree
Hide file tree
Showing 80 changed files with 1,108 additions and 426 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: "11"
distribution: "temurin"
cache: maven
- name: Check code format with Spotless
run: mvn spotless:check
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/release_maven_central.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release to Maven Central
run-name: Release run ${{ github.run_number }}
on:
workflow_dispatch:

jobs:
release:
name: Release
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: "11"
distribution: "temurin"
java-package: "jdk"
check-latest: true
server-id: "ossrh"
server-username: OSSRH_USERNAME
server-password: OSSRH_PASSWORD
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: GPG_PASSPHRASE
cache: "maven"
- name: Build & Deploy
run: mvn -U -B clean deploy -P release
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
103 changes: 103 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Contributing
Thank you very much for your interest in contributing to the improvement of this project. Please, follow the next guidelines.

## General Guidelines
1. Keep the code compatible with Java 11.
1. Follow existing code styles present in the project.
1. Avoid adding new dependencies as much as possible.
1. Ensure to add Javadoc where necessary.
1. Provide unit tests for your code.
1. Large features should be discussed with maintainers before implementation. Use the [Discussion](https://github.com/sashirestela/cleverclient/discussions) section for this.

## Code Formatting
This project is configured with [Spotless](https://github.com/diffplug/spotless/tree/main/plugin-maven) to automatically check code formatting against a [custom code format](codestyle/spotless_java_eclipseformat.xml) specification of modern Java, as well as [import order](codestyle/spotless_java.importorder).

Spotless comes with two Maven commands that you can run at any moment, preferably before committing your changes:

- `mvn spotless:check`, to verify if code is formatted correctly.
- `mvn spotless:apply`, to rewrite the source code in place.

The remote build will check the code formatting, so the build will fail if the code isn't formatted correctly.


## Configure IDE (Optional)
You could set your favorite IDE to be aligned to the custom code format. See details below.

<details>

<summary><b>IntelliJ</b></summary>

1. Import the custom code format:

- Settings > Editor > Code Style > Java > Scheme > ⚙ > Import Scheme > Eclipse XML Profile

2. Select the file on _codestyle/spotless_java_eclipseformat.xml_

3. In the _Imports_ tab for the previous scheme, change the values:
- In _General_ section, mark the option _Use single class import_
- In the field _Class count to use import with '*'_ put the value 99
- In the field _Names count to use static import with '*'_ put the value 99

4. At the bottom part in the _Imports_ section, change the import statement order as:
- **import** all other imports
- **import** javax.*
- **import** java.*
- **import static** all other imports

</details>

<details>

<summary><b>VSCode</b></summary>

1. Install the extension _Language Support for Java by Red Hat_

2. Set the custom code format:

- Settings > Workspace > Extensions > Language Support for Java(TM) by Red Hat > Formatting
- Choose the box _Java/Format/Settings:Url_ and put the value _codestyle/spotless_java_eclipseformat.xml_

3. Set the import order:

- Settings > Workspace > Extensions > Language Support for Java(TM) by Red Hat > Code Completion
- Choose the box _Java/Completion:ImportOrder_ and click the link _Edit in settings.json_
- In the editor, make sure to add the following entries:

```json
"java.completion.importOrder": [
"",
"javax",
"java",
"*"
]
```

</details>

<details>

<summary><b>Eclipse</b></summary>

1. Import the custom code format:

- Preferences > Java > Code Style > Formatter > Import...

2. Select the file on _codestyle/spotless_java_eclipseformat.xml_

3. Import the custom import statement order:

- Preferences > Java > Code Style > Organize Imports > Import...

4. Select the file on _codestyle/spotless_java.importorder_

5. In the _Organize Imports_ section, make sure the values are set as:

- Sorting order:
- \* - all unmatched type imports
- javax
- java
- \* - all unmatched static imports
- Number of imports needed for .*: 99
- Number of static imports needed for .*: 99

</details>
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@

Java library that makes it easier to use the Java's HttpClient to perform http operations, using interfaces.

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=sashirestela_cleverclient&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=sashirestela_cleverclient)
[![codecov](https://codecov.io/gh/sashirestela/cleverclient/graph/badge.svg?token=PEYAFW3EWD)](https://codecov.io/gh/sashirestela/cleverclient)
![Maven Central](https://img.shields.io/maven-central/v/io.github.sashirestela/cleverclient)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/sashirestela/cleverclient/maven.yml)

### Table of Contents
- [Description](#-description)
- [Installation](#-installation)
- [Features](#-features)
- [CleverClient Builder](#cleverclient-builder)
- [Interface Annotations](#interface-annotations)
- [Supported Response Types](#supported-response-types)
- [Interface Default Methods](#interface-default-methods)
- [Examples](#-examples)
- [Contributing](#-contributing)
- [License](#-license)

## 💡 Description

CleverClient is a Java 11+ library that makes it easy to use the standard [HttpClient](https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html) component to call http services by using annotated interfaces.
Expand Down Expand Up @@ -253,8 +266,10 @@ Some examples have been created in the folder [example](https://github.com/sashi
* For example, to run the BasicExample with all the log options:
* ```mvn exec:java -Dexec.mainClass=io.github.sashirestela.cleverclient.example.BasicExample -Dorg.slf4j.simpleLogger.defaultLogLevel=debug -Dorg.slf4j.simpleLogger.logFile=example.log```

## 📄 License
## 💼 Contributing
Please read our [Contributing](CONTRIBUTING.md) guide to learn and understand how to contribute to this project.

## 📄 License
CleverClient is licensed under the MIT License. See the
[LICENSE](https://github.com/sashirestela/cleverclient/blob/main/LICENSE) file
for more information.
6 changes: 6 additions & 0 deletions codestyle/spotless_java.importorder
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Organize Import Order
#Mon Feb 26 16:38:48 PET 2024
0=
1=javax
2=java
3=\#
Loading

0 comments on commit cf6a6e4

Please sign in to comment.