Package org.apache.maven.it
Class Verifier
java.lang.Object
org.apache.maven.it.Verifier
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private final String
private boolean
private boolean
private static final String[]
private final String[]
private static MavenLauncher
private final ByteArrayOutputStream
private Boolean
Iftrue
usesForkedLauncher
, iffalse
usesEmbedded3xLauncher
, otherwise considers the valueforkMode
.private String
Either "auto" (useForkedLauncher
whenenvironmentVariables
is not empty, otherwise useEmbedded3xLauncher
) , "embedder" (always useEmbedded3xLauncher
) or something else (always useForkedLauncher
).private String
private String
private static final String
private String
private static final String
private boolean
private String
private PrintStream
private PrintStream
private final ByteArrayOutputStream
private Properties
private boolean
private Properties
-
Constructor Summary
ConstructorsModifierConstructorDescriptionVerifier
(String basedir, String settingsFile, boolean debug, boolean forkJvm, String[] defaultCliOptions) private
Verifier
(String basedir, String settingsFile, boolean debug, Boolean forkJvm, String[] defaultCliOptions, String mavenHome) Verifier
(String basedir, String settingsFile, boolean debug, String mavenHome, String[] defaultCliOptions) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCliOption
(String option) private static void
addMetadataToList
(File dir, boolean hasCommand, List<String> l, String command) void
Deprecated.void
assertArtifactNotPresent
(String org, String name, String version, String ext) Deprecated.private void
assertArtifactPresence
(boolean wanted, String org, String name, String version, String ext) void
assertArtifactPresent
(String org, String name, String version, String ext) Deprecated.void
assertFileMatches
(String file, String regex) Deprecated.UseverifyFileContentMatches(String, String)
instead.void
assertFileNotPresent
(String file) Deprecated.UseverifyFileNotPresent(String)
instead.void
assertFilePresent
(String file) Deprecated.UseverifyFilePresent(String)
instead.void
deleteArtifact
(String org, String name, String version, String ext) void
deleteArtifacts
(String gid) Deletes all artifacts in the specified group id from the local repository.void
deleteArtifacts
(String gid, String aid, String version) Deletes all artifacts in the specified g:a:v from the local repository.void
deleteDirectory
(String path) Deletes the specified directory.discoverIntegrationTests
(String directory) private void
void
private void
executeCommand
(String line) void
executeGoal
(String goal) void
executeGoal
(String goal, Map<String, String> envVars) void
executeGoals
(List<String> goals) void
void
executeHook
(String filename) filterFile
(String srcPath, String dstPath, String fileEncoding, Map<String, String> filterProperties) Filters a text file by replacing some user-defined tokens.filterFile
(String srcPath, String dstPath, String fileEncoding, Properties filterProperties) Deprecated.private void
findLocalRepo
(String settingsFile) getArtifactFileNameList
(String org, String name, String version, String ext) getArtifactMetadataPath
(String gid, String aid) Gets the path to the local artifact metadata.getArtifactMetadataPath
(String gid, String aid, String version) Gets the path to the local artifact metadata.getArtifactMetadataPath
(String gid, String aid, String version, String filename) Gets the path to a file in the local artifact directory.private String
getArtifactPath
(String artifact) getArtifactPath
(String groupId, String artifactId, String version, String ext) Returns the absolute path to the artifact denoted by groupId, artifactId, version, extension and classifier.private static String
private static String
getLogContents
(File logFile) Gets the name of the file used to log build output.private MavenLauncher
getMavenLauncher
(Map<String, String> envVars) private BufferedReader
private void
boolean
boolean
boolean
private static boolean
isVelocityError
(String line) Checks whether the specified line is just an error message from Velocity.static void
launchSubversion
(String line, String basedir) Loads the (non-empty) lines of the specified text file.loadProperties
(String filename) static void
Gets a new copy of the default filter properties.parseClasspath
(String classpath) replaceArtifacts
(String line, boolean hasCommand) void
private String
private static String
retrieveLocalRepo
(String settingsXmlPath) private static void
runIntegrationTest
(Verifier verifier) void
setAutoclean
(boolean autoclean) void
setCliOptions
(List<String> cliOptions) void
setDebug
(boolean debug) void
setDebugJvm
(boolean debugJvm) void
setEnvironmentVariable
(String key, String value) void
setEnvironmentVariables
(Map<String, String> environmentVariables) void
setForkJvm
(boolean forkJvm) void
setLocalRepo
(String localRepo) void
setLocalRepoLayout
(String localRepoLayout) void
setLogFileName
(String logFileName) Sets the name of the file used to log build output.void
setMavenDebug
(boolean mavenDebug) void
setSystemProperties
(Properties systemProperties) void
setSystemProperty
(String key, String value) void
setVerifierProperties
(Properties verifierProperties) static String
void
verify
(boolean chokeOnErrorOutput) void
verifyArtifactContent
(String groupId, String artifactId, String version, String ext, String content) Verifies that the artifact given by its Maven coordinates exists and contains the given content.void
verifyArtifactNotPresent
(String groupId, String artifactId, String version, String ext) Verifies that the artifact given through its Maven coordinates does not exist.private void
verifyArtifactPresence
(boolean wanted, String groupId, String artifactId, String version, String ext) void
verifyArtifactPresent
(String groupId, String artifactId, String version, String ext) Verifies that the artifact given through its Maven coordinates exists.void
private void
verifyExpectedResult
(String line) void
verifyFileContentMatches
(String file, String regex) Verifies the given file's content matches an regular expression.void
verifyFileNotPresent
(String file) Verifies that the given file does not exist.private void
verifyFilePresence
(String filePath, boolean wanted) void
verifyFilePresent
(String file) Verifies that the given file exists.void
verifyTextInLog
(String text) Throws an exception if the text is not present in the log.void
Writes a text file with the specified contents.
-
Field Details
-
LOG_FILENAME
- See Also:
-
DEFAULT_CLI_OPTIONS
-
localRepo
-
basedir
-
outStream
-
errStream
-
defaultCliOptions
-
originalOut
-
originalErr
-
cliOptions
-
systemProperties
-
environmentVariables
-
verifierProperties
-
autoclean
private boolean autoclean -
localRepoLayout
-
debug
private boolean debug -
forkJvm
Iftrue
usesForkedLauncher
, iffalse
usesEmbedded3xLauncher
, otherwise considers the valueforkMode
. -
logFileName
-
mavenHome
-
mavenDebug
private boolean mavenDebug -
forkMode
Either "auto" (useForkedLauncher
whenenvironmentVariables
is not empty, otherwise useEmbedded3xLauncher
) , "embedder" (always useEmbedded3xLauncher
) or something else (always useForkedLauncher
). Set through system propertyverifier.forkMode
. Only relevant ifforkJvm
isnull
. -
debugJvm
private boolean debugJvm -
useWrapper
private boolean useWrapper -
embeddedLauncher
-
MARKER
- See Also:
-
-
Constructor Details
-
Verifier
- Throws:
VerificationException
-
Verifier
- Throws:
VerificationException
-
Verifier
- Throws:
VerificationException
-
Verifier
- Throws:
VerificationException
-
Verifier
public Verifier(String basedir, String settingsFile, boolean debug, String[] defaultCliOptions) throws VerificationException - Throws:
VerificationException
-
Verifier
public Verifier(String basedir, String settingsFile, boolean debug, boolean forkJvm) throws VerificationException - Throws:
VerificationException
-
Verifier
public Verifier(String basedir, String settingsFile, boolean debug, boolean forkJvm, String[] defaultCliOptions) throws VerificationException - Throws:
VerificationException
-
Verifier
public Verifier(String basedir, String settingsFile, boolean debug, String mavenHome) throws VerificationException - Throws:
VerificationException
-
Verifier
public Verifier(String basedir, String settingsFile, boolean debug, String mavenHome, String[] defaultCliOptions) throws VerificationException - Throws:
VerificationException
-
Verifier
private Verifier(String basedir, String settingsFile, boolean debug, Boolean forkJvm, String[] defaultCliOptions, String mavenHome) throws VerificationException - Throws:
VerificationException
-
-
Method Details
-
getDefaultMavenHome
-
setLocalRepo
-
resetStreams
public void resetStreams() -
displayStreamBuffers
public void displayStreamBuffers() -
verify
- Throws:
VerificationException
-
verifyErrorFreeLog
- Throws:
VerificationException
-
isVelocityError
Checks whether the specified line is just an error message from Velocity. Especially old versions of Doxia employ a very noisy Velocity instance.- Parameters:
line
- The log line to check, must not benull
.- Returns:
true
if the line appears to be a Velocity error,false
otherwise.
-
verifyTextInLog
Throws an exception if the text is not present in the log.- Parameters:
text
- the text to assert present- Throws:
VerificationException
- if text is not found in log
-
stripAnsi
-
loadProperties
- Throws:
VerificationException
-
loadLines
Loads the (non-empty) lines of the specified text file.- Parameters:
filename
- The path to the text file to load, relative to the base directory, must not benull
.encoding
- The character encoding of the file, may benull
or empty to use the platform default encoding.- Returns:
- The list of (non-empty) lines from the text file, can be empty but never
null
. - Throws:
IOException
- If the file could not be loaded.- Since:
- 1.2
-
getReader
- Throws:
IOException
-
loadFile
public List<String> loadFile(String basedir, String filename, boolean hasCommand) throws VerificationException - Throws:
VerificationException
-
loadFile
- Throws:
VerificationException
-
replaceArtifacts
-
addMetadataToList
-
getArtifactPath
-
getArtifactPath
-
getArtifactPath
public String getArtifactPath(String gid, String aid, String version, String ext, String classifier) Returns the absolute path to the artifact denoted by groupId, artifactId, version, extension and classifier.- Parameters:
gid
- The groupId, must not be null.aid
- The artifactId, must not be null.version
- The version, must not be null.ext
- The extension, must not be null.classifier
- The classifier, may be null to be omitted.- Returns:
- the absolute path to the artifact denoted by groupId, artifactId, version, extension and classifier, never null.
-
getArtifactFileNameList
-
getArtifactMetadataPath
Gets the path to the local artifact metadata. Note that the method does not check whether the returned path actually points to existing metadata.- Parameters:
gid
- The group id, must not benull
.aid
- The artifact id, must not benull
.version
- The artifact version, may benull
.- Returns:
- The (absolute) path to the local artifact metadata, never
null
.
-
getArtifactMetadataPath
Gets the path to a file in the local artifact directory. Note that the method does not check whether the returned path actually points to an existing file.- Parameters:
gid
- The group id, must not benull
.aid
- The artifact id, may benull
.version
- The artifact version, may benull
.filename
- The filename to use, must not benull
.- Returns:
- The (absolute) path to the local artifact metadata, never
null
.
-
getArtifactMetadataPath
Gets the path to the local artifact metadata. Note that the method does not check whether the returned path actually points to existing metadata.- Parameters:
gid
- The group id, must not benull
.aid
- The artifact id, must not benull
.- Returns:
- The (absolute) path to the local artifact metadata, never
null
.
-
executeHook
- Throws:
VerificationException
-
executeCommand
- Throws:
VerificationException
-
launchSubversion
- Throws:
VerificationException
-
retrieveLocalRepo
- Throws:
VerificationException
-
deleteArtifact
- Throws:
IOException
-
deleteArtifacts
Deletes all artifacts in the specified group id from the local repository.- Parameters:
gid
- The group id whose artifacts should be deleted, must not benull
.- Throws:
IOException
- If the artifacts could not be deleted.- Since:
- 1.2
-
deleteArtifacts
Deletes all artifacts in the specified g:a:v from the local repository.- Parameters:
gid
- The group id whose artifacts should be deleted, must not benull
.aid
- The artifact id whose artifacts should be deleted, must not benull
.version
- The (base) version whose artifacts should be deleted, must not benull
.- Throws:
IOException
- If the artifacts could not be deleted.- Since:
- 1.3
-
deleteDirectory
Deletes the specified directory.- Parameters:
path
- The path to the directory to delete, relative to the base directory, must not benull
.- Throws:
IOException
- If the directory could not be deleted.- Since:
- 1.2
-
writeFile
Writes a text file with the specified contents. The contents will be encoded using UTF-8.- Parameters:
path
- The path to the file, relative to the base directory, must not benull
.contents
- The contents to write, must not benull
.- Throws:
IOException
- If the file could not be written.- Since:
- 1.2
-
filterFile
public File filterFile(String srcPath, String dstPath, String fileEncoding, Map<String, String> filterProperties) throws IOExceptionFilters a text file by replacing some user-defined tokens.- Parameters:
srcPath
- The path to the input file, relative to the base directory, must not benull
.dstPath
- The path to the output file, relative to the base directory and possibly equal to the input file, must not benull
.fileEncoding
- The file encoding to use, may benull
or empty to use the platform's default encoding.filterProperties
- The mapping from tokens to replacement values, must not benull
.- Returns:
- The path to the filtered output file, never
null
. - Throws:
IOException
- If the file could not be filtered.- Since:
- 1.2
-
filterFile
@Deprecated public File filterFile(String srcPath, String dstPath, String fileEncoding, Properties filterProperties) throws IOException Deprecated.There are 226 references to this method in Maven core ITs. In most (all?) cases it is used together withnewDefaultFilterProperties()
. Need to remove both methods and update all clients eventually/- Parameters:
srcPath
- The path to the input file, relative to the base directory, must not benull
.dstPath
- The path to the output file, relative to the base directory and possibly equal to the input file, must not benull
.fileEncoding
- The file encoding to use, may benull
or empty to use the platform's default encoding.filterProperties
- The mapping from tokens to replacement values, must not benull
.- Returns:
- The path to the filtered output file, never
null
. - Throws:
IOException
- If the file could not be filtered.
-
newDefaultFilterProperties
Gets a new copy of the default filter properties. These default filter properties map the tokens "@basedir@" and "@baseurl@" to the test's base directory and its basefile:
URL, respectively.- Returns:
- The (modifiable) map with the default filter properties, never
null
. - Since:
- 1.2
-
verifyFilePresent
Verifies that the given file exists.- Parameters:
file
- the path of the file to check- Throws:
VerificationException
- in case the given file does not exist
-
assertFilePresent
Deprecated.UseverifyFilePresent(String)
instead.- Parameters:
file
- the path of the file to check
-
verifyFileContentMatches
Verifies the given file's content matches an regular expression. Note this method also checks that the file exists and is readable.- Parameters:
file
- the path of the file to checkregex
- a regular expression- Throws:
VerificationException
- in case the file was not found or its content does not match the given pattern- See Also:
-
assertFileMatches
Deprecated.UseverifyFileContentMatches(String, String)
instead.Check the given file's content matches a regular expression. Note this method also checks that the file exists and is readable.- Parameters:
file
- the path of the file to checkregex
- a regular expression that the file's contents should match- See Also:
-
verifyFileNotPresent
Verifies that the given file does not exist.- Parameters:
file
- the path of the file to check- Throws:
VerificationException
- if the given file exists
-
assertFileNotPresent
Deprecated.UseverifyFileNotPresent(String)
instead.- Parameters:
file
- the path of the file to check
-
verifyArtifactPresence
private void verifyArtifactPresence(boolean wanted, String groupId, String artifactId, String version, String ext) throws VerificationException - Throws:
VerificationException
-
verifyArtifactPresent
public void verifyArtifactPresent(String groupId, String artifactId, String version, String ext) throws VerificationException Verifies that the artifact given through its Maven coordinates exists.- Parameters:
groupId
- the groupId of the artifact (must not be null)artifactId
- the artifactId of the artifact (must not be null)version
- the version of the artifact (must not be null)ext
- the extension of the artifact (must not be null)- Throws:
VerificationException
- if the given artifact does not exist
-
verifyArtifactNotPresent
public void verifyArtifactNotPresent(String groupId, String artifactId, String version, String ext) throws VerificationException Verifies that the artifact given through its Maven coordinates does not exist.- Parameters:
groupId
- the groupId of the artifact (must not be null)artifactId
- the artifactId of the artifact (must not be null)version
- the version of the artifact (must not be null)ext
- the extension of the artifact (must not be null)- Throws:
VerificationException
- if the given artifact exists
-
assertArtifactPresence
-
assertArtifactPresent
Deprecated. -
assertArtifactNotPresent
@Deprecated public void assertArtifactNotPresent(String org, String name, String version, String ext) Deprecated. -
verifyExpectedResult
- Throws:
VerificationException
-
verifyFilePresence
- Throws:
VerificationException
-
executeGoal
- Throws:
VerificationException
-
executeGoal
- Throws:
VerificationException
-
executeGoals
- Throws:
VerificationException
-
getExecutable
-
executeGoals
public void executeGoals(List<String> goals, Map<String, String> envVars) throws VerificationException- Throws:
VerificationException
-
getMavenLauncher
- Throws:
LauncherException
-
initEmbeddedLauncher
- Throws:
LauncherException
-
parseClasspath
- Throws:
LauncherException
-
getMavenVersion
- Throws:
VerificationException
-
getLogContents
-
resolveCommandLineArg
-
discoverIntegrationTests
- Throws:
VerificationException
-
displayLogFile
private void displayLogFile() -
main
- Throws:
VerificationException
-
findLocalRepo
- Throws:
VerificationException
-
runIntegrationTest
- Throws:
VerificationException
-
verifyArtifactContent
public void verifyArtifactContent(String groupId, String artifactId, String version, String ext, String content) throws IOException, VerificationException Verifies that the artifact given by its Maven coordinates exists and contains the given content.- Parameters:
groupId
- the groupId of the artifact (must not be null)artifactId
- the artifactId of the artifact (must not be null)version
- the version of the artifact (must not be null)ext
- the extension of the artifact (must not be null)content
- the expected content- Throws:
IOException
- if reading from the artifact failsVerificationException
- if the content of the artifact differs
-
assertArtifactContents
@Deprecated public void assertArtifactContents(String org, String artifact, String version, String type, String contents) throws IOException Deprecated.- Throws:
IOException
-
getCliOptions
-
setCliOptions
-
addCliOption
-
getSystemProperties
-
setSystemProperties
-
setSystemProperty
-
getEnvironmentVariables
-
setEnvironmentVariables
-
setEnvironmentVariable
-
getVerifierProperties
-
setVerifierProperties
-
isAutoclean
public boolean isAutoclean() -
setAutoclean
public void setAutoclean(boolean autoclean) -
getBasedir
-
getLogFileName
Gets the name of the file used to log build output.- Returns:
- The name of the log file, relative to the base directory, never
null
. - Since:
- 1.2
-
setLogFileName
Sets the name of the file used to log build output.- Parameters:
logFileName
- The name of the log file, relative to the base directory, must not be empty ornull
.- Since:
- 1.2
-
setDebug
public void setDebug(boolean debug) -
isMavenDebug
public boolean isMavenDebug() -
setMavenDebug
public void setMavenDebug(boolean mavenDebug) -
setForkJvm
public void setForkJvm(boolean forkJvm) -
isDebugJvm
public boolean isDebugJvm() -
setDebugJvm
public void setDebugJvm(boolean debugJvm) -
getLocalRepoLayout
-
setLocalRepoLayout
-
getLocalRepository
-
verifyArtifactContent(String, String, String, String, String)
instead.