You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by ld...@apache.org on 2021/07/29 11:17:22 UTC

[plc4x-build-tools] branch feature/PLC4X-307 created (now f982db0)

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

ldywicki pushed a change to branch feature/PLC4X-307
in repository https://gitbox.apache.org/repos/asf/plc4x-build-tools.git.


      at f982db0  PLC4X-307 Support for custom packages.

This branch includes the following new commits:

     new f982db0  PLC4X-307 Support for custom packages.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[plc4x-build-tools] 01/01: PLC4X-307 Support for custom packages.

Posted by ld...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ldywicki pushed a commit to branch feature/PLC4X-307
in repository https://gitbox.apache.org/repos/asf/plc4x-build-tools.git

commit f982db079b6df6588a5c9801a67f875651951316
Author: Ɓukasz Dywicki <lu...@code-house.org>
AuthorDate: Thu Jul 29 13:16:04 2021 +0200

    PLC4X-307 Support for custom packages.
    
    Introduced API changes which allows to pass to generator options in form of key value pairs.
    Underlying generator implementation might utilize that for further customization of code output.
---
 .../plugins/codegenerator/language/LanguageOutput.java   | 12 +++++++++++-
 .../apache/plc4x/plugins/codegenerator/GenerateMojo.java | 16 +++++++++++++++-
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/code-generation/language-base/src/main/java/org/apache/plc4x/plugins/codegenerator/language/LanguageOutput.java b/code-generation/language-base/src/main/java/org/apache/plc4x/plugins/codegenerator/language/LanguageOutput.java
index 7ea5cf6..35da9f0 100644
--- a/code-generation/language-base/src/main/java/org/apache/plc4x/plugins/codegenerator/language/LanguageOutput.java
+++ b/code-generation/language-base/src/main/java/org/apache/plc4x/plugins/codegenerator/language/LanguageOutput.java
@@ -19,6 +19,7 @@
 
 package org.apache.plc4x.plugins.codegenerator.language;
 
+import java.util.Set;
 import org.apache.plc4x.plugins.codegenerator.types.definitions.TypeDefinition;
 import org.apache.plc4x.plugins.codegenerator.types.exceptions.GenerationException;
 
@@ -37,7 +38,16 @@ public interface LanguageOutput {
 
     List<String> supportedOutputFlavors();
 
-    void generate(File outputDir, String languageName, String protocolName, String outputFlavor, Map<String, TypeDefinition> types)
+    /**
+     * An additional method which allows generator to hive a hing which options are supported by it.
+     * This method might be used to improve user experience and warn him if he sets options generator does not support.
+     *
+     * @return Set containing names of options this language output can accept.
+     */
+    Set<String> supportedOptions();
+
+    void generate(File outputDir, String languageName, String protocolName, String outputFlavor, Map<String, TypeDefinition> types,
+        Map<String, String> options)
         throws GenerationException;
 
 }
diff --git a/code-generation/plc4x-maven-plugin/src/main/java/org/apache/plc4x/plugins/codegenerator/GenerateMojo.java b/code-generation/plc4x-maven-plugin/src/main/java/org/apache/plc4x/plugins/codegenerator/GenerateMojo.java
index 4826ff1..160c4af 100644
--- a/code-generation/plc4x-maven-plugin/src/main/java/org/apache/plc4x/plugins/codegenerator/GenerateMojo.java
+++ b/code-generation/plc4x-maven-plugin/src/main/java/org/apache/plc4x/plugins/codegenerator/GenerateMojo.java
@@ -72,6 +72,12 @@ public class GenerateMojo extends AbstractMojo {
     @Parameter(required = true)
     private String outputFlavor;
 
+    /**
+     * Additional options which should be passed to code generator.
+     */
+    @Parameter(required = false)
+    private Map<String, String> options;
+
     public void execute()
         throws MojoExecutionException {
 
@@ -138,9 +144,17 @@ public class GenerateMojo extends AbstractMojo {
         try {
             // Parse the type definitions.
             Map<String, TypeDefinition> types = protocol.getTypeDefinitions();
+            Set<String> supportedOptions = language.supportedOptions();
+            if (options != null) {
+                for (String option : options.keySet()) {
+                    if (!supportedOptions.contains(option)) {
+                        throw new MojoExecutionException("Unsupported option '" + option + "' for language " + languageName);
+                    }
+                }
+            }
 
             // Generate output for the type definitions.
-            language.generate(outputDir, languageName, protocolName, outputFlavor, types);
+            language.generate(outputDir, languageName, protocolName, outputFlavor, types, options == null ? Collections.emptyMap() : options);
         } catch (GenerationException e) {
             throw new MojoExecutionException("Error generating sources", e);
         }