You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/02/27 13:59:36 UTC

[incubator-plc4x] branch feature/daffodil-2.3.0 updated: - Started with the plc4x-maven-plugin

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

cdutz pushed a commit to branch feature/daffodil-2.3.0
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git


The following commit(s) were added to refs/heads/feature/daffodil-2.3.0 by this push:
     new 8b29bb5  - Started with the plc4x-maven-plugin
8b29bb5 is described below

commit 8b29bb5d3a174e42cd318b920d3351f67ac6948b
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Feb 27 14:59:31 2019 +0100

    - Started with the plc4x-maven-plugin
---
 sandbox/plc4x-maven-plugin/pom.xml                 | 184 +++++++++++++++++++++
 sandbox/plc4x-maven-plugin/src/it/settings.xml     |  37 +++++
 .../plc4x-maven-plugin/src/it/simple-it/pom.xml    |  37 +++++
 .../src/main/resources/test/protocol.dfdl.xsd      | 114 +++++++++++++
 .../src/it/simple-it/verify.groovy                 |   3 +
 .../plc4x/plugins/codegenerator/GenerateMojo.java  |  57 +++++++
 .../plugins/codegenerator/GenerateMojoTest.java    |  63 +++++++
 .../src/test/resources/project-to-test/pom.xml     |  24 +++
 8 files changed, 519 insertions(+)

