<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.friendularity</groupId>
		<artifactId>org.friendularity.modules.main</artifactId>
		<version>1.1.1</version>
		<relativePath>../org.friendularity.modules.main/pom.xml</relativePath>
	</parent>

    <artifactId>org.friendularity.bundle.infra</artifactId>

    <packaging>bundle</packaging>

	<name>${project.artifactId} - OSGi</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
        </dependency>

		<!-- Qpid API wiring is needed when we want to send+rcv AMQP within V-world code, under OSGi -->
		<dependency>
			<groupId>org.appdapter</groupId>
			<artifactId>ext.bundle.apache_qpid_032</artifactId>
		</dependency>
		<dependency>
			<groupId>org.appdapter</groupId>
			<artifactId>org.appdapter.bundle.core</artifactId>
		</dependency>

        <dependency>
            <groupId>org.appdapter</groupId>
            <artifactId>ext.bundle.akka.remote_v2315_s210</artifactId>
            <version>${appdapter.version}</version>
        </dependency>

		<dependency>
			<!-- Separate akka-slf4j dependence helps during unit testing -->
			<groupId>com.typesafe.akka</groupId>
			<artifactId>akka-slf4j_2.10</artifactId>
			<version>2.3.15</version>
		</dependency>

		<!-- Wants parboiled, checkers, ...
		<dependency>
			<groupId>io.spray</groupId>
			<artifactId>spray-client_2.10</artifactId>
			<version>1.3.3</version>
		</dependency>
		-->

		<dependency>
			<groupId>org.jflux</groupId>
			<artifactId>org.jflux.impl.messaging.rk</artifactId>
		</dependency>
		<dependency>
			<groupId>org.jflux</groupId>
			<artifactId>org.jflux.impl.transport.qpid</artifactId>
		</dependency>

		<dependency>
			<groupId>org.jflux</groupId>
			<artifactId>org.jflux.impl.registry.osgi</artifactId>
		</dependency>
		<!-- Issue with type parameters in OSGi classes, compiled under java 7, v 4.3.0 and 4.3.1
		http://blog.osgi.org/2012/10/43-companion-code-for-java-7.html
		-->
		<dependency>
			<groupId>org.appdapter</groupId>
			<artifactId>ext.bundle.osgi.common</artifactId>
			<version>${appdapter.version}</version>
		</dependency>


		<!-- Cogchar-core used here by raiz for appro + eHost profile (also by vscli-thact for for o.c.api.thing) -->
		<dependency>
			<groupId>org.cogchar</groupId>
			<artifactId>org.cogchar.bundle.core</artifactId>
		</dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
<!--
                            org.friendularity.bundle.vmsg,
							org.friendularity.akact,
							org.friendularity.cpmsg,
							org.friendularity.qpc,
							org.friendularity.thact,
							org.friendularity.cpump,
							org.friendularity.dull,
							org.friendularity.util

-->
                    <instructions>
                        <Bundle-Activator>org.friendularity.infra.bun.FrienduInfraBundleActivator</Bundle-Activator>
                        <Export-Package>
							org.friendularity.infra.*
                        </Export-Package>
                        <Private-Package>
                        </Private-Package>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <!-- We're not actually using any scala tests right now
                            <goal>testCompile</goal>
                            -->
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>			
    </build>

    <profiles>
        <profile>
            <id>build-for-felix</id>
            <dependencies>
                <dependency>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>org.apache.felix.main</artifactId>
                    <scope>provided</scope>
                </dependency>
                <!-- To include a shell:
                <dependency>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>org.apache.felix.gogo.shell</artifactId>
                    <version>0.10.0</version>
                </dependency>
                -->
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.7</version>
                        <executions>
                            <execution>
                                <id>compile</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <pathconvert property="plugins.jars" pathsep="${path.separator}">
                                            <path refid="maven.runtime.classpath" />
                                            <map from="${project.build.directory}${file.separator}classes" to="" />
                                        </pathconvert>
                                        <pathconvert pathsep=" " property="bundles">
                                            <path path="${plugins.jars}" />
                                            <mapper>
                                                <chainedmapper>
                                                    <flattenmapper />
                                                    <globmapper from="*" to="file:modules/*" casesensitive="no" />
                                                </chainedmapper>
                                            </mapper>
                                        </pathconvert>
                                        <propertyfile file="${project.build.directory}/config.properties">
                                            <entry key="felix.auto.start" value="${bundles} file:modules/${project.build.finalName}.jar" />
                                            <entry key="org.osgi.framework.bootdelegation" value="*" />
                                        </propertyfile>
                                        <copy file="${maven.dependency.org.apache.felix.org.apache.felix.main.jar.path}" tofile="${project.build.directory}/felix.jar" />
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>2.3</version>
                        <executions>
                            <execution>
                                <id>create-executable-jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <descriptors>
                                        <descriptor>${basedir}/src/main/assembly/felix.xml</descriptor>
                                    </descriptors>
                                    <finalName>${project.build.finalName}</finalName>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>run-on-felix</id>
            <dependencies>
                <dependency>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>org.apache.felix.main</artifactId>
                    <scope>provided</scope>
                </dependency>
                <!-- org.apache.felix:org.apache.felix.gogo.shell:0.6.1 useless from Maven since stdin is swallowed -->
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.7</version>
                        <configuration>
                            <target>
                                <property name="vm.args" value="" />
                                <pathconvert property="plugins.jars" pathsep="${path.separator}">
                                    <path refid="maven.runtime.classpath" />
                                    <map from="${project.build.directory}${file.separator}classes" to="" />
                                </pathconvert>
                                <makeurl property="urls" separator=" ">
                                    <path path="${plugins.jars}" />
                                    <path location="${project.build.directory}/${project.build.finalName}.jar" />
                                </makeurl>
                                <propertyfile file="${project.build.directory}/run.properties">
                                    <entry key="felix.auto.start" value="${urls}" />
                                    <entry key="felix.auto.deploy.action" value="uninstall,install,update,start" />
                                    <entry key="org.osgi.framework.storage" value="${project.build.directory}${file.separator}felix-cache" />
                                    <entry key="org.osgi.framework.bootdelegation" value="*" />

									<!-- FriendU addition -->
									<entry key="org.osgi.framework.system.packages.extra" value="sun.misc, org.w3c.dom.css, org.w3c.dom.html, org.w3c.dom.stylesheets, org.w3c.dom.traversal, org.w3c.dom.ranges, org.w3c.dom.views, org.w3c.dom.xpath" />

								</propertyfile>
                                <makeurl property="run.properties.url" file="${project.build.directory}/run.properties" />
                                <java fork="true" jar="${maven.dependency.org.apache.felix.org.apache.felix.main.jar.path}">
                                    <sysproperty key="felix.config.properties" value="${run.properties.url}" />
                                    <jvmarg line="${vm.args}" />
                                </java>
                            </target>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
