Trying to publish directory tree and auxiliary properties file with apache ivy, with later complex retrieval

StackOverflow https://stackoverflow.com/questions/21465207

  •  05-10-2022
  •  | 
  •  

Вопрос

I'm still struggling with figuring out how to integrate Apache Ivy into my somewhat complex Ant build.

If it matters, I'm using ATG Dynamo, which contributes most of the mess I'm trying to deal with.

The result of a build of a module is a "build" directory, with several subdirectories. I need to publish the entire contents of the "build" directory, along with a properties file (env/default.properties) that is not produced by the build, but one property in that file is needed when later retrieving this artifact, as it indicates the absolute path (relative to another property setting) where the contents of the "build" directory need to be installed.

The entire build will have several similarly structured modules. I'm pretty sure the target that does the "ivy:publish" can be defined in a "base" build script that all the module build scripts import.

I imagine the "ivy.xml" for each module would have a "publications" element that specifies the two (?) pieces that are being published, being the "build" directory and the "env/default.properties" file. I've never seen an example that publishes a directory, is that possible? If not, then I would guess that I'd have to specify more processing and detail in the "ivy:publish" target, such that I would first zip up the "build" directory and the "env/default.properties" file both into a zip file and publish that as the single artifact. Is this more likely?

Это было полезно?

Решение

It is quite new in Ivy, and it is not released yet, but there is a concept of "packaging" which can handle directories.

See the official documentation: http://ant.apache.org/ivy/history/trunk/concept.html#packaging

With this feature, Ivy can handle by itself the unzipping of a folder. On the publish part, you are on your own, you'll have to make a zip yourself. On the retrieve part, Ivy will unzip the folder in the cache. So you will still have to do some process to copy it at the proper place.

It has not been tested, but probably you can go even further by implementing a custom unpacking algorithm, which will do the unpacking at the proper place. You'll have to implement a class which extends org.apache.ivy.core.pack.ArchivePacking, and declare it in your ivysettings.xml, like this:

<ivysetting>
    <classpath file="${ivy.settings.dir}/custom-packing.jar"/>
    <typedef name="customPacking" classname="com.acme.ivy.CustomPacking" />
    <customPacking />
</ivysettings>

And then in your ivy.xml, declare your artifact as packaged by your custom packaging name:

<ivy-module version="1.0">
    ...
    <publications>
        <artifact name="mydistrib" type="distrib" ext=".zip" packaging="my-custom-packaging" />
    </publications>
</ivy-module>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top