added generics
git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1341185 13f79535-47bb-0310-9956-ffa450edef68master
parent
88a6f9df83
commit
aa718c105f
|
|
@ -50,17 +50,15 @@ import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public class AntMojoWrapper
|
public class AntMojoWrapper
|
||||||
extends AbstractMojo
|
extends AbstractMojo
|
||||||
implements ContextEnabled, MapOrientedComponent, LogEnabled
|
implements ContextEnabled, MapOrientedComponent, LogEnabled
|
||||||
{
|
{
|
||||||
|
|
||||||
private Map pluginContext;
|
private Map<String, Object> pluginContext;
|
||||||
|
|
||||||
private final AntScriptInvoker scriptInvoker;
|
private final AntScriptInvoker scriptInvoker;
|
||||||
|
|
||||||
|
|
@ -76,7 +74,7 @@ public class AntMojoWrapper
|
||||||
|
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
private transient List unconstructedParts = new ArrayList();
|
private transient List<String> unconstructedParts = new ArrayList<String>();
|
||||||
|
|
||||||
public AntMojoWrapper( AntScriptInvoker scriptInvoker )
|
public AntMojoWrapper( AntScriptInvoker scriptInvoker )
|
||||||
{
|
{
|
||||||
|
|
@ -91,24 +89,23 @@ public class AntMojoWrapper
|
||||||
antProject = scriptInvoker.getProject();
|
antProject = scriptInvoker.getProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map allConfig = new HashMap();
|
Map<String, Object> allConfig = new HashMap<String, Object>();
|
||||||
if ( pluginContext != null && !pluginContext.isEmpty() )
|
if ( pluginContext != null && !pluginContext.isEmpty() )
|
||||||
{
|
{
|
||||||
allConfig.putAll( pluginContext );
|
allConfig.putAll( pluginContext );
|
||||||
}
|
}
|
||||||
|
|
||||||
Map refs = scriptInvoker.getReferences();
|
@SuppressWarnings( "unchecked" )
|
||||||
|
Map<String, PathTranslator> refs = scriptInvoker.getReferences();
|
||||||
if ( refs != null )
|
if ( refs != null )
|
||||||
{
|
{
|
||||||
allConfig.putAll( refs );
|
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();
|
if ( entry.getKey().startsWith( PathTranslator.class.getName() ) )
|
||||||
String key = (String) entry.getKey();
|
|
||||||
if ( key.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" );
|
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 );
|
buffer.append( "\n- " ).append( part );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,18 +229,22 @@ public class AntMojoWrapper
|
||||||
unconstructedParts.add( "Maven parameter expression evaluator for Ant properties." );
|
unconstructedParts.add( "Maven parameter expression evaluator for Ant properties." );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( "unchecked" )
|
||||||
|
Map<String, Object> references = scriptInvoker.getReferences();
|
||||||
|
|
||||||
if ( mavenProject != null )
|
if ( mavenProject != null )
|
||||||
{
|
{
|
||||||
|
|
||||||
// Compile classpath
|
// Compile classpath
|
||||||
Path p = new Path( antProject );
|
Path p = new Path( antProject );
|
||||||
|
|
||||||
p.setPath( StringUtils.join( mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator ) );
|
p.setPath( StringUtils.join( mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator ) );
|
||||||
|
|
||||||
/* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */
|
/* 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 );
|
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 );
|
antProject.addReference( "maven.compile.classpath", p );
|
||||||
|
|
||||||
// Runtime classpath
|
// Runtime classpath
|
||||||
|
|
@ -252,7 +252,7 @@ public class AntMojoWrapper
|
||||||
|
|
||||||
p.setPath( StringUtils.join( mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator ) );
|
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 );
|
antProject.addReference( "maven.runtime.classpath", p );
|
||||||
|
|
||||||
// Test classpath
|
// Test classpath
|
||||||
|
|
@ -260,7 +260,7 @@ public class AntMojoWrapper
|
||||||
|
|
||||||
p.setPath( StringUtils.join( mavenProject.getTestClasspathElements().iterator(), File.pathSeparator ) );
|
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 );
|
antProject.addReference( "maven.test.classpath", p );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -275,7 +275,7 @@ public class AntMojoWrapper
|
||||||
|
|
||||||
Path p = getPathFromArtifacts( mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifacts(), antProject );
|
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 );
|
antProject.addReference( "maven.plugin.classpath", p );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -289,16 +289,13 @@ public class AntMojoWrapper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Path getPathFromArtifacts( Collection artifacts,
|
public Path getPathFromArtifacts( Collection<Artifact> artifacts, Project antProject )
|
||||||
Project antProject )
|
|
||||||
throws DependencyResolutionRequiredException
|
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();
|
File file = a.getFile();
|
||||||
|
|
||||||
if ( file == null )
|
if ( file == null )
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,7 @@ package org.apache.maven.script.ant;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Hashtable;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
@ -46,7 +45,7 @@ public class AntPropertyHelper
|
||||||
private Log log;
|
private Log log;
|
||||||
private ExpressionEvaluator exprEvaluator;
|
private ExpressionEvaluator exprEvaluator;
|
||||||
private MavenProject mavenProject;
|
private MavenProject mavenProject;
|
||||||
private Map artifactMap = new Hashtable();
|
private Map<String, String> artifactMap = new HashMap<String, String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use the other constructor
|
* @deprecated use the other constructor
|
||||||
|
|
@ -66,7 +65,7 @@ public class AntPropertyHelper
|
||||||
*/
|
*/
|
||||||
public AntPropertyHelper( ExpressionEvaluator exprEvaluator, Log l )
|
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 artifacts
|
||||||
* @param l
|
* @param l
|
||||||
*/
|
*/
|
||||||
public AntPropertyHelper( ExpressionEvaluator exprEvaluator, Set artifacts, Log l )
|
public AntPropertyHelper( ExpressionEvaluator exprEvaluator, Set<Artifact> artifacts, Log l )
|
||||||
{
|
{
|
||||||
this.mavenProject = null;
|
this.mavenProject = null;
|
||||||
this.exprEvaluator = exprEvaluator;
|
this.exprEvaluator = exprEvaluator;
|
||||||
this.log = l;
|
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()
|
String key = DEPENDENCY_PREFIX + artifact.getGroupId() + "." + artifact.getArtifactId()
|
||||||
+ ( artifact.getClassifier() != null ? "." + artifact.getClassifier() : "" )
|
+ ( artifact.getClassifier() != null ? "." + artifact.getClassifier() : "" )
|
||||||
+ ( artifact.getType() != null ? "." + artifact.getType() : "" ) + ".path";
|
+ ( artifact.getType() != null ? "." + artifact.getType() : "" ) + ".path";
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ 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.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -52,7 +51,7 @@ public class AntMojoWrapperTest
|
||||||
{
|
{
|
||||||
String pluginXml = "META-INF/maven/plugin-2.1.xml";
|
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, "Unpacked Ant build scripts (in Maven build directory).", false );
|
||||||
assertPresence( messages, "Maven parameter expression evaluator for Ant properties.", 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";
|
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, "Unpacked Ant build scripts (in Maven build directory).", true );
|
||||||
assertPresence( messages, "Maven parameter expression evaluator for Ant properties.", true );
|
assertPresence( messages, "Maven parameter expression evaluator for Ant properties.", true );
|
||||||
|
|
@ -85,31 +84,27 @@ public class AntMojoWrapperTest
|
||||||
assertPresence( messages, "path-is-missing", true );
|
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 ( String message : messages )
|
||||||
|
|
||||||
for ( Iterator it = messages.iterator(); it.hasNext(); )
|
|
||||||
{
|
{
|
||||||
String message = (String) it.next();
|
if ( message.contains( test ) )
|
||||||
if ( message.indexOf( test ) > -1 )
|
|
||||||
{
|
{
|
||||||
found = true;
|
if ( !shouldBePresent )
|
||||||
break;
|
{
|
||||||
|
fail( "Test string: '" + test + "' was found in output, but SHOULD NOT BE THERE." );
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !shouldBePresent && found )
|
if ( shouldBePresent )
|
||||||
{
|
|
||||||
fail( "Test string: '" + test + "' was found in output, but SHOULD NOT BE THERE." );
|
|
||||||
}
|
|
||||||
else if ( shouldBePresent && !found )
|
|
||||||
{
|
{
|
||||||
fail( "Test string: '" + test + "' was NOT found in output, but SHOULD BE THERE." );
|
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,
|
throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException,
|
||||||
ComponentConfigurationException, ArchiverException
|
ComponentConfigurationException, ArchiverException
|
||||||
{
|
{
|
||||||
|
|
@ -135,7 +130,7 @@ public class AntMojoWrapperTest
|
||||||
IOUtil.close( reader );
|
IOUtil.close( reader );
|
||||||
}
|
}
|
||||||
|
|
||||||
Map config = new HashMap();
|
Map<String, Object> config = new HashMap<String, Object>();
|
||||||
config.put( "basedir", new File( "." ).getAbsoluteFile() );
|
config.put( "basedir", new File( "." ).getAbsoluteFile() );
|
||||||
config.put( "messageLevel", "info" );
|
config.put( "messageLevel", "info" );
|
||||||
|
|
||||||
|
|
@ -238,7 +233,7 @@ public class AntMojoWrapperTest
|
||||||
pathTranslatorCtl.verify();
|
pathTranslatorCtl.verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
List messages = new ArrayList();
|
List<String> messages = new ArrayList<String>();
|
||||||
if ( !tbl.messages.isEmpty() )
|
if ( !tbl.messages.isEmpty() )
|
||||||
{
|
{
|
||||||
messages.addAll( tbl.messages );
|
messages.addAll( tbl.messages );
|
||||||
|
|
@ -252,7 +247,7 @@ public class AntMojoWrapperTest
|
||||||
private static final class TestBuildListener
|
private static final class TestBuildListener
|
||||||
implements BuildListener
|
implements BuildListener
|
||||||
{
|
{
|
||||||
private List messages = new ArrayList();
|
private List<String> messages = new ArrayList<String>();
|
||||||
|
|
||||||
public void buildFinished( BuildEvent arg0 )
|
public void buildFinished( BuildEvent arg0 )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue