You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by va...@apache.org on 2020/10/13 08:21:20 UTC

[camel-kafka-connector] branch master updated: ISSUE-146 Prevent the overwrite of existing classes unless they are @Generated annotated (#576)

This is an automated email from the ASF dual-hosted git repository.

valdar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector.git


The following commit(s) were added to refs/heads/master by this push:
     new e8b65ce  ISSUE-146 Prevent the overwrite of existing classes unless they are @Generated annotated (#576)
e8b65ce is described below

commit e8b65ceb55b84ba3905470c139f3db8fd3719ec7
Author: Tom Cunningham <tc...@redhat.com>
AuthorDate: Tue Oct 13 04:21:10 2020 -0400

    ISSUE-146 Prevent the overwrite of existing classes unless they are @Generated annotated (#576)
    
    * ISSUE-146 Prevent the overwrite of existing classes unless they are @Generated annotated
    
    * Remove TODO
---
 .../README.adoc                                     | 21 ++++++++++++++++++++-
 .../kafkaconnector/maven/utils/MavenUtils.java      | 12 +++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/tooling/camel-kafka-connector-generator-maven-plugin/README.adoc b/tooling/camel-kafka-connector-generator-maven-plugin/README.adoc
index bf4640a..a1ada18 100644
--- a/tooling/camel-kafka-connector-generator-maven-plugin/README.adoc
+++ b/tooling/camel-kafka-connector-generator-maven-plugin/README.adoc
@@ -1,3 +1,22 @@
 == Camel Kafka Connector generator plugin
 
-//TODO: write the plugin documentation
+The Camel Kafka Connector generator plugin allows you to generator connectors based off of a catalog of camel components.
+
+=== Goals Supported
+
+| Goal | Description |
+| ------------- | ----------- |
+| generate-camel-kafka-connectors | Generate connectors based off of a catalog |
+
+=== Options
+
+| Parameter | Default Value | Description |
+| --------- | ------------- | ----------- |
+| excludedComponents | empty | components to exclude from connector generation |
+| overridePomFile | false | regenerate the pom file completely even if one exists |
+| initialPomTemplate | empty | Initial pom template |
+| noticeTemplate | empty | Initial NOTICE template |
+| licenseTemplate | empty | Inintial LICENSES template |
+| fixDependenciesProperties | Properties file to configure additional dependencies |
+| packageFileTemplate | Package file template to be placed in src/main/assembly/package.xml |
+| exampleSinkPropertiesFileTemplate | Example connector sink file template |
diff --git a/tooling/camel-kafka-connector-generator-maven-plugin/src/main/java/org/apache/camel/kafkaconnector/maven/utils/MavenUtils.java b/tooling/camel-kafka-connector-generator-maven-plugin/src/main/java/org/apache/camel/kafkaconnector/maven/utils/MavenUtils.java
index c3aed14..1e26f4e 100644
--- a/tooling/camel-kafka-connector-generator-maven-plugin/src/main/java/org/apache/camel/kafkaconnector/maven/utils/MavenUtils.java
+++ b/tooling/camel-kafka-connector-generator-maven-plugin/src/main/java/org/apache/camel/kafkaconnector/maven/utils/MavenUtils.java
@@ -60,6 +60,7 @@ import freemarker.template.Template;
 import freemarker.template.TemplateException;
 import org.apache.camel.tooling.util.PackageHelper;
 import org.apache.camel.tooling.util.srcgen.JavaClass;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.logging.Log;
@@ -271,8 +272,17 @@ public final class MavenUtils {
     }
 
     public static void writeSourceIfChanged(String source, String fileName, File baseDir, File javaFileHeader) throws MojoFailureException {
-        //TODO: Do not write class if a class already exist and has no @generated annotation.
         File target = new File(new File(baseDir, "src/main/java"), fileName);
+        if (target.exists()) {
+            try {
+                if (!FileUtils.readFileToString(target).contains("@Generated")) {
+                    // Do not write class if a class already exists and has no @Generated annotation
+                    return;
+                }
+            } catch (IOException ioe) {
+                throw new MojoFailureException("IO error trying to read whether " + target.toString() + " contains @Generated annotation", ioe);
+            }
+        }
 
         deleteFile(baseDir, target);