You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Baptiste Gaillard <ba...@gomoob.com> on 2012/12/11 23:42:43 UTC

File lock problem in custom Maven Reporting Plugin

Hi, I'm currently creating a new Maven Reporting Plugin which integrate an
external tool used to generate a Javascript documentation in my Maven Web
Site.

My report Mojo is very simple and is declared using :

/**
 * @goal jsduck
 * @phase site
 */
public class JSDuckReportMojo extends AbstractMavenReport {
...
}

I encounter a file locking problem (i.e already opened elsewhere and not
closed) at the beginning of my 'executeReport' method :

*
protected void executeReport(Locale locale) throws MavenReportException {

    // JSDuck creates an 'index.html' file itself and crashes if one file
with this name already exist
    File jsduckIndex = new File("target/site/jsduck/index.html");

    if (jsduckIndex.exists() && !jsduckIndex.delete()) {
        throw new MavenReportException("Fail to delete the previously
generated index.html !"
);
    }

    // Use a document generator which absolutly need to have an empty
target directory
    ...
}
*

The tool I'm integrating is called 'jsduck' and absolutely needs to have an
empty target directory to work, its root index file is called 'index.html'.

So I've also implemented the 'getOutputName' function :

public String getOutputName() {
return "jsduck/index";
}

But, the file 'target/site/jsduck/index.html' has already been created
automagically by Maven.
In the 'executeReport' this file is there, empty and locked !

So, I can't delete this 'index.html' file and let JSDuck create itself :-(

Is it normal that Maven locks this 'index.html' file (because it has been
declared in the 'getOutputName()' ) ?
How can I unlock this file inside the 'executeReport' function to let
JSDuck generate my documentation ?

I've already tried to debug the 'AbstractMavenReport' class and only found
a 'PrintWriter' attached to the 'Sink' (in the 'execute' method) which
could cause this locking problem.
Calling the 'close' method at the beginning of the 'executeReport' method
seems to have no effect...

Thanks for you help,

Baptiste

Re: File lock problem in custom Maven Reporting Plugin

Posted by Baptiste Gaillard <ba...@gomoob.com>.
Hi Olivier,

I've created a JIRA issue here
http://jira.codehaus.org/browse/MSHARED-269with two project used to
reproduce the problem.

Thanks for the help guys,

Baptiste

2012/12/19 Olivier Lamy <ol...@apache.org>

