Skip to content

Commit

Permalink
Excavator: Upgrades Baseline to the latest version (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
svc-excavator-bot authored and bulldozer-bot[bot] committed Oct 28, 2019
1 parent d426dda commit d956c4a
Show file tree
Hide file tree
Showing 22 changed files with 168 additions and 156 deletions.
18 changes: 13 additions & 5 deletions .baseline/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@
<module name="AvoidStarImport"/> <!-- Java Style Guide: No wildcard imports -->
<module name="AvoidStaticImport"> <!-- Java Style Guide: No static imports -->
<property name="excludes" value="
com.google.common.base.Preconditions.*,
com.palantir.logsafe.Preconditions.*,
java.util.Collections.*,
java.util.stream.Collectors.*,
com.palantir.logsafe.Preconditions.*,
com.google.common.base.Preconditions.*,
org.apache.commons.lang3.Validate.*"/>
org.apache.commons.lang3.Validate.*,
org.assertj.core.api.Assertions.*,
org.mockito.Mockito.*"/>
</module>
<module name="ClassTypeParameterName"> <!-- Java Style Guide: Type variable names -->
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
Expand Down Expand Up @@ -127,6 +129,11 @@
<property name="illegalPkgs" value="junit.framework"/>
<message key="import.illegal" value="Use JUnit 4-style (org.junit.*) test classes and assertions instead of JUnit 3 (junit.framework.*)."/>
</module>
<module name="IllegalImport"> <!-- Only relevant for pre-Java 11 because javafx is gone completely in Java 11 -->
<property name="id" value="BanJavafx"/>
<property name="illegalPkgs" value="javafx"/>
<message key="import.illegal" value="Must not import javafx classes because some OpenJDK builds do not include javafx."/>
</module>
<module name="IllegalImport"> <!-- Java Coding Guidelines: Import the canonical package -->
<property name="illegalPkgs" value="org.elasticsearch.common.base, com.clearspring.analytics.util, org.spark_project.guava"/>
<message key="import.illegal" value="Must not import repackaged classes."/>
Expand Down Expand Up @@ -417,6 +424,7 @@
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyTypes" value="true"/>
<property name="allowEmptyLoops" value="true"/>
<property name="allowEmptyLambdas" value="true"/>
<property name="ignoreEnhancedForColon" value="false"/>
<message key="ws.notFollowed" value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
<message key="ws.notPreceded" value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
Expand All @@ -430,7 +438,7 @@
</module>
<module name="CyclomaticComplexity"/> <!-- Java Coding Guidelines: Reduce Cyclomatic Complexity -->
<module name="DesignForExtension"> <!-- Java Coding Guidelines: Design for extension -->
<property name="ignoredAnnotations" value="Test, Before, BeforeEach, After, AfterEach, BeforeClass, BeforeAll, AfterClass, AfterAll"/>
<property name="ignoredAnnotations" value="ParameterizedTest, Test, Before, BeforeEach, After, AfterEach, BeforeClass, BeforeAll, AfterClass, AfterAll"/>
</module>
<module name="JavadocMethod"> <!-- Java Style Guide: Where Javadoc is used -->
<property name="scope" value="public"/>
Expand Down Expand Up @@ -463,7 +471,7 @@
<module name="NestedTryDepth"/> <!-- Java Coding Guide: Try/catch blocks: never nested -->
<module name="NonEmptyAtclauseDescription"/> <!-- Java Style Guide: At-clauses -->
<module name="ParameterName"> <!-- Java Style Guide: Parameter names -->
<property name="format" value="^[a-z][a-zA-Z0-9]+$"/>
<property name="format" value="^_?[a-z][a-zA-Z0-9]+$"/>
<message key="name.invalidPattern" value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="SingleLineJavadoc"/> <!-- Java Style Guide: General form -->
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ buildscript {
classpath 'com.netflix.nebula:gradle-info-plugin:5.1.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.netflix.nebula:nebula-publishing-plugin:14.0.0'
classpath 'com.palantir.baseline:gradle-baseline-java:0.51.1'
classpath 'com.palantir.baseline:gradle-baseline-java:2.26.0'
classpath 'com.palantir.gradle.conjure:gradle-conjure:4.13.4'
classpath 'com.palantir.gradle.gitversion:gradle-git-version:0.12.2'
classpath 'gradle.plugin.org.inferred:gradle-processors:3.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import com.palantir.conjure.spec.UnionDefinition;
import com.palantir.conjure.visitor.DealiasingTypeVisitor;
import com.palantir.conjure.visitor.TypeDefinitionVisitor;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -95,9 +96,8 @@ public static String parseConjurePackage(com.palantir.conjure.parser.types.names
public static String parsePackageOrElseThrow(
Optional<com.palantir.conjure.parser.types.names.ConjurePackage> conjurePackage,
Optional<String> defaultPackage) {
String packageName = conjurePackage
.map(p -> p.name())
.orElseGet(() -> defaultPackage.orElseThrow(() -> new IllegalArgumentException(
String packageName = conjurePackage.map(p -> p.name()).orElseGet(() ->
defaultPackage.orElseThrow(() -> new SafeIllegalArgumentException(
// TODO(rfink): Better errors: Can we provide context on where exactly no package was provided?
"Must provide default conjure package or "
+ "explicit conjure package for every object and service")));
Expand Down Expand Up @@ -373,7 +373,7 @@ private static Optional<AuthType> parseAuthType(
case NONE:
return Optional.empty();
default:
throw new IllegalArgumentException("Unrecognized auth type.");
throw new SafeIllegalArgumentException("Unrecognized auth type.");
}
}

Expand Down Expand Up @@ -415,14 +415,14 @@ private static ParameterType parseParameterType(
return ParameterType.body(BodyParameterType.of());
}
case HEADER:
String headerParamId = argumentDef.paramId().map(id -> id.name()).orElse(argName.get());
String headerParamId = argumentDef.paramId().map(id -> id.name()).orElseGet(() -> argName.get());
return ParameterType.header(HeaderParameterType.of(ParameterId.of(headerParamId)));
case PATH:
return ParameterType.path(PathParameterType.of());
case BODY:
return ParameterType.body(BodyParameterType.of());
case QUERY:
String queryParamId = argumentDef.paramId().map(id -> id.name()).orElse(argName.get());
String queryParamId = argumentDef.paramId().map(id -> id.name()).orElseGet(() -> argName.get());
return ParameterType.query(QueryParameterType.of(ParameterId.of(queryParamId)));
default:
throw new IllegalArgumentException("Unknown parameter type: " + argumentDef.paramType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public ConjureTypeParserVisitor(ReferenceTypeResolver nameResolver) {
}

@Override
public Type visitAny(AnyType type) {
public Type visitAny(AnyType _type) {
return Type.primitive(com.palantir.conjure.spec.PrimitiveType.ANY);
}

Expand Down Expand Up @@ -146,12 +146,12 @@ public Type visitSet(SetType type) {
}

@Override
public Type visitBinary(BinaryType type) {
public Type visitBinary(BinaryType _type) {
return Type.primitive(com.palantir.conjure.spec.PrimitiveType.BINARY);
}

@Override
public Type visitDateTime(DateTimeType type) {
public Type visitDateTime(DateTimeType _type) {
return Type.primitive(com.palantir.conjure.spec.PrimitiveType.DATETIME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,8 @@ public void validate(ConjureDefinition definition) {
// create mapping from object type name -> names of reference types that are fields of that type
Multimap<TypeName, TypeName> typeToRefFields = HashMultimap.create();

definition.getTypes().stream().forEach(type ->
getReferenceType(type)
.ifPresent(entry -> typeToRefFields.put(
type.accept(TypeDefinitionVisitor.TYPE_NAME), entry)));
definition.getTypes().forEach(type -> getReferenceType(type).ifPresent(entry ->
typeToRefFields.put(type.accept(TypeDefinitionVisitor.TYPE_NAME), entry)));

for (TypeName name : typeToRefFields.keySet()) {
verifyTypeHasNoRecursiveDefinitions(name, typeToRefFields, new ArrayList<>());
Expand Down Expand Up @@ -181,14 +179,14 @@ public void validate(ConjureDefinition definition) {
// create mapping for resolving reference types during validation
Map<TypeName, TypeDefinition> definitionMap = definition.getTypes().stream().collect(
Collectors.toMap(entry -> entry.accept(TypeDefinitionVisitor.TYPE_NAME), entry -> entry));
definition.getTypes().stream().forEach(def -> validateTypeDefinition(def, definitionMap));
definition.getTypes().forEach(def -> validateTypeDefinition(def, definitionMap));
definition.getErrors().forEach(def -> validateErrorDefinition(def, definitionMap));
definition.getServices().forEach(def -> validateServiceDefinition(def, definitionMap));
}

private static void validateServiceDefinition(ServiceDefinition serviceDef,
Map<TypeName, TypeDefinition> definitionMap) {
serviceDef.getEndpoints().stream().forEach(endpoint -> {
serviceDef.getEndpoints().forEach(endpoint -> {
endpoint.getArgs().stream()
.filter(arg -> recursivelyFindNestedOptionals(arg.getType(), definitionMap, false))
.findAny()
Expand All @@ -199,9 +197,8 @@ private static void validateServiceDefinition(ServiceDefinition serviceDef,
});
endpoint.getReturns().ifPresent(returnType -> {
if (recursivelyFindNestedOptionals(returnType, definitionMap, false)) {
throw new IllegalStateException(
"Illegal nested optionals found in return type of endpoint "
+ endpoint.getEndpointName().get());
throw new IllegalStateException("Illegal nested optionals found in return type of endpoint "
+ endpoint.getEndpointName().get());
}
});
});
Expand All @@ -224,7 +221,7 @@ private static void validateTypeDefinition(TypeDefinition typeDef,

typeDef.accept(new TypeDefinition.Visitor<Void>() {
@Override
public Void visitAlias(AliasDefinition value) {
public Void visitAlias(AliasDefinition _value) {
AliasDefinition aliasDef = typeDef.accept(TypeDefinitionVisitor.ALIAS);
if (recursivelyFindNestedOptionals(aliasDef.getAlias(), definitionMap, false)) {
throw new IllegalStateException(
Expand All @@ -234,42 +231,40 @@ public Void visitAlias(AliasDefinition value) {
}

@Override
public Void visitObject(ObjectDefinition value) {
public Void visitObject(ObjectDefinition _value) {
ObjectDefinition objectDefinition = typeDef.accept(TypeDefinitionVisitor.OBJECT);
objectDefinition.getFields().stream()
.filter(fieldDefinition -> recursivelyFindNestedOptionals(
fieldDefinition.getType(), definitionMap, false))
.filter(fieldDefinition ->
recursivelyFindNestedOptionals(fieldDefinition.getType(), definitionMap, false))
.findAny()
.ifPresent(found -> {
throw new IllegalStateException(
"Illegal nested optionals found in object "
+ objectDefinition.getTypeName().getName());
throw new IllegalStateException("Illegal nested optionals found in object "
+ objectDefinition.getTypeName().getName());
});
return null;
}

@Override
public Void visitUnion(UnionDefinition value) {
public Void visitUnion(UnionDefinition _value) {
UnionDefinition unionDefinition = typeDef.accept(TypeDefinitionVisitor.UNION);
unionDefinition.getUnion().stream()
.filter(fieldDefinition -> recursivelyFindNestedOptionals(
fieldDefinition.getType(), definitionMap, false))
.filter(fieldDefinition ->
recursivelyFindNestedOptionals(fieldDefinition.getType(), definitionMap, false))
.findAny()
.ifPresent(found -> {
throw new IllegalStateException(
"Illegal nested optionals found in union "
+ unionDefinition.getTypeName().getName());
throw new IllegalStateException("Illegal nested optionals found in union "
+ unionDefinition.getTypeName().getName());
});
return null;
}

@Override
public Void visitEnum(EnumDefinition value) {
public Void visitEnum(EnumDefinition _value) {
return null;
}

@Override
public Void visitUnknown(String unknownType) {
public Void visitUnknown(String _unknownType) {
return null;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.palantir.conjure.visitor.ParameterTypeVisitor;
import com.palantir.conjure.visitor.TypeDefinitionVisitor;
import com.palantir.conjure.visitor.TypeVisitor;
import com.palantir.logsafe.exceptions.SafeRuntimeException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -274,51 +275,51 @@ public void validate(EndpointDefinition definition, DealiasingTypeVisitor dealia
}

private static Boolean recursivelyValidate(Type type, DealiasingTypeVisitor visitor) {
return visitor.dealias(type).fold(
typeDefinition -> typeDefinition.accept(TypeDefinitionVisitor.IS_ENUM),
subType -> subType.accept(new Type.Visitor<Boolean>() {
@Override
public Boolean visitPrimitive(PrimitiveType value) {
return value.get() != PrimitiveType.Value.ANY;
}

@Override
public Boolean visitOptional(OptionalType value) {
return recursivelyValidate(value.getItemType(), visitor);
}

@Override
public Boolean visitList(ListType value) {
return recursivelyValidate(value.getItemType(), visitor);
}

@Override
public Boolean visitSet(SetType value) {
return recursivelyValidate(value.getItemType(), visitor);
}

@Override
public Boolean visitMap(MapType value) {
return false;
}

// The cases below should not be handled here, since they implicitly handled by the
// DealiasingTypeVisitor above
@Override
public Boolean visitReference(TypeName value) {
throw new RuntimeException("Unexpected type when validating query parameters");
}

@Override
public Boolean visitExternal(ExternalReference value) {
throw new RuntimeException("Unexpected type when validating query parameters");
}

@Override
public Boolean visitUnknown(String unknownType) {
throw new RuntimeException("Unexpected type when validating query parameters");
}
}));
return visitor.dealias(type)
.fold(typeDefinition -> typeDefinition.accept(TypeDefinitionVisitor.IS_ENUM), subType ->
subType.accept(new Type.Visitor<Boolean>() {
@Override
public Boolean visitPrimitive(PrimitiveType value) {
return value.get() != PrimitiveType.Value.ANY;
}

@Override
public Boolean visitOptional(OptionalType value) {
return recursivelyValidate(value.getItemType(), visitor);
}

@Override
public Boolean visitList(ListType value) {
return recursivelyValidate(value.getItemType(), visitor);
}

@Override
public Boolean visitSet(SetType value) {
return recursivelyValidate(value.getItemType(), visitor);
}

@Override
public Boolean visitMap(MapType _value) {
return false;
}

// The cases below should not be handled here, since they implicitly handled by the
// DealiasingTypeVisitor above
@Override
public Boolean visitReference(TypeName _value) {
throw new SafeRuntimeException("Unexpected type when validating query parameters");
}

@Override
public Boolean visitExternal(ExternalReference _value) {
throw new SafeRuntimeException("Unexpected type when validating query parameters");
}

@Override
public Boolean visitUnknown(String _unknownType) {
throw new SafeRuntimeException("Unexpected type when validating query parameters");
}
}));
}
}

Expand Down
Loading

0 comments on commit d956c4a

Please sign in to comment.