From 83e81e13f2ed262dc7304a36615549f38cd97fe2 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 7 Jul 2017 15:51:44 +0100 Subject: [PATCH] Add support of metadata generation for Endpoints This commit improves the configuration metadata annotation processor to explicitly handle `@Endpoint` annotated class. Adding a new endpoint on a project potentially creates the following keys: * `endpoints..enabled` * `endpoints..cache.time-to-live` * `endpoints..jmx.enabled` * `endpoints..web.enabled` Default values are extracted from the annotation type. If an endpoint is restricted to a given tech, properties from unrelated techs are not generated. Closes gh-9692 --- ...figurationMetadataAnnotationProcessor.java | 107 ++++++++++++ .../metadata/ConfigurationMetadata.java | 10 ++ ...ationMetadataAnnotationProcessorTests.java | 165 ++++++++++++++++++ ...figurationMetadataAnnotationProcessor.java | 7 + .../metadata/Metadata.java | 4 + .../boot/configurationsample/Endpoint.java | 50 ++++++ .../endpoint/CustomPropertiesEndpoint.java | 41 +++++ .../endpoint/DisabledEndpoint.java | 29 +++ .../endpoint/OnlyJmxEndpoint.java | 29 +++ .../endpoint/OnlyWebEndpoint.java | 29 +++ .../endpoint/SimpleEndpoint.java | 29 +++ .../incremental/IncrementalEndpoint.java | 29 +++ .../incremental/IncrementalJmxEndpoint.java | 29 +++ 13 files changed, 558 insertions(+) create mode 100644 spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/Endpoint.java create mode 100644 spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/CustomPropertiesEndpoint.java create mode 100644 spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/DisabledEndpoint.java create mode 100644 spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyJmxEndpoint.java create mode 100644 spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyWebEndpoint.java create mode 100644 spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/SimpleEndpoint.java create mode 100644 spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/incremental/IncrementalEndpoint.java create mode 100644 spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/incremental/IncrementalJmxEndpoint.java diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java index d7a6ee5e4d4..fc11b48d852 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java @@ -19,7 +19,10 @@ package org.springframework.boot.configurationprocessor; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Set; @@ -70,6 +73,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor static final String DEPRECATED_CONFIGURATION_PROPERTY_ANNOTATION = "org.springframework.boot." + "context.properties.DeprecatedConfigurationProperty"; + static final String ENDPOINT_ANNOTATION = "org.springframework.boot." + + "endpoint.Endpoint"; + static final String LOMBOK_DATA_ANNOTATION = "lombok.Data"; static final String LOMBOK_GETTER_ANNOTATION = "lombok.Getter"; @@ -98,6 +104,10 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor return DEPRECATED_CONFIGURATION_PROPERTY_ANNOTATION; } + protected String endpointAnnotation() { + return ENDPOINT_ANNOTATION; + } + @Override public SourceVersion getSupportedSourceVersion() { return SourceVersion.latestSupported(); @@ -132,6 +142,13 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor processElement(element); } } + TypeElement endpointType = elementUtils.getTypeElement(endpointAnnotation()); + if (endpointType != null) { // Is @Endpoint available + for (Element element : roundEnv.getElementsAnnotatedWith(endpointType)) { + processEndpoint(element); + } + } + if (roundEnv.processingOver()) { try { writeMetaData(); @@ -332,6 +349,59 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor } } + private void processEndpoint(Element element) { + try { + AnnotationMirror annotation = getAnnotation(element, endpointAnnotation()); + if (element instanceof TypeElement) { + processEndpoint(annotation, (TypeElement) element); + } + } + catch (Exception ex) { + throw new IllegalStateException( + "Error processing configuration meta-data on " + element, ex); + } + } + + private void processEndpoint(AnnotationMirror annotation, TypeElement element) { + Map elementValues = getAnnotationElementValues(annotation); + String endpointId = (String) elementValues.get("id"); + if (endpointId == null || "".equals(endpointId)) { + return; // Can't process that endpoint + } + Boolean enabledByDefault = (Boolean) elementValues.get("enabledByDefault"); + if (enabledByDefault == null) { + enabledByDefault = Boolean.TRUE; + } + String type = this.typeUtils.getQualifiedName(element); + this.metadataCollector.add(ItemMetadata.newGroup(endpointKey(endpointId), + type, type, null)); + this.metadataCollector.add(ItemMetadata.newProperty(endpointKey(endpointId), + "enabled", Boolean.class.getName(), type, null, String.format( + "Enable the %s endpoint.", endpointId), enabledByDefault, null)); + this.metadataCollector.add(ItemMetadata.newProperty(endpointKey(endpointId), + "cache.time-to-live", Long.class.getName(), type, null, + "Maximum time in milliseconds that a response can be cached.", 0, null)); + + EndpointTypes endpointTypes = EndpointTypes.parse(elementValues.get("types")); + if (endpointTypes.hasJmx()) { + this.metadataCollector.add(ItemMetadata.newProperty( + endpointKey(endpointId + ".jmx"), "enabled", Boolean.class.getName(), + type, null, String.format("Expose the %s endpoint as a JMX MBean.", + endpointId), enabledByDefault, null)); + } + if (endpointTypes.hasWeb()) { + this.metadataCollector.add(ItemMetadata.newProperty( + endpointKey(endpointId + ".web"), "enabled", Boolean.class.getName(), + type, null, String.format("Expose the %s endpoint as a Web endpoint.", + endpointId), enabledByDefault, null)); + } + } + + private String endpointKey(String suffix) { + return "endpoints." + suffix; + } + + private boolean isNested(Element returnType, VariableElement field, TypeElement element) { if (hasAnnotation(field, nestedConfigurationPropertyAnnotation())) { @@ -454,4 +524,41 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor this.processingEnv.getMessager().printMessage(kind, msg); } + private static class EndpointTypes { + + private static final List ALL_TYPES = Arrays.asList("JMX", "WEB"); + + private final List types; + + EndpointTypes(List types) { + this.types = types; + } + + static EndpointTypes parse(Object typesAttribute) { + if (typesAttribute == null || !(typesAttribute instanceof List)) { + return new EndpointTypes(ALL_TYPES); + } + List values = (List) typesAttribute; + if (values.isEmpty()) { + return new EndpointTypes(ALL_TYPES); + } + List types = new ArrayList<>(); + for (AnnotationValue value : values) { + types.add(((VariableElement) value.getValue()).getSimpleName().toString()); + } + return new EndpointTypes(types); + + } + + public boolean hasJmx() { + return this.types.contains("JMX"); + } + + + public boolean hasWeb() { + return this.types.contains("WEB"); + } + + } + } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java index 448eef94cfa..7dbfcaa66ed 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java @@ -209,4 +209,14 @@ public class ConfigurationMetadata { return content; } + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(String.format("items: %n")); + this.items.values().forEach(itemMetadata -> { + sb.append("\t").append(String.format("%s%n", itemMetadata)); + }); + return sb.toString(); + } + } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java index 9aa0ee352e4..f97243d12ae 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java @@ -36,6 +36,13 @@ import org.springframework.boot.configurationprocessor.metadata.ItemHint; import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; import org.springframework.boot.configurationprocessor.metadata.Metadata; import org.springframework.boot.configurationprocessor.metadata.TestJsonConverter; +import org.springframework.boot.configurationsample.endpoint.CustomPropertiesEndpoint; +import org.springframework.boot.configurationsample.endpoint.DisabledEndpoint; +import org.springframework.boot.configurationsample.endpoint.OnlyJmxEndpoint; +import org.springframework.boot.configurationsample.endpoint.OnlyWebEndpoint; +import org.springframework.boot.configurationsample.endpoint.SimpleEndpoint; +import org.springframework.boot.configurationsample.endpoint.incremental.IncrementalEndpoint; +import org.springframework.boot.configurationsample.endpoint.incremental.IncrementalJmxEndpoint; import org.springframework.boot.configurationsample.incremental.BarProperties; import org.springframework.boot.configurationsample.incremental.FooProperties; import org.springframework.boot.configurationsample.incremental.RenamedBarProperties; @@ -517,6 +524,164 @@ public class ConfigurationMetadataAnnotationProcessorTests { assertThat(metadata.getItems()).hasSize(3); } + + @Test + public void simpleEndpoint() throws IOException { + ConfigurationMetadata metadata = compile(SimpleEndpoint.class); + assertThat(metadata).has(Metadata.withGroup("endpoints.simple") + .fromSource(SimpleEndpoint.class)); + assertThat(metadata).has(enabledFlag("simple", true)); + assertThat(metadata).has(jmxEnabledFlag("simple", true)); + assertThat(metadata).has(webEnabledFlag("simple", true)); + assertThat(metadata).has(cacheTtl("simple")); + assertThat(metadata.getItems()).hasSize(5); + } + + @Test + public void disableEndpoint() throws IOException { + ConfigurationMetadata metadata = compile(DisabledEndpoint.class); + assertThat(metadata).has(Metadata.withGroup("endpoints.disabled") + .fromSource(DisabledEndpoint.class)); + assertThat(metadata).has(enabledFlag("disabled", false)); + assertThat(metadata).has(jmxEnabledFlag("disabled", false)); + assertThat(metadata).has(webEnabledFlag("disabled", false)); + assertThat(metadata).has(cacheTtl("disabled")); + assertThat(metadata.getItems()).hasSize(5); + } + + @Test + public void customPropertiesEndpoint() throws IOException { + ConfigurationMetadata metadata = compile(CustomPropertiesEndpoint.class); + assertThat(metadata).has(Metadata.withGroup("endpoints.customprops") + .fromSource(CustomPropertiesEndpoint.class)); + assertThat(metadata).has(Metadata.withProperty("endpoints.customprops.name"). + ofType(String.class).withDefaultValue("test")); + assertThat(metadata).has(enabledFlag("customprops", true)); + assertThat(metadata).has(jmxEnabledFlag("customprops", true)); + assertThat(metadata).has(webEnabledFlag("customprops", true)); + assertThat(metadata).has(cacheTtl("customprops")); + assertThat(metadata.getItems()).hasSize(6); + } + + @Test + public void jmxOnlyEndpoint() throws IOException { + ConfigurationMetadata metadata = compile(OnlyJmxEndpoint.class); + assertThat(metadata).has(Metadata.withGroup("endpoints.jmx") + .fromSource(OnlyJmxEndpoint.class)); + assertThat(metadata).has(enabledFlag("jmx", true)); + assertThat(metadata).has(jmxEnabledFlag("jmx", true)); + assertThat(metadata).has(cacheTtl("jmx")); + assertThat(metadata.getItems()).hasSize(4); + } + + @Test + public void webOnlyEndpoint() throws IOException { + ConfigurationMetadata metadata = compile(OnlyWebEndpoint.class); + assertThat(metadata).has(Metadata.withGroup("endpoints.web") + .fromSource(OnlyWebEndpoint.class)); + assertThat(metadata).has(enabledFlag("web", true)); + assertThat(metadata).has(webEnabledFlag("web", true)); + assertThat(metadata).has(cacheTtl("web")); + assertThat(metadata.getItems()).hasSize(4); + } + + @Test + public void incrementalEndpointBuildChangeGeneralEnabledFlag() throws Exception { + TestProject project = new TestProject(this.temporaryFolder, + IncrementalEndpoint.class); + ConfigurationMetadata metadata = project.fullBuild(); + assertThat(metadata).has(Metadata.withGroup("endpoints.incremental") + .fromSource(IncrementalEndpoint.class)); + assertThat(metadata).has(enabledFlag("incremental", true)); + assertThat(metadata).has(jmxEnabledFlag("incremental", true)); + assertThat(metadata).has(webEnabledFlag("incremental", true)); + assertThat(metadata).has(cacheTtl("incremental")); + assertThat(metadata.getItems()).hasSize(5); + project.replaceText(IncrementalEndpoint.class, "id = \"incremental\"", + "id = \"incremental\", enabledByDefault = false"); + metadata = project.incrementalBuild(IncrementalEndpoint.class); + assertThat(metadata).has(Metadata.withGroup("endpoints.incremental") + .fromSource(IncrementalEndpoint.class)); + assertThat(metadata).has(enabledFlag("incremental", false)); + assertThat(metadata).has(jmxEnabledFlag("incremental", false)); + assertThat(metadata).has(webEnabledFlag("incremental", false)); + assertThat(metadata).has(cacheTtl("incremental")); + assertThat(metadata.getItems()).hasSize(5); + } + + @Test + public void incrementalEndpointBuildDisableJmxEndpoint() throws Exception { + TestProject project = new TestProject(this.temporaryFolder, + IncrementalEndpoint.class); + ConfigurationMetadata metadata = project.fullBuild(); + assertThat(metadata).has(Metadata.withGroup("endpoints.incremental") + .fromSource(IncrementalEndpoint.class)); + assertThat(metadata).has(enabledFlag("incremental", true)); + assertThat(metadata).has(jmxEnabledFlag("incremental", true)); + assertThat(metadata).has(webEnabledFlag("incremental", true)); + assertThat(metadata).has(cacheTtl("incremental")); + assertThat(metadata.getItems()).hasSize(5); + project.replaceText(IncrementalEndpoint.class, "id = \"incremental\"", + "id = \"incremental\", types = Endpoint.Type.WEB"); + metadata = project.incrementalBuild(IncrementalEndpoint.class); + assertThat(metadata).has(Metadata.withGroup("endpoints.incremental") + .fromSource(IncrementalEndpoint.class)); + assertThat(metadata).has(enabledFlag("incremental", true)); + assertThat(metadata).has(webEnabledFlag("incremental", true)); + assertThat(metadata).has(cacheTtl("incremental")); + assertThat(metadata.getItems()).hasSize(4); + } + + @Test + public void incrementalEndpointBuildEnableJmxEndpoint() throws Exception { + TestProject project = new TestProject(this.temporaryFolder, + IncrementalJmxEndpoint.class); + ConfigurationMetadata metadata = project.fullBuild(); + assertThat(metadata).has(Metadata.withGroup("endpoints.incremental") + .fromSource(IncrementalJmxEndpoint.class)); + assertThat(metadata).has(enabledFlag("incremental", true)); + assertThat(metadata).has(jmxEnabledFlag("incremental", true)); + assertThat(metadata).has(cacheTtl("incremental")); + assertThat(metadata.getItems()).hasSize(4); + project.replaceText(IncrementalJmxEndpoint.class, ", types = Endpoint.Type.JMX", + ""); + metadata = project.incrementalBuild(IncrementalJmxEndpoint.class); + assertThat(metadata).has(Metadata.withGroup("endpoints.incremental") + .fromSource(IncrementalJmxEndpoint.class)); + assertThat(metadata).has(enabledFlag("incremental", true)); + assertThat(metadata).has(jmxEnabledFlag("incremental", true)); + assertThat(metadata).has(webEnabledFlag("incremental", true)); + assertThat(metadata).has(cacheTtl("incremental")); + assertThat(metadata.getItems()).hasSize(5); + } + + private Metadata.MetadataItemCondition enabledFlag(String endpointId, + boolean defaultValue) { + return Metadata.withEnabledFlag("endpoints." + endpointId + ".enabled") + .withDefaultValue(defaultValue).withDescription( + String.format("Enable the %s endpoint.", endpointId)); + } + + private Metadata.MetadataItemCondition jmxEnabledFlag(String endpointId, + boolean defaultValue) { + return Metadata.withEnabledFlag("endpoints." + endpointId + ".jmx.enabled") + .withDefaultValue(defaultValue).withDescription(String.format( + "Expose the %s endpoint as a JMX MBean.", endpointId)); + } + + private Metadata.MetadataItemCondition webEnabledFlag(String endpointId, + boolean defaultValue) { + return Metadata.withEnabledFlag("endpoints." + endpointId + ".web.enabled") + .withDefaultValue(defaultValue).withDescription(String.format( + "Expose the %s endpoint as a Web endpoint.", endpointId)); + } + + private Metadata.MetadataItemCondition cacheTtl(String endpointId) { + return Metadata.withProperty("endpoints." + endpointId + ".cache.time-to-live") + .ofType(Long.class).withDefaultValue(0).withDescription( + "Maximum time in milliseconds that a response can be cached."); + } + @Test public void mergingOfAdditionalProperty() throws Exception { ItemMetadata property = ItemMetadata.newProperty(null, "foo", "java.lang.String", diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestConfigurationMetadataAnnotationProcessor.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestConfigurationMetadataAnnotationProcessor.java index 220fbb4ab14..2e1cf80e14c 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestConfigurationMetadataAnnotationProcessor.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestConfigurationMetadataAnnotationProcessor.java @@ -46,6 +46,8 @@ public class TestConfigurationMetadataAnnotationProcessor static final String DEPRECATED_CONFIGURATION_PROPERTY_ANNOTATION = "org.springframework.boot.configurationsample.DeprecatedConfigurationProperty"; + static final String ENDPOINT_ANNOTATION = "org.springframework.boot.configurationsample.Endpoint"; + private ConfigurationMetadata metadata; private final File outputLocation; @@ -69,6 +71,11 @@ public class TestConfigurationMetadataAnnotationProcessor return DEPRECATED_CONFIGURATION_PROPERTY_ANNOTATION; } + @Override + protected String endpointAnnotation() { + return ENDPOINT_ANNOTATION; + } + @Override protected ConfigurationMetadata writeMetaData() throws Exception { super.writeMetaData(); diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java index 6624cd58333..654f8c59385 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java @@ -62,6 +62,10 @@ public final class Metadata { return new MetadataItemCondition(ItemType.PROPERTY, name).ofType(type); } + public static Metadata.MetadataItemCondition withEnabledFlag(String key) { + return withProperty(key).ofType(Boolean.class); + } + public static MetadataHintCondition withHint(String name) { return new MetadataHintCondition(name); } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/Endpoint.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/Endpoint.java new file mode 100644 index 00000000000..b685e69353a --- /dev/null +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/Endpoint.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-2017 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.boot.configurationsample; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Alternative to Spring Boot's {@code @Endpoint} for testing (removes the need for a + * dependency on the real annotation). + * + * @author Stephane Nicoll + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface Endpoint { + + String id(); + + boolean enabledByDefault() default true; + + Type[] types() default {}; + + enum Type { + + JMX, + + WEB + + } + +} diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/CustomPropertiesEndpoint.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/CustomPropertiesEndpoint.java new file mode 100644 index 00000000000..1f4f38bc479 --- /dev/null +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/CustomPropertiesEndpoint.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2017 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.boot.configurationsample.endpoint; + +import org.springframework.boot.configurationsample.ConfigurationProperties; +import org.springframework.boot.configurationsample.Endpoint; + +/** + * An endpoint with additional custom properties. + * + * @author Stephane Nicoll + */ +@Endpoint(id = "customprops") +@ConfigurationProperties("endpoints.customprops") +public class CustomPropertiesEndpoint { + + private String name = "test"; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/DisabledEndpoint.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/DisabledEndpoint.java new file mode 100644 index 00000000000..d3eeb2a048d --- /dev/null +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/DisabledEndpoint.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2017 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.boot.configurationsample.endpoint; + +import org.springframework.boot.configurationsample.Endpoint; + +/** + * An endpoint that is disabled by default. + * + * @author Stephane Nicoll + */ +@Endpoint(id = "disabled", enabledByDefault = false) +public class DisabledEndpoint { + +} diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyJmxEndpoint.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyJmxEndpoint.java new file mode 100644 index 00000000000..a4e86b9936a --- /dev/null +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyJmxEndpoint.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2017 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.boot.configurationsample.endpoint; + +import org.springframework.boot.configurationsample.Endpoint; + +/** + * An endpoint that only exposes a JMX MBean. + * + * @author Stephane Nicoll + */ +@Endpoint(id = "jmx", types = Endpoint.Type.JMX) +public class OnlyJmxEndpoint { + +} diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyWebEndpoint.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyWebEndpoint.java new file mode 100644 index 00000000000..687744dcb6a --- /dev/null +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/OnlyWebEndpoint.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2017 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.boot.configurationsample.endpoint; + +import org.springframework.boot.configurationsample.Endpoint; + +/** + * An endpoints that only exposes a web endpoint. + * + * @author Stephane Nicoll + */ +@Endpoint(id = "web", types = Endpoint.Type.WEB) +public class OnlyWebEndpoint { + +} diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/SimpleEndpoint.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/SimpleEndpoint.java new file mode 100644 index 00000000000..3c4805c39a1 --- /dev/null +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/SimpleEndpoint.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2017 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.boot.configurationsample.endpoint; + +import org.springframework.boot.configurationsample.Endpoint; + +/** + * A simple endpoint with no default override. + * + * @author Stephane Nicoll + */ +@Endpoint(id = "simple") +public class SimpleEndpoint { + +} diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/incremental/IncrementalEndpoint.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/incremental/IncrementalEndpoint.java new file mode 100644 index 00000000000..817d4d85ad0 --- /dev/null +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/incremental/IncrementalEndpoint.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2017 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.boot.configurationsample.endpoint.incremental; + +import org.springframework.boot.configurationsample.Endpoint; + +/** + * An endpoint that is enabled by default. + * + * @author Stephane Nicoll + */ +@Endpoint(id = "incremental") +public class IncrementalEndpoint { + +} diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/incremental/IncrementalJmxEndpoint.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/incremental/IncrementalJmxEndpoint.java new file mode 100644 index 00000000000..e2f167bd60c --- /dev/null +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/incremental/IncrementalJmxEndpoint.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2017 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.boot.configurationsample.endpoint.incremental; + +import org.springframework.boot.configurationsample.Endpoint; + +/** + * An endpoint that only exposes a JMX MBean. + * + * @author Stephane Nicoll + */ +@Endpoint(id = "incremental", types = Endpoint.Type.JMX) +public class IncrementalJmxEndpoint { + +}