Skip to content

Commit d35f602

Browse files
Improve usage of silent parameter in Copy and Unpack goals
- parameter should be defined where is used, so move to child class from root class AbstractDependencyMojo - use it during logging of coping or unpacking
1 parent 7b5c7ad commit d35f602

File tree

16 files changed

+78
-323
lines changed

16 files changed

+78
-323
lines changed

src/it/projects/copy-dependencies-with-conflict/verify.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ assert file.exists()
2222

2323
String buildLog = file.getText( "UTF-8" )
2424
assert buildLog.contains( '[WARNING] Overwriting ' )
25-
assert buildLog.contains( '[DEBUG] Copying artifact \'org.jdom:jdom:jar:1.1.3\'' )
26-
assert buildLog.contains( '[DEBUG] Copying artifact \'org.jdom:jdom:pom:1.1.3\'' )
27-
assert buildLog.contains( '[DEBUG] Copying artifact \'org.jdom:jdom:jar:1.1.3\'' )
28-
assert buildLog.contains( '[DEBUG] Copying artifact \'org.lucee:jdom:jar:1.1.3\'' )
25+
assert buildLog.contains( '[INFO] Copying artifact \'org.jdom:jdom:jar:1.1.3\'' )
26+
assert buildLog.contains( '[INFO] Copying artifact \'org.jdom:jdom:pom:1.1.3\'' )
27+
assert buildLog.contains( '[INFO] Copying artifact \'org.jdom:jdom:jar:1.1.3\'' )
28+
assert buildLog.contains( '[INFO] Copying artifact \'org.lucee:jdom:jar:1.1.3\'' )
2929
assert buildLog.contains( '[WARNING] Multiple files with the name jdom-1.1.3.jar in the dependency tree.' )
3030

3131
return true

src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
import org.apache.maven.plugin.AbstractMojo;
2626
import org.apache.maven.plugin.MojoExecutionException;
2727
import org.apache.maven.plugin.MojoFailureException;
28-
import org.apache.maven.plugin.logging.SystemStreamLog;
2928
import org.apache.maven.plugins.annotations.Parameter;
30-
import org.apache.maven.plugins.dependency.utils.DependencySilentLog;
3129
import org.apache.maven.project.DefaultProjectBuildingRequest;
3230
import org.apache.maven.project.MavenProject;
3331
import org.apache.maven.project.ProjectBuildingRequest;
@@ -61,16 +59,6 @@ public abstract class AbstractDependencyMojo extends AbstractMojo {
6159
*/
6260
protected final MavenSession session;
6361

64-
/**
65-
* If the plugin should be silent.
66-
*
67-
* @deprecated to be removed in 4.0; use -q command line option instead
68-
* @since 2.0
69-
*/
70-
@Deprecated
71-
@Parameter(property = "silent", defaultValue = "false")
72-
private boolean silent;
73-
7462
/**
7563
* Skip plugin execution completely.
7664
*
@@ -172,27 +160,4 @@ public boolean isSkip() {
172160
public void setSkip(boolean skip) {
173161
this.skip = skip;
174162
}
175-
176-
/**
177-
* @return {@link #silent}
178-
* @deprecated to be removed in 4.0
179-
*/
180-
@Deprecated
181-
protected final boolean isSilent() {
182-
return silent;
183-
}
184-
185-
/**
186-
* @param silent {@link #silent}
187-
* @deprecated to be removed in 4.0; no API replacement, use -q command line option instead
188-
*/
189-
@Deprecated
190-
public void setSilent(boolean silent) {
191-
this.silent = silent;
192-
if (silent) {
193-
setLog(new DependencySilentLog());
194-
} else if (getLog() instanceof DependencySilentLog) {
195-
setLog(new SystemStreamLog());
196-
}
197-
}
198163
}

src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ public abstract class AbstractFromConfigurationMojo extends AbstractDependencyMo
9292
@Parameter(property = "mdep.overIfNewer", defaultValue = "true")
9393
private boolean overIfNewer;
9494

95+
/**
96+
* If the plugin should be more silent with logging.
97+
* <br/>
98+
* Use {@code -q} command line option if you want to suppress all output.
99+
* @since 2.0
100+
*/
101+
@Parameter(property = "silent", defaultValue = "false")
102+
private boolean silent;
103+
95104
/**
96105
* Overwrite if newer
97106
*
@@ -386,6 +395,13 @@ public void setLocalRepositoryDirectory(File localRepositoryDirectory) {
386395
this.localRepositoryDirectory = localRepositoryDirectory;
387396
}
388397

398+
/**
399+
* @return {@link #silent}
400+
*/
401+
protected final boolean isSilent() {
402+
return silent;
403+
}
404+
389405
/**
390406
* @param artifact The artifact.
391407
* @throws MojoFailureException in case of an error.

src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
128128
*
129129
* @param artifactItem containing the information about the artifact to copy
130130
* @throws MojoExecutionException with a message if an error occurs
131-
* @see CopyUtil#copyArtifactFile(Artifact, File)
131+
* @see CopyUtil#copyArtifactFile(Artifact, File, boolean)
132132
*/
133133
protected void copyArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
134134
File destFile = new File(artifactItem.getOutputDirectory(), artifactItem.getDestFileName());
135135
if (destFile.exists()) {
136136
getLog().warn("Overwriting " + destFile);
137137
}
138138
try {
139-
copyUtil.copyArtifactFile(artifactItem.getArtifact(), destFile);
139+
copyUtil.copyArtifactFile(artifactItem.getArtifact(), destFile, isSilent());
140140
} catch (IOException e) {
141141
throw new MojoExecutionException(
142142
"Failed to copy artifact '" + artifactItem.getArtifact() + "' ("

src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/UnpackMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private void unpackArtifact(ArtifactItem artifactItem) throws MojoExecutionExcep
162162
artifactItem.getEncoding(),
163163
ignorePermissions,
164164
artifactItem.getFileMappers(),
165-
getLog());
165+
isSilent());
166166
handler.setMarker();
167167
}
168168

src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractFromDependenciesMojo.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ public abstract class AbstractFromDependenciesMojo extends AbstractDependencyFil
114114
@Parameter(property = "mdep.failOnMissingClassifierArtifact", defaultValue = "false")
115115
protected boolean failOnMissingClassifierArtifact;
116116

117+
/**
118+
* If the plugin should be more silent with logging.
119+
* <br/>
120+
* Use {@code -q} command line option if you want to suppress all output.
121+
* @since 2.0
122+
*/
123+
@Parameter(property = "silent", defaultValue = "false")
124+
private boolean silent;
125+
117126
// CHECKSTYLE_OFF: ParameterNumber
118127
protected AbstractFromDependenciesMojo(
119128
MavenSession session,
@@ -247,4 +256,11 @@ public boolean isUseRepositoryLayout() {
247256
public void setUseRepositoryLayout(boolean useRepositoryLayout) {
248257
this.useRepositoryLayout = useRepositoryLayout;
249258
}
259+
260+
/**
261+
* @return {@link #silent}
262+
*/
263+
protected final boolean isSilent() {
264+
return silent;
265+
}
250266
}

src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ protected void copyArtifact(
245245
* @param useBaseVersion specifies if the baseVersion of the artifact should be used instead of the version
246246
* @param removeClassifier specifies if the classifier should be removed from the file name when copying
247247
* @throws MojoExecutionException with a message if an error occurs
248-
* @see CopyUtil#copyArtifactFile(Artifact, File)
248+
* @see CopyUtil#copyArtifactFile(Artifact, File, boolean)
249249
* @see DependencyUtil#getFormattedOutputDirectory(boolean, boolean, boolean, boolean, boolean, boolean, File, Artifact)
250250
*/
251251
private static final String SIGNATURE_EXTENSION = ".asc";
@@ -275,7 +275,7 @@ protected void copyArtifact(
275275
getLog().warn("Overwriting " + destFile);
276276
}
277277
try {
278-
copyUtil.copyArtifactFile(artifact, destFile);
278+
copyUtil.copyArtifactFile(artifact, destFile, isSilent());
279279

280280
// Copy the signature file if the copySignatures flag is true
281281
if (copySignatures) {
@@ -314,7 +314,7 @@ private void copySignatureFile(Artifact artifact, File destDir, String destFileN
314314
if (signatureFile != null && signatureFile.exists()) {
315315
File signatureDestFile = new File(destDir, destFileName + SIGNATURE_EXTENSION);
316316
try {
317-
copyUtil.copyFile(signatureFile, signatureDestFile);
317+
copyUtil.copyFile(signatureFile, signatureDestFile, isSilent());
318318
} catch (IOException e) {
319319
getLog().warn("Failed to copy signature file: " + signatureFile, e);
320320
}
@@ -361,7 +361,7 @@ public void copyPoms(File destDir, Set<Artifact> artifacts, boolean removeVersio
361361
pomArtifact, removeVersion, prependGroupId, useBaseVersion, removeClassifier));
362362
if (!pomDestFile.exists()) {
363363
try {
364-
copyUtil.copyArtifactFile(pomArtifact, pomDestFile);
364+
copyUtil.copyArtifactFile(pomArtifact, pomDestFile, isSilent());
365365
} catch (IOException e) {
366366
throw new MojoExecutionException(
367367
"Failed to copy artifact '" + pomArtifact + "' (" + pomArtifact.getFile() + ") to "

src/main/java/org/apache/maven/plugins/dependency/fromDependencies/UnpackDependenciesMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected void doExecute() throws MojoExecutionException {
160160
getEncoding(),
161161
ignorePermissions,
162162
getFileMappers(),
163-
getLog());
163+
isSilent());
164164
DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler(artifact, this.markersDirectory);
165165
handler.setMarker();
166166
}

src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.maven.model.Dependency;
3636
import org.apache.maven.plugin.MojoExecutionException;
3737
import org.apache.maven.plugins.annotations.Mojo;
38+
import org.apache.maven.plugins.annotations.Parameter;
3839
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
3940
import org.apache.maven.plugins.dependency.utils.ResolverUtil;
4041
import org.apache.maven.project.MavenProject;
@@ -63,6 +64,15 @@
6364
@Mojo(name = "go-offline", threadSafe = true)
6465
public class GoOfflineMojo extends AbstractResolveMojo {
6566

67+
/**
68+
* If the plugin should be more silent with logging.
69+
* <br/>
70+
* Use {@code -q} command line option if you want to suppress all output.
71+
* @since 2.0
72+
*/
73+
@Parameter(property = "silent", defaultValue = "false")
74+
private boolean silent;
75+
6676
@Inject
6777
// CHECKSTYLE_OFF: ParameterNumber
6878
public GoOfflineMojo(
@@ -100,7 +110,7 @@ protected void doExecute() throws MojoExecutionException {
100110

101111
final Set<Artifact> dependencies = resolveDependencyArtifacts();
102112

103-
if (!isSilent()) {
113+
if (!silent) {
104114
for (Artifact artifact : plugins) {
105115
this.getLog().info("Resolved plugin: " + DependencyUtil.getFormattedFileName(artifact, false));
106116
}

src/main/java/org/apache/maven/plugins/dependency/utils/CopyUtil.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,27 @@ public CopyUtil(BuildContext buildContext) {
5555
*
5656
* @param sourceArtifact the artifact (file) to copy
5757
* @param destination file name of destination file
58+
* @param silent if true, use debug log level, otherwise info for logging
5859
* @throws IOException if copy has failed
5960
* @throws MojoExecutionException if artifact file is a directory (which has not been packaged yet)
6061
*
6162
* @since 3.7.0
6263
*/
63-
public void copyArtifactFile(Artifact sourceArtifact, File destination) throws IOException, MojoExecutionException {
64+
public void copyArtifactFile(Artifact sourceArtifact, File destination, boolean silent)
65+
throws IOException, MojoExecutionException {
6466
File source = sourceArtifact.getFile();
6567
if (source.isDirectory()) {
6668
// usual case is a future jar packaging, but there are special cases: classifier and other packaging
6769
throw new MojoExecutionException("Artifact '" + sourceArtifact
6870
+ "' has not been packaged yet (is a directory). When used on reactor artifact, "
6971
+ "copy should be executed after packaging: see MDEP-187.");
7072
}
71-
logger.debug("Copying artifact '{}' ({}) to {}", sourceArtifact.getId(), sourceArtifact.getFile(), destination);
73+
74+
if (!silent) {
75+
logger.info(
76+
"Copying artifact '{}' ({}) to {}", sourceArtifact.getId(), sourceArtifact.getFile(), destination);
77+
}
78+
7279
FileUtils.copyFile(source, destination);
7380
buildContext.refresh(destination);
7481
}
@@ -78,12 +85,15 @@ public void copyArtifactFile(Artifact sourceArtifact, File destination) throws I
7885
*
7986
* @param source the source file to copy
8087
* @param destination the destination file
88+
* @param silent if true, use debug log level, otherwise info for logging
8189
* @throws IOException if copy has failed
8290
*
8391
* @since 3.2.0
8492
*/
85-
public void copyFile(File source, File destination) throws IOException {
86-
logger.debug("Copying file '{}' to {}", source, destination);
93+
public void copyFile(File source, File destination, boolean silent) throws IOException {
94+
if (!silent) {
95+
logger.info("Copying file '{}' to {}", source, destination);
96+
}
8797
FileUtils.copyFile(source, destination);
8898
buildContext.refresh(destination);
8999
}

0 commit comments

Comments
 (0)