Search in sources :

Example 1 with Configuration

use of org.apache.deltaspike.core.api.config.Configuration in project component-runtime by Talend.

the class Generator method generatedServerConfiguration.

private static void generatedServerConfiguration(final File generatedDir) throws MalformedURLException {
    final File file = new File(generatedDir, "generated_server-configuration.adoc");
    try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) {
        stream.println("");
        stream.println("NOTE: the configuration is read from system properties, environment variables, ....");
        stream.println("");
        stream.println("[role=\"table-striped table-hover table-ordered\",options=\"header,autowidth\"]");
        stream.println("|====");
        stream.println("|Key|Description|Default");
        final File api = jarLocation(ComponentServerConfiguration.class);
        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
        final AnnotationFinder finder = new AnnotationFinder(api.isDirectory() ? new FileArchive(loader, api) : new JarArchive(loader, api.toURI().toURL()));
        finder.findAnnotatedClasses(Configuration.class).stream().flatMap(c -> Stream.of(c.getMethods())).map(method -> {
            final ConfigProperty configProperty = method.getAnnotation(ConfigProperty.class);
            final String name = method.getDeclaringClass().getAnnotation(Configuration.class).prefix() + method.getAnnotation(ConfigProperty.class).name();
            return "|" + name + "|" + method.getAnnotation(Documentation.class).value() + "|" + (ConfigProperty.NULL.equalsIgnoreCase(configProperty.defaultValue()) ? "-" : configProperty.defaultValue());
        }).sorted().forEach(stream::println);
        stream.println("|====");
        stream.println();
    }
}
Also used : Condition(org.talend.sdk.component.api.configuration.condition.meta.Condition) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) ConfigurationTypeParameterEnricher(org.talend.sdk.component.runtime.manager.reflect.parameterenricher.ConfigurationTypeParameterEnricher) Type(org.talend.sdk.component.api.service.schema.Type) Collectors.toMap(java.util.stream.Collectors.toMap) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) Defaults(org.talend.sdk.component.runtime.reflect.Defaults) ENGLISH(java.util.Locale.ENGLISH) UiParameterEnricher(org.talend.sdk.component.runtime.manager.reflect.parameterenricher.UiParameterEnricher) Collectors.toSet(java.util.stream.Collectors.toSet) Validations(org.talend.sdk.component.api.configuration.constraint.meta.Validations) JsonbBuilder(javax.json.bind.JsonbBuilder) ActiveIf(org.talend.sdk.component.api.configuration.condition.ActiveIf) Collection(java.util.Collection) Ui(org.talend.sdk.component.api.configuration.ui.meta.Ui) Mapper(org.apache.johnzon.mapper.Mapper) Set(java.util.Set) FilterOutputStream(java.io.FilterOutputStream) PropertyOrderStrategy(javax.json.bind.config.PropertyOrderStrategy) Collectors.joining(java.util.stream.Collectors.joining) StandardCharsets(java.nio.charset.StandardCharsets) InvocationTargetException(java.lang.reflect.InvocationTargetException) GenericType(javax.ws.rs.core.GenericType) Base64(java.util.Base64) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Documentation(org.talend.sdk.component.api.meta.Documentation) Modifier(java.lang.reflect.Modifier) Annotation(java.lang.annotation.Annotation) Configuration(org.apache.deltaspike.core.api.config.Configuration) PRIVATE(lombok.AccessLevel.PRIVATE) MapperBuilder(org.apache.johnzon.mapper.MapperBuilder) Proxy(java.lang.reflect.Proxy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Client(javax.ws.rs.client.Client) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) Function(java.util.function.Function) Supplier(java.util.function.Supplier) JsonbConfig(javax.json.bind.JsonbConfig) AutoLayout(org.talend.sdk.component.api.configuration.ui.layout.AutoLayout) Schema(org.talend.sdk.component.api.service.schema.Schema) ValidationParameterEnricher(org.talend.sdk.component.runtime.manager.reflect.parameterenricher.ValidationParameterEnricher) ConfigProperty(org.apache.deltaspike.core.api.config.ConfigProperty) FileArchive(org.apache.xbean.finder.archive.FileArchive) ArrayList(java.util.ArrayList) ClientBuilder(javax.ws.rs.client.ClientBuilder) ComponentServerConfiguration(org.talend.sdk.component.server.configuration.ComponentServerConfiguration) Collectors.mapping(java.util.stream.Collectors.mapping) Validation(org.talend.sdk.component.api.configuration.constraint.meta.Validation) ConfigurationType(org.talend.sdk.component.api.configuration.type.meta.ConfigurationType) GridLayout(org.talend.sdk.component.api.configuration.ui.layout.GridLayout) Comparator.comparing(java.util.Comparator.comparing) JsonbJaxrsProvider(org.apache.johnzon.jaxrs.jsonb.jaxrs.JsonbJaxrsProvider) ValidationResult(org.talend.sdk.component.api.service.asyncvalidation.ValidationResult) ConditionParameterEnricher(org.talend.sdk.component.runtime.manager.reflect.parameterenricher.ConditionParameterEnricher) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) BaseEnvironmentProvider(org.talend.sdk.component.junit.environment.BaseEnvironmentProvider) ParameterExtensionEnricher(org.talend.sdk.component.spi.parameter.ParameterExtensionEnricher) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) JarArchive(org.apache.xbean.finder.archive.JarArchive) Values(org.talend.sdk.component.api.service.completion.Values) Optional.ofNullable(java.util.Optional.ofNullable) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) TreeMap(java.util.TreeMap) HealthCheckStatus(org.talend.sdk.component.api.service.healthcheck.HealthCheckStatus) JarLocation.jarLocation(org.apache.ziplock.JarLocation.jarLocation) Data(lombok.Data) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) Jsonb(javax.json.bind.Jsonb) WebTarget(javax.ws.rs.client.WebTarget) Comparator(java.util.Comparator) ActionType(org.talend.sdk.component.api.service.ActionType) NoArgsConstructor(lombok.NoArgsConstructor) PrintStream(java.io.PrintStream) Configuration(org.apache.deltaspike.core.api.config.Configuration) ComponentServerConfiguration(org.talend.sdk.component.server.configuration.ComponentServerConfiguration) JarArchive(org.apache.xbean.finder.archive.JarArchive) ConfigProperty(org.apache.deltaspike.core.api.config.ConfigProperty) FileArchive(org.apache.xbean.finder.archive.FileArchive) File(java.io.File) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder)

