Skip to content

Instantly share code, notes, and snippets.

@basinilya
Created July 17, 2018 13:41
Show Gist options
  • Select an option

  • Save basinilya/c2c1ad3fc0df2323fc5c5337c19648bb to your computer and use it in GitHub Desktop.

Select an option

Save basinilya/c2c1ad3fc0df2323fc5c5337c19648bb to your computer and use it in GitHub Desktop.
Deploy pre-built resource adapter archive as part of Enterprise Application project
<?xml version="1.0" encoding="UTF-8"?>
<project name="EnterpriseApplication1" default="default" basedir="." xmlns:ear="http://www.netbeans.org/ns/j2ee-earproject/2">
<description>Builds, tests, and runs the project EnterpriseApplication1.</description>
<import file="nbproject/build-impl.xml"/>
<!-- This fixes missing ear file before deploy outside of Netbeans -->
<target name="-init-deploy-ant" depends="dist,EnterpriseApplication1-impl.-init-deploy-ant" unless="netbeans.home">
</target>
<!-- The hook to workaround some problems during deployment -->
<target name="pre-run-deploy">
<antcall target="re-eval-fileset-and-expand-archives"/>
</target>
<!-- Extra archives that Netbeans forgets to expand when deploying -->
<!-- The fileset must be global to be visible in <antcall> targets -->
<!-- Don't use it at top level, because ${build.dir} not set yet -->
<fileset dir="${build.dir}" id="archives.to.expand">
<include name="*.rar"/>
</fileset>
<!-- Call "expand-archive" for each file in the fileset -->
<!-- Calling this target with <antcall> to re-evaluate the fileset -->
<target name="re-eval-fileset-and-expand-archives" if="netbeans.home">
<resourcecount property="count.archives.to.expand">
<fileset refid="archives.to.expand"/>
</resourcecount>
<antcall target="repeat.recursive">
<param name="repeat.target" value="expand-archive" />
<param name="repeat.n" value="${count.archives.to.expand}" />
</antcall>
</target>
<!-- unzip nth archive in the fileset into its own directory -->
<target name="expand-archive">
<length property="repeat.base1.i" string="x${save.repeat.grow}" />
<resources id="nth.archive">
<last>
<first count="${repeat.base1.i}">
<fileset refid="archives.to.expand"/>
</first>
</last>
</resources>
<pathconvert property="extract.dir" refid="nth.archive">
<!-- replace last dot with underscore -->
<mapper type="regexp" from="(.*)[.](.*)" to="\1_\2" />
</pathconvert>
<delete dir="${extract.dir}"/>
<unzip dest="${extract.dir}">
<resources refid="nth.archive"/>
</unzip>
<delete>
<resources refid="nth.archive"/>
</delete>
</target>
<!-- repeat using recursion -->
<target name="repeat.recursive">
<!-- default value -->
<property name="repeat.grow" value="" />
<condition property="repeat.break">
<length string="${repeat.grow}" length="${repeat.n}" />
</condition>
<antcall target="_repeat.recursive" />
</target>
<!-- helper for forbidden recurse self -->
<target name="_repeat.recursive" unless="repeat.break">
<antcall target="${repeat.target}">
<param name="save.repeat.grow" value="${repeat.grow}" />
<!-- reset in case of nested loops -->
<param name="repeat.grow" value="" />
</antcall>
<antcall target="repeat.recursive">
<param name="repeat.grow" value="${repeat.grow}x" />
</antcall>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment