Skip to content

Commit

Permalink
Merge branch 'chore/2516/upgrade-libraries-fixup'
Browse files Browse the repository at this point in the history
fixes #2516
  • Loading branch information
dilipkrish committed Jun 29, 2018
2 parents e457745 + dcd5735 commit 2a8d9e2
Show file tree
Hide file tree
Showing 24 changed files with 541 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.9.3-SNAPSHOT
3.0.0-SNAPSHOT
13 changes: 9 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.2"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.7.4"
classpath "org.asciidoctor:asciidoctor-gradle-plugin:1.5.3"
classpath "org.asciidoctor:asciidoctor-gradle-plugin:1.5.7"
classpath "org.ajoberstar:gradle-git:1.7.2"
}
}
Expand All @@ -28,7 +28,7 @@ apply plugin: 'springfox-multi-release'

ext {
apiKey = System.getenv('GIT_HUB_API_KEY')
jdkVersion = 1.6
jdkVersion = 1.8
}

allprojects {
Expand All @@ -44,6 +44,13 @@ subprojects {
javadoc {
options.encoding = 'UTF-8'
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.deprecation = true
options.compilerArgs += ["-Xlint:unchecked", "-Xlint:deprecation", "-parameters"]
}

//Commented PMD and Findbugs as its taking too much time for very little value
//Perhaps run every 20 CI builds (mod of ci build number)
// apply from: "$rootDir/gradle/code-quality.gradle"
Expand Down Expand Up @@ -73,8 +80,6 @@ subprojects {
packageName "springfox"
}

compileJava.options.encoding = 'UTF-8'

sourceCompatibility = jdkVersion
targetCompatibility = jdkVersion
group = 'io.springfox'
Expand Down
11 changes: 6 additions & 5 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
ext {
aptIdeaVersion = 0.17
byteBuddyVersion = "1.8.12"
cglib = "3.2.6"
classmate = "1.4.0"
equalsverifierVersion = '2.4.7'
groovy = "2.4.15"
groovy = "2.5.0"
guava = "20.0"
jacocoVersion = '0.8.1'
jackson = '2.9.6'
Expand All @@ -18,15 +19,15 @@ ext {
slf4j = "1.7.25"
snakeyaml = '1.21'
spock = "1.1-groovy-2.4"
spring = "4.3.18.RELEASE"
spring = "5.0.7.RELEASE"
springHateoas = "0.24.0.RELEASE"
springDataRest = "2.6.13.RELEASE"
springDataRest = "3.0.8.RELEASE"
springPluginVersion = "1.2.0.RELEASE"
swagger2Core = "1.5.20"
springBoot = "1.5.14.RELEASE"
springBoot = "2.0.3.RELEASE"
springfoxRfc6570Version = "1.0.0"
undercouch = "3.4.3"
validationApiVersion = '1.1.0.Final'
validationApiVersion = '2.0.1.Final'

libs = [

Expand Down
2 changes: 1 addition & 1 deletion gradle/ide.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ allprojects {

idea {
project {
languageLevel = '1.6'
languageLevel = '1.8'
vcs = 'Git'
ipr {
withXml { provider ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
package springfox.documentation;

import com.fasterxml.classmate.ResolvedType;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.collect.Ordering;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.HandlerMethod;
Expand All @@ -31,10 +33,12 @@
import springfox.documentation.service.ResolvedMethodParameter;

import java.lang.annotation.Annotation;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public interface RequestHandler {
public interface RequestHandler extends Comparable<RequestHandler> {

/**
* @deprecated @since 2.7.0 This is introduced to preserve backwards compat with groups
Expand Down Expand Up @@ -93,4 +97,25 @@ public interface RequestHandler {
*/
@Incubating
RequestHandler combine(RequestHandler other);

@Override
default int compareTo(RequestHandler other) {
return byPatternsCondition()
.compound(byOperationName())
.compare(this, other);
}

static String sortedPaths(PatternsRequestCondition patternsCondition) {
TreeSet<String> paths = new TreeSet<>(patternsCondition.getPatterns());
return Joiner.on(",").skipNulls().join(paths);
}

static Ordering<RequestHandler> byPatternsCondition() {
return Ordering.from(
Comparator.comparing(requestHandler -> sortedPaths(requestHandler.getPatternsCondition())));
}

static Ordering<RequestHandler> byOperationName() {
return Ordering.from(Comparator.comparing(RequestHandler::getName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ public Optional<Class<?>> getDeclaringClass() {
return getHandlerMethod().transform(new Function<HandlerMethod, Class<?>>() {
@Override
public Class<?> apply(HandlerMethod input) {
if (AopUtils.isAopProxy(handlerMethod.getBean())) {
return AopUtils.getTargetClass(handlerMethod.getBean());
Object bean = new OptionalDeferencer<>().convert(handlerMethod.getBean());
if (AopUtils.isAopProxy(bean)) {
return AopUtils.getTargetClass(bean);
}
return handlerMethod.getBeanType();
return (Class<?>) bean;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.fasterxml.classmate.TypeResolver;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.context.PersistentEntities;
import org.springframework.data.repository.core.CrudMethods;
import org.springframework.data.repository.core.RepositoryInformation;
Expand Down Expand Up @@ -71,11 +72,15 @@ public String getName() {
return resource.getDomainType().getSimpleName();
}

public PersistentEntity<?, ?> entity() {
public PersistentEntity<?, ? extends PersistentProperty<?>> entity() {
Object domainType = resource.getDomainType();
Java8OptionalToGuavaOptionalConverter converter = new Java8OptionalToGuavaOptionalConverter();
Class actualDomainType = (Class) converter.convert(domainType).orNull();
return entities.getPersistentEntity(actualDomainType);
com.google.common.base.Optional<?> actualDomainType = converter.convert(domainType);
if (actualDomainType.isPresent()) {
return entities.getPersistentEntity((Class<?>) actualDomainType.get())
.orElse(null);
}
return null;
}

public CrudMethods crudMethods() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<RequestHandler> extract(EntityContext context) {
SearchResourceMappings searchMappings = context.searchMappings();
for (MethodResourceMapping mapping : searchMappings.getExportedMappings()) {
HandlerMethod handler = new HandlerMethod(
context.getRepositoryInstance(),
new OptionalDeferencer<>().convert(context.getRepositoryInstance()),
mapping.getMethod());
ActionSpecification spec = new ActionSpecification(
actionName(entity, mapping.getMethod()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ public Optional<?> convert(Object source) {
if ((Boolean) optionalIsPresent.invoke(source)) {
return Optional.of(optionalGet.invoke(source));
}
} catch (NoSuchMethodException e) {
LOGGER.warn(e.getMessage());
} catch (IllegalAccessException e) {
LOGGER.warn(e.getMessage());
} catch (InvocationTargetException e) {
} catch (NoSuchMethodException |
InvocationTargetException |
IllegalAccessException e) {
LOGGER.warn(e.getMessage());
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
*
* Copyright 2017-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*/
package springfox.documentation.spring.data.rest;

import org.springframework.core.convert.converter.Converter;

import java.util.Optional;

public class OptionalDeferencer<T> implements Converter<Object, T> {
@SuppressWarnings("unchecked")
@Override
public T convert(Object source) {
if (source instanceof Optional) {
if (((Optional<T>)source).isPresent()) {
return ((Optional<T>)source).get();
}
}
return (T) source;
}
}
2 changes: 1 addition & 1 deletion springfox-petstore/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ext {
jdkVersion = 1.6
jdkVersion = 1.8
}
compileJava.options.encoding = 'UTF-8'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.google.common.collect.Ordering;
import com.google.common.primitives.Ints;
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
import springfox.documentation.RequestHandler;
import springfox.documentation.service.ApiDescription;
import springfox.documentation.service.ApiListingReference;
Expand All @@ -32,121 +31,65 @@
import java.util.Comparator;

import static com.google.common.base.Strings.*;
import static springfox.documentation.RequestHandler.*;

public class Orderings {
private Orderings() {
throw new UnsupportedOperationException();
}

public static Comparator<Operation> nickNameComparator() {
return new Comparator<Operation>() {
@Override
public int compare(Operation first, Operation second) {
return nullToEmpty(first.getUniqueId()).compareTo(nullToEmpty(second.getUniqueId()));
}
};
return Comparator.comparing(operation -> nullToEmpty(operation.getUniqueId()));
}

public static Comparator<Operation> positionComparator() {
return new Comparator<Operation>() {
@Override
public int compare(Operation first, Operation second) {
return Ints.compare(first.getPosition(), second.getPosition());
}
};
return (first, second) -> Ints.compare(first.getPosition(), second.getPosition());
}

public static Comparator<ApiListingReference> listingReferencePathComparator() {
return new Comparator<ApiListingReference>() {
@Override
public int compare(ApiListingReference first, ApiListingReference second) {
return first.getPath().compareTo(second.getPath());
}
};
return Comparator.comparing(ApiListingReference::getPath);
}

public static Comparator<ApiListingReference> listingPositionComparator() {
return new Comparator<ApiListingReference>() {
@Override
public int compare(ApiListingReference first, ApiListingReference second) {
return Ints.compare(first.getPosition(), second.getPosition());
}
};
return (first, second) -> Ints.compare(first.getPosition(), second.getPosition());
}

public static Comparator<ApiDescription> apiPathCompatator() {
return new Comparator<ApiDescription>() {
@Override
public int compare(ApiDescription first, ApiDescription second) {
return first.getPath().compareTo(second.getPath());
}
};
return Comparator.comparing(ApiDescription::getPath);
}

public static Comparator<ResourceGroup> resourceGroupComparator() {
return new Comparator<ResourceGroup>() {
@Override
public int compare(ResourceGroup first, ResourceGroup second) {
return first.getGroupName().compareTo(second.getGroupName());
}
};
return Comparator.comparing(ResourceGroup::getGroupName);
}

public static Comparator<RequestMappingContext> methodComparator() {
return new Comparator<RequestMappingContext>() {
@Override
public int compare(RequestMappingContext first, RequestMappingContext second) {
return qualifiedMethodName(first).compareTo(qualifiedMethodName(second));
}
};
return Comparator.comparing(Orderings::qualifiedMethodName);
}

private static String qualifiedMethodName(RequestMappingContext context) {
return String.format("%s.%s", context.getGroupName(), context.getName());
}

public static Ordering<RequestHandler> byPatternsCondition() {
return Ordering.from(new Comparator<RequestHandler>() {
@Override
public int compare(RequestHandler first, RequestHandler second) {
return patternsCondition(first).toString()
.compareTo(patternsCondition(second).toString());
}
});
return Ordering.from(
Comparator.comparing(requestHandler -> sortedPaths(requestHandler.getPatternsCondition())));
}

public static Ordering<RequestHandler> byOperationName() {
return Ordering.from(new Comparator<RequestHandler>() {
@Override
public int compare(RequestHandler first, RequestHandler second) {
return first.getName().compareTo(second.getName());
}
});
}

public static PatternsRequestCondition patternsCondition(RequestHandler handler) {
return handler.getPatternsCondition();
return Ordering.from(Comparator.comparing(RequestHandler::getName));
}

public static Ordering<DocumentationPlugin> pluginOrdering() {
return Ordering.from(byPluginType()).compound(byPluginName());
}

public static Comparator<DocumentationPlugin> byPluginType() {
return new Comparator<DocumentationPlugin>() {
@Override
public int compare(DocumentationPlugin first, DocumentationPlugin second) {
return Ints.compare(first.getDocumentationType().hashCode(), second.getDocumentationType().hashCode());
}
};
return (first, second) -> Ints.compare(
first.getDocumentationType().hashCode(),
second.getDocumentationType().hashCode());
}

public static Comparator<DocumentationPlugin> byPluginName() {
return new Comparator<DocumentationPlugin>() {
@Override
public int compare(DocumentationPlugin first, DocumentationPlugin second) {
return first.getGroupName().compareTo(second.getGroupName());
}
};
return Comparator.comparing(DocumentationPlugin::getGroupName);
}
}

0 comments on commit 2a8d9e2

Please sign in to comment.