#806 - Fixed package cycle between hateoas and hateoas.core packages.
Moved AffordanceModelFactory to the library's root package. Moved Kotlin extensions to hateoas.mvc package. Added an ArchUnit based test for package cycles.
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -631,6 +631,13 @@
|
||||
<version>3.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tngtech.archunit</groupId>
|
||||
<artifactId>archunit</artifactId>
|
||||
<version>0.9.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.Map;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
import org.springframework.hateoas.core.AffordanceModelFactory;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -37,20 +36,23 @@ import org.springframework.util.Assert;
|
||||
@Value
|
||||
public class Affordance {
|
||||
|
||||
private static List<AffordanceModelFactory> factories = SpringFactoriesLoader.loadFactories(AffordanceModelFactory.class, Affordance.class.getClassLoader());
|
||||
private static List<AffordanceModelFactory> factories = SpringFactoriesLoader
|
||||
.loadFactories(AffordanceModelFactory.class, Affordance.class.getClassLoader());
|
||||
|
||||
/**
|
||||
* Collection of {@link AffordanceModel}s related to this affordance.
|
||||
*/
|
||||
private final Map<MediaType, AffordanceModel> affordanceModels = new HashMap<>();
|
||||
|
||||
public Affordance(String name, Link link, HttpMethod httpMethod, ResolvableType inputType, List<QueryParameter> queryMethodParameters, ResolvableType outputType) {
|
||||
public Affordance(String name, Link link, HttpMethod httpMethod, ResolvableType inputType,
|
||||
List<QueryParameter> queryMethodParameters, ResolvableType outputType) {
|
||||
|
||||
Assert.notNull(httpMethod, "httpMethod must not be null!");
|
||||
Assert.notNull(queryMethodParameters, "queryMethodParameters must not be null!");
|
||||
|
||||
for (AffordanceModelFactory factory : factories) {
|
||||
this.affordanceModels.put(factory.getMediaType(), factory.getAffordanceModel(name, link, httpMethod, inputType, queryMethodParameters, outputType));
|
||||
this.affordanceModels.put(factory.getMediaType(),
|
||||
factory.getAffordanceModel(name, link, httpMethod, inputType, queryMethodParameters, outputType));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,15 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.hateoas.core;
|
||||
package org.springframework.hateoas;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.hateoas.AffordanceModel;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.QueryParameter;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.plugin.core.Plugin;
|
||||
@@ -21,10 +21,10 @@ import java.util.List;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.hateoas.AffordanceModel;
|
||||
import org.springframework.hateoas.AffordanceModelFactory;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.QueryParameter;
|
||||
import org.springframework.hateoas.core.AffordanceModelFactory;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
|
||||
@@ -21,10 +21,10 @@ import java.util.List;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.hateoas.AffordanceModel;
|
||||
import org.springframework.hateoas.AffordanceModelFactory;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.QueryParameter;
|
||||
import org.springframework.hateoas.core.AffordanceModelFactory;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
import org.springframework.hateoas.Affordance;
|
||||
import org.springframework.hateoas.AffordanceModelFactory;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.TemplateVariables;
|
||||
import org.springframework.hateoas.core.AffordanceModelFactory;
|
||||
import org.springframework.hateoas.core.AnnotationMappingDiscoverer;
|
||||
import org.springframework.hateoas.core.DummyInvocationUtils;
|
||||
import org.springframework.hateoas.core.DummyInvocationUtils.MethodInvocation;
|
||||
|
||||
@@ -22,9 +22,9 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.hateoas.Affordance;
|
||||
import org.springframework.hateoas.AffordanceModelFactory;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.QueryParameter;
|
||||
import org.springframework.hateoas.core.AffordanceModelFactory;
|
||||
import org.springframework.hateoas.core.DummyInvocationUtils.MethodInvocation;
|
||||
import org.springframework.hateoas.core.MappingDiscoverer;
|
||||
import org.springframework.hateoas.core.MethodParameters;
|
||||
|
||||
@@ -21,10 +21,10 @@ import java.util.List;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.hateoas.AffordanceModel;
|
||||
import org.springframework.hateoas.AffordanceModelFactory;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.QueryParameter;
|
||||
import org.springframework.hateoas.core.AffordanceModelFactory;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.hateoas
|
||||
package org.springframework.hateoas.mvc
|
||||
|
||||
import org.springframework.hateoas.mvc.ControllerLinkBuilder
|
||||
import org.springframework.hateoas.Affordance
|
||||
import org.springframework.hateoas.Link
|
||||
import org.springframework.hateoas.mvc.ControllerLinkBuilder.afford
|
||||
import org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn
|
||||
|
||||
@@ -14,11 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.hateoas
|
||||
package org.springframework.hateoas.mvc
|
||||
|
||||
import org.springframework.hateoas.Link
|
||||
import org.springframework.hateoas.ResourceSupport
|
||||
import org.springframework.hateoas.mvc.ControllerLinkBuilder
|
||||
import org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo
|
||||
import org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
@@ -1 +1 @@
|
||||
org.springframework.hateoas.core.AffordanceModelFactory=org.springframework.hateoas.hal.forms.HalFormsAffordanceModelFactory,org.springframework.hateoas.collectionjson.CollectionJsonAffordanceModelFactory,org.springframework.hateoas.uber.UberAffordanceModelFactory
|
||||
org.springframework.hateoas.AffordanceModelFactory=org.springframework.hateoas.hal.forms.HalFormsAffordanceModelFactory,org.springframework.hateoas.collectionjson.CollectionJsonAffordanceModelFactory,org.springframework.hateoas.uber.UberAffordanceModelFactory
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 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 org.springframework.hateoas;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.tngtech.archunit.core.domain.JavaClasses;
|
||||
import com.tngtech.archunit.core.importer.ClassFileImporter;
|
||||
import com.tngtech.archunit.core.importer.ImportOption;
|
||||
import com.tngtech.archunit.core.importer.ImportOptions;
|
||||
import com.tngtech.archunit.library.dependencies.SliceRule;
|
||||
import com.tngtech.archunit.library.dependencies.SlicesRuleDefinition;
|
||||
|
||||
/**
|
||||
* Tests to verify certain architectural assumptions.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class ArchitectureTest {
|
||||
|
||||
ImportOptions options = new ImportOptions().with(ImportOption.Predefined.DONT_INCLUDE_TESTS);
|
||||
JavaClasses classes = new ClassFileImporter(options) //
|
||||
.importPackages("org.springframework.hateoas");
|
||||
|
||||
@Test
|
||||
public void assertNoCyclicPackageDependencies() {
|
||||
|
||||
SliceRule rule = SlicesRuleDefinition.slices() //
|
||||
.matching("org.springframework.(**)..") //
|
||||
.should().beFreeOfCycles();
|
||||
|
||||
rule.check(classes);
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,9 @@ import org.junit.Test;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.hateoas.AffordanceModel;
|
||||
import org.springframework.hateoas.AffordanceModelFactory;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.QueryParameter;
|
||||
import org.springframework.hateoas.core.AffordanceModelFactory;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.plugin.core.OrderAwarePluginRegistry;
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.hateoas
|
||||
package org.springframework.hateoas.mvc
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
import org.springframework.hateoas.*
|
||||
import org.springframework.http.HttpMethod
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.hateoas
|
||||
package org.springframework.hateoas.mvc
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
import org.springframework.hateoas.*
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
Reference in New Issue
Block a user