<?xml version="1.0" encoding="UTF-8"?>
<!--
	The following properties must be specified for this script.
	
	src.cmpn.jar	- The path to the osgi.cmpn.jar to be used as input.
	target.cmpn.dir	- The directory for cmpn binary and source output.
	target.util.dir - The directory for util binary and source output.
	temp.dir		- The directory for storing temporary build files.
	
	TODO Add support for updating package version exports in manifest.	
-->
<project name="project" default="main">
	<target name="main" depends="cmpn,util">
		<echo message="Processed target main"/>
	</target>
	
	<target name="cmpn" depends="cleanCmpn,extractCmpn,zipCmpn,copyCmpn">
		<echo message="Processed target cmpn"/>
	</target>
	
	<target name="util" depends="cleanUtil,extractUtil,zipUtil,copyUtil">
		<echo message="Processed target util"/>
	</target>
	
	<target name="copyCmpn" depends="copyCmpnBin,copyCmpnSrc">
		<echo message="Processed target copyCmpn"/>
	</target>
		
	<target name="copyCmpnBin">
		<echo message="Entering target copyCmpnBin"/>
		<echo message="Unzipping ${temp.dir}/cmpn/bin.zip to ${target.cmpn.dir}/"/>
		<unzip dest="${target.cmpn.dir}/" src="${temp.dir}/cmpn/bin.zip"/>
		<echo message="Exiting target copyCmpnBin"/>
	</target>
	
	<target name="copyCmpnSrc">
		<echo message="Entering target copyCmpnSrc"/>
		<echo message="Copying ${temp.dir}/cmpn/src.zip to ${target.cmpn.dir}/"/>
		<copy file="${temp.dir}/cmpn/src.zip" todir="${target.cmpn.dir}/"/>
		<echo message="Exiting target copyCmpnSrc"/>
	</target>
	
	<target name="copyUtil" depends="copyUtilBin,copyUtilSrc">
		<echo message="Processed target copyUtil"/>
	</target>
	
	<target name="copyUtilBin">
		<unzip dest="${target.util.dir}/" src="${temp.dir}/util/bin.zip"/>
	</target>
		
	<target name="copyUtilSrc">
		<echo message="Entering target copyUtilSrc"/>
		<echo message="Copying ${temp.dir}/util/src.zip to ${target.util.dir}/"/>
		<copy file="${temp.dir}/util/src.zip" todir="${target.util.dir}/"/>
		<echo message="Exiting target copyUtilSrc"/>
	</target>
	
	<target name="zipCmpn" depends="zipCmpnBin,zipCmpnSrc">
		<echo message="Processed target zipCmpn"/>
	</target>
		
	<target name="zipCmpnBin">
		<echo message="Entering target zipCmpnBin"/>
		<echo message="Zipping ${temp.dir}/cmpn/bin/ to ${temp.dir}/cmpn/bin.zip"/>
		<zip destfile="${temp.dir}/cmpn/bin.zip" basedir="${temp.dir}/cmpn/bin/"/>
		<echo message="Exiting target zipCmpnBin"/>
	</target>
	
	<target name="zipCmpnSrc">
		<echo message="Entering target zipCmpnSrc"/>
		<echo message="Zipping ${temp.dir}/cmpn/OSGI-OPT/src/ to ${temp.dir}/cmpn/src.zip"/>
		<zip destfile="${temp.dir}/cmpn/src.zip" basedir="${temp.dir}/cmpn/OSGI-OPT/src/"/>
		<echo message="Exiting target zipCmpnSrc"/>
	</target>
	
	<target name="zipUtil" depends="zipUtilBin,zipUtilSrc">
		<echo message="Processed target zipUtil"/>
	</target>
	
	<target name="zipUtilBin">
		<echo message="Entering target zipUtilBin"/>
		<echo message="Zipping ${temp.dir}/util/bin/ to ${temp.dir}/util/bin.zip"/>
		<zip destfile="${temp.dir}/util/bin.zip" basedir="${temp.dir}/util/bin/"/>
		<echo message="Exiting target zipUtilBin"/>
	</target>
		
	<target name="zipUtilSrc">
		<echo message="Entering target zipUtilSrc"/>
		<echo message="Zipping ${temp.dir}/util/OSGI-OPT/src/ to ${temp.dir}/util/src.zip"/>
		<zip destfile="${temp.dir}/util/src.zip" basedir="${temp.dir}/util/OSGI-OPT/src/"/>
		<echo message="Exiting target zipUtilSrc"/>
	</target>
	
	<target name="extractCmpn" depends="extractCmpnBin,extractCmpnSrc">
		<echo message="Processed target extractCmpn"/>
	</target>
		
	<target name="extractCmpnBin">
		<echo message="Entering target extractCmpnBin"/>
		<echo message="Unzipping specified contents from ${src.cmpn.jar} to ${temp.dir}/cmpn/bin/"/>
		<unzip dest="${temp.dir}/cmpn/bin/" src="${src.cmpn.jar}">
			<patternset>
				<include name="org/osgi/service/cm/**/*"/>
				<include name="org/osgi/service/component/**/*"/>
				<include name="org/osgi/service/device/**/*"/>
				<include name="org/osgi/service/event/**/*"/>
				<include name="org/osgi/service/http/**/*"/>
				<include name="org/osgi/service/io/**/*"/>
				<include name="org/osgi/service/log/**/*"/>
				<include name="org/osgi/service/metatype/**/*"/>
				<include name="org/osgi/service/provisioning/**/*"/>
				<include name="org/osgi/service/upnp/**/*"/>
				<include name="org/osgi/service/useradmin/**/*"/>
				<include name="org/osgi/service/wireadmin/**/*"/>
				<exclude name="**/packageinfo"/>
				<exclude name="**/package-info.class"/>
			</patternset>
		</unzip>
		<echo message="Exiting target extractCmpnBin"/>
	</target>
	
	<target name="extractCmpnSrc">
		<echo message="Entering target extractCmpnSrc"/>
		<echo message="Unzipping specified contents from ${src.cmpn.jar} to ${temp.dir}/cmpn/"/>
		<unzip dest="${temp.dir}/cmpn/" src="${src.cmpn.jar}">
			<patternset>
				<include name="OSGI-OPT/src/org/osgi/service/cm/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/service/component/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/service/device/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/service/event/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/service/http/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/service/io/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/service/log/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/service/metatype/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/service/provisioning/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/service/upnp/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/service/useradmin/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/service/wireadmin/**/*"/>
			</patternset>
		</unzip>
		<echo message="Exiting target extractCmpnSrc"/>
	</target>
	
	<target name="extractUtil" depends="extractUtilBin,extractUtilSrc">
		<echo message="Processed target extractUtil"/>
	</target>
	
	<target name="extractUtilBin">
		<echo message="Entering target extractUtilBin"/>
		<echo message="Unzipping specified contents from ${src.cmpn.jar} to ${temp.dir}/util/bin/"/>
		<unzip dest="${temp.dir}/util/bin/" src="${src.cmpn.jar}">
			<patternset>
				<include name="org/osgi/util/measurement/**/*"/>
				<include name="org/osgi/util/position/**/*"/>
				<include name="org/osgi/util/xml/**/*"/>
				<exclude name="**/packageinfo"/>
				<exclude name="**/package-info.class"/>
			</patternset>
		</unzip>
		<echo message="Exiting target extractUtilBin"/>
	</target>
	
	<target name="extractUtilSrc">
		<echo message="Entering target extractUtilSrc"/>
		<echo message="Unzipping specified contents from ${src.cmpn.jar} to ${temp.dir}/util/"/>
		<unzip dest="${temp.dir}/util/" src="${src.cmpn.jar}">
			<patternset>
				<include name="OSGI-OPT/src/org/osgi/util/measurement/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/util/position/**/*"/>
				<include name="OSGI-OPT/src/org/osgi/util/xml/**/*"/>
			</patternset>
		</unzip>
		<echo message="Exiting target extractUtilSrc"/>
	</target>
	
	<target name="cleanCmpn" depends="cleanCmpnTarget,cleanCmpnTemp">
		<echo message="Processed target cleanCmpn"/>
	</target>
	    			
	<target name="cleanCmpnTarget">
		<echo message="Entering target cleanCmpnTarget"/>
		<echo message="Deleting specified files from ${target.cmpn.dir}/"/>
		<delete includeemptydirs="true">
			<fileset dir="${target.cmpn.dir}/">
				<include name="src.zip"/>
				<include name="org/"/>
			</fileset>
		</delete>
		<echo message="Exiting target cleanCmpnTarget"/>
	</target>
		
	<target name="cleanCmpnTemp">
		<echo message="Entering target cleanCmpnTemp"/>
		<echo message="Deleting ${temp.dir}/cmpn/"/>
		<delete dir="${temp.dir}/cmpn/"/>
		<echo message="Exiting target cleanCmpnTemp"/>
	</target>
	
	<target name="cleanUtil" depends="cleanUtilTarget,cleanUtilTemp">
		<echo message="Processed target cleanUtil"/>
	</target>
	
	<target name="cleanUtilTarget">
		<echo message="Entering target cleanUtilTarget"/>
		<echo message="Deleting specified files from ${target.util.dir}/"/>
		<delete includeemptydirs="true">
			<fileset dir="${target.util.dir}/">
				<include name="src.zip"/>
				<include name="org/"/>
			</fileset>
		</delete>
		<echo message="Exiting target cleanUtilTarget"/>
	</target>
	
	<target name="cleanUtilTemp">
		<echo message="Entering target cleanUtilTemp"/>
		<echo message="Deleting ${temp.dir}/util/"/>
		<delete dir="${temp.dir}/util/"/>
		<echo message="Exiting target cleanUtilTemp"/>
	</target>
</project>
