Accessing downloaded files during Maven test phase

I have a Maven build where I need access to a certain set of files in the integration-test phase. These files are downloaded as a zip file from an URL (they are actually Jenkins artifacts) and they need to be unpacked before starting the integration tests. The zip file will be updated no more than once a day (when the Jenkins job runs), often more seldom than that. The zip file is rather large (500MB) and unpacking takes a considerable amount of time (~10 minutes), so downloading and unpacking should only be done when the zip file has been updated.

My first attempt at doing this was to create a Maven module which calls an ant script in its pre-integration-test phase to download/unpack in a local directory, but I cannot figure out how to set up the dependencies correctly so that this module is executed before any other tests are run.

What is the easiest way of doing this, without having to set up a separate repository to store the files in?

Answers


You should consider using the Maven Dependency Plugin which will do what you want.

First make sure that your zip-file is accessible from your Company's repository or your own local repository, look here. I just tried it with the eclipse zip file by issuing this:

$> mvn install:install-file -Dfile=eclipse-jee-indigo-SR1-win32-x86_64.zip -DgroupId=eclipse -DartifactId=eclipse -Dversion=1.0-SNAPSHOT -Dpackaging=zip

OK, now you have access to your zip file easily from maven. Now add these lines to your pom.xml where you need these file unpacked (I have used my newly uploaded eclipse artifact but you can easily replace with yours):

<build>
    <plugins>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>eclipse</groupId>
                                <artifactId>eclipse</artifactId>
                                <version>1.0-SNAPSHOT</version>
                                <type>zip</type>
                            </artifactItem>
                        </artifactItems>
                        <includes>**/*.ini</includes>
                        <outputDirectory>${project.build.directory}</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

The <phase/> indicates when the unpack should be done.

The <includes/> tag is optional and just something I wanted to show. Then the whole zip will not be unpacked and it reduces the time a lot.

The unpacking will now only be performed if the zip has changed and that is what you wanted to achieve.


If your ZIP file is available as a Maven dependency, I think you could do something like the following:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>unpacking</id>
        <phase>initialize</phase>
        <goals>
          <goal>unpack</goal>
        </goals>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>org.your.group.to.zip</groupId>
              <artifactId>the-zip</artifactId>
              <version>1-SNAPSHOT</version>
              <type>zip</type>
              <overWrite>false</overWrite>
              <outputDirectory>src/main/resources/something</outputDirectory>
              <excludes>*/somePath/**, */someOtherPath/**, **/pom.xml</excludes>
            </artifactItem>
          </artifactItems>
          <!-- Do not store markers in target so that they survive a mvn clean -->
          <markersDirectory>src/main/resources/markers/</markersDirectory>
        </configuration>
      </execution>
    </executions>
  </plugin>

Storing the markers in a different directory than target prevents them from being deleted during mvn clean, thus the whole unpacking should only be done when the ZIP actually changed.

I'm not 100% sure if the configuration above exactly fits to your needs, but the general idea should work with some tweaking. Please see especially this and this part of the documentation.


Need Your Help

What are MVP and MVC and what is the difference?

design-patterns model-view-controller user-interface mvp glossary

When looking beyond the RAD (drag-drop and configure) way of building user interfaces that many tools encourage you are likely to come across three design patterns called Model-View-Controller, Model-

Simple XML HELP !

php xml simplexml

I need some help ,