Skip to content

Commit

Permalink
update maven libraries and remove guava restriction
Browse files Browse the repository at this point in the history
Remove the pinning of Guava to version 14.0.1 to fix
spotify/docker-maven-plugin#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 fabric8io#165.
  • Loading branch information
mattnworb committed Jan 4, 2016
1 parent f7e52bf commit 3abf8b0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 19 deletions.
20 changes: 5 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.2.1</version>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.2.1</version>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
Expand All @@ -157,7 +157,7 @@
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>3.1.0</version>
<version>3.3.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -174,7 +174,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>3.1.1</version>
<version>3.3.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -209,16 +209,6 @@
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<testResources>
<testResource>
Expand All @@ -240,7 +230,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<version>3.4</version>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
Expand Down
11 changes: 7 additions & 4 deletions src/test/java/com/spotify/docker/BuildMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/com/spotify/docker/ProjectStub.java
Original file line number Diff line number Diff line change
@@ -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}.
* <p>
* Originally taken from <a href="https://maven.apache.org/plugin-testing/maven-plugin-testing-harness/examples/complex-mojo-parameters.html">
* Maven Plugin Testing Mechanism</a> guide but adapted for our use case.</p>
*/
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<String> compileSourceRoots = new ArrayList<>();
compileSourceRoots.add(getBasedir() + "/src/main/java");
setCompileSourceRoots(compileSourceRoots);

List<String> 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());
}
}

0 comments on commit 3abf8b0

Please sign in to comment.