Author: mbenson Date: Tue May 31 22:50:13 2016 New Revision: 1746356 URL: http://svn.apache.org/viewvc?rev=1746356&view=rev Log: [WEAVER-15] Ensure that all dependency artifacts are available to commons-weaver mojos regardless of project build status
Added: commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractCWMojo.java (with props) Modified: commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractPrepareMojo.java commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/PrepareMojo.java commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestPrepareMojo.java commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestWeaveMojo.java commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java Added: commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractCWMojo.java URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractCWMojo.java?rev=1746356&view=auto ============================================================================== --- commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractCWMojo.java (added) +++ commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractCWMojo.java Tue May 31 22:50:13 2016 @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.commons.weaver.maven; + +import java.io.File; +import java.util.List; +import java.util.Properties; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +/** + * Defines common properties and high-level management common to all commons-weaver Maven goals. + */ +abstract class AbstractCWMojo extends AbstractMojo { + + /** + * {@code verbose} parameter. + */ + @Parameter(defaultValue = "false") + protected boolean verbose; + + /** + * {@code weaver.config} parameter. + */ + @Parameter(property = "weaver.config", required = false) + protected Properties weaverConfig; + + @Parameter(defaultValue = "${project}") + protected MavenProject project; + + /** + * Get the classpath for this prepare mojo. + * @return {@link List} of {@link String} + * @throws DependencyResolutionRequiredException + */ + protected abstract List<String> getClasspath() throws DependencyResolutionRequiredException; + + /** + * Get the target directory for this prepare mojo. + * @return {@link File} + */ + protected abstract File getTarget(); + + /** + * Execute this mojo. + * @throws MojoExecutionException in the event of failure + */ + @Override + public final void execute() throws MojoExecutionException, MojoFailureException { + final JavaLoggingToMojoLoggingRedirector logRedirector = new JavaLoggingToMojoLoggingRedirector(getLog()); + logRedirector.activate(); + + project.setArtifactFilter(new ArtifactFilter() { + + @Override + public boolean include(Artifact artifact) { + return true; + } + }); + try { + final List<String> classpath; + try { + classpath = getClasspath(); + } catch (DependencyResolutionRequiredException e) { + throw new MojoExecutionException("Error getting classpath artifacts", e); + } + final File target = getTarget(); + final Properties config = weaverConfig == null ? new Properties() : weaverConfig; + + getLog().debug(String.format("classpath=%s%ntarget=%s%nconfig=%s", classpath, target, config)); + + doExecute(target, classpath, config); + } finally { + logRedirector.deactivate(); + } + } + + protected abstract void doExecute(File target, List<String> classpath, Properties config) + throws MojoExecutionException, MojoFailureException; + +} Propchange: commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractCWMojo.java ------------------------------------------------------------------------------ svn:executable = * Modified: commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractPrepareMojo.java URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractPrepareMojo.java?rev=1746356&r1=1746355&r2=1746356&view=diff ============================================================================== --- commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractPrepareMojo.java (original) +++ commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractPrepareMojo.java Tue May 31 22:50:13 2016 @@ -23,64 +23,23 @@ import java.util.List; import java.util.Properties; import org.apache.commons.weaver.CleanProcessor; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Parameter; /** - * Defines common properties. + * Implements weaver preparation. */ -public abstract class AbstractPrepareMojo extends AbstractMojo { +public abstract class AbstractPrepareMojo extends AbstractCWMojo { - /** - * {@code verbose} parameter. - */ - @Parameter(defaultValue = "false") - protected boolean verbose; - - /** - * {@code weaver.config} parameter. - */ - @Parameter(property = "weaver.config", required = false) - protected Properties weaverConfig; - - /** - * Get the classpath for this prepare mojo. - * @return {@link List} of {@link String} - */ - protected abstract List<String> getClasspath(); - - /** - * Get the target directory for this prepare mojo. - * @return {@link File} - */ - protected abstract File getTarget(); - - /** - * Execute this mojo. - * @throws MojoExecutionException in the event of failure - */ @Override - public void execute() throws MojoExecutionException { - if (!getTarget().isDirectory()) { + protected void doExecute(File target, List<String> classpath, Properties config) throws MojoExecutionException { + if (!target.isDirectory()) { return; } - final JavaLoggingToMojoLoggingRedirector logRedirector = new JavaLoggingToMojoLoggingRedirector(getLog()); - logRedirector.activate(); - - final List<String> classpath = getClasspath(); - final File target = getTarget(); - final Properties config = weaverConfig == null ? new Properties() : weaverConfig; - - getLog().debug(String.format("classpath=%s%ntarget=%s%nconfig=%s", classpath, target, config)); - try { final CleanProcessor cleanProcessor = new CleanProcessor(classpath, target, config); cleanProcessor.clean(); } catch (Exception e) { throw new MojoExecutionException("cleaning failed due to " + e.getMessage(), e); - } finally { - logRedirector.deactivate(); } } Modified: commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java?rev=1746356&r1=1746355&r2=1746356&view=diff ============================================================================== --- commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java (original) +++ commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java Tue May 31 22:50:13 2016 @@ -23,61 +23,20 @@ import java.util.List; import java.util.Properties; import org.apache.commons.weaver.WeaveProcessor; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Parameter; /** * Defines common properties. */ -public abstract class AbstractWeaveMojo extends AbstractMojo { +public abstract class AbstractWeaveMojo extends AbstractCWMojo { - /** - * {@code verbose} parameter. - */ - @Parameter(defaultValue = "false") - protected boolean verbose; - - /** - * {@code weaver.config} parameter. - */ - @Parameter(property = "weaver.config", required = false) - protected Properties weaverConfig; - - /** - * Get the classpath for this weave mojo. - * @return {@link List} of {@link String} - */ - protected abstract List<String> getClasspath(); - - /** - * Get the target directory for this weave mojo. - * @return {@link File} - */ - protected abstract File getTarget(); - - /** - * Execute this mojo. - * @throws MojoExecutionException in the event of failure - */ @Override - public void execute() throws MojoExecutionException { - final JavaLoggingToMojoLoggingRedirector logRedirector = new JavaLoggingToMojoLoggingRedirector(getLog()); - logRedirector.activate(); - - final List<String> classpath = getClasspath(); - final File target = getTarget(); - final Properties config = weaverConfig == null ? new Properties() : weaverConfig; - - getLog().debug(String.format("classpath=%s%ntarget=%s%nconfig=%s", classpath, target, config)); - + protected void doExecute(File target, List<String> classpath, Properties config) throws MojoExecutionException { try { final WeaveProcessor weaveProcessor = new WeaveProcessor(classpath, target, config); weaveProcessor.weave(); } catch (Exception e) { throw new MojoExecutionException("weaving failed due to " + e.getMessage(), e); - } finally { - logRedirector.deactivate(); } } Modified: commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/PrepareMojo.java URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/PrepareMojo.java?rev=1746356&r1=1746355&r2=1746356&view=diff ============================================================================== --- commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/PrepareMojo.java (original) +++ commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/PrepareMojo.java Tue May 31 22:50:13 2016 @@ -19,14 +19,17 @@ package org.apache.commons.weaver.maven; import java.io.File; +import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; +import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.model.Build; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.project.MavenProject; /** * Goal to clean woven classes. @@ -34,16 +37,11 @@ import org.apache.maven.project.MavenPro @Mojo( name = "prepare", defaultPhase = LifecyclePhase.INITIALIZE, - requiresDependencyCollection = ResolutionScope.COMPILE + requiresDependencyCollection = ResolutionScope.RUNTIME_PLUS_SYSTEM, + requiresDependencyResolution = ResolutionScope.RUNTIME_PLUS_SYSTEM ) public class PrepareMojo extends AbstractPrepareMojo { /** - * {@link MavenProject#getCompileClasspathElements()}. - */ - @Parameter(readonly = true, required = true, defaultValue = "${project.compileClasspathElements}") - protected List<String> classpath; - - /** * {@link Build#getOutputDirectory()}. */ @Parameter(readonly = true, required = true, defaultValue = "${project.build.outputDirectory}") @@ -53,8 +51,11 @@ public class PrepareMojo extends Abstrac * {@inheritDoc} */ @Override - protected List<String> getClasspath() { - return classpath; + protected List<String> getClasspath() throws DependencyResolutionRequiredException { + final Set<String> result = new LinkedHashSet<String>(); + result.addAll(project.getCompileClasspathElements()); + result.addAll(project.getRuntimeClasspathElements()); + return new ArrayList<String>(result); } /** Modified: commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestPrepareMojo.java URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestPrepareMojo.java?rev=1746356&r1=1746355&r2=1746356&view=diff ============================================================================== --- commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestPrepareMojo.java (original) +++ commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestPrepareMojo.java Tue May 31 22:50:13 2016 @@ -21,12 +21,12 @@ package org.apache.commons.weaver.maven; import java.io.File; import java.util.List; +import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.model.Build; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.project.MavenProject; /** * Goal to clean woven test classes. @@ -34,16 +34,10 @@ import org.apache.maven.project.MavenPro @Mojo( name = "test-prepare", defaultPhase = LifecyclePhase.INITIALIZE, - requiresDependencyCollection = ResolutionScope.TEST + requiresDependencyCollection = ResolutionScope.TEST, + requiresDependencyResolution = ResolutionScope.TEST ) public class TestPrepareMojo extends AbstractPrepareMojo { - - /** - * {@link MavenProject#getTestClasspathElements()}. - */ - @Parameter(readonly = true, required = true, defaultValue = "${project.testClasspathElements}") - protected List<String> classpath; - /** * {@link Build#getTestOutputDirectory()}. */ @@ -54,8 +48,8 @@ public class TestPrepareMojo extends Abs * {@inheritDoc} */ @Override - protected List<String> getClasspath() { - return classpath; + protected List<String> getClasspath() throws DependencyResolutionRequiredException { + return project.getTestClasspathElements(); } /** Modified: commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestWeaveMojo.java URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestWeaveMojo.java?rev=1746356&r1=1746355&r2=1746356&view=diff ============================================================================== --- commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestWeaveMojo.java (original) +++ commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestWeaveMojo.java Tue May 31 22:50:13 2016 @@ -21,6 +21,7 @@ package org.apache.commons.weaver.maven; import java.io.File; import java.util.List; +import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.model.Build; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -34,7 +35,8 @@ import org.apache.maven.project.MavenPro @Mojo( name = "test-weave", defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES, - requiresDependencyCollection = ResolutionScope.TEST + requiresDependencyCollection = ResolutionScope.TEST, + requiresDependencyResolution = ResolutionScope.TEST ) public class TestWeaveMojo extends AbstractWeaveMojo { @@ -54,8 +56,8 @@ public class TestWeaveMojo extends Abstr * {@inheritDoc} */ @Override - protected List<String> getClasspath() { - return classpath; + protected List<String> getClasspath() throws DependencyResolutionRequiredException { + return project.getTestClasspathElements(); } /** Modified: commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java?rev=1746356&r1=1746355&r2=1746356&view=diff ============================================================================== --- commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java (original) +++ commons/proper/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java Tue May 31 22:50:13 2016 @@ -19,14 +19,17 @@ package org.apache.commons.weaver.maven; import java.io.File; +import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; +import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.model.Build; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.project.MavenProject; /** * Goal to weave classes. @@ -34,17 +37,12 @@ import org.apache.maven.project.MavenPro @Mojo( name = "weave", defaultPhase = LifecyclePhase.PROCESS_CLASSES, - requiresDependencyCollection = ResolutionScope.COMPILE + requiresDependencyCollection = ResolutionScope.RUNTIME_PLUS_SYSTEM, + requiresDependencyResolution = ResolutionScope.RUNTIME_PLUS_SYSTEM ) public class WeaveMojo extends AbstractWeaveMojo { /** - * {@link MavenProject#getCompileClasspathElements()}. - */ - @Parameter(readonly = true, required = true, defaultValue = "${project.compileClasspathElements}") - protected List<String> classpath; - - /** * {@link Build#getOutputDirectory()}. */ @Parameter(readonly = true, required = true, defaultValue = "${project.build.outputDirectory}") @@ -54,8 +52,11 @@ public class WeaveMojo extends AbstractW * {@inheritDoc} */ @Override - protected List<String> getClasspath() { - return classpath; + protected List<String> getClasspath() throws DependencyResolutionRequiredException { + final Set<String> result = new LinkedHashSet<String>(); + result.addAll(project.getCompileClasspathElements()); + result.addAll(project.getRuntimeClasspathElements()); + return new ArrayList<String>(result); } /**