John Mercier
John Mercier

Reputation: 1705

Ant task to delete from ivy local repo

I have a local repository where artifacts are publish as an m2 compatible repository.

<filesystem name="local" m2compatible="true" local="true">
    <ivy pattern="${ivy.local.default.root}/[organization]/[module]/[revision]/[module]-[revision](-[classifier]).pom" />
    <artifact pattern="${ivy.local.default.root}/[organization]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]" />
</filesystem>

The ivy info has '.'s in the organization.

For example,

<info organization="com.github.org" module="module" rev="0.1" status="release"/>

When artifacts are published they end up in directories like this:

/.ivy2/local/com/github/org/module/0.1/*

The delete task is setup like this:

<delete dir="${ivy.local.default.root}/${ivy.organization}/${ivy.module}/${ivy.revision}"/>

I believe this doesn't work because ivy.organization is not split into separate directories for the delete task.

How can I setup the projects to correctly delete the published jar files?

Upvotes: 1

Views: 235

Answers (1)

Lolo
Lolo

Reputation: 4357

It can be done with a bit of scripting to call String.replaceAll() on the string you want to transform into a file path fragment. For instance with the following macrodef:

  <!-- =============================================================================
    Replaces all '.' in groupId with '/' and put the result in a property
    Attributes:
    - groupId: maven groupId
    - result: name of the property in which to put the result
  ============================================================================== -->

  <macrodef name="pathFrom">
    <attribute name="groupId"/>
    <attribute name="result" default="path"/>
    <sequential>
      <local name="g"/>
      <property name="g" value="@{groupId}"/>
      <script language="javascript">
        project.setProperty("@{result}", project.getProperty("g").replaceAll("\\.", "/"));
      </script>
    </sequential>
  </macrodef>

Here's an example usage:

  <target name="test">
    <property name="myGroup" value="com.github.org"/>
    <pathFrom groupId="${myGroup}" result="tmp.path"/>
    <echo message="converted from '${myGroup}' to '${tmp.path}'"/>
  </target>

With the following output when invoked with ant test:

test:
    [echo] converted from 'com.github.org' to 'com/github/org'

Upvotes: 2

Related Questions