[ http://jira.codehaus.org/browse/MNG-2237?page=comments#action_65174 ] 

Anatol Pomozov commented on MNG-2237:
-------------------------------------

I have problem with self-written plugin. My plugin patches web.xml file and it 
is configured in parent and child pom - so it runs twice.

For me patching web.xml twice is fatal error that is why I add quick fix of the 
problem to MY plugin. Here it is

{{
    //Quick fix for double plugin execution. See maven bug reports in maven2 
JIRA (MNG-2221, MNG-2237, MNG-2054)
    //First of all check that we have not patched web.xml yet.
    private static List<String> _processedWebXMLFiles = new 
LinkedList<String>();

    private boolean isDoubledPluginExecution(String aFileName) {
        //Build hash from params
        StringBuffer params = new StringBuffer();
        
params.append(contextParams).append(jspConfig).append(listeners).append(servletMappings).append(servlets).append(taglibs);
        int hash = params.toString().hashCode();

        String hashedFileName = aFileName + String.valueOf(hash);
        if (_processedWebXMLFiles.contains(hashedFileName))
            return true;
        else {
            _processedWebXMLFiles.add(hashedFileName);
            return false;
        }
    }
}}

and in execute() method of plugin I have added checking that file already 
patched

{{
        File webXmlFile = new File(webappDirectory, "WEB-INF/web.xml");

            if (isDoubledPluginExecution(webXmlFile.getCanonicalPath())) {
                getLog().warn("File already patched. Skip it!");
                return;
            }
}}

It works for me well but I prefer that this bug was fixed. I would like that 
you vote for this bug because it is very important. 

And I hope that my quick fix helps you!

> Inherited plugin executed twice if child pom merges configuration
> -----------------------------------------------------------------
>
>          Key: MNG-2237
>          URL: http://jira.codehaus.org/browse/MNG-2237
>      Project: Maven 2
>         Type: Bug

>   Components: Inheritence and Interpolation
>     Versions: 2.0.4
>     Reporter: Joerg Schaible

>
>
> According the docs the configuration of a plugin is merged, when the plugin 
> is inherited. This actually hapens, but the plugin with the merged 
> configuration is added twice in the effective-pom and therefore executed 
> twice.
> Setup a parent pom with a plugin configuration to attach the javadocs:
> {noformat}
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-javadoc-plugin</artifactId>
>                 <executions>
>                     <execution>
>                         <id>attach-javadocs</id>
>                         <goals>
>                             <goal>jar</goal>
>                         </goals>
>                     </execution>
>                 </executions>
>                 <inherited>true</inherited>
>                 <configuration>
>                     <linksource>true</linksource>
>                 </configuration>
>             </plugin>
> {noformat}
> and a child pom that adds additional elements in the configuration:
> {noformat}
>            <plugin>
>                 <artifactId>maven-javadoc-plugin</artifactId>
>                 <configuration>
>                     <links>
>                         <link>http://java.sun.com/j2se/1.4.2/docs/api/</link>
>                         
> <link>http://jakarta.apache.org/commons/logging/commons-logging-1.0.4/docs/apidocs/</link>
>                         <link>http://jmock.codehaus.org/docs/javadoc/</link>
>                         <link>http://www.junit.org/junit/javadoc/3.8.1/</link>
>                     </links>
>                 </configuration>
>             </plugin>
> {noformat}
> In this case the javadoc is generated twice, the goal help:effective-pom 
> reveals, that the plugin was merged, but added twice.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to