ant-ivy-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dstei...@web.de
Subject Proposal: listModules with [index]
Date Thu, 02 Aug 2007 16:10:28 GMT
Hi Gilles,

you asked for the right value to give using the listmodules task. Here is the modified code
of org.apache.ivy.ant.IvyListModules for using [index] in the result of the listmodules task.
My changes are marked with /*** DS - start ***/ and /*** DS - end ***/:

public void doExecute() throws BuildException {
        if (organisation == null) {
            throw new BuildException("no organisation provided for ivy findmodules");
        }
        if (module == null) {
            throw new BuildException("no module name provided for ivy findmodules");
        }
        if (revision == null) {
            throw new BuildException("no revision provided for ivy findmodules");
        }
        if (property == null) {
            throw new BuildException("no property provided for ivy findmodules");
        }
        if (value == null) {
            throw new BuildException("no value provided for ivy findmodules");
        }
        Ivy ivy = getIvyInstance();
        IvySettings settings = ivy.getSettings();
        ModuleRevisionId[] mrids = ivy.listModules(ModuleRevisionId.newInstance(organisation,
            module, branch, revision), settings.getMatcher(matcher));
        /*** DS - start ***/
        int length = mrids.length;
        int digits = 1;
        while ((length = length / 10) > 0) digits++;
        NumberFormat formatter = NumberFormat.getInstance();
        formatter.setMinimumIntegerDigits(digits);
        /*** DS - end ***/
        for (int i = 0; i < mrids.length; i++) {
            String name = IvyPatternHelper.substitute(settings.substitute(property), mrids[i]);
            String value = IvyPatternHelper.substitute(settings.substitute(this.value), mrids[i]);
            /*** DS - start ***/
            name = name.replaceAll("\\[index\\]",  formatter.format(i));
            /*** DS - end ***/
            getProject().setProperty(name, value);
        }
    }

The code is optimizable. It is just an example.
Now you can run listmodules that way having a well formatted result:

<ivy:listmodules
	organisation="${ivy.input.organisation}"
	module="${ivy.input.module}"
	revision="${ivy.input.revision}"
	property="ivy.list.[index]"
	value="   { [organisation] | [module] | [revision] }"/>
<echoproperties regex="ivy.list.*"/>

I hope you like the proposal and will adopt it.

Cheers,
Dieter

_____________________________________________________________________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000066


Mime
View raw message