You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sc...@apache.org on 2017/02/25 04:12:14 UTC

svn commit: r1784345 - in /maven/plugin-tools/trunk/maven-script: maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/ maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/ maven-script-ant/s...

Author: schulte
Date: Sat Feb 25 04:12:14 2017
New Revision: 1784345

URL: http://svn.apache.org/viewvc?rev=1784345&view=rev
Log:
o Updated to make the test work when checking out into a directory like "/tmp/Spaces & Special Char/plugin-tools".


Modified:
    maven/plugin-tools/trunk/maven-script/maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractorTest.java
    maven/plugin-tools/trunk/maven-script/maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParserTest.java
    maven/plugin-tools/trunk/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java

Modified: maven/plugin-tools/trunk/maven-script/maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractorTest.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-script/maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractorTest.java?rev=1784345&r1=1784344&r2=1784345&view=diff
==============================================================================
--- maven/plugin-tools/trunk/maven-script/maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractorTest.java (original)
+++ maven/plugin-tools/trunk/maven-script/maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractorTest.java Sat Feb 25 04:12:14 2017
@@ -19,6 +19,16 @@ package org.apache.maven.tools.plugin.ex
  * 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.Def
 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 AntMojoDescriptorExtractorT
             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
 
 }

Modified: maven/plugin-tools/trunk/maven-script/maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParserTest.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-script/maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParserTest.java?rev=1784345&r1=1784344&r2=1784345&view=diff
==============================================================================
--- maven/plugin-tools/trunk/maven-script/maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParserTest.java (original)
+++ maven/plugin-tools/trunk/maven-script/maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParserTest.java Sat Feb 25 04:12:14 2017
@@ -19,16 +19,12 @@ package org.apache.maven.tools.plugin.ex
  * 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", " " ) );
     }
 
 }

Modified: maven/plugin-tools/trunk/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java?rev=1784345&r1=1784344&r2=1784345&view=diff
==============================================================================
--- maven/plugin-tools/trunk/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java (original)
+++ maven/plugin-tools/trunk/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java Sat Feb 25 04:12:14 2017
@@ -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
 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<String> 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();