<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
-->
<!--
    Maven release plugin requires the project tag to be on a single line.
-->
<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">
    <!--
        To build the distribution files from project root:

        mvn clean compile package -Dtest=false -DfailIfNoTests=false

        To build and deploy a fully signed release with docs, run:

            mvn clean deploy -Papache-release,docbook-profile

        Note that to sign the release, you need to have "gpg" installed and
        create a key. See http://apache.org/dev/release-signing.html
    -->

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.apache.openjpa</groupId>
        <artifactId>openjpa-parent</artifactId>
        <version>2.4.2</version>
    </parent>

    <groupId>org.apache.openjpa</groupId>
    <artifactId>apache-openjpa</artifactId>
    <packaging>pom</packaging>
    <name>OpenJPA Project Docs and Assemblies</name>
    <description>OpenJPA Project Docs and Assemblies</description>

    <properties>
        <openjpa.release.keyAlias>
            ${user.name}@apache.org
        </openjpa.release.keyAlias>

        <openjpa.assembly.finalName>
            ${project.artifactId}-${project.version}</openjpa.assembly.finalName>
        <openjpa.assembly.outputDirectory>
        ${project.basedir}/target/site/downloads
        </openjpa.assembly.outputDirectory>

        <openjpa.assembly.binarySuffix>binary</openjpa.assembly.binarySuffix>
        <openjpa.assembly.binaryBase>
        ${openjpa.assembly.outputDirectory}/${openjpa.assembly.finalName}-${openjpa.assembly.binarySuffix}
        </openjpa.assembly.binaryBase>
        <openjpa.assembly.binaryFile>
        ${openjpa.assembly.binaryBase}.zip
        </openjpa.assembly.binaryFile>

        <openjpa.assembly.sourceSuffix>source</openjpa.assembly.sourceSuffix>
        <openjpa.assembly.sourceBase>
        ${openjpa.assembly.outputDirectory}/${openjpa.assembly.finalName}-${openjpa.assembly.sourceSuffix}
        </openjpa.assembly.sourceBase>
        <openjpa.assembly.sourceFile>
        ${openjpa.assembly.sourceBase}.zip
        </openjpa.assembly.sourceFile>

        <parent.site.docs>
        ${project.basedir}/target/site/docs
        </parent.site.docs>

        <docbook.source>${project.basedir}/src/doc/manual</docbook.source>
        <docbook.target>${project.build.directory}/docbook</docbook.target>
        <docbook.version>1.67.2</docbook.version>
        <local.repository>${settings.localRepository}</local.repository>

        <!-- 
            Java imaging apis are needed to include images in a PDF.
            //X THAT seems not to be true anymore with the new dockbkx plugin!
            JIMI or JAI may be used. Neither is available in a maven
            repository and should be downloaded and installed manually
            to your local repository.

            JAI can be found here:
            http://download.java.net/media/jai/builds/release/1_1_3/

            ie :
            $ mvn install:install-file -Dfile=jai_core.jar \
              -DgroupId=com.sun -DartifactId=jai_core \
              -Dversion=1.1.3 -Dpackaging=jar
            $ mvn install:install-file -Dfile=jai_codec.jar \
              -DgroupId=com.sun -DartifactId=jai_codec \
              -Dpackaging=jar -Dversion=1.1.3

            Alternatively if you have installed the JAI artifacts to an 
            internal repository you can specify it on the command line:
              -Djai.maven.repo=REPOS_URL
              -Djai.groupId=com.sun
            -->
        <jai.maven.repo>https://m2proxy.atlassian.com/repository/public</jai.maven.repo>
        <jai.groupId>com.sun</jai.groupId>
        <jai.version>1.1.3</jai.version>

        <nightly.version>latest</nightly.version>
        <!-- authentication for nightly uploads -->
        <nightly.user.name>${user.name}</nightly.user.name>
        <nightly.password>passw0rd</nightly.password>
    </properties>

    <build>
        <!-- needed to let maven pass the "compile" phase -->
        <testSourceDirectory>/none/</testSourceDirectory>

        <!-- filter site resources -->
        <resources>
            <resource>
                <directory>${project.basedir}/src/site</directory>
                <!-- targetPath is relative to target/classes/ -->
                <targetPath>../filtered-site</targetPath>
                <filtering>false</filtering>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>bin</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>assembly.xml</descriptor>
                                <descriptor>source-assembly.xml</descriptor>
                                <descriptor>bin-assembly.xml</descriptor>
                            </descriptors>
                            <outputDirectory>${openjpa.assembly.outputDirectory}</outputDirectory>
                            <workDirectory>target/work</workDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--
                Copy over site files from src/site to target/filtered-site
                so we can filter resources and include other generated
                content from the openjpa-project module.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>prefilter-site</id>
                        <phase>site</phase>
                        <goals>
                            <goal>resources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <configuration>
                    <siteDirectory>target/filtered-site</siteDirectory>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>ianal-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>verify-legal-files</goal>
                        </goals>
                        <configuration>
                            <!-- Do not fail the build, as ianal will fail on source zips due to included META-INF dirs -->
                            <strict>false</strict>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!--
            Docbook profile. Docs can be built by running:
            MAVEN_OPTS=-Xmx512m
            mvn -f openjpa-project/pom.xml process-resources -Pdocbook-profile
        -->
        <profile>
            <id>docbook-profile</id>
            <build>
                <plugins>
                    <!-- build the docs when processing resources -->
                    <plugin>
                        <groupId>com.agilejava.docbkx</groupId>
                        <artifactId>docbkx-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>build-pdf-doc</id>
                                <phase>process-resources</phase>
                                <goals><goal>generate-pdf</goal></goals>
                                <configuration>
                                    <sourceDirectory>
                                        ${docbook.source}
                                    </sourceDirectory>
                                    <targetDirectory>
                                        ${docbook.target}
                                    </targetDirectory>
                                    <includes>manual.xml</includes>
                                    <foCustomization>
                                        ${docbook.source}/manual-pdf.xsl
                                    </foCustomization>
                                    <imgSrcPath>
                                        ${docbook.source}/
                                    </imgSrcPath>
                                    <postProcess>
                                        <!-- copy to parent module for
                                             expanded access in upload -->
                                        <mkdir dir="${parent.site.docs}" />
                                        <delete file="${docbook.target}/manual.fo" />
                                        <copy todir="${parent.site.docs}">
                                            <fileset dir="${docbook.target}">
                                                <include name="manual.pdf" />
                                            </fileset>
                                        </copy>
                                    </postProcess>
                                </configuration>
                            </execution>
                            <execution>
                                <id>build-chunked-doc</id>
                                <phase>process-resources</phase>
                                <goals><goal>generate-html</goal></goals>
                                <configuration>
                                    <sourceDirectory>
                                        ${docbook.source}
                                    </sourceDirectory>
                                    <targetDirectory>
                                        ${docbook.target}
                                    </targetDirectory>
                                    <includes>manual.xml</includes>
                                    <chunkedOutput>true</chunkedOutput>
                                    <chunkQuietly>false</chunkQuietly>
                                    <htmlCustomization>
                                        ${docbook.source}/manual-xhtml-chunk.xsl
                                    </htmlCustomization>
                                    <postProcess>
                                        <!-- rename manual to index -->
                                        <move file="${docbook.target}/manual.html" tofile="${docbook.target}/index.html" />
                                        <!-- Replace a 'base href' token to 'base target' in the index.html -->
                                        <!-- This base href was inserted by manual-xhtml-chunk.xsl parameter 'html.base' -->
                                        <replace file="${docbook.target}/index.html" token="base href" value="base target" />
                                        <!-- Copy main.html from original location to docbook target  -->
                                        <copy file="${docbook.source}/main.html" tofile="${docbook.target}/main.html" />
                                        <!-- copy over images and styles -->
                                        <mkdir dir="${docbook.target}/img" />
                                        <copy todir="${docbook.target}/img">
                                            <fileset dir="${docbook.source}/img">
                                                <include name="*.*" />
                                            </fileset>
                                        </copy>

                                        <mkdir dir="${docbook.target}/css" />
                                        <copy todir="${docbook.target}/css">
                                            <fileset dir="${docbook.source}/css">
                                                <include name="*.*" />
                                            </fileset>
                                        </copy>

                                        <!-- copy to parent module for
                                             expanded access in upload -->
                                        <mkdir dir="${parent.site.docs}" />
                                        <copy todir="${parent.site.docs}">
                                            <fileset dir="${docbook.target}">
                                                <include name="*.*" />
                                            </fileset>
                                        </copy>
                                    </postProcess>
                                </configuration>
                            </execution>
                            <execution>
                                <id>build-single-doc</id>
                                <phase>process-resources</phase>
                                <goals><goal>generate-html</goal></goals>
                                <configuration>
                                    <sourceDirectory>
                                        ${docbook.source}
                                    </sourceDirectory>
                                    <targetDirectory>
                                        ${docbook.target}
                                    </targetDirectory>
                                    <includes>manual.xml</includes>
                                    <chunkedOutput>false</chunkedOutput>
                                    <htmlCustomization>
                                        ${docbook.source}/manual-xhtml.xsl
                                    </htmlCustomization>
                                    <postProcess>
                                        <!-- copy to parent module for
                                             expanded access in upload -->
                                        <mkdir dir="${parent.site.docs}" />
                                        <copy todir="${parent.site.docs}">
                                            <fileset dir="${docbook.target}">
                                                <include name="manual.html" />
                                            </fileset>
                                        </copy>
                                    </postProcess>
                                </configuration>
                            </execution>
                        </executions>
                        <dependencies>
                        <dependency>
                            <groupId>org.docbook</groupId>
                            <artifactId>docbook-xml</artifactId>
                            <version>4.4</version>
                            <scope>runtime</scope>
                        </dependency>
