Class MavenUtils


  • public final class MavenUtils
    extends Object
    Auxiliary methods to work with maven entities.
    Since:
    2.3.0
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static String findProperty​(org.apache.maven.execution.MavenSession session, org.apache.maven.project.MavenProject project, String key, String defaultValue)  
      static boolean isTestPhase​(org.apache.maven.plugin.MojoExecution execution)
      Check that execution in a test mode.
      static String makeArtifactRecord​(org.apache.maven.artifact.Artifact artifact)
      Make artifact record from a maven artifact
      static org.apache.maven.project.ProjectBuildingRequest makeResolveArtifactProjectBuildingRequest​(org.apache.maven.execution.MavenSession session, List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories)
      Make resolve artifact project building request.
      static org.apache.maven.artifact.Artifact parseArtifactRecord​(String record, org.apache.maven.artifact.handler.ArtifactHandler handler)
      Parse string containing artifact record
      static List<Tuple<org.apache.maven.artifact.Artifact,​File>> scanForMvnGoArtifacts​(org.apache.maven.project.MavenProject mavenProject, boolean includeTestDependencies, org.apache.maven.plugin.AbstractMojo mojo, org.apache.maven.execution.MavenSession session, org.apache.maven.plugin.MojoExecution execution, org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver resolver, List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories)
      Scan project dependencies to find artifacts generated by mvn golang project.
    • Method Detail

      • isTestPhase

        public static boolean isTestPhase​(@Nonnull
                                          org.apache.maven.plugin.MojoExecution execution)
        Check that execution in a test mode.
        Parameters:
        execution - maven execution object, must not be null
        Returns:
        true if a test mode is active, false otherwise
      • makeResolveArtifactProjectBuildingRequest

        @Nonnull
        public static org.apache.maven.project.ProjectBuildingRequest makeResolveArtifactProjectBuildingRequest​(@Nonnull
                                                                                                                org.apache.maven.execution.MavenSession session,
                                                                                                                @Nonnull @MustNotContainNull
                                                                                                                List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories)
        Make resolve artifact project building request.
        Parameters:
        session - maven session, must not be null
        remoteRepositories - list of remote repositories, must not be null and can't contain null
        Returns:
        created request, must not be null
      • parseArtifactRecord

        @Nonnull
        public static org.apache.maven.artifact.Artifact parseArtifactRecord​(@Nonnull
                                                                             String record,
                                                                             @Nonnull
                                                                             org.apache.maven.artifact.handler.ArtifactHandler handler)
                                                                      throws org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
        Parse string containing artifact record
        Parameters:
        record - string containing record, must not be null
        handler - artifact handler for created artifact, must not be null
        Returns:
        new created artifact from the record, must not be null
        Throws:
        org.apache.maven.artifact.versioning.InvalidVersionSpecificationException - it will be thrown if version format is wrong
        IllegalArgumentException - it will be thrown if record can't be recognized as artifact record
      • scanForMvnGoArtifacts

        @Nonnull
        @MustNotContainNull
        public static List<Tuple<org.apache.maven.artifact.Artifact,​File>> scanForMvnGoArtifacts​(@Nonnull
                                                                                                       org.apache.maven.project.MavenProject mavenProject,
                                                                                                       boolean includeTestDependencies,
                                                                                                       @Nonnull
                                                                                                       org.apache.maven.plugin.AbstractMojo mojo,
                                                                                                       @Nonnull
                                                                                                       org.apache.maven.execution.MavenSession session,
                                                                                                       @Nonnull
                                                                                                       org.apache.maven.plugin.MojoExecution execution,
                                                                                                       @Nonnull
                                                                                                       org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver resolver,
                                                                                                       @Nonnull @MustNotContainNull
                                                                                                       List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories)
                                                                                                throws org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException
        Scan project dependencies to find artifacts generated by mvn golang project.
        Parameters:
        mavenProject - maven project, must not be null
        includeTestDependencies - flag to process dependencies marked for test phases
        mojo - calling mojo, must not be null
        session - maven session, must not be null
        execution - maven execution, must not be null
        resolver - artifact resolver, must not be null
        remoteRepositories - list of remote repositories, must not be null
        Returns:
        list of files found in artifacts generated by mvn golang plugin
        Throws:
        org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException - exception thrown if some artifact can't be resolved