<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <groupId>org.opencoweb</groupId>
        <artifactId>coweb-java</artifactId>
        <version>1.0.1-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <groupId>org.opencoweb</groupId>
    <artifactId>coweb-javascript</artifactId>
    <name>OpenCoweb :: Java :: JavaScript</name>
    <packaging>war</packaging>

    <properties>
	    <i18n-plugin-url>http://requirejs.org/docs/release/1.0.0/minified/i18n.js</i18n-plugin-url>
        <coweb-jsoe>${project.build.directory}/${project.artifactId}-${project.version}/coweb/jsoe</coweb-jsoe>
        <coweb-jsoe-src>src/main/webapp/coweb/jsoe</coweb-jsoe-src>
	</properties>

    <build>
        <plugins>
			<plugin>
			    <groupId>org.apache.maven.plugins</groupId>
			    <artifactId>maven-war-plugin</artifactId>
			    <version>2.2</version>
				<configuration>
                    <warSourceExcludes>coweb/jsoe/</warSourceExcludes>
				</configuration>
			</plugin>
		    <plugin>
			    <groupId>org.apache.maven.plugins</groupId>
			    <artifactId>maven-dependency-plugin</artifactId>
			    <version>2.4</version>
			    <executions>
				  <execution>
					<id>unpack</id>
					<phase>compile</phase>
					<goals><goal>unpack</goal></goals>
			        <configuration>
			          <artifactItems>
			            <artifactItem>
			              <groupId>org.cometd.javascript</groupId>
			              <artifactId>cometd-javascript-common</artifactId>
			              <version>${cometd.version}</version>
			              <type>war</type>
			              <overWrite>false</overWrite>
			              <outputDirectory>${project.build.directory}/tmp</outputDirectory>
						  <includes>**/cometd.js,**/cometd/AckExtension.js</includes>
			            </artifactItem>
			          </artifactItems>
			          <!-- other configurations here -->
			        </configuration>
			     </execution>
		      </executions>
			  
			</plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>prepare-package</phase>
                        <configuration>
                            <tasks>
								<property name="workpath" location="${project.build.directory}/tmp" />
								<echo message="HERE ***************************   ${workpath}" />

                                <!-- Pull in cometd. -->
                                <delete dir="${project.build.directory}/${project.artifactId}-${project.version}/org/cometd" />
                                <copy file="${workpath}/org/cometd.js"
                                    tofile="${project.build.directory}/${project.artifactId}-${project.version}/org/cometd.js" />
                                <copy file="${workpath}/org/cometd/AckExtension.js"
                                    tofile="${project.build.directory}/${project.artifactId}-${project.version}/org/cometd/AckExtension.js" />

                                <!-- Pull in requirejs's i18n library. -->
								<mkdir dir="${project.build.directory}/${project.artifactId}-${project.version}/org/requirejs"/>
                                <get src="${i18n-plugin-url}"
                                    dest="${project.build.directory}/${project.artifactId}-${project.version}/org/requirejs/i18n.js"/>

                                <!-- Use only the relevant coweb-jsoe files. -->
                                <copy todir="${coweb-jsoe}">
                                    <fileset dir="${coweb-jsoe-src}/src/coweb/jsoe">
                                        <include name="*.js" />
                                        <exclude name="OTEngine.js" />
                                    </fileset>
                                </copy>
                                <copy todir="${coweb-jsoe}/nls">
                                    <fileset dir="${coweb-jsoe-src}/src/coweb/jsoe/nls" />
                                </copy>

							  </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
	<dependencies>
	  <dependency>
		<groupId>org.cometd.javascript</groupId>
        <artifactId>cometd-javascript-common</artifactId>
        <version>${cometd-version}</version>
		<type>war</type>
		<scope>provided</scope>
	</dependency>
    </dependencies>
</project>
