<?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>
    <parent>
        <groupId>org.mule.tools.devkit</groupId>
        <artifactId>mule-devkit-parent</artifactId>
        <version>3.4.1</version>
    </parent>

    <groupId>org.mule.modules</groupId>
    <artifactId>mule-module-stormpath</artifactId>
    <version>3.4.0</version>
    <packaging>mule-module</packaging>
    <name>Stormpath Connector</name>

    <properties>
        <mule.version>3.4.0</mule.version>
        <category>Community</category>
        <licensePath>LICENSE.md</licensePath>
        <devkit.studio.package.skip>false</devkit.studio.package.skip>
    </properties>

    <scm>
        <connection>scm:git:git@github.com:mulesoft/stormpath-connector.git</connection>
        <developerConnection>scm:git:git@github.com:mulesoft/stormpath-connector.git</developerConnection>
        <url>https://github.com/mulesoft/stormpath-connector</url>
    </scm>

    <build>
        <plugins>
            <plugin>
                <groupId>com.googlecode.jsonschema2pojo</groupId>
                <artifactId>jsonschema2pojo-maven-plugin</artifactId>
                <version>0.3.7</version>
                <configuration>
                    <sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
                    <targetPackage>org.mule.modules.stormpath.model</targetPackage>
                    <annotationStyle>jackson1</annotationStyle>
                    <generateBuilders>true</generateBuilders>
                    <propertyWordDelimiters>_</propertyWordDelimiters>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <phase>initialize</phase>
                    </execution>
                </executions>
            </plugin>

            <!-- brittle and ugly fix for the output of jsonschema2pojo-maven-plugin until either jsonschema2pojo or devkit gets fixed -->
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <version>1.5</version>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.gmaven.runtime</groupId>
                        <artifactId>gmaven-runtime-1.7</artifactId>
                        <version>1.5</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source><![CDATA[
                                def fileToFix = new File('${project.build.directory}/java-gen/org/mule/modules/stormpath/model/HRef.java')

                                if (fileToFix.text.contains('Codegen fix')) {
                                  println 'jsonschema2pojo codegen fix already in place'
                                  return
                                }

                                println 'Fixing jsonschema2pojo codegen'

                                def fixedContentWriter = new StringWriter()
                                def writer = new BufferedWriter(fixedContentWriter)

                                fileToFix.eachLine() { line ->
                                  if (line.contains('@JsonAnySetter')) {
                                    writer.append('    // Codegen fix for https://github.com/joelittlejohn/jsonschema2pojo/issues/136').newLine()
                                    writer.append('    public void setAdditionalProperties(final Map<String, Object> props)').newLine()
                                    writer.append('    {').newLine()
                                    writer.append('        this.additionalProperties.putAll(props);').newLine()
                                    writer.append('    }').newLine()
                                    writer.newLine()
                                  }

                                  writer.append(line).newLine()
                                }

                                writer.close()

                                fileToFix.write fixedContentWriter.toString()
                            ]]></source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/java-gen</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>it</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>2.14</version>
                        <configuration>
                            <failIfNoTests>true</failIfNoTests>
                        </configuration>
                        <executions>
                            <execution>
                                <id>integration-test</id>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>verify</id>
                                <goals>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <dependencies>
        <!-- Mule transports and modules -->
        <dependency>
            <artifactId>mule-transport-http</artifactId>
            <groupId>org.mule.transports</groupId>
            <version>${mule.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mule.modules</groupId>
            <artifactId>mule-module-json</artifactId>
            <version>${mule.version}</version>
        </dependency>

        <!-- Mule provided libraries -->
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.3-osgi</version>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Tests -->
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-vm</artifactId>
            <version>${mule.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.modules</groupId>
            <artifactId>mule-module-client</artifactId>
            <version>${mule.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>mulesoft-releases</id>
            <name>MuleSoft Releases Repository</name>
            <url>http://repository.mulesoft.org/releases/</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>mulesoft-snapshots</id>
            <name>MuleSoft Snapshots Repository</name>
            <url>http://repository.mulesoft.org/snapshots/</url>
            <layout>default</layout>
        </repository>
    </repositories>
</project>
