Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop execute() override workaround #137

Closed
wants to merge 1 commit into from

Conversation

hboutemy
Copy link
Contributor

@hboutemy hboutemy commented Oct 11, 2023

see discussion https://lists.apache.org/thread/ko6g9sgwysm46t9j0nqw4bj6krj72q2b

for quick run limited to the failing IT:

mvn -Dinvoker.test=CreateReport clean verify -P integration-test

issue visible in target/it/CreateReport/build.log:

Caused by: java.lang.NullPointerException: Cannot invoke "org.apache.maven.doxia.tools.SiteTool.getSiteLocales(String)" because "this.siteTool" is null
    at org.apache.maven.reporting.AbstractMavenReport.getLocale (AbstractMavenReport.java:400)

AbstractMavenReport.siteTool is not injected as it should as it is declared as @Component https://github.com/apache/maven-reporting-impl/blob/maven-reporting-impl-4.0.0-M10/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java#L150

@hboutemy hboutemy marked this pull request as draft October 11, 2023 13:24
@hboutemy
Copy link
Contributor Author

hboutemy commented Oct 11, 2023

looking at target/classes/META-INF/maven/plugin.xml line 158 (= <requirements> for aspectj-report goal)

  • siteTool is not listed
  • siteRenderer is listed because it has been declared in AcjReportMojo.java, but it should not have been declared here as it is already available in AbstractMavenReport

it looks you found a bug in plugin-tools on @Component inheritence...

@hboutemy
Copy link
Contributor Author

https://issues.apache.org/jira/browse/MPLUGIN-483 created

@michael-o
Copy link

looking at target/classes/META-INF/maven/plugin.xml line 158 (= <requirements> for aspectj-report goal)

* `siteTool` is not listed

* `siteRenderer` is listed because it has been declared in `AcjReportMojo.java`, but it should not have been declared here as it is already available in `AbstractMavenReport`

it looks you found a bug in plugin-tools on @Component inheritence...

I wonder why this is the case? Because one so and the other one so? Mixed one? All other reporting plugins don't fail with Doxia 2.0.0 deps...

@hboutemy
Copy link
Contributor Author

hboutemy commented Oct 11, 2023

looking at apache/maven-javadoc-plugin@master...doxia-2.0.0

you added a new @Component SiteTool siteTool field

