Skip to content

Commit

Permalink
Change code style to Google Java Style (#51)
Browse files Browse the repository at this point in the history
* feat: Move to Google Java Style code formatting

* feat: Added pre-commit config

* feat: Update README on pre-commit
  • Loading branch information
tomdesair authored Jul 11, 2023
1 parent ce33980 commit 758b545
Show file tree
Hide file tree
Showing 150 changed files with 11,297 additions and 10,541 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,6 @@ buildNumber.properties
# Ignore all local history of files
.history
.ionide
.vscode

# End of https://www.toptal.com/developers/gitignore/api/java,maven,intellij,visualstudiocode
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-added-large-files
- id: check-json
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/dustinsand/pre-commit-jvm
rev: v0.8.0
hooks:
- id: google-java-formatter-jdk11
args: [--replace, --set-exit-if-changed]
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ language: java
sudo: false # faster builds

jdk:
# Latest
- openjdk16
# LTS versions
- openjdk11
- openjdk8
- openjdk11
- openjdk17

addons:
sonarcloud:
organization: "tomdesair-github"

script:
- mvn clean install -P checkstyle
- mvn clean install -P codestyle
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# tus-java-server
This library can be used to enable resumable (and potentially asynchronous) file uploads in any Java web application. This allows the users of your application to upload large files over slow and unreliable internet connections. The ability to pause or resume a file upload (after a connection loss or reset) is achieved by implementing the open file upload protocol tus (https://tus.io/). This library implements the server-side of the tus v1.0.0 protocol with [all optional extensions](#tus-protocol-extensions).

The Javadoc of this library can be found at https://tus.desair.me/. The following Java versions are supported: 8,
9, 10, 11 and 17.
The Javadoc of this library can be found at https://tus.desair.me/. The following Java LTS versions are supported: 8, 11 and 17.

## Quick Start and Examples
The tus-java-server library only depends on Jakarta Servlet API 6.0 and some Apache Commons utility libraries. This
Expand Down Expand Up @@ -79,4 +78,24 @@ This tus protocol implementation has been [tested](https://github.com/tomdesair/
This artifact is versioned as `A.B.C-X.Y` where `A.B.C` is the version of the implemented tus protocol (currently 1.0.0) and `X.Y` is the version of this library.

## Contributing
This library comes without any warranty and is released under a [MIT license](https://github.com/tomdesair/tus-java-server/blob/master/LICENSE). If you encounter any bugs or if you have an idea for a useful improvement you are welcome to [open a new issue](https://github.com/tomdesair/tus-java-server/issues) or to [create a pull request](https://github.com/tomdesair/tus-java-server/pulls) with the proposed implementation. Please note that any contributed code needs to be accompanied by automated unit and/or integration tests and comply with the [defined code-style](https://github.com/tomdesair/tus-java-server/blob/master/checkstyle.xml).
This library comes without any warranty and is released under a [MIT license](https://github.com/tomdesair/tus-java-server/blob/master/LICENSE). If you encounter any bugs or if you have an idea for a useful improvement you are welcome to [open a new issue](https://github.com/tomdesair/tus-java-server/issues) or to [create a pull request](https://github.com/tomdesair/tus-java-server/pulls) with the proposed implementation. Please note that any contributed code needs to be accompanied by automated unit and/or integration tests and comply with the [defined code-style](#code-style).

### Code Style
All pull requests should have the correct formatting according to [Google Java Style](https://github.com/google/google-java-format) code formatting. To verify if the code style is correct run:

```
mvn -P codestyle com.spotify.fmt:fmt-maven-plugin:check
```

To reformat your code run:

```
mvn -P codestyle com.spotify.fmt:fmt-maven-plugin:format
```

See the [Google Java Style Github page](https://github.com/google/google-java-format) on recommendations on how to configure this in your IDE. Or if you have Python 3, you can also use [pre-commit](https://pre-commit.com) to make your live easier:

```
pip install pre-commit
pre-commit install
```
432 changes: 289 additions & 143 deletions checkstyle.xml

Large diffs are not rendered by default.

45 changes: 19 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>me.desair.tus</groupId>
Expand Down Expand Up @@ -274,7 +275,8 @@
<goal>sonar</goal>
</goals>
<configuration>
<sonar.jacoco.reportPaths>${project.build.directory}/coverage-reports/jacoco-it.exec,${project.build.directory}/coverage-reports/jacoco-ut.exec</sonar.jacoco.reportPaths>
<sonar.jacoco.reportPaths>
${project.build.directory}/coverage-reports/jacoco-it.exec,${project.build.directory}/coverage-reports/jacoco-ut.exec</sonar.jacoco.reportPaths>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -313,8 +315,10 @@
<configuration>
<failOnServiceError>false</failOnServiceError>
<jacocoReports>
<jacocoReport>${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml</jacocoReport>
<jacocoReport>${project.reporting.outputDirectory}/jacoco-it/jacoco.xml</jacocoReport>
<jacocoReport>
${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml</jacocoReport>
<jacocoReport>
${project.reporting.outputDirectory}/jacoco-it/jacoco.xml</jacocoReport>
</jacocoReports>
</configuration>
</execution>
Expand All @@ -325,38 +329,27 @@
</profile>

<profile>
<id>checkstyle</id>
<id>codestyle</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.20</version>
<configuration>
<style>google</style>
</configuration>
<executions>
<execution>
<id>verify-style</id>
<!-- Bind to verify so it runs after package & unit tests, but before install -->
<!-- Bind to verify so it runs after package & unit tests, but
before install -->
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<configLocation>${project.basedir}/checkstyle.xml</configLocation>
<encoding>${project.build.sourceEncoding}</encoding>
<logViolationsToConsole>true</logViolationsToConsole>
<failOnViolation>true</failOnViolation>
<!-- Enable checks on all test source files -->
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.44</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Expand Down Expand Up @@ -466,4 +459,4 @@
<url>https://github.com/tomdesair/tus-java-server/tree/master</url>
</scm>

</project>
</project>
203 changes: 103 additions & 100 deletions src/main/java/me/desair/tus/server/HttpHeader.java
Original file line number Diff line number Diff line change
@@ -1,104 +1,107 @@
package me.desair.tus.server;

/**
* Class that will hold constants for all HTTP headers relevant to the tus v1.0.0 protocol
*/
/** Class that will hold constants for all HTTP headers relevant to the tus v1.0.0 protocol */
public class HttpHeader {
/**
* The X-HTTP-Method-Override request header MUST be a string which MUST be interpreted as the request’s method
* by the Server, if the header is presented. The actual method of the request MUST be ignored.
* The Client SHOULD use this header if its environment does not support the PATCH or DELETE methods.
*/
public static final String METHOD_OVERRIDE = "X-HTTP-Method-Override";

public static final String CACHE_CONTROL = "Cache-Control";
public static final String CONTENT_TYPE = "Content-Type";
public static final String CONTENT_LENGTH = "Content-Length";
public static final String CONTENT_DISPOSITION = "Content-Disposition";
public static final String LOCATION = "Location";

/**
* The Transfer-Encoding header specifies the form of encoding used to safely transfer the entity to the user.
*/
public static final String TRANSFER_ENCODING = "Transfer-Encoding";

/**
* The Upload-Offset request and response header indicates a byte offset within a resource.
* The value MUST be a non-negative integer.
*/
public static final String UPLOAD_OFFSET = "Upload-Offset";
public static final String UPLOAD_METADATA = "Upload-Metadata";

/**
* The Upload-Checksum request header contains information about the checksum of the current body payload.
* The header MUST consist of the name of the used checksum algorithm and the Base64 encoded checksum
* separated by a space.
*/
public static final String UPLOAD_CHECKSUM = "Upload-Checksum";

/**
* The Upload-Length request and response header indicates the size of the entire upload in bytes.
* The value MUST be a non-negative integer.
*/
public static final String UPLOAD_LENGTH = "Upload-Length";

/**
* The Upload-Expires response header indicates the time after which the unfinished upload expires.
* The value of the Upload-Expires header MUST be in RFC 7231 (https://tools.ietf.org/html/rfc7231#section-7.1.1.1)
* datetime format.
*/
public static final String UPLOAD_EXPIRES = "Upload-Expires";

/**
* The Upload-Defer-Length request and response header indicates that the size of the upload is not known
* currently and will be transferred later. Its value MUST be 1. If the length of an upload is not deferred,
* this header MUST be omitted.
*/
public static final String UPLOAD_DEFER_LENGTH = "Upload-Defer-Length";

/**
* The Upload-Concat request and response header MUST be set in both partial and upload creation requests.
* It indicates whether the upload is either a partial or upload.
*/
public static final String UPLOAD_CONCAT = "Upload-Concat";

/**
* The Tus-Version response header MUST be a comma-separated list of protocol versions supported by the Server.
* The list MUST be sorted by Server’s preference where the first one is the most preferred one.
*/
public static final String TUS_VERSION = "Tus-Version";

/**
* The Tus-Resumable header MUST be included in every request and response except for OPTIONS requests.
* The value MUST be the version of the protocol used by the Client or the Server.
*/
public static final String TUS_RESUMABLE = "Tus-Resumable";

/**
* The Tus-Extension response header MUST be a comma-separated list of the extensions supported by the Server.
* If no extensions are supported, the Tus-Extension header MUST be omitted.
*/
public static final String TUS_EXTENSION = "Tus-Extension";

/**
* The Tus-Max-Size response header MUST be a non-negative integer indicating the maximum allowed size of an
* entire upload in bytes. The Server SHOULD set this header if there is a known hard limit.
*/
public static final String TUS_MAX_SIZE = "Tus-Max-Size";

/**
* The Tus-Checksum-Algorithm response header MUST be a comma-separated list of the checksum algorithms supported
* by the server.
*/
public static final String TUS_CHECKSUM_ALGORITHM = "Tus-Checksum-Algorithm";

/**
* The X-Forwarded-For (XFF) HTTP header field is a common method for identifying the originating IP address of a
* client connecting to a web server through an HTTP proxy or load balancer.
*/
public static final String X_FORWARDED_FOR = "X-Forwarded-For";

private HttpHeader() {
//This is an utility class to hold constants
}
/**
* The X-HTTP-Method-Override request header MUST be a string which MUST be interpreted as the
* request’s method by the Server, if the header is presented. The actual method of the request
* MUST be ignored. The Client SHOULD use this header if its environment does not support the
* PATCH or DELETE methods.
*/
public static final String METHOD_OVERRIDE = "X-HTTP-Method-Override";

public static final String CACHE_CONTROL = "Cache-Control";
public static final String CONTENT_TYPE = "Content-Type";
public static final String CONTENT_LENGTH = "Content-Length";
public static final String CONTENT_DISPOSITION = "Content-Disposition";
public static final String LOCATION = "Location";

/**
* The Transfer-Encoding header specifies the form of encoding used to safely transfer the entity
* to the user.
*/
public static final String TRANSFER_ENCODING = "Transfer-Encoding";

/**
* The Upload-Offset request and response header indicates a byte offset within a resource. The
* value MUST be a non-negative integer.
*/
public static final String UPLOAD_OFFSET = "Upload-Offset";

public static final String UPLOAD_METADATA = "Upload-Metadata";

/**
* The Upload-Checksum request header contains information about the checksum of the current body
* payload. The header MUST consist of the name of the used checksum algorithm and the Base64
* encoded checksum separated by a space.
*/
public static final String UPLOAD_CHECKSUM = "Upload-Checksum";

/**
* The Upload-Length request and response header indicates the size of the entire upload in bytes.
* The value MUST be a non-negative integer.
*/
public static final String UPLOAD_LENGTH = "Upload-Length";

/**
* The Upload-Expires response header indicates the time after which the unfinished upload
* expires. The value of the Upload-Expires header MUST be in RFC 7231
* (https://tools.ietf.org/html/rfc7231#section-7.1.1.1) datetime format.
*/
public static final String UPLOAD_EXPIRES = "Upload-Expires";

/**
* The Upload-Defer-Length request and response header indicates that the size of the upload is
* not known currently and will be transferred later. Its value MUST be 1. If the length of an
* upload is not deferred, this header MUST be omitted.
*/
public static final String UPLOAD_DEFER_LENGTH = "Upload-Defer-Length";

/**
* The Upload-Concat request and response header MUST be set in both partial and upload creation
* requests. It indicates whether the upload is either a partial or upload.
*/
public static final String UPLOAD_CONCAT = "Upload-Concat";

/**
* The Tus-Version response header MUST be a comma-separated list of protocol versions supported
* by the Server. The list MUST be sorted by Server’s preference where the first one is the most
* preferred one.
*/
public static final String TUS_VERSION = "Tus-Version";

/**
* The Tus-Resumable header MUST be included in every request and response except for OPTIONS
* requests. The value MUST be the version of the protocol used by the Client or the Server.
*/
public static final String TUS_RESUMABLE = "Tus-Resumable";

/**
* The Tus-Extension response header MUST be a comma-separated list of the extensions supported by
* the Server. If no extensions are supported, the Tus-Extension header MUST be omitted.
*/
public static final String TUS_EXTENSION = "Tus-Extension";

/**
* The Tus-Max-Size response header MUST be a non-negative integer indicating the maximum allowed
* size of an entire upload in bytes. The Server SHOULD set this header if there is a known hard
* limit.
*/
public static final String TUS_MAX_SIZE = "Tus-Max-Size";

/**
* The Tus-Checksum-Algorithm response header MUST be a comma-separated list of the checksum
* algorithms supported by the server.
*/
public static final String TUS_CHECKSUM_ALGORITHM = "Tus-Checksum-Algorithm";

/**
* The X-Forwarded-For (XFF) HTTP header field is a common method for identifying the originating
* IP address of a client connecting to a web server through an HTTP proxy or load balancer.
*/
public static final String X_FORWARDED_FOR = "X-Forwarded-For";

private HttpHeader() {
// This is an utility class to hold constants
}
}
Loading

0 comments on commit 758b545

Please sign in to comment.