<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">


    <!--

        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.
    -->

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.apache.sshd</groupId>
        <artifactId>sshd</artifactId>
        <version>2.13.2</version>
    </parent>

    <artifactId>sshd-osgi</artifactId>
    <name>Apache Mina SSHD :: OSGi</name>
    <packaging>jar</packaging>
    <inceptionYear>2018</inceptionYear>

    <properties>
        <projectRoot>${project.basedir}/..</projectRoot>
        <!--
          The BC security provider class resides in a package that is referenced nowhere, except reflectively in the BouncyCastleSecurityRegistrar.
          The (optional) package import will thus be missing in the generated MANIFEST.MF. However, the BouncyCastleSecurityRegistrar expects to find
          class org.bouncycastle.jce.provider.BouncyCastleProvider on the classpath; otherwise its isSupported() returns false and Bouncycastle is
          considered not available.
          
          However, in OSGi the package will not be on the bundle classpath if there is no Import-Package for it. (And using a Require-Bundle would restrict
          bundle wiring too much.)
          
          Arguably this is a shortcoming of the BouncyCastleSecurityRegistrar. For the EdDSASecurityProviderRegistrar, this problem does not exist
          since the security provider is in a package that is also referenced elsewhere.
        -->
        <bnd.extraImports>org.bouncycastle.jce.provider;version="$$&lt;range;[==,+);${bouncycastle.version}&gt;";resolution:=optional,</bnd.extraImports>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.sshd</groupId>
            <artifactId>sshd-common</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.sshd</groupId>
            <artifactId>sshd-core</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpg-jdk18on</artifactId>
            <optional>true</optional>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpkix-jdk18on</artifactId>
            <optional>true</optional>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.i2p.crypto</groupId>
            <artifactId>eddsa</artifactId>
            <optional>true</optional>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>tomcat</groupId>
            <artifactId>tomcat-apr</artifactId>
            <optional>true</optional>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <configuration>
                    <skipSource>true</skipSource>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-dependencies</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <excludeTransitive>true</excludeTransitive>
                            <includeGroupIds>org.apache.sshd</includeGroupIds>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                                <!-- Exclude the unpacked Maven files from the dependencies -->
                            <excludes>META-INF/maven/**/*.*,META-INF/maven/**/*</excludes>
                            <outputDirectory>${project.build.directory}/classes</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

                <!-- We need special build instructions for the sources JAR
                    since this is a 'shaded' JAR constructed from the already
                    compiled classes of its component modules -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>create-sources-artifact</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target name="create-sources-artifact-jar" unless="skip.osgi.sources">
                                <mkdir dir="${project.build.directory}/osgi-sources/META-INF/maven/${project.groupId}/${project.artifactId}" />

                                <copy todir="${project.build.directory}/osgi-sources/META-INF/maven/${project.groupId}/${project.artifactId}">
                                    <fileset dir="${project.basedir}" includes="pom.xml" />
                                </copy>

                                <echo file="${project.build.directory}/osgi-sources/META-INF/maven/${project.groupId}/${project.artifactId}/pom.properties">
#Created by Apache Maven with Maven Antrun Plugin
version=${project.version}
groupId=${project.groupId}
artifactId=${project.artifactId}
                                </echo>
                                <echo file="${project.build.directory}/osgi-sources/META-INF/MANIFEST.MF">
Manifest-Version: 1.0
Created-By: Maven Antrun Plugin
                                </echo>

                                <jar destfile="${project.build.directory}/${project.artifactId}-${project.version}-sources.jar" manifest="${project.build.directory}/osgi-sources/META-INF/MANIFEST.MF">
                                    <fileset dir="${project.basedir}/../sshd-common/src/main/java" includes="**/*" />
                                    <fileset dir="${project.basedir}/../sshd-common/src/main/resources" includes="**/*" erroronmissingdir="false" />
                                    <fileset dir="${project.basedir}/../sshd-core/src/main/java" includes="**/*" />
                                    <fileset dir="${project.basedir}/../sshd-core/src/main/resources" includes="**/*" erroronmissingdir="false" />
                                    <fileset dir="${project.build.directory}/osgi-sources" includes="META-INF/**/*" />
                                </jar>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-source-artifact</id>
                        <phase>package</phase>
                        <goals>
                           <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${project.artifactId}-${project.version}-sources.jar</file>
                                    <type>jar</type>
                                    <classifier>sources</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
