<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">
  <parent>
    <artifactId>mocca</artifactId>
    <groupId>at.gv.egiz</groupId>
    <version>1.3.9-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>BKUWebStart</artifactId>
  <packaging>jar</packaging>
  <name>MOCCA Webstart</name>
  <url>http://joinup.ec.europa.eu/site/mocca/</url>
  <description>Bürgerkartenumgebung</description>
  
  <build>
    <plugins>

      <!-- Include the BKULocal war artifact in the BKUWebStart jar
       |   BKULauncher resolves resource and copies it to jetty's webapp dir 
       |
       |   don't: overlay BKULocal with maven-war-plugin 
       |   don't: unpack BKULocal dependency (jetty and webstart classloaders interfere) -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-resources</id>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <includeArtifactIds>BKULocal</includeArtifactIds>
              <includeGroupIds>at.gv.egiz</includeGroupIds>
              <outputDirectory>${project.build.directory}/classes</outputDirectory>
              <stripVersion>true</stripVersion>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>buildnumber-maven-plugin</artifactId>
        <groupId>org.codehaus.mojo</groupId>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>create</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <doCheck>false</doCheck>
          <doUpdate>false</doUpdate>
          <revisionOnScmFailure>SvnRevMissing</revisionOnScmFailure>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <groupId>org.apache.maven.plugins</groupId>
        <configuration>
          <archive>
            <manifest>
              <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            </manifest>
            <manifestEntries>
              <Implementation-Build>${project.version}-r${buildNumber}</Implementation-Build>
            </manifestEntries>
          </archive>
          <verbose>true</verbose>
        </configuration>
      </plugin>
      
      <plugin>
          <artifactId>webstart-maven-plugin</artifactId>
          <groupId>org.codehaus.mojo.webstart</groupId>
          <executions>
            <execution>
              <phase>package</phase>
              <goals>
                <goal>jnlp-inline</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <excludeTransitive>false</excludeTransitive>
            <jnlp>
              <inputTemplateResourcePath>${project.basedir}/src/main/jnlp</inputTemplateResourcePath>
              <inputTemplate>template-unstable.xml</inputTemplate>
              <outputFile>mocca.jnlp</outputFile>
              <mainClass>at.gv.egiz.bku.webstart.Launcher</mainClass>
            </jnlp>
            <sign>
              <alias>test-applet signer</alias>
              <keystore>${project.basedir}/src/main/jnlp/keystore.ks</keystore>
              <storepass>storepass</storepass>
              <keypass>keypass</keypass>
              <verify>true</verify>
              <keystoreConfig>
                <delete>false</delete>
                <gen>false</gen>
              </keystoreConfig>
            </sign>
            <pack200>false</pack200>
            <gzip>false</gzip>
            <outputJarVersions>false</outputJarVersions>
            <unsignAlreadySignedJars>true</unsignAlreadySignedJars>
            <verbose>true</verbose>
          </configuration>
        </plugin>

    </plugins>
  </build>

  <profiles>
    <profile>
      <!-- development profile -->
      <id>local-webstart</id>
      <build>
        <plugins>
        <plugin>
          <artifactId>webstart-maven-plugin</artifactId>
          <groupId>org.codehaus.mojo.webstart</groupId>
          <configuration>
            <jnlp>
              <inputTemplate>template-local.xml</inputTemplate>
              <outputFile>mocca-local.jnlp</outputFile>
            </jnlp>
          </configuration>
        </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>pkcs11-sign</id>
      <build>
        <plugins>
        <plugin>
          <artifactId>webstart-maven-plugin</artifactId>
          <groupId>org.codehaus.mojo.webstart</groupId>
          <!-- use pkcs11-patched webstart-maven-plugin-->
          <version>1.0-beta-1-mocca</version>
          <executions>
            <execution>
              <phase>package</phase>
              <goals>
                <goal>jnlp-inline</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <excludeTransitive>false</excludeTransitive>
            <jnlp>
              <inputTemplateResourcePath>${project.basedir}/src/main/jnlp</inputTemplateResourcePath>
              <inputTemplate>template.xml</inputTemplate>
              <outputFile>mocca.jnlp</outputFile>
              <mainClass>at.gv.egiz.bku.webstart.Launcher</mainClass>
            </jnlp>
            <sign>
              <keystore>NONE</keystore>
              <storetype>PKCS11</storetype>
              <providerClass>iaik.pkcs.pkcs11.provider.IAIKPkcs11</providerClass>
              <alias>a-sit-2</alias>
              <storepass>${pkcs11-pass}</storepass>
              <verify>true</verify>
              <keystoreConfig>
                <delete>false</delete>
                <gen>false</gen>
              </keystoreConfig>
            </sign>
            <pack200>false</pack200>
            <gzip>false</gzip>
            <outputJarVersions>false</outputJarVersions>
            <unsignAlreadySignedJars>true</unsignAlreadySignedJars>
            <verbose>true</verbose>
          </configuration>
        </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>non-webstart</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <groupId>org.apache.maven.plugins</groupId>
            <configuration>
              <archive>
                <manifest>
                  <addClasspath>true</addClasspath>
                  <mainClass>at.gv.egiz.bku.webstart.Launcher</mainClass>
                </manifest>
                <manifestEntries>
                  <mode>development</mode>
                  <url>${pom.url}</url>
                  <SplashScreen-Image>at/gv/egiz/bku/webstart/splash.png</SplashScreen-Image>
                </manifestEntries>
              </archive>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <!-- TODO somehow provide javaws.jar on manifest class-path -->
    </profile>

    <profile>
      <!--
      This profile is here for triggering when another scm than svn is
      used (for example git). Instead of getting the version build number
      from svn we will use the build date and the user name.
      -->
      <id>buildnumber-git</id>
      <activation>
        <file>
          <missing>.svn</missing>
        </file>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.groovy.maven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.0</version>
            <executions>
              <execution>
                <phase>generate-resources</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <source>
                    def gitSvnProc = ["sh", "-c", "git svn info | awk '/Revision:/ { print \$2 }'"].execute()
                    gitSvnProc.waitFor()
                    project.properties['gitSvnRev'] = gitSvnProc.in.text.trim()
                  </source>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <executions>
              <execution>
                <phase>generate-resources</phase>
                <goals>
                  <goal>create</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <doCheck>false</doCheck>
              <doUpdate>false</doUpdate>
              <format>{0}</format>
              <items>
                <item>${gitSvnRev}</item>
              </items>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <dependencies>
    <!-- ATTENTION update of application descriptor (jnlp file) is special...
     |   The JNLP Client must use the Last-Modified header field returned by
     |   the Web Server to determine if a newer JNLP file is present on the Web
     |   server.
     |   Don't assume changes to the descriptor (changes in dependencies) to
     |   appear directly on the client descriptor (even if 'update available'
     |   was shown to user).
     |   Note: Download via browser ensures the updated jnlp file is used. -->
    <dependency>
      <groupId>at.gv.egiz</groupId>
      <artifactId>BKULocal</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <!-- make dependency not transitive -->
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>at.gv.egiz</groupId>
      <artifactId>BKUCertificates</artifactId>
    </dependency>
    <dependency>
      <groupId>iaik</groupId>
      <artifactId>iaik_jce_full</artifactId>
      <scope>compile</scope>
    </dependency>
    
    <!-- Jetty 6.1.15+ required, see
     |   http://jira.codehaus.org/browse/JETTY-843
     |-->
    <dependency>
      <groupId>org.mortbay.jetty</groupId>
      <artifactId>jetty</artifactId>
      <version>6.1.19</version>
    </dependency>
    <!-- JSP support
     |   http://jira.codehaus.org/browse/JETTY-827
     |   jsp-2.1-jetty-6.1.19 depends on the required jsp-2.1-glassfish jars (?)
     |
    <dependency>
      <groupId>org.mortbay.jetty</groupId>
      <artifactId>jsp-2.1-jetty</artifactId>
      <version>6.1.19</version>
    </dependency-->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <scope>compile</scope>
    </dependency>

    <!-- javax.jnlp.* not included in SUN JDK's rt.jar,
     |   don't declare here if using OpenJDK -->
    <dependency>
      <groupId>jre</groupId>
      <artifactId>javaws</artifactId>
      <version>6.0</version>
      <type>jar</type>
      <scope>system</scope>
      <systemPath>${java.home}/lib/javaws.jar</systemPath>
    </dependency>
  </dependencies>
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>2.1.2</version>
        <configuration>
          <dependencyDetailsEnabled>true</dependencyDetailsEnabled>
          <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
        </configuration>
        <reportSets>
          <reportSet>
            <reports>
              <report>index</report>
              <report>summary</report>
              <report>license</report>
              <report>dependencies</report>
              <report>dependency-management</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>
</project>