> Can you create a jira entry with a sample ?
>
> 2012/12/18 Baptiste Gaillard <ba...@gomoob.com>:
> > Hi and thanks for the response,
> >
> > My Mojo already overwrites the isExternalReport() function and returns
> true
> > into it.
> >
> > To deep a little more I've tried to debug the execution of the Mojo when
> > running a 'mvn site' command using that Mojo.
> >
> > It seems that the function 'executeReport' associated to a reporting Mojo
> > is called before 'isExternalReport' is used.
> >
> > The 'execute' method associated to the 'AbstractMavenReport' (I'm using
> > 'maven-reporting-impl' version 2.2)   class contains the following lines
> :
> >
> >         Writer writer = null;
> >         try
> >         {
> >             File outputDirectory = new File( getOutputDirectory() );
> >
> >             String filename = getOutputName() + ".html";
> >
> >             Locale locale = Locale.getDefault();
> >
> >             SiteRenderingContext siteContext = new
> SiteRenderingContext();
> >             siteContext.setDecoration( new DecorationModel() );
> >             siteContext.setTemplateName(
> > "org/apache/maven/doxia/siterenderer/resources/default-site.vm" );
> >             siteContext.setLocale( locale );
> >
> >             RenderingContext context = new RenderingContext(
> > outputDirectory, filename );
> >
> >             SiteRendererSink sink = new SiteRendererSink( context );
> >
> >             generate( sink, null, locale );
> >
> > ...
> >
> > The 'generate' function then calls the reporting mojo 'executeReport'
> > function, so I think my locking problems comes from one of the following
> > calls :
> >     - 'new RenderingContext'
> >     - 'new SiteRendererSink'
> >
> > Do you have any other ideas ?
> >
> > Perhaps I should post this message on the developer Mailing List, my
> > problems seems to be linked to what Maven (or the 'maven-reporting-impl
> > plugin executes internally ?
> >
> > Thanks,
> >
> > Baptiste
> >
> > 2012/12/16 Robert Scholte <rf...@apache.org>
> >
> >> This is probably what you need:
> >> from org.apache.maven.reporting.**MavenReport.isExternalReport()
> >>
> >>     /**
> >>      * An external report is a report which calls a third party program
> >> which generates some reports too.
> >>      * A good example is javadoc tool.
> >>      *
> >>      * @return <tt>true</tt> if this report is external, <tt>false</tt>
> >> otherwise.
> >>      * Default should be <tt>false</tt>.
> >>      */
> >>     boolean isExternalReport();
> >>
> >>
> >> Op Tue, 11 Dec 2012 23:42:43 +0100 schreef Baptiste Gaillard <
> >> baptiste.gaillard@gomoob.com>**:
> >>
> >>  Hi, I'm currently creating a new Maven Reporting Plugin which
> integrate an
> >>> external tool used to generate a Javascript documentation in my Maven
> Web
> >>> Site.
> >>>
> >>> My report Mojo is very simple and is declared using :
> >>>
> >>> /**
> >>>  * @goal jsduck
> >>>  * @phase site
> >>>  */
> >>> public class JSDuckReportMojo extends AbstractMavenReport {
> >>> ...
> >>> }
> >>>
> >>> I encounter a file locking problem (i.e already opened elsewhere and
> not
> >>> closed) at the beginning of my 'executeReport' method :
> >>>
> >>> *
> >>>
> >>> protected void executeReport(Locale locale) throws
> MavenReportException {
> >>>
> >>>     // JSDuck creates an 'index.html' file itself and crashes if one
> file
> >>> with this name already exist
> >>>     File jsduckIndex = new File("target/site/jsduck/**index.html");
> >>>
> >>>     if (jsduckIndex.exists() && !jsduckIndex.delete()) {
> >>>         throw new MavenReportException("Fail to delete the previously
> >>> generated index.html !"
> >>> );
> >>>     }
> >>>
> >>>     // Use a document generator which absolutly need to have an empty
> >>> target directory
> >>>     ...
> >>> }
> >>> *
> >>>
> >>> The tool I'm integrating is called 'jsduck' and absolutely needs to
> have
> >>> an
> >>> empty target directory to work, its root index file is called
> >>> 'index.html'.
> >>>
> >>> So I've also implemented the 'getOutputName' function :
> >>>
> >>> public String getOutputName() {
> >>> return "jsduck/index";
> >>> }
> >>>
> >>> But, the file 'target/site/jsduck/index.**html' has already been
> created
> >>> automagically by Maven.
> >>> In the 'executeReport' this file is there, empty and locked !
> >>>
> >>> So, I can't delete this 'index.html' file and let JSDuck create itself
> :-(
> >>>
> >>> Is it normal that Maven locks this 'index.html' file (because it has
> been
> >>> declared in the 'getOutputName()' ) ?
> >>> How can I unlock this file inside the 'executeReport' function to let
> >>> JSDuck generate my documentation ?
> >>>
> >>> I've already tried to debug the 'AbstractMavenReport' class and only
> found
> >>> a 'PrintWriter' attached to the 'Sink' (in the 'execute' method) which
> >>> could cause this locking problem.
> >>> Calling the 'close' method at the beginning of the 'executeReport'
> method
> >>> seems to have no effect...
> >>>
> >>> Thanks for you help,
> >>>
> >>> Baptiste
> >>>
> >>
> >>
> ------------------------------**------------------------------**---------
> >> To unsubscribe, e-mail: users-unsubscribe@maven.**apache.org<
> users-unsubscribe@maven.apache.org>
> >> For additional commands, e-mail: users-help@maven.apache.org
> >>
> >>
> >
> >
> > --
> >
> > *Baptiste GAILLARD*
> > *Mobile : +33(6) 85 12 81 26  <http://
> +33%286%29%2085%2012%2081%2026%20/>*
> > *Mail     :* *baptiste.gaillard@gomoob.com*
> > *http://www.gomoob.com*
> > *
> > *
> > **
> > *
> > *
>
>
>
> --
> Olivier Lamy
> Talend: http://coders.talend.com
> http://twitter.com/olamy | http://linkedin.com/in/olamy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 

*Baptiste GAILLARD*
*Mobile : +33(6) 85 12 81 26  <http://+33%286%29%2085%2012%2081%2026%20/>*
*Mail     :* *baptiste.gaillard@gomoob.com*
*http://www.gomoob.com*
*
*
**
*
*

Re: File lock problem in custom Maven Reporting Plugin

Posted by Olivier Lamy <ol...@apache.org>.
Can you create a jira entry with a sample ?

2012/12/18 Baptiste Gaillard <ba...@gomoob.com>:
> Hi and thanks for the response,
>
> My Mojo already overwrites the isExternalReport() function and returns true
> into it.
>
> To deep a little more I've tried to debug the execution of the Mojo when
> running a 'mvn site' command using that Mojo.
>
> It seems that the function 'executeReport' associated to a reporting Mojo
> is called before 'isExternalReport' is used.
>
> The 'execute' method associated to the 'AbstractMavenReport' (I'm using
> 'maven-reporting-impl' version 2.2)   class contains the following lines :
>
>         Writer writer = null;
>         try
>         {
>             File outputDirectory = new File( getOutputDirectory() );
>
>             String filename = getOutputName() + ".html";
>
>             Locale locale = Locale.getDefault();
>
>             SiteRenderingContext siteContext = new SiteRenderingContext();
>             siteContext.setDecoration( new DecorationModel() );
>             siteContext.setTemplateName(
> "org/apache/maven/doxia/siterenderer/resources/default-site.vm" );
>             siteContext.setLocale( locale );
>
>             RenderingContext context = new RenderingContext(
> outputDirectory, filename );
>
>             SiteRendererSink sink = new SiteRendererSink( context );
>
>             generate( sink, null, locale );
>
> ...
>
> The 'generate' function then calls the reporting mojo 'executeReport'
> function, so I think my locking problems comes from one of the following
> calls :
>     - 'new RenderingContext'
>     - 'new SiteRendererSink'
>
> Do you have any other ideas ?
>
> Perhaps I should post this message on the developer Mailing List, my
> problems seems to be linked to what Maven (or the 'maven-reporting-impl
> plugin executes internally ?
>
> Thanks,
>
> Baptiste
>
> 2012/12/16 Robert Scholte <rf...@apache.org>
>
>> This is probably what you need:
>> from org.apache.maven.reporting.**MavenReport.isExternalReport()
>>
>>     /**
>>      * An external report is a report which calls a third party program
>> which generates some reports too.
>>      * A good example is javadoc tool.
>>      *
>>      * @return <tt>true</tt> if this report is external, <tt>false</tt>
>> otherwise.
>>      * Default should be <tt>false</tt>.
>>      */
>>     boolean isExternalReport();
>>
>>
>> Op Tue, 11 Dec 2012 23:42:43 +0100 schreef Baptiste Gaillard <
>> baptiste.gaillard@gomoob.com>**:
>>
>>  Hi, I'm currently creating a new Maven Reporting Plugin which integrate an
>>> external tool used to generate a Javascript documentation in my Maven Web
>>> Site.
>>>
>>> My report Mojo is very simple and is declared using :
>>>
>>> /**
>>>  * @goal jsduck
>>>  * @phase site
>>>  */
>>> public class JSDuckReportMojo extends AbstractMavenReport {
>>> ...
>>> }
>>>
>>> I encounter a file locking problem (i.e already opened elsewhere and not
>>> closed) at the beginning of my 'executeReport' method :
>>>
>>> *
>>>
>>> protected void executeReport(Locale locale) throws MavenReportException {
>>>
>>>     // JSDuck creates an 'index.html' file itself and crashes if one file
>>> with this name already exist
>>>     File jsduckIndex = new File("target/site/jsduck/**index.html");
>>>
>>>     if (jsduckIndex.exists() && !jsduckIndex.delete()) {
>>>         throw new MavenReportException("Fail to delete the previously
>>> generated index.html !"
>>> );
>>>     }
>>>
>>>     // Use a document generator which absolutly need to have an empty
>>> target directory
>>>     ...
>>> }
>>> *
>>>
>>> The tool I'm integrating is called 'jsduck' and absolutely needs to have
>>> an
>>> empty target directory to work, its root index file is called
>>> 'index.html'.
>>>
>>> So I've also implemented the 'getOutputName' function :
>>>
>>> public String getOutputName() {
>>> return "jsduck/index";
>>> }
>>>
>>> But, the file 'target/site/jsduck/index.**html' has already been created
>>> automagically by Maven.
>>> In the 'executeReport' this file is there, empty and locked !
>>>
>>> So, I can't delete this 'index.html' file and let JSDuck create itself :-(
>>>
>>> Is it normal that Maven locks this 'index.html' file (because it has been
>>> declared in the 'getOutputName()' ) ?
>>> How can I unlock this file inside the 'executeReport' function to let
>>> JSDuck generate my documentation ?
>>>
>>> I've already tried to debug the 'AbstractMavenReport' class and only found
>>> a 'PrintWriter' attached to the 'Sink' (in the 'execute' method) which
>>> could cause this locking problem.
>>> Calling the 'close' method at the beginning of the 'executeReport' method
>>> seems to have no effect...
>>>
>>> Thanks for you help,
>>>
>>> Baptiste
>>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@maven.**apache.org<us...@maven.apache.org>
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>
>
> --
>
> *Baptiste GAILLARD*
> *Mobile : +33(6) 85 12 81 26  <http://+33%286%29%2085%2012%2081%2026%20/>*
> *Mail     :* *baptiste.gaillard@gomoob.com*
> *http://www.gomoob.com*
> *
> *
> **
> *
> *



-- 
Olivier Lamy
Talend: http://coders.talend.com
http://twitter.com/olamy | http://linkedin.com/in/olamy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: File lock problem in custom Maven Reporting Plugin

Posted by Baptiste Gaillard <ba...@gomoob.com>.
Hi and thanks for the response,

My Mojo already overwrites the isExternalReport() function and returns true
into it.

To deep a little more I've tried to debug the execution of the Mojo when
running a 'mvn site' command using that Mojo.

It seems that the function 'executeReport' associated to a reporting Mojo
is called before 'isExternalReport' is used.

The 'execute' method associated to the 'AbstractMavenReport' (I'm using
'maven-reporting-impl' version 2.2)   class contains the following lines :

        Writer writer = null;
        try
        {
            File outputDirectory = new File( getOutputDirectory() );

            String filename = getOutputName() + ".html";

            Locale locale = Locale.getDefault();

            SiteRenderingContext siteContext = new SiteRenderingContext();
            siteContext.setDecoration( new DecorationModel() );
            siteContext.setTemplateName(
"org/apache/maven/doxia/siterenderer/resources/default-site.vm" );
            siteContext.setLocale( locale );

            RenderingContext context = new RenderingContext(
outputDirectory, filename );

            SiteRendererSink sink = new SiteRendererSink( context );

            generate( sink, null, locale );

...

The 'generate' function then calls the reporting mojo 'executeReport'
function, so I think my locking problems comes from one of the following
calls :
    - 'new RenderingContext'
    - 'new SiteRendererSink'

Do you have any other ideas ?

Perhaps I should post this message on the developer Mailing List, my
problems seems to be linked to what Maven (or the 'maven-reporting-impl
plugin executes internally ?

Thanks,

Baptiste

2012/12/16 Robert Scholte <rf...@apache.org>

> This is probably what you need:
> from org.apache.maven.reporting.**MavenReport.isExternalReport()
>
>     /**
>      * An external report is a report which calls a third party program
> which generates some reports too.
>      * A good example is javadoc tool.
>      *
>      * @return <tt>true</tt> if this report is external, <tt>false</tt>
> otherwise.
>      * Default should be <tt>false</tt>.
>      */
>     boolean isExternalReport();
>
>
> Op Tue, 11 Dec 2012 23:42:43 +0100 schreef Baptiste Gaillard <
> baptiste.gaillard@gomoob.com>**:
>
>  Hi, I'm currently creating a new Maven Reporting Plugin which integrate an
>> external tool used to generate a Javascript documentation in my Maven Web
>> Site.
>>
>> My report Mojo is very simple and is declared using :
>>
>> /**
>>  * @goal jsduck
>>  * @phase site
>>  */
>> public class JSDuckReportMojo extends AbstractMavenReport {
>> ...
>> }
>>
>> I encounter a file locking problem (i.e already opened elsewhere and not
>> closed) at the beginning of my 'executeReport' method :
>>
>> *
>>
>> protected void executeReport(Locale locale) throws MavenReportException {
>>
>>     // JSDuck creates an 'index.html' file itself and crashes if one file
>> with this name already exist
>>     File jsduckIndex = new File("target/site/jsduck/**index.html");
>>
>>     if (jsduckIndex.exists() && !jsduckIndex.delete()) {
>>         throw new MavenReportException("Fail to delete the previously
>> generated index.html !"
>> );
>>     }
>>
>>     // Use a document generator which absolutly need to have an empty
>> target directory
>>     ...
>> }
>> *
>>
>> The tool I'm integrating is called 'jsduck' and absolutely needs to have
>> an
>> empty target directory to work, its root index file is called
>> 'index.html'.
>>
>> So I've also implemented the 'getOutputName' function :
>>
>> public String getOutputName() {
>> return "jsduck/index";
>> }
>>
>> But, the file 'target/site/jsduck/index.**html' has already been created
>> automagically by Maven.
>> In the 'executeReport' this file is there, empty and locked !
>>
>> So, I can't delete this 'index.html' file and let JSDuck create itself :-(
>>
>> Is it normal that Maven locks this 'index.html' file (because it has been
>> declared in the 'getOutputName()' ) ?
>> How can I unlock this file inside the 'executeReport' function to let
>> JSDuck generate my documentation ?
>>
>> I've already tried to debug the 'AbstractMavenReport' class and only found
>> a 'PrintWriter' attached to the 'Sink' (in the 'execute' method) which
>> could cause this locking problem.
>> Calling the 'close' method at the beginning of the 'executeReport' method
>> seems to have no effect...
>>
>> Thanks for you help,
>>
>> Baptiste
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@maven.**apache.org<us...@maven.apache.org>
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 

*Baptiste GAILLARD*
*Mobile : +33(6) 85 12 81 26  <http://+33%286%29%2085%2012%2081%2026%20/>*
*Mail     :* *baptiste.gaillard@gomoob.com*
*http://www.gomoob.com*
*
*
**
*
*

Re: File lock problem in custom Maven Reporting Plugin

Posted by Robert Scholte <rf...@apache.org>.
This is probably what you need:
 from org.apache.maven.reporting.MavenReport.isExternalReport()

     /**
      * An external report is a report which calls a third party program  
which generates some reports too.
      * A good example is javadoc tool.
      *
      * @return <tt>true</tt> if this report is external, <tt>false</tt>  
otherwise.
      * Default should be <tt>false</tt>.
      */
     boolean isExternalReport();


Op Tue, 11 Dec 2012 23:42:43 +0100 schreef Baptiste Gaillard  
<ba...@gomoob.com>:

> Hi, I'm currently creating a new Maven Reporting Plugin which integrate  
> an
> external tool used to generate a Javascript documentation in my Maven Web
> Site.
>
> My report Mojo is very simple and is declared using :
>
> /**
>  * @goal jsduck
>  * @phase site
>  */
> public class JSDuckReportMojo extends AbstractMavenReport {
> ...
> }
>
> I encounter a file locking problem (i.e already opened elsewhere and not
> closed) at the beginning of my 'executeReport' method :
>
> *
> protected void executeReport(Locale locale) throws MavenReportException {
>
>     // JSDuck creates an 'index.html' file itself and crashes if one file
> with this name already exist
>     File jsduckIndex = new File("target/site/jsduck/index.html");
>
>     if (jsduckIndex.exists() && !jsduckIndex.delete()) {
>         throw new MavenReportException("Fail to delete the previously
> generated index.html !"
> );
>     }
>
>     // Use a document generator which absolutly need to have an empty
> target directory
>     ...
> }
> *
>
> The tool I'm integrating is called 'jsduck' and absolutely needs to have  
> an
> empty target directory to work, its root index file is called  
> 'index.html'.
>
> So I've also implemented the 'getOutputName' function :
>
> public String getOutputName() {
> return "jsduck/index";
> }
>
> But, the file 'target/site/jsduck/index.html' has already been created
> automagically by Maven.
> In the 'executeReport' this file is there, empty and locked !
>
> So, I can't delete this 'index.html' file and let JSDuck create itself  
> :-(
>
> Is it normal that Maven locks this 'index.html' file (because it has been
> declared in the 'getOutputName()' ) ?
> How can I unlock this file inside the 'executeReport' function to let
> JSDuck generate my documentation ?
>
> I've already tried to debug the 'AbstractMavenReport' class and only  
> found
> a 'PrintWriter' attached to the 'Sink' (in the 'execute' method) which
> could cause this locking problem.
> Calling the 'close' method at the beginning of the 'executeReport' method
> seems to have no effect...
>
> Thanks for you help,
>
> Baptiste

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org