<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>org.mechio</groupId>
        <artifactId>org.mechio.modules.motion</artifactId>
        <version>1.0.0</version>
		<relativePath>../../org.mechio.modules.motion/pom.xml</relativePath>
    </parent>
    <artifactId>org.mechio.api.motion</artifactId>
    <name>${project.artifactId} OSGi Bundle</name>
    <packaging>bundle</packaging>
    
    <dependencies>
        <dependency>
            <groupId>org.jflux</groupId>
            <artifactId>org.jflux.api.common.rk</artifactId>
            <version>${jflux.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jflux</groupId>
            <artifactId>org.jflux.api.messaging.rk</artifactId>
            <version>${jflux.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.0.1</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Export-Package>org.mechio.api.motion.*</Export-Package>
                        <Bundle-Activator>org.mechio.api.motion.osgi.Activator</Bundle-Activator>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- this profile executes the bundle on apache felix-->
            <id>run-on-felix</id>
            <dependencies>
                <dependency>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>org.apache.felix.main</artifactId>
                    <version>2.0.2</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.apache.felix.gogo</groupId>
                    <artifactId>org.apache.felix.gogo.commands</artifactId>
                    <version>0.2.2</version>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.3</version>
                        <executions>
                            <execution>
                                <id>compile</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <property name="plugins" refid="maven.runtime.classpath" />
                                        <pathconvert pathsep=" " dirsep="/" property="project.build.url">
                                            <path path="${project.build.directory}" />
                                        </pathconvert>
                                        <pathconvert property="plugins.jars" pathsep=":">
                                            <path path="${plugins}" />
                                            <map from="${project.build.directory}/classes" to="" />
                                        </pathconvert>
                                        <makeurl property="urls" separator=" " validate="false">
                                            <path path="${plugins.jars}" />
                                        </makeurl>
                                        <pathconvert pathsep=" " property="bundles">
                                            <path path="${plugins}" />
                                            <mapper>
                                                <chainedmapper>
                                                    <flattenmapper />
                                                    <globmapper from="*" to="file:modules/*" casesensitive="no" />
                                                </chainedmapper>
                                            </mapper>
                                        </pathconvert>
                                        <makeurl property="main.bundle.url" file="${project.build.directory}/${project.artifactId}-${project.version}.jar" />
                                        <echo file="${project.build.directory}/run.properties">
                                            felix.auto.install=${urls}
                                            felix.auto.start=${main.bundle.url}
                                            org.osgi.framework.storage=${project.build.url}/felix-cache
                                            org.osgi.framework.bootdelegation=*
                                        </echo>
                                        <replace file="${project.build.directory}/run.properties" token="\" value="\\" />
                                        <echo file="${project.build.directory}/config.properties">
                                            felix.auto.install="${bundles}"
                                            felix.auto.start=file:modules/${project.artifactId}-${project.version}.jar
                                        </echo>
                                        <copy file="${maven.dependency.org.apache.felix.org.apache.felix.main.jar.path}" tofile="${project.build.directory}/felix.jar" />
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>2.2-beta-5</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.artifactId}-${project.version}</finalName>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
