Terri Simon Terri Simon - 1 month ago 19
Bash Question

Can I use a variable in a Maven profile as a parameter for a postinstallScriptlet with the RPM plugin?

I am updating some RPMs that were originally done with spec files to use the Maven RPM plugin. The original setup is rather convoluted, but includes a "common" project which is used by four other projects. The spec files were in that common project, as well as shell scripts that used parameters to specify certain things (let's say, to distinguish between Project A and Project B when making folder names). I want to make profiles that handle the parameter that were passed into the shell scripts. Those scripts handle a lot of things that I don't want to rework if I don't have to. Is there a way to use values that I set in the profile to act as the shell script parameters, providing that I use that shell script (minimally modified) as the postInstallScriptlet.

This is all on Linux (Centos 6).

So, the profile would look something like this:

<profile>
<id>beta</id>
<properties>
<ENVIRONMENT>Beta</ENVIRONMENT>
<INSTALL_DIR>/var/ProjA</INSTALL_DIR>
</properties>
</profile>


The script file would have something like this:

ENVIRONMENT=$1
INSTALL_DIR=$2


How can I get those two things to work together?

Answer

After further hunting and experimentation, I've been able to resolve this. There are two questions which describe how to do this at a higher level. Below the links, I will show what I did, in hopes of making this a useful example.

does-an-external-script-in-rpm-maven-plugin-have-access-to-maven-properties

and using-maven-rpm-plugin-how-do-i-to-replace-text-in-files-similar-to-the-assembly

The plugin section is:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-resources-plugin</artifactId>
   <version>3.0.1</version>
   <executions>
      <execution>
         <id>copy-resources</id>
         <phase>validate</phase>
         <goals>
            <goal>copy-resources</goal>
         </goals>
         <configuration>
            <outputDirectory>${basedir}/bin</outputDirectory>
            <resources>
               <resource>
                  <!-- note that this will process all files in this directory -->                  
                  <directory>trunk/rpm_scripts/resources</directory>
                  <filtering>true</filtering>
               </resources>
         </configuration>
      </execution>
   </executions>
</plugin>

Then, in the profile:

<profile>
   <id>beta</id>
   <properties>
      <VERSION>5.0.0</VERSION>
      <MODULE>Project A</MODULE>
      <!-- and more -->
   </properties>
</profile>

And in the postinstallScriptlet file:

VERSION=${VERSION}
MODULE=${MODULE}

This results in the file being copied into the ${basedir}/bin directory with all the variable substitutions being made. This is exactly what I needed, so I hope this helps someone else.