Fix sorting of auto configuration classes on JDK 8
This commit is contained in:
parent
fd15b62a9d
commit
1a44b3e676
|
@ -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<String> orderedClassNames = new ArrayList<String>(classNames);
|
||||
|
||||
// Sort initially by order
|
||||
Collections.sort(orderedClassNames);
|
||||
|
||||
// Then sort by order
|
||||
Collections.sort(orderedClassNames, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
|
@ -130,7 +133,7 @@ class AutoConfigurationSorter {
|
|||
}
|
||||
|
||||
public Set<String> getClassesRequestedAfter(String className) {
|
||||
Set<String> rtn = new HashSet<String>();
|
||||
Set<String> rtn = new LinkedHashSet<String>();
|
||||
rtn.addAll(get(className).getAfter());
|
||||
for (Map.Entry<String, AutoConfigurationClass> entry : this.classes
|
||||
.entrySet()) {
|
||||
|
|
|
@ -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<String> 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<String> actual = this.sorter.getInPriorityOrder(Arrays.asList(A, B));
|
||||
|
|
Loading…
Reference in New Issue