[ 
https://issues.apache.org/jira/browse/MNG-6800?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16969743#comment-16969743
 ] 

glmapper edited comment on MNG-6800 at 11/8/19 2:01 AM:
--------------------------------------------------------

h2. Background:

Write an idea plugin for maven project structure conversion
h2. Issue

I encountered a ClassCastException when I tried to use the API provided by 
maven-model to add a plugin element in pom

 

details:

 
{code:java}
//代码占位符
Plugin plugin = new Plugin();
plugin.setGroupId("com.alipay.sofa");
plugin.setArtifactId("sofa-ark-maven-plugin");
plugin.setVersion("1.1.0-SNAPSHOT");
//1
final Xpp3Dom config = createPluginConfiguration();
plugin.setConfiguration(config);

model.getBuild().getPlugins().add(plugin);
FileWriter fileWriter = new FileWriter(pomPath);
//2
writer.write(fileWriter,model);
{code}
1.here, config object is loaded by PluginClassLoader(idea provided)

 

2.org.apache.maven.model.io.xpp3.MavenXpp3Writer#writePlugin:1417 version is 
3.3.9, 

 
{code:java}
//代码占位符
if ( plugin.getConfiguration() != null )
{
    // 3
    ((Xpp3Dom) plugin.getConfiguration()).writeToSerializer( NAMESPACE, 
serializer );
}
{code}
 

3. Xpp3Dom is loaded by URLClassLoader, so there will be throw 
ClassCastException

 

In the ConfigurationContainer class, the configuration property type is Object, 
But in actual processing, it will be converted to Xpp3Dom, why not directly use 
Xpp3Dom as the type description of the configuration

 

 

 


was (Author: glmapper):
h2. Background:

Write an ide plugin for maven project structure conversion
h2. Issue

I encountered a ClassCastException when I tried to use the API provided by 
maven-model to add a plugin element in pom

 

details:

 
{code:java}
//代码占位符
Plugin plugin = new Plugin();
plugin.setGroupId("com.alipay.sofa");
plugin.setArtifactId("sofa-ark-maven-plugin");
plugin.setVersion("1.1.0-SNAPSHOT");
//1
final Xpp3Dom config = createPluginConfiguration();
plugin.setConfiguration(config);

model.getBuild().getPlugins().add(plugin);
FileWriter fileWriter = new FileWriter(pomPath);
//2
writer.write(fileWriter,model);
{code}
1.here, config object is loaded by PluginClassLoader(idea provided)

 

2.org.apache.maven.model.io.xpp3.MavenXpp3Writer#writePlugin:1417 version is 
3.3.9, 

 
{code:java}
//代码占位符
if ( plugin.getConfiguration() != null )
{
    // 3
    ((Xpp3Dom) plugin.getConfiguration()).writeToSerializer( NAMESPACE, 
serializer );
}
{code}
 

3. Xpp3Dom is loaded by URLClassLoader, so there will be throw 
ClassCastException

 

In the ConfigurationContainer class, the configuration property type is Object, 
But in actual processing, it will be converted to Xpp3Dom, why not directly use 
Xpp3Dom as the type description of configuration

 

 

 

> 在执行 writePlugin 时 发生 ClassCastException 
> ----------------------------------------
>
>                 Key: MNG-6800
>                 URL: https://issues.apache.org/jira/browse/MNG-6800
>             Project: Maven
>          Issue Type: Improvement
>          Components: Artifacts and Repositories
>    Affects Versions: 3.3.9
>            Reporter: glmapper
>            Priority: Blocker
>             Fix For: waiting-for-feedback
>
>
> {code:java}
> //代码占位符
> java.lang.ClassCastException: org.codehaus.plexus.util.xml.Xpp3Dom cannot be 
> cast to org.codehaus.plexus.util.xml.Xpp3Domjava.lang.ClassCastException: 
> org.codehaus.plexus.util.xml.Xpp3Dom cannot be cast to 
> org.codehaus.plexus.util.xml.Xpp3Dom at 
> org.apache.maven.model.io.xpp3.MavenXpp3Writer.writePlugin(MavenXpp3Writer.java:1417)
>  at 
> org.apache.maven.model.io.xpp3.MavenXpp3Writer.writeBuild(MavenXpp3Writer.java:329)
>  at 
> org.apache.maven.model.io.xpp3.MavenXpp3Writer.writeModel(MavenXpp3Writer.java:1115)
>  at 
> org.apache.maven.model.io.xpp3.MavenXpp3Writer.write(MavenXpp3Writer.java:100)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to