<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.appdapter</groupId>
		<artifactId>org.appdapter.modules.core</artifactId>
		<version>1.1.6</version>
		<relativePath>../org.appdapter.modules.core/pom.xml</relativePath>
	</parent>
    <artifactId>ext.bundle.osgi.common</artifactId>
    <packaging>bundle</packaging>
	<name>${project.artifactId} - OSGi + Logging + Scala - platform wrapper</name>
	
	<description>OSGi platform dependency wrapper.
				This bundle sets up dependencies on specific versions of OSGi common components,
				and our logging infrastructure.
	</description>
				
	<!-- This bundle launches cleanly standalone, *IF* an SLF4J runtime binding is supplied to it -->
    <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
			<!-- TODO:  Are we ready for 4.3? -->
            <version>${osgi.core.version}</version>		
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.compendium</artifactId>
			<!-- TODO:  Are we ready for 4.3? -->
            <version>${osgi.core.version}</version>
        </dependency>


		<dependency>
			<!-- This version of apache-commons-codec is a proper OSGi bundle, which uses a different version numbering 
				stream than the apache-servicemix wrapper-bundle previously pulled into o.a.bundle.core on behalf of 
				apache POI.   
				Apache ARQ and POI and probably other libraries want this bundle.
			-->
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>1.6</version>
			<scope>runtime</scope>
		</dependency>		

		
		<!-- Core Scala runtime libs, at a defined version point. 
			TODO:  Proposed:   Split into their own ext.bundle.
		-->		
		<dependency>
			<groupId>org.scala-lang</groupId>
			<artifactId>scala-library</artifactId>
			<version>2.10.2</version>
		</dependency>
		<dependency>
			<groupId>org.scala-lang</groupId>
			<artifactId>scala-reflect</artifactId>
			<version>2.10.2</version>
		</dependency>
		<dependency>
			<groupId>org.scala-lang</groupId>
			<artifactId>scala-compiler</artifactId>
			<version>2.10.2</version>
		</dependency>
		
		<!-- BEGIN logging section.
		-->
		<dependency>
			<!-- Hooray - commons-logging default distro is now a bundle!  
				That is not clear in the online pom at Maven central, but the manifest in the jar looks good.
				This version is needed by httpclient-osgi 4.3, which is needed by Jena.
				
				It is also used at compile time by our ported Jena code in o.a.lib.remote.
			-->
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
			<version>1.1.3</version>
		</dependency>		
				
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.5</version>
		</dependency>
		
		<dependency>
			<!-- We propagate a particular version of Log4J itself, but *not* an SLF4J-Log4J binding (other than at 
				test scope) from this ext.bundle.osgi.common.
				The SLF4J-Log4J binding is supplied at runtime scope from the o.a.b.core bundle. 

				At compile scope, we propagate an OSGi-friendly Log4J bundle, which we presume can be initialized 
				through	the methods provided by Appdapter, which assumes a log4j.properties file at
				root of the bundle that calls those methods - typically your launcher bundle.
				
				It is also possible to use BasicConfigurator from your main() method to enable ALL or most
				logging, without any log4j.properties.
			-->			
			<groupId>org.apache.log4j</groupId>
			<artifactId>com.springsource.org.apache.log4j</artifactId>
			<version>1.2.16</version>
			
		</dependency>
		<dependency>
			<!-- Local SLF4J-Log4J binding used during bundle dev testing only -->
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.5</version>
			<!-- 
				To use the SLF4J-Log4J binding from any bundle, either
					1) Depend on org.appdapter.bundle.core, which applies this dep at "runtime" scope.
				or
					2) Copy this dependency and apply at test or runtime scope.
					
					Further guidelines for establishing your own dep: 
					
				a) This test scope makes the binding available only for main() programs in your "Test Packages".
				
				b) To run your bundle as a direct felix-launchable (useful for testing that your bundle wires OK),
				and use Log4J logging, you will need at least runtime scope.
				
				Note that you must also address Log4J config, as discussed under the log4J dependency above.
			-->
			<scope>test</scope>
			<exclusions>
				<!-- We exclude the normally embedded Log4J version, because it is not OSGi friendly.
					We instead use the bundled version supplied by SpringSource above.
				-->			
				<exclusion>
					<artifactId>log4j</artifactId>
					<groupId>log4j</groupId>
				</exclusion>
			</exclusions>
		</dependency>			
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-Activator>ext.osgi.common.ExtOSGiCommonBundleActivator</Bundle-Activator>
                        <Export-Package>ext.osgi.common</Export-Package>

                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

<!--	This bundle has its own copy of the launch profile stuff, because there is some customization 
		to generate an ant-runnable launch script at bottom.  TODO:  Either make that feature standard, or
		remove it.  (We do have docs about this feature in our Appdapter wiki).
-->
    <profiles>
        <profile>
            <id>build-for-felix</id>
            <dependencies>
                <dependency>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>org.apache.felix.main</artifactId>
                    <version>4.2.1</version>
                    <scope>provided</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.6</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.2</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>
                    <version>4.2.1</version>
                    <scope>provided</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.6</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="*" />
                                    <!-- org.w3c.dom.* are missing from default.properties in felix 4.2.1, they are present in 3.0.7 -->
                                    <entry key="org.osgi.framework.system.packages.extra" value="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" />
								
								<!--
										This is the execution form supplied by maven-OSGi archetype.
										But it does not allow console interaction with Felix shell.
										
                                <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>
								
										So, we (appdapter) add the ability to run ant with same properties
										outside of Maven.   Maven run also works (with no console input
										to stdin).  
										
										TODO:  Find a way to pass stdin stream of maven into ant (or directly into Felix).
									
								-->
								<property name="felix.ant.run.props" value="${project.build.directory}/felix.ant.run.props" />
								<echo>[m-a] felix.ant.run.props=${felix.ant.run.props}</echo>
								
								<!-- Write/update runtime properties out for external use (in future ant run). -->
								<propertyfile file="${felix.ant.run.props}">
									<entry key="felix.main.jar.path" value="${maven.dependency.org.apache.felix.org.apache.felix.main.jar.path}" />
									<entry key="felix.config.props.url" value="${run.properties.url}" />
									<entry key="felix.jvm.args" value="${vm.args}" />
								</propertyfile>
								<!-- Load those same props into current context -->
								<property file="${felix.ant.run.props}" />
								
								<echo>[m-a] felix.main.jar.path=${felix.main.jar.path}</echo> 
								<echo>[m-a] felix.config.props.url=${felix.config.props.url}</echo> 	
								<echo>[m-a] felix.jvm.args=${felix.jvm.args}</echo>
								
								<ant antfile="${basedir}/ant_run.xml">
									<target name="java-fork-felix-jar" />
								</ant>											
                            </target>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
