Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Catch up checkstyle with JDK 17 (QubitPi#81)
Browse files Browse the repository at this point in the history
* Catch up checkstyle with JDK 17

* self-review
  • Loading branch information
QubitPi committed Apr 22, 2024
1 parent 62501ac commit 1f4497a
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 45 deletions.
17 changes: 15 additions & 2 deletions athena-core/src/main/java/com/paiondata/athena/file/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
* <p>
* A {@link File} has two parts
* <ol>
* <li> file content, and
* <li> file content wrapped inside an {@link InputStream}, and
* <li> file {@link MetaData metadata}
* </ol>
*
* Note that an instance of it is guaranteed not to {@link InputStream#close() close} the encapsulated file at any time.
*/
@Immutable
@ThreadSafe
Expand All @@ -44,7 +46,8 @@ public class File {
* Constructor.
*
* @param metaData File metadata
* @param fileContent File content
* @param fileContent File content wrapped inside an {@link InputStream}, which cannot be
* {@link InputStream#close() closed} when passed in
*
* @throws NullPointerException if {@code metaData} or {@code fileContent} is {@code null}
*/
Expand All @@ -53,11 +56,21 @@ public File(final @NotNull MetaData metaData, final @NotNull InputStream fileCon
this.fileContent = Objects.requireNonNull(fileContent);
}

/**
* Returns an immutable representation of all metadata associated with this {@code File}.
*
* @return a read-only object
*/
@NotNull
public MetaData getMetaData() {
return metaData;
}

/**
* Returns the content of the file wrapped in an {@link InputStream}.
*
* @return an unclosed {@link InputStream}
*/
@NotNull
public InputStream getFileContent() {
return fileContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,9 @@ public synchronized String apply(final File file) {
final String fileName = Objects.requireNonNull(file).getMetaData().getFileName();
final Date now = new Date();

getMessageDigest().update(fileName.getBytes(StandardCharsets.US_ASCII));
getMessageDigest().update(now.toString().getBytes(StandardCharsets.US_ASCII));
messageDigest.update(fileName.getBytes(StandardCharsets.US_ASCII));
messageDigest.update(now.toString().getBytes(StandardCharsets.US_ASCII));

return new String(Base64.getEncoder().encode(getMessageDigest().digest()));
}

public MessageDigest getMessageDigest() {
return messageDigest;
return new String(Base64.getEncoder().encode(messageDigest.digest()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,21 @@ public static MetaData of(final @NotNull Map<String, Object> fieldMap) {
return new MetaData(fieldMap.get(FILE_NAME).toString(), FileType.valueOf(fieldMap.get(FILE_TYPE).toString()));
}

/**
* Returns the name of the file associated with this metadata instance.
*
* @return the file name, including its extension
*/
@NotNull
public String getFileName() {
return fileName;
}

/**
* Returns the extension info of the file associated with this metadata instance.
*
* @return file type information
*/
@NotNull
public FileType getFileType() {
return fileType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public class JacksonParser implements JsonDocumentParser {

private static final JsonDocumentParser INSTANCE = new JacksonParser();

/**
* Returns a fully initialized {@link JsonDocumentParser} of this implementation.
*
* @return the same instance all the time
*/
@NotNull
public static JsonDocumentParser getInstance() {
return INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private StartHarness() throws InterruptedException {
* Start the test harness and track it for timeouts.
*
* @throws InterruptedException if the harness is interrupted
* @throws IllegalStateException if stopping the harness throws an error
*/
@SuppressWarnings("IllegalCatch")
public void startHarness() throws InterruptedException {
Expand Down Expand Up @@ -199,7 +200,7 @@ public void start() {
* @throws Exception if there's a problem tearing things down
*/
public void tearDown() throws Exception {
getHarness().tearDown();
harness.tearDown();
applicationState.resetAllStates();
}

Expand Down Expand Up @@ -235,7 +236,7 @@ public Builder makeRequest(final @NotNull String target) {
*/
public Builder makeRequest(final String target, final Map<String, Object> queryParams) {
// Set target of call
WebTarget httpCall = getHarness().target(target);
WebTarget httpCall = harness.target(target);

// Add query params to call
for (final Map.Entry<String, Object> entry : queryParams.entrySet()) {
Expand All @@ -245,16 +246,6 @@ public Builder makeRequest(final String target, final Map<String, Object> queryP
return httpCall.request();
}

@NotNull
public AbstractBinder getBinder() {
return binder;
}

@NotNull
public JerseyTest getHarness() {
return harness;
}

/**
* Builds a test binder factory.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public GraphQLFactory(
* @return a resource file content
*
* @throws NullPointerException if {@code resourceName} is {@code null}
* @throws IllegalStateException if {@code resourceName} corresponds a non-existing file source
*/
@NotNull
public static String getGraphQLSchemaResourceAsString(@NotNull final String resourceName) {
Expand All @@ -97,6 +98,11 @@ public static String getGraphQLSchemaResourceAsString(@NotNull final String reso
throw new IllegalStateException(message);
}

/**
* Returns the {@link GraphQL native GraphQL API} factorized.
*
* @return the same instance
*/
@NotNull
public GraphQL getApi() {
return api;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class LayeredFileSystemConfig implements SystemConfig {

/**
* Constructor.
*
* @throws IllegalStateException if loading an existing {@code userConfig.properties} file fails
*/
public LayeredFileSystemConfig() {
this.compositeConfiguration = new CompositeConfiguration();
Expand Down
9 changes: 0 additions & 9 deletions checkstyle-suppressions.xml

This file was deleted.

16 changes: 15 additions & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<module name="JavadocMethod">
<property name="allowedAnnotations" value="Override"/>
<property name="validateThrows" value="true"/>
<property name="scope" value="anoninner"/>
<property name="accessModifiers" value="public, protected, package, private"/>
<property name="allowMissingParamTags" value="false"/>
<property name="allowMissingReturnTag" value="false"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
Expand Down Expand Up @@ -169,6 +169,20 @@
<property name="tokens" value="ENUM_CONSTANT_DEF"/>
<property name="severity" value="error"/>
</module>
<module name="MissingJavadocMethod">
<property name="severity" value="error"/>
<property name="allowMissingPropertyJavadoc" value="false"/>
<property name="scope" value="anoninner"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF"/>
</module>
<module name="MissingJavadocPackage">
<property name="severity" value="error"/>
</module>
<module name="MissingJavadocType">
<property name="scope" value="anoninner"/>
<property name="tokens" value="INTERFACE_DEF, CLASS_DEF, ENUM_DEF, ANNOTATION_DEF, RECORD_DEF"/>
<property name="severity" value="error"/>
</module>
<module name="NonEmptyAtclauseDescription">
<property name="javadocTokens" value=" PARAM_LITERAL, RETURN_LITERAL, THROWS_LITERAL, DEPRECATED_LITERAL"/>
<property name="severity" value="error"/>
Expand Down
20 changes: 6 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
</scm>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<checkstyle.skip>false</checkstyle.skip>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<version.athena>1.0-SNAPSHOT</version.athena>
<version.validation.api>3.0.1</version.validation.api>
Expand All @@ -73,14 +74,7 @@
<version.maven.surefire.plugin>3.0.0-M5</version.maven.surefire.plugin>
<version.maven.compiler.plugin>3.7.0</version.maven.compiler.plugin>
<version.maven.failsafe.plugin>3.0.0-M4</version.maven.failsafe.plugin>
<version.maven.checkstyle.plugin>3.1.2</version.maven.checkstyle.plugin>
<version.maven.surefire.report.plugin>${version.maven.surefire.plugin}</version.maven.surefire.report.plugin>

<checkstyle.skip>false</checkstyle.skip>
<checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
<checkstyle.suppressions.location>checkstyle-suppressions.xml</checkstyle.suppressions.location>
<checkstyle.version>8.30</checkstyle.version>
<checkstyle.resourceIncludes>**/*.properties*</checkstyle.resourceIncludes>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -427,23 +421,21 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${version.maven.checkstyle.plugin}</version>
<version>3.3.1</version>
<dependencies>
<!-- override default checkstyle version -->
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
<version>10.14.2</version>
</dependency>
</dependencies>
<configuration>
<suppressionsLocation>${checkstyle.suppressions.location}</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
<configLocation>${checkstyle.config.location}</configLocation>
<configLocation>checkstyle.xml</configLocation>
<includes>**\/*.java,**\/*.groovy</includes>
<resourceIncludes>**/*.properties,**/*.sample</resourceIncludes>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
</plugin>

Expand Down

0 comments on commit 1f4497a

Please sign in to comment.