Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/it/projects/verbose-logging/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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.
-->

<project>
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.shade.verbose</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>verbose-logging</name>
<description>
Test that the verbose option logs included/excluded dependencies at info level.
</description>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<verbose>true</verbose>
<artifactSet>
<excludes>
<exclude>org.slf4j:slf4j-simple</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
26 changes: 26 additions & 0 deletions src/it/projects/verbose-logging/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.
*/
def buildLog = new File(basedir, 'build.log')
assert buildLog.exists()

def content = buildLog.text
assert content.contains('[INFO] Including org.slf4j:slf4j-api:jar:1.7.36 in the shaded jar.')
assert content.contains('[INFO] Excluding org.slf4j:slf4j-simple:jar:1.7.36 from the shaded jar.')

return true
28 changes: 23 additions & 5 deletions src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ public class ShadeMojo extends AbstractMojo {
@Parameter(defaultValue = "false")
private boolean skip;

/**
* When true, the plugin logs details about the shading process at info level, such as the dependencies
* included in or excluded from the shaded jar. When false, those details are only logged at debug level.
* This restores the output that was logged at info level before version 3.6.1.
*
* @since 3.6.3
*/
@Parameter(property = "shade.verbose", defaultValue = "false")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like you're reinventing log levels.

private boolean verbose;

/**
* Extra JAR files to infuse into shaded result. Accepts list of files that must exists. If any of specified
* files does not exist (or is not a file), Mojo will fail.
Expand Down Expand Up @@ -787,7 +797,7 @@ private List<Artifact> processArtifactSelectors(
continue;
}

getLog().debug("Including " + artifact.getId() + " in the shaded jar.");
logVerbose("Including " + artifact.getId() + " in the shaded jar.");

artifacts.add(artifact.getFile());
artifactIds.add(getId(artifact));
Expand Down Expand Up @@ -846,10 +856,10 @@ private List<Artifact> processArtifactSelectors(
processedArtifacts.removeAll(emptyTestSourceArtifacts);

for (Artifact artifact : excludedArtifacts) {
getLog().debug("Excluding " + artifact.getId() + " from the shaded jar.");
logVerbose("Excluding " + artifact.getId() + " from the shaded jar.");
}
for (Artifact artifact : pomArtifacts) {
getLog().debug("Skipping pom dependency " + artifact.getId() + " in the shaded jar.");
logVerbose("Skipping pom dependency " + artifact.getId() + " in the shaded jar.");
}
for (Artifact artifact : emptySourceArtifacts) {
getLog().warn("Skipping empty source jar " + artifact.getId() + ".");
Expand All @@ -868,8 +878,16 @@ private boolean invalidMainArtifact() {
|| !project.getArtifact().getFile().isFile();
}

private void logVerbose(String message) {
if (verbose) {
getLog().info(message);
} else {
getLog().debug(message);
}
}

private void replaceFile(File oldFile, File newFile) throws MojoExecutionException {
getLog().debug("Replacing " + oldFile + " with " + newFile);
logVerbose("Replacing " + oldFile + " with " + newFile);

File origFile = new File(outputDirectory, "original-" + oldFile.getName());
if (oldFile.exists() && !oldFile.renameTo(origFile)) {
Expand Down Expand Up @@ -1029,7 +1047,7 @@ private List<Filter> getFilters(List<Artifact> artifactCollection, ArtifactSelec
}

if (jars.isEmpty()) {
getLog().debug("No artifact matching filter " + filter.getArtifact());
logVerbose("No artifact matching filter " + filter.getArtifact());

continue;
}
Expand Down
Loading