You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Lacoste, Dana" <da...@hp.com> on 2007/04/05 19:05:46 UTC

Problem with replaceregexp in maven 2

After much googling and attempting to find out how to make this work,
I'm emailing for help :)

The ant optional task "replaceregexp" replaces the contents of a file
by using a regular expression.  Because there are multiple regexp
libraries, ant loads the regexp class selected by a property after
the replaceregexp class is loaded.

See http://ant.apache.org/manual/OptionalTasks/replaceregexp.html
for info on the task or for more info on the regexp mapping, see:
http://ant.apache.org/manual/CoreTypes/regexp.html#implementation

So the simplest build.xml would look like this:
<project name="testrun">
  <property name="ant.regexp.regexpimpl"
value="org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp" />
  <target name="dochange">
    <echo>Classpath ${compileClasspath}</echo>
    <taskdef name="replaceregexp"
classname="org.apache.tools.ant.taskdefs.optional.ReplaceRegExp">
       <classpath path="${compileClasspath}"/>
    </taskdef>
    <replaceregexp file='${basedir}/test.h'
                   match='define VERSION'
                   replace='define TEST' />
  </target>
</project>

with test.h having the contents simply "define VERSION" and running
out-of-the-box binary distribution ant 1.6.5, this works fine.

Doing this in maven, though, has issues: maven's filter doesn't
do regular expressions, so I decided to call the build.xml using
antrun.  Note the commented-out dependencies from when I tried
all of the different regexp implementations!

Running out-of-the-box maven 2.0.4 I get the following error.
The class in question
(org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp)
is actually INSIDE the same .jar file that contains the replaceregexp
(org.apache.tools.ant.taskdefs.optional.ReplaceRegExp) : ant-nodeps.jar

Any suggestions?  From googling, I've seen that the maven 1.1 way to
deal
with this was to make the dependencies use "classloader root" but that's
not valid syntax in maven 2!

Thanks for any help or suggestions!

Dana Lacoste
San Diego, CA

--- error output ---

$ mvn process-resources
[INFO] Scanning for projects...
[INFO]
------------------------------------------------------------------------
----
[INFO] Building Test Project
[INFO]    task-segment: [process-resources]
[INFO]
------------------------------------------------------------------------
----
[INFO] [antrun:run {execution: update-version}]
[INFO] Executing tasks

dochange:
     [echo] Classpath C:\DOCUME~1\LACOSTE\d\target\classes;C:\Documents
and
Settings\lacoste\.m2\repository\ant\ant-nodeps\1.6.5\ant-nodeps-1.6.5.ja
r
Trying to override old definition of datatype replaceregexp
[INFO]
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] Error executing ant tasks

Embedded error: The following error occurred while executing this line:
C:\DOCUME~1\LACOSTE\d\build.xml:11: java.lang.ClassNotFoundException:
org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp
[INFO]
------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Apr 05 10:02:39 PDT 2007
[INFO] Final Memory: 2M/4M
[INFO]
------------------------------------------------------------------------


--- pom.xml ---

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example.project</groupId>
  <version>1.00-SNAPSHOT</version>
  <artifactId>project</artifactId>
  <packaging>pom</packaging>
  <name>Test Project</name>
  <dependencies>
    <!--
    <dependency>
      <groupId>oro</groupId>
      <artifactId>oro</artifactId>
      <version>2.0.8</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-jakarta-oro</artifactId>
      <version>1.6.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-apache-oro</artifactId>
      <version>1.6.5</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-apache-regexp</artifactId>
      <version>1.6.5</version>
    </dependency>
    <dependency>
      <groupId>jakarta-regexp</groupId>
      <artifactId>jakarta-regexp</artifactId>
      <version>1.4</version>
    </dependency>
    -->
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-nodeps</artifactId>
      <version>1.6.5</version>
      <scope>compile</scope>
    </dependency>
  </dependencies> 
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>update-version</id>
            <phase>process-resources</phase>
            <configuration>
              <tasks>
                <property name="compileClasspath"
refid="maven.compile.classpath"/>
                <ant antfile="build.xml" dir="." target="dochange"
inheritRefs="true"/>
                <!-- <taskdef name="replaceregexp"
classname="org.apache.tools.ant.taskdefs.optional.ReplaceRegExp">
                    <classpath refid="maven.compile.classpath" />
                </taskdef>
                <property name="ant.regexp.regexpimpl"
value="org.apache.tools.ant.util.regexp.JakartaRegexpRegexp"/>
                <property name="ant.regexp.regexpimpl"
value="org.apache.tools.ant.util.regexp.JakartaOroRegexp"/>
                <property name="ant.regexp.regexpimpl"
value="org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp"/>
                <replaceregexp file='${basedir}/test.h'
                               match='define VERSION'
                               replace='define TEST' />
                -->
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

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


Re: Problem with replaceregexp in maven 2

