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

feat(#1602): discover depends on place #2432

Merged

Conversation

maxonfjvipon
Copy link
Member

@maxonfjvipon maxonfjvipon commented Aug 23, 2023

Ref: #1602

More details here


PR-Codex overview

This PR focuses on hiding a static constant DELIMITER to avoid code duplication in multiple places.

Detailed summary

  • Updated the OnReplaced class to include OnDefault in the list of places where DELIMITER is used.
  • Added a new class OnDefault to handle default object names.
  • Updated the DiscoverMojo class to use the OnDefault class for object discovery.

The following files were skipped due to too many changes: eo-maven-plugin/src/main/java/org/eolang/maven/DiscoverMojo.java

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@maxonfjvipon maxonfjvipon requested review from volodya-lombrozo and removed request for volodya-lombrozo August 23, 2023 11:35
@maxonfjvipon
Copy link
Member Author

@volodya-lombrozo please have a look one more time

*
* @since 0.31.0
*/
public final class OnDefault implements ObjectName {
Copy link
Member

Choose a reason for hiding this comment

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

@maxonfjvipon I believe this change should be done in a separate PR. Please take a look that issue:
#2420

Copy link
Member Author

Choose a reason for hiding this comment

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

@volodya-lombrozo I'm not sure in such particular case. OnDefault is just one more ObjectName without complex behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

@maxonfjvipon From the issue description:

Apparently we have to create a class which will parse raw string into two parts value and
optional version.

We have the same split function among many classes (The same we can say about DELIMETER static field). Hence, I believe this issue exactly about this.

Copy link
Member Author

Choose a reason for hiding this comment

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

@volodya-lombrozo I suggest to extend the #2420 so it affected this class too

Copy link
Member Author

Choose a reason for hiding this comment

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

@volodya-lombrozo I believe adding OnDefault class is not about solving the problem #2420. It's just one more object name. Yes, with code duplication, that will be somehow resolved after solving #2420.

Copy link
Member

Choose a reason for hiding this comment

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

@maxonfjvipon Let's do it for now. But I would recommend to solve #2420 issue first and then return to that PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

@volodya-lombrozo yes, let's leave this as it. Object versioning has higher priority than refactoring at the moment

@maxonfjvipon
Copy link
Member Author

@volodya-lombrozo please have a look one more time

*
* @since 0.31.0
*/
public final class OnDefault implements ObjectName {
Copy link
Member

Choose a reason for hiding this comment

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

@maxonfjvipon From the issue description:

Apparently we have to create a class which will parse raw string into two parts value and
optional version.

We have the same split function among many classes (The same we can say about DELIMETER static field). Hence, I believe this issue exactly about this.

@@ -42,15 +43,24 @@ public final class OnVersioned implements ObjectName {
/**
* Default hash.
*/
private final CommitHash hsh;
private final Unchecked<CommitHash> hsh;
Copy link
Member

Choose a reason for hiding this comment

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

@maxonfjvipon Why do we need this overcomplication? I didn't find any usage of the next constructor:

public OnVersioned(final ObjectName origin, final Scalar<CommitHash> hash) {
    this(new Unchecked<>(origin::toString), new Unchecked<>(hash));
}

And to be honest, I don't see the reason for it.

Copy link
Member Author

@maxonfjvipon maxonfjvipon Aug 30, 2023

Choose a reason for hiding this comment

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

@volodya-lombrozo here. Scalar is needed because explicit new OnDefault(tojo).hash() may fail with IndexOutOfBounds exception if tojo does not contain delimiter |

Copy link
Member

Choose a reason for hiding this comment

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

@maxonfjvipon I see, thank you. Maybe it's better to let it fail as fast as possible? Otherwise it looks like you are trying to swallow the exception or use exceptions for flow control (both of the approaches don't lead to a good design).

Copy link
Member Author

Choose a reason for hiding this comment

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

@volodya-lombrozo It should not fail at this step at all. Pay a bit more attention to the code:

new OnSwap(
    tojo.contains(OnReplaced.DELIMITER),
    new OnVersioned(
        replaced,
        new OnDefault(tojo)::hash
    ),
    replaced
)

If condition tojo.contains(OnReplaced.DELIMITER) is FALSE, the first object will be never evaluated, the second one will be - replaced. But we need to construct it here and it should now fail on the construction step

Copy link
Member Author

Choose a reason for hiding this comment

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

@volodya-lombrozo maybe we will add one more object name for such cases, but there's only one for now, so there's no need

* Otherwise, try to append a version from tojo if there's no one already
*
* @param name Object name with tag on not.
* @param tojo Current tojo.
Copy link
Member

Choose a reason for hiding this comment

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

@maxonfjvipon Is it a tojo? Maybe we can name it as a "default object name", or "default version"?

Copy link
Member Author

Choose a reason for hiding this comment

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

@volodya-lombrozo it's an identifier of tojo

Copy link
Member

Choose a reason for hiding this comment

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

@maxonfjvipon But what is the identifier of tojo in this context?

Copy link
Member Author

@maxonfjvipon maxonfjvipon Aug 30, 2023

Choose a reason for hiding this comment

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

@volodya-lombrozo just a name of it as string

Copy link
Member

Choose a reason for hiding this comment

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

@maxonfjvipon You treat it as an object name with hash, or I'm wrong?

Copy link
Member Author

@maxonfjvipon maxonfjvipon Aug 30, 2023

Choose a reason for hiding this comment

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

@volodya-lombrozo with or without. But if I wrap tojo.identifier() into OnDefault somewhere before this function, I'll not be able check if it contains hash or not. The check should happen in this function, that's why I pass tojo String not as ObjectName

@maxonfjvipon
Copy link
Member Author

@volodya-lombrozo please have a look one more time

@volodya-lombrozo
Copy link
Member

@Graur Could you take a look, please?

@maxonfjvipon maxonfjvipon requested review from Graur and removed request for volodya-lombrozo August 31, 2023 09:51
@maxonfjvipon
Copy link
Member Author

@Graur please review this one since Volodya is not able now

Copy link
Contributor

@Graur Graur left a comment

Choose a reason for hiding this comment

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

@maxonfjvipon I believe it's good to merge

@maxonfjvipon
Copy link
Member Author

@yegor256 please have a look

@yegor256
Copy link
Member

yegor256 commented Sep 1, 2023

@rultor merge

@rultor
Copy link
Contributor

rultor commented Sep 1, 2023

@rultor merge

@yegor256 OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit fd7475b into objectionary:master Sep 1, 2023
10 checks passed
@rultor
Copy link
Contributor

rultor commented Sep 1, 2023

@rultor merge

@yegor256 Done! FYI, the full log is here (took me 13min)

@maxonfjvipon maxonfjvipon deleted the feat/#1602/discover-depends-on-place branch September 18, 2023 12:10
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.

5 participants