oh, public class JavadocReport extends AbstractJavadocMojo implements MavenMultiPageReport {: maven-reporting-impl is not used here...

@kriegaex
Copy link
Contributor

kriegaex commented Oct 12, 2023

  • siteRenderer is listed because it has been declared in AcjReportMojo.java, but it should not have been declared here as it is already available in AbstractMavenReport

Well, the site renderer has been in AcjReportMojo since kaare put it there in 2005 when the class was introduced. Last time it was touched in 2011 when Robert Scholte changed the type from SiteRenderer to just Renderer. Nobody has ever touched it since then, because it worked. Only last year, the site renderer was introduced into the super class, so only now when upgrading the dependency, this field becomes redundant. When @michael-o said this on the mailing list, ...

I had these NPEs when I started to migrate reporting plugins and both the plugin
and the super class contained the same fields which created conflicts. After I
have removed them from the plugin and used the super ones all went fine.

... I tried to remove the now redundant field and its getter, but it did not solve the problem with siteTool not being injected, so I did not commit that change yet. But after MPLUGIN-483 will have been fixed and that fix released, I think I can continue to clean up a bit. OTOH, I think I could remove the field now and my ugly workaround to override execute() would still work.

@kriegaex
Copy link
Contributor

One more funny thing that I noticed was that it seems all protected fields are affected, not just @Component but also @Parameter ones. They will be injected into the extending class, if redeclared there, but not into the super class. So, step by step I redundantly redeclared all protected parent fields in my mojo and did this experimentally:

    @Override
    public void execute() throws MojoExecutionException {
        super.siteTool = this.siteTool;
        super.siteRenderer = this.siteRenderer;
        super.project = this.project;
        super.reactorProjects = this.reactorProjects;
        super.repoSession = this.repoSession;
        super.remoteProjectRepositories = this.remoteProjectRepositories;
        super.siteDirectory = this.siteDirectory;
        super.mojoExecution = this.mojoExecution;
        super.execute();
    }

If any of these assignments are missing, the CreateReport integration test fails. Is there anything that needs to be done in a mojo extending AbstractMavenReport to avoid this problem? It is hard to imagine that there is just this one mojo extending it and having this problem. Should that not have been noticed before? Maybe there is something wrong in my plugin. Otherwise, MPLUGIN-483 would be a huge bug indeed.

@kriegaex
Copy link
Contributor

Instead of redundantly adding the fields and initialisations, it also helps to manually patch plugin.xml to contain the relevant parent class <parameter> + corresponding <configuration> entries for @Parameters and the relevant <requirement> entries for @Components. That proves that if Plugin Tools would correctly generate them, the plugin would be fine.

@kriegaex
Copy link
Contributor

kriegaex commented Oct 17, 2023

@hboutemy, @michael-o: If I copy the source code of org.apache.maven.reporting.AbstractMavenReport into my project as class org.apache.maven.reporting.AbstractMavenReportXXX and make my org.codehaus.mojo.aspectj.AjcReportMojo extend AbstractMavenReportXXX, the integration test passes. If I switch back to extending class AbstractMavenReport from the external dependency, it fails again. Is there any mojo setting I need to use for this to work?

@michael-o
Copy link

@hboutemy, @michael-o: If I copy the source code of org.apache.maven.reporting.AbstractMavenReport into my project as class org.apache.maven.reporting.AbstractMavenReportXXX and make my org.codehaus.mojo.aspectj.AjcReportMojo extend AbstractMavenReportXXX, the integration test passes. If I switch back to extending class AbstractMavenReport from the external dependency, it fails again. Is there any mojo setting I need to use for this to work?

While I don't have an answer from the top of my head, did you compare your plugin with the other reporting plugins in the doxia-2.0.0 I have provided? Did you see any logical difference?

@kriegaex
Copy link
Contributor

did you compare your plugin with the other reporting plugins in the doxia-2.0.0 I have provided? Did you see any logical difference?

@michael-o, I am not sure what you are talking about. Where did you provide anything?

@michael-o
Copy link

did you compare your plugin with the other reporting plugins in the doxia-2.0.0 I have provided? Did you see any logical difference?

@michael-o, I am not sure what you are talking about. Where did you provide anything?

Here: https://www.mail-archive.com/users@maven.apache.org/msg145060.html

@kriegaex
Copy link
Contributor

kriegaex commented Oct 17, 2023

Sorry, if I sound stupid, but I never understood that remark on the mailing list:

You can also look at all of your reporting plugins in branch doxia-2.0.0 you'll see all necessary migration magic from me. The PR with finalizing the method is good and already merged.

@michael-o: Which repository? Which files? Do you have a link for me? I am utterly lost. How can any of your changes contain migration magic relating to my reporting plugins? I really do not want to get on your nerves or play stupid, I simply do not have enough information to understand what you are talking about. Terse is nice, but too terse means lenghty discussions like these. I am keen to follow your advice, but first I need to understand it and find what you are trying to point me to.

@michael-o
Copy link

michael-o commented Oct 17, 2023

Sorry, if I sound stupid, but I never understood that remark on the mailing list:

You can also look at all of your reporting plugins in branch doxia-2.0.0 you'll see all necessary migration magic from me. The PR with finalizing the method is good and already merged.

@michael-o: Which repository? Which files? Do you have a link for me? I am utterly lost. How can any of your changes contain migration magic relating to my reporting plugins? I really do not want to get on your nerves or play stupid, I simply do not have enough information to understand what you are talking about. Terse is nice, but too terse means lenghty discussions like these. I am keen to follow your advice, but first I need to understand it and find what you are trying to point me to.

My apologies, the text contains a significant typo. It should read:

You can also look at all of our reporting plugins in branch doxia-2.0.0 you'll see all necessary migration magic from me. The PR with finalizing the method is good and already merged.

This refers to all reporting plugin under org.apache.maven.plugins group id. Is that better?

Again, my bad, I did not proof-read.

@kriegaex
Copy link
Contributor

kriegaex commented Oct 18, 2023

This refers to all reporting plugin under org.apache.maven.plugins group id. Is that better?

@michael-o: No. Maven Central lists 67 entries for that group ID. Firstly, I do not know in which plugins I could find a situation comparable to this one. Secondly, I would not know what to look for and what to compare. Thirdly, here is a reproducer with some additional findings, which is debuggable by someone as knowledeable and experienced in building and converting plugins as you are. Why was I asked to provide a reproducer on the mailing list, if now is is not being used? Last but not least, what about MPLUGIN-483? It has neither been worked on nor closed as invalid. Why are you assuming that the problem sits in front of the computer, if @hboutemy thinks that there is a bug in Maven Plugin Plugin or its infrastructure?

@michael-o
Copy link

This refers to all reporting plugin under org.apache.maven.plugins group id. Is that better?

@michael-o: No. Maven Central lists 67 entries for that group ID. Firstly, I do not know in which plugins I could find a situation comparable to this one. Secondly, I would not know what to look for and what to compare. Thirdly, here is a reproducer with some additional findings, which is debuggable by someone as knowledeable and experienced in building and converting plugins as you are. Why was I asked to provide a reproducer on the mailing list, if now is is not being used? Last but not least, what about MPLUGIN-483? It has neither been worked on nor closed as invalid. Why are you assuming that the problem sits in front of the computer, if @hboutemy thinks that there is a bug in Maven Plugin Plugin or its infrastructure?

A good amount of them is reporting only and documented on our project page. I encourage you to investigate yourself.

@kriegaex
Copy link
Contributor

kriegaex commented Oct 18, 2023

@michael-o, are you trying to mock me by responding fuzzily and refusing to share a link to some piece of code you want me to look at? How am I supposed to know what you are talking about what what "our project" is? And why are you ignoring my new finding from #137 (comment)? That should be a clue for you to get to the bottom of this. Why does it make a difference, if the parent class is in a dependency (maven-reporting-impl) vs. the same project as the plugin, if the source code of both is identical? Is that not proof that I did in fact investigate and try to help you guys find the root cause of the problem?

@michael-o
Copy link

Here is the listing: https://maven.apache.org/plugins/index.html. Filter for type R, then checkout the plugin's repo for the branch doxia-2.0.0.

kriegaex added a commit that referenced this pull request Oct 19, 2023
The root cause for the problem was the 'mojoDependencies' config for
maven-plugin-plugin, which aimed to fix
https://issues.apache.org/jira/browse/MPLUGIN-328 by the workaround from
mojohaus/aspectj-maven-plugin#34. That old
workaround was actually bad to begin with, because it only included
dev.aspectj:aspectj-maven-plugin, therefore implicitly excluding other
dependencies like maven-reporting-impl. The latter, however, contains
class AbstractMavenReport, which led to all super class @parameter and
@component properties to not be included in the generated plugin.xml.

Relates to #137.
Solves https://issues.apache.org/jira/browse/MPLUGIN-483.
@kriegaex
Copy link
Contributor

kriegaex commented Oct 19, 2023

I managed to solve the problem, see the explanation in my MPLUGIN-483 comment.

@michael-o, @hboutemy, the problem was not in the code but in the POM. I had hoped that one of you would help me identify the root cause, because it was quite tricky to find for a plugin noob like me, especially because the bug was old, but only manifested itself now after the upgrade to Doxia 2. I am sure, you would have found it in a fraction of the time that I needed. Anyway, thanks for the well-meant advice, even though it did not help me in this particular case.

@kriegaex kriegaex closed this Oct 19, 2023
@michael-o
Copy link

I managed to solve the problem, see the explanation in my MPLUGIN-483 comment.

@michael-o, @hboutemy, the problem was not in the code but in the POM. I had hoped that one of you would help me identify the root cause, because it was quite tricky to find for a plugin noob like me, especially because the bug was old, but only manifested itself now after the upgrade to Doxia 2. I am sure, you would have found it in a fraction of the time that I needed. Anyway, thanks for the well-meant advice, even though it did not help me in this particular case.

That is fantastic news. I know that kind of hacks from elsewhere, but not this problem. We all have learned that every hack can incur a very high cost at the end...

@hboutemy
Copy link
Contributor Author

I had hoped that one of you would help me identify the root cause, [...] I am sure, you would have found it in a fraction of the time that I needed. Anyway, thanks for the well-meant advice, even though it did not help me in this particular case.

@kriegaex are you serious? Do you really think we did not work hard to help?
next time, you'll discover what not helping means

@kriegaex
Copy link
Contributor

kriegaex commented Oct 20, 2023

I said it (the advice) did not help me, not you did not help me. That pronoun makes a difference, I think. So please, read carefully.

I do appreciate that at least you (Hervé) actually checked out my reproducer, found out about the missing plugin.xml entries and raised a bug over there, albeit an invalid one, because the root cause was not in Maven but in the reproducer project.

That someone dismissed MPLUGIN-483 without so much as a look at the project, falsely stating

Afaik Mojo annotations were never scanned in class hierarchy, and it was done on purpose.

was not helpful at all. Thanks also for supporting my objection over there.

I do, just like I said, appreciate Michael's hints, too, even though they were not helpful either. He meant well, which is why I called them "well-meant" before. I have, however, problems understanding why usually, just like in this case, people on the mailing list, ask for a reproducer, but then in the face of one instead of using it to debug the problem, they tell me things like (paraphrasing): "I never had that problem. Just look at how I did it in other (unnamed) projects and compare." Combine that with a back-and-forth meta discussion, me trying finding out which exact project and piece(s) of code Michael was suggesting me to look at. I actually looked at 5 projects with doxia-2.0 branches and did not find any major differences in their code, compared to this one. Nobody, including Michael, could have known that the problem was not in the code or in bumped version numbers in the POM, but in another place in the POM. Hence the reproducer! What I did say and still believe to be true, however, is that if an expert like Michael would have debugged this case instead of me, he would have found the root cause in a fraction of the time I needed, because I had no idea where to look. I was hoping that Michael, an expert with an impressive track record of having upgraded many major Maven plugins to Doxia 2, would - without even "working hard", as Hervé called it - have found the root cause in a very short time frame.

Sorry for explaining so much, but I do not want to be misunderstood again and certainly not risk pissing anyone off, refusing to help me in the future. BTW, I do not find it particularly nice to threaten users like that. Please do accept some criticism along with my sincere thanks, though. I think, that should be permitted.

@kriegaex
Copy link
Contributor

kriegaex commented Oct 20, 2023

That is fantastic news. I know that kind of hacks from elsewhere, but not this problem. We all have learned that every hack can incur a very high cost at the end...

@michael-o, I could not agree more, especially because workarounds, even if originally meant to be temporary ones, often remain in projects longer than their creators, leaving the task to figure out problems caused by them to future generations. Either way, it was an opportunity to leave the camp ground behind a little cleaner than I found it, according to the old boyscout rule.

That old plugin probably needs more maintenance work by someone who knows much better than I how to develop good Maven plugins. I am simply trying to keep the plugin up to date and working with new dependency versions (AspectJ, JDK, libraries, plugins), adding features rather infrequently, because the plugin basically does what it is supposed to already.

kriegaex added a commit that referenced this pull request Oct 20, 2023
The root cause for the problem was the 'mojoDependencies' config for
maven-plugin-plugin, which aimed to fix
https://issues.apache.org/jira/browse/MPLUGIN-328 by the workaround from
mojohaus/aspectj-maven-plugin#34. That old
workaround was actually bad to begin with, because it only included
dev.aspectj:aspectj-maven-plugin, therefore implicitly excluding other
dependencies like maven-reporting-impl. The latter, however, contains
class AbstractMavenReport, which led to all super class @parameter and
@component properties to not be included in the generated plugin.xml.

Relates to #137.
Solves https://issues.apache.org/jira/browse/MPLUGIN-483.
@kriegaex kriegaex added this to the Release 1.14 milestone Oct 20, 2023
kriegaex added a commit that referenced this pull request Oct 20, 2023
The root cause for the problem was the 'mojoDependencies' config for
maven-plugin-plugin, which aimed to fix
https://issues.apache.org/jira/browse/MPLUGIN-328 by the workaround from
mojohaus/aspectj-maven-plugin#34. That old
workaround was actually bad to begin with, because it only included
dev.aspectj:aspectj-maven-plugin, therefore implicitly excluding other
dependencies like maven-reporting-impl. The latter, however, contains
class AbstractMavenReport, which led to all super class @parameter and
@component properties to not be included in the generated plugin.xml.

Relates to #137.
Solves https://issues.apache.org/jira/browse/MPLUGIN-483.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants