<?xml version="1.0"?>

<project 
  xmlns:j="jelly:core"
  xmlns:maven="jelly:maven"
  xmlns:ant="jelly:ant">

  <goal name="jdee"
    description="Generate JDEE project file"
    prereqs="jdee:generate-project"/>
  
  <!-- Generate project file in basedir -->
  <goal name="jdee:generate-project"
    description="Generate project file in basedir">

    <j:set var="projectFile"
	  value="${context.getVariable('maven.jdee.project.file')}" />
    <j:if test="${projectFile == null}">
      <j:set var="projectFile" value="prj.el"/>
    </j:if>

	<ant:echo>Generating file ${projectFile} ...</ant:echo>
	
    <j:file name="${basedir}/${projectFile}" prettyPrint="false"
	   omitXmlDeclaration ="true" xmlns="dummy">
;; generated by jdee plugin (see http://maven.apache.org/reference/plugins/jdee/)
(jde-project-file-version "1.0")
(jde-set-variables
 (quote (jde-project-name "${pom.artifactId}"))
 (quote (jde-project-file-name "${maven.jdee.project.file}"))
      <j:if test="${sourcesPresent}">
        <maven:makeRelativePath var="srcDir" basedir="${basedir}" path="${pom.build.sourceDirectory}" />
 (quote (jde-sourcepath (quote ("./${srcDir}"))))
		<j:whitespace />
      </j:if>
 (quote (jde-compile-option-directory "./target/classes"))
 (quote (jde-javadoc-gen-destination-directory "./target/docs/apidocs"))
 (quote (jde-project-file-name "${projectFile}"))
 (quote (jde-javadoc-gen-window-title "${pom.name} - ${pom.organization} (${pom.inceptionYear})"))
 (quote (jde-import-excluded-packages (quote ("target.*"))))

    <j:set var="mainClass"
	  value="${context.getVariable('maven.jdee.application.class')}" />
	  <j:if test="${mainClass != null}">
 (quote (jde-run-application-class "${mainClass}"))
		<j:whitespace> </j:whitespace>
	  </j:if>
(quote (jde-global-classpath (quote ("./target/classes"
      <j:if test="${unitTestSourcesPresent}">
        <maven:makeRelativePath var="srcDir" basedir="${basedir}" path="${pom.build.unitTestSourceDirectory}" />
"./${srcDir}" 	<j:whitespace />
      </j:if>
	  <!-- now iterate through all dependencies -->
        <j:forEach var="lib" items="${pom.artifacts}">
"${lib.path}"	<j:whitespace />
	  </j:forEach>
)))))
	</j:file>

	<ant:echo>Now reload the created project file (${projectFile}) in JDEE</ant:echo>
  </goal>
  
</project>
