<?xml version="1.0" encoding="UTF-8"?>
<!--
  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

      https://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">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.apache.plc4x</groupId>
    <artifactId>plc4x-parent</artifactId>
    <version>0.10.0</version>
  </parent>

  <artifactId>plc4go</artifactId>
  <packaging>mvn-golang</packaging>

  <name>PLC4Go</name>
  <description>Implementation of the protocol adapters for usage as Go(lang) library.</description>

  <properties>
    <!-- Tell Sonar where to find the sources -->
    <sonar.sources>examples,internal,pkg,tools</sonar.sources>
    <maven.install.skip>true</maven.install.skip>
    <!-- The deploy-goal of the go plugin uses go install to install the result, unfortunately disabling the deploy, disables the go install. -->
    <!--maven.deploy.skip>true</maven.deploy.skip-->
  </properties>

  <build>
    <sourceDirectory>pkg</sourceDirectory>
    <plugins>
      <!--
        Copy the test-resources in here
      -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack-protocol-test-suites</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.apache.plc4x</groupId>
                  <artifactId>plc4x-protocols-ab-eth</artifactId>
                  <classifier>tests</classifier>
                  <type>test-jar</type>
                  <outputDirectory>${project.basedir}/assets/testing</outputDirectory>
                  <includes>**/*.xml</includes>
                  <excludes>META-INF/**</excludes>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.plc4x</groupId>
                  <artifactId>plc4x-protocols-ads</artifactId>
                  <classifier>tests</classifier>
                  <type>test-jar</type>
                  <outputDirectory>${project.basedir}/assets/testing</outputDirectory>
                  <includes>**/*.xml</includes>
                  <excludes>META-INF/**</excludes>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.plc4x</groupId>
                  <artifactId>plc4x-protocols-bacnetip</artifactId>
                  <classifier>tests</classifier>
                  <type>test-jar</type>
                  <outputDirectory>${project.basedir}/assets/testing</outputDirectory>
                  <includes>**/*.xml</includes>
                  <excludes>META-INF/**</excludes>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.plc4x</groupId>
                  <artifactId>plc4x-protocols-c-bus</artifactId>
                  <classifier>tests</classifier>
                  <type>test-jar</type>
                  <outputDirectory>${project.basedir}/assets/testing</outputDirectory>
                  <includes>**/*.xml</includes>
                  <excludes>META-INF/**</excludes>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.plc4x</groupId>
                  <artifactId>plc4x-protocols-df1</artifactId>
                  <classifier>tests</classifier>
                  <type>test-jar</type>
                  <outputDirectory>${project.basedir}/assets/testing</outputDirectory>
                  <includes>**/*.xml</includes>
                  <excludes>META-INF/**</excludes>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.plc4x</groupId>
                  <artifactId>plc4x-protocols-eip</artifactId>
                  <classifier>tests</classifier>
                  <type>test-jar</type>
                  <outputDirectory>${project.basedir}/assets/testing</outputDirectory>
                  <includes>**/*.xml</includes>
                  <excludes>META-INF/**</excludes>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.plc4x</groupId>
                  <artifactId>plc4x-protocols-firmata</artifactId>
                  <classifier>tests</classifier>
                  <type>test-jar</type>
                  <outputDirectory>${project.basedir}/assets/testing</outputDirectory>
                  <includes>**/*.xml</includes>
                  <excludes>META-INF/**</excludes>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.plc4x</groupId>
                  <artifactId>plc4x-protocols-knxnetip</artifactId>
                  <classifier>tests</classifier>
                  <type>test-jar</type>
                  <outputDirectory>${project.basedir}/assets/testing</outputDirectory>
                  <includes>**/*.xml</includes>
                  <excludes>META-INF/**,org/**</excludes>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.plc4x</groupId>
                  <artifactId>plc4x-protocols-modbus</artifactId>
                  <classifier>tests</classifier>
                  <type>test-jar</type>
                  <outputDirectory>${project.basedir}/assets/testing</outputDirectory>
                  <includes>**/*.xml</includes>
                  <excludes>META-INF/**</excludes>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.plc4x</groupId>
                  <artifactId>plc4x-protocols-s7</artifactId>
                  <classifier>tests</classifier>
                  <type>test-jar</type>
                  <outputDirectory>${project.basedir}/assets/testing</outputDirectory>
                  <includes>**/*.xml</includes>
                  <excludes>META-INF/**,org/**</excludes>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.plc4x</groupId>
                  <artifactId>plc4x-protocols-simulated</artifactId>
                  <classifier>tests</classifier>
                  <type>test-jar</type>
                  <outputDirectory>${project.basedir}/assets/testing</outputDirectory>
                  <includes>**/*.xml</includes>
                  <excludes>META-INF/**,org/**</excludes>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!--
        Generate the driver code.
      -->
      <plugin>
        <groupId>org.apache.plc4x.plugins</groupId>
        <artifactId>plc4x-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>generate-driver-ab-eth</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-driver</goal>
            </goals>
            <configuration>
              <protocolName>ab-eth</protocolName>
              <languageName>go</languageName>
              <outputFlavor>read-write</outputFlavor>
              <outputDir>${project.basedir}/protocols</outputDir>
            </configuration>
          </execution>
           <execution>
            <id>generate-driver-ads</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-driver</goal>
            </goals>
            <configuration>
              <protocolName>ads</protocolName>
              <languageName>go</languageName>
              <outputFlavor>read-write</outputFlavor>
              <outputDir>${project.basedir}/protocols</outputDir>
            </configuration>
          </execution>
          <execution>
            <id>generate-driver-bacnetip</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-driver</goal>
            </goals>
            <configuration>
              <protocolName>bacnetip</protocolName>
              <languageName>go</languageName>
              <outputFlavor>read-write</outputFlavor>
              <outputDir>${project.basedir}/protocols</outputDir>
            </configuration>
          </execution>
          <execution>
            <id>generate-driver-c-bus</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-driver</goal>
            </goals>
            <configuration>
              <protocolName>c-bus</protocolName>
              <languageName>go</languageName>
              <outputFlavor>read-write</outputFlavor>
              <outputDir>${project.basedir}/protocols</outputDir>
            </configuration>
          </execution>
          <execution>
            <id>generate-driver-df1</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-driver</goal>
            </goals>
            <configuration>
              <protocolName>df1</protocolName>
              <languageName>go</languageName>
              <outputFlavor>read-write</outputFlavor>
              <outputDir>${project.basedir}/protocols</outputDir>
            </configuration>
          </execution>
          <execution>
            <id>generate-driver-eip</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-driver</goal>
            </goals>
            <configuration>
              <protocolName>eip</protocolName>
              <languageName>go</languageName>
              <outputFlavor>read-write</outputFlavor>
              <outputDir>${project.basedir}/protocols</outputDir>
            </configuration>
          </execution>
          <execution>
            <id>generate-driver-firmata</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-driver</goal>
            </goals>
            <configuration>
              <protocolName>firmata</protocolName>
              <languageName>go</languageName>
              <outputFlavor>read-write</outputFlavor>
              <outputDir>${project.basedir}/protocols</outputDir>
            </configuration>
          </execution>
          <execution>
            <id>generate-driver-knxnetip</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-driver</goal>
            </goals>
            <configuration>
              <protocolName>knxnetip</protocolName>
              <languageName>go</languageName>
              <outputFlavor>read-write</outputFlavor>
              <outputDir>${project.basedir}/protocols</outputDir>
            </configuration>
          </execution>
          <execution>
            <id>generate-driver-modbus</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-driver</goal>
            </goals>
            <configuration>
              <protocolName>modbus</protocolName>
              <languageName>go</languageName>
              <outputFlavor>read-write</outputFlavor>
              <outputDir>${project.basedir}/protocols</outputDir>
            </configuration>
          </execution>
          <execution>
            <id>generate-driver-s7</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-driver</goal>
            </goals>
            <configuration>
              <protocolName>s7</protocolName>
              <languageName>go</languageName>
              <outputFlavor>read-write</outputFlavor>
              <outputDir>${project.basedir}/protocols</outputDir>
            </configuration>
          </execution>
          <execution>
            <id>generate-driver-simulated</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate-driver</goal>
            </goals>
            <configuration>
              <protocolName>simulated</protocolName>
              <languageName>go</languageName>
              <outputFlavor>read-write</outputFlavor>
              <outputDir>${project.basedir}/protocols</outputDir>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>com.igormaznitsa</groupId>
        <artifactId>mvn-golang-wrapper</artifactId>
        <version>2.3.10</version>
        <extensions>true</extensions>
        <executions>
          <!-- add tools required for generating code, test, etc-->
          <execution>
            <id>get-stringer</id>
            <phase>initialize</phase>
            <goals>
              <goal>install</goal>
            </goals>
            <configuration>
              <packages>
                <package>golang.org/x/tools/cmd/stringer@latest</package>
              </packages>
            </configuration>
          </execution>
          <execution>
            <id>get-licenser</id>
            <phase>initialize</phase>
            <goals>
              <goal>install</goal>
            </goals>
            <configuration>
              <packages>
                <package>github.com/elastic/go-licenser@latest</package>
              </packages>
            </configuration>
          </execution>
          <execution>
            <id>get-goxunit</id>
            <phase>initialize</phase>
            <goals>
              <goal>install</goal>
            </goals>
            <configuration>
              <packages>
                <package>github.com/tebeka/go2xunit@latest</package>
              </packages>
            </configuration>
          </execution>
          <execution>
            <id>get-gotestsum</id>
            <phase>initialize</phase>
            <goals>
              <goal>install</goal>
            </goals>
            <configuration>
              <packages>
                <package>gotest.tools/gotestsum@latest</package>
              </packages>
            </configuration>
          </execution>

          <!-- Run the go code-generation -->
          <execution>
            <id>default-generate</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <packages>
                <!-- We want to format every package here, so we don't get dirty commits -->
                <package>./...</package>
              </packages>
            </configuration>
          </execution>

          <!-- Add the apache license header to stuff generated by the stringer -->
          <!--
            NOTE: Don't try merging the following 4 executions ...
                  It doesn't work by merging the "packages" sections
            TODO: The licenser adds a version of the Apache Header with http url
          -->
          <execution>
            <id>add-license</id>
            <phase>process-sources</phase>
            <goals>
              <goal>custom</goal>
            </goals>
            <configuration>
              <exec>go-licenser</exec>
              <customCommand>-licensor</customCommand>
              <buildFlags>
                <flag>Apache Software Foundation (ASF)</flag>
              </buildFlags>
              <packages>
                <package>internal/modbus/fieldtype_string.go</package>
              </packages>
            </configuration>
          </execution>
          <execution>
            <id>add-license2</id>
            <phase>process-sources</phase>
            <goals>
              <goal>custom</goal>
            </goals>
            <configuration>
              <exec>go-licenser</exec>
              <customCommand>-licensor</customCommand>
              <buildFlags>
                <flag>Apache Software Foundation (ASF)</flag>
              </buildFlags>
              <packages>
                <package>internal/ads/fieldtype_string.go</package>
              </packages>
            </configuration>
          </execution>
          <execution>
            <id>add-license3</id>
            <phase>process-sources</phase>
            <goals>
              <goal>custom</goal>
            </goals>
            <configuration>
              <exec>go-licenser</exec>
              <customCommand>-licensor</customCommand>
              <buildFlags>
                <flag>Apache Software Foundation (ASF)</flag>
              </buildFlags>
              <packages>
                <package>internal/cbus/fieldtype_string.go</package>
              </packages>
            </configuration>
          </execution>
          <execution>
            <id>add-license4</id>
            <phase>process-sources</phase>
            <goals>
              <goal>custom</goal>
            </goals>
            <configuration>
              <exec>go-licenser</exec>
              <customCommand>-licensor</customCommand>
              <buildFlags>
                <flag>Apache Software Foundation (ASF)</flag>
              </buildFlags>
              <packages>
                <package>internal/s7/fieldtype_string.go</package>
              </packages>
            </configuration>
          </execution>
          <execution>
            <id>add-license5</id>
            <phase>process-sources</phase>
            <goals>
              <goal>custom</goal>
            </goals>
            <configuration>
              <exec>go-licenser</exec>
              <customCommand>-licensor</customCommand>
              <buildFlags>
                <flag>Apache Software Foundation (ASF)</flag>
              </buildFlags>
              <packages>
                <package>spi/testutils/steptype_string.go</package>
              </packages>
            </configuration>
          </execution>

          <!-- Processes code that uses old APIs and rewrites them use newer ones -->
          <execution>
            <id>default-fix</id>
            <phase>process-sources</phase>
            <goals>
              <goal>fix</goal>
            </goals>
          </execution>

          <!-- Format the codebase correctly (this mainly has an effect on generated code) -->
          <execution>
            <id>default-fmt</id>
            <phase>process-sources</phase>
            <goals>
              <goal>fmt</goal>
            </goals>
            <configuration>
              <packages>
                <!-- We want to format every package here so we don't get dirty commits -->
                <package>./...</package>
              </packages>
            </configuration>
          </execution>

          <!-- Get all dependencies for test cases -->
          <execution>
            <id>get-test-dependencies</id>
            <phase>generate-test-sources</phase>
            <goals>
              <goal>get</goal>
            </goals>
            <configuration>
              <buildFlags>
                <flag>-t</flag>
              </buildFlags>
              <packages>
                <package>./...</package>
              </packages>
            </configuration>
          </execution>

          <!-- Check all tests with producing report file in Golang format -->
          <execution>
            <id>default-test</id>
            <phase>test</phase>
            <!-- TODO: Which goal?!? -->
            <configuration>
              <buildFlags>
                <flag>-v</flag>
              </buildFlags>
              <outLogFile>test-out-verbose.log</outLogFile>
              <ignoreErrorExitCode>true</ignoreErrorExitCode>
              <packages>
                <package>./...</package>
              </packages>
            </configuration>
          </execution>

          <execution>
            <id>readable-test</id>
            <!-- TODO: Possibly move to test or prepare-package -->
            <phase>test</phase>
            <goals>
              <goal>custom</goal>
            </goals>
            <configuration>
              <exec>gotestsum</exec>
              <customCommand>-f</customCommand>
              <buildFlags>
                <flag>short</flag>
              </buildFlags>
              <packages>
                <package>./...</package>
              </packages>
            </configuration>
          </execution>

          <!-- Convert generated test report into xunit format and save as file -->
          <execution>
            <id>makeXUnitReport</id>
            <phase>test</phase>
            <goals>
              <goal>custom</goal>
            </goals>
            <configuration>
              <skip>${skipTests}</skip>
              <exec>go2xunit</exec>
              <customCommand>-fail</customCommand>
              <buildFlags>
                <flag>-input</flag>
                <flag>${project.build.directory}${file.separator}reports${file.separator}test-out-verbose.log</flag>
                <flag>-output</flag>
              </buildFlags>
              <echo>
                <info>XUnit report saved as ${xunit.report}</info>
              </echo>
              <packages>
                <package>target${file.separator}surefire-reports${file.separator}xuint.xml</package>
              </packages>
            </configuration>
          </execution>

          <execution>
            <id>run-go-vet</id>
            <phase>verify</phase>
            <goals>
              <goal>vet</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <packages>
            <package>github.com/apache/plc4x/plc4go/pkg/api</package>
          </packages>
          <sources>${project.basedir}</sources>
          <verbose>true</verbose>
        </configuration>
      </plugin>

      <!--
        Create surefire folder for report
      -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <mkdir dir="target${file.separator}surefire-reports" />
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Ensure we don't deploy anything -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <!-- This dependency is just to ensure thrift is built first -->
  <dependencies>
    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4x-code-generation-language-go</artifactId>
      <version>0.10.0</version>
      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4x-protocols-ab-eth</artifactId>
      <version>0.10.0</version>
      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4x-protocols-ads</artifactId>
      <version>0.10.0</version>
      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4x-protocols-bacnetip</artifactId>
      <version>0.10.0</version>
      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4x-protocols-c-bus</artifactId>
      <version>0.10.0</version>
      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4x-protocols-df1</artifactId>
      <version>0.10.0</version>
      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4x-protocols-eip</artifactId>
      <version>0.10.0</version>
      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4x-protocols-firmata</artifactId>
      <version>0.10.0</version>
      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4x-protocols-knxnetip</artifactId>
      <version>0.10.0</version>
      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4x-protocols-modbus</artifactId>
      <version>0.10.0</version>
      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4x-protocols-s7</artifactId>
      <version>0.10.0</version>
      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4x-protocols-simulated</artifactId>
      <version>0.10.0</version>
      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
      <scope>provided</scope>
    </dependency>
  </dependencies>

</project>