<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.cogchar</groupId>
		<artifactId>org.cogchar.modules.main</artifactId>
		<version>1.0.9.1</version>
		<relativePath>../org.cogchar.modules.main/pom.xml</relativePath>
	</parent>	
	
    <artifactId>ext.bundle.lift</artifactId>
	
	<packaging>bundle</packaging>

	<name>${project.artifactId} - OSGi bundle for Lift (liftweb.net) web framework deps.</name>


    <dependencies>
		<!--  Main lift Jar -->
		<dependency>
			<groupId>net.liftweb</groupId>
			<artifactId>lift-webkit_2.10</artifactId>
			<version>2.5.1</version>
			<scope>provided</scope>
			<exclusions>
				<exclusion>
					<artifactId>scala-library</artifactId>
					<groupId>org.scala-lang</groupId>
				</exclusion>
                <exclusion>
                    <artifactId>scala-actors</artifactId>
                    <groupId>org.scala-lang</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>scala-compiler</artifactId>
                    <groupId>org.scala-lang</groupId>
                </exclusion>
                <exclusion>
                 <artifactId>slf4j-api</artifactId>
                 <groupId>org.slf4j</groupId>
              </exclusion>
              <exclusion>
                  <artifactId>scalap</artifactId>
                  <groupId>org.scala-lang</groupId>
              </exclusion>
			</exclusions>
		</dependency>
       <!-- TODO : Recheck source of this dep  -->
		
		<!--	Lift 2.3 (which is not OSGi-fied, while 2.4 is but has some ugly deps)
				wants these classes;  We could mark the imports as optional to avoid this dep.
		-->

				
		<dependency>
			<groupId>net.liftweb</groupId>
			<artifactId>lift-actor_2.10</artifactId>
			<version>2.5.1</version>
			<scope>provided</scope>
			<exclusions>
				<exclusion>
                 <artifactId>slf4j-api</artifactId>
                 <groupId>org.slf4j</groupId>
              </exclusion>
              <exclusion>
                  <artifactId>scalap</artifactId>
                  <groupId>org.scala-lang</groupId>
              </exclusion>
                <exclusion>
					<artifactId>scala-library</artifactId>
					<groupId>org.scala-lang</groupId>
				</exclusion>
                <exclusion>
                    <artifactId>scala-actors</artifactId>
                    <groupId>org.scala-lang</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>scala-compiler</artifactId>
                    <groupId>org.scala-lang</groupId>
                </exclusion>
			</exclusions>
		</dependency>
		<!-- Pick this up from ext.bundles.osgi.common
		<dependency>
			<artifactId>scala-library</artifactId>
			<groupId>org.scala-lang</groupId>
			<type>jar</type>
			<version>2.10.2</version>
		</dependency>
		-->		
        <dependency>
			<groupId>net.liftweb</groupId>
			<artifactId>lift-testkit_2.10</artifactId>
			<version>2.5.1</version>
			<scope>provided</scope>
			<exclusions>
				<exclusion>
                  <artifactId>scalap</artifactId>
                  <groupId>org.scala-lang</groupId>
              </exclusion>
                <exclusion>
					<artifactId>commons-codec</artifactId>
					<groupId>commons-codec</groupId>
				</exclusion>
				<exclusion>
					<artifactId>commons-httpclient</artifactId>
					<groupId>commons-httpclient</groupId>
				</exclusion>
				<exclusion>
					<artifactId>scala-library</artifactId>
					<groupId>org.scala-lang</groupId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>4.3.0</version>
            <scope>provided</scope>
        </dependency>
                
		<dependency>
			<!-- Used by lift-json -->	
			<groupId>org.apache.servicemix.bundles</groupId>
			<artifactId>org.apache.servicemix.bundles.paranamer</artifactId>
			<version>2.4_1</version>
		</dependency><dependency>
			<groupId>org.apache.servicemix.bundles</groupId>
			<artifactId>org.apache.servicemix.bundles.javax-inject</artifactId>
			<version>1_2</version>
		</dependency>

		<dependency>
			<groupId>org.apache.directory.studio</groupId>
			<artifactId>org.apache.commons.io</artifactId>
			<version>2.1</version>
			<exclusions>
				<exclusion>
					<artifactId>commons-io</artifactId>
					<groupId>commons-io</groupId>
				</exclusion>
			</exclusions>
		</dependency>		
		<dependency>
			<groupId>org.apache.servicemix.bundles</groupId>
			<artifactId>org.apache.servicemix.bundles.xmlpull</artifactId>
			<version>1.1.3.1_2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.servicemix.bundles</groupId>
			<artifactId>org.apache.servicemix.bundles.xpp3</artifactId>
			<version>1.1.4c_6</version>
		</dependency>
		<!-- Used by liftweb code and also needed in webapp code, so we propagate explicit dep -->
        <dependency>
            <artifactId>joda-time</artifactId>
            <groupId>joda-time</groupId>
            <type>jar</type>
            <version>2.1</version>
        </dependency>
        <dependency>
            <artifactId>joda-convert</artifactId>
            <groupId>org.joda</groupId>
            <type>jar</type>
            <version>1.2</version>
        </dependency>
        <dependency>
            <artifactId>lift-util_2.10</artifactId>
            <groupId>net.liftweb</groupId>
            <type>jar</type>
            <version>2.5.1</version>
			<scope>provided</scope>
            <exclusions>
                <exclusion>
                    <artifactId>scala-compiler</artifactId>
                    <groupId>org.scala-lang</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>scala-library</artifactId>
                    <groupId>org.scala-lang</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <artifactId>lift-json_2.10</artifactId>
            <groupId>net.liftweb</groupId>
            <type>jar</type>
            <version>2.5.1</version>
			<scope>provided</scope>
            <exclusions>
                <exclusion>
                    <artifactId>scala-compiler</artifactId>
                    <groupId>org.scala-lang</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>scala-library</artifactId>
                    <groupId>org.scala-lang</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>scalap</artifactId>
                    <groupId>org.scala-lang</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <artifactId>lift-common_2.10</artifactId>
            <groupId>net.liftweb</groupId>
            <type>jar</type>
            <version>2.5.1</version>
			<scope>provided</scope>
            <exclusions>
                <exclusion>
                    <artifactId>scala-library</artifactId>
                    <groupId>org.scala-lang</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
			<!-- There is a servicemix bundle for this, but not clear what version we want -->
            <artifactId>commons-codec</artifactId>
            <groupId>commons-codec</groupId>
            <type>jar</type>
            <version>1.6</version>
        </dependency>
        <dependency>
			<!-- Bundle out there for this guy? -->
            <artifactId>commons-fileupload</artifactId>
            <groupId>commons-fileupload</groupId>
            <type>jar</type>
            <version>1.2.2</version>
        </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>

						<Export-Package>
							i18n,
							net.liftweb.*, 
							toserve.*,  
							nu.validator.*
						</Export-Package>
						<Import-Package>
							!nu.xom.*,
							!org.mozilla.*,
							!ch.qos.logback.*, 
							!org.specs2.*, 
							!scala.tools.scalap.*, 
							<!-- We do not want import links to this *old* version of httpclient.
								We are using httpclient 4.3.1.   When we see "commons" in the name,
								that is referring to version 3.* (or earlier).
							-->
							!org.apache.commons.httpclient.*,
							*
						</Import-Package>
						
						
						<!--
							DynamicImport-Package is not needed if we private-pkg our statics into the webapp bundles.
							But in a naive "single net.liftweb classloader" config, this DynamicImport workaround is  
							necessary so that OSGi can wire up the 	Class.forName() lookups by lift	into outer webapp code.
							
							Default bootstrap.liftweb package is used here, but can be overriden in web.xml of the webapp bundle.
						
						<DynamicImport-Package>
							bootstrap.liftweb,		
							org.cogchar.lifter.*,
							org.friendularity.minlift.*
						</DynamicImport-Package>										
						-->	
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>build-for-felix</id>
            <dependencies>
                <dependency>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>org.apache.felix.main</artifactId>
                    <version>4.0.3</version>
                    <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>
                    <version>4.0.3</version>
                    <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="*" />
                                </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>