Posted by Jerome Lacoste <je...@gmail.com>.
On 4/6/07, Lacoste, Dana <da...@hp.com> wrote:
> Testing this has been exceedingly difficult (our project takes
> over an hour to build and some components are failing for me,
> so I keep tracking down changes rather than moving on to my
> testing :)
>
> But this SEEMS to work:
>
> In the parent pom (and all parent poms of affected antruns)
> add a build section that does nothing but call antrun.
>
> So if project looks like:
>
> project/pom.xml
> project/component1/pom.xml
> project/component1/libraryA/pom.xml
> project/component2/pom.xml
> project/component2/libraryB/pom.xml
>
> If I need to add an antrun with dependencies in LibraryB, but
> that Library depends on Library A (so if I'm building the whole
> project, LibraryA will always run first, but if I'm building LibraryB
> by itself, I can do so direct in its pom.
>
> I added the code below to project/pom.xml, project/component2/pom.xml,
> and project/component2/libraryB/pom.xml (well, technically that last
> one already worked, so I used the existing code, but the concept's
> the same.)
>
> This seems to make sure my dependencies are set, regardless of where
> I start the build or what order it's run in.  It's silly and redundant,
> but it seems to work :)
>
>   <build>
>     <plugins>
>       <plugin>
>         <artifactId>maven-antrun-plugin</artifactId>
>         <dependencies>
>           <dependency>
>             <groupId>ant</groupId>
>             <artifactId>ant-nodeps</artifactId>
>             <version>1.6.5</version>
>           </dependency>
>           <dependency>
>             <groupId>jakarta-regexp</groupId>
>             <artifactId>jakarta-regexp</artifactId>
>             <version>1.4</version>
>           </dependency>
>           <dependency>
>             <groupId>ant</groupId>
>             <artifactId>ant-jakarta-regexp</artifactId>
>             <version>1.6.1</version>
>           </dependency>
>         </dependencies>
>       </plugin>
>     </plugins>
>   </build>
>
> What do you think?  I'm fairly new to maven, so I'm trying
> to learn the intricacies of how it's supposed to work while
> I go along :)
>
> Thanks,
>
> Dana

Let's stay on list :)

You implemented the work-around proposed by Brett:

http://jira.codehaus.org/browse/MNG-1323#action_54948

So it looks like it should work.Kenney said underneath that there's no
working work-around. I am not sure if that applies to your particular
case.

Hope for you that future version of maven won't break your solution...
If I were you I would try maven 2.0.5 or 2.0.6 to see if that still
works. If that still works, you should also probably follow the list
and try any future release candidates for maven: you really want to
catch regressions before they get into an official release.

Cheers,

Jerome

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


Re: Problem with replaceregexp in maven 2

Posted by Jerome Lacoste <je...@gmail.com>.
On 4/5/07, Lacoste, Dana <da...@hp.com> wrote:
> OK, well, I still don't have a solution as to why this doesn't work :)
>
> But I've figured out a way to "make it go" at least :)
>
> http://www.nabble.com/Classloader-issue-with-ant-optional-tasks-in-a-hie
> rarchical-structure-tf2431669s177.html#a6780357
>
> That earlier post (October 12, 2006) showed someone with a similar
> problem.
> The problem appears to be that if the maven-antrun-plugin is called
> BEFORE
> you declare the dependencies as in below (i.e. from a different level
> pom
> in the project), then these dependencies will be IGNORED
>
> So you have to include the dependencies mentioned in the above link,
> in the format in the above link, in the first call to
> maven-antrun-plugin
> in the project.
>
> So, basically, you need to do it in the super pom.
>
> And if you want it to work in the "child" pom, I guess you have to do it
> there too.
>
> Any suggestions on how to make that work easier?  Perhaps a way of
> defining plugin dependencies in the parent pom without calling them, so that if
> the plugin is called anywhere in the child, it will inherit those
> dependencies properly?

Hei Dana,

http://jira.codehaus.org/browse/MNG-1323

One of the most voted issue I think.

Seems like there's no solution today. At least I don't have a work-around.

I would probably try to use a different approach when trying to
generate this file. Avoid using the ant run plugin and a regular
expression altogether. Can't you just use the standard resource
filtering (maybe filtering it twice, once for 'define VERSION' once
for 'define TEST') ?

If that doesn't work, you can also write your own maven2 regexp
plugin... That shouldn't be too much work.

Cheers,

Jerome (also Lacoste, from the other side of the ocean)

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


RE: Problem with replaceregexp in maven 2

Posted by "Lacoste, Dana" <da...@hp.com>.
OK, well, I still don't have a solution as to why this doesn't work :)

But I've figured out a way to "make it go" at least :)

http://www.nabble.com/Classloader-issue-with-ant-optional-tasks-in-a-hie
rarchical-structure-tf2431669s177.html#a6780357

That earlier post (October 12, 2006) showed someone with a similar
problem.
The problem appears to be that if the maven-antrun-plugin is called
BEFORE
you declare the dependencies as in below (i.e. from a different level
pom
in the project), then these dependencies will be IGNORED

So you have to include the dependencies mentioned in the above link,
in the format in the above link, in the first call to
maven-antrun-plugin
in the project.

So, basically, you need to do it in the super pom.

And if you want it to work in the "child" pom, I guess you have to do it
there too.

