mojohaus / jaxb2-maven-plugin

JAXB2 Maven Plugin
https://www.mojohaus.org/jaxb2-maven-plugin/
Apache License 2.0
107 stars 77 forks source link

Plugin not m2e compatible (regression) #24

Closed andham closed 7 years ago

andham commented 9 years ago

As reported over at codehaus, the mojo is no longer compatible with m2e since the v2 rewrite. It's a major deficiency for those of us using Eclipse/m2e. The code uses the right APIs though, but it still doesn't work in m2e.

andham commented 9 years ago

I tested with Eclipse Mars (4.5.0) and m2e 1.6.0.20150526-2032 and a simple project based on IT "XJC-main". I get a NPE in the IDE:

null (org.codehaus.mojo:jaxb2-maven-plugin:2.1:xjc:xjc:generate-sources)

org.apache.maven.plugin.MojoExecutionException at org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo.performExecution(AbstractJavaGeneratorMojo.java:464) at org.codehaus.mojo.jaxb2.AbstractJaxbMojo.execute(AbstractJaxbMojo.java:200) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:331) at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1362) at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112) at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1360) at org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant.build(MojoExecutionBuildParticipant.java:52) at org.eclipse.m2e.core.internal.builder.MavenBuilderImpl.build(MavenBuilderImpl.java:137) at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:172) at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:1) at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1$1.call(MavenBuilder.java:115) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112) at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1.call(MavenBuilder.java:105) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:99) at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.execute(MavenBuilder.java:86) at org.eclipse.m2e.core.internal.builder.MavenBuilder.build(MavenBuilder.java:200) at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:205) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:245) at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:300) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303) at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:359) at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:382) at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144) at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55) Caused by: java.lang.NullPointerException at org.codehaus.mojo.jaxb2.shared.environment.ToolExecutionEnvironment.restore(ToolExecutionEnvironment.java:166) at org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo.performExecution(AbstractJavaGeneratorMojo.java:409) ... 33 more

lennartj commented 9 years ago

We need to create unit tests and an IT, to determine what m2e needs, in order to evaluate this. Anyone who uses eclipse and knows how to do that is welcome to develop and create a PR.

cpjones commented 9 years ago

When running in m2e, some of the classpath URLs passed to the classloader use the OSGi 'bundleresource' scheme, which causes ThreadContextClassLoaderBuilder.getClassPathElement() to toss an IllegalArgumentException. That exception appears to be getting swallowed. Adding another else clause to return 'bundleresource' URLs as strings is a possible fix.

bheku commented 8 years ago

I've also run into this problem. Although I don't know enough about the inner workings of Eclipse and plugins, with a little guidance, I wouldn't mind helping.

lennartj commented 8 years ago

OSGi class loaders are generally nice to work with - but I am uncertain how to re-create the conditions of Eclipse/M2E in a Maven unit test or integration test to enable verifying that our implementation works within the Eclipse IDE.

Does the M2E community have an integration into a pure Maven build environment to enable validating that an M2E integration works for plugins? Or is it currently impossible to verify an M2E integration without using the Eclipse IDE to run the plugin?

kirenpillay commented 8 years ago

I'm experiencing the same problem. Is there a workaround?

andham commented 8 years ago

Not that I'm aware of. I'm still using v1.6 due to this.

lennartj commented 8 years ago

Well - the problems re-creating the conditions of Eclipse/M2E within a pure Maven build should not be something unique to this plugin. Do the folks from the M2E community provide an integration into a pure Maven build environment as I indicated above - or do they not?

Otherwise, the request for an IT (not running the build within Eclipse) from someone who can create the M2E integration is still appreciated. There was no M2E-verifying IT in the 1.x codebase versions of this plugin - and there is still no IT in the codebase currently.

IMHO, plugins should really not need to implement special support for M2E; that is reverse logic. In case the M2E community requires something special from plugins (as is obviously the case), it is their responsibility to provide either better Maven integration or mechanics for an IT.

samized commented 8 years ago

http://www.eclipse.org/m2e/documentation/m2e-extension-development.html#java-code-generation-overview

andham commented 8 years ago

@samized That section talks about creating a m2e extension/connector. That's not what we're talking about here, but rather making the plugin m2e compatible. Which is used to be in v1.

lennartj commented 8 years ago

There is no integration test in the V1 or V2 codebase which validates M2E compatibility. Feel free to provide one.

sergiomichels commented 8 years ago

+1

posl01 commented 7 years ago

I want to go back to version 1.6 too. Where can I find documentation?

metas-ts commented 7 years ago

