<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.alfresco</groupId>
      <artifactId>aikau-parent</artifactId>
   <version>1.0.21</version>
      <relativePath>../pom.xml</relativePath>
   </parent>

   <artifactId>aikau</artifactId>
   
   <name>Aikau</name>
   <description>Aikau is a meta-framework for Alfresco specific UI development</description>

   <build>

      <!-- Everything gets place into the META-INF folder of the JAR because Surf (the expected platform for Aikau)
           will be able to access resources from that location via the /res/ path -->
      <resources>
         <!-- By default we're going to place the Aikau source files into a versioned path... -->
         <resource>
            <targetPath>META-INF/js/aikau/${project.version}/alfresco</targetPath>
            <filtering>false</filtering>
            <directory>${basedir}/src/main/resources/alfresco</directory>
         </resource>

         <!-- Put the release notes in the root of the JAR file -->
         <resource>
            <targetPath>.</targetPath>
            <filtering>true</filtering>
            <includes>
               <include>ReleaseNotes.md</include>
            </includes>
            <directory>${basedir}</directory>
         </resource>

         <resource>
            <!-- Path has to be aligned with version because Surf caches by XML path -->
            <targetPath>./alfresco/site-data/extensions/${project.version}</targetPath>
            <filtering>true</filtering>
            <directory>${basedir}/src/main/resources/extension-module</directory>
         </resource>

         <resource>
            <!-- WebScript library files go straight into a package -->
            <targetPath>./alfresco/site-webscripts/org/alfresco/aikau/webscript/libs</targetPath>
            <filtering>false</filtering>
            <directory>${basedir}/src/main/resources/webscript-libs</directory>
         </resource>

         <resource>
            <!-- WebScripts go into their own package -->
            <targetPath>./alfresco/site-webscripts/org/alfresco/aikau</targetPath>
            <filtering>false</filtering>
            <directory>${basedir}/src/main/resources/webscripts</directory>
         </resource>

         <!-- ...but everything else goes into a standard path -->
         <resource>
            <targetPath>META-INF/js/lib</targetPath>
            <filtering>false</filtering>
            <directory>${basedir}/src/main/resources/lib</directory>
         </resource>
      </resources>

      <testResources>
         <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
            <includes>
               <include>testApp/WEB-INF/surf.xml</include>
            </includes>
         </testResource>
         <testResource>
            <directory>src/test/resources</directory>
            <filtering>false</filtering>
            <excludes>
               <exclude>testApp/WEB-INF/surf.xml</exclude>
            </excludes>
         </testResource>
      </testResources>

      <plugins>

         <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
               <execution>
                  <id>duplicate-english-messages</id>
                  <phase>generate-resources</phase>
                  <goals>
                     <goal>run</goal>
                  </goals>
                  <configuration>
                     <target>
                        <copy todir="${project.build.outputDirectory}/META-INF/js/aikau/${project.version}">
                           <fileset dir="${basedir}/src/main/resources" includes="alfresco/**/*.properties" />
                           <mapper from="^([^_]*).properties$" to="\1_en.properties" type="regexp" />
                        </copy>
                     </target>
                  </configuration>
               </execution>
               <execution>
                  <id>copy-webscript-beans</id>
                  <phase>process-test-classes</phase>
                  <goals>
                     <goal>run</goal>
                  </goals>
                  <configuration>
                     <target>
                        <copy todir="${project.build.testOutputDirectory}/testApp/WEB-INF/classes">
                           <fileset dir="${project.build.testOutputDirectory}" includes="**/*.class" />
                        </copy>
                      </target>
                  </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.9</version>
            <executions>
               <execution>
                  <id>unpack-dependencies</id>
                  <phase>prepare-package</phase>
                  <goals>
                     <goal>unpack</goal>
                  </goals>
                  <configuration>
                     <artifactItems>
                        <artifactItem>
                           <groupId>org.dojotoolkit</groupId>
                           <artifactId>dojo</artifactId>
                           <version>${dependency.dojo.version}</version>
                           <type>zip</type>
                           <classifier>distribution</classifier>
                           <overWrite>true</overWrite>
                           <outputDirectory>${basedir}/target/classes/META-INF/js/lib</outputDirectory>
                        </artifactItem>
                     </artifactItems>
                  </configuration>
                </execution>
            </executions>
         </plugin>

         <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.2.5.v20141112</version>
            <configuration>

               <!-- Sets the port when using mvn jetty:run-forked -->
               <jvmArgs>-Djetty.port=8089</jvmArgs>

               <!-- Override the system properties to set a port that *should* be unused -->
               <systemProperties>
                  <force>true</force>
                  <systemProperty>
                     <name>jetty.port</name>
                     <value>8089</value>
                  </systemProperty>
               </systemProperties>

               <!--  The following 3 settings allow us to execute a mvn jetty:stop command to shutdown the test application -->
               <stopPort>9966</stopPort>
               <stopKey>foo</stopKey>
               <stopWait>20</stopWait>

                <!-- Configure the application, this will essentially be Share but overlaid with the test resources -->
               <webApp>
                  <descriptor>target/test-classes/testApp/WEB-INF/web.xml</descriptor>
                  <contextPath>/aikau</contextPath>
                  <resourceBases>
                     <resourceBase>target/test-classes/testApp</resourceBase>
                     <resourceBase>target/classes/META-INF</resourceBase>
                     <!-- <resourceBase>${project.build.directory}/${project.build.finalName}</resourceBase> -->
                  </resourceBases>
                  <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames> 
               </webApp>
               <webAppSourceDirectory>target/test-classes/testApp</webAppSourceDirectory>
               <classesDirectory>target/classes</classesDirectory>
               <testClassesDirectory>target/test-classes/testApp/WEB-INF/classes</testClassesDirectory>
               <baseAppFirst>false</baseAppFirst>
            </configuration>
         </plugin>

         <!-- Generate jsdoc using a Maven plugin (Command: mvn jsdoc3:jsdoc3) -->
         <plugin>
            <groupId>com.phasebash.jsdoc</groupId>
            <artifactId>jsdoc3-maven-plugin</artifactId>
            <version>1.1.0</version>
            <configuration>
               <recursive>true</recursive>
               <directoryRoots>
                  <directoryRoot>${basedir}/src/main/resources/alfresco/</directoryRoot>
               </directoryRoots>
               <templateDirectory>${basedir}/src/jsdoc-templates/alfresco</templateDirectory>
               <configFile>${basedir}/conf.json</configFile>
            </configuration>
         </plugin>
         
      </plugins>
   </build>

</project>
