<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.projectdarkstar.example.hack</groupId>
    <artifactId>hack</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>hack-server</artifactId>
  <name>Hack Example Server</name>
  <packaging>jar</packaging>
  <description>
    Server module for the Project Darkstar Hack example.
  </description>

  <dependencies>
    <!-- Compile time dependencies -->
    <dependency>
      <groupId>com.projectdarkstar.server</groupId>
      <artifactId>sgs-server-api</artifactId>
    </dependency>
    <dependency>
      <groupId>com.projectdarkstar.server</groupId>
      <artifactId>sgs-shared</artifactId>
    </dependency>
    <dependency>
      <groupId>com.projectdarkstar.example.hack</groupId>
      <artifactId>hack-shared</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>

    <!-- Runtime dependencies -->
    <dependency>
      <groupId>com.projectdarkstar.server</groupId>
      <artifactId>sgs-server</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.projectdarkstar.ext.berkeleydb</groupId>
      <artifactId>db-binaries</artifactId>
      <type>zip</type>
    </dependency>
  </dependencies>


  <!-- Profiles setup to execute the server
       Enabling these profiles will bind the antrun test-run execution
       to the process-test-resources phase
       i.e. mvn process-test-resources -Psingle-node-server -->
  <profiles>

    <profile>
      <id>single-node-server</id>
      <properties>
	<run.phase>process-test-resources</run.phase>
	<run.properties>${run.properties.single}</run.properties>
      </properties>
    </profile>

    <profile>
      <id>multi-node-server-core</id>
      <properties>
	<run.phase>process-test-resources</run.phase>
	<run.properties>${run.properties.multi.core}</run.properties>
      </properties>
    </profile>

    <!-- Remember to set the com.sun.sgs.server.host property to the
         host running the core server if it is running on a different
         host -->
    <profile>
      <id>multi-node-server-app</id>
      <!-- Never recreate the data store, the core node will do this
           if necessary. -->
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>clean-datastore</id>
                <phase></phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <properties>
	<run.phase>process-test-resources</run.phase>
	<run.properties>${run.properties.multi.app}</run.properties>
      </properties>
    </profile>

    <!-- Disable the deletion of the datastore
	 by unbinding it from the lifecycle.
	 Enabling this profile will keep the datastore from a previous
	 execution if it exists.  example:
	 mvn process-test-resources -Psingle-node-server,retain-datastore -->
    <profile>
      <id>retain-datastore</id>
      <build>
	<plugins>
	  <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
	    <executions>
	      <execution>
		<id>clean-datastore</id>
		<phase></phase>
	      </execution>
	    </executions>
	  </plugin>
	</plugins>
      </build>
    </profile>

    <!-- In order to enable the netbeans profiler, this profile must
	 be activated.
	 This needs to be reworked slightly so that it is platform
	 and machine independent -->
    <profile>
      <id>netbeans-profiler</id>
      <properties>
	<run.jvm.args.profile>-agentpath:/opt/netbeans-6.1/profiler3/lib/deployed/jdk15/linux/libprofilerinterface.so=/opt/netbeans-6.1/profiler3/lib,5140</run.jvm.args.profile>
      </properties>
    </profile>

  </profiles>



  <build>
    <plugins>

      <!-- The berkeleydb binary package must be retrieved and unpacked
	   Before the test phase so that they are available during
	   runtime of the unit tests and other executions-->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack-bdb-binaries</id>
          </execution>
        </executions>
      </plugin>


      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
	<executions>

	  <!-- Cleans out the directories used to run the app
	       Runs during the validate phase -->
	  <execution>
	    <id>clean-datastore</id>
	    <phase>generate-test-resources</phase>
	    <goals>
              <goal>run</goal>
            </goals>
	    <configuration>
              <tasks>
		<delete dir="${datastore.dir}"/>
              </tasks>
            </configuration>
	  </execution>

	  <!-- Builds the directories necessary for running the app
	       with the antrun configuration.  Runs in the
	       generate-test-resources phase -->
          <execution>
            <id>make-datastore</id>
            <phase>generate-test-resources</phase>
	    <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <mkdir dir="${datastore.dir}"/>
              </tasks>
            </configuration>
          </execution>

	  <!-- Copies the Hack game data (dungeons, items, monsters,
	       etc.) to the build directory.  Runs in the
	       generate-test-resources phase -->
          <execution>
            <id>copy-game-data</id>
            <phase>generate-test-resources</phase>
	    <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <copy todir="${project.build.directory}/gameData">
		  <fileset dir="${basedir}/gameData"/>
		</copy>
              </tasks>
            </configuration>
          </execution>

	  <!-- The test-run profile execution of the antrun plugin
	       is configured to run the application
	       In order to bind it to a lifecycle phase and 
	       provide the appropriate logging parameter, enable
	       one of the profiles above.  example:
	       mvn process-test-resources -Psingle-node-server -->
	  <execution>
	    <id>test-run</id>
	    <phase>${run.phase}</phase>
	    <goals>
	      <goal>run</goal>
	    </goals>
	    <configuration>
	      <tasks>
		<java classname="com.sun.sgs.impl.kernel.Kernel"
		      fork="true">
		  <jvmarg line="${run.jvm.args}"/>
		  <jvmarg line="${run.jvm.args.profile}"/>
		  <jvmarg line="-server"/>
		  <sysproperty key="java.library.path" 
			       file="${run.javapath}"/>
		  <sysproperty key="java.util.logging.config.file"
			       file="${run.logging}"/>
		  <sysproperty key="com.sun.sgs.impl.service.data.store.db.environment.class"
			       value="${run.bdb.env}"/>
                  <sysproperty key="com.sun.sgs.impl.service.data.store.DataStoreImpl.directory"
                               value="${datastore.dir}"/>
                  <sysproperty key="com.sun.sgs.server.host"
                               value="${com.sun.sgs.server.host}"/>
		  <classpath>
		    <path refid="maven.test.classpath"/>
		  </classpath>
		  <arg value="${run.properties}"/>
		</java>
	      </tasks>
	    </configuration>
	  </execution>


	  
        </executions>
      </plugin>

    </plugins>
  </build>


  <properties>
    <run.jvm.args></run.jvm.args>
    <run.jvm.args.profile></run.jvm.args.profile>

    <run.logging>${basedir}/src/test/properties/logging.properties</run.logging>
    <run.properties.single>src/test/properties/HackSingle.properties</run.properties.single>
    <run.properties.multi.core>src/test/properties/HackMulti.properties</run.properties.multi.core>
    <run.properties.multi.app>src/test/properties/HackApp.properties</run.properties.multi.app>
    <datastore.dir>${project.build.directory}/dsdb</datastore.dir>
    <com.sun.sgs.server.host>localhost</com.sun.sgs.server.host>
  </properties>


</project>
