Skip to content

Commit 946d8bc

Browse files
SamCarlbergJLLeitschuh
authored andcommitted
Add checkstyle plugin to enforce consistency (#605)
* Add checkstyle plugin to enforce consistency * Use checkstyle version 6.18 * Don't use the 'check' task to run tests since checkstyle screws it up * Change import order, remove dependencies from checkstyle tasks Also formatted build.gradle and checkstyle.xml New import order: edu.wpi.grip.* non-GRIP imports, alphabetically static imports, alphabetically
1 parent 33c3999 commit 946d8bc

File tree

317 files changed

+21643
-19677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

317 files changed

+21643
-19677
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ install:
3030
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && ./gradlew :ui:assemble --stacktrace || ./gradlew --stacktrace '
3131

3232
script:
33-
- ./gradlew check --stacktrace -Pheadless=true -PlogTests
33+
- ./gradlew checkstyleMain checkstyleTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests
3434

3535
after_success:
3636
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then codecov ; fi

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build_script:
66

77
# to run your custom scripts instead of automatic tests
88
test_script:
9-
- gradlew.bat check --stacktrace -Pheadless=true -PlogTests
9+
- gradlew.bat checkstyleMain checkstyleTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests
1010

1111
platform:
1212
- x64

build.gradle

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def getGitCommit = { ->
3030
idea.project {
3131
ipr.withXml { provider ->
3232
def node = provider.asNode()
33-
def compilerConfig = node.component.find { it.'@name' == 'CompilerConfiguration'}
33+
def compilerConfig = node.component.find { it.'@name' == 'CompilerConfiguration' }
3434
compilerConfig.annotationProcessing[0].'@enabled' = 'true'
3535
// def ccfg = node.component.find { it.@name == 'CompilerConfiguration' }
3636
// ccfg.remove(ccfg.annotationProcessing)
@@ -89,11 +89,22 @@ allprojects {
8989
apply plugin: 'application'
9090
apply plugin: 'jacoco'
9191
apply plugin: 'net.ltgt.errorprone'
92+
apply plugin: 'checkstyle'
9293

9394
configurations.errorprone {
9495
resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.9'
9596
}
9697

98+
checkstyle {
99+
configFile = new File(rootDir, "checkstyle.xml")
100+
toolVersion = '6.19'
101+
}
102+
103+
tasks.withType(Checkstyle) {
104+
// Remove checkstyle dependencies on compilation
105+
// (This neuters :core:checkstyleGenerated, but since that's not needed anyway, who cares)
106+
it.dependsOn = []
107+
}
97108

98109
repositories {
99110
mavenCentral()
@@ -125,8 +136,6 @@ allprojects {
125136
}
126137
}
127138

128-
check.dependsOn jacocoTestReport
129-
130139
tasks.withType(Javadoc) {
131140
source compileJava.source
132141
options.addStringOption('Xdoclint:all,-html', '-quiet')
@@ -141,7 +150,7 @@ allprojects {
141150
test {
142151
testLogging {
143152
if (project.hasProperty('logTests')) {
144-
events "started", "passed", "skipped", "failed"
153+
events "started", "passed", "skipped", "failed"
145154
} else {
146155
events "failed"
147156
}
@@ -372,7 +381,6 @@ task jacocoRootReport(type: JacocoReport, group: 'Coverage reports') {
372381
executionData = files(executionData.findAll { it.exists() })
373382
}
374383
}
375-
check.dependsOn jacocoRootReport
376384

377385
task wrapper(type: Wrapper) {
378386
gradleVersion = '2.13'

buildSrc/src/main/java/edu/wpi/gripgenerator/FileParser.java

Lines changed: 110 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.github.javaparser.ast.expr.FieldAccessExpr;
99
import com.github.javaparser.ast.expr.NameExpr;
1010
import com.github.javaparser.ast.type.PrimitiveType;
11+
1112
import edu.wpi.gripgenerator.defaults.DefaultValueCollector;
1213
import edu.wpi.gripgenerator.defaults.EnumDefaultValue;
1314
import edu.wpi.gripgenerator.defaults.PrimitiveDefaultValue;
@@ -24,116 +25,120 @@
2425
import java.util.Set;
2526

2627
public class FileParser {
27-
/**
28-
* Regex splits the parameter into three distinct capture groups.
29-
* <ol>
30-
* <li>The type and the param with optional varargs.</li>
31-
* <li>The comment that is after the parameter.</li>
32-
* <li>The various ways that the parameter can end.</li>
33-
* </ol>
34-
*/
35-
protected static final String methodReorderPattern = "([A-Za-z1-9]+ (?:\\.\\.\\.)?[a-z][A-Za-z0-9_]*)(/\\*=[^ ]*\\*/)((?:,)|(?:\\s*\\)))";
36-
37-
/**
38-
* Reorders the {@link FileParser#methodReorderPattern} capture groups so the JavaParser can correctly
39-
* associate the params with their respective comments.
40-
*/
41-
protected static final String methodNewOrder = "$2$1$3";
42-
43-
/**
44-
* There is a bug in the JavaParser that will incorrectly associate comments after a parameter but
45-
* before a comma will incorrectly associate that comment with the next param in the method's params.
46-
*
47-
* @param stream The original input file.
48-
* @return The processed output stream.
49-
* @see <a href="https://github.com/javaparser/javaparser/issues/199">Javaparser Issue:199</a>
50-
*/
51-
private static InputStream preProcessStream(InputStream stream) {
52-
//FIXME: This is a hack around. This should be removed once the above noted issue is resolved.
53-
java.util.Scanner s = new java.util.Scanner(stream, StandardCharsets.UTF_8.name()).useDelimiter("\\A");
54-
String input = s.hasNext() ? s.next() : "";
55-
input = input.replaceAll(methodReorderPattern, methodNewOrder);
56-
return new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8));
57-
}
58-
59-
private static CompilationUnit readFile(URL url) {
60-
try {
61-
return JavaParser.parse(preProcessStream(url.openStream()));
62-
} catch (IOException e) {
63-
throw new IllegalStateException(e);
64-
} catch (ParseException e) {
65-
throw new IllegalStateException(e);
66-
}
28+
/**
29+
* Regex splits the parameter into three distinct capture groups. <ol> <li>The type and the param
30+
* with optional varargs.</li> <li>The comment that is after the parameter.</li> <li>The various
31+
* ways that the parameter can end.</li> </ol>
32+
*/
33+
protected static final String methodReorderPattern = "([A-Za-z1-9]+ (?:\\.\\.\\.)" +
34+
"?[a-z][A-Za-z0-9_]*)(/\\*=[^ ]*\\*/)((?:,)|(?:\\s*\\)))";
35+
36+
/**
37+
* Reorders the {@link FileParser#methodReorderPattern} capture groups so the JavaParser can
38+
* correctly associate the params with their respective comments.
39+
*/
40+
protected static final String methodNewOrder = "$2$1$3";
41+
42+
/**
43+
* There is a bug in the JavaParser that will incorrectly associate comments after a parameter but
44+
* before a comma will incorrectly associate that comment with the next param in the method's
45+
* params.
46+
*
47+
* @param stream The original input file.
48+
* @return The processed output stream.
49+
* @see <a href="https://github.com/javaparser/javaparser/issues/199">Javaparser Issue:199</a>
50+
*/
51+
private static InputStream preProcessStream(InputStream stream) {
52+
//FIXME: This is a hack around. This should be removed once the above noted issue is resolved.
53+
java.util.Scanner s = new java.util.Scanner(stream, StandardCharsets.UTF_8.name())
54+
.useDelimiter("\\A");
55+
String input = s.hasNext() ? s.next() : "";
56+
input = input.replaceAll(methodReorderPattern, methodNewOrder);
57+
return new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8));
58+
}
59+
60+
private static CompilationUnit readFile(URL url) {
61+
try {
62+
return JavaParser.parse(preProcessStream(url.openStream()));
63+
} catch (IOException e) {
64+
throw new IllegalStateException(e);
65+
} catch (ParseException e) {
66+
throw new IllegalStateException(e);
6767
}
68-
69-
/**
70-
* Generates all of the source code from the opencv bindings
71-
*
72-
* @return A map of the filename with the compilation units
73-
*/
74-
public static Map<String, CompilationUnit> generateAllSourceCode() {
75-
URL INPUT_URL = FileParser.class.getResource("/org/bytedeco/javacpp/opencv_core.txt");
76-
CompilationUnit compilationUnit = readFile(INPUT_URL);
77-
Map<String, CompilationUnit> returnMap = new HashMap<>();
78-
DefaultValueCollector collector = new DefaultValueCollector();
79-
collector.add(new PrimitiveDefaultValue(new PrimitiveType(PrimitiveType.Primitive.Double)) {
80-
@Override
81-
protected Set<String> getDefaultValues() {
82-
return Collections.singleton("CV_PI");
83-
}
84-
85-
@Override
86-
public Expression getDefaultValue(String defaultValue) {
87-
return new FieldAccessExpr(
88-
new NameExpr("Math"),
89-
"PI"
90-
);
91-
}
92-
});
93-
94-
collector.add(new EnumDefaultValue("edu.wpi.grip.core.operations.opencv.enumeration", "FlipCode", "X_AXIS", "Y_AXIS", "BOTH_AXES"));
95-
96-
OperationList operationList = new OperationList(
97-
new ImportDeclaration(new NameExpr("edu.wpi.grip.generated.opencv_core"), false, true),
98-
new ImportDeclaration(new NameExpr("edu.wpi.grip.generated.opencv_imgproc"), false, true)
68+
}
69+
70+
/**
71+
* Generates all of the source code from the opencv bindings
72+
*
73+
* @return A map of the filename with the compilation units
74+
*/
75+
public static Map<String, CompilationUnit> generateAllSourceCode() {
76+
URL openCvCoreUrl = FileParser.class.getResource("/org/bytedeco/javacpp/opencv_core.txt");
77+
CompilationUnit compilationUnit = readFile(openCvCoreUrl);
78+
Map<String, CompilationUnit> returnMap = new HashMap<>();
79+
DefaultValueCollector collector = new DefaultValueCollector();
80+
collector.add(new PrimitiveDefaultValue(new PrimitiveType(PrimitiveType.Primitive.Double)) {
81+
@Override
82+
protected Set<String> getDefaultValues() {
83+
return Collections.singleton("CV_PI");
84+
}
85+
86+
@Override
87+
public Expression getDefaultValue(String defaultValue) {
88+
return new FieldAccessExpr(
89+
new NameExpr("Math"),
90+
"PI"
9991
);
92+
}
93+
});
10094

101-
if (compilationUnit != null) {
102-
returnMap.putAll(parseOpenCVCore(compilationUnit, collector, operationList));
103-
} else {
104-
System.err.print("Invalid File input");
105-
}
106-
URL INPUT_URL2 = FileParser.class.getResource("/org/bytedeco/javacpp/opencv_imgproc.txt");
107-
compilationUnit = readFile(INPUT_URL2);
108-
if (compilationUnit != null) {
109-
returnMap.putAll(parseOpenImgprc(compilationUnit, collector, operationList));
110-
111-
}
112-
return returnMap;
113-
}
114-
115-
public static Map<String, CompilationUnit> parseOpenImgprc(CompilationUnit imgprocDeclaration, DefaultValueCollector collector, OperationList operations) {
116-
Map<String, CompilationUnit> compilationUnits = new HashMap<>();
117-
final String baseClassName = "opencv_imgproc";
118-
119-
OpenCVEnumVisitor enumVisitor = new OpenCVEnumVisitor(baseClassName, collector);
120-
enumVisitor.visit(imgprocDeclaration, compilationUnits);
121-
compilationUnits.putAll(enumVisitor.generateCompilationUnits());
122-
return compilationUnits;
123-
}
95+
collector.add(new EnumDefaultValue("edu.wpi.grip.core.operations.opencv.enumeration",
96+
"FlipCode", "X_AXIS", "Y_AXIS", "BOTH_AXES"));
12497

125-
public static Map<String, CompilationUnit> parseOpenCVCore(CompilationUnit coreDeclaration, DefaultValueCollector collector, OperationList operations) {
126-
Map<String, CompilationUnit> compilationUnits = new HashMap<>();
127-
final String baseClassName = "opencv_core";
98+
OperationList operationList = new OperationList(
99+
new ImportDeclaration(new NameExpr("edu.wpi.grip.generated.opencv_core"), false, true),
100+
new ImportDeclaration(new NameExpr("edu.wpi.grip.generated.opencv_imgproc"), false, true)
101+
);
128102

129-
OpenCVEnumVisitor enumVisitor = new OpenCVEnumVisitor(baseClassName, collector);
130-
enumVisitor.visit(coreDeclaration, compilationUnits);
131-
compilationUnits.putAll(enumVisitor.generateCompilationUnits());
132-
133-
return compilationUnits;
103+
if (compilationUnit != null) {
104+
returnMap.putAll(parseOpenCVCore(compilationUnit, collector, operationList));
105+
} else {
106+
System.err.print("Invalid File input");
134107
}
135-
136-
public static void main(String... args) {
137-
FileParser.generateAllSourceCode();
108+
URL openCvImgprocUrl = FileParser.class.getResource("/org/bytedeco/javacpp/opencv_imgproc.txt");
109+
compilationUnit = readFile(openCvImgprocUrl);
110+
if (compilationUnit != null) {
111+
returnMap.putAll(parseOpenImgprc(compilationUnit, collector, operationList));
138112
}
113+
return returnMap;
114+
}
115+
116+
public static Map<String, CompilationUnit> parseOpenImgprc(CompilationUnit imgprocDeclaration,
117+
DefaultValueCollector collector,
118+
OperationList operations) {
119+
Map<String, CompilationUnit> compilationUnits = new HashMap<>();
120+
final String baseClassName = "opencv_imgproc";
121+
122+
OpenCVEnumVisitor enumVisitor = new OpenCVEnumVisitor(baseClassName, collector);
123+
enumVisitor.visit(imgprocDeclaration, compilationUnits);
124+
compilationUnits.putAll(enumVisitor.generateCompilationUnits());
125+
return compilationUnits;
126+
}
127+
128+
public static Map<String, CompilationUnit> parseOpenCVCore(CompilationUnit coreDeclaration,
129+
DefaultValueCollector collector,
130+
OperationList operations) {
131+
Map<String, CompilationUnit> compilationUnits = new HashMap<>();
132+
final String baseClassName = "opencv_core";
133+
134+
OpenCVEnumVisitor enumVisitor = new OpenCVEnumVisitor(baseClassName, collector);
135+
enumVisitor.visit(coreDeclaration, compilationUnits);
136+
compilationUnits.putAll(enumVisitor.generateCompilationUnits());
137+
138+
return compilationUnits;
139+
}
140+
141+
public static void main(String... args) {
142+
FileParser.generateAllSourceCode();
143+
}
139144
}

0 commit comments

Comments
 (0)