<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>io.apiman</groupId>
    <artifactId>apiman-manager-ui</artifactId>
    <version>1.2.2.Final</version>
  </parent>
  <artifactId>apiman-manager-ui-war</artifactId>
  <packaging>war</packaging>
  <name>apiman-manager-ui-war</name>

  <properties>
    <maven.build.timestamp.format>yyyy-MM-dd_HH:mm</maven.build.timestamp.format>
    <ui.webcontext>/apimanui/</ui.webcontext>
    <timestamp>${maven.build.timestamp}</timestamp>
  </properties>

  <dependencies>
    <!-- Project Dependencies -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>apiman-common-auth</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>apiman-common-servlet</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>apiman-common-util</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>apiman-common-config</artifactId>
    </dependency>

    <!-- Third Party Dependencies -->
    <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-configuration</groupId>
      <artifactId>commons-configuration</artifactId>
    </dependency>
    <dependency>
      <artifactId>slf4j-log4j12</artifactId>
      <groupId>org.slf4j</groupId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
    </dependency>

    <!-- Provided Dependencies -->
    <dependency>
      <groupId>org.keycloak</groupId>
      <artifactId>keycloak-core</artifactId>
      <scope>provided</scope>
      <exclusions>
        <exclusion>
          <artifactId>jackson-core-asl</artifactId>
          <groupId>org.codehaus.jackson</groupId>
        </exclusion>
        <exclusion>
          <artifactId>jackson-mapper-asl</artifactId>
          <groupId>org.codehaus.jackson</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.keycloak</groupId>
      <artifactId>keycloak-common</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- Spec Libs -->
    <dependency>
      <groupId>org.jboss.spec.javax.servlet</groupId>
      <artifactId>jboss-servlet-api_3.0_spec</artifactId>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>apimanui</finalName>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
      </resource>
      <resource>
        <directory>src/main/resources-filtered</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <configuration>
          <skip>false</skip>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <webResources>
            <resource>
              <directory>${basedir}/src/main/resources-filtered</directory>
              <filtering>true</filtering>
            </resource>
            <resource>
              <directory>.</directory>
              <includes>
                <include>index.html</include>
                <include>favicon.ico</include>
                <include>dist/**</include>
                <include>plugins/**</include>
              </includes>
            </resource>
          </webResources>
        </configuration>
      </plugin>

      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <executions>

          <execution>
            <id>install node and npm</id>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
            <configuration>
              <nodeVersion>v5.6.0</nodeVersion>
              <npmVersion>3.6.0</npmVersion>
            </configuration>
          </execution>

          <execution>
            <id>npm install</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>install</arguments>
            </configuration>
          </execution>

          <execution>
            <id>gulp build</id>
            <goals>
              <goal>gulp</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
              <arguments>build</arguments>
            </configuration>
          </execution>

        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <dependencies>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.8.2</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>transform-indexhtml</id>
            <phase>package</phase>
            <configuration>
              <target>
                <antversion property="antversion" />
                <echo>Ant Version: ${antversion}</echo>

                <echo></echo>
                <echo>********************************************************************</echo>
                <echo>Generating API Manager index.html file</echo>
                <echo>********************************************************************</echo>
                <echo></echo>

                <replaceregexp file="${basedir}/target/apimanui/index.html"
                  match="&lt;base.href....&gt;" replace="&lt;base href=&apos;${ui.webcontext}&apos;&gt;" byline="true" />
                <replaceregexp file="${basedir}/target/apimanui/index.html"
                  match="&lt;script.src=&quot;([\w\/\.\-]+)&quot;" replace="&lt;script src=&quot;\1?cid=${timestamp}&quot;" byline="true" />
                <replaceregexp file="${basedir}/target/apimanui/index.html"
                  match="&lt;link.rel=&quot;stylesheet&quot;.href=&quot;([\w\/\.\-]+)&quot;" replace="&lt;link rel=&quot;stylesheet&quot; href=&quot;\1?cid=${timestamp}&quot;" byline="true" />
                <echo>Successfully processed file ${project.build.directory}/${project.artifactId}-${project.version}/index.html</echo>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>ui</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <attach>true</attach>
              <descriptors>
                <descriptor>src/main/assembly/ui.xml</descriptor>
              </descriptors>
              <archiverConfig>
                <defaultDirectoryMode>0755</defaultDirectoryMode>
              </archiverConfig>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

</project>
