<!--
  Maven dist plugin only runs jar:jar when creating the binary distribution,
  meaning that if the current project is of another type, then the artifact
  in the binary distribution is incorrect.  This is solved by running the
  goal to create the artifact if the current project is not of type 'jar'
  (cf. maven.multiproject.type), except when the current project is a project
  of type 'master' (a master project itself actually doesn't generate an
  artifact (but its subprojects do).
-->
<postGoal name="dist:prepare-bin-filesystem">

  <j:set var="type"
    value="${context.getVariable('maven.multiproject.type')}"/>

  <j:if test="${type != 'jar'}">

    <delete file="${maven.dist.bin.assembly.dir}/${maven.final.name}.jar"/> 

    <j:if test="${type != 'master'}">

      <attainGoal name="${type}:${type}"/>

      <j:choose>
        <!-- TBV : is maven.final.name always initialized? (e.g.  not defined
        in maven war plugin, but defined in ejb, jar, ear, ...  plugins) -->
        <j:when test="${type == 'ejb' || type = 'uberjar'}">
          <j:set var="fileToCopy" value="${maven.final.name}.jar"/>
        </j:when>
        <j:otherwise>
          <j:set var="fileToCopy" value="${maven.final.name}.${type}"/>
        </j:otherwise>
      </j:choose>

      <copy todir="${maven.dist.bin.assembly.dir}">
        <fileset dir="${maven.build.dir}">
          <include name="${fileToCopy}"/>
        </fileset>
      </copy>

    </j:if>

  </j:if>

</postGoal>

