Skip to content
Permalink
Browse files

add checkstyle plugin

  • Loading branch information...
egetman committed Feb 24, 2019
1 parent 0a188a7 commit e9e7d5d969e2122664a7b9887de56bd20012a546
@@ -0,0 +1,176 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java, properties, xml"/>

<module name="TreeWalker">
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
<property name="format"
value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message" value="Avoid using corresponding octal or Unicode escape."/>
</module>
<module name="AvoidEscapedUnicodeCharacters">
<property name="allowEscapesForControlCharacters" value="true"/>
<property name="allowByTailComment" value="true"/>
<property name="allowNonPrintableEscapes" value="true"/>
</module>
<module name="LineLength">
<property name="max" value="120"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<module name="AvoidStarImport"/>
<module name="OneTopLevelClass"/>
<module name="NoLineWrap"/>
<module name="EmptyBlock">
<property name="option" value="TEXT"/>
<property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
</module>
<module name="NeedBraces"/>
<module name="LeftCurly">
<property name="maxLineLength" value="100"/>
</module>
<module name="RightCurly"/>
<module name="RightCurly">
<property name="option" value="alone"/>
<property name="tokens"
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
</module>
<module name="WhitespaceAround">
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyTypes" value="true"/>
<property name="allowEmptyLoops" value="true"/>
<message key="ws.notFollowed"
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
<message key="ws.notPreceded"
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
</module>
<module name="OneStatementPerLine"/>
<module name="MultipleVariableDeclarations"/>
<module name="ArrayTypeStyle"/>
<module name="MissingSwitchDefault"/>
<module name="UpperEll"/>
<module name="ModifierOrder"/>
<module name="EmptyLineSeparator">
<property name="allowNoEmptyLineBetweenFields" value="true"/>
</module>
<module name="SeparatorWrap">
<property name="tokens" value="DOT"/>
<property name="option" value="nl"/>
</module>
<module name="SeparatorWrap">
<property name="tokens" value="COMMA"/>
<property name="option" value="EOL"/>
</module>
<module name="PackageName">
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
<message key="name.invalidPattern"
value="Package name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="TypeName">
<property name="format" value="^[A-Z][a-zA-Z0-9_]*$"/>
<message key="name.invalidPattern"
value="Type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MemberName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<message key="name.invalidPattern"
value="Member name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ParameterName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<message key="name.invalidPattern"
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="LocalVariableName">
<property name="tokens" value="VARIABLE_DEF"/>
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<property name="allowOneCharVarInForLoop" value="true"/>
<message key="name.invalidPattern"
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ClassTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9_]*[T]$)"/>
<message key="name.invalidPattern"
value="Class type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MethodTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9_]*[T]$)"/>
<message key="name.invalidPattern"
value="Method type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="NoFinalizer"/>
<module name="GenericWhitespace">
<message key="ws.followed"
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
<message key="ws.preceded"
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
<message key="ws.illegalFollow"
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
<message key="ws.notPreceded"
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="4"/>
</module>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="VariableDeclarationUsageDistance">
<property name="allowedDistance" value="10"/>
</module>
<module name="MethodParamPad"/>
<module name="OperatorWrap">
<property name="option" value="NL"/>
<property name="tokens"
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/>
</module>
<module name="AnnotationLocation">
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
</module>
<module name="AnnotationLocation">
<property name="tokens" value="VARIABLE_DEF"/>
<property name="allowSamelineMultipleAnnotations" value="true"/>
</module>
<module name="NonEmptyAtclauseDescription"/>
<module name="JavadocTagContinuationIndentation"/>
<module name="SummaryJavadocCheck">
<property name="forbiddenSummaryFragments"
value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
</module>
<module name="JavadocParagraph"/>
<module name="AtclauseOrder">
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
<property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
</module>
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="tokens" value="METHOD_DEF,ANNOTATION_FIELD_DEF"/>
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingThrowsTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="minLineCount" value="2"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="allowThrowsTagsForSubclasses" value="true"/>
</module>

<module name="MethodName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
<message key="name.invalidPattern"
value="Method name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="SingleLineJavadoc">
<property name="ignoreInlineTags" value="false"/>
</module>
<module name="EmptyCatchBlock">
<property name="exceptionVariableName" value="expected"/>
</module>
<module name="CommentsIndentation"/>
</module>
</module>
23 pom.xml
@@ -29,6 +29,7 @@
<maven-jar-plugin.version>3.1.0</maven-jar-plugin.version>
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.0.1</maven-javadoc-plugin.version>
<maven-checkstyle-plugin.version>2.17</maven-checkstyle-plugin.version>
</properties>

<repositories>
@@ -263,6 +264,28 @@
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
<violationSeverity>warning</violationSeverity>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

