
<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.felix</artifactId>
		<version>1.0.3</version>
		<relativePath>../org.appdapter.modules.felix/pom.xml</relativePath>
	</parent>

	<artifactId>org.appdapter.bundle.felix.shell</artifactId>	
	<packaging>bundle</packaging>
	<name>${project.artifactId} - Binds to felix shell, runs from maven repo. (Apache-Felix OSGi Bundle)</name>
	<description>Appdapter bundle for runnable OSGi deployment from repo, including Felix gogo shell and concrete SLF4J binding.</description>

	<repositories>
		<repository>
			<id>com.springsource.repository.bundles.external</id>
			<name>Spring EBR External Release Repository</name>
			<url>http://repository.springsource.com/maven/bundles/external</url>
		</repository>		
	</repositories>
	<dependencies>
		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>org.appdapter.bundle.core</artifactId>
			<version>${project.version}</version>
		 <exclusions>
			 <!--
		  <exclusion>
		   <artifactId>org.appdapter.lib.core</artifactId>
		   <groupId>org.appdapter</groupId>
		  </exclusion>
		  -->
		  <exclusion>
		   <artifactId>org.osgi.core</artifactId>
		   <groupId>org.apache.felix</groupId>
		  </exclusion>
		 </exclusions>
		</dependency>
		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>ext.bundle.felix.shell</artifactId>
			<version>${project.version}</version>
		</dependency>
		<!-- The log4j 1.2.16  bundle in central repo is broken, and gives:
		org.osgi.framework.BundleException: Duplicate import: com.sun.jdmk.comm
		see:
			http://mail-archives.apache.org/mod_mbox/felix-users/201006.mbox/%3CEAA5E99A-F41F-4FAF-A3A0-C8B19A5D0040@apache.org%3E
			https://issues.apache.org/bugzilla/show_bug.cgi?id=49470
		-->
				
		<dependency>
			<groupId>org.apache.log4j</groupId>
			<artifactId>com.springsource.org.apache.log4j</artifactId>
			<version>1.2.16</version>
			<scope>runtime</scope>			
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.6.1</version>
			<scope>runtime</scope>
		    <exclusions>
		        <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.2.0</version>
				<extensions>true</extensions>
				<configuration>
					<instructions>
						<Bundle-Activator>org.appdapter.osgi.felix.shell.AppdapterFelixShellBundleActivator</Bundle-Activator>
					</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>3.0.7</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>3.0.7</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.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="*" />
								</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>

<!--
/*
 *  Copyright 2011 by The Appdapter Project (www.appdapter.org).
 *
 *  Licensed 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.
 */
-->
