| “Strategies in (*)ability” | [iDareMedia] [JWare] [PET] [CI-Dashboard] |
How do I ensure a particular artifact is generated at most once?
To force SAM to reuse an artifact once it has been generated, you need to make sure of two things. First, the artifact in question must be announced when it is first generated. By announcing an artifact you publicize it’s location and the creation context where others or it’s own definition can find it later. Second, the artifact’s definition must be setup so that it will definitely reuse previously announced artifacts (assuming the contexts match). The following <artifactdef> example demonstrates how you might declare a set of artifacts varconfs that will be generated once and reused thereafter:
<artifactdef name="varconfs">
<defaults announce="yes" usecache="yes">
<method use="mksandbox"/>
<parameter name="module" value="saladbar-varconfs"/>
<parameter name="in" value="${pristine.dir}"/>
<parameter name="clean" value="no"/>
</defaults>
<version name="all">
<parameter name="selection" value="."/>
</version>
<version name="java">
<parameter name="selection" value="java"/>
</version>
<version name="java-stable" inherit="java">
<parameter name="tag" value="r1-1build16"/>
<parameter name="in" value="${pristine.dir}/snapshots/r1-1build16"/>
</version>
<version name="xslt">
<parameter name="selection" value="xslt"/>
</version>
…
</artifactdef>
In this example, the announce and usecache options have been explicitly included in the artifact definition to ensure the required behavior regardless of the values of the SAM global properties that would otherwise control these features. Normally, you would not set these options on each artifact definition. You would instead either rely on the SAM system defaults (artifacts are automatically announced and reused if possible), or set the global configuration property jware.antx.defaults.artifacts.announced to either yes or no. In our case, even if announcements are turned off in general, our set of varconfs will be announced and reused as needed. So in the following script, if we called the latest-all target, the varconfs-java artifact would be generated once and reused.
<property name="jware.antx.defaults.artifacts.announced" value="no"/>
<target name="latest-libraries" depends="init,…">
<varconfs-java/>
<sources-latest varconfs.home="${varconfs-java.loc}"/>
…
</target>
<target name="latest-examples" depends="init,…">
<varconfs-java/>
<examples-latest varconfs.home="${varconfs-java.loc}"/>
…
</target>
<target name="latest-all" depends="latest-libraries,latest-examples,…">
<varconfs-xslt/>
…
</target>