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.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
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.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.apache.maven.tools.plugin.generator.Generator;
|
||||
import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator;
|
||||
|
||||
import java.io.File;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
||||
/**
|
||||
* Generate a plugin descriptor.
|
||||
|
|
@ -43,7 +44,7 @@ import java.io.File;
|
|||
* @since 2.0
|
||||
*/
|
||||
@Mojo( name = "descriptor", defaultPhase = LifecyclePhase.PROCESS_CLASSES,
|
||||
requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true )
|
||||
requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true )
|
||||
public class DescriptorGeneratorMojo
|
||||
extends AbstractGeneratorMojo
|
||||
{
|
||||
|
|
@ -55,25 +56,35 @@ public class DescriptorGeneratorMojo
|
|||
|
||||
/**
|
||||
* A flag to disable generation of the <code>plugin.xml</code> in favor of a hand authored plugin descriptor.
|
||||
*
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
@Parameter( defaultValue = "false" )
|
||||
private boolean skipDescriptor;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Component
|
||||
protected Logger logger;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected File getOutputDirectory()
|
||||
{
|
||||
return outputDirectory;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected Generator createGenerator()
|
||||
{
|
||||
return new PluginDescriptorGenerator();
|
||||
return new PluginDescriptorGenerator( logger );
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,21 +19,6 @@ package org.apache.maven.tools.plugin.generator;
|
|||
* 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.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
|
@ -46,6 +31,20 @@ import java.util.LinkedHashSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
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
|
||||
|
|
@ -57,10 +56,16 @@ import java.util.Set;
|
|||
* get validation directives to help users in IDEs.
|
||||
*/
|
||||
public class PluginDescriptorGenerator
|
||||
extends AbstractLogEnabled
|
||||
implements Generator
|
||||
{
|
||||
|
||||
private final Logger log;
|
||||
|
||||
public PluginDescriptorGenerator( Logger log )
|
||||
{
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
@ -68,7 +73,7 @@ public class PluginDescriptorGenerator
|
|||
throws GeneratorException
|
||||
{
|
||||
// eventually rewrite help mojo class to match actual package name
|
||||
PluginHelpGenerator.rewriteHelpMojo( request, getLogger() );
|
||||
PluginHelpGenerator.rewriteHelpMojo( request, log );
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -79,8 +84,7 @@ public class PluginDescriptorGenerator
|
|||
// write plugin-help.xml help-descriptor
|
||||
MavenProject mavenProject = request.getProject();
|
||||
|
||||
f =
|
||||
new File( mavenProject.getBuild().getOutputDirectory(),
|
||||
f = new File( mavenProject.getBuild().getOutputDirectory(),
|
||||
PluginHelpGenerator.getPluginHelpPath( mavenProject ) );
|
||||
|
||||
writeDescriptor( f, request, true );
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ package org.apache.maven.tools.plugin.generator;
|
|||
* 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.plugin.descriptor.MojoDescriptor;
|
||||
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.codehaus.plexus.PlexusTestCase;
|
||||
import org.codehaus.plexus.component.repository.ComponentDependency;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
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>
|
||||
* @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 );
|
||||
|
||||
generator = (Generator) generatorClass.newInstance();
|
||||
Logger logger = getContainer().getLogger();
|
||||
try
|
||||
{
|
||||
Constructor<?> constructor = generatorClass.getConstructor( Logger.class );
|
||||
generator = (Generator) constructor.newInstance( logger );
|
||||
}
|
||||
catch ( NoSuchMethodException ignore )
|
||||
{
|
||||
generator = (Generator) generatorClass.newInstance();
|
||||
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,10 @@ package org.apache.maven.tools.plugin.extractor.java;
|
|||
* 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.Model;
|
||||
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.console.ConsoleLogger;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.custommonkey.xmlunit.Diff;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*/
|
||||
|
|
@ -79,13 +79,14 @@ public class JavaMojoDescriptorExtractorTest
|
|||
model.setArtifactId( "maven-unitTesting-plugin" );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
project.setBuild( new Build(){
|
||||
project.setBuild( new Build()
|
||||
{
|
||||
@Override
|
||||
public String getOutputDirectory()
|
||||
{
|
||||
return System.getProperty( "filePath" );
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
project.setFile( new File( root, "pom.xml" ) );
|
||||
project.addCompileSourceRoot( new File( root, directory ).getPath() );
|
||||
|
|
@ -120,7 +121,7 @@ public class JavaMojoDescriptorExtractorTest
|
|||
request.getPluginDescriptor().addMojo( mojoDescriptor );
|
||||
}
|
||||
|
||||
Generator descriptorGenerator = new PluginDescriptorGenerator();
|
||||
Generator descriptorGenerator = new PluginDescriptorGenerator( new ConsoleLogger( 0, "A" ) );
|
||||
|
||||
descriptorGenerator.execute( new File( root, directory ), request );
|
||||
|
||||
|
|
@ -137,9 +138,9 @@ public class JavaMojoDescriptorExtractorTest
|
|||
|
||||
XMLUnit.setIgnoreWhitespace( true );
|
||||
XMLUnit.setIgnoreComments( true );
|
||||
|
||||
Document expected =
|
||||
XMLUnit.buildControlDocument( FileUtils.fileRead( new File( testDirectory, "plugin-expected.xml" ), "UTF-8" ) );
|
||||
|
||||
Document expected = XMLUnit.buildControlDocument(
|
||||
FileUtils.fileRead( new File( testDirectory, "plugin-expected.xml" ), "UTF-8" ) );
|
||||
Document actual =
|
||||
XMLUnit.buildTestDocument( FileUtils.fileRead( new File( testDirectory, "plugin.xml" ), "UTF-8" ) );
|
||||
|
||||
|
|
@ -182,8 +183,7 @@ public class JavaMojoDescriptorExtractorTest
|
|||
|
||||
MojoDescriptor mojoDescriptor = results.get( 0 );
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
List<Parameter> parameters = mojoDescriptor.getParameters();
|
||||
@SuppressWarnings( "unchecked" ) List<Parameter> parameters = mojoDescriptor.getParameters();
|
||||
|
||||
assertEquals( 1, parameters.size() );
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ public class JavaMojoDescriptorExtractorTest
|
|||
|
||||
/**
|
||||
* Check that the mojo descriptor extractor will ignore any annotations that are found.
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testAnnotationInPlugin()
|
||||
|
|
@ -216,7 +216,7 @@ public class JavaMojoDescriptorExtractorTest
|
|||
|
||||
assertNull( results );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check that the mojo descriptor extractor will successfully parse sources with Java 1.5 language features like
|
||||
* generics.
|
||||
|
|
|
|||
Loading…
Reference in New Issue