camel git commit: CAMEL-11163 Add @Generated annotation in REST D...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

camel git commit: CAMEL-11163 Add @Generated annotation in REST D...

zregvart
Repository: camel
Updated Branches:
  refs/heads/master 13d16f1db -> ff463456a


CAMEL-11163 Add @Generated annotation in REST D...

SL Swagger generated code

Adds the `@Generated` annotation to the generated source code of
`RouteBuilder` implementations. This way IDEs and source code analysis
tools know that the code was generated.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ff463456
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ff463456
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ff463456

Branch: refs/heads/master
Commit: ff463456afb5a66b9576806311deb9737a00c6c7
Parents: 13d16f1
Author: Zoran Regvart <[hidden email]>
Authored: Tue Apr 18 15:08:08 2017 +0200
Committer: Zoran Regvart <[hidden email]>
Committed: Tue Apr 18 15:17:02 2017 +0200

----------------------------------------------------------------------
 .../swagger/RestDslSourceCodeGenerator.java        | 17 +++++++++++++++++
 .../generator/swagger/RestDslGeneratorTest.java    | 10 +++++++---
 .../src/test/resources/MyRestRoute.txt             |  5 +++++
 .../src/test/resources/SwaggerPetstore.txt         |  5 +++++
 4 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ff463456/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslSourceCodeGenerator.java
----------------------------------------------------------------------
diff --git a/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslSourceCodeGenerator.java b/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslSourceCodeGenerator.java
index cd27c3b..bbc4b22 100644
--- a/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslSourceCodeGenerator.java
+++ b/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslSourceCodeGenerator.java
@@ -17,11 +17,14 @@
 package org.apache.camel.generator.swagger;
 
 import java.io.IOException;
+import java.time.Instant;
 import java.util.function.Function;
 import java.util.stream.Collector;
 
+import javax.annotation.Generated;
 import javax.lang.model.element.Modifier;
 
+import com.squareup.javapoet.AnnotationSpec;
 import com.squareup.javapoet.JavaFile;
 import com.squareup.javapoet.MethodSpec;
 import com.squareup.javapoet.TypeSpec;
@@ -43,6 +46,8 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
 
     private Function<Swagger, String> classNameGenerator = RestDslSourceCodeGenerator::generateClassName;
 
+    private Instant generated = Instant.now();
+
     private String indent = DEFAULT_INDENT;
 
     private Function<Swagger, String> packageNameGenerator = RestDslSourceCodeGenerator::generatePackageName;
@@ -85,6 +90,10 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
         return emitter.result();
     }
 
+    Instant generated() {
+        return generated;
+    }
+
     JavaFile generateSourceCode() {
         final MethodSpec methodSpec = generateConfigureMethod(swagger);
 
@@ -92,6 +101,8 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
 
         final TypeSpec generatedRouteBulder = TypeSpec.classBuilder(classNameToUse).superclass(RouteBuilder.class)
             .addModifiers(Modifier.PUBLIC, Modifier.FINAL).addMethod(methodSpec)
+            .addAnnotation(AnnotationSpec.builder(Generated.class).addMember("value", "$S", getClass().getName())
+                .addMember("date", "$S", generated()).build())
             .addJavadoc("Generated from Swagger specification by Camel REST DSL generator.\n").build();
 
         final String packageNameToUse = packageNameGenerator.apply(swagger);
@@ -99,6 +110,12 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
         return JavaFile.builder(packageNameToUse, generatedRouteBulder).indent(indent).build();
     }
 
