added generics

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1341185 13f79535-47bb-0310-9956-ffa450edef68
master
Herve Boutemy 2012-05-21 20:10:04 +00:00
parent 88a6f9df83
commit aa718c105f
3 changed files with 41 additions and 52 deletions

View File

@ -50,17 +50,15 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class AntMojoWrapper
extends AbstractMojo
implements ContextEnabled, MapOrientedComponent, LogEnabled
{
private Map pluginContext;
private Map<String, Object> pluginContext;
private final AntScriptInvoker scriptInvoker;
@ -76,7 +74,7 @@ public class AntMojoWrapper
private Logger logger;
private transient List unconstructedParts = new ArrayList();
private transient List<String> unconstructedParts = new ArrayList<String>();
public AntMojoWrapper( AntScriptInvoker scriptInvoker )
{
@ -91,24 +89,23 @@ public class AntMojoWrapper
antProject = scriptInvoker.getProject();
}
Map allConfig = new HashMap();
Map<String, Object> allConfig = new HashMap<String, Object>();
if ( pluginContext != null && !pluginContext.isEmpty() )
{
allConfig.putAll( pluginContext );
}
Map refs = scriptInvoker.getReferences();
@SuppressWarnings( "unchecked" )
Map<String, PathTranslator> refs = scriptInvoker.getReferences();
if ( refs != null )
{
allConfig.putAll( refs );
for ( Iterator it = refs.entrySet().iterator(); it.hasNext(); )
for ( Map.Entry<String, PathTranslator> entry : refs.entrySet() )
{
Map.Entry entry = (Map.Entry) it.next();
String key = (String) entry.getKey();
if ( key.startsWith( PathTranslator.class.getName() ) )
if ( entry.getKey().startsWith( PathTranslator.class.getName() ) )
{
pathTranslator = (PathTranslator) entry.getValue();
pathTranslator = entry.getValue();
}
}
}
@ -129,9 +126,8 @@ public class AntMojoWrapper
buffer.append( "The following standard Maven Ant-mojo support objects could not be created:\n\n" );
for ( Iterator it = unconstructedParts.iterator(); it.hasNext(); )
for ( String part : unconstructedParts )
{
String part = (String) it.next();
buffer.append( "\n- " ).append( part );
}
@ -233,18 +229,22 @@ public class AntMojoWrapper
unconstructedParts.add( "Maven parameter expression evaluator for Ant properties." );
}
@SuppressWarnings( "unchecked" )
Map<String, Object> references = scriptInvoker.getReferences();
if ( mavenProject != null )
{
// Compile classpath
Path p = new Path( antProject );
p.setPath( StringUtils.join( mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator ) );
/* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */
scriptInvoker.getReferences().put( "maven.dependency.classpath", p );
references.put( "maven.dependency.classpath", p );
antProject.addReference( "maven.dependency.classpath", p );
scriptInvoker.getReferences().put( "maven.compile.classpath", p );
references.put( "maven.compile.classpath", p );
antProject.addReference( "maven.compile.classpath", p );
// Runtime classpath
@ -252,7 +252,7 @@ public class AntMojoWrapper
p.setPath( StringUtils.join( mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator ) );
scriptInvoker.getReferences().put( "maven.runtime.classpath", p );
references.put( "maven.runtime.classpath", p );
antProject.addReference( "maven.runtime.classpath", p );
// Test classpath
@ -260,7 +260,7 @@ public class AntMojoWrapper
p.setPath( StringUtils.join( mavenProject.getTestClasspathElements().iterator(), File.pathSeparator ) );
scriptInvoker.getReferences().put( "maven.test.classpath", p );
references.put( "maven.test.classpath", p );
antProject.addReference( "maven.test.classpath", p );
}
@ -275,7 +275,7 @@ public class AntMojoWrapper
Path p = getPathFromArtifacts( mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifacts(), antProject );
scriptInvoker.getReferences().put( "maven.plugin.classpath", p );
references.put( "maven.plugin.classpath", p );
antProject.addReference( "maven.plugin.classpath", p );
}
else
@ -289,16 +289,13 @@ public class AntMojoWrapper
}
}
public Path getPathFromArtifacts( Collection artifacts,
Project antProject )
public Path getPathFromArtifacts( Collection<Artifact> artifacts, Project antProject )
throws DependencyResolutionRequiredException
{
List list = new ArrayList( artifacts.size() );
List<String> list = new ArrayList<String>( artifacts.size() );
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
for ( Artifact a : artifacts )
{
Artifact a = (Artifact) i.next();
File file = a.getFile();
if ( file == null )

View File

@ -21,8 +21,7 @@ package org.apache.maven.script.ant;
import java.io.File;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@ -46,7 +45,7 @@ public class AntPropertyHelper
private Log log;
private ExpressionEvaluator exprEvaluator;
private MavenProject mavenProject;
private Map artifactMap = new Hashtable();
private Map<String, String> artifactMap = new HashMap<String, String>();
/**
* @deprecated use the other constructor
@ -66,7 +65,7 @@ public class AntPropertyHelper
*/
public AntPropertyHelper( ExpressionEvaluator exprEvaluator, Log l )
{
this( exprEvaluator, Collections.EMPTY_SET, l );
this( exprEvaluator, Collections.<Artifact>emptySet(), l );
}
/**
@ -74,16 +73,14 @@ public class AntPropertyHelper
* @param artifacts
* @param l
*/
public AntPropertyHelper( ExpressionEvaluator exprEvaluator, Set artifacts, Log l )
public AntPropertyHelper( ExpressionEvaluator exprEvaluator, Set<Artifact> artifacts, Log l )
{
this.mavenProject = null;
this.exprEvaluator = exprEvaluator;
this.log = l;
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
for ( Artifact artifact : artifacts )
{
Artifact artifact = (Artifact) it.next();
String key = DEPENDENCY_PREFIX + artifact.getGroupId() + "." + artifact.getArtifactId()
+ ( artifact.getClassifier() != null ? "." + artifact.getClassifier() : "" )
+ ( artifact.getType() != null ? "." + artifact.getType() : "" ) + ".path";

View File

@ -36,7 +36,6 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -52,7 +51,7 @@ public class AntMojoWrapperTest
{
String pluginXml = "META-INF/maven/plugin-2.1.xml";
List messages = run( pluginXml, true );
List<String> messages = run( pluginXml, true );
assertPresence( messages, "Unpacked Ant build scripts (in Maven build directory).", false );
assertPresence( messages, "Maven parameter expression evaluator for Ant properties.", false );
@ -72,7 +71,7 @@ public class AntMojoWrapperTest
{
String pluginXml = "META-INF/maven/plugin-2.0.xml";
List messages = run( pluginXml, false );
List<String> messages = run( pluginXml, false );
assertPresence( messages, "Unpacked Ant build scripts (in Maven build directory).", true );
assertPresence( messages, "Maven parameter expression evaluator for Ant properties.", true );
@ -85,31 +84,27 @@ public class AntMojoWrapperTest
assertPresence( messages, "path-is-missing", true );
}
private void assertPresence( List messages, String test, boolean shouldBePresent )
private void assertPresence( List<String> messages, String test, boolean shouldBePresent )
{
boolean found = false;
for ( Iterator it = messages.iterator(); it.hasNext(); )
for ( String message : messages )
{
String message = (String) it.next();
if ( message.indexOf( test ) > -1 )
if ( message.contains( test ) )
{
found = true;
break;
if ( !shouldBePresent )
{
fail( "Test string: '" + test + "' was found in output, but SHOULD NOT BE THERE." );
}
return;
}
}
if ( !shouldBePresent && found )
{
fail( "Test string: '" + test + "' was found in output, but SHOULD NOT BE THERE." );
}
else if ( shouldBePresent && !found )
if ( shouldBePresent )
{
fail( "Test string: '" + test + "' was NOT found in output, but SHOULD BE THERE." );
}
}
private List run( String pluginXml, boolean includeImplied )
private List<String> run( String pluginXml, boolean includeImplied )
throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException,
ComponentConfigurationException, ArchiverException
{
@ -135,7 +130,7 @@ public class AntMojoWrapperTest
IOUtil.close( reader );
}
Map config = new HashMap();
Map<String, Object> config = new HashMap<String, Object>();
config.put( "basedir", new File( "." ).getAbsoluteFile() );
config.put( "messageLevel", "info" );
@ -238,7 +233,7 @@ public class AntMojoWrapperTest
pathTranslatorCtl.verify();
}
List messages = new ArrayList();
List<String> messages = new ArrayList<String>();
if ( !tbl.messages.isEmpty() )
{
messages.addAll( tbl.messages );
@ -252,7 +247,7 @@ public class AntMojoWrapperTest
private static final class TestBuildListener
implements BuildListener
{
private List messages = new ArrayList();
private List<String> messages = new ArrayList<String>();
public void buildFinished( BuildEvent arg0 )
{