You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Juven Xu <ju...@gmail.com> on 2008/05/09 11:17:31 UTC

plugin:descriptor works wrong in a special case

Hi, all:

The case is this:

1. It's a multi-module project, like this:
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.juven.maven2.plugin</groupId>
    <artifactId>maven2-plugin</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>Maven Plugins</name>

   <modules>
        <module>container-plugin</module>
        <module>sar-plugin</module>
        <module>parameter-replace-plugin</module>
   </modules>

2. All submodules are projects of maven-plugin.

3. I configured surefire-report-plugin in the parent, like this:
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.4.2</version>
      </plugin>

4. I ran mvn site in the parent.

The error from the console is:
****************************************
[INFO] Preparing surefire-report:report
[INFO] [plugin:descriptor]
[INFO] Using 2 extractors.
[INFO] Applying extractor for language: java
[INFO] Extractor for language: java found 12 mojo descriptors.
...
[INFO] Error extracting plugin descriptor: 'Goal: stop already exists in the
plugin descriptor for prefix: container
Existing implementation is:
com.juven.maven2.plugin.container.StopContainerMojo
Conflicting implementation is:
com.juven.maven2.plugin.container.StopContainerMojo'
*****************************************

As I investigated, there should be only 4 mojo descriptors, but
plugin:descriptor found 12, with each mojo 3 copies, so the exception is
thrown.

What's strange is, if I run mvn install, it's ok;  if I remove
surefire-report-plugin and run mvn site, it's ok; if I ran
surefire-report:report, it's ok!

I also checkouted the maven source code to research, and I found these java
codes in DefaultMojoScanner.java:

            logger.info( "Applying extractor for language: " + language );
            List extractorDescriptors = extractor.execute( project,
pluginDescriptor );
            logger.info( "Extractor for language: " + language + " found " +
extractorDescriptors.size() +
                " mojo descriptors." );
            numMojoDescriptors += extractorDescriptors.size();

Here the size is wrong in my case, so I checked the extractor,
JavaMojoDescriptorExtractor.java, here's two methods related to the size:

 public List execute( MavenProject project, PluginDescriptor
pluginDescriptor )
        throws ExtractionException, InvalidPluginDescriptorException
    {
        JavaClass[] javaClasses = discoverClasses( project );

        List descriptors = new ArrayList();

        for ( int i = 0; i < javaClasses.length; i++ )
        {
            DocletTag tag = javaClasses[i].getTagByName( GOAL );

            if ( tag != null )
            {
                MojoDescriptor mojoDescriptor = createMojoDescriptor(
javaClasses[i] );
                mojoDescriptor.setPluginDescriptor( pluginDescriptor );

                // Validate the descriptor as best we can before allowing it
to be processed.
                validate( mojoDescriptor );

                descriptors.add( mojoDescriptor );
            }
        }

        return descriptors;
    }


    protected JavaClass[] discoverClasses( final MavenProject project )
    {
        JavaDocBuilder builder = new JavaDocBuilder();

        for ( Iterator i = project.getCompileSourceRoots().iterator();
i.hasNext(); )
        {
            builder.addSourceTree( new File( (String) i.next() ) );
        }

        // TODO be more dynamic
        if ( !project.getCompileSourceRoots()
            .contains( new File( project.getBasedir(),
"target/generated-sources/plugin" ).getAbsolutePath() ) )
        {
            builder.addSourceTree( new File( project.getBasedir(),
"target/generated-sources/plugin" ) );
        }

        return builder.getClasses();
    }


And I end to this, still don't why this error occurs, anybody can help me ??

Thx.
-Juven

plugin:descriptor works wrong in a special case

Posted by Juven Xu <ju...@gmail.com>.
Hi, all:

The case is this:

1. It's a multi-module project, like this:
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.juven.maven2.plugin</groupId>
    <artifactId>maven2-plugin</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>Maven Plugins</name>

   <modules>
        <module>container-plugin</module>
        <module>sar-plugin</module>
        <module>parameter-replace-plugin</module>
   </modules>

2. All submodules are projects of maven-plugin.

3. I configured surefire-report-plugin in the parent, like this:
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.4.2</version>
      </plugin>

4. I ran mvn site in the parent.

The error from the console is:
****************************************
[INFO] Preparing surefire-report:report
[INFO] [plugin:descriptor]
[INFO] Using 2 extractors.
[INFO] Applying extractor for language: java
[INFO] Extractor for language: java found 12 mojo descriptors.
...
[INFO] Error extracting plugin descriptor: 'Goal: stop already exists in the
plugin descriptor for prefix: container
Existing implementation is:
com.juven.maven2.plugin.container.StopContainerMojo
Conflicting implementation is:
com.juven.maven2.plugin.container.StopContainerMojo'
*****************************************

As I investigated, there should be only 4 mojo descriptors, but
plugin:descriptor found 12, with each mojo 3 copies, so the exception is
thrown.

What's strange is, if I run mvn install, it's ok;  if I remove
surefire-report-plugin and run mvn site, it's ok; if I ran
surefire-report:report, it's ok!

I also checkouted the maven source code to research, and I found these java
codes in DefaultMojoScanner.java:

            logger.info( "Applying extractor for language: " + language );
            List extractorDescriptors = extractor.execute( project,
pluginDescriptor );
            logger.info( "Extractor for language: " + language + " found " +
extractorDescriptors.size() +
                " mojo descriptors." );
            numMojoDescriptors += extractorDescriptors.size();

Here the size is wrong in my case, so I checked the extractor,
JavaMojoDescriptorExtractor.java, here's two methods related to the size:

 public List execute( MavenProject project, PluginDescriptor
pluginDescriptor )
        throws ExtractionException, InvalidPluginDescriptorException
    {
        JavaClass[] javaClasses = discoverClasses( project );

        List descriptors = new ArrayList();

        for ( int i = 0; i < javaClasses.length; i++ )
        {
            DocletTag tag = javaClasses[i].getTagByName( GOAL );

            if ( tag != null )
            {
                MojoDescriptor mojoDescriptor = createMojoDescriptor(
javaClasses[i] );
                mojoDescriptor.setPluginDescriptor( pluginDescriptor );

                // Validate the descriptor as best we can before allowing it
to be processed.
                validate( mojoDescriptor );

                descriptors.add( mojoDescriptor );
            }
        }

        return descriptors;
    }


    protected JavaClass[] discoverClasses( final MavenProject project )
    {
        JavaDocBuilder builder = new JavaDocBuilder();

        for ( Iterator i = project.getCompileSourceRoots().iterator();
i.hasNext(); )
        {
            builder.addSourceTree( new File( (String) i.next() ) );
        }

        // TODO be more dynamic
        if ( !project.getCompileSourceRoots()
            .contains( new File( project.getBasedir(),
"target/generated-sources/plugin" ).getAbsolutePath() ) )
        {
            builder.addSourceTree( new File( project.getBasedir(),
"target/generated-sources/plugin" ) );
        }

        return builder.getClasses();
    }


And I end to this, still don't why this error occurs, anybody can help me ??

Thx.
-Juven