<!--
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 * 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.
 */
 -->
<project xmlns:j="jelly:core"
         xmlns:assert="assert"
         xmlns:ant="jelly:ant"
         xmlns:u="jelly:util"
         xmlns:maven="jelly:maven"
         xmlns:x="jelly:xml">

  <goal name="testPlugin" prereqs="test-default, test-classpath, test-project">
  </goal>

   <goal name="test-init">
    <j:set var="dotProject" value="${basedir}/.project"/>
    <j:set var="dotClasspath" value="${basedir}/.classpath"/>
    <attainGoal name="eclipse:clean"/>
  </goal>

  <goal name="test-default">
    <attainGoal name="test-init"/>
    <j:set var="maven.eclipse.resources.addtoclasspath" value="true"/>
    <attainGoal name="eclipse"/>

    <assert:assertFileExists file="${dotClasspath}" />
    <assert:assertFileExists file="${dotProject}" />

  </goal>

  <goal name="test-classpath">
    <attainGoal name="test-init"/>
    <j:set var="maven.eclipse.resources.addtoclasspath" value="true"/>
    <attainGoal name="eclipse:generate-classpath"/>

    <assert:assertFileExists file="${dotClasspath}" />

    <u:file var="classpathFile" name="${dotClasspath}"/>
    <x:parse var="classpathDoc" xml="${classpathFile.toURL()}" />
    <x:set var="countResources" select="count($classpathDoc/classpath/classpathentry[contains(@path,'src/main/resources')])"/>
    <assert:assertEquals expected="1" value="${countResources.intValue().toString()}" msg="resources entry not found"/> 
    <x:set var="countNoresources" select="count($classpathDoc/classpath/classpathentry[contains(@path,'src/main/noresources')])"/>
    <assert:assertEquals expected="0" value="${countNoresources.intValue().toString()}" msg="noresources entry found"/> 
    <x:set var="countSources" select="count($classpathDoc/classpath/classpathentry[contains(@path,'src/main/java')])"/>
    <assert:assertEquals expected="0" value="${countSources.intValue().toString()}" msg="sources entry found"/> 

  </goal>

  <goal name="test-project">
    <attainGoal name="test-init"/>
    <j:set var="maven.eclipse.resources.addtoclasspath" value="true"/>
    <attainGoal name="eclipse:generate-project"/>

    <assert:assertFileExists file="${dotProject}" />

    <u:file var="projectFile" name="${dotProject}"/>
    <x:parse var="projectDoc" xml="${projectFile.toURL()}" />

    <x:set var="natures" select="$projectDoc/projectDescription/natures/nature"/>
    <x:set var="countNatures" select="count($natures)"/>
    <assert:assertEquals expected="1" value="${countNatures.intValue().toString()}" msg="expected only 1 nature"/>
    <assert:assertEquals expected="org.eclipse.jdt.core.javanature" value="${natures[0].text}" msg="expected the nature to be the java one"/>

    <x:set var="builders" select="$projectDoc/projectDescription/buildSpec/buildCommand/name"/>
    <x:set var="countBuilders" select="count($builders)"/>
    <assert:assertEquals expected="1" value="${countBuilders.intValue().toString()}" msg="expected only 1 builder"/>
    <assert:assertEquals expected="org.eclipse.jdt.core.javabuilder" value="${builders[0].text}" msg="expected the builder to be the java one"/>

  </goal>



</project>
