<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">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>it.uniroma2.art.semanticturkey</groupId>
        <artifactId>semanticturkey</artifactId>
        <version>10.1</version>
    </parent>

    <artifactId>st-builder</artifactId>
    <name>Semantic Turkey Builder</name>
    <packaging>pom</packaging>
    <description>Semantic turkey builder subproject. It creates the karaf archive with the application already
        deployed.
    </description>

    <repositories>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>

        <repository>
            <id>Shibbolet</id>
            <name>Shibbolet</name>
            <url>https://build.shibboleth.net/nexus/content/repositories/releases/</url>
        </repository>

    </repositories>

    <properties>
        <maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format>
        <!-- The following property definition is requred because of a bug described
            here: https://dzone.com/articles/stamping-version-number-and -->
        <timestamp>${maven.build.timestamp}</timestamp>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.karaf</groupId>
            <artifactId>apache-karaf</artifactId>
            <version>${karaf.version}</version>
            <type>zip</type>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/filtered-resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>filter</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>resources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- This goal attaches the feature file semanticturkey.xml as an additional
                artifact to this compilation unit so that it can be referenced through Maven. -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-artifact</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.basedir}/target/classes/semanticturkey.xml</file>
                                    <type>xml</type>
                                    <classifier>features</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- This goal has been dictated by the same principle of the previous
                "attach-artifact" one. The difference is that normally attached artifacts
                may be declared in any phase, but are actually installed during the install
                phase. This is ok for the semanticturkey.xml file, while we need the files
                listed here to be available for the following tasks (carried on during the
                prepackage and package phases). For this reason, we force here their install
                during the compile phase. -->
            <plugin>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.3.1</version>
                <executions>
                    <execution>
                        <id>install-pax-mvn-file</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <file>${project.basedir}/src/main/distribution/etc/org.ops4j.pax.url.mvn.cfg</file>
                            <groupId>it.uniroma2.art.semanticturkey</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <packaging>cfg</packaging>
                            <classifier>pax</classifier>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-pax-file</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <file>${project.basedir}/src/main/distribution/etc/org.ops4j.pax.web.cfg</file>
                            <groupId>it.uniroma2.art.semanticturkey</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <packaging>cfg</packaging>
                            <classifier>pax</classifier>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-st-file</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <file>${project.basedir}/target/classes/etc/${project.groupId}.cfg</file>
                            <groupId>it.uniroma2.art.semanticturkey</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <packaging>cfg</packaging>
                            <classifier>st</classifier>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-samllogin-file</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <file>${project.basedir}/src/main/distribution/etc/saml-login.properties</file>
                            <groupId>it.uniroma2.art.semanticturkey</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <packaging>properties</packaging>
                            <classifier>saml-login</classifier>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-samllogin-metadata-file</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <file>${project.basedir}/src/main/distribution/etc/saml-login.xml</file>
                            <groupId>it.uniroma2.art.semanticturkey</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <packaging>xml</packaging>
                            <classifier>saml-login</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <!-- Uncompress the standard Karaf distribution -->
                        <id>unpack</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.apache.karaf</groupId>
                                    <artifactId>apache-karaf</artifactId>
                                    <type>zip</type>
                                    <outputDirectory>${project.basedir}/target/dependencies</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- Copy CODA configuration file (because the plugin features-maven-plugin
                            only supports the population of the directory /system) -->
                        <id>copy CODA cfg</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>it.uniroma2.art.coda</groupId>
                                    <artifactId>coda-karaf</artifactId>
                                    <version>${coda.version}</version>
                                    <type>cfg</type>
                                    <classifier>provisioning</classifier>
                                    <outputDirectory>${project.basedir}/target/dependencies/etc</outputDirectory>
                                    <destFileName>it.uniroma2.art.coda.provisioning.cfg</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.karaf.tooling</groupId>
                <artifactId>karaf-maven-plugin</artifactId>
                <version>${karaf.version}</version>
                <!-- <version>2.1.6</version> 2.1.6 has no issues with Maven3 (at least,
                    some version of MVN3), but fails in deploying all content to the target -->
                <executions>
                    <execution>
                        <id>add-features-to-repo</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>features-add-to-repository</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>mvn:org.apache.karaf.features/standard/${karaf.version}/xml/features
                                </descriptor>
                                <descriptor>mvn:org.apache.karaf.features/enterprise/${karaf.version}/xml/features
                                </descriptor>
                                <descriptor>mvn:org.apache.karaf.features/spring/${karaf.version}/xml/features
                                </descriptor>
                                <descriptor>file:${project.basedir}/target/classes/semanticturkey.xml</descriptor>
                            </descriptors>
                            <features>
                                <feature>semantic_turkey</feature>
                            </features>
                            <addTransitiveFeatures>true</addTransitiveFeatures>
                            <!-- In 2.3.3 this property defaults to ${project.build.directory}/features-repo -->
                            <!-- <repository>${project.build.directory}/features-repo</repository> -->
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <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>single</goal>
                        </goals>
                        <configuration>
                            <finalName>${project.parent.artifactId}-${project.parent.version}</finalName>
                            <outputDirectory>
                                ${project.parent.build.directory}
                            </outputDirectory>
                            <descriptors>
                                <descriptor>src/main/descriptors/bin.xml</descriptor>
                            </descriptors>
                            <appendAssemblyId>false</appendAssemblyId>
                            <tarLongFileMode>gnu</tarLongFileMode>
                            <!-- In the descriptor, the base Karaf distribution is copied mostly
                                at the end, so skipping duplicates leaves the copy introduced by the build
                                of ST (see: https://github.com/codehaus-plexus/plexus-archiver/blob/master/src/main/java/org/codehaus/plexus/archiver/Archiver.java#L335) -->
                            <archiverConfig>
                                <duplicateBehavior>skip</duplicateBehavior>
                            </archiverConfig>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


</project>