Any suggestions on how to make that work easier?  Perhaps a way of
defining
plugin dependencies in the parent pom without calling them, so that if
the
plugin is called anywhere in the child, it will inherit those
dependencies
properly?

Thanks,

Dana Lacoste

-----Original Message-----
From: Lacoste, Dana 
Sent: Thursday, April 05, 2007 10:06 AM
To: users@maven.apache.org
Subject: Problem with replaceregexp in maven 2

After much googling and attempting to find out how to make this work,
I'm emailing for help :)

The ant optional task "replaceregexp" replaces the contents of a file by
using a regular expression.  Because there are multiple regexp
libraries, ant loads the regexp class selected by a property after the
replaceregexp class is loaded.

See http://ant.apache.org/manual/OptionalTasks/replaceregexp.html
for info on the task or for more info on the regexp mapping, see:
http://ant.apache.org/manual/CoreTypes/regexp.html#implementation

So the simplest build.xml would look like this:
<project name="testrun">
  <property name="ant.regexp.regexpimpl"
value="org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp" />
  <target name="dochange">
    <echo>Classpath ${compileClasspath}</echo>
    <taskdef name="replaceregexp"
classname="org.apache.tools.ant.taskdefs.optional.ReplaceRegExp">
       <classpath path="${compileClasspath}"/>
    </taskdef>
    <replaceregexp file='${basedir}/test.h'
                   match='define VERSION'
                   replace='define TEST' />
  </target>
</project>

with test.h having the contents simply "define VERSION" and running
out-of-the-box binary distribution ant 1.6.5, this works fine.

Doing this in maven, though, has issues: maven's filter doesn't do
regular expressions, so I decided to call the build.xml using antrun.
Note the commented-out dependencies from when I tried all of the
different regexp implementations!

Running out-of-the-box maven 2.0.4 I get the following error.
The class in question
(org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp)
is actually INSIDE the same .jar file that contains the replaceregexp
(org.apache.tools.ant.taskdefs.optional.ReplaceRegExp) : ant-nodeps.jar

Any suggestions?  From googling, I've seen that the maven 1.1 way to
deal with this was to make the dependencies use "classloader root" but
that's not valid syntax in maven 2!

Thanks for any help or suggestions!

Dana Lacoste
San Diego, CA

--- error output ---

$ mvn process-resources
[INFO] Scanning for projects...
[INFO]
------------------------------------------------------------------------
----
[INFO] Building Test Project
[INFO]    task-segment: [process-resources]
[INFO]
------------------------------------------------------------------------
----
[INFO] [antrun:run {execution: update-version}] [INFO] Executing tasks

dochange:
     [echo] Classpath C:\DOCUME~1\LACOSTE\d\target\classes;C:\Documents
and
Settings\lacoste\.m2\repository\ant\ant-nodeps\1.6.5\ant-nodeps-1.6.5.ja
r
Trying to override old definition of datatype replaceregexp [INFO]
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] Error executing ant tasks

Embedded error: The following error occurred while executing this line:
C:\DOCUME~1\LACOSTE\d\build.xml:11: java.lang.ClassNotFoundException:
org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp
[INFO]
------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch [INFO]
------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Apr 05 10:02:39 PDT 2007 [INFO] Final Memory:
2M/4M [INFO]
------------------------------------------------------------------------


--- pom.xml ---

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example.project</groupId>
  <version>1.00-SNAPSHOT</version>
  <artifactId>project</artifactId>
  <packaging>pom</packaging>
  <name>Test Project</name>
  <dependencies>
    <!--
    <dependency>
      <groupId>oro</groupId>
      <artifactId>oro</artifactId>
      <version>2.0.8</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-jakarta-oro</artifactId>
      <version>1.6.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-apache-oro</artifactId>
      <version>1.6.5</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-apache-regexp</artifactId>
      <version>1.6.5</version>
    </dependency>
    <dependency>
      <groupId>jakarta-regexp</groupId>
      <artifactId>jakarta-regexp</artifactId>
      <version>1.4</version>
    </dependency>
    -->
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-nodeps</artifactId>
      <version>1.6.5</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>update-version</id>
            <phase>process-resources</phase>
            <configuration>
              <tasks>
                <property name="compileClasspath"
refid="maven.compile.classpath"/>
                <ant antfile="build.xml" dir="." target="dochange"
inheritRefs="true"/>
                <!-- <taskdef name="replaceregexp"
classname="org.apache.tools.ant.taskdefs.optional.ReplaceRegExp">
                    <classpath refid="maven.compile.classpath" />
                </taskdef>
                <property name="ant.regexp.regexpimpl"
value="org.apache.tools.ant.util.regexp.JakartaRegexpRegexp"/>
                <property name="ant.regexp.regexpimpl"
value="org.apache.tools.ant.util.regexp.JakartaOroRegexp"/>
                <property name="ant.regexp.regexpimpl"
value="org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp"/>
                <replaceregexp file='${basedir}/test.h'
                               match='define VERSION'
                               replace='define TEST' />
                -->
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

---------------------------------------------------------------------
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