<!-- As far as I did test we do not need JAI for generating our docs.
                        <dependency>
                            <groupId>${jai.groupId}</groupId>
                            <artifactId>jai_core</artifactId>
                            <version>${jai.version}</version>
                            <scope>runtime</scope>
                        </dependency>
                        <dependency>
                            <groupId>${jai.groupId}</groupId>
                            <artifactId>jai_codec</artifactId>
                            <version>${jai.version}</version>
                            <scope>runtime</scope>
                        </dependency>
-->
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
            <activation>
                <property>
                    <name>builddocs</name>
                    <value>true</value>
                </property>
            </activation>

        </profile>
        <!--
          Upload distribution files, javadoc and manual to openjpa.apache.org/builds/${nightly.version}.
          This profile is designed to be run nightly by a continuous build server, but can
          also be run manually.

          The nightly.user.name and nightly.password properties need to be set prior to using
          this profile, ie : 
          $ mvn -Dnightly.user.name=mikedd -Dnightly.password=mikesPassword -Pnightly-upload package
          or (using a profile defined in $user.home/.m2/settings.xml )
          $ mvn -Pnightly-upload,mikes-nightly-credentials package
          -->
        <profile>
            <id>nightly-upload</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <configuration>
                                    <tasks>
                                        <ant antfile="upload.xml" target="upload" inheritRefs="true">
                                            <property name="nightly.user.name" value="${nightly.user.name}" />
                                            <property name="nightly.password" value="${nightly.password}" />
                                            <property name="nightly.keyfile" value="${nightly.keyfile}" />
                                            <property name="nightly.passphrase" value="${nightly.passphrase}" />
                                            <property name="nightly.version" value="${nightly.version}" />
                                            <property name="project.version" value="${project.version}" />
                                        </ant>
                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <!-- need to explicitly list dependencies for assembly to work -->
    <dependencies>
        <dependency>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa-all</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- included so we can include it in the distribution -->
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
        </dependency>

        <!-- included for Apache Bean Validation provider -->
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-validation_1.0_spec</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.bval</groupId>
            <artifactId>org.apache.bval.bundle</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
        </dependency>
    </dependencies>
</project>
