Skip to content

Commit 68db74f

Browse files
author
Rohit Agarwal
committed
Add maven-checkstyle-plugin and fix some violations.
1 parent 5a94279 commit 68db74f

23 files changed

+228
-102
lines changed

checkstyle.xml

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
4+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
5+
6+
<!--
7+
8+
Checkstyle configuration from
9+
https://github.com/checkstyle/checkstyle/blob/checkstyle-6.1.1/sun_checks.xml
10+
11+
Removed some checks which had a lot of existing violations. :-(
12+
13+
-->
14+
15+
<module name="Checker">
16+
<!--
17+
If you set the basedir property below, then all reported file
18+
names will be relative to the specified directory. See
19+
http://checkstyle.sourceforge.net/5.x/config.html#Checker
20+
21+
<property name="basedir" value="${basedir}"/>
22+
-->
23+
24+
<!-- Checks whether files end with a new line. -->
25+
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
26+
<module name="NewlineAtEndOfFile"/>
27+
28+
<!-- Checks that property files contain the same keys. -->
29+
<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
30+
<module name="Translation"/>
31+
32+
<!-- Checks for Size Violations. -->
33+
<!-- See http://checkstyle.sf.net/config_sizes.html -->
34+
<module name="FileLength"/>
35+
36+
<!-- Checks for whitespace -->
37+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
38+
<module name="FileTabCharacter"/>
39+
40+
<!-- Miscellaneous other checks. -->
41+
<!-- See http://checkstyle.sf.net/config_misc.html -->
42+
<module name="RegexpSingleline">
43+
<property name="format" value="\s+$"/>
44+
<property name="minimum" value="0"/>
45+
<property name="maximum" value="0"/>
46+
<property name="message" value="Line has trailing spaces."/>
47+
</module>
48+
49+
<module name="TreeWalker">
50+
51+
<!-- Checks for Naming Conventions. -->
52+
<!-- See http://checkstyle.sf.net/config_naming.html -->
53+
<module name="ConstantName"/>
54+
<module name="LocalFinalVariableName"/>
55+
<module name="LocalVariableName"/>
56+
<module name="PackageName"/>
57+
<module name="StaticVariableName"/>
58+
59+
<!-- Checks for imports -->
60+
<!-- See http://checkstyle.sf.net/config_import.html -->
61+
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
62+
<module name="RedundantImport"/>
63+
<module name="UnusedImports"/>
64+
65+
<!-- Checks for Size Violations. -->
66+
<!-- See http://checkstyle.sf.net/config_sizes.html -->
67+
<module name="MethodLength"/>
68+
69+
<!-- Checks for whitespace -->
70+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
71+
<module name="EmptyForIteratorPad"/>
72+
<module name="GenericWhitespace"/>
73+
<module name="MethodParamPad"/>
74+
<module name="NoWhitespaceAfter"/>
75+
<module name="NoWhitespaceBefore"/>
76+
<module name="OperatorWrap"/>
77+
<module name="ParenPad"/>
78+
<module name="TypecastParenPad"/>
79+
<module name="WhitespaceAfter"/>
80+
81+
<!-- Modifier Checks -->
82+
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
83+
<module name="ModifierOrder"/>
84+
85+
<!-- Checks for blocks. You know, those {}'s -->
86+
<!-- See http://checkstyle.sf.net/config_blocks.html -->
87+
<module name="AvoidNestedBlocks"/>
88+
<module name="NeedBraces"/>
89+
90+
<!-- Checks for common coding problems -->
91+
<!-- See http://checkstyle.sf.net/config_coding.html -->
92+
<module name="EmptyStatement"/>
93+
<module name="EqualsHashCode"/>
94+
<module name="IllegalInstantiation"/>
95+
<module name="InnerAssignment"/>
96+
<module name="MissingSwitchDefault"/>
97+
<module name="RedundantThrows"/>
98+
<module name="SimplifyBooleanExpression"/>
99+
<module name="SimplifyBooleanReturn"/>
100+
101+
<!-- Checks for class design -->
102+
<!-- See http://checkstyle.sf.net/config_design.html -->
103+
<module name="HideUtilityClassConstructor"/>
104+
<module name="InterfaceIsType"/>
105+
106+
<!-- Miscellaneous other checks. -->
107+
<!-- See http://checkstyle.sf.net/config_misc.html -->
108+
<module name="ArrayTypeStyle"/>
109+
<module name="TodoComment"/>
110+
<module name="UpperEll"/>
111+
112+
</module>
113+
114+
</module>

pom.xml

+17
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@
107107
<target>1.6</target>
108108
</configuration>
109109
</plugin>
110+
<plugin>
111+
<groupId>org.apache.maven.plugins</groupId>
112+
<artifactId>maven-checkstyle-plugin</artifactId>
113+
<version>2.15</version>
114+
<executions>
115+
<execution>
116+
<id>checkstyle</id>
117+
<phase>validate</phase>
118+
<goals>
119+
<goal>check</goal>
120+
</goals>
121+
<configuration>
122+
<configLocation>checkstyle.xml</configLocation>
123+
</configuration>
124+
</execution>
125+
</executions>
126+
</plugin>
110127
</plugins>
111128
<resources>
112129
<resource>

src/main/java/com/qubole/qds/sdk/java/api/DbSimpleImportCommandBuilder.java

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package com.qubole.qds.sdk.java.api;
1717

1818
import com.qubole.qds.sdk.java.entities.CommandResponse;
19-
import java.util.Map;
2019

2120
public interface DbSimpleImportCommandBuilder extends InvokableBuilder<CommandResponse>
2221
{

src/main/java/com/qubole/qds/sdk/java/api/ShellCommandBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ public interface ShellCommandBuilder extends InvokableBuilder<CommandResponse>
3636
public ShellCommandBuilder tags(String[] queryTags);
3737

3838
public BaseCommand build();
39-
}
39+
}

