diff --git a/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java b/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java index bbf981af9..45e43be16 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java @@ -25,6 +25,7 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.SystemStreamLog; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.dependency.utils.DependencySilentLog; @@ -86,7 +87,7 @@ public abstract class AbstractDependencyMojo extends AbstractMojo { /** * If the plugin should be silent. * - * @deprecated to be removed in 4.0; use -Q command line option instead + * @deprecated to be removed in 4.0; use -q command line option instead * @since 2.0 */ @Deprecated @@ -181,13 +182,15 @@ protected final boolean isSilent() { /** * @param silent {@link #silent} - * @deprecated to be removed in 4.0; no API replacement, use -Q command line option instead + * @deprecated to be removed in 4.0; no API replacement, use -q command line option instead */ @Deprecated public void setSilent(boolean silent) { this.silent = silent; if (silent) { setLog(new DependencySilentLog()); + } else if (getLog() instanceof DependencySilentLog) { + setLog(new SystemStreamLog()); } } } diff --git a/src/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java b/src/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java index 070cbb69c..265bb17a2 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java @@ -23,14 +23,16 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.testing.SilentLog; import org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo; +import org.apache.maven.plugins.dependency.resolvers.ResolveDependenciesMojo; import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub; +import org.apache.maven.plugins.dependency.utils.DependencySilentLog; import org.apache.maven.plugins.dependency.utils.DependencyStatusSets; import org.apache.maven.project.MavenProject; public class TestCollectMojo extends AbstractDependencyMojoTestCase { + @Override protected void setUp() throws Exception { // required for mojo lookups to work super.setUp("markers", false); @@ -98,10 +100,15 @@ public void testCollectTestEnvironment_excludeTransitive() throws Exception { } public void testSilent() throws Exception { - File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml"); - CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom); - mojo.setSilent(false); + File testPom = new File(getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml"); + ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo("resolve", testPom); + + assertFalse(mojo.getLog() instanceof DependencySilentLog); - assertFalse(mojo.getLog() instanceof SilentLog); + mojo.setSilent(true); + assertTrue(mojo.getLog() instanceof DependencySilentLog); + + mojo.setSilent(false); + assertFalse(mojo.getLog() instanceof DependencySilentLog); } // TODO: Test skipping artifacts. } diff --git a/src/test/java/org/apache/maven/plugins/dependency/resolvers/TestResolveMojo.java b/src/test/java/org/apache/maven/plugins/dependency/resolvers/TestResolveMojo.java index 9c1d6a56f..720d13f7b 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/resolvers/TestResolveMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/resolvers/TestResolveMojo.java @@ -23,14 +23,15 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.testing.SilentLog; import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase; import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub; +import org.apache.maven.plugins.dependency.utils.DependencySilentLog; import org.apache.maven.plugins.dependency.utils.DependencyStatusSets; import org.apache.maven.project.MavenProject; public class TestResolveMojo extends AbstractDependencyMojoTestCase { + @Override protected void setUp() throws Exception { // required for mojo lookups to work super.setUp("markers", false); @@ -47,7 +48,7 @@ protected void setUp() throws Exception { * * @throws Exception in case of errors. */ - public void testresolveTestEnvironment() throws Exception { + public void testResolveTestEnvironment() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml"); ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo("resolve", testPom); @@ -79,8 +80,13 @@ public void testresolveTestEnvironment() throws Exception { public void testSilent() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml"); ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo("resolve", testPom); - mojo.setSilent(false); - assertFalse(mojo.getLog() instanceof SilentLog); + assertFalse(mojo.getLog() instanceof DependencySilentLog); + + mojo.setSilent(true); + assertTrue(mojo.getLog() instanceof DependencySilentLog); + + mojo.setSilent(false); + assertFalse(mojo.getLog() instanceof DependencySilentLog); } // TODO: Test skipping artifacts. } diff --git a/src/test/java/org/apache/maven/plugins/dependency/utils/TestSilentLog.java b/src/test/java/org/apache/maven/plugins/dependency/utils/TestSilentLog.java index b6cd7e435..025e42338 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/utils/TestSilentLog.java +++ b/src/test/java/org/apache/maven/plugins/dependency/utils/TestSilentLog.java @@ -19,6 +19,7 @@ package org.apache.maven.plugins.dependency.utils; import org.apache.maven.plugin.logging.Log; +import org.junit.Assert; import org.junit.Test; public class TestSilentLog { @@ -40,9 +41,9 @@ public void testLog() { log.error(text); log.error(text, e); log.error(e); - log.isDebugEnabled(); - log.isErrorEnabled(); - log.isWarnEnabled(); - log.isInfoEnabled(); + Assert.assertFalse(log.isDebugEnabled()); + Assert.assertFalse(log.isErrorEnabled()); + Assert.assertFalse(log.isWarnEnabled()); + Assert.assertFalse(log.isInfoEnabled()); } }