From 3abf8b0db2f0357f1cbb0891bec508e92c718205 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Mon, 4 Jan 2016 15:10:34 -0500 Subject: [PATCH] update maven libraries and remove guava restriction Remove the pinning of Guava to version 14.0.1 to fix https://github.com/spotify/docker-maven-plugin/issues/165. Guava was held to 14.0.1 before because a combination of Plexus/Guice code used or invoked by the maven plugin testing harness called methods in Guava that have been removed after version (specifically `MapMaker.makeComputingMap). The main fix to remove that need is to avoid using that part of the testing harness altogether by stubbing out the `MavenProject` instance instead of trying to look it up in the Plexus container. Fixes #165. --- pom.xml | 20 ++------ .../com/spotify/docker/BuildMojoTest.java | 11 ++-- .../java/com/spotify/docker/ProjectStub.java | 51 +++++++++++++++++++ 3 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 src/test/java/com/spotify/docker/ProjectStub.java diff --git a/pom.xml b/pom.xml index 2e5b9b931..ee33a193b 100644 --- a/pom.xml +++ b/pom.xml @@ -142,12 +142,12 @@ org.apache.maven maven-core - 3.2.1 + 3.3.3 org.apache.maven maven-artifact - 3.2.1 + 3.3.3 org.eclipse.jgit @@ -157,7 +157,7 @@ org.apache.maven.plugin-testing maven-plugin-testing-harness - 3.1.0 + 3.3.0 test @@ -174,7 +174,7 @@ org.apache.maven maven-compat - 3.1.1 + 3.3.3 test @@ -209,16 +209,6 @@ - - - - com.google.guava - guava - 14.0.1 - - - - @@ -240,7 +230,7 @@ org.apache.maven.plugins maven-plugin-plugin - 3.2 + 3.4 true diff --git a/src/test/java/com/spotify/docker/BuildMojoTest.java b/src/test/java/com/spotify/docker/BuildMojoTest.java index 1dcd41923..17d94cce5 100644 --- a/src/test/java/com/spotify/docker/BuildMojoTest.java +++ b/src/test/java/com/spotify/docker/BuildMojoTest.java @@ -34,9 +34,11 @@ import org.apache.maven.execution.DefaultMavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Build; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuilder; import org.apache.maven.project.ProjectBuildingRequest; @@ -336,11 +338,12 @@ public void testNoCache() throws Exception { } private BuildMojo setupMojo(final File pom) throws Exception { - final MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); - final ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest(); - final ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class); - final MavenProject project = projectBuilder.build(pom, buildingRequest).getProject(); + final MavenProject project = new ProjectStub(pom); final MavenSession session = newMavenSession(project); + // for some reason the superclass method newMavenSession() does not copy properties from the + // project model to the session. This is needed for the use of ExpressionEvaluator in BuildMojo. + session.getRequest().setUserProperties(project.getModel().getProperties()); + final MojoExecution execution = newMojoExecution("build"); final BuildMojo mojo = (BuildMojo) this.lookupConfiguredMojo(session, execution); mojo.buildDirectory = "target"; diff --git a/src/test/java/com/spotify/docker/ProjectStub.java b/src/test/java/com/spotify/docker/ProjectStub.java new file mode 100644 index 000000000..be49c01ca --- /dev/null +++ b/src/test/java/com/spotify/docker/ProjectStub.java @@ -0,0 +1,51 @@ +package com.spotify.docker; + +import org.apache.maven.model.Build; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.plugin.testing.stubs.MavenProjectStub; +import org.codehaus.plexus.util.ReaderFactory; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * Custom stub implementation of {@link org.apache.maven.project.MavenProject}. + *

+ * Originally taken from + * Maven Plugin Testing Mechanism guide but adapted for our use case.

+ */ +public class ProjectStub extends MavenProjectStub { + + public ProjectStub(File pom) { + MavenXpp3Reader pomReader = new MavenXpp3Reader(); + Model model; + try { + model = pomReader.read(ReaderFactory.newXmlReader(pom)); + setModel(model); + } catch (Exception e) { + throw new RuntimeException(e); + } + + setGroupId(model.getGroupId()); + setArtifactId(model.getArtifactId()); + setVersion(model.getVersion()); + setName(model.getName()); + setUrl(model.getUrl()); + setPackaging(model.getPackaging()); + setBuild(model.getBuild()); + + List compileSourceRoots = new ArrayList<>(); + compileSourceRoots.add(getBasedir() + "/src/main/java"); + setCompileSourceRoots(compileSourceRoots); + + List testCompileSourceRoots = new ArrayList<>(); + testCompileSourceRoots.add(getBasedir() + "/src/test/java"); + setTestCompileSourceRoots(testCompileSourceRoots); + + // normalize some expressions + getBuild().setDirectory("${project.basedir}/target"); + getBuild().setTestOutputDirectory(new File(getBasedir(), "target/classes").getAbsolutePath()); + } +}