Maven plugin to replace text in file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Maven plugin to replace text in file

David Hoffer
Hi,

I need to process a file during the build to replace constructs like this:

"allOf": [
  {
    "$ref": "#/definitions/Eligibility"
  }
],

to be:

"$ref": "#/definitions/Eligibility",

Where the $ref can point to anything.  How can I do this sort of writing
custom code?

-Dave
Reply | Threaded
Open this post in threaded view
|

Re: Maven plugin to replace text in file

Jürgen Weber
Ant to the rescue: ReplaceRegExp task

David Hoffer <[hidden email]> schrieb am So., 8. Nov. 2020, 18:01:

> Hi,
>
> I need to process a file during the build to replace constructs like this:
>
> "allOf": [
>   {
>     "$ref": "#/definitions/Eligibility"
>   }
> ],
>
> to be:
>
> "$ref": "#/definitions/Eligibility",
>
> Where the $ref can point to anything.  How can I do this sort of writing
> custom code?
>
> -Dave
>
Reply | Threaded
Open this post in threaded view
|

Re: Maven plugin to replace text in file

Bernd Eckenfels
In reply to this post by David Hoffer
You can use the antrun plugin to run a ant search and replace, or you an call a jruby or groovy script. Or is the exec plugin to run a java class. The resources plugin can replace placeholders, but that does not sound like the right tool for your case.

Gruss
Bernd
--
http://bernd.eckenfels.net
________________________________
Von: David Hoffer <[hidden email]>
Gesendet: Sunday, November 8, 2020 6:00:41 PM
An: Maven Users List <[hidden email]>
Betreff: Maven plugin to replace text in file

Hi,

I need to process a file during the build to replace constructs like this:

"allOf": [
  {
    "$ref": "#/definitions/Eligibility"
  }
],

to be:

"$ref": "#/definitions/Eligibility",

Where the $ref can point to anything.  How can I do this sort of writing
custom code?

-Dave
Reply | Threaded
Open this post in threaded view
|

Re: Maven plugin to replace text in file

David Hoffer
Yeah I was trying to use com.google.code.maven-replacer-plugin but I don't
think that can replace with the variable content found in what is to be
removed.

I'm not familiar with Ant ReplaceRegExp can anyone suggest how to do the
replacement?

-Dave

On Sun, Nov 8, 2020 at 10:19 AM Bernd Eckenfels <[hidden email]>
wrote:

> You can use the antrun plugin to run a ant search and replace, or you an
> call a jruby or groovy script. Or is the exec plugin to run a java class.
> The resources plugin can replace placeholders, but that does not sound like
> the right tool for your case.
>
> Gruss
> Bernd
> --
> http://bernd.eckenfels.net
> ________________________________
> Von: David Hoffer <[hidden email]>
> Gesendet: Sunday, November 8, 2020 6:00:41 PM
> An: Maven Users List <[hidden email]>
> Betreff: Maven plugin to replace text in file
>
> Hi,
>
> I need to process a file during the build to replace constructs like this:
>
> "allOf": [
>   {
>     "$ref": "#/definitions/Eligibility"
>   }
> ],
>
> to be:
>
> "$ref": "#/definitions/Eligibility",
>
> Where the $ref can point to anything.  How can I do this sort of writing
> custom code?
>
> -Dave
>
Reply | Threaded
Open this post in threaded view
|

Re: Maven plugin to replace text in file

Arnaud bourree-2
You want to reformat json file ... why not using jq in exec-maven-plugin ?

Arnaud

Le dim. 8 nov. 2020 à 19:14, David Hoffer <[hidden email]> a écrit :

> Yeah I was trying to use com.google.code.maven-replacer-plugin but I don't
> think that can replace with the variable content found in what is to be
> removed.
>
> I'm not familiar with Ant ReplaceRegExp can anyone suggest how to do the
> replacement?
>
> -Dave
>
> On Sun, Nov 8, 2020 at 10:19 AM Bernd Eckenfels <[hidden email]>
> wrote:
>
> > You can use the antrun plugin to run a ant search and replace, or you an
> > call a jruby or groovy script. Or is the exec plugin to run a java class.
> > The resources plugin can replace placeholders, but that does not sound
> like
> > the right tool for your case.
> >
> > Gruss
> > Bernd
> > --
> > http://bernd.eckenfels.net
> > ________________________________
> > Von: David Hoffer <[hidden email]>
> > Gesendet: Sunday, November 8, 2020 6:00:41 PM
> > An: Maven Users List <[hidden email]>
> > Betreff: Maven plugin to replace text in file
> >
> > Hi,
> >
> > I need to process a file during the build to replace constructs like
> this:
> >
> > "allOf": [
> >   {
> >     "$ref": "#/definitions/Eligibility"
> >   }
> > ],
> >
> > to be:
> >
> > "$ref": "#/definitions/Eligibility",
> >
> > Where the $ref can point to anything.  How can I do this sort of writing
> > custom code?
> >
> > -Dave
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Maven plugin to replace text in file

Oliver B. Fischer-2
IMHO not very portable, as jq is an external dependency and maybe not
available on every machine.

Am 09.11.20 um 18:03 schrieb Arnaud bourree:
> You want to reformat json file ... why not using jq in exec-maven-plugin ?
>
> Arnaud
>
--
N Oliver B. Fischer
A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
P +49 30 44793251
M +49 178 7903538
E [hidden email]
S oliver.b.fischer
J [hidden email]
X http://xing.to/obf


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Maven plugin to replace text in file

Christofer Dutz
I recently tend to use the groovy plugin to do stuff like at in a portable way.

Chris
________________________________
Von: Oliver B. Fischer <[hidden email]>
Gesendet: Montag, 9. November 2020 22:42
An: Maven Users List <[hidden email]>; Arnaud bourree <[hidden email]>
Betreff: Re: Maven plugin to replace text in file

IMHO not very portable, as jq is an external dependency and maybe not
available on every machine.

Am 09.11.20 um 18:03 schrieb Arnaud bourree:
> You want to reformat json file ... why not using jq in exec-maven-plugin ?
>
> Arnaud
>
--
N Oliver B. Fischer
A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
P +49 30 44793251
M +49 178 7903538
E [hidden email]
S oliver.b.fischer
J [hidden email]
X http://xing.to/obf


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Maven plugin to replace text in file

Oliver B. Fischer-2
+1

Am 10.11.20 um 08:15 schrieb Christofer Dutz:
> I recently tend to use the groovy plugin to do stuff like at in a
> portable way. 
>
> Chris
> ------------------------------------------------------------------------
>
--
N Oliver B. Fischer
A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
P +49 30 44793251
M +49 178 7903538
E [hidden email]
S oliver.b.fischer
J [hidden email]
X http://xing.to/obf