Manybubbles has uploaded a new change for review.
https://gerrit.wikimedia.org/r/187825
Change subject: Enforce Java code style with checkstyle
......................................................................
Enforce Java code style with checkstyle
It doesn't enforce groovy but its something.
Change-Id: Ib039b92e89bc244b9fb6c93e1890f9254f48bc00
---
M console.sh
M pom.xml
M server.sh
A src/build/checkstyle.xml
M src/main/java/org/wikidata/gremlin/DomainSpecificLanguageTraversal.java
M src/main/java/org/wikidata/gremlin/IteratorUtils.java
M src/main/java/org/wikidata/gremlin/LoadingTraversal.java
M src/main/java/org/wikidata/gremlin/SelfAware.java
M src/main/java/org/wikidata/gremlin/TreePipe.java
M src/main/java/org/wikidata/gremlin/WikidataTraversal.java
10 files changed, 234 insertions(+), 73 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikidata/gremlin
refs/changes/25/187825/1
diff --git a/console.sh b/console.sh
index fd7884b..8b3994c 100755
--- a/console.sh
+++ b/console.sh
@@ -16,4 +16,4 @@
# Compiles everything and launches a console.
-mvn -Pconsole test
+mvn -Pconsole,skipTests test
diff --git a/pom.xml b/pom.xml
index 109f5d5..6babf65 100644
--- a/pom.xml
+++ b/pom.xml
@@ -199,7 +199,7 @@
<include>org.apache.httpcomponents:httpclient</include>
<include>org.apache.httpcomponents:httpcore</include>
<include>org.codehaus.groovy:groovy-all</include>
-\
<include>org.codehaus.groovy.modules.http-builder:http-builder</include>
+
<include>org.codehaus.groovy.modules.http-builder:http-builder</include>
<include>org.javatuples:javatuples</include>
<include>org.objenesis:objenesis</include>
<include>org.slf4j:slf4j-api</include>
@@ -218,6 +218,34 @@
</configuration>
</execution>
</executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>2.13</version>
+ <executions>
+ <execution>
+ <id>validate</id>
+ <phase>validate</phase>
+ <configuration>
+
<configLocation>src/build/checkstyle.xml</configLocation>
+ <encoding>UTF-8</encoding>
+ <consoleOutput>true</consoleOutput>
+ <failsOnError>true</failsOnError>
+ <linkXRef>false</linkXRef>
+ </configuration>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>com.puppycrawl.tools</groupId>
+ <artifactId>checkstyle</artifactId>
+ <version>6.2</version>
+ </dependency>
+ </dependencies>
</plugin>
</plugins>
<pluginManagement>
@@ -264,9 +292,18 @@
</testResource>
</testResources>
</build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>codenarc-maven-plugin</artifactId>
+ <version>0.18-1</version>
+ </plugin>
+ </plugins>
+ </reporting>
<profiles>
<profile>
- <id>console</id>
+ <id>skipTests</id>
<build>
<plugins>
<plugin>
@@ -278,6 +315,23 @@
<skipTests>true</skipTests>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>validate</id>
+ <phase>never</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>console</id>
+ <build>
+ <plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
@@ -313,15 +367,6 @@
<build>
<plugins>
<plugin>
- <!-- Don't run tests before running the poller -
that'd take too long. -->
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.18.1</version>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
- </plugin>
- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
@@ -354,15 +399,6 @@
<build>
<plugins>
<plugin>
- <!-- Don't run tests before running the poller -
that'd take too long. -->
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.18.1</version>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
- </plugin>
- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
@@ -385,50 +421,6 @@
<classpath/>
<argument>com.tinkerpop.gremlin.server.GremlinServer</argument>
<argument>src/test/resources/gremlin-server.yaml</argument>
- </arguments>
- <classpathScope>test</classpathScope>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- <profile>
- <id>bootstrap</id>
- <build>
- <plugins>
- <plugin>
- <!-- Don't run tests before running the poller -
that'd take too long. -->
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.18.1</version>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <version>1.3.2</version>
- <executions>
- <execution>
- <id>console</id>
- <phase>test</phase>
- <goals>
- <!-- The exec:java goal fail with
GROOVY-6951. No idea why.
- This is better anyway because we have
more control. -->
- <goal>exec</goal>
- </goals>
- <configuration>
- <executable>java</executable>
- <longClasspath>true</longClasspath>
- <arguments>
- <argument>-Xmx1G</argument>
-
<argument>-Xrunjdwp:transport=dt_socket,address=8890,server=y,suspend=n</argument>
- <argument>-classpath</argument>
- <classpath/>
-
<argument>org.wikidata.gremlin.Bootstrap</argument>
</arguments>
<classpathScope>test</classpathScope>
</configuration>
diff --git a/server.sh b/server.sh
index 0e46cd5..94d2abb 100755
--- a/server.sh
+++ b/server.sh
@@ -16,4 +16,4 @@
# Compiles everything and launches a server.
-mvn -Pserver test
+mvn -Pserver,skipTests test
diff --git a/src/build/checkstyle.xml b/src/build/checkstyle.xml
new file mode 100644
index 0000000..58a6c68
--- /dev/null
+++ b/src/build/checkstyle.xml
@@ -0,0 +1,145 @@
+<?xml version="1.0"?>
+<!--
+
+ Copyright (C) 2014 Wikimedia Foundation
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<!DOCTYPE module PUBLIC
+ "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
+ "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
+
+<module name="Checker">
+ <module name="TreeWalker">
+ <!-- Javadoc -->
+ <module name="JavadocType"/>
+ <module name="JavadocMethod">
+ <property name="allowUndeclaredRTE" value="true"/> <!-- You aren't
supposed to declare these anyway... -->
+ <property name="allowMissingReturnTag" value="true"/> <!-- Sometimes its
just overkill -->
+ <property name="allowMissingParamTags" value="true"/> <!-- Sometimes its
just overkill -->
+ </module>
+ <module name="JavadocStyle"/>
+ <module name="JavadocVariable"/>
+
+
+ <!-- Formatting -->
+ <!-- https://github.com/checkstyle/checkstyle/issues/281
+ <module name="Indentation">
+ <property name="basicOffset" value="2"/>
+ <property name="caseIndent" value="0"/>
+ </module>
+ -->
+ <module name="LineLength">
+ <property name="max" value="120"/>
+ </module>
+ <module name="MethodParamPad"/>
+ <module name="NoWhitespaceAfter"/>
+ <module name="NoWhitespaceBefore"/>
+ <module name="ParenPad"/>
+ <module name="TypecastParenPad">
+ <property name="option" value="nospace"/>
+ </module>
+ <module name="WhitespaceAfter">
+ <property name="tokens" value="COMMA, SEMI"/> <!-- not typecasts -->
+ </module>
+ <module name="WhitespaceAround">
+ <property name="allowEmptyConstructors" value="true"/>
+ <property name="allowEmptyMethods" value="true"/>
+ <property name="allowEmptyTypes" value="true"/>
+ <property name="allowEmptyLoops" value="true"/>
+ </module>
+ <module name="ModifierOrder"/>
+ <module name="RedundantModifier"/>
+ <module name="EmptyBlock"/> <!-- Put a comment in it if you need one
explaining why -->
+ <module name="LeftCurly">
+ <property name="maxLineLength" value="120"/>
+ </module>
+ <module name="RightCurly"/>
+ <module name="AvoidNestedBlocks">
+ <property name="allowInSwitchCase" value="true"/>
+ </module>
+ <module name="EmptyStatement"/>
+ <module name="UpperEll"/> <!-- Lowercase l is hard to read -->
+ <module name="ArrayTypeStyle"/>
+
+
+ <!-- Naming conventions -->
+ <module name="PackageName">
+ <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
+ </module>
+ <module name="TypeName"/>
+ <module name="ConstantName"/>
+ <module name="MemberName"/>
+ <module name="LocalFinalVariableName"/>
+ <module name="LocalVariableName"/>
+ <module name="ParameterName"/>
+ <module name="StaticVariableName"/>
+ <module name="UnnecessaryParentheses"/>
+ <module name="PackageDeclaration"/>
+
+
+ <!-- Import -->
+ <module name="AvoidStarImport"/>
+ <module name="IllegalImport"/>
+ <module name="RedundantImport"/>
+ <module name="UnusedImports"/>
+ <module name="ImportOrder"/>
+
+
+ <!-- Common coding problems/opinionates stuff -->
+ <module name="CovariantEquals"/>
+ <module name="EqualsHashCode"/>
+ <module name="HiddenField"/> <!-- Rarely the right thing to do -->
+ <module name="InnerAssignment"/> <!-- Too suprising -->
+ <module name="MissingSwitchDefault"/> <!-- Just comment that its a noop if
its a noop -->
+ <module name="ModifiedControlVariable"/>
+ <module name="SimplifyBooleanExpression"/>
+ <module name="SimplifyBooleanReturn"/>
+ <module name="StringLiteralEquality"/>
+ <module name="SuperClone"/>
+ <module name="SuperFinalize"/>
+ <module name="IllegalCatch"/>
+ <module name="IllegalThrows"/>
+ <module name="ExplicitInitialization"/> <!-- May as well let Java do what
its going to do -->
+ <module name="DefaultComesLast"/>
+ <module name="FallThrough"/>
+ <module name="MultipleVariableDeclarations"/>
+ <module name="VisibilityModifier"/> <!-- May as well follow standard Java
style here -->
+ <module name="FinalClass"/>
+ <module name="HideUtilityClassConstructor"/>
+ <module name="DesignForExtension"/>
+ <module name="MutableException"/>
+ <module name="UncommentedMain">
+ <property name="excludedClasses"
value="org\.wikidata\.gremlin\.tool\..*"/>
+ </module>
+
+
+ <!-- Really opinionated. Probably wrong. -->
+ <module name="ClassFanOutComplexity"/>
+ <module name="CyclomaticComplexity"/>
+ <module name="NPathComplexity"/>
+
+ <!-- These are explicitly ok -->
+ <!--
+ <module name="ParameterAssignment"/> Usually used when munging parameters.
Fine.
+ <module name="TrailingComment"/>
+ -->
+ </module>
+
+ <!-- More formatting stuff that can't be in TreeWalker -->
+ <module name="NewlineAtEndOfFile"/>
+ <module name="RegexpSingleline">
+ <property name="format" value="\s+$"/>
+ <property name="message" value="Line has trailing spaces."/>
+ </module>
+</module>
diff --git
a/src/main/java/org/wikidata/gremlin/DomainSpecificLanguageTraversal.java
b/src/main/java/org/wikidata/gremlin/DomainSpecificLanguageTraversal.java
index 6cef231..b563275 100644
--- a/src/main/java/org/wikidata/gremlin/DomainSpecificLanguageTraversal.java
+++ b/src/main/java/org/wikidata/gremlin/DomainSpecificLanguageTraversal.java
@@ -15,7 +15,6 @@
package org.wikidata.gremlin;
import com.tinkerpop.gremlin.process.graph.GraphTraversal;
-import com.tinkerpop.gremlin.process.graph.step.sideEffect.IdentityStep;
import com.tinkerpop.gremlin.process.graph.step.sideEffect.StartStep;
import com.tinkerpop.gremlin.structure.Vertex;
@@ -24,6 +23,9 @@
/**
* Domain specific language for traversing wikidata.
+ * @param <S> type of starts
+ * @param <E> element type being traversed - .get returns this
+ * @param <Self> self type for casting
*/
public interface DomainSpecificLanguageTraversal<S, E, Self> extends
GraphTraversal<S, E>, SelfAware<Self> {
/**
diff --git a/src/main/java/org/wikidata/gremlin/IteratorUtils.java
b/src/main/java/org/wikidata/gremlin/IteratorUtils.java
index 08e1243..5bcfc8f 100644
--- a/src/main/java/org/wikidata/gremlin/IteratorUtils.java
+++ b/src/main/java/org/wikidata/gremlin/IteratorUtils.java
@@ -21,7 +21,7 @@
/**
* Utilities for building iterators.
*/
-public class IteratorUtils {
+public abstract class IteratorUtils {
/**
* Build an iterator of a single element.
*/
@@ -38,4 +38,9 @@
}
return of(s);
}
+
+ /**
+ * Util class - do not construct.
+ */
+ private IteratorUtils() {}
}
diff --git a/src/main/java/org/wikidata/gremlin/LoadingTraversal.java
b/src/main/java/org/wikidata/gremlin/LoadingTraversal.java
index 2b81e2f..50e95ed 100644
--- a/src/main/java/org/wikidata/gremlin/LoadingTraversal.java
+++ b/src/main/java/org/wikidata/gremlin/LoadingTraversal.java
@@ -23,6 +23,9 @@
/**
* Implementations of methods to load items from wikidata and ensure the schema
* is good.
+ * @param <S> type of starts
+ * @param <E> element type being traversed - .get returns this
+ * @param <Self> self type for casting
*/
public interface LoadingTraversal<S, E, Self> extends GraphTraversal<S, E>,
SelfAware<Self> {
/**
diff --git a/src/main/java/org/wikidata/gremlin/SelfAware.java
b/src/main/java/org/wikidata/gremlin/SelfAware.java
index 32c15ba..d0f84dc 100644
--- a/src/main/java/org/wikidata/gremlin/SelfAware.java
+++ b/src/main/java/org/wikidata/gremlin/SelfAware.java
@@ -14,14 +14,14 @@
*/
package org.wikidata.gremlin;
-import com.tinkerpop.gremlin.process.graph.GraphTraversal;
-import com.tinkerpop.gremlin.process.graph.step.sideEffect.IdentityStep;
-import com.tinkerpop.gremlin.process.graph.step.sideEffect.StartStep;
-import com.tinkerpop.gremlin.structure.Vertex;
-
/**
* Objects of this type can cast things to their ultimate type.
+ * @param <Self> self type used for casting
*/
public interface SelfAware<Self> {
+ /**
+ * Cast o to self safely. Use with builder pattern to force return of
Self
+ * when calling a method that returns some superclass.
+ */
Self cast(Object o);
}
diff --git a/src/main/java/org/wikidata/gremlin/TreePipe.java
b/src/main/java/org/wikidata/gremlin/TreePipe.java
index e7d392d..c448fd6 100644
--- a/src/main/java/org/wikidata/gremlin/TreePipe.java
+++ b/src/main/java/org/wikidata/gremlin/TreePipe.java
@@ -25,6 +25,9 @@
// import com.tinkerpop.pipes.transform.TransformPipe;
// import com.tinkerpop.pipes.util.iterators.SingleIterator;
+/**
+ * Port me.
+ */
public class TreePipe {//extends AbstractPipe<Vertex,Vertex> implements
TransformPipe<Vertex, Vertex> {
// TODO port me
diff --git a/src/main/java/org/wikidata/gremlin/WikidataTraversal.java
b/src/main/java/org/wikidata/gremlin/WikidataTraversal.java
index 7685624..6527883 100644
--- a/src/main/java/org/wikidata/gremlin/WikidataTraversal.java
+++ b/src/main/java/org/wikidata/gremlin/WikidataTraversal.java
@@ -24,6 +24,8 @@
/**
* Traversal interface defining new steps for wikidata. Note that this must
be written in Java
* because Groovy doesn't yet support default method implementations on
interface methods.
+ * @param <S> type of starts
+ * @param <E> element type being traversed - .get returns this
*/
public interface WikidataTraversal<S, E> extends GraphTraversal<S, E>,
LoadingTraversal<S, E, WikidataTraversal<S, E>>,
@@ -34,10 +36,16 @@
return (WikidataTraversal) self;
}
+ /**
+ * Build the default implementation. Used by Tinkerpop's g.of() method.
+ */
static <S> WikidataTraversal<S, S> of(Graph graph) {
return new DefaultWikidataTraversal(graph);
}
+ /**
+ * Default traversal implementation.
+ */
class DefaultWikidataTraversal extends DefaultTraversal implements
WikidataTraversal {
static {
DefaultTraversalStrategies traversalStrategies = new
DefaultTraversalStrategies();
@@ -45,6 +53,9 @@
TraversalStrategies.GlobalCache.registerStrategies(DefaultWikidataTraversal.class,
traversalStrategies);
}
+ /**
+ * Build witha graph reference.
+ */
public DefaultWikidataTraversal(Graph graph) {
super(graph);
}
--
To view, visit https://gerrit.wikimedia.org/r/187825
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib039b92e89bc244b9fb6c93e1890f9254f48bc00
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/gremlin
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits