Skip to content

Commit

Permalink
Added Checkstyle checks based on checks used by Spring Boot
Browse files Browse the repository at this point in the history
  • Loading branch information
hzpz committed Dec 1, 2015
1 parent 39ba675 commit f5c9318
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 14 deletions.
15 changes: 15 additions & 0 deletions src/checkstyle/checkstyle-header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
^\Q/*\E$
^\Q * Licensed under the Apache License, Version 2.0 (the "License");\E$
^\Q * you may not use this file except in compliance with the License.\E$
^\Q * You may obtain a copy of the License at\E$
^\Q *\E$
^\Q * http://www.apache.org/licenses/LICENSE-2.0\E$
^\Q *\E$
^\Q * Unless required by applicable law or agreed to in writing, software\E$
^\Q * distributed under the License is distributed on an "AS IS" BASIS,\E$
^\Q * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\E$
^\Q * See the License for the specific language governing permissions and\E$
^\Q * limitations under the License.\E$
^\Q */\E$
^$
^.*$
8 changes: 8 additions & 0 deletions src/checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress files="[\\/]autoconfigure[\\/]" checks="JavadocType"/>
<suppress files="[\\/]autoconfigure[\\/]" checks="JavadocVariable"/>
</suppressions>
141 changes: 141 additions & 0 deletions src/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">

<!-- Root Checks -->
<module name="RegexpHeader">
<property name="headerFile" value="${checkstyle.header.file}"/>
<property name="fileExtensions" value="java"/>
</module>
<module name="NewlineAtEndOfFile"/>

<!-- TreeWalker Checks -->
<module name="TreeWalker">

<!-- Annotations -->
<module name="AnnotationUseStyle">
<property name="elementStyle" value="compact"/>
</module>
<module name="MissingOverride"/>
<module name="PackageAnnotation"/>
<module name="AnnotationLocation">
<property name="allowSamelineSingleParameterlessAnnotation"
value="false"/>
</module>

<!-- Block Checks -->
<module name="EmptyBlock">
<property name="option" value="text"/>
</module>
<module name="LeftCurly"/>
<module name="RightCurly"/>
<module name="NeedBraces"/>
<module name="AvoidNestedBlocks"/>

<!-- Class Design -->
<module name="FinalClass"/>
<module name="InterfaceIsType"/>
<module name="HideUtilityClassConstructor"/>
<module name="MutableException"/>
<module name="InnerTypeLast"/>
<module name="OneTopLevelClass"/>

<!-- Coding -->
<module name="CovariantEquals"/>
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="InnerAssignment"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>
<module name="NestedForDepth">
<property name="max" value="3"/>
</module>
<module name="NestedIfDepth">
<property name="max" value="3"/>
</module>
<module name="NestedTryDepth">
<property name="max" value="3"/>
</module>
<module name="MultipleVariableDeclarations"/>
<module name="RequireThis">
<property name="checkMethods" value="false"/>
</module>
<module name="OneStatementPerLine"/>

<!-- Imports -->
<module name="AvoidStaticImport">
<property name="excludes"
value="org.junit.Assert.*, org.junit.Assume.*, org.junit.internal.matchers.ThrowableMessageMatcher.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*, org.springframework.boot.configurationprocessor.TestCompiler.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.Matchers.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*, org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*, org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo"/>
</module>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="true"/>
</module>

<!-- Javadoc Comments -->
<module name="JavadocType">
<property name="scope" value="package"/>
<property name="authorFormat" value=".+\s.+"/>
</module>
<module name="JavadocMethod">
<property name="allowMissingJavadoc" value="true"/>
</module>
<module name="JavadocVariable">
<property name="scope" value="public"/>
</module>
<module name="JavadocStyle">
<property name="checkEmptyJavadoc" value="true"/>
</module>
<module name="NonEmptyAtclauseDescription"/>
<module name="JavadocTagContinuationIndentation">
<property name="offset" value="0"/>
</module>
<module name="AtclauseOrder">
<property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF"/>
<property name="tagOrder" value="@param, @author, @since, @see, @version, @serial, @deprecated"/>
</module>
<module name="AtclauseOrder">
<property name="target" value="METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
<property name="tagOrder" value="@param, @return, @throws, @since, @deprecated, @see"/>
</module>

