From 37f80c63a5b6eda05cf7a4b213f201f6c38abc69 Mon Sep 17 00:00:00 2001 From: Jae Gangemi Date: Thu, 19 Feb 2015 15:49:21 -0500 Subject: [PATCH] issue #82 - inject the 'MavenReaderFilter' to enable filtering Signed-off-by: Jae Gangemi --- .../org/jolokia/docker/maven/BuildMojo.java | 11 +++++++++-- .../DockerAssemblyConfigurationSource.java | 2 +- .../docker/maven/util/MojoParameters.java | 17 ++++++++++++----- .../DockerAssemblyConfigurationSourceTest.java | 4 ++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jolokia/docker/maven/BuildMojo.java b/src/main/java/org/jolokia/docker/maven/BuildMojo.java index 1bba1e513..f9b08f2d3 100644 --- a/src/main/java/org/jolokia/docker/maven/BuildMojo.java +++ b/src/main/java/org/jolokia/docker/maven/BuildMojo.java @@ -6,6 +6,7 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.shared.filtering.MavenFileFilter; +import org.apache.maven.shared.filtering.MavenReaderFilter; import org.jolokia.docker.maven.access.DockerAccess; import org.jolokia.docker.maven.access.DockerAccessException; import org.jolokia.docker.maven.assembly.DockerAssemblyManager; @@ -38,6 +39,9 @@ public class BuildMojo extends AbstractDockerMojo { /** @component */ private MavenFileFilter mavenFileFilter; + /** @component */ + private MavenReaderFilter mavenFilterReader; + /** @component */ private DockerAssemblyManager dockerAssemblyManager; @@ -73,12 +77,15 @@ private void buildImage(ImageConfiguration imageConfig, DockerAccess dockerAcces checkImageWithAutoPull(dockerAccess, fromImage, new ImageName(fromImage).getRegistry()); - MojoParameters params = new MojoParameters(session, project, archive, mavenFileFilter, sourceDirectory, outputDirectory); + MojoParameters params = createMojoParameters(); File dockerArchive = dockerAssemblyManager.create(params, imageConfig.getBuildConfiguration()); dockerAccess.buildImage(imageName, dockerArchive); debug("Build successful!"); } - + private MojoParameters createMojoParameters() { + return new MojoParameters(session, project, archive, mavenFileFilter, mavenFilterReader, + sourceDirectory, outputDirectory); + } } diff --git a/src/main/java/org/jolokia/docker/maven/assembly/DockerAssemblyConfigurationSource.java b/src/main/java/org/jolokia/docker/maven/assembly/DockerAssemblyConfigurationSource.java index 7da8701e4..d8f800b26 100644 --- a/src/main/java/org/jolokia/docker/maven/assembly/DockerAssemblyConfigurationSource.java +++ b/src/main/java/org/jolokia/docker/maven/assembly/DockerAssemblyConfigurationSource.java @@ -222,7 +222,7 @@ public String getArchiverConfig() { @Override public MavenReaderFilter getMavenReaderFilter() { - return null; + return params.getMavenFilterReader(); } @Override diff --git a/src/main/java/org/jolokia/docker/maven/util/MojoParameters.java b/src/main/java/org/jolokia/docker/maven/util/MojoParameters.java index f2e585fdb..1d243f8b2 100644 --- a/src/main/java/org/jolokia/docker/maven/util/MojoParameters.java +++ b/src/main/java/org/jolokia/docker/maven/util/MojoParameters.java @@ -4,6 +4,7 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.filtering.MavenFileFilter; +import org.apache.maven.shared.filtering.MavenReaderFilter; /** * Helper class for encapsulating Mojo params which are not Plexus components @@ -12,19 +13,21 @@ * @since 09.05.14 */ public class MojoParameters { - private MavenArchiveConfiguration archive; - private MavenSession session; - private MavenFileFilter mavenFileFilter; - private MavenProject project; + private final MavenArchiveConfiguration archive; + private final MavenSession session; + private final MavenFileFilter mavenFileFilter; + private final MavenReaderFilter mavenFilterReader; + private final MavenProject project; private final String outputDirectory; private final String sourceDirectory; public MojoParameters(MavenSession session, MavenProject project, MavenArchiveConfiguration archive, MavenFileFilter mavenFileFilter, - String sourceDirectory, String outputDirectory) { + MavenReaderFilter mavenFilterReader, String sourceDirectory, String outputDirectory) { this.archive = archive; this.session = session; this.mavenFileFilter = mavenFileFilter; + this.mavenFilterReader = mavenFilterReader; this.project = project; this.sourceDirectory = sourceDirectory; @@ -50,6 +53,10 @@ public MavenSession getSession() { public MavenFileFilter getMavenFileFilter() { return mavenFileFilter; } + + public MavenReaderFilter getMavenFilterReader() { + return mavenFilterReader; + } public MavenProject getProject() { return project; diff --git a/src/test/java/org/jolokia/docker/maven/assembly/DockerAssemblyConfigurationSourceTest.java b/src/test/java/org/jolokia/docker/maven/assembly/DockerAssemblyConfigurationSourceTest.java index 714699d5a..5ab743265 100644 --- a/src/test/java/org/jolokia/docker/maven/assembly/DockerAssemblyConfigurationSourceTest.java +++ b/src/test/java/org/jolokia/docker/maven/assembly/DockerAssemblyConfigurationSourceTest.java @@ -38,13 +38,13 @@ public void testCreateSourceRelative() { private MojoParameters buildParameters(String projectDir, String sourceDir, String outputDir) { MavenProject mavenProject = new MavenProject(); mavenProject.setFile(new File(projectDir)); - return new MojoParameters(null, mavenProject, null, null, sourceDir, outputDir); + return new MojoParameters(null, mavenProject, null, null, null, sourceDir, outputDir); } @Test public void testEmptyAssemblyConfig() { DockerAssemblyConfigurationSource source = new DockerAssemblyConfigurationSource( - new MojoParameters(null, null, null, null, "/src/docker", "/output/docker"), + new MojoParameters(null, null, null, null, null, "/src/docker", "/output/docker"), null ); assertEquals(0,source.getDescriptors().length);