From 1a44b3e676e06dcf3bae11ceedeef3ced1f80f05 Mon Sep 17 00:00:00 2001 From: Christian Dupuis Date: Thu, 9 Jan 2014 20:55:57 +0100 Subject: [PATCH] Fix sorting of auto configuration classes on JDK 8 --- .../boot/autoconfigure/AutoConfigurationSorter.java | 9 ++++++--- .../autoconfigure/AutoConfigurationSorterTests.java | 10 +++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java index e4aca8efc24..c4a5a1b9493 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 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. @@ -15,7 +15,6 @@ */ package org.springframework.boot.autoconfigure; - import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -38,6 +37,7 @@ import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.util.Assert; + /** * Sort {@link EnableAutoConfiguration auto-configuration} classes into priority order by * reading {@link Ordered} and {@link AutoConfigureAfter} annotations (without loading @@ -63,6 +63,9 @@ class AutoConfigurationSorter { List orderedClassNames = new ArrayList(classNames); // Sort initially by order + Collections.sort(orderedClassNames); + + // Then sort by order Collections.sort(orderedClassNames, new Comparator() { @Override public int compare(String o1, String o2) { @@ -130,7 +133,7 @@ class AutoConfigurationSorter { } public Set getClassesRequestedAfter(String className) { - Set rtn = new HashSet(); + Set rtn = new LinkedHashSet(); rtn.addAll(get(className).getAfter()); for (Map.Entry entry : this.classes .entrySet()) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java index 3644734633f..f3296c8330c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 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. @@ -94,6 +94,14 @@ public class AutoConfigurationSorterTests { assertThat(actual, nameMatcher(C, W, B, A, X)); } + @Test + public void byAutoConfigureMixedBeforeAndAfterWithDifferentInputOrder() + throws Exception { + List actual = this.sorter + .getInPriorityOrder(Arrays.asList(W, X, A, B, C)); + assertThat(actual, nameMatcher(C, W, B, A, X)); + } + @Test public void byAutoConfigureAfterWithMissing() throws Exception { List actual = this.sorter.getInPriorityOrder(Arrays.asList(A, B));