Skip to content

Commit 2694605

Browse files
committed
Polish
1 parent ce2346b commit 2694605

File tree

10 files changed

+41
-55
lines changed

10 files changed

+41
-55
lines changed

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ public void skipsFilterIfMissingServices() throws Exception {
180180
@Test
181181
public void skipsFilterIfPropertyDisabled() throws Exception {
182182
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
183-
EnvironmentTestUtils.addEnvironment(context, "endpoints.metrics.filter.enabled:false");
183+
EnvironmentTestUtils.addEnvironment(context,
184+
"endpoints.metrics.filter.enabled:false");
184185
context.register(Config.class, MetricFilterAutoConfiguration.class);
185186
context.refresh();
186187
assertThat(context.getBeansOfType(Filter.class).size(), equalTo(0));

spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,8 @@ private void processNestedTypes(String prefix, TypeElement element,
255255
String name = entry.getKey();
256256
ExecutableElement getter = entry.getValue();
257257
VariableElement field = members.getFields().get(name);
258-
Element returnType = this.processingEnv.getTypeUtils()
259-
.asElement(getter.getReturnType());
260-
AnnotationMirror annotation = getAnnotation(getter,
261-
configurationPropertiesAnnotation());
262-
boolean isNested = isNested(returnType, field, element);
263-
if (returnType != null && returnType instanceof TypeElement
264-
&& annotation == null && isNested) {
265-
String nestedPrefix = ConfigurationMetadata.nestedPrefix(prefix, name);
266-
this.metadataCollector.add(ItemMetadata.newGroup(nestedPrefix,
267-
this.typeUtils.getType(returnType),
268-
this.typeUtils.getType(element), getter.toString()));
269-
processTypeElement(nestedPrefix, (TypeElement) returnType);
270-
}
258+
processNestedType(prefix, element, name, getter, field,
259+
getter.getReturnType());
271260
}
272261
}
273262

@@ -276,19 +265,8 @@ private void processNestedLombokTypes(String prefix, TypeElement element,
276265
for (Map.Entry<String, VariableElement> entry : members.getFields().entrySet()) {
277266
String name = entry.getKey();
278267
VariableElement field = entry.getValue();
279-
if (!isLombokField(field, element)) {
280-
continue;
281-
}
282-
Element returnType = this.processingEnv.getTypeUtils()
283-
.asElement(field.asType());
284-
boolean isNested = isNested(returnType, field, element);
285-
if (returnType != null && returnType instanceof TypeElement
286-
&& isNested) {
287-
String nestedPrefix = ConfigurationMetadata.nestedPrefix(prefix, name);
288-
this.metadataCollector.add(ItemMetadata.newGroup(nestedPrefix,
289-
this.typeUtils.getType(returnType),
290-
this.typeUtils.getType(element), null));
291-
processTypeElement(nestedPrefix, (TypeElement) returnType);
268+
if (isLombokField(field, element)) {
269+
processNestedType(prefix, element, name, null, field, field.asType());
292270
}
293271
}
294272
}
@@ -306,6 +284,23 @@ private boolean hasLombokSetter(VariableElement field, TypeElement element) {
306284
|| hasAnnotation(element, LOMBOK_DATA_ANNOTATION));
307285
}
308286

287+
private void processNestedType(String prefix, TypeElement element, String name,
288+
ExecutableElement getter, VariableElement field, TypeMirror returnType) {
289+
Element returnElement = this.processingEnv.getTypeUtils().asElement(returnType);
290+
boolean isNested = isNested(returnElement, field, element);
291+
AnnotationMirror annotation = getAnnotation(getter,
292+
configurationPropertiesAnnotation());
293+
if (returnElement != null && returnElement instanceof TypeElement
294+
&& annotation == null && isNested) {
295+
String nestedPrefix = ConfigurationMetadata.nestedPrefix(prefix, name);
296+
this.metadataCollector.add(ItemMetadata.newGroup(nestedPrefix,
297+
this.typeUtils.getType(returnElement),
298+
this.typeUtils.getType(element),
299+
(getter == null ? null : getter.toString())));
300+
processTypeElement(nestedPrefix, (TypeElement) returnElement);
301+
}
302+
}
303+
309304
private boolean isNested(Element returnType, VariableElement field,
310305
TypeElement element) {
311306
if (hasAnnotation(field, nestedConfigurationPropertyAnnotation())) {

spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,12 @@ public void lombokInnerClassProperties() throws Exception {
319319
assertThat(metadata, containsProperty("config.second.bar.name"));
320320
assertThat(metadata, containsGroup("config.third").ofType(SimpleLombokPojo.class)
321321
.fromSource(LombokInnerClassProperties.class));
322-
// For some reason the annotation processor resolves a type for SimpleLombokPojo that
323-
// is resolved (compiled) and the source annotations are gone. Because we don't see the
324-
// @Data annotation anymore, no field is harvested. What is crazy is that a sample project
325-
// works fine so this seem to be related to the unit test environment for some reason.
326-
//assertThat(metadata, containsProperty("config.third.value"));
322+
// For some reason the annotation processor resolves a type for SimpleLombokPojo
323+
// that is resolved (compiled) and the source annotations are gone. Because we
324+
// don't see the @Data annotation anymore, no field is harvested. What is crazy is
325+
// that a sample project works fine so this seem to be related to the unit test
326+
// environment for some reason. assertThat(metadata,
327+
// containsProperty("config.third.value"));
327328
assertThat(metadata, containsProperty("config.fourth"));
328329
assertThat(metadata, not(containsGroup("config.fourth")));
329330
}
@@ -335,7 +336,6 @@ public void mergingOfAdditionalMetadata() throws Exception {
335336
File additionalMetadataFile = new File(metaInfFolder,
336337
"additional-spring-configuration-metadata.json");
337338
additionalMetadataFile.createNewFile();
338-
339339
JSONObject property = new JSONObject();
340340
property.put("name", "foo");
341341
property.put("type", "java.lang.String");
@@ -347,11 +347,8 @@ public void mergingOfAdditionalMetadata() throws Exception {
347347
FileWriter writer = new FileWriter(additionalMetadataFile);
348348
additionalMetadata.write(writer);
349349
writer.flush();
350-
351350
ConfigurationMetadata metadata = compile(SimpleProperties.class);
352-
353351
assertThat(metadata, containsProperty("simple.comparator"));
354-
355352
assertThat(metadata, containsProperty("foo", String.class)
356353
.fromSource(AdditionalMetadata.class));
357354
}
@@ -361,29 +358,23 @@ public void incrementalBuild() throws Exception {
361358
TestProject project = new TestProject(this.temporaryFolder, FooProperties.class,
362359
BarProperties.class);
363360
assertFalse(project.getOutputFile(METADATA_PATH).exists());
364-
365361
ConfigurationMetadata metadata = project.fullBuild();
366362
assertTrue(project.getOutputFile(METADATA_PATH).exists());
367-
368363
assertThat(metadata,
369364
containsProperty("foo.counter").fromSource(FooProperties.class));
370365
assertThat(metadata,
371366
containsProperty("bar.counter").fromSource(BarProperties.class));
372-
373367
metadata = project.incrementalBuild(BarProperties.class);
374-
375368
assertThat(metadata,
376369
containsProperty("foo.counter").fromSource(FooProperties.class));
377370
assertThat(metadata,
378371
containsProperty("bar.counter").fromSource(BarProperties.class));
379-
380372
project.addSourceCode(BarProperties.class,
381373
BarProperties.class.getResourceAsStream("BarProperties.snippet"));
382374
metadata = project.incrementalBuild(BarProperties.class);
383375
assertThat(metadata, containsProperty("bar.extra"));
384376
assertThat(metadata, containsProperty("foo.counter"));
385377
assertThat(metadata, containsProperty("bar.counter"));
386-
387378
project.revert(BarProperties.class);
388379
metadata = project.incrementalBuild(BarProperties.class);
389380
assertThat(metadata, not(containsProperty("bar.extra")));
@@ -398,7 +389,6 @@ public void incrementalBuildAnnotationRemoved() throws Exception {
398389
ConfigurationMetadata metadata = project.fullBuild();
399390
assertThat(metadata, containsProperty("foo.counter"));
400391
assertThat(metadata, containsProperty("bar.counter"));
401-
402392
project.replaceText(BarProperties.class, "@ConfigurationProperties",
403393
"//@ConfigurationProperties");
404394
metadata = project.incrementalBuild(BarProperties.class);
@@ -417,7 +407,6 @@ public void incrementalBuildTypeRenamed() throws Exception {
417407
containsProperty("bar.counter").fromSource(BarProperties.class));
418408
assertThat(metadata, not(
419409
containsProperty("bar.counter").fromSource(RenamedBarProperties.class)));
420-
421410
project.delete(BarProperties.class);
422411
project.add(RenamedBarProperties.class);
423412
metadata = project.incrementalBuild(RenamedBarProperties.class);

spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestProject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void delete(Class<?> type) {
161161
/**
162162
* Restore source code of given class to its original contents.
163163
* @param type the class to revert
164-
* @throws IOException
164+
* @throws IOException on IO error
165165
*/
166166
public void revert(Class<?> type) throws IOException {
167167
Assert.assertTrue(getSourceFile(type).exists());
@@ -171,7 +171,7 @@ public void revert(Class<?> type) throws IOException {
171171
/**
172172
* Add source code of given class to this project.
173173
* @param type the class to add
174-
* @throws IOException
174+
* @throws IOException on IO error
175175
*/
176176
public void add(Class<?> type) throws IOException {
177177
Assert.assertFalse(getSourceFile(type).exists());

spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/lombok/LombokInnerClassProperties.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929
@Data
3030
@ConfigurationProperties(prefix = "config")
31+
@SuppressWarnings("unused")
3132
public class LombokInnerClassProperties {
3233

3334
private final Foo first = new Foo();
@@ -58,4 +59,5 @@ public static class Bar {
5859
public enum Fourth {
5960
YES, NO
6061
}
62+
6163
}

spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/lombok/LombokSimpleDataProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*/
3131
@Data
3232
@ConfigurationProperties(prefix = "data")
33+
@SuppressWarnings("unused")
3334
public class LombokSimpleDataProperties {
3435

3536
private final String id = "super-id";

spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/lombok/LombokSimpleProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
@Getter
3333
@Setter
3434
@ConfigurationProperties(prefix = "simple")
35+
@SuppressWarnings("unused")
3536
public class LombokSimpleProperties {
3637

3738
private final String id = "super-id";

spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/lombok/SimpleLombokPojo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* @author Stephane Nicoll
2525
*/
2626
@Data
27+
@SuppressWarnings("unused")
2728
public class SimpleLombokPojo {
2829

2930
private int value;

spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,4 @@ public URL nextElement() {
291291

292292
}
293293

294-
}
294+
}

spring-boot/src/main/java/org/springframework/boot/ansi/AnsiOutput.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,15 @@ private static void buildDisabled(StringBuilder sb, Object[] elements) {
110110

111111
private static boolean isEnabled() {
112112
if (enabled == Enabled.DETECT) {
113-
return detectIfAnsiCapable();
113+
if (ansiCapable == null) {
114+
ansiCapable = detectIfAnsiCapable();
115+
}
116+
return ansiCapable;
114117
}
115118
return enabled == Enabled.ALWAYS;
116119
}
117120

118121
private static boolean detectIfAnsiCapable() {
119-
if (ansiCapable == null) {
120-
ansiCapable = doDetectIfAnsiCapable();
121-
}
122-
return ansiCapable;
123-
}
124-
125-
private static boolean doDetectIfAnsiCapable() {
126122
try {
127123
if (System.console() == null) {
128124
return false;

0 commit comments

Comments
 (0)