diff --git a/maven-script/maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractorTest.java b/maven-script/maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractorTest.java index 002dda2..70c7820 100644 --- a/maven-script/maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractorTest.java +++ b/maven-script/maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractorTest.java @@ -19,6 +19,16 @@ package org.apache.maven.tools.plugin.extractor.ant; * under the License. */ +import java.io.File; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import junit.framework.TestCase; import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.Parameter; @@ -29,18 +39,6 @@ import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; import org.apache.maven.tools.plugin.PluginToolsRequest; import org.apache.maven.tools.plugin.extractor.ExtractionException; import org.codehaus.plexus.component.repository.ComponentRequirement; -import org.codehaus.plexus.util.StringUtils; - -import java.io.File; -import java.net.URL; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import junit.framework.TestCase; public class AntMojoDescriptorExtractorTest extends TestCase @@ -100,39 +98,47 @@ public class AntMojoDescriptorExtractorTest assertEquals( "Mojo descriptor: " + desc.getGoal() + " is missing 'PathTranslator' component requirement.", PathTranslator.class.getName(), req.getRole() ); } } - + private Map buildTestMap( String resourceDirName ) { - Map result = new HashMap(); - - ClassLoader cloader = Thread.currentThread().getContextClassLoader(); - URL mojosXmlUrl = cloader.getResource( resourceDirName + "/test.mojos.xml" ); - - if ( mojosXmlUrl == null ) + try { - fail( "No classpath resource named: '" + resourceDirName + "/test.mojos.xml' could be found." ); - } - - File mojosXml = new File( StringUtils.replace( mojosXmlUrl.getPath(), "%20", " " ) ); - File dir = mojosXml.getParentFile(); - - Set scripts = new HashSet(); - String[] listing = dir.list(); - for ( int i = 0; listing != null && i < listing.length; i++ ) - { - if ( listing[i].endsWith( ".mojos.xml" ) ) + Map result = new HashMap(); + + ClassLoader cloader = Thread.currentThread().getContextClassLoader(); + URL mojosXmlUrl = cloader.getResource( resourceDirName + "/test.mojos.xml" ); + + if ( mojosXmlUrl == null ) { - File f = new File( dir, listing[i] ).getAbsoluteFile(); - - scripts.add( f ); + fail( "No classpath resource named: '" + resourceDirName + "/test.mojos.xml' could be found." ); } + + // TODO As of JDK 7, replace with Paths.get( resource.toURI() ).toFile() + File mojosXml = new File( mojosXmlUrl.toURI() ); + File dir = mojosXml.getParentFile(); + + Set scripts = new HashSet(); + String[] listing = dir.list(); + for ( int i = 0; listing != null && i < listing.length; i++ ) + { + if ( listing[i].endsWith( ".mojos.xml" ) ) + { + File f = new File( dir, listing[i] ).getAbsoluteFile(); + + scripts.add( f ); + } + } + + result.put( dir.getAbsolutePath(), scripts ); + + return result; + } + catch ( final URISyntaxException e ) + { + throw new AssertionError( e ); } - - result.put( dir.getAbsolutePath(), scripts ); - - return result; } - + // TODO } diff --git a/maven-script/maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParserTest.java b/maven-script/maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParserTest.java index d1233e6..944d7d4 100644 --- a/maven-script/maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParserTest.java +++ b/maven-script/maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParserTest.java @@ -19,16 +19,12 @@ package org.apache.maven.tools.plugin.extractor.model; * under the License. */ -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.tools.plugin.extractor.model.PluginMetadataParseException; -import org.apache.maven.tools.plugin.extractor.model.PluginMetadataParser; -import org.codehaus.plexus.util.StringUtils; - import java.io.File; +import java.net.URISyntaxException; import java.net.URL; import java.util.Set; - import junit.framework.TestCase; +import org.apache.maven.plugin.descriptor.MojoDescriptor; public class PluginMetadataParserTest extends TestCase @@ -59,16 +55,24 @@ public class PluginMetadataParserTest assertTrue( desc.getImplementation().endsWith( ":test2" ) ); assertEquals( "test2", desc.getGoal() ); } - + private File getMetadataFile( String name ) { - URL resource = Thread.currentThread().getContextClassLoader().getResource( name ); - if ( resource == null ) + try { - fail( "Cannot find classpath resource: '" + name + "'." ); + URL resource = Thread.currentThread().getContextClassLoader().getResource( name ); + if ( resource == null ) + { + fail( "Cannot find classpath resource: '" + name + "'." ); + } + + // TODO As of JDK 7, replace with Paths.get( resource.toURI() ).toFile() + return new File( resource.toURI() ); + } + catch ( final URISyntaxException e ) + { + throw new AssertionError( e ); } - - return new File( StringUtils.replace( resource.getPath(), "%20", " " ) ); } } diff --git a/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java b/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java index c4836ed..76c7909 100644 --- a/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java +++ b/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java @@ -18,10 +18,6 @@ package org.apache.maven.script.ant; * specific language governing permissions and limitations * under the License. */ -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import java.io.ByteArrayOutputStream; import java.io.File; @@ -29,13 +25,14 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.Reader; +import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; - +import junit.framework.TestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Build; @@ -59,9 +56,10 @@ import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.console.ConsoleLogger; import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.StringUtils; - -import junit.framework.TestCase; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; public class AntMojoWrapperTest extends TestCase @@ -69,7 +67,7 @@ public class AntMojoWrapperTest public void test2xStylePlugin() throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException, - ComponentConfigurationException, ArchiverException + ComponentConfigurationException, ArchiverException, URISyntaxException { String pluginXml = "META-INF/maven/plugin-2.1.xml"; @@ -89,7 +87,7 @@ public class AntMojoWrapperTest public void test20StylePlugin() throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException, - ComponentConfigurationException, ArchiverException + ComponentConfigurationException, ArchiverException, URISyntaxException { String pluginXml = "META-INF/maven/plugin-2.0.xml"; @@ -128,7 +126,7 @@ public class AntMojoWrapperTest private List run( String pluginXml, boolean includeImplied ) throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException, - ComponentConfigurationException, ArchiverException + ComponentConfigurationException, ArchiverException, URISyntaxException { StackTraceElement stack = new Throwable().getStackTrace()[1]; System.out.println( "\n\nRunning: " + stack.getMethodName() + "\n\n" ); @@ -146,6 +144,8 @@ public class AntMojoWrapperTest { reader = new InputStreamReader( resource.openStream() ); pd = new PluginDescriptorBuilder().build( reader, pluginXml ); + reader.close(); + reader = null; } finally { @@ -168,7 +168,8 @@ public class AntMojoWrapperTest if ( includeImplied ) { - File pluginXmlFile = new File( StringUtils.replace( resource.getPath(), "%20", " " ) ); + // TODO As of JDK 7, replace with Paths.get( resource.toURI() ).toFile() + File pluginXmlFile = new File( resource.toURI() ); File jarFile = File.createTempFile( "AntMojoWrapperTest.", ".test.jar" ); jarFile.deleteOnExit();