src/main/java/com/qubole/qds/sdk/java/client/DefaultQdsConfiguration.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public class DefaultQdsConfiguration implements QdsConfiguration
4343
public static final String API_ENDPOINT = "https://api.qubole.com/api";
4444
public static final String API_VERSION = "v1.2";
4545

46-
private static final int DEFAULT_CONNECTION_TIMEOUT = (int)TimeUnit.SECONDS.toMillis(10);
47-
private static final int DEFAULT_READ_TIMEOUT = (int)TimeUnit.SECONDS.toMillis(30);
46+
private static final int DEFAULT_CONNECTION_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10);
47+
private static final int DEFAULT_READ_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(30);
4848

4949
/**
5050
* @param apiToken your API token
@@ -103,7 +103,7 @@ public DefaultQdsConfiguration(String apiEndpoint, String apiToken, ClientConfig
103103
this.apiEndpoint = Preconditions.checkNotNull(apiEndpoint, "apiEndpoint cannot be null");
104104
this.apiToken = Preconditions.checkNotNull(apiToken, "apiToken cannot be null");
105105

106-
if ( jerseyConfiguration == null )
106+
if (jerseyConfiguration == null)
107107
{
108108
jerseyConfiguration = new ClientConfig();
109109
jerseyConfiguration.property(ClientProperties.CONNECT_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);

src/main/java/com/qubole/qds/sdk/java/client/ResultLatch.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public class ResultLatch
3535
private final String queryId;
3636
private final AtomicLong pollMs = new AtomicLong(DEFAULT_POLL_MS);
3737

38-
private static final ExecutorService executorService = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("ResultLatch-%d").setDaemon(true).build());
38+
private static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("ResultLatch-%d").setDaemon(true).build());
3939

40-
private static final Logger log = Logger.getLogger(ResultLatch.class.getName());
40+
private static final Logger LOG = Logger.getLogger(ResultLatch.class.getName());
4141

4242
private static final int DEFAULT_POLL_MS = 5000;
4343
private static final int MIN_POLL_MS = 1000;
@@ -74,9 +74,9 @@ public ResultLatch(QdsClient client, String queryId)
7474
*/
7575
public void setPollSleep(long time, TimeUnit unit)
7676
{
77-
if ( unit.toMillis(time) < MIN_POLL_MS )
77+
if (unit.toMillis(time) < MIN_POLL_MS)
7878
{
79-
log.warning(String.format("Poll interval cannot be less than %d seconds. Setting it to %d seconds.", TimeUnit.MILLISECONDS.toSeconds(MIN_POLL_MS), TimeUnit.MILLISECONDS.toSeconds(MIN_POLL_MS)));
79+
LOG.warning(String.format("Poll interval cannot be less than %d seconds. Setting it to %d seconds.", TimeUnit.MILLISECONDS.toSeconds(MIN_POLL_MS), TimeUnit.MILLISECONDS.toSeconds(MIN_POLL_MS)));
8080
pollMs.set(MIN_POLL_MS);
8181
}
8282
else
@@ -126,13 +126,13 @@ public void run()
126126
{
127127
callback.result(queryId, awaitResult());
128128
}
129-
catch ( Exception e )
129+
catch (Exception e)
130130
{
131131
callback.error(queryId, e);
132132
}
133133
}
134134
};
135-
executorService.submit(runnable);
135+
EXECUTOR_SERVICE.submit(runnable);
136136
}
137137

