Skip to content

Commit

Permalink
Using checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
tveronezi committed Oct 24, 2013
1 parent 28f5386 commit daf0afc
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 25 deletions.
16 changes: 16 additions & 0 deletions photodb-web/pom.xml
Expand Up @@ -61,6 +61,22 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
<configuration>
<enableRulesSummary>false</enableRulesSummary>
<configLocation>src/main/config/checkstyle.xml</configLocation>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
Expand Down
150 changes: 150 additions & 0 deletions photodb-web/src/main/config/checkstyle.xml
@@ -0,0 +1,150 @@
<?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">
<!--
If you set the basedir property below, then all reported file
names will be relative to the specified directory. See
http://checkstyle.sourceforge.net/5.x/config.html#Checker
<property name="basedir" value="${basedir}"/>
-->

<!-- Checks that property files contain the same keys. -->
<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
<module name="Translation"/>

<module name="FileLength"/>

<!-- Following interprets the header file as regular expressions. -->
<!-- <module name="RegexpHeader"/> -->

<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>

<module name="RegexpSingleline">
<!-- \s matches whitespace character, $ matches end of line. -->
<property name="format" value="\s+$"/>
<property name="message" value="Line has trailing spaces."/>
</module>

<module name="TreeWalker">

<property name="cacheFile" value="${checkstyle.cache.file}"/>

<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<!--<module name="JavadocMethod"/>-->
<!--<module name="JavadocType"/>-->
<!--<module name="JavadocVariable"/>-->
<!--<module name="JavadocStyle"/>-->


<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>


<!-- Checks for Headers -->
<!-- See http://checkstyle.sf.net/config_header.html -->
<!-- <module name="Header"> -->
<!-- The follow property value demonstrates the ability -->
<!-- to have access to ANT properties. In this case it uses -->
<!-- the ${basedir} property to allow Checkstyle to be run -->
<!-- from any directory within a project. See property -->
<!-- expansion, -->
<!-- http://checkstyle.sf.net/config.html#properties -->
<!-- <property -->
<!-- name="headerFile" -->
<!-- value="${basedir}/java.header"/> -->
<!-- </module> -->


<!-- Checks for imports -->
<!-- See http://checkstyle.sf.net/config_import.html -->
<module name="IllegalImport"/>
<!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports"/>


<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="LineLength">
<property name="max" value="120"/>
</module>
<module name="MethodLength"/>
<module name="ParameterNumber"/>


<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="EmptyForIteratorPad"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>

<!-- Modifier Checks -->
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>


<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>


<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="HiddenField">
<property name="ignoreSetter" value="true"/>
</module>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MagicNumber">
<property name="ignoreHashCodeMethod" value="true"/>
</module>
<module name="MissingSwitchDefault"/>
<module name="RedundantThrows"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>

<!-- Checks for class design -->
<!-- See http://checkstyle.sf.net/config_design.html -->
<module name="FinalClass"/>
<module name="HideUtilityClassConstructor"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier">
<property name="packageAllowed" value="true"/>
<property name="protectedAllowed" value="true"/>
</module>

<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->
<module name="ArrayTypeStyle"/>
<module name="TodoComment"/>
<module name="UpperEll"/>

</module>

</module>
20 changes: 11 additions & 9 deletions photodb-web/src/main/java/photodb/cdi/ImageManager.java
Expand Up @@ -60,17 +60,24 @@ private void calculateScale(final Integer maxSize, final Values values) {
values.b = Math.round(values.b * scale);
}

private Values buildValues(float a, float b) {
Values values = new Values();
values.a = a;
values.b = b;
return values;
}

private BufferedImage getResizedImage(final BufferedImage original) {
int width = original.getWidth();
int height = original.getHeight();

Values values = new Values(width, height);
Values values = buildValues(width, height);
calculateScale(MAX_SIZE, values);

width = Math.round(values.a);
height = Math.round(values.b);

values = new Values(height, width);
values = buildValues(height, width);
calculateScale(MAX_SIZE, values);

width = Math.round(values.b);
Expand Down Expand Up @@ -107,12 +114,7 @@ public String getThumb(final String originalBase64) throws IOException {
}

private class Values {
public float a;
public float b;

private Values(float a, float b) {
this.a = a;
this.b = b;
}
float a;
float b;
}
}
15 changes: 9 additions & 6 deletions photodb-web/src/main/java/photodb/data/entity/BaseEntity.java
Expand Up @@ -39,13 +39,16 @@ public void setUid(Long uid) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BaseEntity that = (BaseEntity) o;

if (uid != null ? !uid.equals(that.uid) : that.uid != null) return false;

if (uid != null ? !uid.equals(that.uid) : that.uid != null) {
return false;
}
return true;
}

Expand Down
19 changes: 12 additions & 7 deletions photodb-web/src/main/java/photodb/data/entity/User.java
Expand Up @@ -40,14 +40,19 @@ public void setName(String name) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;

if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
User user = (User) o;

if (name != null ? !name.equals(user.name) : user.name != null) return false;

if (name != null ? !name.equals(user.name) : user.name != null) {
return false;
}
return true;
}

Expand Down
Expand Up @@ -50,8 +50,7 @@ public Photo savePhoto(Long id, String fileName, String content, String contentT
setValues(photo, fileName, content, contentType, publicData);

// Set photo owner
final User user = this.user.getUser();
photo.setUser(user);
photo.setUser(this.user.getUser());

// Create the photo object
photo = this.baseEAO.create(photo);
Expand Down
Expand Up @@ -70,7 +70,7 @@ public User getUser() {
return user;
}

public void requestUser(String userName, String userAccount, String userPassword) throws ArithmeticException {
public void requestUser(String userName, String userAccount, String userPassword) {
try {
sendRequest(userName, userAccount, userPassword);
} catch (Exception e) {
Expand Down

0 comments on commit daf0afc

Please sign in to comment.