Tag Archives: ant

Regular Expression Replacement in an Ant Property

I’m quite a newbie in Ant, but I thought it would be straightforward to do a regular expression replacement in a string contained in a property; in my case, I had to replace Windows backslashes with Unix slashes… apparently, unless you use the propertyregex task from Ant Contrib, that is not supported out-of-the-box: you have to pass through a file!

This stackoverflow post shows a possible solution, and starting from that, I created a macrodef to make it easier

This macro takes the property value to process (property.to.process) and the property name where to store the result; it outputs the input value to a temporary file, reads it back with a regular expression replacement (which is supported for files) and store it in the specified property (the temporary file is then deleted).

Here’s an example of use

 

Be Sociable, Share!

Mirror Eclipse repositories from Eclipse

In a previous post, I blogged about mirroring Eclipse repositories with the p2.mirror Ant task; Since this Ant task needs to be run via the Eclipse antRunner application, you need a full installation of Eclipse on the machine that will run the task and I showed how to run this task from the command line.

It might be more comfortable sometimes to run it from Eclipse; for this, you need to create a launch configuration which runs an Eclipse Application, the same you run from the command line: org.eclipse.ant.core.antRunner.

We create a new general project (say, my.eclipse.mirror) and we create a mirror.ant file with the following example content (see the previous post for more details):

mirror-repos 2012-12-22 13:48:46

This example will mirror

  • org.eclipse.rcp.sdk, the eclipse launcher and the feature for adding update site features to your RCP, from the main Juno release site,
  • the whole Orbit repository (that version of the repository)
  • the whole Buckminster headless repository

Now we select the “Run Configurations…” dialog

mirror-repos 2012-12-22 13:49:02

and we create a new Eclipse Application launch configuration, which we call run_mirror; we choose, as the Program to Run, the application org.eclipse.ant.core.antRunner. Note that this application is installed by default in your SDK, but if there is a different target platform active in your workspace, which does not include the org.apache.ant bundle, this launch will fail.

mirror-repos 2012-12-22 13:49:45

In the Arguments tab, we must specify the -buildfile argument (expected by the runner) passing our ant file mirror.ant; this file is intended to be relative to the Working directory, thus we must modify it by selecting our project relative to the workspace:

mirror-repos 2012-12-22 13:50:35

Optionally, we save this launch configuration, using the “Common” tab, into our project

mirror-repos 2012-12-22 13:51:00

By default, the mirror will be saved into the folder eclipsemirror into cartoon porn your home folder; you may want to change this by specifying the additional program argument -Dtarget.dir=<path>, for instance,

mirror-repos 2012-12-22 13:51:27

Choose Apply and then Run; in your console view you should see that the mirror task has started

 

You can ignore possible problems of dependencies which cannot be satisfied

 

Depending on your Network connection it might take some time, but in the end you should see something like

mirror-repos 2012-12-22 15:39:46

And you can see that the mirror directory will mimic the original repositories structure

mirror-repos 2012-12-22 16:54:33

This example project can be found at https://github.com/LorenzoBettini/eclipse-mirror-example

Happy mirroring! :)

 

Be Sociable, Share!