Class InstallMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    @Mojo(name="install",
          defaultPhase=PRE_INTEGRATION_TEST,
          requiresDependencyResolution=RUNTIME,
          threadSafe=true)
    public class InstallMojo
    extends org.apache.maven.plugin.AbstractMojo
    Installs the project artifacts of the main build into the local repository as a preparation to run the sub projects. More precisely, all artifacts of the project itself, all its locally reachable parent POMs and all its dependencies from the reactor will be installed to the local repository.
    Since:
    1.2
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory
      The component used to create artifacts.
      private java.util.Collection<java.lang.String> copiedArtifacts
      The identifiers of already copied artifacts, used to avoid multiple installation of the same artifact.
      private java.lang.String[] extraArtifacts
      Extra dependencies that need to be installed on the local repository.
      Format:
      private java.util.Collection<java.lang.String> installedArtifacts
      The identifiers of already installed artifacts, used to avoid multiple installation of the same artifact.
      private org.apache.maven.shared.transfer.artifact.install.ArtifactInstaller installer
      Maven artifact install component to copy artifacts to the local repository.
      private org.apache.maven.artifact.repository.ArtifactRepository localRepository  
      private java.io.File localRepositoryPath
      The path to the local repository into which the project artifacts should be installed for the integration tests.
      private org.apache.maven.project.MavenProject project
      The current Maven project.
      private org.apache.maven.project.ProjectBuildingRequest projectBuildingRequest  
      private java.util.Collection<org.apache.maven.project.MavenProject> reactorProjects
      The set of Maven projects in the reactor build.
      private org.apache.maven.shared.transfer.repository.RepositoryManager repositoryManager  
      private org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver resolver  
      private org.apache.maven.execution.MavenSession session  
      private boolean skipInstallation
      A flag used to disable the installation procedure.
      private boolean useLocalRepository
      if the local repository is not used as test repo, the parameter can force get artifacts from local repo if available instead of download the artifacts again.
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Constructor Summary

      Constructors 
      Constructor Description
      InstallMojo()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void collectAllProjectReferences​(org.apache.maven.project.MavenProject project, java.util.Collection<java.lang.String> dependencyProjects)  
      private void copyArtifact​(java.io.File file, org.apache.maven.artifact.Artifact artifact)
      Installs the specified artifact to the local repository.
      private void copyArtifact​(org.apache.maven.artifact.Artifact artifact)  
      private void copyFileIfDifferent​(java.io.File src, java.io.File dst)  
      private void copyParentPoms​(java.io.File pomFile)
      Installs all parent POMs of the specified POM file that are available in the local repository.
      private void copyParentPoms​(java.lang.String groupId, java.lang.String artifactId, java.lang.String version)
      Installs the specified POM and all its parent POMs to the local repository.
      private void copyPoms​(org.apache.maven.artifact.Artifact artifact)  
      private void createTestRepository()
      Creates the local repository for the integration tests.
      void execute()
      Performs this mojo's tasks.
      private void installArtifact​(java.io.File file, org.apache.maven.artifact.Artifact artifact)
      Installs the specified artifact to the local repository.
      private void installExtraArtifacts​(java.lang.String[] extraArtifacts)  
      private void installProjectArtifacts​(org.apache.maven.project.MavenProject mvnProject)
      Installs the main artifact and any attached artifacts of the specified project to the local repository.
      private void installProjectDependencies​(org.apache.maven.project.MavenProject mvnProject, java.util.Collection<org.apache.maven.project.MavenProject> reactorProjects)
      Installs the dependent projects from the reactor to the local repository.
      private void installProjectParents​(org.apache.maven.project.MavenProject mvnProject)
      Installs the (locally reachable) parent POMs of the specified project to the local repository.
      private void installProjectPom​(org.apache.maven.project.MavenProject mvnProject)
      Installs the POM of the specified project to the local repository.
      private java.util.List<org.apache.maven.artifact.Artifact> toArtifactsList​(java.lang.Iterable<org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult> artifactResults)  
      • Methods inherited from class org.apache.maven.plugin.AbstractMojo

        getLog, getPluginContext, setLog, setPluginContext
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • installer

        @Component
        private org.apache.maven.shared.transfer.artifact.install.ArtifactInstaller installer
        Maven artifact install component to copy artifacts to the local repository.
      • repositoryManager

        @Component
        private org.apache.maven.shared.transfer.repository.RepositoryManager repositoryManager
      • artifactFactory

        @Component
        private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory
        The component used to create artifacts.
      • localRepository

        @Parameter(property="localRepository",
                   required=true,
                   readonly=true)
        private org.apache.maven.artifact.repository.ArtifactRepository localRepository
      • localRepositoryPath

        @Parameter(property="invoker.localRepositoryPath",
                   defaultValue="${session.localRepository.basedir}",
                   required=true)
        private java.io.File localRepositoryPath
        The path to the local repository into which the project artifacts should be installed for the integration tests. If not set, the regular local repository will be used. To prevent soiling of your regular local repository with possibly broken artifacts, it is strongly recommended to use an isolated repository for the integration tests (e.g. ${project.build.directory}/it-repo).
      • project

        @Parameter(defaultValue="${project}",
                   readonly=true,
                   required=true)
        private org.apache.maven.project.MavenProject project
        The current Maven project.
      • session

        @Parameter(defaultValue="${session}",
                   readonly=true,
                   required=true)
        private org.apache.maven.execution.MavenSession session
      • reactorProjects

        @Parameter(defaultValue="${reactorProjects}",
                   readonly=true)
        private java.util.Collection<org.apache.maven.project.MavenProject> reactorProjects
        The set of Maven projects in the reactor build.
      • skipInstallation

        @Parameter(property="invoker.skip",
                   defaultValue="false")
        private boolean skipInstallation
        A flag used to disable the installation procedure. This is primarily intended for usage from the command line to occasionally adjust the build.
        Since:
        1.4
      • installedArtifacts

        private java.util.Collection<java.lang.String> installedArtifacts
        The identifiers of already installed artifacts, used to avoid multiple installation of the same artifact.
      • copiedArtifacts

        private java.util.Collection<java.lang.String> copiedArtifacts
        The identifiers of already copied artifacts, used to avoid multiple installation of the same artifact.
      • extraArtifacts

        @Parameter
        private java.lang.String[] extraArtifacts
        Extra dependencies that need to be installed on the local repository.
        Format:
         groupId:artifactId:version:type:classifier
         
        Examples:
         org.apache.maven.plugins:maven-clean-plugin:2.4:maven-plugin
         org.apache.maven.plugins:maven-clean-plugin:2.4:jar:javadoc
         
        If the type is 'maven-plugin' the plugin will try to resolve the artifact using plugin remote repositories, instead of using artifact remote repositories.
        Since:
        1.6
      • resolver

        @Component
        private org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver resolver
      • useLocalRepository

        @Parameter(property="invoker.useLocalRepository",
                   defaultValue="false")
        private boolean useLocalRepository
        if the local repository is not used as test repo, the parameter can force get artifacts from local repo if available instead of download the artifacts again.
        Since:
        3.2.1
      • projectBuildingRequest

        private org.apache.maven.project.ProjectBuildingRequest projectBuildingRequest
    • Constructor Detail

      • InstallMojo

        public InstallMojo()
    • Method Detail

      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException
        Performs this mojo's tasks.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - If the artifacts could not be installed.
      • createTestRepository

        private void createTestRepository()
                                   throws org.apache.maven.plugin.MojoExecutionException
        Creates the local repository for the integration tests. If the user specified a custom repository location, the custom repository will have the same identifier, layout and policies as the real local repository. That means apart from the location, the custom repository will be indistinguishable from the real repository such that its usage is transparent to the integration tests.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - If the repository could not be created.
      • installArtifact

        private void installArtifact​(java.io.File file,
                                     org.apache.maven.artifact.Artifact artifact)
                              throws org.apache.maven.plugin.MojoExecutionException
        Installs the specified artifact to the local repository. Note: This method should only be used for artifacts that originate from the current (reactor) build. Artifacts that have been grabbed from the user's local repository should be installed to the test repository via copyArtifact(File, Artifact).
        Parameters:
        file - The file associated with the artifact, must not be null. This is in most cases the value of artifact.getFile() with the exception of the main artifact from a project with packaging "pom". Projects with packaging "pom" have no main artifact file. They have however artifact metadata (e.g. site descriptors) which needs to be installed.
        artifact - The artifact to install, must not be null.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - If the artifact could not be installed (e.g. has no associated file).
      • copyArtifact

        private void copyArtifact​(java.io.File file,
                                  org.apache.maven.artifact.Artifact artifact)
                           throws org.apache.maven.plugin.MojoExecutionException
        Installs the specified artifact to the local repository. This method serves basically the same purpose as installArtifact(File, Artifact) but is meant for artifacts that have been resolved from the user's local repository (and not the current build outputs). The subtle difference here is that artifacts from the repository have already undergone transformations and these manipulations should not be redone by the artifact installer. For this reason, this method performs plain copy operations to install the artifacts.
        Parameters:
        file - The file associated with the artifact, must not be null.
        artifact - The artifact to install, must not be null.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - If the artifact could not be installed (e.g. has no associated file).
      • copyFileIfDifferent

        private void copyFileIfDifferent​(java.io.File src,
                                         java.io.File dst)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • installProjectArtifacts

        private void installProjectArtifacts​(org.apache.maven.project.MavenProject mvnProject)
                                      throws org.apache.maven.plugin.MojoExecutionException
        Installs the main artifact and any attached artifacts of the specified project to the local repository.
        Parameters:
        mvnProject - The project whose artifacts should be installed, must not be null.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - If any artifact could not be installed.
      • installProjectParents

        private void installProjectParents​(org.apache.maven.project.MavenProject mvnProject)
                                    throws org.apache.maven.plugin.MojoExecutionException
        Installs the (locally reachable) parent POMs of the specified project to the local repository. The parent POMs from the reactor must be installed or the forked IT builds will fail when using a clean repository.
        Parameters:
        mvnProject - The project whose parent POMs should be installed, must not be null.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - If any POM could not be installed.
      • installProjectPom

        private void installProjectPom​(org.apache.maven.project.MavenProject mvnProject)
                                throws org.apache.maven.plugin.MojoExecutionException
        Installs the POM of the specified project to the local repository.
        Parameters:
        mvnProject - The project whose POM should be installed, must not be null.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - If the POM could not be installed.
      • installProjectDependencies

        private void installProjectDependencies​(org.apache.maven.project.MavenProject mvnProject,
                                                java.util.Collection<org.apache.maven.project.MavenProject> reactorProjects)
                                         throws org.apache.maven.plugin.MojoExecutionException
        Installs the dependent projects from the reactor to the local repository. The dependencies on other modules from the reactor must be installed or the forked IT builds will fail when using a clean repository.
        Parameters:
        mvnProject - The project whose dependent projects should be installed, must not be null.
        reactorProjects - The set of projects in the reactor build, must not be null.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - If any dependency could not be installed.
      • collectAllProjectReferences

        protected void collectAllProjectReferences​(org.apache.maven.project.MavenProject project,
                                                   java.util.Collection<java.lang.String> dependencyProjects)
      • copyArtifact

        private void copyArtifact​(org.apache.maven.artifact.Artifact artifact)
                           throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • copyPoms

        private void copyPoms​(org.apache.maven.artifact.Artifact artifact)
                       throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • copyParentPoms

        private void copyParentPoms​(java.io.File pomFile)
                             throws org.apache.maven.plugin.MojoExecutionException
        Installs all parent POMs of the specified POM file that are available in the local repository.
        Parameters:
        pomFile - The path to the POM file whose parents should be installed, must not be null.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - If any (existing) parent POM could not be installed.
      • copyParentPoms

        private void copyParentPoms​(java.lang.String groupId,
                                    java.lang.String artifactId,
                                    java.lang.String version)
                             throws org.apache.maven.plugin.MojoExecutionException
        Installs the specified POM and all its parent POMs to the local repository.
        Parameters:
        groupId - The group id of the POM which should be installed, must not be null.
        artifactId - The artifact id of the POM which should be installed, must not be null.
        version - The version of the POM which should be installed, must not be null.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - If any (existing) parent POM could not be installed.
      • installExtraArtifacts

        private void installExtraArtifacts​(java.lang.String[] extraArtifacts)
                                    throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • toArtifactsList

        private java.util.List<org.apache.maven.artifact.Artifact> toArtifactsList​(java.lang.Iterable<org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult> artifactResults)