Author: khmarbaise
Date: Thu Jun  4 19:47:50 2015
New Revision: 1683617

URL: http://svn.apache.org/r1683617
Log:
[MSHADE-185] systemPath content is interpolated for system dependencies

Added:
    maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-185/
    maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-185/pom.xml
    maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-185/verify.groovy
Modified:
    
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java

Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-185/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-185/pom.xml?rev=1683617&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-185/pom.xml (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-185/pom.xml Thu Jun  4 
19:47:50 2015
@@ -0,0 +1,56 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>test.shade</groupId>
+  <artifactId>system-dep</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0.0-SNAPSHOT</version>
+  <dependencies>
+    <dependency>
+      <groupId>jline</groupId>
+      <artifactId>jline</artifactId>
+      <version>2.12</version>
+    </dependency>
+    <dependency>
+      <groupId>com.sun</groupId>
+      <artifactId>tools</artifactId>
+      <version>1.6</version>
+      <scope>system</scope>
+      <systemPath>${java.home}/../lib/tools.jar</systemPath>
+      <optional>true</optional>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>@project.groupId@</groupId>
+        <artifactId>@project.artifactId@</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <shadedArtifactAttached>false</shadedArtifactAttached>
+              <createDependencyReducedPom>true</createDependencyReducedPom>
+              <createSourcesJar>true</createSourcesJar>
+              <artifactSet>
+                <includes>
+                  <include>jline:jline</include>
+                </includes>
+              </artifactSet>
+              <relocations>
+                <relocation>
+                  <pattern>jline</pattern>
+                  <shadedPattern>org.crsh.console.jline</shadedPattern>
+                </relocation>
+              </relocations> 
+           </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
+

Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-185/verify.groovy
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-185/verify.groovy?rev=1683617&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-185/verify.groovy 
(added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-185/verify.groovy Thu 
Jun  4 19:47:50 2015
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+File pomFile = new File( basedir, "dependency-reduced-pom.xml" );
+assert pomFile.isFile()
+
+def project = new XmlSlurper().parse( pomFile )
+
+assert project.dependencies.dependency[0].artifactId == 'tools'
+assert project.dependencies.dependency[0].groupId == 'com.sun'
+assert project.dependencies.dependency[0].version == '1.6'
+assert project.dependencies.dependency[0].scope == 'system'
+// Check that the dependency-reduced pom does not have expand properties in 
+// dependencies. They should be left untouched.
+assert project.dependencies.dependency[0].systemPath == 
'${java.home}/../lib/tools.jar'

Modified: 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java?rev=1683617&r1=1683616&r2=1683617&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
 Thu Jun  4 19:47:50 2015
@@ -88,9 +88,9 @@ import org.codehaus.plexus.util.WriterFa
  * @author David Blevins
  * @author Hiram Chirino
  */
-//CHECKSTYLE_OFF: LineLength
+// CHECKSTYLE_OFF: LineLength
 @Mojo( name = "shade", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = 
true, requiresDependencyResolution = ResolutionScope.RUNTIME )
-//CHECKSTYLE_ON: LineLength
+// CHECKSTYLE_ON: LineLength
 public class ShadeMojo
     extends AbstractMojo
     implements Contextualizable
@@ -900,13 +900,14 @@ public class ShadeMojo
     private void createDependencyReducedPom( Set<String> artifactsToRemove )
         throws IOException, DependencyGraphBuilderException, 
ProjectBuildingException
     {
-        Model model = project.getOriginalModel();
         List<Dependency> dependencies = new ArrayList<Dependency>();
 
         boolean modified = false;
 
         List<Dependency> transitiveDeps = new ArrayList<Dependency>();
 
+        // NOTE: By using the getArtifacts() we get the completely evaluated 
artifacts
+        // including the system scoped artifacts with expanded values of 
properties used.
         for ( Artifact artifact : project.getArtifacts() )
         {
             if ( "pom".equals( artifact.getType() ) )
@@ -919,7 +920,6 @@ public class ShadeMojo
             Dependency dep = createDependency( artifact );
 
             // we'll figure out the exclusions in a bit.
-
             transitiveDeps.add( dep );
         }
         List<Dependency> origDeps = project.getDependencies();
@@ -929,6 +929,13 @@ public class ShadeMojo
             origDeps = transitiveDeps;
         }
 
+        Model model = project.getOriginalModel();
+        // MSHADE-185: We will remove all system scoped dependencies which 
usually
+        // have some kind of property usage. At this time the properties within
+        // such things are already evaluated.
+        List<Dependency> originalDependencies = model.getDependencies();
+        removeSystemScopedDependencies( artifactsToRemove, 
originalDependencies );
+
         for ( Dependency d : origDeps )
         {
             dependencies.add( d );
@@ -950,6 +957,11 @@ public class ShadeMojo
             }
         }
 
+        // MSHADE-185: We will add those system scoped dependencies
+        // from the non interpolated original pom file. So we keep
+        // things like this: <systemPath>${tools.jar}</systemPath> intact.
+        addSystemScopedDependencyFromNonInterpolatedPom( dependencies, 
originalDependencies );
+
         // Check to see if we have a reduction and if so rewrite the POM.
         if ( modified )
         {
@@ -1027,6 +1039,7 @@ public class ShadeMojo
 
                 ProjectBuildingResult result = projectBuilder.build( f, 
projectBuildingRequest );
 
+                getLog().debug( "updateExcludesInDeps()" );
                 modified = updateExcludesInDeps( result.getProject(), 
dependencies, transitiveDeps );
             }
 
@@ -1034,6 +1047,29 @@ public class ShadeMojo
         }
     }
 
+    private void removeSystemScopedDependencies( Set<String> 
artifactsToRemove, List<Dependency> originalDependencies )
+    {
+        for ( Dependency dependency : originalDependencies )
+        {
+            if ( dependency.getScope() != null && 
dependency.getScope().equalsIgnoreCase( "system" ) )
+            {
+                artifactsToRemove.add( getId( dependency ) );
+            }
+        }
+    }
+
+    private void addSystemScopedDependencyFromNonInterpolatedPom( 
List<Dependency> dependencies,
+                                                                  
List<Dependency> originalDependencies )
+    {
+        for ( Dependency dependency : originalDependencies )
+        {
+            if ( dependency.getScope() != null && 
dependency.getScope().equalsIgnoreCase( "system" ) )
+            {
+                dependencies.add( dependency );
+            }
+        }
+    }
+
     private Dependency createDependency( Artifact artifact )
     {
         Dependency dep = new Dependency();


Reply via email to