Skip to content

[core] Allow deep copying of RuleSets#464

Merged
adangel merged 2 commits into
pmd:masterfrom
jsotuyod:deep-copy-rulesets
Aug 24, 2017
Merged

[core] Allow deep copying of RuleSets#464
adangel merged 2 commits into
pmd:masterfrom
jsotuyod:deep-copy-rulesets

Conversation

@jsotuyod

Copy link
Copy Markdown
Member
  • Copy constructor for RuleSets
  • Copy constructor for RuleSet
  • Copy method for Rules
  • I'm still sharing a few objects that are not strictly immutables, but
    treated as them

This would allow to start resolving the issue commented on #194 (comment)

This change adds new methods, but doesn't modify existing APIs, so it would be safe for 5.8.0.

However, I'd still want a second opinion as to wether the classes that I allow to share are really to be treated / converted to immutables, or I should extend deep copying to them.

  • The PR is submitted against master. The PMD team will merge back to support branches as needed.
  • mvn test passes.
  • mvn checkstyle:check passes. Check this for more info

@jsotuyod jsotuyod added an:enhancement An improvement on existing features / rules in:pmd-internals Affects PMD's internals is:WIP For PRs that are not fully ready, or issues that are actively being tackled labels Jun 22, 2017
@jsotuyod jsotuyod added this to the 5.8.0 milestone Jun 22, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In AbstractPropertySource there are already some methods, that may help here (or need to be adjusted to do a real deep copy): copyPropertyDescriptors, hasDescriptor.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll check those, good to know. Thanks!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm now using hasDescriptor, but do not use copyPropertyDescriptors (it just creates a new list with the same property descriptor instances), but I'd rather call the definePropertyDescriptor method to allow rules overriding the method applying their logic rather than just assigning the list.

@adangel

adangel commented Jun 24, 2017

Copy link
Copy Markdown
Member

Since this is not really required for 5.8.0, I'm moving this to 6.0.0.

There would be more to do in Rule - e.g. use correct getter/setter method names (e.g. setUsesDFA(true) instead of usesDFA()).

I'm still sharing a few objects that are not strictly immutables, but treated as them
Which one do you mean? The property values?

@adangel adangel modified the milestones: 6.0.0, 5.8.0 Jun 24, 2017
@jsotuyod

Copy link
Copy Markdown
Member Author

Things I'm sharing but treating as immutable:

  • property descriptors (can probably be turned into immutables)
  • property values (they are objects, I'm copying the map, but the value instances are shared)
  • RuleSetReference (can be turned into immutable, is not one yet)

I may be sharing something else I'm not fully aware of.

 - Copy constructor for RuleSets
 - Copy constructor for RuleSet
 - Copy method for Rules
 - I'm still sharing a few objects that are not strictly immutables, but
treated as them
@jsotuyod jsotuyod force-pushed the deep-copy-rulesets branch from 259177c to 19da55f Compare July 24, 2017 15:48
@jsotuyod jsotuyod removed the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Jul 24, 2017
@jsotuyod

Copy link
Copy Markdown
Member Author

RuleSetReference are now immutable. Thanks to #479 properties are now really immutable.
The only shared state is the actual values of properties, but since those are only altered during ruleset parsing, so it should be ok.

@jsotuyod

Copy link
Copy Markdown
Member Author

The changes to setters / getters for things like DFA should probably be a separate PR to keep things organized.

@adangel am I missing anything else here?

@adangel adangel merged commit 5eb47c4 into pmd:master Aug 24, 2017
@adangel

adangel commented Aug 24, 2017

Copy link
Copy Markdown
Member

@jsotuyod Merged! Sorry it took so long.
The getters/setters change should indeed be a separate PR.

@jsotuyod jsotuyod deleted the deep-copy-rulesets branch August 24, 2017 23:16
jsotuyod added a commit to jsotuyod/pmd that referenced this pull request Sep 12, 2017
  Under multi-thread runs, each thread parsed it's own copy of the
ruleset, and removed dysfunctional rules. This meant 1 `ConfigError` per
thread was being generated.
  Since pmd#519, we now log `ConfigErrors`, meaning multiple identical
logs in reports and noise for the user.
  Therefore, we change our approach. RuleSets are parsed only once.
Dysfunctional rules are filtered and reported early on, before
dispathing actual file analysis. Each analysis thread can then produce
their own copy of the ruleset by taking advantage of the `deepCopy`
support for rules, ruleset and rulesets introduced in pmd#464.
  The result is not only more concise reports, but the analysis thread
actually perform less work. Rulesets XMLs are parsed exactly once,
instead of 1 + 1 per thread as before, and rule configuration is
validated only once.

  During this process an issue with how property descriptors where
copied has arised and was fixed. A new unit test to validate this
scenario has been introduced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

an:enhancement An improvement on existing features / rules in:pmd-internals Affects PMD's internals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants