Skip to content

Add a store to the extension model - #1692

Merged
leonard84 merged 33 commits into
spockframework:masterfrom
leonard84:add-extension-store
Dec 15, 2023
Merged

leonard84 merged 33 commits into
spockframework:masterfrom
leonard84:add-extension-store

Conversation

@leonard84

Copy link
Copy Markdown
Member

No description provided.

@leonard84
leonard84 requested a review from Vampire June 6, 2023 15:55
@leonard84 leonard84 self-assigned this Jun 6, 2023
@codecov

codecov Bot commented Jun 6, 2023 •

Copy link
Copy Markdown

Codecov Report

Attention: 18 lines in your changes are missing coverage. Please review.

Comparison is base (b5169f1) 80.33% compared to head (ee8e43c) 80.48%.

Files Patch % Lines
...a/org/spockframework/runtime/extension/IStore.java 80.64% 4 Missing and 2 partials ⚠️
...n/java/org/spockframework/util/ReflectionUtil.java 64.28% 4 Missing and 1 partial ⚠️
.../src/main/java/org/spockframework/util/Checks.java 57.14% 0 Missing and 3 partials ⚠️
...in/java/org/spockframework/util/ExceptionUtil.java 0.00% 3 Missing ⚠️
...kframework/runtime/extension/IGlobalExtension.java 80.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1692      +/-   ##
============================================
+ Coverage     80.33%   80.48%   +0.14%     
- Complexity     4242     4299      +57     
============================================
  Files           434      438       +4     
  Lines         13300    13432     +132     
  Branches       1693     1697       +4     
============================================
+ Hits          10685    10811     +126     
  Misses         1976     1976              
- Partials        639      645       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leonard84
leonard84 force-pushed the add-extension-store branch from 62e45c5 to b97c016 Compare June 6, 2023 17:45
Comment thread docs/extensions.adoc Resolved
Comment thread docs/extensions.adoc Resolved
Comment thread docs/extensions.adoc Resolved
Comment thread docs/extensions.adoc Resolved
Comment thread docs/extensions.adoc Resolved
@Vampire

Vampire commented Jun 9, 2023

Copy link
Copy Markdown
Member

Additionally to the annotations, Codecov is a bit unhappy

marcphilipp
marcphilipp previously approved these changes Jun 21, 2023

@marcphilipp marcphilipp left a comment

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.

Looks promising 🙂

Comment thread docs/extensions.adoc Resolved

@Vampire Vampire left a comment

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.

Some comments to the changes so far. :-)

Comment thread docs/extensions.adoc Resolved
Comment thread docs/extensions.adoc Resolved
* @throws PreconditionViolationException if the supplied object is {@code null}
* @see #notNull(Object, Supplier)
*/
public static <T> T notNull(T object, Supplier<String> messageProvider) throws PreconditionViolationException {

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.

That's one valid argument yes.
What I say is, whether it makes sense to not use the default method that is meant for exactly that case.
The JavaDoc of Objects.requireNonNull says:

This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below

If you are aware of that and think it is better not to follow the standard and throw IAE instead, that's fine of course, just wanted to make sure you didn't miss it. :-)

* @throws PreconditionViolationException if the supplied object is {@code null}
* @see #notNull(Object, Supplier)
*/
public static <T> T notNull(T object, Supplier<String> messageProvider) throws PreconditionViolationException {

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.

You mean one that can be used for both cases?
Like IllegalThingException?
Also not sure that's worth it.
But on the other hand, if you want to use it for anything else than arguments, throwing IAE feels awkward too. 😕

}

public static <T> T newInstance(Class<T> clazz, Object... args) {
Preconditions.notNull(clazz, "Class must not be null");

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.

2 unused imports are left now. :-)

Comment on lines +22 to +23
// Spring dependency management downgrades the jupiter version to 5.7.2 otherwise
ext['junit-jupiter.version'] = '5.10.0-M1'

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.

Doesn't change that it does more harm than good and even its maintainer strongly recommends not to use it anymore but the built-in BOM support: https://www.linen.dev/s/gradle-community/t/2579116/what-is-the-proper-way-to-apply-a-bom-in-a-library-project-i#a7d4a60a-ab60-48dc-8477-f3f4462d1e6a :-)

@leonard84
leonard84 force-pushed the add-extension-store branch 5 times, most recently from 1400c86 to edd88c6 Compare November 12, 2023 14:25
@leonard84
leonard84 force-pushed the add-extension-store branch 3 times, most recently from fceb690 to d969db0 Compare November 30, 2023 17:59
return;
}

context = context.withChildStoreProvider();

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.

I am not a big fan of overriding parameter values in the method.

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 understand, but we've used this pattern for the context so far. We could change it in another PR.

* @return the previous value; may be {@code null}
* @see AutoCloseable
*/
Object put(Object key, Object value);

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.

If it stays Object, I would add @Nullable at least.

Comment on lines +265 to +327
/**
* Create a namespace which restricts access to data to all extensions
* which use the same sequence of {@code parts} for creating a namespace.
*
* <p>The order of the {@code parts} is significant.
*
* <p>Internally the {@code parts} are compared using {@link Object#equals(Object)}.
*/
public static Namespace create(Object... parts) {

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.

Shouldn't this document that the used Objects for parts, need to be Immutable or at least have a stable equals/hashcode contract.
If an object changes its hashcode I guess the thing is broken.
Or do we say, yeah if you do such things, that is not our problem...

* @see #get(Object, Class)
* @see #getOrDefault(Object, Class, Object)
*/
Object get(Object key);

ghost Dec 14, 2023

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.

But do we really need those extra methods with the extra argument?
Is store.get(THING, Bar.class).getFoo(); really more fluent than
store.<Bar>get(THING).getFoo(); which would spare those extra methods?

Comment thread docs/extensions.adoc Resolved

ghost left a comment

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.

We're almost there. :-)

Comment thread docs/extensions.adoc Resolved
}

public static <T> T newInstance(Class<T> clazz, Object... args) {
Preconditions.notNull(clazz, "Class must not be null");

ghost Dec 15, 2023

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.

You really like your unused imports, don't you? :-D

@leonard84
leonard84 requested a review from Vampire December 15, 2023 13:18

ghost left a comment

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.

Added via Giphy

@leonard84
leonard84 merged commit 618c70e into spockframework:master Dec 15, 2023
@leonard84
leonard84 deleted the add-extension-store branch December 15, 2023 19:15
@leonard84

ghost commented Dec 15, 2023

Copy link
Copy Markdown
Member Author

Thanks for the reviews @Vampire and @AndreasTu

@leonard84 leonard84 added this to the 2.4-M2 milestone Feb 22, 2024
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.

4 participants