Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aozarov committed Jan 5, 2015
1 parent bf4f035 commit e7ce4ea
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 62 deletions.
2 changes: 1 addition & 1 deletion RobustaSettings.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<RobustaSettings><ProjectDetect FolderName="java" enable="true" /><ProjectDetect FolderName="resources" enable="true" /></RobustaSettings>
<RobustaSettings><ProjectDetect FolderName="java" enable="true" /><ProjectDetect FolderName="resources" enable="false" /></RobustaSettings>
48 changes: 15 additions & 33 deletions pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@
<description>PMD Plugin preferences rule set</description>
<rule ref="rulesets/java/design.xml/AbstractClassWithoutAbstractMethod"/>
<rule ref="rulesets/java/design.xml/AbstractClassWithoutAnyMethod"/>
<rule ref="rulesets/java/naming.xml/AbstractNaming"/>
<rule ref="rulesets/java/design.xml/AccessorClassGeneration"/>
<rule ref="rulesets/java/optimizations.xml/AddEmptyString"/>
<rule ref="rulesets/java/strings.xml/AppendCharacterWithChar"/>
<rule ref="rulesets/java/sunsecure.xml/ArrayIsStoredDirectly"/>
<rule ref="rulesets/ecmascript/basic.xml/AssignmentInOperand"/>
<rule ref="rulesets/java/controversial.xml/AssignmentInOperand"/>
<rule ref="rulesets/java/design.xml/AssignmentToNonFinalStatic"/>
<rule ref="rulesets/java/controversial.xml/AtLeastOneConstructor"/>
<rule ref="rulesets/java/controversial.xml/AvoidAccessibilityAlteration"/>
<rule ref="rulesets/java/optimizations.xml/AvoidArrayLoops"/>
<rule ref="rulesets/java/migrating.xml/AvoidAssertAsIdentifier"/>
<rule ref="rulesets/xsl/xpath.xml/AvoidAxisNavigation"/>
<rule ref="rulesets/java/basic.xml/AvoidBranchingStatementAsLastInLoop"/>
<rule ref="rulesets/java/finalizers.xml/AvoidCallingFinalize"/>
<rule ref="rulesets/java/strictexception.xml/AvoidCatchingGenericException"/>
<rule ref="rulesets/java/strictexception.xml/AvoidCatchingNPE"/>
<rule ref="rulesets/java/strictexception.xml/AvoidCatchingThrowable"/>
<rule ref="rulesets/java/design.xml/AvoidConstantsInterface"/>
Expand All @@ -31,12 +25,9 @@
<rule ref="rulesets/java/naming.xml/AvoidDollarSigns"/>
<rule ref="rulesets/java/strings.xml/AvoidDuplicateLiterals"/>
<rule ref="rulesets/java/migrating.xml/AvoidEnumAsIdentifier"/>
<rule ref="rulesets/java/naming.xml/AvoidFieldNameMatchingMethodName"/>
<rule ref="rulesets/java/naming.xml/AvoidFieldNameMatchingTypeName"/>
<rule ref="rulesets/java/controversial.xml/AvoidFinalLocalVariable"/>
<rule ref="rulesets/java/design.xml/AvoidInstanceofChecksInCatchClause"/>
<rule ref="rulesets/java/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>
<rule ref="rulesets/java/controversial.xml/AvoidLiteralsInIfCondition"/>
<rule ref="rulesets/java/strictexception.xml/AvoidLosingExceptionInformation"/>
<rule ref="rulesets/java/basic.xml/AvoidMultipleUnaryOperators"/>
<rule ref="rulesets/java/controversial.xml/AvoidPrefixingMethodParameters"/>
Expand All @@ -59,15 +50,13 @@
<rule ref="rulesets/java/controversial.xml/AvoidUsingShortType"/>
<rule ref="rulesets/java/controversial.xml/AvoidUsingVolatile"/>
<rule ref="rulesets/java/design.xml/BadComparison"/>
<rule ref="rulesets/java/javabeans.xml/BeanMembersShouldSerialize"/>
<rule ref="rulesets/java/basic.xml/BigIntegerInstantiation"/>
<rule ref="rulesets/java/naming.xml/BooleanGetMethodName"/>
<rule ref="rulesets/java/basic.xml/BooleanInstantiation"/>
<rule ref="rulesets/java/controversial.xml/BooleanInversion"/>
<rule ref="rulesets/java/basic.xml/BrokenNullCheck"/>
<rule ref="rulesets/java/migrating.xml/ByteInstantiation"/>
<rule ref="rulesets/java/android.xml/CallSuperFirst"/>
<rule ref="rulesets/java/controversial.xml/CallSuperInConstructor"/>
<rule ref="rulesets/java/android.xml/CallSuperLast"/>
<rule ref="rulesets/java/basic.xml/CheckResultSet"/>
<rule ref="rulesets/java/basic.xml/CheckSkipResult"/>
Expand All @@ -80,19 +69,24 @@
<rule ref="rulesets/java/basic.xml/CollapsibleIfStatements"/>
<rule ref="rulesets/vm/basic.xml/CollapsibleIfStatements"/>
<rule ref="rulesets/java/comments.xml/CommentContent"/>
<rule ref="rulesets/java/comments.xml/CommentSize"/>
<rule ref="rulesets/java/comments.xml/CommentSize">
<properties>
<property name="maxLineLength" value="100"/>
</properties>
</rule>
<rule ref="rulesets/java/design.xml/CompareObjectsWithEquals"/>
<rule ref="rulesets/java/design.xml/ConfusingTernary"/>
<rule ref="rulesets/java/strings.xml/ConsecutiveAppendsShouldReuse"/>
<rule ref="rulesets/java/strings.xml/ConsecutiveLiteralAppends"/>
<rule ref="rulesets/ecmascript/basic.xml/ConsistentReturn"/>
<rule ref="rulesets/java/design.xml/ConstructorCallsOverridableMethod"/>
<rule ref="rulesets/java/coupling.xml/CouplingBetweenObjects"/>
<rule ref="rulesets/plsql/codesize.xml/CyclomaticComplexity"/>
<rule ref="rulesets/plsql/codesize.xml/CyclomaticComplexity">
<properties>
<property name="reportLevel" value="14"/>
</properties>
</rule>
<rule ref="rulesets/java/codesize.xml/CyclomaticComplexity"/>
<rule ref="rulesets/java/controversial.xml/DataflowAnomalyAnalysis"/>
<rule ref="rulesets/java/design.xml/DefaultLabelNotLastInSwitchStmt"/>
<rule ref="rulesets/java/controversial.xml/DefaultPackage"/>
<rule ref="rulesets/java/controversial.xml/DoNotCallGarbageCollectionExplicitly"/>
<rule ref="rulesets/java/j2ee.xml/DoNotCallSystemExit"/>
<rule ref="rulesets/java/strictexception.xml/DoNotExtendJavaLangError"/>
Expand All @@ -107,7 +101,6 @@
<rule ref="rulesets/java/basic.xml/DoubleCheckedLocking"/>
<rule ref="rulesets/java/imports.xml/DuplicateImports"/>
<rule ref="rulesets/jsp/basic.xml/DuplicateJspImports"/>
<rule ref="rulesets/java/empty.xml/EmptyCatchBlock"/>
<rule ref="rulesets/java/finalizers.xml/EmptyFinalizer"/>
<rule ref="rulesets/java/empty.xml/EmptyFinallyBlock"/>
<rule ref="rulesets/vm/basic.xml/EmptyForeachStmt"/>
Expand Down Expand Up @@ -149,10 +142,8 @@
<rule ref="rulesets/ecmascript/braces.xml/ForLoopsMustUseBraces"/>
<rule ref="rulesets/java/naming.xml/GenericsNaming"/>
<rule ref="rulesets/ecmascript/basic.xml/GlobalVariable"/>
<rule ref="rulesets/java/design.xml/GodClass"/>
<rule ref="rulesets/java/logging-jakarta-commons.xml/GuardDebugLogging"/>
<rule ref="rulesets/java/logging-jakarta-commons.xml/GuardLogStatement"/>
<rule ref="rulesets/java/logging-java.xml/GuardLogStatementJavaUtil"/>
<rule ref="rulesets/java/design.xml/IdempotentOperations"/>
<rule ref="rulesets/java/braces.xml/IfElseStmtsMustUseBraces"/>
<rule ref="rulesets/ecmascript/braces.xml/IfElseStmtsMustUseBraces"/>
Expand All @@ -171,25 +162,20 @@
<rule ref="rulesets/java/migrating.xml/JUnit4TestShouldUseAfterAnnotation"/>
<rule ref="rulesets/java/migrating.xml/JUnit4TestShouldUseBeforeAnnotation"/>
<rule ref="rulesets/java/migrating.xml/JUnit4TestShouldUseTestAnnotation"/>
<rule ref="rulesets/java/junit.xml/JUnitAssertionsShouldIncludeMessage"/>
<rule ref="rulesets/java/junit.xml/JUnitSpelling"/>
<rule ref="rulesets/java/junit.xml/JUnitStaticSuite"/>
<rule ref="rulesets/java/junit.xml/JUnitTestContainsTooManyAsserts"/>
<rule ref="rulesets/java/junit.xml/JUnitTestsShouldIncludeAssert"/>
<rule ref="rulesets/java/migrating.xml/JUnitUseExpected"/>
<rule ref="rulesets/jsp/basic.xml/JspEncoding"/>
<rule ref="rulesets/java/basic.xml/JumbledIncrementer"/>
<rule ref="rulesets/java/coupling.xml/LawOfDemeter"/>
<rule ref="rulesets/java/j2ee.xml/LocalHomeNamingConvention"/>
<rule ref="rulesets/java/j2ee.xml/LocalInterfaceSessionNamingConvention"/>
<rule ref="rulesets/java/logging-java.xml/LoggerIsNotStaticFinal"/>
<rule ref="rulesets/java/design.xml/LogicInversion"/>
<rule ref="rulesets/java/migrating.xml/LongInstantiation"/>
<rule ref="rulesets/java/naming.xml/LongVariable"/>
<rule ref="rulesets/java/coupling.xml/LooseCoupling"/>
<rule ref="rulesets/java/coupling.xml/LoosePackageCoupling"/>
<rule ref="rulesets/java/j2ee.xml/MDBAndSessionBeanNamingConvention"/>
<rule ref="rulesets/java/optimizations.xml/MethodArgumentCouldBeFinal"/>
<rule ref="rulesets/java/naming.xml/MethodNamingConventions"/>
<rule ref="rulesets/java/sunsecure.xml/MethodReturnsInternalArray"/>
<rule ref="rulesets/java/naming.xml/MethodWithSameNameAsEnclosingClass"/>
Expand Down Expand Up @@ -222,9 +208,7 @@
<rule ref="rulesets/java/design.xml/NonCaseLabelInSwitchStatement"/>
<rule ref="rulesets/java/design.xml/NonStaticInitializer"/>
<rule ref="rulesets/java/design.xml/NonThreadSafeSingleton"/>
<rule ref="rulesets/java/controversial.xml/NullAssignment"/>
<rule ref="rulesets/java/controversial.xml/OneDeclarationPerLine"/>
<rule ref="rulesets/java/controversial.xml/OnlyOneReturn"/>
<rule ref="rulesets/java/design.xml/OptimizableToArrayCall"/>
<rule ref="rulesets/java/basic.xml/OverrideBothEqualsAndHashcode"/>
<rule ref="rulesets/java/naming.xml/PackageCase"/>
Expand All @@ -243,10 +227,13 @@
<rule ref="rulesets/java/design.xml/ReturnEmptyArrayRatherThanNull"/>
<rule ref="rulesets/java/basic.xml/ReturnFromFinallyBlock"/>
<rule ref="rulesets/ecmascript/basic.xml/ScopeForInVariable"/>
<rule ref="rulesets/java/naming.xml/ShortClassName"/>
<rule ref="rulesets/java/naming.xml/ShortClassName">
<properties>
<property name="minimum" value="3"/>
</properties>
</rule>
<rule ref="rulesets/java/migrating.xml/ShortInstantiation"/>
<rule ref="rulesets/java/naming.xml/ShortMethodName"/>
<rule ref="rulesets/java/naming.xml/ShortVariable"/>
<rule ref="rulesets/java/strictexception.xml/SignatureDeclareThrowsException"/>
<rule ref="rulesets/java/design.xml/SimpleDateFormatNeedsLocale"/>
<rule ref="rulesets/java/junit.xml/SimplifyBooleanAssertion"/>
Expand Down Expand Up @@ -276,9 +263,6 @@
<rule ref="rulesets/plsql/codesize.xml/TooManyFields"/>
<rule ref="rulesets/java/codesize.xml/TooManyFields"/>
<rule ref="rulesets/plsql/codesize.xml/TooManyMethods"/>
<rule ref="rulesets/java/codesize.xml/TooManyMethods"/>
<rule ref="rulesets/java/imports.xml/TooManyStaticImports"/>
<rule ref="rulesets/java/design.xml/UncommentedEmptyConstructor"/>
<rule ref="rulesets/java/design.xml/UncommentedEmptyMethod"/>
<rule ref="rulesets/java/basic.xml/UnconditionalIfStatement"/>
<rule ref="rulesets/ecmascript/unnecessary.xml/UnnecessaryBlock"/>
Expand Down Expand Up @@ -312,7 +296,6 @@
<rule ref="rulesets/ecmascript/basic.xml/UseBaseWithParseInt"/>
<rule ref="rulesets/java/design.xml/UseCollectionIsEmpty"/>
<rule ref="rulesets/xsl/xpath.xml/UseConcatOnce"/>
<rule ref="rulesets/java/controversial.xml/UseConcurrentHashMap"/>
<rule ref="rulesets/java/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>
<rule ref="rulesets/java/strings.xml/UseEqualsToCompareStrings"/>
<rule ref="rulesets/java/strings.xml/UseIndexOfChar"/>
Expand All @@ -328,7 +311,6 @@
<rule ref="rulesets/java/basic.xml/UselessOverridingMethod"/>
<rule ref="rulesets/java/basic.xml/UselessParentheses"/>
<rule ref="rulesets/java/strings.xml/UselessStringValueOf"/>
<rule ref="rulesets/java/naming.xml/VariableNamingConventions"/>
<rule ref="rulesets/java/braces.xml/WhileLoopsMustUseBraces"/>
<rule ref="rulesets/ecmascript/braces.xml/WhileLoopsMustUseBraces"/>
</ruleset>
19 changes: 10 additions & 9 deletions src/main/java/com/google/gcloud/RetryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import java.util.logging.Logger;

