<?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright (c) 2001-2015, Zoltan Farkas All Rights Reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-->
<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.spf4j</groupId>
  <artifactId>spf4j-aspects</artifactId>
  <packaging>jar</packaging>
  <parent>
    <groupId>org.spf4j</groupId>
    <artifactId>spf4j</artifactId>
    <version>8.2.1</version>
  </parent>
  <name>${project.artifactId}</name>
  <description>spf4j aspects for monitoring performance and retry</description>
        
  <dependencies>
    <dependency>
      <groupId>org.spf4j</groupId>
      <artifactId>spf4j-core</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>${aspectj.version}</version>
    </dependency>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>${aspectj.version}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <scope>test</scope>
      <version>${slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.avro</groupId>
      <artifactId>avro-tools</artifactId>
      <version>${avro.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-library</artifactId>
      <version>1.3</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  
  <build>
    <plugins>
            
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy</id>
            <phase>generate-test-resources</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.aspectj</groupId>
                  <artifactId>aspectjweaver</artifactId>
                  <version>${aspectj.version}</version>
                  <type>jar</type>
                  <overWrite>false</overWrite>
                  <outputDirectory>${project.build.directory}/lib</outputDirectory>
                </artifactItem>
                <artifactItem>
                  <groupId>org.spf4j</groupId>
                  <artifactId>spf4j-core</artifactId>
                  <version>${project.version}</version>
                  <type>jar</type>
                  <overWrite>false</overWrite>
                  <outputDirectory>${project.build.directory}/lib</outputDirectory>
                </artifactItem>
              </artifactItems>
              <outputDirectory>${project.build.directory}/lib</outputDirectory>
              <overWriteReleases>false</overWriteReleases>
              <overWriteSnapshots>true</overWriteSnapshots>
            </configuration>
          </execution>
        </executions>
      </plugin>
            
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
          <forkMode>always</forkMode>
          <argLine>-Djava.io.tmpdir=./target -javaagent:${project.build.directory}/lib/aspectjweaver-${aspectj.version}.jar -javaagent:${project.build.directory}/lib/spf4j-core-${project.version}.jar</argLine>
          <systemPropertyVariables>
            <property>
              <name>aj.weaving.verbose</name>
              <value>true</value>
            </property>
          </systemPropertyVariables>
        </configuration>
        <executions>
          <execution>
            <id>surefire-it</id>
            <phase>integration-test</phase>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <skip>false</skip>
            </configuration>
          </execution>
        </executions>
      </plugin>
                       
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
      </plugin>
            
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
      </plugin>

      <!-- install avrodoc -->
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>1.0</version>
        <!-- executions go here -->
        <executions>
          <execution>
            <id>install node and npm</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>install-node-and-npm</goal>
            </goals>
            <configuration>
                <nodeVersion>v4.4.4</nodeVersion>
                <npmVersion>2.15.1</npmVersion>
            </configuration>
         </execution>
          <execution>
              <id>install AVRODOC</id>
              <phase>generate-resources</phase>
              <goals>
                  <goal>npm</goal>
              </goals>
              <configuration>
                  <arguments>install avrodoc -g</arguments>
              </configuration>
          </execution>
        </executions>
        <configuration>
          <skip>${skip.avrodoc}</skip>
          <installDirectory>${project.basedir}/target</installDirectory>
        </configuration>
      </plugin>


      <!-- discover system property uses -->
      <plugin>
        <groupId>${project.groupId}</groupId>
        <artifactId>spf4j-config-discovery-maven-plugin</artifactId>
        <version>${project.version}</version>
        <executions>
          <execution>
            <id>generate</id>
            <phase>process-classes</phase>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- Start generated avsc files for all IDL -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <id>create avsc destination folder</id>
            <phase>initialize</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <echo message="creating avsc folder target/generated-sources/avsc" />
                <mkdir dir="target/generated-sources/avsc" />
              </target>
            </configuration>
          </execution>
         <execution>
            <id>generate all sysprop defined files</id>
            <phase>process-classes</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
              <apply executable="java" force="true">
                <arg value="-cp" />
                <arg pathref="maven.test.classpath" />
                <arg value="org.apache.avro.tool.Main" />
                <arg value="idl2schemata" />
                <srcfile />
                <targetFile />
                <mapper type="regexp" from="^((.*/)?)([^/]+)\.avdl$$" to="${project.basedir}/target/generated-sources/avsc/\1" />
                <fileset dir="${project.basedir}/target/generated-sources/avdl" includes="**/*.avdl" />
              </apply>
             </target>
            </configuration>
          </execution>

          <execution>
            <id>generate avrodoc for all schemas</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <skip>${skip.avrodoc}</skip>
              <target>
                <fileset id="fileset" dir="${project.basedir}/target/generated-sources/avsc">
                        <include name="**/*.avsc" />
                </fileset>
                <pathconvert refid="fileset" property="converted" pathsep=" ">
                  <globmapper from="${project.basedir}/target/generated-sources/avsc/*" to="*" />
                </pathconvert>
                <exec executable="${project.basedir}/target/node/node" dir="${project.basedir}/target/generated-sources/avsc">
                  <arg value="${project.basedir}/target/lib/node_modules/avrodoc/bin/avrodoc" />
                  <arg line="${converted}" />
                  <arg value="-o${project.basedir}/target/avrodoc.html" />
                </exec>
              </target>
            </configuration>
          </execution>
          <execution>
            <phase>site</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <mkdir dir="target/site" />
                <copy file="target/avrodoc.html" todir="target/site" />
              </tasks>
            </configuration>
          </execution>

        </executions>
      </plugin>

    </plugins>
  </build>
</project>
