All our company's RCP plug-ins have the same Maven parent, and after adding a bunch of Maven plug-ins to it I realized that Tycho is not as deterministic as I'd like it to be.
That's hardly news, I know, so that's why I want to set up some tests for the parent pom.xml. I'm thinking of basic stuff: which profiles are enabled, which plug-ins are executed, what exception is thrown for a defined pom.xml, command line arguments and target platform.
Even though most other projects seem to have a master POM somewhere, I could not find any way to test it. How do I do that?
My team is responsible for creating a suite of corporate POMs for the development staff. I have used the maven-invoker-plugin
for validating parent POM behavior. Look at the source (test) code for many of the Apache Maven plugins and you'll find invoker test cases if you need help getting started.
Validation of the results is done with a post build script written in either Beanshell or Groovy. For the types of things you'd like to verify (plugin executions, profile activations, etc.) the best way I've found is to examine the build.log
for expected messages. I wrote a helper class with methods like this:
public static boolean assertPatternsExist(final InputStream is, final String fileName,
final List<String> patternList) throws IOException {
try (final Scanner scanner = new Scanner(is)) {
for (final String pattern : patternList) {
if (scanner.findWithinHorizon(pattern, 0) == null) {
LOG.error(String.format("Could not match pattern '%s' in file %s", pattern, fileName)); //$NON-NLS-1$
return false;
}
}
}
return true;
}
And then my validation script (verify.groovy) includes validations using those helper methods.
def result = assertPatternsExist(new File(basedir, '/build.log'), [
'INFO.*?maven-dependency-plugin:.*?:copy-dependencies \\(some-execution-id\\)',
'INFO.*?maven-assembly-plugin:.*?:single \\(another-execution-id\\)',
'.*?propertyDefinedInProfile = valueFromActivatedProfile' ])
In this example, the test is expecting the dependency plugin's copy-dependencies
goal to be run as part of an execution with id 'some-execution-id', followed by the assembly plugin's single
goal run as part of execution 'another-execution-id'. The third pattern verifies that a property defined in a profile has the value expected if that profile was activated. Order of the patterns matters.
Note that the search criteria is specified in terms of regular expressions. This should insulate the tests from minor changes in log format. The test suite was written for Maven 3.0.x and has continued to work with later Maven versions thus far.