/**
* Utility class for retrying operations. For more details about the parameters, see
* {@link RetryParams}. If the request is never successful, a {@link RetriesExhaustedException} will
* be thrown.
* Utility class for retrying operations.
* For more details about the parameters, see {@link RetryParams}.
* If the request is never successful, a {@link RetriesExhaustedException} will be thrown.
*
* @param <V> return value of the closure that is being run with retries
*/
Expand Down Expand Up @@ -99,8 +99,8 @@ public static final class NonRetriableException extends RetryHelperException {

private static final long serialVersionUID = -2331878521983499652L;

NonRetriableException(Throwable ex) {
super(ex);
NonRetriableException(Throwable throwable) {
super(throwable);
}
}

Expand Down Expand Up @@ -164,12 +164,13 @@ private V doRetry() throws RetryHelperException {
log.fine(this + ": attempt #" + attemptNumber + " succeeded");
}
return value;
} catch (InterruptedException | InterruptedIOException | ClosedByInterruptException e) {
if (!exceptionHandler.shouldRetry(e)) {
RetryInterruptedException.propagate();
}
exception = e;
} catch (Exception e) {
if (!exceptionHandler.shouldRetry(e)) {
if (e instanceof InterruptedException || e instanceof InterruptedIOException
|| e instanceof ClosedByInterruptException) {
RetryInterruptedException.propagate();
}
throw new NonRetriableException(e);
}
exception = e;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/google/gcloud/datastore/Cursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public String toUrlSafe() {
try {
return URLEncoder.encode(toPb().toString(), UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Unxpeced encoding exception", e);
throw new IllegalStateException("Unxpeced encoding exception", e);
}
}

Expand All @@ -77,7 +77,7 @@ public static Cursor fromUrlSafe(String urlSafe) {
String utf8Str = URLDecoder.decode(urlSafe, UTF_8.name());
return fromPb(DatastoreV1.Value.parseFrom(utf8Str.getBytes()));
} catch (UnsupportedEncodingException | InvalidProtocolBufferException e) {
throw new RuntimeException("Unxpeced decoding exception", e);
throw new IllegalStateException("Unxpeced decoding exception", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class Builder extends ServiceOptions.Builder<Builder> {

private String dataset;
private String namespace;
private boolean force = false;
private boolean force;
private Datastore datastore;

private Builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public IsolationLevel(Level level) {
public Level level() {
return level;
}

@Override
BatchWriteOption toBatchWriteOption() {
return null;
}
}

TransactionOption() {
Expand Down Expand Up @@ -89,7 +94,5 @@ static Map<Class<? extends TransactionOption>, TransactionOption> asImmutableMap
return builder.build();
}

BatchWriteOption toBatchWriteOption() {
return null;
}
abstract BatchWriteOption toBatchWriteOption();
}
5 changes: 4 additions & 1 deletion src/main/java/com/google/gcloud/datastore/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
/**
* Utility to validate Datastore type/values.
*/
class Validator {
final class Validator {

private static final Pattern DATASET_PATTERN = Pattern.compile(
"([a-z\\d\\-]{1,100}~)?([a-z\\d][a-z\\d\\-\\.]{0,99}\\:)?([a-z\\d][a-z\\d\\-]{0,99})");
private static final int MAX_NAMESPACE_LENGTH = 100;
private static final Pattern NAMESPACE_PATTERN =
Pattern.compile(String.format("[0-9A-Za-z\\._\\-]{0,%d}", MAX_NAMESPACE_LENGTH));

private Validator() {
// utility class
}

static String validateDataset(String dataset) {
checkArgument(!Strings.isNullOrEmpty(dataset), "dataset can't be empty or null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void start() throws IOException, InterruptedException {
File datasetFolder = new File(gcdFolder, GCD + "/" + dataset);
datasetFolder.delete();

// TODO: When System.getProperty("os.name").startsWith("Windows") use cmd.exe /c and gcd.cmd
// TODO: if System.getProperty("os.name").startsWith("Windows") use cmd.exe /c and gcd.cmd
Process temp = new ProcessBuilder()
.redirectErrorStream(true)
.directory(new File(gcdFolder, GCD))
Expand Down Expand Up @@ -159,7 +159,6 @@ public void stop() throws IOException, InterruptedException {
}
if (gcdPath != null) {
deleteRecurse(gcdPath);
gcdPath = null;
}
}

Expand Down
21 changes: 11 additions & 10 deletions src/test/java/com/google/gcloud/datastore/SerializationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

Expand Down Expand Up @@ -97,7 +98,8 @@ public class SerializationTest {
private static final ProjectionEntity PROJECTION_ENTITY = ProjectionEntity.fromPb(ENTITY1.toPb());

@SuppressWarnings("rawtypes")
private Multimap<Type, Value> typeToValues = ImmutableMultimap.<Type, Value>builder()
private static final Multimap<Type, Value> TYPE_TO_VALUES =
ImmutableMultimap.<Type, Value>builder()
.put(Type.NULL, NULL_VALUE)
.put(Type.KEY, KEY_VALUE)
.put(Type.STRING, STRING_VALUE)
Expand All @@ -115,7 +117,7 @@ public class SerializationTest {
@Test
public void testValues() throws Exception {
for (Type type : Type.values()) {
for (Value<?> value : typeToValues.get(type)) {
for (Value<?> value : TYPE_TO_VALUES.get(type)) {
Value<?> copy = serialiazeAndDeserialize(value);
assertEquals(value, value);
assertEquals(value, copy);
Expand All @@ -141,15 +143,14 @@ public void testTypes() throws Exception {
}

@SuppressWarnings("unchecked")
private <T> T serialiazeAndDeserialize(T obj) throws Exception {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream)) {
objectOutputStream.writeObject(obj);
private <T> T serialiazeAndDeserialize(T obj) throws IOException, ClassNotFoundException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try (ObjectOutputStream output = new ObjectOutputStream(bytes)) {
output.writeObject(obj);
}
byte[] bytes = byteArrayOutputStream.toByteArray();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
try (ObjectInputStream in = new ObjectInputStream(byteArrayInputStream)) {
return (T) in.readObject();
try (ObjectInputStream input =
new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
return (T) input.readObject();
}
}
}

0 comments on commit e7ce4ea

Please sign in to comment.