138138
/**
@@ -157,22 +157,22 @@ public boolean await(long maxWait, TimeUnit timeUnit) throws Exception
157157
{
158158
boolean hasWait = (timeUnit != null);
159159
long startMs = System.currentTimeMillis();
160-
for(;;)
160+
for (;;)
161161
{
162162
String status = client.command().status(queryId).invoke().get().getStatus();
163-
if ( status.equalsIgnoreCase(STATUS_DONE) )
163+
if (status.equalsIgnoreCase(STATUS_DONE))
164164
{
165165
break;
166166
}
167-
if ( !status.equalsIgnoreCase(STATUS_RUNNING) && !status.equalsIgnoreCase(STATUS_WAITING) )
167+
if (!status.equalsIgnoreCase(STATUS_RUNNING) && !status.equalsIgnoreCase(STATUS_WAITING))
168168
{
169169
throw new Exception(String.format("Bad status for query %s: %s", queryId, status));
170170
}
171171

172-
if ( hasWait )
172+
if (hasWait)
173173
{
174174
long elapsedMs = System.currentTimeMillis() - startMs;
175-
if ( elapsedMs >= timeUnit.toMillis(maxWait) )
175+
if (elapsedMs >= timeUnit.toMillis(maxWait))
176176
{
177177
return false;
178178
}
@@ -204,7 +204,7 @@ public ResultValue awaitResult() throws Exception
204204
*/
205205
public ResultValue awaitResult(long maxWait, TimeUnit timeUnit) throws Exception
206206
{
207-
if ( !await(maxWait, timeUnit) )
207+
if (!await(maxWait, timeUnit))
208208
{
209209
throw new TimeoutException();
210210
}

src/main/java/com/qubole/qds/sdk/java/client/ResultStreamer.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public ResultStreamer(QdsClient client)
7474
*/
7575
public Reader getResults(ResultValue resultValue) throws Exception
7676
{
77-
if ( resultValue.isInline() )
77+
if (resultValue.isInline())
7878
{
7979
return new StringReader(resultValue.getResults());
8080
}
@@ -85,7 +85,7 @@ public Reader getResults(ResultValue resultValue) throws Exception
8585
@Override
8686
public synchronized void close()
8787
{
88-
if ( s3Client != null )
88+
if (s3Client != null)
8989
{
9090
s3Client.shutdown();
9191
s3Client = null;
@@ -94,7 +94,7 @@ public synchronized void close()
9494

9595
private synchronized void ensureClient() throws Exception
9696
{
97-
if ( s3Client != null )
97+
if (s3Client != null)
9898
{
9999
return;
100100
}
@@ -158,18 +158,18 @@ public PathReader(List<String> paths)
158158
@Override
159159
public int read(char[] cbuf, int off, int len) throws IOException
160160
{
161-
if ( currentReader == null )
161+
if (currentReader == null)
162162
{
163163
loadNextReader();
164164
}
165165

166-
if ( currentReader == null )
166+
if (currentReader == null)
167167
{
168168
return -1;
169169
}
170170

171171
int count = currentReader.read(cbuf, off, len);
172-
if ( count < 0 )
172+
if (count < 0)
173173
{
174174
currentReader.close();
175175
currentReader = null;
@@ -180,17 +180,17 @@ public int read(char[] cbuf, int off, int len) throws IOException
180180

181181
private void loadNextReader()
182182
{
183-
if ( pathIterator.hasNext() )
183+
if (pathIterator.hasNext())
184184
{
185185
String path = pathIterator.next();
186186

187-
if ( path.startsWith(S3_PREFIX) )
187+
if (path.startsWith(S3_PREFIX))
188188
{
189189
path = path.substring(S3_PREFIX.length());
190190
}
191191

192192
int slashIndex = path.indexOf("/");
193-
if ( (slashIndex < 0) || (slashIndex == (path.length() - 1)) )
193+
if ((slashIndex < 0) || (slashIndex == (path.length() - 1)))
194194
{
195195
// error? don't know what to do
196196
loadNextReader();
@@ -199,13 +199,13 @@ private void loadNextReader()
199199
String bucket = path.substring(0, slashIndex);
200200
String key = path.substring(slashIndex + 1);
201201

202-
if ( key.endsWith("/") )
202+
if (key.endsWith("/"))
203203
{
204204
ObjectListing objectListing = s3Client.listObjects(new ListObjectsRequest().withBucketName(bucket).withPrefix(key));
205205
List<String> paths = Lists.newArrayList();
206-
for ( S3ObjectSummary summary : objectListing.getObjectSummaries() )
206+
for (S3ObjectSummary summary : objectListing.getObjectSummaries())
207207
{
208-
if ( !summary.getKey().equals(key) && (summary.getSize() > 0) )
208+
if (!summary.getKey().equals(key) && (summary.getSize() > 0))
209209
{
210210
paths.add(summary.getBucketName() + "/" + summary.getKey());
211211
}

0 commit comments

Comments
 (0)