@@ -7,7 +7,7 @@
* clustered environment. (To avoid situations when multiple services read the same offset from
* {@link io.jes.JEventStore} and apply duplicate changes concurrently).
*
* Note: there no any reentrancy guarantee by contract. Different implementations may or may not behave as reentrant.
* <p>Note: there no any reentrancy guarantee by contract. Different implementations may or may not behave as reentrant.
*/
public interface LockManager {

@@ -1,4 +1,5 @@
@ParametersAreNullableByDefault

package io.jes;

import javax.annotation.ParametersAreNullableByDefault;
@@ -21,7 +21,7 @@
import io.jes.snapshot.SnapshotReader;
import lombok.extern.slf4j.Slf4j;

import static java.lang.Integer.*;
import static java.lang.Integer.MAX_VALUE;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

@@ -13,6 +13,14 @@ private DDLFactory() {}

private static final String UNSUPPORTED_TYPE = "%s for %s type not supported";

/**
* Constructs new DDL producer based on DB vendor name and provided schema.
*
* @param databaseName vendor name of db product. Obtained through
* {@code connection.getMetaData()..getDatabaseProductName()}.
* @param schema schema name to use.
* @return {@link StoreDDLProducer} for event store.
*/
public static StoreDDLProducer newDDLProducer(@Nonnull String databaseName, @Nonnull String schema) {
if ("PostgreSQL".equals(databaseName)) {
return new PostgresDDL(schema);
@@ -21,6 +29,14 @@ public static StoreDDLProducer newDDLProducer(@Nonnull String databaseName, @Non
}
}

/**
* Constructs new DDL producer based on DB vendor name and provided schema.
*
* @param databaseName vendor name of db product. Obtained through
* {@code connection.getMetaData()..getDatabaseProductName()}.
* @param schema schema name to use.
* @return {@link SnapshotDDLProducer} for snapshot store.
*/
public static SnapshotDDLProducer newSnapshotDDLProducer(@Nonnull String databaseName, @Nonnull String schema) {
if ("PostgreSQL".equals(databaseName)) {
return new PostgresDDL(schema);
@@ -8,15 +8,15 @@
/**
* Provided ddl statements (assumed schema name 'foo')
*
* CREATE SCHEMA IF NOT EXISTS foo;
* <p>CREATE SCHEMA IF NOT EXISTS foo;</p>
*
* CREATE TABLE IF NOT EXISTS foo.event_store (
* <p>CREATE TABLE IF NOT EXISTS foo.event_store (
* id BIGSERIAL PRIMARY KEY,
* uuid UUID,
* data (BYTEA | TEXT) NOT NULL
* );
* );</p>
*
* CREATE INDEX CONCURRENTLY IF NOT EXISTS uuid_idx ON foo.event_store (uuid NULLS LAST);
* <p>CREATE INDEX CONCURRENTLY IF NOT EXISTS uuid_idx ON foo.event_store (uuid NULLS LAST);</p>
*
*/
private static final String READ_EVENTS = "SELECT * FROM %sevent_store WHERE id > ? ORDER BY id";
@@ -12,6 +12,9 @@

private StoreEntryFactory() {}

/**
* Resolves and return entry type based on provided {@literal payloadClass} type.
*/
public static Class<? extends StoreEntry> entryTypeOf(@Nonnull Class<?> payloadClass) {
if (String.class == payloadClass) {
return StoreEntry.StoreStringEntry.class;
@@ -21,6 +24,9 @@ private StoreEntryFactory() {}
throw new SerializationException("Payload of type " + payloadClass + " cannot be processed");
}

/**
* Factory mathod for creatig new {@literal store entry} based on paeload type.
*/
public static StoreEntry newEntry(@Nullable UUID uuid, @Nonnull Object payload) {
Objects.requireNonNull(payload, "Event payload must not be null");
if (payload instanceof String) {
@@ -1,4 +1,5 @@
@ParametersAreNullableByDefault

package io.jes.reactors;

import javax.annotation.ParametersAreNullableByDefault;
@@ -26,6 +26,9 @@ private SerializerFactory() {}
return (E) new EventSerializerProxy<>(new JacksonSerializer<>());
}

/**
* Produces and return new {@link Serializer} for events.
*/
@Nonnull
@SuppressWarnings({"unchecked", "squid:S1905"})
public static <T> Serializer<Event, T> newEventSerializer(@Nonnull Class<T> serializationType,
@@ -39,6 +42,9 @@ private SerializerFactory() {}
throw new IllegalArgumentException("Serialization for type " + serializationType + " not supported");
}

/**
* Produces and return new {@link Serializer} for aggregates.
*/
@Nonnull
@SuppressWarnings({"unchecked", "unused", "squid:S2293"})
public static <T> Serializer<Aggregate, T> newAggregateSerializer(@Nonnull Class<T> serializationType,
@@ -29,7 +29,6 @@
private final SnapshotDDLProducer ddlProducer;
private final Serializer<Aggregate, T> serializer;

@SuppressWarnings("WeakerAccess")
public JdbcSnapshotProvider(@Nonnull DataSource dataSource, @Nonnull Class<T> serializationType,
@Nonnull SerializationOption... options) {
try {
@@ -141,11 +140,11 @@ private Aggregate findAggregateByUuid(@Nonnull UUID uuid) {
/**
* Applies this function to the given argument.
*
* @param t the function argument
* @param argument the function argument
* @return the function result
*/
@SuppressWarnings("squid:S00112")
R apply(T t) throws Throwable;
R apply(T argument) throws Throwable;

}
}
@@ -9,8 +9,15 @@

public interface SnapshotProvider {

/**
* Returns initial state for given {@literal type} aggregate.
*
* @param uuid is event stream (aggregate) identifier.
* @param type is the class of aggregate.
* @param <T> is the type of agregate.
* @return aggregate of type {@literal T} initialized with initial state.
*/
@Nonnull
@SuppressWarnings("unused")
default <T extends Aggregate> T initialStateOf(@Nonnull UUID uuid, @Nonnull Class<T> type) {
try {
return type.newInstance();

0 comments on commit e9e7d5d

Please sign in to comment.
You can’t perform that action at this time.