<!-- Miscellaneous -->
<module name="CommentsIndentation"/>
<module name="UpperEll"/>
<module name="ArrayTypeStyle"/>
<module name="OuterTypeFilename"/>

<!-- Modifiers -->
<module name="RedundantModifier"/>

<!-- Regexp -->
<module name="RegexpSinglelineJava">
<property name="maximum" value="0"/>
<property name="format" value="org\.mockito\.Mockito\.(when|doThrow|doAnswer)"/>
<property name="message"
value="Please use BDDMockto imports."/>
<property name="ignoreComments" value="true"/>
</module>
<module name="Regexp">
<property name="format" value="[ \t]+$"/>
<property name="illegalPattern" value="true"/>
<property name="message" value="Trailing whitespace"/>
</module>

<!-- Whitespace -->
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter">
<property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS, UNARY_PLUS, ARRAY_DECLARATOR"/>
</module>
<module name="NoWhitespaceBefore"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>

</module>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,29 @@ public static class MongeezConfiguration {

@PostConstruct
public void checkLocationExists() {
Resource resource = resourceLoader.getResource(mongeezProperties.getLocation());
Resource resource = this.resourceLoader.getResource(this.mongeezProperties.getLocation());
Assert.state(resource.exists(),
"Cannot find Mongeez migration script at '" + mongeezProperties.getLocation() + "'");
"Cannot find Mongeez migration script at '" + this.mongeezProperties.getLocation() + "'");
}

@Bean(initMethod = "process")
public Mongeez mongeez(MongoProperties mongoProperties, Mongo mongo) {
Mongeez mongeez = new Mongeez();
mongeez.setMongo(mongo);
if (StringUtils.hasText(mongeezProperties.getDatabase())) {
mongeez.setDbName(mongeezProperties.getDatabase());
if (StringUtils.hasText(this.mongeezProperties.getDatabase())) {
mongeez.setDbName(this.mongeezProperties.getDatabase());
} else {
mongeez.setDbName(mongoProperties.getMongoClientDatabase());
}
if (mongeezProperties.hasCredentials()) {
MongoAuth auth = mongeezProperties.createMongoAuth();
if (this.mongeezProperties.hasCredentials()) {
MongoAuth auth = this.mongeezProperties.createMongoAuth();
mongeez.setAuth(auth);
} else if (hasCredentials(mongoProperties)) {
String msg = "Credentials under spring.data.mongodb.* found but no credentials for mongeez.* defined." +
"Please add correct mongeez.password and mongeez.username";
throw new BeanCreationException(msg);
}
mongeez.setFile(resourceLoader.getResource(mongeezProperties.getLocation()));
mongeez.setFile(this.resourceLoader.getResource(this.mongeezProperties.getLocation()));
return mongeez;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,47 +51,47 @@ public class MongeezProperties {
private String database;

public String getLocation() {
return location;
return this.location;
}

public void setLocation(String location) {
this.location = location;
}

public boolean isEnabled() {
return enabled;
return this.enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public String getUsername() {
return username;
return this.username;
}

public void setUsername(String username) {
this.username = username;
}

public char[] getPassword() {
return password;
return this.password;
}

public void setPassword(char[] password) {
this.password = password;
}

public String getDatabase() {
return database;
return this.database;
}

public void setDatabase(String database) {
this.database = database;
}

public boolean hasCredentials() {
return username != null && password != null;
return this.username != null && this.password != null;
}

public void clearPassword() {
Expand All @@ -105,7 +105,7 @@ public void clearPassword() {

public MongoAuth createMongoAuth() {
try {
return new MongoAuth(username, new String(password));
return new MongoAuth(this.username, new String(this.password));
} finally {
clearPassword();
}
Expand Down

0 comments on commit f5c9318

Please sign in to comment.