o Updated to make the test work when checking out into a directory like "/tmp/Spaces & Special Char/plugin-tools".
git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1784345 13f79535-47bb-0310-9956-ffa450edef68master
parent
04684f0fc3
commit
d484f85160
|
|
@ -19,6 +19,16 @@ package org.apache.maven.tools.plugin.extractor.ant;
|
||||||
* under the License.
|
* 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.InvalidPluginDescriptorException;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
import org.apache.maven.plugin.descriptor.Parameter;
|
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.PluginToolsRequest;
|
||||||
import org.apache.maven.tools.plugin.extractor.ExtractionException;
|
import org.apache.maven.tools.plugin.extractor.ExtractionException;
|
||||||
import org.codehaus.plexus.component.repository.ComponentRequirement;
|
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
|
public class AntMojoDescriptorExtractorTest
|
||||||
extends TestCase
|
extends TestCase
|
||||||
|
|
@ -100,39 +98,47 @@ public class AntMojoDescriptorExtractorTest
|
||||||
assertEquals( "Mojo descriptor: " + desc.getGoal() + " is missing 'PathTranslator' component requirement.", PathTranslator.class.getName(), req.getRole() );
|
assertEquals( "Mojo descriptor: " + desc.getGoal() + " is missing 'PathTranslator' component requirement.", PathTranslator.class.getName(), req.getRole() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map buildTestMap( String resourceDirName )
|
private Map buildTestMap( String resourceDirName )
|
||||||
{
|
{
|
||||||
Map result = new HashMap();
|
try
|
||||||
|
|
||||||
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
|
|
||||||
URL mojosXmlUrl = cloader.getResource( resourceDirName + "/test.mojos.xml" );
|
|
||||||
|
|
||||||
if ( mojosXmlUrl == null )
|
|
||||||
{
|
{
|
||||||
fail( "No classpath resource named: '" + resourceDirName + "/test.mojos.xml' could be found." );
|
Map result = new HashMap();
|
||||||
}
|
|
||||||
|
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
|
||||||
File mojosXml = new File( StringUtils.replace( mojosXmlUrl.getPath(), "%20", " " ) );
|
URL mojosXmlUrl = cloader.getResource( resourceDirName + "/test.mojos.xml" );
|
||||||
File dir = mojosXml.getParentFile();
|
|
||||||
|
if ( mojosXmlUrl == null )
|
||||||
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();
|
fail( "No classpath resource named: '" + resourceDirName + "/test.mojos.xml' could be found." );
|
||||||
|
|
||||||
scripts.add( f );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// TODO
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,12 @@ package org.apache.maven.tools.plugin.extractor.model;
|
||||||
* under the License.
|
* 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.io.File;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
|
|
||||||
public class PluginMetadataParserTest
|
public class PluginMetadataParserTest
|
||||||
extends TestCase
|
extends TestCase
|
||||||
|
|
@ -59,16 +55,24 @@ public class PluginMetadataParserTest
|
||||||
assertTrue( desc.getImplementation().endsWith( ":test2" ) );
|
assertTrue( desc.getImplementation().endsWith( ":test2" ) );
|
||||||
assertEquals( "test2", desc.getGoal() );
|
assertEquals( "test2", desc.getGoal() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getMetadataFile( String name )
|
private File getMetadataFile( String name )
|
||||||
{
|
{
|
||||||
URL resource = Thread.currentThread().getContextClassLoader().getResource( name );
|
try
|
||||||
if ( resource == null )
|
|
||||||
{
|
{
|
||||||
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", " " ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,6 @@ package org.apache.maven.script.ant;
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* 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.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
@ -29,13 +25,14 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import junit.framework.TestCase;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Build;
|
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.Logger;
|
||||||
import org.codehaus.plexus.logging.console.ConsoleLogger;
|
import org.codehaus.plexus.logging.console.ConsoleLogger;
|
||||||
import org.codehaus.plexus.util.IOUtil;
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import static org.easymock.EasyMock.createMock;
|
||||||
|
import static org.easymock.EasyMock.expect;
|
||||||
import junit.framework.TestCase;
|
import static org.easymock.EasyMock.replay;
|
||||||
|
import static org.easymock.EasyMock.verify;
|
||||||
|
|
||||||
public class AntMojoWrapperTest
|
public class AntMojoWrapperTest
|
||||||
extends TestCase
|
extends TestCase
|
||||||
|
|
@ -69,7 +67,7 @@ public class AntMojoWrapperTest
|
||||||
|
|
||||||
public void test2xStylePlugin()
|
public void test2xStylePlugin()
|
||||||
throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException,
|
throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException,
|
||||||
ComponentConfigurationException, ArchiverException
|
ComponentConfigurationException, ArchiverException, URISyntaxException
|
||||||
{
|
{
|
||||||
String pluginXml = "META-INF/maven/plugin-2.1.xml";
|
String pluginXml = "META-INF/maven/plugin-2.1.xml";
|
||||||
|
|
||||||
|
|
@ -89,7 +87,7 @@ public class AntMojoWrapperTest
|
||||||
|
|
||||||
public void test20StylePlugin()
|
public void test20StylePlugin()
|
||||||
throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException,
|
throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException,
|
||||||
ComponentConfigurationException, ArchiverException
|
ComponentConfigurationException, ArchiverException, URISyntaxException
|
||||||
{
|
{
|
||||||
String pluginXml = "META-INF/maven/plugin-2.0.xml";
|
String pluginXml = "META-INF/maven/plugin-2.0.xml";
|
||||||
|
|
||||||
|
|
@ -128,7 +126,7 @@ public class AntMojoWrapperTest
|
||||||
|
|
||||||
private List<String> run( String pluginXml, boolean includeImplied )
|
private List<String> run( String pluginXml, boolean includeImplied )
|
||||||
throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException,
|
throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException,
|
||||||
ComponentConfigurationException, ArchiverException
|
ComponentConfigurationException, ArchiverException, URISyntaxException
|
||||||
{
|
{
|
||||||
StackTraceElement stack = new Throwable().getStackTrace()[1];
|
StackTraceElement stack = new Throwable().getStackTrace()[1];
|
||||||
System.out.println( "\n\nRunning: " + stack.getMethodName() + "\n\n" );
|
System.out.println( "\n\nRunning: " + stack.getMethodName() + "\n\n" );
|
||||||
|
|
@ -146,6 +144,8 @@ public class AntMojoWrapperTest
|
||||||
{
|
{
|
||||||
reader = new InputStreamReader( resource.openStream() );
|
reader = new InputStreamReader( resource.openStream() );
|
||||||
pd = new PluginDescriptorBuilder().build( reader, pluginXml );
|
pd = new PluginDescriptorBuilder().build( reader, pluginXml );
|
||||||
|
reader.close();
|
||||||
|
reader = null;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
@ -168,7 +168,8 @@ public class AntMojoWrapperTest
|
||||||
|
|
||||||
if ( includeImplied )
|
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" );
|
File jarFile = File.createTempFile( "AntMojoWrapperTest.", ".test.jar" );
|
||||||
jarFile.deleteOnExit();
|
jarFile.deleteOnExit();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue