From e386152805ebadd8b22e933e20cdb6f15eec6fd7 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Mon, 15 Jun 2020 12:23:58 -0400 Subject: [PATCH 1/3] update plexus-utils --- pom.xml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index b89888b..bbe83d4 100644 --- a/pom.xml +++ b/pom.xml @@ -178,7 +178,7 @@ under the License. org.codehaus.plexus plexus-utils - 3.0.15 + 3.3.0 provided @@ -192,16 +192,12 @@ under the License. - - junit junit - - From 98faf30d54234caa3fa9716f906105cd96d7c5dd Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Mon, 15 Jun 2020 12:58:16 -0400 Subject: [PATCH 2/3] fix AbstractMojoTestCase --- .../maven/plugin/testing/AbstractMojoTestCase.java | 11 +++++------ pom.xml | 1 - 2 files changed, 5 insertions(+), 7 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..1eb129b 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.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; @@ -146,12 +147,10 @@ protected void setUp() configurator = getContainer().lookup( ComponentConfigurator.class, "basic" ); InputStream is = getClass().getResourceAsStream( "/" + getPluginDescriptorLocation() ); - - XmlStreamReader reader = new XmlStreamReader( is ); - - InterpolationFilterReader interpolationFilterReader = - new InterpolationFilterReader( new BufferedReader( reader ), container.getContext().getContextData() ); - + Reader reader = new BufferedReader( new XmlStreamReader( is ) ); + Context context = container.getContext(); + Map map = context.getContextData(); + InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( reader, map, "${", "}" ); PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build( interpolationFilterReader ); Artifact artifact = diff --git a/pom.xml b/pom.xml index bbe83d4..67ad7c1 100644 --- a/pom.xml +++ b/pom.xml @@ -179,7 +179,6 @@ under the License. org.codehaus.plexus plexus-utils 3.3.0 - provided From 83dfb1d2dd3a45d1989ef57aaaf4c39cb4926702 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Mon, 15 Jun 2020 13:07:06 -0400 Subject: [PATCH 3/3] close streams --- .../plugin/testing/AbstractMojoTestCase.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 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 1eb129b..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 @@ -145,32 +145,35 @@ protected void setUp() MAVEN_VERSION == null || new DefaultArtifactVersion( "3.2.3" ).compareTo( MAVEN_VERSION ) < 0 ); configurator = getContainer().lookup( ComponentConfigurator.class, "basic" ); - - InputStream is = getClass().getResourceAsStream( "/" + getPluginDescriptorLocation() ); - Reader reader = new BufferedReader( new XmlStreamReader( is ) ); Context context = container.getContext(); Map map = context.getContextData(); - InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( reader, map, "${", "}" ); - 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() ) - { - getContainer().addComponentDescriptor( desc ); - } - mojoDescriptors = new HashMap<>(); - for ( MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos() ) + try ( InputStream is = getClass().getResourceAsStream( "/" + getPluginDescriptorLocation() ); + Reader reader = new BufferedReader( new XmlStreamReader( is ) ); + InterpolationFilterReader interpolationReader = new InterpolationFilterReader( reader, map, "${", "}" ) ) { - 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 ); + } } } @@ -572,11 +575,12 @@ private void finalizeMojoConfiguration( MojoExecution mojoExecution ) 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 ); + } } /**