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

[MNG-8150] Handle absent source/target files in transfer listener #1575

Conversation

pshevche
Copy link
Contributor

Summary

The PR address two issues observed in the SimplexTransferListener and ConsoleMavenTransferListener:

  1. TransferResource#getFile() can be null. The current SimplexTransferListener will break with an NPE if the file is not set on the resource.
  2. TransferResource is not immutable and does not implement equals or hashCode, making its usage in collections brittle. Listener consumers are not guaranteed to reuse the same instance across listener invocations. I suggest wrapping it in an immutable identifier.

Let me know if I am overthinking this or if anything else is needed.

Resolves https://issues.apache.org/jira/browse/MNG-8150

@cstamas
Copy link
Member

cstamas commented Jun 10, 2024

Looks nice, but the maven-3.9.x branch (Maven 3.9.x) is Java 8...

@cstamas cstamas requested review from gnodet and CrazyHZM June 10, 2024 12:52
@pshevche
Copy link
Contributor Author

Looks nice, but the maven-3.9.x branch (Maven 3.9.x) is Java 8...

Yeah, I see that now :) Do you want me to keep records on this branch and use a class on maven-3.9.x branch or would you rather prefer the same style everywhere?

@cstamas
Copy link
Member

cstamas commented Jun 10, 2024

No, IMO records on master (Maven 4, that is Java 17) is ok, I just warned you when you try to backport this to maven-3.9.x branch...

@pshevche
Copy link
Contributor Author

No, IMO records on master (Maven 4, that is Java 17) is ok, I just warned you when you try to backport this to maven-3.9.x branch...

Makes sense, thank you. Here is the PR for backport: #1576

Copy link
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

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

Two minor changes would be nice if included.

@@ -35,7 +35,7 @@
*/
public class ConsoleMavenTransferListener extends AbstractMavenTransferListener {

private Map<TransferResource, Long> transfers = new LinkedHashMap<>();
private Map<TransferResourceIdentifier, TransferResourceAndSize> transfers = new LinkedHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Those 3 fields should be final.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 274f180

@@ -35,7 +35,7 @@
*/
public class ConsoleMavenTransferListener extends AbstractMavenTransferListener {

private Map<TransferResource, Long> transfers = new LinkedHashMap<>();
private Map<TransferResourceIdentifier, TransferResourceAndSize> transfers = new LinkedHashMap<>();
private FileSizeFormat format = new FileSizeFormat(Locale.ENGLISH); // use in a synchronized fashion
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to get rid of the Locale.ENGLISH parameter which is unused, though this can be done in a subsequent PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in #1579

@@ -35,7 +35,7 @@
*/
public class ConsoleMavenTransferListener extends AbstractMavenTransferListener {
Copy link
Contributor

@gnodet gnodet Jun 11, 2024

Choose a reason for hiding this comment

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

Can we add a comment specifying that this class is not thread safe and should only be used from a single thread, or wrapped in the SimplexTransferListener ?
It would avoid having to look why this class is not thread safe (the StringBuffer as a field makes that quite easy to spot).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 274f180

cstamas pushed a commit that referenced this pull request Jun 11, 2024
)

Backporting #1575 to Maven 3.9.x.

 - [x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)

---

https://issues.apache.org/jira/browse/MNG-8150
@cstamas cstamas merged commit e995ba6 into apache:master Jun 11, 2024
13 checks passed
cstamas pushed a commit that referenced this pull request Jun 11, 2024
## Summary

Addressing #1575 (comment)

 - [x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)

---

https://issues.apache.org/jira/browse/MNG-8150
@pshevche pshevche deleted the pshevche/8150-handle-absent-file-in-transfer-listener branch June 12, 2024 06:44
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