home.

tagged: ant

Ant: Replacing text

You can use Ant to replace tokens in a file with values. With hello.txt as:
 
This is bullshit, really.
 
This target

 <target name="replace">
         <replace
              file="hello.txt"
              token="bullshit"
              value="sunshine, lollipops"
              summary="yes"
              >
         </replace>
 </target>

Will ensure hello.txt now states:

 This is sunshine, lollipops, really.

This target will do the same, but will allow you to specify multiple replaces:

       <replace
            file="hello.txt"
            summary="yes"
            >
            <replacefilter
                    token="bullshit"
                    value="definitely sunshine and lollipops"/>
            <replacefilter
                    token="is"
                    value="really is"/>
       </replace>

You can specify a property file too. Such as secrets.txt:

 hiya=EVERYTHING NICE

And this command

 <replace
    file="hello.txt"
    propertyFile="secrets.txt"
    summary="yes"
 >
    <replacefilter
       token="bullshit"
       property="hiya"
    />
 </replace>

Will result in
 
this is EVERYTHING NICE, really.

ant ant-replace


Ant: Timestamps

You can set the format of a timestamp as follows:

 <tstamp>
  <format pattern="yyyy-MM-dd-HH-mm-ss" property="TIME_STAMP"/>
 </tstamp>

And then echo it as a ${TIME_STAMP}.
 
The format is the same as Java's.

ant ant-date


ant sources as jar

To create a jar of your sources, the kind of this Eclipse likes to attach to jars so you can see what's happening when you're debugging, add this target:

 <target name="src-jar">
    <mkdir dir="${jar.dir}" />
    <jar destfile="${jar.dir}/${sourcesjar.name}" basedir="${src.dir}">
      <manifest>
      </manifest>
    </jar>
  </target>

ant


ant javadoc

These targets in your build.xml will one generate the javadoc in a directory and two put it in a jar for you.

    <target name="doc">
      <javadoc sourcepath="${src.dir}" destdir="${doc.dir}" />
    </target>
  
    <target name="doc-jar" depends="doc">
      <mkdir dir="${jar.dir}" />
      <jar destfile="${jar.dir}/${jardoc.name}" basedir="${doc.dir}">
        <manifest>
        </manifest>
      </jar>
    </target>

ant


apache ivy fetching

If your repository isn't local or isn't on the default maven reposistory on the internet, you'll need to specify it in ivysettings.xml. Apache Ivy calls these 'resolvers':

<ivysettings>
  <settings defaultResolver="chain"/>
  <resolvers>
    <chain name="chain">
      <ibiblio name="central" m2compatible="true"/>
       <url name="denevell">
          <ivy      pattern="http://ivy.denevell.org/[organisation]/[module]/[revision]/ivy-[revision].xml" />
          <artifact pattern="http://ivy.denevell.org/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
        </url>
    </chain>
  </resolvers>
</ivysettings>

Note we've kept the 'central' ibiblio resolver. This is the one at mvnrespository.com.
 
The pattern matches how we published using ssh.
 
Then in ivy.xml you'll say what you want to grab from that repository:

<ivy-module version="2.0">
  <info organisation="denevell" module="bws"/>
  <dependencies>
    <dependency org="denevell" name="BriefWebServer" rev="0.1"/>
  </dependencies>
</ivy-module>

So we're looking at http://ivy.denevell.org/denevell/BriefWebServer/0.1/ivy-0.1.xml next to find the files to get back down. That file was generated when ivy published the module.
 
Then you can run ant to do the retrieving.

<project xmlns:ivy="antlib:org.apache.ivy.ant" name="SampleApp" default="resolve">
 <target name="resolve">
     <ivy:retrieve type="jar" pattern="libs/[artifact]-[revision].[ext]"/>
     <ivy:retrieve type="source" pattern="libs-non-dex/[artifact]-[revision]-[type].[ext]"/>
 </target>
</project>

These two retrieve lines get different tpyes, jar and source, and put them into different directories, libs and libs-non-dex, specifying their filename pattern.
 
The files will be in lib/ by default.

ant ivy ivy-fetching

Page 2 of 3
prev next