Hi, please let me first say that I'm not a member of this project's community and when I added this issue's URL to my commit message, I just wanted to document my step and wasn't aware that github would make it show up in here. So I just wanted to get my build working and did not intent to play any games or otherwise put pressure on this community. I find it plausible what @lennartj wrote further up.

However, if you want to see how we downgraded to 1.6 and make it work with a recent java-version, you can take a look at our parent pom:

Btw, if you use eclipse, you might wat to also add -Djavax.xml.accessExternalSchema=all to your eclipse.ini.

sergiomichels commented 7 years ago

@metas-ts modifying the eclipse.ini is supposed to fix the integration?

metas-ts commented 7 years ago

@sergiomichels no, unfortunately not. It just allows me to run eclipse, java-8, the m2e plugin and the jaxb-connector all together with jaxb-maven-plugin-1.6 (as opposed to the recent version 2.x)

dskow commented 7 years ago

A java.lang.NullPointerException in org.codehaus.mojo.jaxb2.shared.environment ToolExecutionEnvironment.restore(ToolExecutionEnvironment.java:182)

I have confirmed this null pointer issue on Eclipse Neon using a version 2.2 of the maven plugin. It appears that someone fixed the issue with the m2e eclipse plugin for the 2.3 version of the maven plugin.

So change to version 2.3.

org.codehaus.mojo jaxb2-maven-plugin 2.3

If you change to jaxb2-maven-plugin to version 2.3, the problem goes away.

kuraidai commented 7 years ago

I use Eclipse Neon and configured to use 2.3 version jaxb2-maven-plugin, the NPE is still there:

Description Resource Path Location Type null (org.codehaus.mojo:jaxb2-maven-plugin:2.3:xjc:generate-classes:generate-sources)

org.apache.maven.plugin.MojoExecutionException at org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo.performExecution(AbstractJavaGeneratorMojo.java:484) at org.codehaus.mojo.jaxb2.AbstractJaxbMojo.execute(AbstractJaxbMojo.java:257) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:331) at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1362) at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112) at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1360) at org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant.build(MojoExecutionBuildParticipant.java:52) at org.eclipse.m2e.core.internal.builder.MavenBuilderImpl.build(MavenBuilderImpl.java:137) at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:172) at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:1) at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1$1.call(MavenBuilder.java:115) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112) at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1.call(MavenBuilder.java:105) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:99) at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.execute(MavenBuilder.java:86) at org.eclipse.m2e.core.internal.builder.MavenBuilder.build(MavenBuilder.java:200) at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246) at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304) at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360) at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383) at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144) at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55) Caused by: java.lang.NullPointerException at org.codehaus.mojo.jaxb2.shared.environment.ToolExecutionEnvironment.restore(ToolExecutionEnvironment.java:182) at org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo.performExecution(AbstractJavaGeneratorMojo.java:429) ... 33 more pom.xml /pain-schema line 37 Maven Build Problem

dskow commented 7 years ago

After a clean install of eclipse neon with jaxb2-maven-plugin version 2.3, I am seeing the null pointer again at org.codehaus.mojo.jaxb2.shared.environment.ToolExecutionEnvironment.restore(ToolExecutionEnvironment.java:182) It does not appear to have been fixed.

lennartj commented 7 years ago

Correct - just to iterate:

"... the request for an IT (not running the build within Eclipse) from someone who can create the M2E integration is still appreciated. There was no M2E-verifying IT in the 1.x codebase versions of this plugin - and there is still no IT in the codebase currently."

davidsedlar commented 7 years ago

Any new developments regarding this? The null pointer is really a bummer. However if I Run->Maven install it compiles the XSD files fine and the error goes away, but only until the next time I change the XSD files, after which the null pointer comes back.

andham commented 7 years ago

I've tracked the problem to an IllegalArgumentException in ThreadContextClassLoaderBuilder.getClassPathElement: Unknown protocol [bundleresource]; could not handle URL [bundleresource://554.fwk41975027/]

abeldlfa commented 7 years ago

Did someone solve the problem?. I have used the 2.3.1 plugin version and the mistake continues.

davidsedlar commented 7 years ago

The 2.3.1 released fixed it for me. Are you sure you are using the latest version?

kirenpillay commented 7 years ago

Yes 2.3.1 fixed it for me as well.

On 26 Apr 2017 8:23 PM, "David Sedlar" notifications@github.com wrote:

The 2.3.1 released fixed it for me. Are you sure you are using the latest version?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mojohaus/jaxb2-maven-plugin/issues/24#issuecomment-297498961, or mute the thread https://github.com/notifications/unsubscribe-auth/AFXRhMDBufe72dPT9CpG4EXGS1a_oXQUks5rz4u3gaJpZM4FpRNi .