You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Gajo Csaba <cs...@cosylab.com> on 2009/12/16 13:34:04 UTC

Custom plugin - resolve variables loaded from a file

Hello,

We're using the rpm plugin for packaging, and we have a problem with its 
install script. There are two ways to include a script. One is the 
(deprecated) <install> tag. In this case, we would put the bash script 
into the pom.xml, which is rather ugly, but it works. The bash script 
itself contains Maven variables, and these are replaced by maven before 
the script is used by the rpm plugin.
The other way is to user the <installScriptlet> tag. This tag required 
the name of an external file, which contains the contents of the bash 
script. This is a much cleaner approach. However, the problem is the 
maven variables are not replaced in the external file, so the script 
doesn't work.

I've looked at the source code of the rpm plugin, and it seems that it 
simply opens the external script file, and prints it line-by-line into 
the generated spec file, with no modification to the line.

I think it would be a good idea to modify the rpm plugin code at this 
point, so that the line is first processed, expanding all maven variables.

How can I do this? How is maven expanding its variables? Is there a 
method somewhere like MavenEnv.expandVariables(str) ?

Thanks, Csaba


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


Re: Custom plugin - resolve variables loaded from a file

Posted by Ryan Connolly <ry...@gmail.com>.
Ok, what I was suggesting should still work out for you.  What I was
suggesting was to put your script file into src/main/resources and configure
filtering like so:
              <resources>
                <resource>
                  <directory>src/main/resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>

Then in the plugin, simply refer to the filtered version of the script file:

              <installScriptlet>${project.build.directory}/classes/yourScriptFile.sh</installScriptlet>

Of course you could use a different output directory for the resources
config so that the path to installScriptlet need not point to the target
dir.

HTH.
-Ryan


On Wed, Dec 16, 2009 at 8:09 AM, Gajo Csaba <cs...@cosylab.com> wrote:

> Well on initial testing it doesn't seem to work. Maybe the rpm plugin is
> supposed to load the file through some maven resource interface? Right now,
> it's doing this:
>
> final Reader reader = new FileReader( scriptFile );
>
> Where scriptFile is a java.io.File. I think this way, it's bypassing
> Maven's framework. This could be yet another bug...
>
> Thanks for the help, Csaba
>
>
>
> Ryan Connolly wrote:
>
>> Hi. I have no experience with this plugin but it would seem that you
>> could first filter the file as a typical maven resource and then have
>> the plugin point to the filtered version?
>>
>>
>>
>> On 12/16/09, Gajo Csaba <cs...@cosylab.com> wrote:
>>
>>
>>> Hello,
>>>
>>> We're using the rpm plugin for packaging, and we have a problem with its
>>> install script. There are two ways to include a script. One is the
>>> (deprecated) <install> tag. In this case, we would put the bash script
>>> into the pom.xml, which is rather ugly, but it works. The bash script
>>> itself contains Maven variables, and these are replaced by maven before
>>> the script is used by the rpm plugin.
>>> The other way is to user the <installScriptlet> tag. This tag required
>>> the name of an external file, which contains the contents of the bash
>>> script. This is a much cleaner approach. However, the problem is the
>>> maven variables are not replaced in the external file, so the script
>>> doesn't work.
>>>
>>> I've looked at the source code of the rpm plugin, and it seems that it
>>> simply opens the external script file, and prints it line-by-line into
>>> the generated spec file, with no modification to the line.
>>>
>>> I think it would be a good idea to modify the rpm plugin code at this
>>> point, so that the line is first processed, expanding all maven
>>> variables.
>>>
>>> How can I do this? How is maven expanding its variables? Is there a
>>> method somewhere like MavenEnv.expandVariables(str) ?
>>>
>>> Thanks, Csaba
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
>>>
>>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
®¥@N

Re: Custom plugin - resolve variables loaded from a file

Posted by Gajo Csaba <cs...@cosylab.com>.
Well on initial testing it doesn't seem to work. Maybe the rpm plugin is 
supposed to load the file through some maven resource interface? Right 
now, it's doing this:

final Reader reader = new FileReader( scriptFile );

Where scriptFile is a java.io.File. I think this way, it's bypassing 
Maven's framework. This could be yet another bug...

Thanks for the help, Csaba


Ryan Connolly wrote:
> Hi. I have no experience with this plugin but it would seem that you
> could first filter the file as a typical maven resource and then have
> the plugin point to the filtered version?
>
>
>
> On 12/16/09, Gajo Csaba <cs...@cosylab.com> wrote:
>   
>> Hello,
>>
>> We're using the rpm plugin for packaging, and we have a problem with its
>> install script. There are two ways to include a script. One is the
>> (deprecated) <install> tag. In this case, we would put the bash script
>> into the pom.xml, which is rather ugly, but it works. The bash script
>> itself contains Maven variables, and these are replaced by maven before
>> the script is used by the rpm plugin.
>> The other way is to user the <installScriptlet> tag. This tag required
>> the name of an external file, which contains the contents of the bash
>> script. This is a much cleaner approach. However, the problem is the
>> maven variables are not replaced in the external file, so the script
>> doesn't work.
>>
>> I've looked at the source code of the rpm plugin, and it seems that it
>> simply opens the external script file, and prints it line-by-line into
>> the generated spec file, with no modification to the line.
>>
>> I think it would be a good idea to modify the rpm plugin code at this
>> point, so that the line is first processed, expanding all maven variables.
>>
>> How can I do this? How is maven expanding its variables? Is there a
>> method somewhere like MavenEnv.expandVariables(str) ?
>>
>> Thanks, Csaba
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>>     
>
>   


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


Re: Custom plugin - resolve variables loaded from a file

Posted by Ryan Connolly <ry...@gmail.com>.
Hi. I have no experience with this plugin but it would seem that you
could first filter the file as a typical maven resource and then have
the plugin point to the filtered version?



On 12/16/09, Gajo Csaba <cs...@cosylab.com> wrote:
> Hello,
>
> We're using the rpm plugin for packaging, and we have a problem with its
> install script. There are two ways to include a script. One is the
> (deprecated) <install> tag. In this case, we would put the bash script
> into the pom.xml, which is rather ugly, but it works. The bash script
> itself contains Maven variables, and these are replaced by maven before
> the script is used by the rpm plugin.
> The other way is to user the <installScriptlet> tag. This tag required
> the name of an external file, which contains the contents of the bash
> script. This is a much cleaner approach. However, the problem is the
> maven variables are not replaced in the external file, so the script
> doesn't work.
>
> I've looked at the source code of the rpm plugin, and it seems that it
> simply opens the external script file, and prints it line-by-line into
> the generated spec file, with no modification to the line.
>
> I think it would be a good idea to modify the rpm plugin code at this
> point, so that the line is first processed, expanding all maven variables.
>
> How can I do this? How is maven expanding its variables? Is there a
> method somewhere like MavenEnv.expandVariables(str) ?
>
> Thanks, Csaba
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

-- 
Sent from my mobile device

®¥@N

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