Skip to content

Instantly share code, notes, and snippets.

@cpilsworth
Created September 12, 2018 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpilsworth/b088c2f59c72c8d49eb5e3fc88ed9243 to your computer and use it in GitHub Desktop.
Save cpilsworth/b088c2f59c72c8d49eb5e3fc88ed9243 to your computer and use it in GitHub Desktop.
Maven POM for content sync - empty package creation | source upload | source build | source download | target install
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ====================================================================== -->
<!-- P R O J E C T D E S C R I P T I O N -->
<!-- ====================================================================== -->
<groupId>uk.co.diffa.contentsync</groupId>
<artifactId>sync</artifactId>
<version>1.1.0-SNAPSHOT</version>
<name>pkg-content-sync</name>
<description>Create, build, download, upload, install &amp; uninstall</description>
<!-- with this custom packaging type, the content package will be built during the `package` phase -->
<packaging>content-package</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<source.host>http://localhost:4502</source.host>
<source.username>admin</source.username>
<source.password>admin</source.password>
<target.host>http://deploy-content-to-here:4502</target.host>
<target.username>admin</target.username>
<target.password>admin</target.password>
<group.name>content-sync</group.name>
</properties>
<!-- NOTES:
* a package can be built and uploaded on the source ok
* it can be build on *source* instance _if_ we know the url (calculate?)
* It could probably be fetched using remote resources
* it can be installed on the remote (by specifying packageFile on install)
* could credentials be encryped using maven and passed in as params?
mvn install == create package locally, upload and build on source
mvn deploy == upload & install on target
mvn com.day.jcr.vault:content-package-maven-plugin:uninstall@rollback == rollback on target
-->
<build>
<resources>
<!-- vault META-INF resources (thumbnail etc.) -->
<resource>
<directory>${basedir}/src/main/content/META-INF</directory>
<targetPath>../vault-work/META-INF</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<includeEmptyDirs>true</includeEmptyDirs>
</configuration>
</plugin>
<!-- ====================================================================== -->
<!-- V A U L T P A C K A G E P L U G I N -->
<!-- ====================================================================== -->
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<!-- Upload the package in the *source* system without installing -->
<id>install-package-source</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
<configuration>
<targetURL>${source.host}/crx/packmgr/service.jsp</targetURL>
<install>false</install>
</configuration>
</execution>
<execution>
<!-- Upload the package in the *source* system without installing -->
<id>build-package-source</id>
<phase>install</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<targetURL>${source.host}/crx/packmgr/service.jsp</targetURL>
</configuration>
</execution>
<execution>
<!-- Upload the package to the *target* system and install -->
<id>install-package-target</id>
<phase>deploy</phase>
<goals>
<goal>install</goal>
</goals>
<configuration>
<targetURL>${target.host}/crx/packmgr/service.jsp</targetURL>
</configuration>
</execution>
<execution>
<!-- rollback is not bound to a phase but the execution id can be called directly
mvn com.day.jcr.vault:content-package-maven-plugin:uninstall@rollback ... -->
<id>rollback</id>
<goals>
<goal>uninstall</goal>
</goals>
<configuration>
<targetURL>${target.host}/crx/packmgr/service.jsp</targetURL>
</configuration>
</execution>
</executions>
<!-- general configuration for the plugin -->
<configuration>
<name>${project.artifactId}</name>
<filterSource>src/main/content/META-INF/vault/filter.xml</filterSource>
<verbose>true</verbose>
<failOnMissingEmbed>true</failOnMissingEmbed>
<failOnError>true</failOnError>
<group>${group.name}</group>
</configuration>
</plugin>
<!-- download the built package from the source system to the target/downloads folder -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>download-files</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- download file -->
<mkdir dir="${project.build.directory}/downloads"/>
<get src="${source.host}/etc/packages/${group.name}/${project.artifactId}-${project.version}.zip"
dest="${project.build.directory}/downloads/${project.artifactId}-${project.version}.zip"
verbose="true"
usetimestamp="true"
username="${source.username}"
password="${source.password}"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<!-- this removes the default deploy plugin from the maven deploy lifecycle phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
<!-- Fix the version of the plugin we are using for a reproducible build -->
<pluginManagement>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<version>0.0.24</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<!-- deploy is active by default - but will not register install if the rollback (or any other) profile is enabled -->
<profile>
<id>deploy</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<executions>
<execution>
<!-- Upload the package to the *target* system and install -->
<id>install-package-target</id>
<phase>deploy</phase>
<goals>
<goal>install</goal>
</goals>
<configuration>
<targetURL>${target.host}/crx/packmgr/service.jsp</targetURL>
</configuration>
</execution>
</executions>
<configuration>
<targetURL>http://${target.host}:${target.port}/crx/packmgr/service.jsp</targetURL>
<failOnError>true</failOnError>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!-- profile to rollback the package deployment on the target
this will uninstall the package (reverting to snapshot) but leave the package in-place
-->
<profile>
<id>rollback</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<executions>
<execution>
<id>rollback</id>
<goals>
<goal>uninstall</goal>
</goals>
<configuration>
<targetURL>${target.host}/crx/packmgr/service.jsp</targetURL>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment