Skip to content
Permalink
Browse files

feat (#354): Add the ability to use annotationless style with generic

java applications. Add vertx examples.
  • Loading branch information...
iocanel committed Oct 7, 2019
1 parent 9cbbbfe commit 3b6ba30cbcda481f3152a3e2faaaf5e80d557a3e
@@ -90,6 +90,91 @@ limitations under the License.
</annotationProcessors>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${version.maven-shade-plugin}</version>
<executions>
<execution>
<id>annotation</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>annotations</shadedClassifierName>
<filters>
<filter>
<artifact>*:*</artifact>
<includes>
<include>io/dekorate/kubernetes/annotation/**</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
<execution>
<id>processor</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>processors</shadedClassifierName>
<filters>
<filter>
<artifact>*:*</artifact>
<includes>
<include>io/dekorate/adapter/**</include>
<include>io/dekorate/apt/**</include>
<include>io/dekorate/annotation/**</include>
<include>io/dekorate/config/**</include>
<include>io/dekorate/doc/**</include>
<include>io/dekorate/hook/**</include>
<include>io/dekorate/kubernetes/**</include>
<include>io/dekorate/logger/**</include>
<include>io/dekorate/processor/**</include>
<include>io/dekorate/project/**</include>
<include>io/dekorate/utils/**</include>
<include>META-INF/services/*</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
<execution>
<id>noapt</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>noapt</shadedClassifierName>
<filters>
<filter>
<artifact>*:*</artifact>
<includes>
<include>io/dekorate/adapter/**</include>
<include>io/dekorate/annotation/**</include>
<include>io/dekorate/config/**</include>
<include>io/dekorate/doc/**</include>
<include>io/dekorate/hook/**</include>
<include>io/dekorate/kubernetes/**</include>
<include>io/dekorate/logger/**</include>
<include>io/dekorate/processor/**</include>
<include>io/dekorate/project/**</include>
<include>io/dekorate/utils/**</include>
<include>META-INF/services/io.dekorate.*</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,44 @@
/**
* Copyright 2018 The original 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 io.dekorate.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import io.sundr.builder.annotations.Adapter;
import io.sundr.builder.annotations.Buildable;
import io.sundr.builder.annotations.Pojo;

/**
* This annotations is meant to be used as a trigger of the dekorate process.
*/

@Buildable(builderPackage = "io.dekorate.deps.kubernetes.api.builder")
@Pojo(name = "DekorateConifg", relativePath = "../config",
mutable = true,
withStaticBuilderMethod = false,
withStaticAdapterMethod = false,
adapter = @Adapter(suffix = "Adapter", relativePath = "../adapter", withMapAdapterMethod = true))
@Target({ElementType.CONSTRUCTOR, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
public @interface Dekorate {

String[] resources() default {};
}
@@ -0,0 +1,66 @@
/**
* Copyright 2018 The original 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 io.dekorate.apt;

import java.util.Set;

import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;

import io.dekorate.annotation.Dekorate;
import io.dekorate.Logger;
import io.dekorate.LoggerFactory;
import io.dekorate.Session;
import io.dekorate.adapter.DekorateConifgAdapter;
import io.dekorate.config.DekorateConifg;
import io.dekorate.doc.Description;
import io.dekorate.processor.AbstractAnnotationProcessor;

@Description("Detects @Dekorate and configures application based on the specified configuration files.")
@SupportedAnnotationTypes({"io.dekorate.annotation.Dekorate"})
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class DekorateProcessor extends AbstractAnnotationProcessor {

private static final String[] DEFAULT_CONFIG_FILES = { "application.properties", "application.yml" };
private final Logger LOGGER = LoggerFactory.getLogger();

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Session session = Session.getSession();
if (roundEnv.processingOver()) {
session.close();
return true;
}

for (TypeElement typeElement : annotations) {
for (Element mainClass : roundEnv.getElementsAnnotatedWith(typeElement)) {
LOGGER.info("Found @Dekorate on: " + mainClass.toString());
Dekorate dekorate = mainClass.getAnnotation(Dekorate.class);
DekorateConifg dekorateConfig = DekorateConifgAdapter.adapt(dekorate);
String[] configFiles = dekorateConfig.getResources().length > 0 ? dekorateConfig.getResources() : DEFAULT_CONFIG_FILES;
session.feed(readApplicationConfig(configFiles));
}
}

return false;
}
}
@@ -39,7 +39,7 @@
withStaticAdapterMethod = false)
@Target({ElementType.CONSTRUCTOR, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
@interface Dekorate {
@interface Base {

/**
* The group of the application.
@@ -0,0 +1 @@
io.dekorate.apt.DekorateProcessor
@@ -31,6 +31,8 @@
<module>pojo-to-custom-resource-example</module>
<module>thorntail-on-kubernetes-example</module>
<module>thorntail-on-openshift-example</module>
<module>vertx-on-kubernetes-example</module>
<module>vertx-on-openshift-example</module>
</modules>

<profiles>
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2018 The original 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>examples</artifactId>
<groupId>io.dekorate</groupId>
<version>0.9-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>vertx-on-kubernetes-example</artifactId>
<name>Dekorate :: Examples :: Vertx on Kuberentes</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<version.vertx>3.8.2</version.vertx>
<version.maven-compiler-plugin>3.3</version.maven-compiler-plugin>
</properties>

<dependencies>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>kubernetes-annotations</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${version.vertx}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.maven-compiler-plugin}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,43 @@
/**
* Copyright 2018 The original 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 io.dekorate.example;

import io.dekorate.annotation.Dekorate;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;

@Dekorate
public class Main extends AbstractVerticle {

@Override
public void start(Future<Void> future) {
vertx
.createHttpServer()
.requestHandler(r -> {
r.response().end("hello world!");
})
.listen(8080, result -> {
if (result.succeeded()) {
future.complete();
} else {
future.fail(result.cause());
}
});
}
}
@@ -0,0 +1,5 @@
dekorate.kubernetes.ports[0].name=http
dekorate.kubernetes.ports[0].containerPort=8080
dekorate.kubernetes.readinessProbe.httpActionPath=/
dekorate.kubernetes.readinessProbe.periodSeconds=30
dekorate.kubernetes.readinessProbe.timeoutSeconds=10
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2018 The original 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>examples</artifactId>
<groupId>io.dekorate</groupId>
<version>0.9-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>vertx-on-openshift-example</artifactId>
<name>Dekorate :: Examples :: Vertx on Openshift</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<version.vertx>3.8.2</version.vertx>
<version.maven-compiler-plugin>3.3</version.maven-compiler-plugin>
</properties>

<dependencies>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>openshift-annotations</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${version.vertx}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.maven-compiler-plugin}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 3b6ba30

Please sign in to comment.
You can’t perform that action at this time.