Example 2 with Configuration

use of org.apache.deltaspike.core.api.config.Configuration in project deltaspike by apache.

the class ProxyConfigurationLifecycle method create.

@Override
public Object create(final Bean bean, final CreationalContext creationalContext) {
    // TODO: support partialbean binding? can make sense for virtual properties + would integrate with jcache
    // we'd need to add @PartialBeanBinding on a bean created from ConfigurationHandler
    // detection can just be a loadClass of this API
    // for now: waiting for user request for it
    final Configuration configuration = api[0].getAnnotation(Configuration.class);
    final long cacheFor = configuration.cacheFor();
    return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), api, new ConfigurationHandler(cacheFor <= 0 ? -1 : configuration.cacheUnit().toMillis(cacheFor), configuration.prefix()));
}
Also used : Configuration(org.apache.deltaspike.core.api.config.Configuration)

Aggregations

Configuration (org.apache.deltaspike.core.api.config.Configuration)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FilterOutputStream (java.io.FilterOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 Annotation (java.lang.annotation.Annotation)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Modifier (java.lang.reflect.Modifier)1 Proxy (java.lang.reflect.Proxy)1 MalformedURLException (java.net.MalformedURLException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1 Base64 (java.util.Base64)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Comparator.comparing (java.util.Comparator.comparing)1