As part of a development deployment - I need to SCP a zipped folder of assets to a virtual machine, and then extract it there.
Is there a plugin(s) that will do this, before I roll my own?
Software Recommendations Stack Exchange is a question and answer site for people seeking specific software recommendations. It only takes a minute to sign up.
Sign up to join this communityI found the maven-antrun-plugin
is perfect for this kind of thing.
Taken from this StackOverflow answer
<profiles>
<profile>
<id>deploy</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>ftp</id>
<phase>install</phase>
<configuration>
<failOnError>false</failOnError>
<tasks>
<fileset id="zipfiles.to.copy" dir="${archives.source}" includes = "*.zip">
<include name = "*unminified.zip"/>
<include name = "*thirdparty.zip"/>
</fileset>
<!-- copy the archives to the remote server -->
<scp todir="${user}:${password}@${vagrant.host}:${archives.destination}">
<fileset refid="zipfiles.to.copy" />
</scp>
<!-- Build the command line for unzip - the idea here is to turn the local
paths into the corresponding paths on the remote, i.e. to turn
C:\path\to\zipfiles\file1.zip;C:\path\to\zipfiles\file2.zip... into
/home/testuser/archives/file1.zip /home/testuser/archives/file2.zip
For this to work there must be no spaces in any of the zipfile names.
-->
<pathconvert targetos="unix" pathsep=" " property="unzip.files" refid="zipfiles.to.copy">
<map from="${basedir}/${archives.source}" to="${archives.destination}" />
</pathconvert>
<!-- execute the command. Use the "-d" option to unzip so it will work
whatever the "current" directory on the remote side -->
<sshexec host="${vagrant.host}" username="${user}" password="${password}"
command="/bin/sh -c '
for zipfile in ${unzip.files}; do
/usr/bin/unzip -o -d ${unzip.destination} $$zipfile ; done '" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The one thing to be aware of is the use of your ${archive.source}
and ${basedir}
in the pathconvert
command.
I made it this way because you need to explicit with the full path name in the pathconvert - but you want to be relative in sourcing where they're from in the first place.