You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/06/15 18:07:20 UTC

[maven-plugin-testing] branch master updated: [MPLUGINTESTING-69] update plexus-utils (#17)

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-plugin-testing.git


The following commit(s) were added to refs/heads/master by this push:
     new 0766245  [MPLUGINTESTING-69] update plexus-utils (#17)
0766245 is described below

commit 0766245a8eb5626caff32ce958ccebee6e9d0042
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Mon Jun 15 14:07:11 2020 -0400

    [MPLUGINTESTING-69] update plexus-utils (#17)
    
    * update plexus-utils
    
    * fix AbstractMojoTestCase
    
    * close streams
---
 .../maven/plugin/testing/AbstractMojoTestCase.java | 65 +++++++++++-----------
 pom.xml                                            |  7 +--
 2 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java
index a64fd1c..7296c01 100644
--- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java
@@ -72,6 +72,7 @@ import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator
 import org.codehaus.plexus.component.repository.ComponentDescriptor;
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.context.Context;
 import org.codehaus.plexus.logging.LoggerManager;
 import org.codehaus.plexus.util.InterpolationFilterReader;
 import org.codehaus.plexus.util.ReaderFactory;
@@ -144,34 +145,35 @@ public abstract class AbstractMojoTestCase
                     MAVEN_VERSION == null || new DefaultArtifactVersion( "3.2.3" ).compareTo( MAVEN_VERSION ) < 0 );
 
         configurator = getContainer().lookup( ComponentConfigurator.class, "basic" );
+        Context context = container.getContext();
+        Map<Object, Object> map = context.getContextData();
 
-        InputStream is = getClass().getResourceAsStream( "/" + getPluginDescriptorLocation() );
-
-        XmlStreamReader reader = new XmlStreamReader( is );
-
-        InterpolationFilterReader interpolationFilterReader =
-            new InterpolationFilterReader( new BufferedReader( reader ), container.getContext().getContextData() );
-
-        PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build( interpolationFilterReader );
-
-        Artifact artifact =
-            lookup( RepositorySystem.class ).createArtifact( pluginDescriptor.getGroupId(),
-                                                             pluginDescriptor.getArtifactId(),
-                                                             pluginDescriptor.getVersion(), ".jar" );
-
-        artifact.setFile( getPluginArtifactFile() );
-        pluginDescriptor.setPluginArtifact( artifact );
-        pluginDescriptor.setArtifacts( Arrays.asList( artifact ) );
-
-        for ( ComponentDescriptor<?> desc : pluginDescriptor.getComponents() )
+        try ( InputStream is = getClass().getResourceAsStream( "/" + getPluginDescriptorLocation() );
+              Reader reader = new BufferedReader( new XmlStreamReader( is ) ); 
+              InterpolationFilterReader interpolationReader = new InterpolationFilterReader( reader, map, "${", "}" ) )
         {
-            getContainer().addComponentDescriptor( desc );
-        }
-
-        mojoDescriptors = new HashMap<>();
-        for ( MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos() )
-        {
-            mojoDescriptors.put( mojoDescriptor.getGoal(), mojoDescriptor );
+            
+            PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build( interpolationReader );
+    
+            Artifact artifact =
+                lookup( RepositorySystem.class ).createArtifact( pluginDescriptor.getGroupId(),
+                                                                 pluginDescriptor.getArtifactId(),
+                                                                 pluginDescriptor.getVersion(), ".jar" );
+    
+            artifact.setFile( getPluginArtifactFile() );
+            pluginDescriptor.setPluginArtifact( artifact );
+            pluginDescriptor.setArtifacts( Arrays.asList( artifact ) );
+    
+            for ( ComponentDescriptor<?> desc : pluginDescriptor.getComponents() )
+            {
+                getContainer().addComponentDescriptor( desc );
+            }
+    
+            mojoDescriptors = new HashMap<>();
+            for ( MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos() )
+            {
+                mojoDescriptors.put( mojoDescriptor.getGoal(), mojoDescriptor );
+            }
         }
     }
 
@@ -573,11 +575,12 @@ public abstract class AbstractMojoTestCase
     protected PlexusConfiguration extractPluginConfiguration( String artifactId, File pom )
         throws Exception
     {
-        Reader reader = ReaderFactory.newXmlReader( pom );
-
-        Xpp3Dom pomDom = Xpp3DomBuilder.build( reader );
-
-        return extractPluginConfiguration( artifactId, pomDom );
+        
+        try ( Reader reader = ReaderFactory.newXmlReader( pom ) )
+        {
+            Xpp3Dom pomDom = Xpp3DomBuilder.build( reader );
+            return extractPluginConfiguration( artifactId, pomDom );
+        }
     }
 
     /**
diff --git a/pom.xml b/pom.xml
index b89888b..67ad7c1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -178,8 +178,7 @@ under the License.
       <dependency>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-utils</artifactId>
-        <version>3.0.15</version>
-        <scope>provided</scope>
+        <version>3.3.0</version>
       </dependency>    
     
       <dependency>
@@ -192,16 +191,12 @@ under the License.
   </dependencyManagement>
 
   <dependencies>
-  
-    <!-- misc -->
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
     </dependency>
-    
   </dependencies>
   
-  
   <build>
     <pluginManagement>
       <plugins>