diff --git a/sandbox/plc4x-maven-plugin/pom.xml b/sandbox/plc4x-maven-plugin/pom.xml
new file mode 100644
index 0000000..c4f38a9
--- /dev/null
+++ b/sandbox/plc4x-maven-plugin/pom.xml
@@ -0,0 +1,184 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+  <modelVersion>4.0.0</modelVersion>
+
+  <!--
+    This is intentionally set to the apache parent as this way
+    we can release this module separately from the rest of the project
+  -->
+  <parent>
+    <groupId>org.apache</groupId>
+    <artifactId>apache</artifactId>
+    <version>21</version>
+  </parent>
+
+  <groupId>org.apache.plc4x.plugins</groupId>
+  <artifactId>plc4x-maven-plugin</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <packaging>maven-plugin</packaging>
+
+  <name>Sandbox: PLC4X Maven Plugin</name>
+
+  <prerequisites>
+    <maven>${maven.version}</maven>
+  </prerequisites>
+
+  <properties>
+    <maven.version>3.3.9</maven.version>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>${maven.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>${maven.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>${maven.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-compat</artifactId>
+      <version>${maven.version}</version>
+      <scope>test</scope>
+    </dependency> 
+    <dependency>
+      <groupId>org.apache.maven.plugin-tools</groupId>
+      <artifactId>maven-plugin-annotations</artifactId>
+      <version>3.6.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.12</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugin-testing</groupId>
+      <artifactId>maven-plugin-testing-harness</artifactId>
+      <version>3.3.0</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
+      <plugins>
+        <plugin>
+          <artifactId>maven-clean-plugin</artifactId>
+          <version>3.1.0</version>
+        </plugin>
+        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_maven-plugin_packaging -->
+        <plugin>
+          <artifactId>maven-resources-plugin</artifactId>
+          <version>3.0.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.8.0</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-plugin-plugin</artifactId>
+          <version>3.6.0</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>2.22.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>3.0.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-install-plugin</artifactId>
+          <version>2.5.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-deploy-plugin</artifactId>
+          <version>2.8.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-invoker-plugin</artifactId>
+          <version>3.1.0</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-plugin-plugin</artifactId>
+        <version>3.6.0</version>
+        <configuration>
+          <!-- <goalPrefix>maven-archetype-plugin</goalPrefix> -->
+          <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+        </configuration>
+        <executions>
+          <execution>
+            <id>mojo-descriptor</id>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>help-goal</id>
+            <goals>
+              <goal>helpmojo</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <profiles>
+    <profile>
+      <id>run-its</id>
+      <build>
+
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-invoker-plugin</artifactId>
+            <version>3.1.0</version>
+            <configuration>
+              <debug>true</debug>
+              <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+              <pomIncludes>
+                <pomInclude>*/pom.xml</pomInclude>
+              </pomIncludes>
+              <postBuildHookScript>verify</postBuildHookScript>
+              <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
+              <settingsFile>src/it/settings.xml</settingsFile>
+              <goals>
+                <goal>clean</goal>
+                <goal>test-compile</goal>
+              </goals>
+            </configuration>
+            <executions>
+              <execution>
+                <id>integration-test</id>
+                <goals>
+                  <goal>install</goal>
+                  <goal>integration-test</goal>
+                  <goal>verify</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+</project>
diff --git a/sandbox/plc4x-maven-plugin/src/it/settings.xml b/sandbox/plc4x-maven-plugin/src/it/settings.xml
new file mode 100644
index 0000000..000e726
--- /dev/null
+++ b/sandbox/plc4x-maven-plugin/src/it/settings.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+
+<settings>
+  <profiles>
+    <profile>
+      <id>it-repo</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <repositories>
+        <repository>
+          <id>local.central</id>
+          <url>@localRepositoryUrl@</url>
+          <releases>
+            <enabled>true</enabled>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+          </snapshots>
+        </repository>
+      </repositories>
+      <pluginRepositories>
+        <pluginRepository>
+          <id>local.central</id>
+          <url>@localRepositoryUrl@</url>
+          <releases>
+            <enabled>true</enabled>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+          </snapshots>
+        </pluginRepository>
+      </pluginRepositories>
+    </profile>
+  </profiles>
+</settings>
diff --git a/sandbox/plc4x-maven-plugin/src/it/simple-it/pom.xml b/sandbox/plc4x-maven-plugin/src/it/simple-it/pom.xml
new file mode 100644
index 0000000..a506bd9
--- /dev/null
+++ b/sandbox/plc4x-maven-plugin/src/it/simple-it/pom.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.plc4x.plugins.it</groupId>
+  <artifactId>simple-it</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <description>A simple IT verifying the basic use case.</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>@project.groupId@</groupId>
+        <artifactId>@project.artifactId@</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>generate-sources</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>generate-driver</goal>
+            </goals>
+            <configuration>
+              <dfdl-schema>test/protocol.dfdl.xsd</dfdl-schema>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/sandbox/plc4x-maven-plugin/src/it/simple-it/src/main/resources/test/protocol.dfdl.xsd b/sandbox/plc4x-maven-plugin/src/it/simple-it/src/main/resources/test/protocol.dfdl.xsd
new file mode 100644
index 0000000..5e322f5
--- /dev/null
+++ b/sandbox/plc4x-maven-plugin/src/it/simple-it/src/main/resources/test/protocol.dfdl.xsd
@@ -0,0 +1,114 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you 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.
+  -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+           xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+           xmlns:knx="http://plc4x.apache.org/knxnet-ip"
+           targetNamespace="http://plc4x.apache.org/knxnet-ip">
+
+    <xs:annotation>
+        <xs:appinfo source="http://www.ogf.org/dfdl/">
+            <dfdl:defineVariable name="messageType" type="xs:string"/>
+            <dfdl:defineFormat name="knxNetIpFullFormat">
+                <dfdl:format representation="binary"
+                             binaryNumberRep="binary"
+                             byteOrder="bigEndian"
+                             lengthKind="implicit" lengthUnits="bytes" length="0"
+                             occursCountKind="implicit"
+                             textOutputMinLength="0"
+                             alignment="1" alignmentUnits="bits"
+                             leadingSkip="0" trailingSkip="0"
+                             textPadKind="none" ignoreCase="no"
+                             textBidi="no" floating="no"
+                             encoding="utf-8" truncateSpecifiedLengthString="no"
+                             initiator="" terminator=""
+                             sequenceKind="ordered" separator=""
+                             escapeSchemeRef="" initiatedContent="no"
+                             encodingErrorPolicy="replace"/>
+            </dfdl:defineFormat>
+            <dfdl:format ref="knx:knxNetIpFullFormat"/>
+        </xs:appinfo>
+    </xs:annotation>
+
+    <!--
+
+        Simple type definition.
+
+    -->
+
+    <xs:simpleType name="bit" dfdl:lengthUnits="bits" dfdl:length="1" dfdl:lengthKind="explicit">
+        <xs:restriction base="xs:boolean"/>
+    </xs:simpleType>
+
+    <xs:simpleType name="byte" dfdl:lengthUnits="bytes" dfdl:length="1" dfdl:lengthKind="explicit">
+        <xs:restriction base="xs:unsignedByte"/>
+    </xs:simpleType>
+
+    <xs:simpleType name="short" dfdl:lengthUnits="bytes" dfdl:length="2" dfdl:lengthKind="explicit">
+        <xs:restriction base="xs:unsignedShort"/>
+    </xs:simpleType>
+
+    <xs:simpleType name="hexByte" dfdl:lengthUnits="bytes" dfdl:length="1" dfdl:lengthKind="explicit">
+        <xs:restriction base="xs:hexBinary"/>
+    </xs:simpleType>
+
+    <!--
+
+        TPKT - Iso-On-TCP
+
+    -->
+
+    <xs:element name="KNXNetIPMessage" type="knx:KNXNetIPMessageType"/>
+
+    <xs:complexType name="KNXNetIPMessageType">
+        <xs:sequence>
+            <xs:element name="header">
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element name="headerLength" type="knx:byte" fixed="06"/>
+                        <xs:element name="protocolVersion" type="knx:byte" fixed="10"/>
+                        <xs:element name="serviceTypeIdentifier" type="knx:short"/>
+                        <!-- length of the entire message (including header) -->
+                        <xs:element name="totalLength" type="knx:short"/>
+                    </xs:sequence>
+                </xs:complexType>
+            </xs:element>
+            <xs:element name="body">
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element name="cEMIFrame" type="knx:cEMIFrameType"/>
+                    </xs:sequence>
+                </xs:complexType>
+            </xs:element>
+        </xs:sequence>
+    </xs:complexType>
+    http://www.eb-systeme.de/?page_id=479
+    <xs:complexType name="cEMIFrameType">
+        <xs:sequence>
+            <xs:element name="structureLength" type="knx:byte"/>
+            <xs:element name="descriptionType" type="knx:byte"/>
+            <xs:choice dfdl:choiceDispatchKey="{descriptionType}">
+                <xs:element dfdl:choiceBranchKey="" ref="knx:blah"/>
+                <xs:element dfdl:choiceBranchKey="" ref="knx:blah"/>
+                <xs:element dfdl:choiceBranchKey="" ref="knx:blah"/>
+                <xs:element dfdl:choiceBranchKey="" ref="knx:blah"/>
+            </xs:choice>
+        </xs:sequence>
+    </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
diff --git a/sandbox/plc4x-maven-plugin/src/it/simple-it/verify.groovy b/sandbox/plc4x-maven-plugin/src/it/simple-it/verify.groovy
new file mode 100644
index 0000000..37ef011
--- /dev/null
+++ b/sandbox/plc4x-maven-plugin/src/it/simple-it/verify.groovy
@@ -0,0 +1,3 @@
+File touchFile = new File( basedir, "target/touch.txt" )
+
+assert touchFile.isFile()
diff --git a/sandbox/plc4x-maven-plugin/src/main/java/org/apache/plc4x/plugins/codegenerator/GenerateMojo.java b/sandbox/plc4x-maven-plugin/src/main/java/org/apache/plc4x/plugins/codegenerator/GenerateMojo.java
new file mode 100644
index 0000000..4cab905
--- /dev/null
+++ b/sandbox/plc4x-maven-plugin/src/main/java/org/apache/plc4x/plugins/codegenerator/GenerateMojo.java
@@ -0,0 +1,57 @@
+package org.apache.plc4x.plugins.codegenerator;
+
+
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.project.MavenProject;
+
+import java.io.File;
+
+/**
+ * Generate the types, serializer and parser classes based on a DFDL shema.
+ */
+@Mojo(name = "generate-driver",
+    defaultPhase = LifecyclePhase.GENERATE_SOURCES,
+    requiresDependencyResolution = ResolutionScope.RUNTIME)
+public class GenerateMojo extends AbstractMojo {
+
+    @Parameter(defaultValue = "${project}", readonly = true, required = true)
+    private MavenProject project;
+
+    /**
+     * Where to generate the code.
+     */
+    @Parameter(defaultValue = "${project.build.directory}/generated-sources/plc4x/", property = "outputDir", required = true)
+    private File outputDirectory;
+
+    /**
+     * The path to the DFDL schema file in the modules classpath (Ideally as runtime dependency)
+     */
+    @Parameter(property = "dfdl-schema", required = true)
+    private File dfdlSchemaFile;
+
+    public void execute()
+        throws MojoExecutionException {
+
+        // Make sure the output directory exists.
+        if (!outputDirectory.exists()) {
+            if(!outputDirectory.mkdirs()) {
+                throw new MojoExecutionException("Could not generate output directory " + outputDirectory.getAbsolutePath());
+            }
+        }
+
+        try {
+            for (String runtimeClasspathElement : project.getRuntimeClasspathElements()) {
+                getLog().info("Inspecting " + runtimeClasspathElement);
+            }
+        } catch (DependencyResolutionRequiredException e) {
+            throw new MojoExecutionException("Error resolving dependencies", e);
+        }
+    }
+
+}
diff --git a/sandbox/plc4x-maven-plugin/src/test/java/org/apache/plc4x/plugins/codegenerator/GenerateMojoTest.java b/sandbox/plc4x-maven-plugin/src/test/java/org/apache/plc4x/plugins/codegenerator/GenerateMojoTest.java
new file mode 100644
index 0000000..a773aa2
--- /dev/null
+++ b/sandbox/plc4x-maven-plugin/src/test/java/org/apache/plc4x/plugins/codegenerator/GenerateMojoTest.java
@@ -0,0 +1,63 @@
+package org.apache.plc4x.plugins.codegenerator;
+
+
+import org.apache.maven.plugin.testing.MojoRule;
+import org.apache.maven.plugin.testing.WithoutMojo;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class GenerateMojoTest
+{
+    @Rule
+    public MojoRule rule = new MojoRule()
+    {
+        @Override
+        protected void before() throws Throwable 
+        {
+        }
+
+        @Override
+        protected void after()
+        {
+        }
+    };
+
+    /**
+     * @throws Exception if any
+     */
+    @Test
+    public void testSomething()
+            throws Exception
+    {
+        File pom = new File( "target/test-classes/project-to-test/" );
+        assertNotNull( pom );
+        assertTrue( pom.exists() );
+
+        GenerateMojo myMojo = (GenerateMojo) rule.lookupConfiguredMojo( pom, "generate-driver" );
+        assertNotNull( myMojo );
+        myMojo.execute();
+
+        File outputDirectory = ( File ) rule.getVariableValueFromObject( myMojo, "outputDirectory" );
+        assertNotNull( outputDirectory );
+        assertTrue( outputDirectory.exists() );
+
+        File touch = new File( outputDirectory, "touch.txt" );
+        assertTrue( touch.exists() );
+
+    }
+
+    /** Do not need the MojoRule. */
+    @WithoutMojo
+    @Test
+    public void testSomethingWhichDoesNotNeedTheMojoAndProbablyShouldBeExtractedIntoANewClassOfItsOwn()
+    {
+        assertTrue( true );
+    }
+
+}
+
diff --git a/sandbox/plc4x-maven-plugin/src/test/resources/project-to-test/pom.xml b/sandbox/plc4x-maven-plugin/src/test/resources/project-to-test/pom.xml
new file mode 100644
index 0000000..e1f3be7
--- /dev/null
+++ b/sandbox/plc4x-maven-plugin/src/test/resources/project-to-test/pom.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.plc4x.plugins</groupId>
+  <artifactId>plc4x-maven-plugin</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <name>Test MyMojo</name>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-my-plugin</artifactId>
+        <configuration>
+          <!-- Specify the MyMojo parameter -->
+          <outputDirectory>target/test-harness/project-to-test</outputDirectory>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>