<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.harctoolbox</groupId>
    <artifactId>IrpTransmogrifier</artifactId>
    <packaging>jar</packaging>
    <version>1.2.13</version>
    <name>${project.artifactId}</name>
    <licenses>
        <license>
            <name>GPL 3+</name>
            <url>https://www.gnu.org/licenses/gpl.html</url>
        </license>
    </licenses>
    <description>Parser for IRP notation protocols, with rendering, code generation, recognition applications.</description>
    <url>http://www.harctoolbox.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.nameLowercase>irptransmogrifier</project.nameLowercase>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <developers>
        <developer>
            <name>Bengt Martensson</name>
            <email>barf@bengt-martensson.de</email>
            <url>http://www.bengt-martensson.de</url>
            <roles>
                <role>Project leader and architect</role>
                <role>Developer</role>
            </roles>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git://github.com:bengtmartensson/${project.artifactId}.git</connection>
        <developerConnection>scm:git:ssh://github.com:bengtmartensson/${project.artifactId}.git</developerConnection>
        <url>https://github.com/bengtmartensson/${project.artifactId}/tree/master</url>
    </scm>

    <issueManagement>
        <system>GitHub Issues</system>
        <url>https://github.com/bengtmartensson/IrpTransmogrifier/issues</url>
    </issueManagement>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/xdocs</directory>
            </resource>
            <resource>
                <directory>src/main/schemas</directory>
                <includes>
                    <include>irp-protocols.xsd</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>xml-maven-plugin</artifactId>
                <version>1.1.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>validate</goal>
                            <goal>transform</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <basedir>common/schemas</basedir>
                    <catalogHandling>strict</catalogHandling>
                    <catalogs>
                        <catalog>catalog.xml</catalog>
                    </catalogs>
                    <validationSets>
                        <validationSet>
                            <dir>src/main/resources</dir>
                            <includes>
                                <include>IrpProtocols.xml</include>
                            </includes>
                            <xincludeAware>true</xincludeAware>
                            <systemId>http://www.harctoolbox.org/schemas/irp-protocols.xsd</systemId>
                        </validationSet>
                    </validationSets>
                    <transformationSets>
                        <transformationSet>
                            <!-- Generate Version.java from Version.xml using mkVersion.xsl. -->
                            <dir>src/main/xml</dir>
                            <outputDir>${project.build.directory}/generated-sources/xml/org/harctoolbox/irp</outputDir>
                            <includes>
                                <include>Version.xml</include>
                            </includes>
                            <stylesheet>${project.basedir}/common/xslt/mkVersion.xsl</stylesheet>
                            <parameters>
                                <parameter>
                                    <name>version</name>
                                    <value>${project.version}</value>
                                </parameter>
                                <parameter>
                                    <name>url</name>
                                    <value>${project.url}</value>
                                </parameter>
                                <parameter>
                                    <name>appName</name>
                                    <value>${project.artifactId}</value>
                                </parameter>
                                <parameter>
                                    <name>commitId</name>
                                    <value>${git.commit.id}</value>
                                </parameter>
                            </parameters>
                            <fileMappers>
                                <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                                    <targetExtension>.java</targetExtension>
                                </fileMapper>
                            </fileMappers>
                        </transformationSet>
                        <transformationSet>
                            <dir>src/main/resources</dir>
                            <outputDir>${project.build.directory}</outputDir>
                            <includes>
                                <include>IrpProtocols.xml</include>
                            </includes>
                            <stylesheet>${project.basedir}/src/main/resources/IrpProtocols2html.xsl</stylesheet>
                            <fileMappers>
                                <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                                    <targetExtension>.html</targetExtension>
                                </fileMapper>
                            </fileMappers>
                        </transformationSet>
                        <transformationSet>
                            <dir>src/main/resources</dir>
                            <outputDir>${project.build.directory}</outputDir>
                            <includes>
                                <include>IrpProtocols.xml</include>
                            </includes>
                            <stylesheet>${project.basedir}/src/main/resources/IrpProtocols2md.xsl</stylesheet>
                            <fileMappers>
                                <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                                    <targetExtension>.md</targetExtension>
                                </fileMapper>
                            </fileMappers>
                        </transformationSet>
                        <transformationSet>
                            <xincludeAware>true</xincludeAware>
                            <dir>src/main/xdocs</dir>
                            <outputDir>${project.build.directory}/generated-documents</outputDir>
                            <includes>
                                <include>${project.name}.xml</include>
                            </includes>
                            <stylesheet>${project.basedir}/common/xslt/xdoc2html.xsl</stylesheet>
                            <fileMappers>
                                <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                                    <targetExtension>.html</targetExtension>
                                </fileMapper>
                            </fileMappers>
                        </transformationSet>
                    </transformationSets>
                </configuration>

                <dependencies>
                    <dependency>
                        <groupId>xalan</groupId>
                        <artifactId>xalan</artifactId>
                        <version>2.7.2</version>
                    </dependency>
                </dependencies>
            </plugin>

            <!-- Generate target/generated-sources/antlr4/org/harctoolbox/irp/Irp[Parser,Lexer].java from
            src/main/antrlr4/Irp.g4 -->
            <plugin>
                <groupId>org.antlr</groupId>
                <artifactId>antlr4-maven-plugin</artifactId>
                <version>4.9.3</version> <!-- Newer versions seem not compatible -->
                <executions>
                    <execution>
                        <id>antlr</id>
                        <goals>
                            <goal>antlr4</goal>
                        </goals>
                        <configuration>
                            <atn>true</atn>
                            <listener>true</listener>
                            <visitor>true</visitor>
                            <treatWarningsAsErrors>true</treatWarningsAsErrors>
                        </configuration>
                    </execution>

                </executions>
            </plugin>

            <!-- Binary tarballs from src/assembly*/ files. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>org.harctoolbox.irp.IrpTransmogrifier</mainClass> <!-- does not interpolate variables -->
                        </manifest>
                    </archive>
                    <!--finalName>${project.name}</finalName-->
                    <!--appendAssemblyId>true</appendAssemblyId-->
                    <descriptors>
                        <descriptor>src/assembly/jar-with-dependencies.xml</descriptor>
                        <descriptor>src/assembly/target.xml</descriptor>
                    </descriptors>
                    <!--descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                        <descriptorRef>bin</descriptorRef>
                    </descriptorRefs-->
                </configuration>
                <executions>
                    <execution>
                        <id>exec-bin</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <!-- Copy resources  in src/main/config to target dir. -->
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.3.1</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/config</directory>
                                    <filtering>true</filtering>
                                </resource>
                                <resource>
                                    <directory>src/main/resources</directory>
                                    <includes>
                                        <include>IrpProtocols.xml</include>
                                        <include>IrpProtocols2html.xsl</include>
                                    </includes>
                                    <filtering>false</filtering>
                                </resource>
                                <resource>
                                    <directory>src/main/xdocs</directory>
                                    <filtering>false</filtering>
                                    <includes>
                                        <include>${project.name}.xml</include>
                                    </includes>
                                </resource>
                                <resource>
                                    <directory>src/main/schemas</directory>
                                    <includes>
                                        <include>irp-protocols.xsd</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-remote-resources-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>bundle</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <resourcesDirectory>target</resourcesDirectory> <!-- Pretty awful, use while only one resourcesDirectory permitted -->
                    <includes>
                        <include>IrpProtocols.xml</include>
                        <include>IrpProtocols2html.xsl</include>
                        <include>${project.artifactId}.xml</include>
                        <include>irp-protocols.xsd</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.5.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/xml</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <skipTests>false</skipTests>
                    <argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>4.9.10</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <dateFormat>yyyyMMdd</dateFormat><!--  human-readable part of the version number -->
                    <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
                    <generateGitPropertiesFile>false</generateGitPropertiesFile><!-- somehow necessary. otherwise the variables are not available in the pom -->
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>3.6.2</version>
                        <configuration>
                            <outputDirectory>${project.build.directory}/apidocs</outputDirectory>
                            <show>package</show> <!-- Document also package private classes -->
                            <aggregate>true</aggregate>
                        </configuration>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.3.0</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.13</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>buildSetup.exe</id>
            <activation>
                <file>
                    <exists>/usr/bin/chmod</exists> <!-- good enough for now :-) -->
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>3.1.1</version>
                        <executions>
                            <execution>
                                <id>make-wrapper-executable</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>chmod</executable>
                                    <workingDirectory>${project.build.directory}</workingDirectory>
                                    <arguments>
                                        <argument>0755</argument>
                                        <argument>${project.nameLowercase}.sh</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>mk-checksums</id>
            <activation>
                <file>
                    <exists>/bin/sh</exists> <!-- good enough for now :-) -->
                </file>
            </activation>
            <build>
                <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>3.1.1</version>
                    <executions>
                        <!-- compute checksums -->
                        <!-- I know the checksum-maven-plugin, but it does not do what I want) -->
                        <execution>
                            <id>mk-checksums</id>
                            <phase>install</phase>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                            <configuration>
                                <executable>${basedir}/common/scripts/mkchecksums.sh</executable>
                                <workingDirectory>${project.build.directory}</workingDirectory>
                                <arguments>
                                    <argument>${project.artifactId}-${project.version}-bin.zip</argument>
                                </arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4</artifactId> <!-- transitively includes ST4, antlr-runtime, antlr4-runtime -->
            <version>4.9.3</version> <!-- 4.10.* and 4.11.* not compatible -->
            <exclusions>
                <exclusion>
                    <groupId>com.ibm.icu</groupId>
                    <artifactId>icu4j</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.glassfish</groupId>
                    <artifactId>javax.json</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.beust</groupId>
            <artifactId>jcommander</artifactId>
            <scope>compile</scope>
            <version>1.82</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.5.1</version> <!-- later versions not coompatible -->
            <exclusions>
                <exclusion>
                    <groupId>com.beust</groupId>
                    <artifactId>jcommander</artifactId>
                </exclusion>
            </exclusions>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
