o Logging works even better when the logger is not null
git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1406538 13f79535-47bb-0310-9956-ffa450edef68master
parent
805e0f84a7
commit
b66095855d
|
|
@ -19,15 +19,16 @@ package org.apache.maven.plugin.plugin;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
|
import org.apache.maven.plugins.annotations.Component;
|
||||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||||
import org.apache.maven.tools.plugin.generator.Generator;
|
import org.apache.maven.tools.plugin.generator.Generator;
|
||||||
import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator;
|
import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator;
|
||||||
|
import org.codehaus.plexus.logging.Logger;
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a plugin descriptor.
|
* Generate a plugin descriptor.
|
||||||
|
|
@ -61,19 +62,29 @@ public class DescriptorGeneratorMojo
|
||||||
@Parameter( defaultValue = "false" )
|
@Parameter( defaultValue = "false" )
|
||||||
private boolean skipDescriptor;
|
private boolean skipDescriptor;
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
@Component
|
||||||
|
protected Logger logger;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
protected File getOutputDirectory()
|
protected File getOutputDirectory()
|
||||||
{
|
{
|
||||||
return outputDirectory;
|
return outputDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
protected Generator createGenerator()
|
protected Generator createGenerator()
|
||||||
{
|
{
|
||||||
return new PluginDescriptorGenerator();
|
return new PluginDescriptorGenerator( logger );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
public void execute()
|
public void execute()
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -19,21 +19,6 @@ package org.apache.maven.tools.plugin.generator;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.plugin.descriptor.DuplicateMojoDescriptorException;
|
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
|
||||||
import org.apache.maven.plugin.descriptor.Parameter;
|
|
||||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
|
||||||
import org.apache.maven.plugin.descriptor.Requirement;
|
|
||||||
import org.apache.maven.project.MavenProject;
|
|
||||||
import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
|
|
||||||
import org.apache.maven.tools.plugin.PluginToolsRequest;
|
|
||||||
import org.apache.maven.tools.plugin.util.PluginUtils;
|
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
|
||||||
import org.codehaus.plexus.util.IOUtil;
|
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
|
||||||
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
|
|
||||||
import org.codehaus.plexus.util.xml.XMLWriter;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -46,6 +31,20 @@ import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import org.apache.maven.plugin.descriptor.DuplicateMojoDescriptorException;
|
||||||
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
|
import org.apache.maven.plugin.descriptor.Parameter;
|
||||||
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
|
import org.apache.maven.plugin.descriptor.Requirement;
|
||||||
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
|
||||||
|
import org.apache.maven.tools.plugin.PluginToolsRequest;
|
||||||
|
import org.apache.maven.tools.plugin.util.PluginUtils;
|
||||||
|
import org.codehaus.plexus.logging.Logger;
|
||||||
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
|
||||||
|
import org.codehaus.plexus.util.xml.XMLWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a <a href="/ref/current/maven-plugin-api/plugin.html">Maven Plugin Descriptor XML file</a> and
|
* Generate a <a href="/ref/current/maven-plugin-api/plugin.html">Maven Plugin Descriptor XML file</a> and
|
||||||
|
|
@ -57,10 +56,16 @@ import java.util.Set;
|
||||||
* get validation directives to help users in IDEs.
|
* get validation directives to help users in IDEs.
|
||||||
*/
|
*/
|
||||||
public class PluginDescriptorGenerator
|
public class PluginDescriptorGenerator
|
||||||
extends AbstractLogEnabled
|
|
||||||
implements Generator
|
implements Generator
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private final Logger log;
|
||||||
|
|
||||||
|
public PluginDescriptorGenerator( Logger log )
|
||||||
|
{
|
||||||
|
this.log = log;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -68,7 +73,7 @@ public class PluginDescriptorGenerator
|
||||||
throws GeneratorException
|
throws GeneratorException
|
||||||
{
|
{
|
||||||
// eventually rewrite help mojo class to match actual package name
|
// eventually rewrite help mojo class to match actual package name
|
||||||
PluginHelpGenerator.rewriteHelpMojo( request, getLogger() );
|
PluginHelpGenerator.rewriteHelpMojo( request, log );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -79,8 +84,7 @@ public class PluginDescriptorGenerator
|
||||||
// write plugin-help.xml help-descriptor
|
// write plugin-help.xml help-descriptor
|
||||||
MavenProject mavenProject = request.getProject();
|
MavenProject mavenProject = request.getProject();
|
||||||
|
|
||||||
f =
|
f = new File( mavenProject.getBuild().getOutputDirectory(),
|
||||||
new File( mavenProject.getBuild().getOutputDirectory(),
|
|
||||||
PluginHelpGenerator.getPluginHelpPath( mavenProject ) );
|
PluginHelpGenerator.getPluginHelpPath( mavenProject ) );
|
||||||
|
|
||||||
writeDescriptor( f, request, true );
|
writeDescriptor( f, request, true );
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,11 @@ package org.apache.maven.tools.plugin.generator;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import org.apache.maven.model.Build;
|
import org.apache.maven.model.Build;
|
||||||
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;
|
||||||
|
|
@ -27,13 +32,9 @@ import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
|
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
import org.codehaus.plexus.component.repository.ComponentDependency;
|
import org.codehaus.plexus.component.repository.ComponentDependency;
|
||||||
|
import org.codehaus.plexus.logging.Logger;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
||||||
* @version $Id: AbstractGeneratorTestCase.java,v 1.1 2005/02/20 16:25:21
|
* @version $Id: AbstractGeneratorTestCase.java,v 1.1 2005/02/20 16:25:21
|
||||||
|
|
@ -136,7 +137,17 @@ public abstract class AbstractGeneratorTestCase
|
||||||
{
|
{
|
||||||
Class<?> generatorClass = Thread.currentThread().getContextClassLoader().loadClass( generatorClassName );
|
Class<?> generatorClass = Thread.currentThread().getContextClassLoader().loadClass( generatorClassName );
|
||||||
|
|
||||||
|
Logger logger = getContainer().getLogger();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Constructor<?> constructor = generatorClass.getConstructor( Logger.class );
|
||||||
|
generator = (Generator) constructor.newInstance( logger );
|
||||||
|
}
|
||||||
|
catch ( NoSuchMethodException ignore )
|
||||||
|
{
|
||||||
generator = (Generator) generatorClass.newInstance();
|
generator = (Generator) generatorClass.newInstance();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,10 @@ package org.apache.maven.tools.plugin.extractor.java;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import org.apache.maven.model.Build;
|
import org.apache.maven.model.Build;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
|
|
@ -36,15 +39,12 @@ import org.codehaus.plexus.component.repository.ComponentDependency;
|
||||||
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.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
import org.custommonkey.xmlunit.Diff;
|
import org.custommonkey.xmlunit.Diff;
|
||||||
import org.custommonkey.xmlunit.XMLUnit;
|
import org.custommonkey.xmlunit.XMLUnit;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jdcasey
|
* @author jdcasey
|
||||||
*/
|
*/
|
||||||
|
|
@ -79,13 +79,14 @@ public class JavaMojoDescriptorExtractorTest
|
||||||
model.setArtifactId( "maven-unitTesting-plugin" );
|
model.setArtifactId( "maven-unitTesting-plugin" );
|
||||||
|
|
||||||
MavenProject project = new MavenProject( model );
|
MavenProject project = new MavenProject( model );
|
||||||
project.setBuild( new Build(){
|
project.setBuild( new Build()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public String getOutputDirectory()
|
public String getOutputDirectory()
|
||||||
{
|
{
|
||||||
return System.getProperty( "filePath" );
|
return System.getProperty( "filePath" );
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
|
|
||||||
project.setFile( new File( root, "pom.xml" ) );
|
project.setFile( new File( root, "pom.xml" ) );
|
||||||
project.addCompileSourceRoot( new File( root, directory ).getPath() );
|
project.addCompileSourceRoot( new File( root, directory ).getPath() );
|
||||||
|
|
@ -120,7 +121,7 @@ public class JavaMojoDescriptorExtractorTest
|
||||||
request.getPluginDescriptor().addMojo( mojoDescriptor );
|
request.getPluginDescriptor().addMojo( mojoDescriptor );
|
||||||
}
|
}
|
||||||
|
|
||||||
Generator descriptorGenerator = new PluginDescriptorGenerator();
|
Generator descriptorGenerator = new PluginDescriptorGenerator( new ConsoleLogger( 0, "A" ) );
|
||||||
|
|
||||||
descriptorGenerator.execute( new File( root, directory ), request );
|
descriptorGenerator.execute( new File( root, directory ), request );
|
||||||
|
|
||||||
|
|
@ -138,8 +139,8 @@ public class JavaMojoDescriptorExtractorTest
|
||||||
XMLUnit.setIgnoreWhitespace( true );
|
XMLUnit.setIgnoreWhitespace( true );
|
||||||
XMLUnit.setIgnoreComments( true );
|
XMLUnit.setIgnoreComments( true );
|
||||||
|
|
||||||
Document expected =
|
Document expected = XMLUnit.buildControlDocument(
|
||||||
XMLUnit.buildControlDocument( FileUtils.fileRead( new File( testDirectory, "plugin-expected.xml" ), "UTF-8" ) );
|
FileUtils.fileRead( new File( testDirectory, "plugin-expected.xml" ), "UTF-8" ) );
|
||||||
Document actual =
|
Document actual =
|
||||||
XMLUnit.buildTestDocument( FileUtils.fileRead( new File( testDirectory, "plugin.xml" ), "UTF-8" ) );
|
XMLUnit.buildTestDocument( FileUtils.fileRead( new File( testDirectory, "plugin.xml" ), "UTF-8" ) );
|
||||||
|
|
||||||
|
|
@ -182,8 +183,7 @@ public class JavaMojoDescriptorExtractorTest
|
||||||
|
|
||||||
MojoDescriptor mojoDescriptor = results.get( 0 );
|
MojoDescriptor mojoDescriptor = results.get( 0 );
|
||||||
|
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" ) List<Parameter> parameters = mojoDescriptor.getParameters();
|
||||||
List<Parameter> parameters = mojoDescriptor.getParameters();
|
|
||||||
|
|
||||||
assertEquals( 1, parameters.size() );
|
assertEquals( 1, parameters.size() );
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue