Skip to content

Conversation

@dgarzon
Copy link
Contributor

@dgarzon dgarzon commented Dec 6, 2018

This PR addresses #658 and #657 on the CasC side of things. Currently, if there are duplicate symbols both the configure and getImplementors methods throw ugly exceptions. Ideally, they should not throw and instead log a warning to the user to report the duplicates to maintainers.

I may have gone a bit overboard with the refactoring, but I think it is valuable nonetheless. The code now is easier to reason about as I have moved code to functions and given them clear names. Also tried to DRY this as much as possible.

Behavior:

  1. getImplementors: if a duplicate key is found, we discard it, and log Found multiple implementations for symbol = fooBar: [foo.bar.FooBar, foo.baz.FooBar]. Please report to plugin maintainer.
  2. configure: if a duplicate key is found, we log Found multiple implementations for symbol = fooBar: [foo.bar.FooBar, foo.baz.FooBar]. Please report to plugin maintainer. and configure the first instance returned by getDescriptors() which is the same behavior we had before this refactoring.

@jetersen
Copy link
Member

jetersen commented Dec 7, 2018

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

Looks reasonable, want to resolve the conflicts and try get a green build?

@jetersen jetersen force-pushed the FEAT-hetero-describable-should-detect-duplicate-implementations-of-keys branch from 576249d to 30700cf Compare March 19, 2019 20:56
@jetersen
Copy link
Member

💪 I have too much power @timja

@dgarzon
Copy link
Contributor Author

dgarzon commented Mar 19, 2019

Thank you @Casz and @timja I completely forgot about this PR :)

@jetersen
Copy link
Member

jetersen commented Mar 19, 2019

@BlueAndi this should hopefully fix help you with duplicate (diagnosing the sinner) schema issue and together with #777 everything should be better.

Honestly me too @dgarzon 😆

@jetersen
Copy link
Member

CI is having a field day 😢

@jetersen
Copy link
Member

@BlueAndi
Copy link
Contributor

@Casz Thanks for pointing this out. I hope I can check this tomorrow in the office.

@jetersen
Copy link
Member

jetersen commented Mar 21, 2019

@dgarzon this breaks binary compatibility, however, since none of the custom plugin configurators have been merged I think we are safe.

It would require some rework in some of the PRs such as jenkinsci/job-dsl-plugin#1142

@jetersen
Copy link
Member

@dgarzon and @timja please take a look 😄

@jetersen jetersen requested a review from timja March 21, 2019 01:21
@jetersen jetersen force-pushed the FEAT-hetero-describable-should-detect-duplicate-implementations-of-keys branch 2 times, most recently from 409352a to 1715987 Compare March 21, 2019 01:24
@jetersen jetersen force-pushed the FEAT-hetero-describable-should-detect-duplicate-implementations-of-keys branch from 1715987 to 52c0069 Compare March 21, 2019 03:27
@jetersen
Copy link
Member

Moved my extra work to a separate PR, it started to become more work than I expected 😄

@dgarzon
Copy link
Contributor Author

dgarzon commented Mar 21, 2019

@Casz will take a look tomorrow, I feel responsible to get this fixed :)

@jetersen
Copy link
Member

@dgarzon 👀 🙈

.collect(Collectors.toMap(
d -> DescribableAttribute.getSymbols(d, api, target).get(0),
d -> d.getKlass().toJavaClass()));
@SuppressWarnings("unused")
Copy link
Member

@timja timja Mar 22, 2019

Choose a reason for hiding this comment

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

do you need this suppression given its used in tests?
if you do need one maybe VisibleForTesting would be better

return Option.of(Jenkins.getInstance().getPlugin(name)).isDefined();
}

private HashMap<String, Descriptor<T>> handleDuplicateSymbols(HashMap<String, Descriptor<T>> r, Tuple2<String, Descriptor<T>> t) {
Copy link
Member

Choose a reason for hiding this comment

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

it's not very clear what the parameters are here, what are r and t?

also do we need to be using HashMap or can we use Map?

@Nonnull
@Override
public List<Configurator> getConfigurators(ConfigurationContext context) {
public List<Configurator<GeneratedItems[]>> getConfigurators(ConfigurationContext context) {
Copy link
Member

Choose a reason for hiding this comment

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

looks unrelated?

Copy link
Member

Choose a reason for hiding this comment

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

No, it is very much related. The Configurator class was changed to actually need the type defined and not done through reflection. Hence the binary incompatibility fix.

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

Code looks great, and nice test. Have asked a couple of question but no blockers

@jetersen jetersen changed the title FEAT: describable should warn on multiple implementations of a symbol. feat: describable should warn on multiple implementations of a symbol. Mar 23, 2019
@jetersen jetersen added the feature A PR that adds a feature - used by Release Drafter label Mar 24, 2019
@jetersen
Copy link
Member

@dgarzon 🙏

@jetersen jetersen force-pushed the FEAT-hetero-describable-should-detect-duplicate-implementations-of-keys branch 2 times, most recently from ac2cbc0 to 805b651 Compare March 29, 2019 00:09
@jetersen jetersen force-pushed the FEAT-hetero-describable-should-detect-duplicate-implementations-of-keys branch from 805b651 to 021240b Compare March 29, 2019 01:23
@jetersen jetersen force-pushed the FEAT-hetero-describable-should-detect-duplicate-implementations-of-keys branch from 021240b to 54e2b59 Compare March 29, 2019 01:29
@timja
Copy link
Member

timja commented Mar 29, 2019

@Casz this ready to go?

@jetersen
Copy link
Member

It is, I just want @dgarzon to have look at it again with my additions 😅

@dgarzon
Copy link
Contributor Author

dgarzon commented Mar 29, 2019

Thanks @Casz for taking care of this! Looks good on my end :) Been super busy at work, hopefully I will free up a bit and be back here to contribute more often!

@jetersen jetersen changed the title feat: describable should warn on multiple implementations of a symbol. Describable will give a warning on multiple implementations of a symbol Mar 29, 2019
@jetersen jetersen merged commit 63c82a8 into jenkinsci:master Mar 29, 2019
@jetersen
Copy link
Member

🙌

ingwarsw added a commit to ingwarsw/configuration-as-code-plugin that referenced this pull request Mar 30, 2019
@BlueAndi
Copy link
Contributor

BlueAndi commented Apr 4, 2019

If the descriptor list of the describable attribute is empty, another problem raise up in the schema, because of the "oneOf"

...
  "schema" : {
    "oneOf": [
  <j:forEach items="${app.getDescriptorList(it.type)}" var="d" varStatus="st">
...

which expects at least one item.

@jetersen
Copy link
Member

jetersen commented Apr 4, 2019

@BlueAndi wrap it in a app.getDescriptorList(it.type).size if statement?

@BlueAndi
Copy link
Contributor

BlueAndi commented Apr 4, 2019

@Casz Sounds good, I will try. I saw that here the same problem appears: schema
Can I use it.implementors.entrySet().size here?

...
  "${it.target.name}": {
    "type": "object",
    "oneOf" : [
  <j:forEach items="${it.implementors.entrySet()}" var="impl" varStatus="st">
...

@BlueAndi
Copy link
Contributor

BlueAndi commented Apr 5, 2019

Previous mentioned problem fixed in db44a1e

Regarding the

...
  "schema" : {
    "oneOf": [
  <j:forEach items="${app.getDescriptorList(it.type)}" var="d" varStatus="st">
...

I don't get the point about the whole construction, as I think "schema" misses a dollar sign as well.

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

Labels

feature A PR that adds a feature - used by Release Drafter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants