Skip to content

Commit cd9084a

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 9377649 commit cd9084a

File tree

16 files changed

+72
-324
lines changed

16 files changed

+72
-324
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-
* @since 2.0
68-
* @deprecated to be removed in 4.0; use -q command line option instead
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,11 @@ public boolean isUseRepositoryLayout() {
233233
public void setUseRepositoryLayout(boolean useRepositoryLayout) {
234234
this.useRepositoryLayout = useRepositoryLayout;
235235
}
236+
237+
/**
238+
* @return {@link #silent}
239+
*/
240+
protected final boolean isSilent() {
241+
return silent;
242+
}
236243
}

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
@@ -237,7 +237,7 @@ protected void copyArtifact(
237237
* @param useBaseVersion specifies if the baseVersion of the artifact should be used instead of the version
238238
* @param removeClassifier specifies if the classifier should be removed from the file name when copying
239239
* @throws MojoExecutionException with a message if an error occurs
240-
* @see CopyUtil#copyArtifactFile(Artifact, File)
240+
* @see CopyUtil#copyArtifactFile(Artifact, File, boolean)
241241
* @see DependencyUtil#getFormattedOutputDirectory(boolean, boolean, boolean, boolean, boolean, boolean, File, Artifact)
242242
*/
243243
private static final String SIGNATURE_EXTENSION = ".asc";
@@ -267,7 +267,7 @@ protected void copyArtifact(
267267
getLog().warn("Overwriting " + destFile);
268268
}
269269
try {
270-
copyUtil.copyArtifactFile(artifact, destFile);
270+
copyUtil.copyArtifactFile(artifact, destFile, isSilent());
271271

272272
// Copy the signature file if the copySignatures flag is true
273273
if (copySignatures) {
@@ -307,7 +307,7 @@ private void copySignatureFile(Artifact artifact, File destDir, String destFileN
307307
if (signatureFile != null && signatureFile.exists()) {
308308
File signatureDestFile = new File(destDir, destFileName + SIGNATURE_EXTENSION);
309309
try {
310-
copyUtil.copyFile(signatureFile, signatureDestFile);
310+
copyUtil.copyFile(signatureFile, signatureDestFile, isSilent());
311311
} catch (IOException e) {
312312
getLog().warn("Failed to copy signature file: " + signatureFile, e);
313313
}
@@ -354,7 +354,7 @@ public void copyPoms(File destDir, Set<Artifact> artifacts, boolean removeVersio
354354
pomArtifact, removeVersion, prependGroupId, useBaseVersion, removeClassifier));
355355
if (!pomDestFile.exists()) {
356356
try {
357-
copyUtil.copyArtifactFile(pomArtifact, pomDestFile);
357+
copyUtil.copyArtifactFile(pomArtifact, pomDestFile, isSilent());
358358
} catch (IOException e) {
359359
throw new MojoExecutionException(
360360
"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
@@ -146,7 +146,7 @@ protected void doExecute() throws MojoExecutionException {
146146
getEncoding(),
147147
ignorePermissions,
148148
getFileMappers(),
149-
getLog());
149+
isSilent());
150150
DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler(artifact, this.markersDirectory);
151151
handler.setMarker();
152152
}

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;
@@ -64,6 +65,15 @@ public class GoOfflineMojo extends AbstractResolveMojo {
6465

6566
private final DependencyResolver dependencyResolver;
6667

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

94104
final Set<Artifact> dependencies = resolveDependencyArtifacts();
95105

96-
if (!isSilent()) {
106+
if (!silent) {
97107
for (Artifact artifact : plugins) {
98108
this.getLog().info("Resolved plugin: " + DependencyUtil.getFormattedFileName(artifact, false));
99109
}

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,19 +55,26 @@ 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, don't show information about copied files
5859
* @throws IOException if copy has failed
5960
* @throws MojoExecutionException if artifact file is a directory (which has not been packaged yet)
6061
* @since 3.7.0
6162
*/
62-
public void copyArtifactFile(Artifact sourceArtifact, File destination) throws IOException, MojoExecutionException {
63+
public void copyArtifactFile(Artifact sourceArtifact, File destination, boolean silent)
64+
throws IOException, MojoExecutionException {
6365
File source = sourceArtifact.getFile();
6466
if (source.isDirectory()) {
6567
// usual case is a future jar packaging, but there are special cases: classifier and other packaging
6668
throw new MojoExecutionException("Artifact '" + sourceArtifact
6769
+ "' has not been packaged yet (is a directory). When used on reactor artifact, "
6870
+ "copy should be executed after packaging: see MDEP-187.");
6971
}
70-
logger.debug("Copying artifact '{}' ({}) to {}", sourceArtifact.getId(), sourceArtifact.getFile(), destination);
72+
73+
if (!silent || logger.isDebugEnabled()) {
74+
logger.info(
75+
"Copying artifact '{}' ({}) to {}", sourceArtifact.getId(), sourceArtifact.getFile(), destination);
76+
}
77+
7178
FileUtils.copyFile(source, destination);
7279
buildContext.refresh(destination);
7380
}
@@ -77,11 +84,14 @@ public void copyArtifactFile(Artifact sourceArtifact, File destination) throws I
7784
*
7885
* @param source the source file to copy
7986
* @param destination the destination file
87+
* @param silent if true, don't show information about copied files
8088
* @throws IOException if copy has failed
8189
* @since 3.2.0
8290
*/
83-
public void copyFile(File source, File destination) throws IOException {
84-
logger.debug("Copying file '{}' to {}", source, destination);
91+
public void copyFile(File source, File destination, boolean silent) throws IOException {
92+
if (!silent || logger.isDebugEnabled()) {
93+
logger.info("Copying file '{}' to {}", source, destination);
94+
}
8595
FileUtils.copyFile(source, destination);
8696
buildContext.refresh(destination);
8797
}

0 commit comments

Comments
 (0)