+    RestDslSourceCodeGenerator<T> withGeneratedTime(final Instant generated) {
+        this.generated = generated;
+
+        return this;
+    }
+
     static String generateClassName(final Swagger swagger) {
         final Info info = swagger.getInfo();
         if (info == null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/ff463456/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslGeneratorTest.java
----------------------------------------------------------------------
diff --git a/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslGeneratorTest.java b/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslGeneratorTest.java
index 3602654..69aee57 100644
--- a/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslGeneratorTest.java
+++ b/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslGeneratorTest.java
@@ -22,6 +22,7 @@ import java.net.URISyntaxException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import java.time.Instant;
 
 import io.swagger.models.Swagger;
 import io.swagger.parser.SwaggerParser;
@@ -35,6 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class RestDslGeneratorTest {
 
+    final Instant generated = Instant.parse("2017-10-17T00:00:00.000Z");
+
     final Swagger swagger = new SwaggerParser().read("petstore.json");
 
     @Test
@@ -50,7 +53,7 @@ public class RestDslGeneratorTest {
     public void shouldGenerateSourceCodeWithDefaults() throws IOException, URISyntaxException {
         final StringBuilder code = new StringBuilder();
 
-        RestDslGenerator.toAppendable(swagger).generate(code);
+        RestDslGenerator.toAppendable(swagger).withGeneratedTime(generated).generate(code);
 
         final URI file = RestDslGeneratorTest.class.getResource("/SwaggerPetstore.txt").toURI();
         final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
@@ -62,8 +65,9 @@ public class RestDslGeneratorTest {
     public void shouldGenerateSourceCodeWithOptions() throws IOException, URISyntaxException {
         final StringBuilder code = new StringBuilder();
 
-        RestDslGenerator.toAppendable(swagger).withClassName("MyRestRoute").withPackageName("com.example")
-            .withIndent("\t").withDestinationGenerator(o -> "direct:rest-" + o.getOperationId()).generate(code);
+        RestDslGenerator.toAppendable(swagger).withGeneratedTime(generated).withClassName("MyRestRoute")
+            .withPackageName("com.example").withIndent("\t")
+            .withDestinationGenerator(o -> "direct:rest-" + o.getOperationId()).generate(code);
 
         final URI file = RestDslGeneratorTest.class.getResource("/MyRestRoute.txt").toURI();
         final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);

http://git-wip-us.apache.org/repos/asf/camel/blob/ff463456/tooling/swagger-rest-dsl-generator/src/test/resources/MyRestRoute.txt
----------------------------------------------------------------------
diff --git a/tooling/swagger-rest-dsl-generator/src/test/resources/MyRestRoute.txt b/tooling/swagger-rest-dsl-generator/src/test/resources/MyRestRoute.txt
index 4b19f69..d782300 100644
--- a/tooling/swagger-rest-dsl-generator/src/test/resources/MyRestRoute.txt
+++ b/tooling/swagger-rest-dsl-generator/src/test/resources/MyRestRoute.txt
@@ -1,5 +1,6 @@
 package com.example;
 
+import javax.annotation.Generated;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.model.rest.CollectionFormat;
 import org.apache.camel.model.rest.RestParamType;
@@ -7,6 +8,10 @@ import org.apache.camel.model.rest.RestParamType;
 /**
  * Generated from Swagger specification by Camel REST DSL generator.
  */
+@Generated(
+ value = "org.apache.camel.generator.swagger.AppendableGenerator",
+ date = "2017-10-17T00:00:00Z"
+)
 public final class MyRestRoute extends RouteBuilder {
  /**
  * Defines Apache Camel routes using REST DSL fluent API.

http://git-wip-us.apache.org/repos/asf/camel/blob/ff463456/tooling/swagger-rest-dsl-generator/src/test/resources/SwaggerPetstore.txt
----------------------------------------------------------------------
diff --git a/tooling/swagger-rest-dsl-generator/src/test/resources/SwaggerPetstore.txt b/tooling/swagger-rest-dsl-generator/src/test/resources/SwaggerPetstore.txt
index 21d259c..6a4cb0f 100644
--- a/tooling/swagger-rest-dsl-generator/src/test/resources/SwaggerPetstore.txt
+++ b/tooling/swagger-rest-dsl-generator/src/test/resources/SwaggerPetstore.txt
@@ -1,5 +1,6 @@
 package io.swagger.petstore;
 
+import javax.annotation.Generated;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.model.rest.CollectionFormat;
 import org.apache.camel.model.rest.RestParamType;
@@ -7,6 +8,10 @@ import org.apache.camel.model.rest.RestParamType;
 /**
  * Generated from Swagger specification by Camel REST DSL generator.
  */
+@Generated(
+        value = "org.apache.camel.generator.swagger.AppendableGenerator",
+        date = "2017-10-17T00:00:00Z"
+)
 public final class SwaggerPetstore extends RouteBuilder {
     /**
      * Defines Apache Camel routes using REST DSL fluent API.

Loading...