Class Verifier

java.lang.Object
org.apache.maven.shared.verifier.Verifier

public class Verifier extends Object
Author:
Jason van Zyl, Brett Porter
  • Constructor Details

  • Method Details

    • setLocalRepo

      public void setLocalRepo(String localRepo)
    • resetStreams

      @Deprecated public void resetStreams()
      Deprecated.
      will be removed without replacement
    • displayStreamBuffers

      @Deprecated public void displayStreamBuffers()
      Deprecated.
      will be removed without replacement
    • verify

      public void verify(boolean chokeOnErrorOutput) throws VerificationException
      Throws:
      VerificationException
    • verifyErrorFreeLog

      public void verifyErrorFreeLog() throws VerificationException
      Throws:
      VerificationException
    • verifyTextInLog

      public void verifyTextInLog(String text) throws VerificationException
      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

      public static String stripAnsi(String msg)
    • loadProperties

      public Properties loadProperties(String filename) throws VerificationException
      Throws:
      VerificationException
    • loadLines

      public List<String> loadLines(String filename, String encoding) throws IOException
      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 be null.
      encoding - The character encoding of the file, may be null 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
    • loadFile

      public List<String> loadFile(String basedir, String filename, boolean hasCommand) throws VerificationException
      Throws:
      VerificationException
    • loadFile

      public List<String> loadFile(File file, boolean hasCommand) throws VerificationException
      Throws:
      VerificationException
    • getArtifactPath

      public String getArtifactPath(String groupId, String artifactId, String version, String ext)
    • 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

      public List<String> getArtifactFileNameList(String org, String name, String version, String ext)
    • getArtifactMetadataPath

      public String getArtifactMetadataPath(String gid, String aid, String version)
      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 be null.
      aid - The artifact id, must not be null.
      version - The artifact version, may be null.
      Returns:
      The (absolute) path to the local artifact metadata, never null.
    • getArtifactMetadataPath

      public String getArtifactMetadataPath(String gid, String aid, String version, String filename)
      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 be null.
      aid - The artifact id, may be null.
      version - The artifact version, may be null.
      filename - The filename to use, must not be null.
      Returns:
      The (absolute) path to the local artifact metadata, never null.
    • getArtifactMetadataPath

      public String getArtifactMetadataPath(String gid, String aid)
      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 be null.
      aid - The artifact id, must not be null.
      Returns:
      The (absolute) path to the local artifact metadata, never null.
    • deleteArtifact

      public void deleteArtifact(String org, String name, String version, String ext) throws IOException
      Throws:
      IOException
    • deleteArtifacts

      public void deleteArtifacts(String gid) throws IOException
      Deletes all artifacts in the specified group id from the local repository.
      Parameters:
      gid - The group id whose artifacts should be deleted, must not be null.
      Throws:
      IOException - If the artifacts could not be deleted.
      Since:
      1.2
    • deleteArtifacts

      public void deleteArtifacts(String gid, String aid, String version) throws IOException
      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 be null.
      aid - The artifact id whose artifacts should be deleted, must not be null.
      version - The (base) version whose artifacts should be deleted, must not be null.
      Throws:
      IOException - If the artifacts could not be deleted.
      Since:
      1.3
    • deleteDirectory

      public void deleteDirectory(String path) throws IOException
      Deletes the specified directory.
      Parameters:
      path - The path to the directory to delete, relative to the base directory, must not be null.
      Throws:
      IOException - If the directory could not be deleted.
      Since:
      1.2
    • writeFile

      public void writeFile(String path, String contents) throws IOException
      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 be null.
      contents - The contents to write, must not be null.
      Throws:
      IOException - If the file could not be written.
      Since:
      1.2
    • filterFile

      public File filterFile(String srcPath, String dstPath, String fileEncoding) throws IOException
      Filters a text file by replacing some user-defined tokens. This method is equivalent to:
           filterFile( srcPath, dstPath, fileEncoding, verifier.newDefaultFilterMap() )
       
      Parameters:
      srcPath - The path to the input file, relative to the base directory, must not be null.
      dstPath - The path to the output file, relative to the base directory and possibly equal to the input file, must not be null.
      fileEncoding - The file encoding to use, may be null or empty to use the platform's default encoding.
      Returns:
      The path to the filtered output file, never null.
      Throws:
      IOException - If the file could not be filtered.
      Since:
      2.0
    • filterFile

      public File filterFile(String srcPath, String dstPath, String fileEncoding, Map<String,String> filterMap) throws IOException
      Filters a text file by replacing some user-defined tokens.
      Parameters:
      srcPath - The path to the input file, relative to the base directory, must not be null.
      dstPath - The path to the output file, relative to the base directory and possibly equal to the input file, must not be null.
      fileEncoding - The file encoding to use, may be null or empty to use the platform's default encoding.
      filterMap - The mapping from tokens to replacement values, must not be null.
      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
      There are 226 references to this method in Maven core ITs. In most (all?) cases it is used together with newDefaultFilterProperties(). 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 be null.
      dstPath - The path to the output file, relative to the base directory and possibly equal to the input file, must not be null.
      fileEncoding - The file encoding to use, may be null or empty to use the platform's default encoding.
      filterProperties - The mapping from tokens to replacement values, must not be null.
      Returns:
      The path to the filtered output file, never null.
      Throws:
      IOException - If the file could not be filtered.
    • newDefaultFilterProperties

      @Deprecated public Properties newDefaultFilterProperties()
      Deprecated.
      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 base file: URL, respectively.
      Returns:
      The (modifiable) map with the default filter properties, never null.
      Since:
      1.2
    • newDefaultFilterMap

      public Map<String,String> newDefaultFilterMap()
      Gets a new copy of the default filter map. These default filter map, contains the tokens "@basedir@" and "@baseurl@" to the test's base directory and its base file: URL, respectively.
      Returns:
      The (modifiable) map with the default filter map, never null.
      Since:
      2.0
    • verifyFilePresent

      public void verifyFilePresent(String file) throws VerificationException
      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
    • verifyFileContentMatches

      public void verifyFileContentMatches(String file, String regex) throws VerificationException
      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 check
      regex - a regular expression
      Throws:
      VerificationException - in case the file was not found or its content does not match the given pattern
      See Also:
    • verifyFileNotPresent

      public void verifyFileNotPresent(String file) throws VerificationException
      Verifies that the given file does not exist.
      Parameters:
      file - the path of the file to check
      Throws:
      VerificationException - if the given file exists
    • 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
    • executeGoal

      @Deprecated public void executeGoal(String goal) throws VerificationException
      Deprecated.
      will be removed.

      For replacement please use:

         verifier.addCliArgument( "goal" );
         verifier.execute();
       
      Execute Maven.
      Throws:
      VerificationException
    • executeGoal

      @Deprecated public void executeGoal(String goal, Map<String,String> envVars) throws VerificationException
      Deprecated.
      will be removed.

      For replacement please use:

         verifier.addCliArgument( "goal" );
         verifier.setEnvironmentVariable( "key1", "value1" );
         verifier.setEnvironmentVariable( "key2", "value2" );
         verifier.execute();
       
      Execute Maven.
      Throws:
      VerificationException
    • executeGoals

      @Deprecated public void executeGoals(List<String> goals) throws VerificationException
      Deprecated.
      will be removed

      For replacement please use:

         verifier.addCliArguments( "goal1", "goal2" );
         verifier.execute();
       
      Execute Maven.
      Throws:
      VerificationException
    • getExecutable

      public String getExecutable()
    • executeGoals

      @Deprecated public void executeGoals(List<String> goals, Map<String,String> envVars) throws VerificationException
      Deprecated.
      will be removed

      For replacement please use:

         verifier.addCliArguments( "goal1", "goal2" );
         verifier.setEnvironmentVariable( "key1", "value1" );
         verifier.setEnvironmentVariable( "key2", "value2" );
         verifier.execute();
       
      Execute Maven.
      Throws:
      VerificationException
    • execute

      public void execute() throws VerificationException
      Execute Maven.
      Throws:
      VerificationException
    • getMavenLauncher

      protected org.apache.maven.shared.verifier.MavenLauncher getMavenLauncher(Map<String,String> envVars) throws org.apache.maven.shared.verifier.LauncherException
      Throws:
      org.apache.maven.shared.verifier.LauncherException
    • getMavenVersion

      public String getMavenVersion() throws VerificationException
      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 fails
      VerificationException - if the content of the artifact differs
    • getCliOptions

      @Deprecated public List<String> getCliOptions()
      Deprecated.
      will be removed without replacement, for arguments adding please use addCliArgument(String), addCliArguments(String...)
    • setCliOptions

      @Deprecated public void setCliOptions(List<String> cliOptions)
      Deprecated.
      will be removed
    • addCliOption

      @Deprecated public void addCliOption(String option)
      Deprecated.
      Add a command line argument, each argument must be set separately one by one.

      ${basedir} in argument will be replaced by value of getBasedir() during execution.

      Parameters:
      option - an argument to add
    • addCliArgument

      public void addCliArgument(String cliArgument)
      Add a command line argument, each argument must be set separately one by one.

      ${basedir} in argument will be replaced by value of getBasedir() during execution.

      Parameters:
      cliArgument - an argument to add
    • addCliArguments

      public void addCliArguments(String... cliArguments)
      Add a command line arguments, each argument must be set separately one by one.

      ${basedir} in argument will be replaced by value of getBasedir() during execution.

      Parameters:
      cliArguments - an arguments list to add
    • getSystemProperties

      public Properties getSystemProperties()
    • setSystemProperties

      public void setSystemProperties(Properties systemProperties)
    • setSystemProperty

      public void setSystemProperty(String key, String value)
    • getEnvironmentVariables

      public Map<String,String> getEnvironmentVariables()
    • setEnvironmentVariables

      public void setEnvironmentVariables(Map<String,String> environmentVariables)
    • setEnvironmentVariable

      public void setEnvironmentVariable(String key, String value)
    • getVerifierProperties

      public Properties getVerifierProperties()
    • setVerifierProperties

      public void setVerifierProperties(Properties verifierProperties)
    • isAutoclean

      public boolean isAutoclean()
    • setAutoclean

      public void setAutoclean(boolean autoclean)
      Clean project before execution by adding CLEAN_CLI_ARGUMENT to command line.

      By default, options is enabled.

      Parameters:
      autoclean - indicate if option is enabled
    • getBasedir

      public String getBasedir()
    • getLogFileName

      public String 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

      public void setLogFileName(String logFileName)
      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 or null.
      Since:
      1.2
    • setDebug

      @Deprecated public void setDebug(boolean debug)
      Deprecated.
      will be removed without replacement
    • isMavenDebug

      @Deprecated public boolean isMavenDebug()
      Deprecated.
      will be removed without replacement
    • setMavenDebug

      @Deprecated public void setMavenDebug(boolean mavenDebug)
      Deprecated.
      will be removed without replacement.
      For replacement please use:
           verifier.addCliArgument( "-X" );
       
    • setForkJvm

      public void setForkJvm(boolean forkJvm)
    • isDebugJvm

      public boolean isDebugJvm()
    • setDebugJvm

      public void setDebugJvm(boolean debugJvm)
    • getLocalRepoLayout

      public String getLocalRepoLayout()
    • setLocalRepoLayout

      public void setLocalRepoLayout(String localRepoLayout)
    • getLocalRepository

      public String getLocalRepository()