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
85 changes: 85 additions & 0 deletions src/it/projects/MSHADE-434_ratSideEffect/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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</groupId>
<artifactId>mshade-434</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>MSHADE-434</name>
<description>
Test that project.getFile() is restored to the original pom.xml after shading,
preventing side effects on subsequent plugins (e.g., RAT, checkstyle).
</description>

<dependencies>
<dependency>
<groupId>org.apache.maven.its.shade.fac</groupId>
<artifactId>a</artifactId>
<version>0.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>shade</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>check-project-file</id>
<phase>package</phase>
<goals>
<goal>evaluate</goal>
</goals>
<configuration>
<expression>project.file</expression>
<forceStdout>true</forceStdout>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
41 changes: 41 additions & 0 deletions src/it/projects/MSHADE-434_ratSideEffect/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.
*/

// Verify the dependency-reduced POM was created in the expected location
File drpFile = new File(basedir, "target/dependency-reduced-pom.xml")
assert drpFile.isFile() : "DRP should exist at " + drpFile

// Verify the shaded JAR was created
File shadedJar = new File(basedir, "target/mshade-434-1.0.jar")
assert shadedJar.isFile() : "Shaded JAR should exist at " + shadedJar

// Verify that project.getFile() was restored to the original pom.xml after shading
// by checking the build log for the help:evaluate output
File buildLog = new File(basedir, "../build.log")
if (!buildLog.isFile()) {
buildLog = new File(basedir, "build.log")
}
assert buildLog.isFile() : "build.log should exist"

def lines = buildLog.readLines()
// help:evaluate with forceStdout prints the expression value on its own line
// Look for a bare absolute path that ends with "/pom.xml" (not "dependency-reduced-pom.xml")
def projectFileLine = lines.find { it =~ /^\// && it.endsWith("/pom.xml") }
assert projectFileLine != null : "project.file value not found in build log (expected a path ending with /pom.xml)"
assert projectFileLine.endsWith("/pom.xml") : "project.file should be pom.xml, but was: " + projectFileLine
Comment on lines +39 to +41
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,15 @@ public void execute() throws MojoExecutionException {
List<ResourceTransformer> resourceTransformers = getResourceTransformers();

if (createDependencyReducedPom) {
File originalProjectFile = project.getFile();
createDependencyReducedPom(artifactIds);

if (useDependencyReducedPomInJar) {
// In some cases the used implementation of the resourceTransformers is immutable.
resourceTransformers = new ArrayList<>(resourceTransformers);
resourceTransformers.addAll(createPomReplaceTransformers(project, dependencyReducedPomLocation));
}
project.setFile(originalProjectFile);
}

ShadeRequest shadeRequest =
Expand Down
Loading