Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit f1c6a7b

Browse files
authored
Merge pull request #266 from loveleif/1.1-code-style
Introduce codestyle
2 parents 58f8738 + 852a849 commit f1c6a7b

File tree

112 files changed

+8322
-4623
lines changed

Some content is hidden

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

112 files changed

+8322
-4623
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ buildscript {
1111

1212
allprojects {
1313
apply plugin: 'java'
14+
apply plugin: 'checkstyle'
1415

1516
sourceCompatibility = 1.8
1617
targetCompatibility = 1.8

config/checkstyle/checkstyle.xml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
4+
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
5+
6+
<module name="Checker">
7+
8+
<property name="charset" value="UTF-8"/>
9+
<property name="fileExtensions" value="java"/>
10+
11+
<!-- Require license headers (GPL, AGPL or Apache 2.0) -->
12+
<module name="RegexpSingleline">
13+
<property name="format"
14+
value="^(\s|\*)*Copyright \(c\) 2002-[0-9]{4} &quot;Neo4j,&quot;"/>
15+
<property name="minimum" value="1"/>
16+
<property name="maximum" value="1"/>
17+
<property name="message" value="Missing, wrong or duplicated license header"/>
18+
</module>
19+
20+
<!-- Prohibit tabs -->
21+
<module name="FileTabCharacter">
22+
<property name="eachLine" value="true"/>
23+
</module>
24+
25+
<!-- Require new line at the end of file -->
26+
<module name="NewlineAtEndOfFile">
27+
<property name="lineSeparator" value="lf_cr_crlf" />
28+
</module>
29+
30+
<!-- Prohibit trailing spaces -->
31+
<module name="RegexpSingleline">
32+
<property name="format" value="\s+$"/>
33+
<property name="minimum" value="0"/>
34+
<property name="maximum" value="0"/>
35+
<property name="message" value="Line has trailing spaces."/>
36+
</module>
37+
38+
<!-- Prohibit consecutive empty lines (except the lines after package/import) -->
39+
<module name="RegexpMultiline">
40+
<property name="format" value="\n *(?!package )(?!import )[^\n]+\n{3,}"/>
41+
<property name="message" value="Two or more consecutive empty lines"/>
42+
</module>
43+
44+
<module name="LineLength">
45+
<property name="fileExtensions" value="java" />
46+
<property name="max" value="160"/>
47+
<property name="ignorePattern" value="a href|href|http://|https://"/>
48+
</module>
49+
50+
<module name="TreeWalker">
51+
52+
<module name="PackageDeclaration"/>
53+
<module name="UpperEll"/>
54+
<module name="ArrayTypeStyle"/>
55+
<module name="MissingOverride"/>
56+
<module name="EmptyStatement"/>
57+
<module name="SuperFinalize"/>
58+
<module name="EqualsHashCode"/>
59+
<module name="ModifierOrder"/>
60+
<module name="RedundantImport"/>
61+
<module name="MissingSwitchDefault"/>
62+
<module name="DefaultComesLast"/>
63+
<module name="MethodParamPad"/>
64+
<module name="TypecastParenPad"/>
65+
<module name="EmptyCatchBlock">
66+
<property name="exceptionVariableName" value="ignore|ignored"/>
67+
</module>
68+
<module name="AnnotationLocation">
69+
<property name="allowSamelineMultipleAnnotations" value="false"/>
70+
<property name="allowSamelineSingleParameterlessAnnotation" value="false"/>
71+
<property name="allowSamelineParameterizedAnnotation" value="false"/>
72+
</module>
73+
<module name="UnnecessaryParentheses"/>
74+
<module name="LeftCurly">
75+
<property name="option" value="nl"/>
76+
<property name="tokens" value="INTERFACE_DEF, CLASS_DEF, ANNOTATION_DEF, ENUM_DEF, CTOR_DEF, METHOD_DEF, ENUM_CONSTANT_DEF, LITERAL_WHILE, LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_SYNCHRONIZED, LITERAL_SWITCH, LITERAL_DO, LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, STATIC_INIT, OBJBLOCK"/>
77+
</module>
78+
<module name="RightCurly">
79+
<property name="option" value="alone"/>
80+
</module>
81+
<module name="NeedBraces"/>
82+
<module name="RedundantModifier"/>
83+
<module name="WhitespaceAround">
84+
<property name="allowEmptyConstructors" value="true"/>
85+
<property name="allowEmptyLambdas" value="true"/>
86+
<property name="allowEmptyMethods" value="true"/>
87+
</module>
88+
<module name="OneStatementPerLine">
89+
<property name="treatTryResourcesAsStatement" value="true"/>
90+
</module>
91+
<module name="ParenPad">
92+
<property name="tokens"
93+
value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, ENUM_CONSTANT_DEF, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA, METHOD_DEF"/>
94+
<property name="option" value="space"/>
95+
</module>
96+
<module name="AvoidStarImport"/>
97+
<module name="GenericWhitespace"/>
98+
<module name="ExplicitInitialization"/>
99+
100+
<!-- Included in mono repo but not worth it to introduce here at this moment
101+
<module name="IllegalImport">
102+
<property name="illegalPkgs" value="junit.framework"/>
103+
</module>
104+
-->
105+
106+
<module name="LocalVariableName">
107+
<property name="allowOneCharVarInForLoop" value="true"/>
108+
</module>
109+
</module>
110+
111+
</module>

cypher-shell/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ dependencies {
6868
testCompile "org.mockito:mockito-core:$mockitoVersion"
6969
testCompileOnly "com.google.code.findbugs:annotations:$findbugsVersion"
7070
}
71+
72+
checkstyle {
73+
toolVersion = '8.35'
74+
}
Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
1+
/*
2+
* Copyright (c) 2002-2020 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
120
package org.neo4j.shell;
221

322
import org.junit.Before;
423
import org.junit.Test;
5-
import org.neo4j.shell.cli.CliArgs;
6-
import org.neo4j.shell.log.AnsiLogger;
7-
import org.neo4j.shell.log.Logger;
8-
import org.neo4j.shell.prettyprint.PrettyConfig;
924

1025
import java.io.ByteArrayInputStream;
1126
import java.io.ByteArrayOutputStream;
1227
import java.io.InputStream;
1328
import java.io.PrintStream;
1429

30+
import org.neo4j.shell.cli.CliArgs;
31+
import org.neo4j.shell.log.AnsiLogger;
32+
import org.neo4j.shell.log.Logger;
33+
import org.neo4j.shell.prettyprint.PrettyConfig;
34+
1535
import static org.junit.Assert.assertEquals;
1636
import static org.junit.Assert.assertTrue;
1737

18-
public class MainIntegrationTest {
38+
public class MainIntegrationTest
39+
{
1940

2041
private String inputString = String.format( "neo4j%nneo%n" );
2142
private ByteArrayOutputStream baos;
@@ -26,82 +47,87 @@ public class MainIntegrationTest {
2647
private InputStream inputStream;
2748

2849
@Before
29-
public void setup() {
50+
public void setup()
51+
{
3052
// given
31-
inputStream = new ByteArrayInputStream(inputString.getBytes());
53+
inputStream = new ByteArrayInputStream( inputString.getBytes() );
3254

3355
baos = new ByteArrayOutputStream();
34-
printStream = new PrintStream(baos);
56+
printStream = new PrintStream( baos );
3557

36-
main = new Main(inputStream, printStream);
58+
main = new Main( inputStream, printStream );
3759

3860
CliArgs cliArgs = new CliArgs();
39-
cliArgs.setUsername("", "");
40-
cliArgs.setPassword("", "");
61+
cliArgs.setUsername( "", "" );
62+
cliArgs.setPassword( "", "" );
4163

42-
Logger logger = new AnsiLogger(cliArgs.getDebugMode());
43-
PrettyConfig prettyConfig = new PrettyConfig(cliArgs);
64+
Logger logger = new AnsiLogger( cliArgs.getDebugMode() );
65+
PrettyConfig prettyConfig = new PrettyConfig( cliArgs );
4466
connectionConfig = new ConnectionConfig(
4567
cliArgs.getScheme(),
4668
cliArgs.getHost(),
4769
cliArgs.getPort(),
4870
cliArgs.getUsername(),
4971
cliArgs.getPassword(),
50-
cliArgs.getEncryption());
72+
cliArgs.getEncryption() );
5173

52-
shell = new CypherShell(logger, prettyConfig);
74+
shell = new CypherShell( logger, prettyConfig );
5375
}
5476

55-
5677
@Test
57-
public void promptsOnWrongAuthenticationIfInteractive() throws Exception {
78+
public void promptsOnWrongAuthenticationIfInteractive() throws Exception
79+
{
5880
// when
59-
assertEquals("", connectionConfig.username());
60-
assertEquals("", connectionConfig.password());
81+
assertEquals( "", connectionConfig.username() );
82+
assertEquals( "", connectionConfig.password() );
6183

62-
main.connectMaybeInteractively(shell, connectionConfig, true, true);
84+
main.connectMaybeInteractively( shell, connectionConfig, true, true );
6385

6486
// then
6587
// should be connected
66-
assertTrue(shell.isConnected());
88+
assertTrue( shell.isConnected() );
6789
// should have prompted and set the username and password
68-
assertEquals("neo4j", connectionConfig.username());
69-
assertEquals("neo", connectionConfig.password());
90+
assertEquals( "neo4j", connectionConfig.username() );
91+
assertEquals( "neo", connectionConfig.password() );
7092

7193
String out = baos.toString();
72-
assertEquals(String.format( "username: neo4j%npassword: ***%n" ), out);
94+
assertEquals( String.format( "username: neo4j%npassword: ***%n" ), out );
7395
}
7496

7597
@Test
76-
public void doesNotPromptToStdOutOnWrongAuthenticationIfOutputRedirected() throws Exception {
98+
public void doesNotPromptToStdOutOnWrongAuthenticationIfOutputRedirected() throws Exception
99+
{
77100
// when
78-
assertEquals("", connectionConfig.username());
79-
assertEquals("", connectionConfig.password());
101+
assertEquals( "", connectionConfig.username() );
102+
assertEquals( "", connectionConfig.password() );
80103

81104
// Redirect System.in and System.out
82105
InputStream stdIn = System.in;
83106
PrintStream stdOut = System.out;
84-
System.setIn(inputStream);
85-
System.setOut(printStream);
107+
System.setIn( inputStream );
108+
System.setOut( printStream );
86109

87110
// Create a Main with the standard in and out
88-
try {
111+
try
112+
{
89113
Main realMain = new Main();
90-
realMain.connectMaybeInteractively(shell, connectionConfig, true, false);
114+
realMain.connectMaybeInteractively( shell, connectionConfig, true, false );
91115

92116
// then
93117
// should be connected
94-
assertTrue(shell.isConnected());
118+
assertTrue( shell.isConnected() );
95119
// should have prompted silently and set the username and password
96-
assertEquals("neo4j", connectionConfig.username());
97-
assertEquals("neo", connectionConfig.password());
120+
assertEquals( "neo4j", connectionConfig.username() );
121+
assertEquals( "neo", connectionConfig.password() );
98122

99123
String out = baos.toString();
100-
assertEquals("", out);
101-
} finally {
124+
assertEquals( "", out );
125+
}
126+
finally
127+
{
102128
// Restore in and out
103-
System.setIn(stdIn);
104-
System.setOut(stdOut);
129+
System.setIn( stdIn );
130+
System.setOut( stdOut );
105131
}
106132
}
107133
}
Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
1+
/*
2+
* Copyright (c) 2002-2020 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
120
package org.neo4j.shell;
221

322
import org.neo4j.shell.prettyprint.LinePrinter;
423
import org.neo4j.shell.prettyprint.OutputFormatter;
524

6-
public class StringLinePrinter implements LinePrinter {
25+
public class StringLinePrinter implements LinePrinter
26+
{
727

828
private StringBuilder sb = new StringBuilder();
929

1030
@Override
11-
public void printOut(String line) {
12-
sb.append(line).append(OutputFormatter.NEWLINE);
31+
public void printOut( String line )
32+
{
33+
sb.append( line ).append( OutputFormatter.NEWLINE );
1334
}
1435

15-
public void clear() {
16-
sb.setLength(0);
36+
public void clear()
37+
{
38+
sb.setLength( 0 );
1739
}
1840

19-
public String output() {
41+
public String output()
42+
{
2043
return sb.toString();
2144
}
2245
}

0 commit comments

Comments
 (0)