[ http://jira.codehaus.org/browse/MNG-2509?page=all ]
Davy Toch updated MNG-2509:
---------------------------
Attachment: pom.xml
> M2/ANT : Weird ClassCastException in <m:pom> in macrodef when calling
> Beanshell scripting.
> ------------------------------------------------------------------------------------------
>
> Key: MNG-2509
> URL: http://jira.codehaus.org/browse/MNG-2509
> Project: Maven 2
> Issue Type: Bug
> Components: Ant tasks
> Affects Versions: 2.0.4
> Environment: - ANT 1.6.5 (with bsh-2.0b4.jar in ANT_HOME/lib)
> - JDK 1.5
> Reporter: Davy Toch
> Attachments: build.xml, pom.xml
>
>
> Hi,
> In ANT, sometimes more than one artifact is generated from the same
> build file (e.g. myapp.jar, myapp-client.jar, myapp-with-deps.jar).
> If using the M2 plugin for ANT (currently 2.0.4), this would mean
> we would need three POM's for the above 3 artifacts. However, in the
> above case the 3 POM's would be almost identical.
> So I have taken the following approach in order to have only one generic
> POM:
> pom.xml (with ANT tokens _TOKEN_...):
> <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>be.steria.test</groupId>
> <artifactId>_TOKEN_ARTIFACTID_</artifactId>
> <packaging>_TOKEN_PACKAGING_</packaging>
> <version>1.5-SNAPSHOT</version>
> <description>Test artifact</description>
> <dependencies>
> <dependency>
> <groupId>log4j</groupId>
> <artifactId>log4j</artifactId>
> <version>1.2.9</version>
> <scope>compile</scope>
> </dependency>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>3.8.1</version>
> <scope>test</scope>
> </dependency>
> </dependencies>
> <distributionManagement>
> <repository>
> <id>repo_dev</id>
> <url>scp://localhost/m2demo/repo_dev</url>
> </repository>
> </distributionManagement>
> </project>
> build.xml:
> <project name="example-ant-using-m2-plugin" default="m2init"
> xmlns:m="antlib:org.apache.maven.artifact.ant">
> <macrodef name="create-pom">
> <attribute name="pomRefId"/>
> <attribute name="artifactId"/>
> <attribute name="packaging" default="jar"/>
> <sequential>
> <!-- IMPORTANT : derived POM files must be generated in the same
> folder as pom.xml, otherwise the paths, ... will be incorrect -->
> <copy file="pom.xml" filtering="true"
> toFile="[EMAIL PROTECTED]">
> <filterchain>
> <tokenfilter>
> <replacestring from="_TOKEN_ARTIFACTID_"
> to="@{artifactId}"/>
> <replacestring from="_TOKEN_PACKAGING_"
> to="@{packaging}"/>
> </tokenfilter>
> </filterchain>
> </copy>
> <m:pom id="@{pomRefId}" file="[EMAIL PROTECTED]"/>
> </sequential>
> </macrodef>
> <target name="m2init">
> <m:pom id="M2POM" file="pom.xml"/>
> <!-- causes ClassCastException in macrodef 'create-pom' -->
> <!--script language="beanshell"/-->
> <!-- create POM's on-the-fly (one for each artifact) -->
> <create-pom pomRefId="M2POM_MYAPP" artifactId="myapp"/>
> <create-pom pomRefId="M2POM_MYAPP_CLIENT" artifactId="myapp-client"/>
> <create-pom pomRefId="M2POM_MYAPP_WITH_DEPS"
> artifactId="myapp-with-deps"/>
>
> </target>
> <target name="package" depends="m2init">
> <!-- ... generate artifacts (pure ANT) ... -->
> </target>
> <target name="install" depends="package">
> <m:install file="myapp.jar"
> pomRefId="M2POM_MYAPP"/>
> <m:install file="myapp-client.jar"
> pomRefId="M2POM_MYAPP_CLIENT"/>
> <m:install file="myapp-with-deps.jar"
> pomRefId="M2POM_MYAPP_WITH_DEPS"/>
> </target>
> <target name="deploy">
> <m:deploy file="myapp.jar"
> pomRefId="M2POM_MYAPP"/>
> <m:deploy file="myapp-client.jar"
> pomRefId="M2POM_MYAPP_CLIENT"/>
> <m:deploy file="myapp-with-deps.jar"
> pomRefId="M2POM_MYAPP_WITH_DEPS"/>
> </target>
> </project>
> Now if I execute the above, everything works fine, but if I add <script
> language="beanshell"/> in the target 'm2init', then the following error
> is generated on the first <create-pom> call:
> "java.lang.ClassCastException: org.apache.maven.artifact.ant.Pom"
> Regards,
> Davy Toch
--
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