0

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?

1

I 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.