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

[MPMD-379] Upgrade to use PMD 7.0.0 by default #144

Merged
merged 13 commits into from
Apr 18, 2024

Conversation

mkolesnikov
Copy link

@mkolesnikov mkolesnikov commented Mar 20, 2024

https://issues.apache.org/jira/projects/MPMD/issues/MPMD-379

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MPMD-XXX] - Subject of the JIRA Ticket,
    where you replace MPMD-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@mkolesnikov mkolesnikov changed the title Feature/mpmd 379 pmd 7 [MPMD-379] PMD 7.0.0 support Mar 20, 2024
@adangel adangel self-requested a review March 20, 2024 06:07
Copy link
Member

@adangel adangel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

As mentioned in the comments, I'm going to release PMD 7.0.0 tomorrow, so this PR should be updated to use the final version then (which requires some more changes).

Since the switch from PMD6 to PMD7 is a major change, that impacts end users, this needs a bit more thought: The end users might need to migrate the rulesets as well, to be PMD 7 compatible. It's not just a change of the version...

I'm personally undecided, whether it would be OK to ship such an update in a minor version of maven-pmd-plugin. We obviously did this last time with 3.9.0, when upgrading from PMD 5.x to PMD 6.0.1.

In any case, we should also add this to the docs, e.g. here:

* Upgrading Notes
<<Note:>> Starting with PMD 6.0.0 and Maven PMD Plugin 3.9.0, the rules have been reorganized
into categories, e.g. <<</category/java/bestpractices.xml>>>. So when upgrading to
Maven PMD Plugin 3.9.0 you should review your plugin configuration and/or custom ruleset.
See {{{./examples/usingRuleSets.html}Using Rule Sets}} for more information.

Since there is already a solution on how to use maven-pmd-plugin with PMD 7 (see pmd/pmd#4478), which will also work with the final PMD 7.0.0 release, there is no pressure to hurry this upgrade. MPMD-379 should be maybe renamed to be "Upgrade to use PMD 7.0.0 by default".

For what's worth, my previous work on this topic:

@lapostoj
Copy link

lapostoj commented Apr 5, 2024

@adangel any blocker still with this one or could the plugin be released with the PMD 7 support? 🙂

Copy link
Member

@adangel adangel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates.

I've finished review now and will shortly push some commits to fix the remaining issues.

any blocker still with this one or could the plugin be released with the PMD 7 support?

The only point is: @mkolesnikov Could you indicate on the PR that you either have signed the Apache ICLA or "declare this contribution to be licenced under the Apache License" by ticking the checkbox? Thanks!

If there are no objections against the plan to ship this upgrade in the next minor version 3.22.0, I'll merge this the next days.

src/main/java/org/apache/maven/plugins/pmd/CpdReport.java Outdated Show resolved Hide resolved
src/site/apt/index.apt.vm Outdated Show resolved Hide resolved
src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm Outdated Show resolved Hide resolved
src/site/apt/index.apt.vm Outdated Show resolved Hide resolved
Copy link
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small issues

src/it/MPMD-379-JDK21/invoker.properties Outdated Show resolved Hide resolved
src/it/MPMD-379-JDK21/invoker.properties Outdated Show resolved Hide resolved
src/main/java/org/apache/maven/plugins/pmd/PmdReport.java Outdated Show resolved Hide resolved
Copy link
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now

@instagibb
Copy link

Is there anything holding this up now? Really keen to start using this without the version workarounds

@adangel adangel self-assigned this Apr 17, 2024
@adangel adangel changed the title [MPMD-379] PMD 7.0.0 support [MPMD-379] Upgrade to use PMD 7.0.0 by default Apr 18, 2024
@adangel adangel merged commit 89a7cdb into apache:master Apr 18, 2024
19 checks passed
@lapostoj
Copy link

Hey @adangel, thanks for getting the PR merged!
I believe the new version has not been deployed and pushed to the mvn repository, any step missing there?

@slawekjaranowski
Copy link
Member

@lapostoj
Copy link

Ah my bad I didn't know that part of the process!
Sounds great then! 🙌

@michael-o
Copy link
Member

@adangel That merge was a pile of junk. You imported all intermediate work into master making it impossible to trace down the actual change. Don't do that again please, always squash and rebase first. Clearly a -1 for the methodology.

@cstamas
Copy link
Member

cstamas commented May 4, 2024

@michael-o please abstain from statements like these. Any contribution is welcome, and mistakes do happen (yes, squashing the PR would be good, but this is not the end of the world). @adangel Thank you!

@michael-o
Copy link
Member

michael-o commented May 4, 2024

@michael-o please abstain from statements like these. Any contribution is welcome, and mistakes do happen (yes, squashing the PR would be good, but this is not the end of the world). @adangel Thank you!

I don't have a problem with the change, it is mostly fine. The merge is what I totally dislike.

@michael-o
Copy link
Member

michael-o commented May 4, 2024

This change introduced now a failing test which did no bubble up in CI, but should have:

[INFO] Running org.apache.maven.plugins.pmd.CpdReportTest
org.apache.maven.reporting.MavenReportException: Can't find CPD custom format xhtml: java.lang.ClassNotFoundException
        at org.apache.maven.plugins.pmd.exec.CpdExecutor.createRenderer(CpdExecutor.java:251)
        at org.apache.maven.plugins.pmd.exec.CpdExecutor.writeFormattedReport(CpdExecutor.java:226)
        at org.apache.maven.plugins.pmd.exec.CpdExecutor.lambda$run$1(CpdExecutor.java:181)
        at net.sourceforge.pmd.cpd.CpdAnalysis.performAnalysis(CpdAnalysis.java:203)
        at org.apache.maven.plugins.pmd.exec.CpdExecutor.run(CpdExecutor.java:174)
        at org.apache.maven.plugins.pmd.exec.CpdExecutor.execute(CpdExecutor.java:64)
        at org.apache.maven.plugins.pmd.CpdReport.executeCpd(CpdReport.java:204)
        at org.apache.maven.plugins.pmd.CpdReport.canGenerateReport(CpdReport.java:156)
        at org.apache.maven.reporting.AbstractMavenReport.execute(AbstractMavenReport.java:143)
        at org.apache.maven.plugins.pmd.AbstractPmdReportTestCase.generateReport(AbstractPmdReportTestCase.java:119)
        at org.apache.maven.plugins.pmd.CpdReportTest.testInvalidFormat(CpdReportTest.java:129)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at junit.framework.TestCase.runTest(TestCase.java:177)
        at junit.framework.TestCase.runBare(TestCase.java:142)
        at junit.framework.TestResult$1.protect(TestResult.java:122)
        at junit.framework.TestResult.runProtected(TestResult.java:142)
        at junit.framework.TestResult.run(TestResult.java:125)
        at junit.framework.TestCase.run(TestCase.java:130)
        at junit.framework.TestSuite.runTest(TestSuite.java:241)
        at junit.framework.TestSuite.run(TestSuite.java:236)
        at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:90)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:316)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:240)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:214)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:155)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
        at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
Caused by: java.lang.ClassNotFoundException: xhtml
        at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at org.apache.maven.plugins.pmd.exec.CpdExecutor.createRenderer(CpdExecutor.java:247)
        ... 31 more

Verififed against maven-pmd-plugin-3.21.2.

The actual reason is this change:

+                } catch (MavenReportException e) {
+                    LOG.error("Error while writing CPD report", e);
+                }

and the reason why it does not bubble up is because org.apache.maven.plugins.pmd.CpdReportTest.testInvalidFormat() does

        } catch (Exception e) {
            assertTrue(true);
        }

There is an exception thrown because the test file des not set localRepository parameter:

D:\Entwicklung\Projekte\maven-pmd-plugin [master ≡ +0 ~1 -0 !]> git diff -U0
diff --git a/src/test/resources/unit/invalid-format/cpd-invalid-format-plugin-config.xml b/src/test/resources/unit/invalid-format/cpd-invalid-format-plugin-config.xml
index e3cff6c2..aca6d08e 100644
--- a/src/test/resources/unit/invalid-format/cpd-invalid-format-plugin-config.xml
+++ b/src/test/resources/unit/invalid-format/cpd-invalid-format-plugin-config.xml
@@ -38,0 +39 @@ under the License.
+          <localRepository>${localRepository}</localRepository>

}
});
} catch (IOException e) {
LOG.error("Error while executing CPD", e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bad change -- it swallows the exception, build continues.

writeFormattedReport(report);
}
} catch (MavenReportException e) {
LOG.error("Error while writing CPD report", e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bad change -- it swallows the exception, build continues.

@michael-o
Copy link
Member

@mkolesnikov Please rework this with a followup PR. for now, the flow is broken.

@michael-o
Copy link
Member

@michael-o
Copy link
Member

Reminds of apache/maven-fluido-skin#39 (comment)

@adangel
Copy link
Member

adangel commented May 10, 2024

@adangel That merge was a pile of junk. You imported all intermediate work into master making it impossible to trace down the actual change. Don't do that again please, always squash and rebase first. Clearly a -1 for the methodology.

I was not aware, that the general rule of thumb for merging PRs is "squash and rebase". If this is the common
decision around the maven project, then I'd expect this to be clearly documented, e.g. on https://maven.apache.org/developers/conventions/git.html .
I'm missing there an example on how to merge PRs which consist of more than one commits. E.g. it says there
"commit it to a branch, fix it up, and merge the branch." instead of "commit it to a branch, fix it up and squash and rebase this branch onto master/main".
To be honest, I'm not sure if it would have prevented my merge push... (because I don't think I would have read this doc before pushing).

Following the discussion on apache/maven-fluido-skin#39 (comment) - which is very helpful - it seems
the decision is to try to have a linear history on the master/main branch:

Simply we require linear commit on master branch - from master perspective final result is important - we needn't history of work on PR in master.

This decision should be somehow officially be documented to be transparent for everyone...

For me, as a casual committer, who only pushes once every blue moon and working mostly on other projects, I would suggest to

  • Update the PR Template on GitHub with a section "Before merging... Maven Project requires a linear history, ... squash+rebase. Either before merge or whoever merges this. See also https://maven.apache.org/developers/conventions/git.html". I think, this would help to remember this decision.
  • Enforce via push/update hook to prevent merge commits pushed to master/main. GitHub has some options to enforce a linear history. I'm sure, the infra team can configure something similar on gitbox.apache.org. That would at least prevent someone like me from simply pushing a merge. Of course, it wouldn't prevent me from pushing the complete rebased history of a PR (which is also not desired)...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants