Skip to content

General Coding rule to detect usages of old time and date classes (#1384 / #1385)#1385

Merged
hankem merged 1 commit into
TNG:mainfrom
Bukama:dateutil
Jan 26, 2025
Merged

General Coding rule to detect usages of old time and date classes (#1384 / #1385)#1385
hankem merged 1 commit into
TNG:mainfrom
Bukama:dateutil

Conversation

@Bukama
Copy link
Copy Markdown
Contributor

@Bukama Bukama commented Nov 27, 2024

Update:

Provided commit message

General coding rule to detect usages of old time and date classes (#1384 / #1385)

With this commit new general rules are added which detect the usages of old
time and date classes, e.g. java.util.Date.

closes #1384

I would like to provide rules for #1384, but I'm failing with the OLD_DATE_AND_TIME_CLASSES_SHOULD_NOT_BE_USED_should_fail_when_class_uses_java_util_date test as my violation is not captured, but this

[violation details (should have some detail containing 'since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.')]
Expecting any elements of:
["Method <com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaUtilDate.usesJavaUtilDate()> calls method <java.util.Date.from(java.time.Instant)> in (UsesJavaUtilDate.java:9)"]
to match given predicate but none did.
java.lang.AssertionError: [violation details (should have some detail containing 'since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.')]
Expecting any elements of:
["Method <com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaUtilDate.usesJavaUtilDate()> calls method <java.util.Date.from(java.time.Instant)> in (UsesJavaUtilDate.java:9)"]
to match given predicate but none did.

Can anyone give me a hint how to fix that?

P.S. I know that my formatting (e.g. star import) are not yet correct. Will fix this when my tests are working and before changing this draft into a real PR, including providing a real commit message.

@hankem
Copy link
Copy Markdown
Member

hankem commented Nov 27, 2024

Thanks for your contribution! I think that your confusion is that

since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.

is part of the rule description, but you're testing the violation description, which is

Method <com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaUtilDate.usesJavaUtilDate()> calls method <java.util.Date.from(java.time.Instant)> in (UsesJavaUtilDate.java:9)

@Bukama
Copy link
Copy Markdown
Contributor Author

Bukama commented Nov 28, 2024

Thanks for your contribution! I think that your confusion is that

since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.

is part of the rule description, but you're testing the violation description, which is

Method <com.tngtech.archunit.library.testclasses.timeapi.incorrect.UsesJavaUtilDate.usesJavaUtilDate()> calls method <java.util.Date.from(java.time.Instant)> in (UsesJavaUtilDate.java:9)

Thanks that helped!

@Bukama Bukama marked this pull request as ready for review November 28, 2024 16:07
@Bukama Bukama changed the title General Coding rule to detect usages of old time and date classes (DRAFT for #1384) General Coding rule to detect usages of old time and date classes (#1384 / #1385) Nov 28, 2024
@codecholeric
Copy link
Copy Markdown
Collaborator

Hey @Bukama, thanks a lot for your support, we really appreciate it 😃 Could you do me a favor and sign off your commits according to the DCO? (-> https://github.com/TNG/ArchUnit/blob/main/DCO) It's basically some legal thing where you confirm that you contribute the code under the project license and are allowed to contribute it.

I think the easiest would be to squash your commits(I think this change in the end is small enough for a single commit, right?) and then run git commit -s --amend --no-edit from the command line. The -s option adds the standardized sign-off part to the commit message 🙂

Bukama added a commit to Bukama/ArchUnit that referenced this pull request Jan 19, 2025
…G#1384 / TNG#1385)

With this commit new general rules are added which detect the usages of old
time and date classes, e.g. java.util.Date.

closes TNG#1384

> Developer's Certificate of Origin 1.1
>
> By making a contribution to this project, I certify that:
>
> (a) The contribution was created in whole or in part by me and I
>     have the right to submit it under the open source license
>     indicated in the file; or
>
> (b) The contribution is based upon previous work that, to the best
>     of my knowledge, is covered under an appropriate open source
>     license and I have the right under that license to submit that
>     work with modifications, whether created in whole or in part
>     by me, under the same open source license (unless I am
>     permitted to submit under a different license), as indicated
>     in the file; or
>
> (c) The contribution was provided directly to me by some other
>     person who certified (a), (b) or (c) and I have not modified
>     it.
>
> (d) I understand and agree that this project and the contribution
>     are public and that a record of the contribution (including all
>     personal information I submit with it, including my sign-off) is
>     maintained indefinitely and may be redistributed consistent with
>     this project or the open source license(s) involved.

Signed-off-by: Matthias Bünger <[email protected]>
@Bukama
Copy link
Copy Markdown
Contributor Author

Bukama commented Jan 19, 2025

Hey @Bukama, thanks a lot for your support, we really appreciate it 😃 Could you do me a favor and sign off your commits according to the DCO? (-> https://github.com/TNG/ArchUnit/blob/main/DCO) It's basically some legal thing where you confirm that you contribute the code under the project license and are allowed to contribute it.

I think the easiest would be to squash your commits(I think this change in the end is small enough for a single commit, right?) and then run git commit -s --amend --no-edit from the command line. The -s option adds the standardized sign-off part to the commit message 🙂

Hey, thanks for the response.
Didn't notice that part, so I only prepared a commit message for you to use when squash-merging the PR (which I'm used from other projects, but ofc this is no valid excuse, because every project defines how it deals with PR). Hope I've done it right now.

hankem pushed a commit to Bukama/ArchUnit that referenced this pull request Jan 25, 2025
…G#1384 / TNG#1385)

With this commit new general rules are added which detect the usages of old
time and date classes, e.g. java.util.Date.

closes TNG#1384

> Developer's Certificate of Origin 1.1
>
> By making a contribution to this project, I certify that:
>
> (a) The contribution was created in whole or in part by me and I
>     have the right to submit it under the open source license
>     indicated in the file; or
>
> (b) The contribution is based upon previous work that, to the best
>     of my knowledge, is covered under an appropriate open source
>     license and I have the right under that license to submit that
>     work with modifications, whether created in whole or in part
>     by me, under the same open source license (unless I am
>     permitted to submit under a different license), as indicated
>     in the file; or
>
> (c) The contribution was provided directly to me by some other
>     person who certified (a), (b) or (c) and I have not modified
>     it.
>
> (d) I understand and agree that this project and the contribution
>     are public and that a record of the contribution (including all
>     personal information I submit with it, including my sign-off) is
>     maintained indefinitely and may be redistributed consistent with
>     this project or the open source license(s) involved.

Signed-off-by: Matthias Bünger <[email protected]>
hankem pushed a commit to Bukama/ArchUnit that referenced this pull request Jan 25, 2025
…G#1384 / TNG#1385)

With this commit new general rules are added which detect the usages of old
time and date classes, e.g. java.util.Date.

closes TNG#1384

> Developer's Certificate of Origin 1.1
>
> By making a contribution to this project, I certify that:
>
> (a) The contribution was created in whole or in part by me and I
>     have the right to submit it under the open source license
>     indicated in the file; or
>
> (b) The contribution is based upon previous work that, to the best
>     of my knowledge, is covered under an appropriate open source
>     license and I have the right under that license to submit that
>     work with modifications, whether created in whole or in part
>     by me, under the same open source license (unless I am
>     permitted to submit under a different license), as indicated
>     in the file; or
>
> (c) The contribution was provided directly to me by some other
>     person who certified (a), (b) or (c) and I have not modified
>     it.
>
> (d) I understand and agree that this project and the contribution
>     are public and that a record of the contribution (including all
>     personal information I submit with it, including my sign-off) is
>     maintained indefinitely and may be redistributed consistent with
>     this project or the open source license(s) involved.

Signed-off-by: Matthias Bünger <[email protected]>
hankem pushed a commit that referenced this pull request Jan 25, 2025
 / #1385)

With this commit new general rules are added which detect the usages of old
time and date classes, e.g. java.util.Date.

closes #1384

> Developer's Certificate of Origin 1.1
>
> By making a contribution to this project, I certify that:
>
> (a) The contribution was created in whole or in part by me and I
>     have the right to submit it under the open source license
>     indicated in the file; or
>
> (b) The contribution is based upon previous work that, to the best
>     of my knowledge, is covered under an appropriate open source
>     license and I have the right under that license to submit that
>     work with modifications, whether created in whole or in part
>     by me, under the same open source license (unless I am
>     permitted to submit under a different license), as indicated
>     in the file; or
>
> (c) The contribution was provided directly to me by some other
>     person who certified (a), (b) or (c) and I have not modified
>     it.
>
> (d) I understand and agree that this project and the contribution
>     are public and that a record of the contribution (including all
>     personal information I submit with it, including my sign-off) is
>     maintained indefinitely and may be redistributed consistent with
>     this project or the open source license(s) involved.

Signed-off-by: Matthias Bünger <[email protected]>
Copy link
Copy Markdown
Member

@hankem hankem left a comment

Choose a reason for hiding this comment

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

I've reformatted your commit according to the code style of the project (cf. CONTRIBUTING.md).

Comment on lines +524 to +525
.as("since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.")
.because("since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.");
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 you use the same text in as and because, you essentially duplicate it in the final rule description:

Rule 'since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used., because since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.' was violated [...]

How about

Suggested change
.as("since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.")
.because("since Java 8 (and JavaEE 7 if JPA is needed) java.time-API should be used.");
.as("java.time API should be used")
.because("legacy date/time APIs have been replaced since Java 8 (JSR 310)");

which gives the final rule description

Rule 'java.time API should be used, because legacy date/time APIs have been replaced since Java 8' was violated [...]

  • without full stop before , because,
  • without the reference to Java EE 7 & JPA, because it might be confusing if the general coding rule is used in an context unrelated to Java EE/JPA, but
  • with a reference to JSR 310, which might help unexperienced developers to find more information.

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.

For your convenience, I've prepared this suggestion on the dateutil-review branch.

Copy link
Copy Markdown
Contributor Author

@Bukama Bukama Jan 25, 2025

Choose a reason for hiding this comment

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

Thank you for your suggestion. I'm fine with that. In my initial version I added the JPA information, because we have that at work, that Java 8 is available, but not JavaEE 7.
Also run spotless tasks, so that should fit too now.

edit: and rebased as obvious after months that there are commits on mains.

hankem pushed a commit that referenced this pull request Jan 25, 2025
 / #1385)

With this commit new general rules are added which detect the usages of old
time and date classes, e.g. java.util.Date.

closes #1384

> Developer's Certificate of Origin 1.1
>
> By making a contribution to this project, I certify that:
>
> (a) The contribution was created in whole or in part by me and I
>     have the right to submit it under the open source license
>     indicated in the file; or
>
> (b) The contribution is based upon previous work that, to the best
>     of my knowledge, is covered under an appropriate open source
>     license and I have the right under that license to submit that
>     work with modifications, whether created in whole or in part
>     by me, under the same open source license (unless I am
>     permitted to submit under a different license), as indicated
>     in the file; or
>
> (c) The contribution was provided directly to me by some other
>     person who certified (a), (b) or (c) and I have not modified
>     it.
>
> (d) I understand and agree that this project and the contribution
>     are public and that a record of the contribution (including all
>     personal information I submit with it, including my sign-off) is
>     maintained indefinitely and may be redistributed consistent with
>     this project or the open source license(s) involved.

Signed-off-by: Matthias Bünger <[email protected]>
Bukama added a commit to Bukama/ArchUnit that referenced this pull request Jan 25, 2025
…G#1384 / TNG#1385)

With this commit new general rules are added which detect the usages of old
time and date classes, e.g. java.util.Date.

closes TNG#1384

> Developer's Certificate of Origin 1.1
>
> By making a contribution to this project, I certify that:
>
> (a) The contribution was created in whole or in part by me and I
>     have the right to submit it under the open source license
>     indicated in the file; or
>
> (b) The contribution is based upon previous work that, to the best
>     of my knowledge, is covered under an appropriate open source
>     license and I have the right under that license to submit that
>     work with modifications, whether created in whole or in part
>     by me, under the same open source license (unless I am
>     permitted to submit under a different license), as indicated
>     in the file; or
>
> (c) The contribution was provided directly to me by some other
>     person who certified (a), (b) or (c) and I have not modified
>     it.
>
> (d) I understand and agree that this project and the contribution
>     are public and that a record of the contribution (including all
>     personal information I submit with it, including my sign-off) is
>     maintained indefinitely and may be redistributed consistent with
>     this project or the open source license(s) involved.

Signed-off-by: Matthias Bünger <[email protected]>
…G#1384 / TNG#1385)

With this commit new general rules are added which detect the usages of old
time and date classes, e.g. java.util.Date.

closes TNG#1384

> Developer's Certificate of Origin 1.1
>
> By making a contribution to this project, I certify that:
>
> (a) The contribution was created in whole or in part by me and I
>     have the right to submit it under the open source license
>     indicated in the file; or
>
> (b) The contribution is based upon previous work that, to the best
>     of my knowledge, is covered under an appropriate open source
>     license and I have the right under that license to submit that
>     work with modifications, whether created in whole or in part
>     by me, under the same open source license (unless I am
>     permitted to submit under a different license), as indicated
>     in the file; or
>
> (c) The contribution was provided directly to me by some other
>     person who certified (a), (b) or (c) and I have not modified
>     it.
>
> (d) I understand and agree that this project and the contribution
>     are public and that a record of the contribution (including all
>     personal information I submit with it, including my sign-off) is
>     maintained indefinitely and may be redistributed consistent with
>     this project or the open source license(s) involved.

Signed-off-by: Matthias Bünger <[email protected]>
@hankem hankem enabled auto-merge January 26, 2025 11:10
@hankem hankem merged commit 54fae8d into TNG:main Jan 26, 2025
@rweisleder
Copy link
Copy Markdown
Contributor

@hankem It looks like this nice enhancement is missing in the 1.4.0 release notes. 😢

@hankem
Copy link
Copy Markdown
Member

hankem commented Feb 11, 2025

Oooh, I'm sorry for overlooking that one! The release notes have been fixed.

@Bukama Bukama deleted the dateutil branch February 11, 2025 15:45
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