Class DependencyCalculator


  • public class DependencyCalculator
    extends Object
    This class is effectively an unmitigated hack. Any offers to do it 'properly' are gratefully received from someone who can get the guts of Maven to do what want.

    Basically, given our 'uberwar' project, instead of simply merging WEB-INF/lib files, we wish to treat those war files as ordinary dependencies, and to calculate the 'effective' list of jar files that SHOULD be in WEB-INF/lib that way. I.E, if we are including A.WAR and B.WAR, both of which use different versions of X.JAR, then we should calculate what the 'right' version of the X.JAR that we ought to be using.

    This seems very hard to do given the tools provided by maven. There are alternate solutions, such as WAR files producing their code in a JAR as well, but this relies on including BOTH the WAR and the JAR, which is not pretty.

    This class does it a hacky way. For each of the war files in the dependency tree (including the caller), it generates an alternate pom file, which 'pretends' that the WAR file is a POM, and replaces any dependent WARS with equivalent dependencies of type POM with a different classifier. It then invokes maven to resolve that project, which appears to resolve the versions (as would have been done in an all-jar universe).

    A better way would probably be to be able to customise the dependency calculation system, but this seems very bound up in all the project/artifact gubbins.
    • Constructor Summary

      Constructors 
      Constructor Description
      DependencyCalculator​(org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver dependencyResolver, org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver artifactResolver, org.apache.maven.project.ProjectBuildingRequest projectBuildingRequest, org.apache.maven.project.MavenProject mavenProject, org.apache.maven.project.ProjectBuilder mavenProjectBuilder, org.apache.maven.shared.transfer.artifact.install.ArtifactInstaller installer)
      Saves all attributes.
    • Constructor Detail

      • DependencyCalculator

        public DependencyCalculator​(org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver dependencyResolver,
                                    org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver artifactResolver,
                                    org.apache.maven.project.ProjectBuildingRequest projectBuildingRequest,
                                    org.apache.maven.project.MavenProject mavenProject,
                                    org.apache.maven.project.ProjectBuilder mavenProjectBuilder,
                                    org.apache.maven.shared.transfer.artifact.install.ArtifactInstaller installer)
        Saves all attributes.
        Parameters:
        dependencyResolver - Dependency resolver.
        artifactResolver - Artifact resolver.
        projectBuildingRequest - Maven 3 project building request.
        mavenProject - Maven 3 project.
        mavenProjectBuilder - Maven 3 project builder.
        installer - Artifact installer.
    • Method Detail

      • execute

        public Set<File> execute()
                          throws Exception
        Execute the dependency calculator.
        Returns:
        List of dependency files.
        Throws:
        Exception - If anything goes wrong.
      • fixupProjectArtifact

        protected void fixupProjectArtifact()
                                     throws Exception
        Fixup the project artifact.
        Throws:
        Exception - If anything goes wrong.
      • fixupRepositoryArtifact

        protected void fixupRepositoryArtifact​(org.apache.maven.artifact.Artifact artifact)
                                        throws Exception
        Fixup an artifact.
        Parameters:
        artifact - Artifact to fixup.
        Throws:
        Exception - If anything goes wrong.
      • fixModelAndSaveInRepository

        protected void fixModelAndSaveInRepository​(org.apache.maven.artifact.Artifact artifact,
                                                   org.apache.maven.model.Model pomFile)
                                            throws Exception
        Fix model and save in repository.
        Parameters:
        artifact - Artifact.
        pomFile - Maven 3 model file.
        Throws:
        Exception - If anything goes wrong.