<?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>0.8.3</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>
	</properties>

    <build>
        <plugins>
		    <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}" />
									
							        <concat destfile="${workpath}/amd">define(function () {
if (typeof dojo !== 'undefined' &amp;&amp; !dojo.provide) { dojo.provide = function() {}; this.org = this.org || {}; org.cometd = {}; }
							        </concat>
							        <concat destfile="${workpath}/amd" append="yes">
							                <fileset file="${workpath}/org/cometd.js" />
							        </concat>
							        <concat destfile="${workpath}/amd" append="yes">
							                <fileset file="${workpath}/org/cometd/AckExtension.js" />
							        </concat>
							        <concat destfile="${workpath}/amd" append="yes">return org.cometd;
});
							        </concat>
									
							        <move file="${workpath}/amd" tofile="${project.build.directory}/${project.artifactId}-${project.version}/org/cometd.js" />
									<delete dir="${project.build.directory}/${project.artifactId}-${project.version}/org/cometd" />

									<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"/>
							  </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>
