diff --git a/src/site/markdown/getting-started.md b/src/site/markdown/getting-started.md new file mode 100644 index 0000000..6290c35 --- /dev/null +++ b/src/site/markdown/getting-started.md @@ -0,0 +1,133 @@ + + +# Getting Started + +## Overview + +Using the `Verifier` consists out of three different phases + +1. Configure +2. Run +3. Verify + +## Configure + +The `Verifier` instance is constructed in the simplest case with just one argument taking the path name of the base directory containing the `pom.xml` of the project you want to build. + +``` +String baseDir = ... +Verifier verifier = new Verifier( baseDir ); +``` + +The configuration can be further tweaked with additional setter methods and/or constructors taking more parameters. + +### System Properties + +The following system properties are evaluated. None of them are required and in most cases the same behavior can also be achieved through constructor or setter method programmatically. + +| System Property | Description | Default Value | +| --- | --- | +| `verifier.forkMode` | The following values are supported:
`auto` uses the forked launcher when environment variables are set
`embedder` always uses the embedded launcher
any other value leads to always using the forked launcher | `auto` | +| `maven.home` | The directory containing the Maven executable in `bin/mvn` | not set | +| `user.home` | Set by JRE, used for determining Maven default local repository path or the fallback Maven executable | always set by JRE | +| `maven.bootclasspath` | Only relevant if Maven home could be determined and the embedded launcher is being used. Determines the classpath of the launcher. May contain multiple paths separated by the system specific path separator. | not set (using all JARs below `/boot` as class path) | +| `classworlds.conf` | Only relevant if Maven home could be determined and the embedded launcher is being used. The configuration file used by [Plexus Classworlds Loader][plexus-classwords]. | `/bin/m2.conf` +| `maven.repo.local` | Contains the path of the local Maven repository | Either repository path set in `settings.xml` or `/.m2/repository` | +| `maven.repo.local.layout` | Layout of the local Maven repository. Either `legacy` or `default` | `default` | + +### Finding Maven Executable + +The following mechanism determines the binary which is used for executing Maven. This is + +- either the embedded launcher which uses + - the `org.apache.maven.cli.MavenCli` class loaded from the context class loader (in case Maven Home could not be determined) or + - the [Plexus Classworlds Loader][plexus-classwords] (in case Maven Home could be determined) +- or the forked launcher + +Whether the embedded or the forked launcher are used depends on the field `forkJvm` set through the constructor or `setForkJvm` or as fallback on the value of system property `verifier.forkMode`. + +### Class Path For Embedded Launcher + +To use the embedded launcher it is important that some artifacts are in the class path. For the Context Class Loader case this would mean the following dependencies are needed at least (for Maven 3.8.4): + +``` + + + org.apache.maven + maven-embedder + 3.8.4 + test + + + + org.slf4j + slf4j-simple + 1.7.32 + test + + + + org.apache.maven + maven-compat + 3.8.4 + test + + + org.apache.maven.resolver + maven-resolver-connector-basic + 1.6.3 + test + + + org.apache.maven.resolver + maven-resolver-transport-http + 1.6.3 + test + +``` + +### Determining Maven Home Directory + +The following directories are considered as potential Maven home directory (relevant for both forked launcher and embedded launcher with [Plexus Classworlds Loader][plexus-classwords]). The first existing directory from the list is used. + +1. Maven Home path given in the constructor +2. System property `maven.home` +3. Environment variable `M2_HOME` +4. System property `user.home` suffixed with `/m2` (only considered if it contains `bin/mvn`) + +## Run + +Calling `executeGoals` runs Maven with the given goals or phases and optionally some additional environment variables. It throws a `VerificationException` in case the execution is not successful (e.g. binary not found or exit code > 0). It is either using a forked JVM or is executed in the same JVM depending on the configuration. + +``` +verifier.executeGoals( "package" ); +``` + +## Verify + +After executing the Maven goals there are several methods starting with prefix `verify` which allow you to check for the build result, check the log for certain contents and the existence of generated artifacts. + +The main method `verify(boolean)` takes into consideration a file named `expected-results.txt` being located in the base directory. Each line consists of a file path (optionally prefixed by `!`) and it is automatically verified that the file exists or is missing (in case the path starts with `!`). + +``` +verifier.verify( true ); // if true, throws an exception in case of errors in the build log +``` + +[plexus-classwords]: https://codehaus-plexus.github.io/plexus-classworlds/launcher.html \ No newline at end of file diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md new file mode 100644 index 0000000..2e797ef --- /dev/null +++ b/src/site/markdown/index.md @@ -0,0 +1,24 @@ + + +# About Apache Maven Verifier Component + +Provides a test harness for Maven integration tests. This is a library which can be used in own Java-based integration tests. Look at the [Getting Started guide](./getting-started.html) for more information on how to use it. + +More complex example usages can be found in the the [different integration tests](https://github.com/apache/maven-integration-testing/tree/master/core-it-suite/src/test/java/org/apache/maven/it) of [Maven Core Integration Tests](https://github.com/apache/maven-integration-testing). \ No newline at end of file diff --git a/src/site/site.xml b/src/site/site.xml index 97c1564..02586fa 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -24,6 +24,7 @@ under the License. +