-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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-6825] Get rid of commons-lang #1080
Conversation
bb53cea
to
db428b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like a lot of this very much. I do want to avoid introducing yet more utils classes though.
maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
Show resolved
Hide resolved
maven-core/src/main/java/org/apache/maven/internal/StringUtils.java
Outdated
Show resolved
Hide resolved
@@ -158,7 +158,7 @@ public void testCalculateDegreeOfConcurrency() { | |||
int cpus = Runtime.getRuntime().availableProcessors(); | |||
assertEquals((int) (cpus * 2.2), cli.calculateDegreeOfConcurrency("2.2C")); | |||
assertEquals(1, cli.calculateDegreeOfConcurrency("0.0001C")); | |||
assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2.C")); | |||
assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2.xC")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this changed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When changing the related code, I found out that 2.C
was rejected early, although fully supported, so the test ended up failing after removing the early test which was using commons-lang Validate
, as this part is completely duplicated by the exception thrown by the Float.parseFloat
which also validates the syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so it's an extra test. That's fine, but I suggest also keeping
assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2.C"));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really an extra test per se, I saw it as a test checking a bad float syntax. That's still the case.
I can't keep really the old test, because that test would not throw an exception anymore, as 2.
is a legit float number according to the Float.parseFloat
which is now used to validate the syntax. So while it is of course doable, it would actually add some specific code in the calculateDegreeOfConcurrentcy
method simply to ensure this test fails. I'm not really struck by the fact that 2.
is correctly parsed, and therefore that 2.C
is a valid degree of concurrency, so I'd rather keep the code lean and accept this use case as valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is a behavior change and a bug fix? That's good, but probably needs a specific Jira issue focused on this particularly, and an individual PR. Otherwise if this behavior change causes problems it's going to be quite hard to backtrack to this change in the middle of all the other refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a behaviour change for sure, whether this is considered a bug can be discussed I suppose. I'll raise a JIRA for that one and rebase on top of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've splitted in two commits (not to be squashed) and two JIRA issues...
Great to see these changes! I think the Other cases that came up in discussion elsewhere are not as clear in the general case, but can be automated in specific cases. For instance the utils I'm traveling this week, so can't fully dive in, but hope to revisit the automations next week. Let me know if there's any over replacements that you'd like to distill from this one. Only looking to help & amplify changes such as this PR. |
Yes, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. The behavior change in MavenCli perhaps needs to be split out to a separate PR/issue though.
maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java
Outdated
Show resolved
Hide resolved
maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java
Outdated
Show resolved
Hide resolved
@@ -158,7 +158,7 @@ public void testCalculateDegreeOfConcurrency() { | |||
int cpus = Runtime.getRuntime().availableProcessors(); | |||
assertEquals((int) (cpus * 2.2), cli.calculateDegreeOfConcurrency("2.2C")); | |||
assertEquals(1, cli.calculateDegreeOfConcurrency("0.0001C")); | |||
assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2.C")); | |||
assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2.xC")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is a behavior change and a bug fix? That's good, but probably needs a specific Jira issue focused on this particularly, and an individual PR. Otherwise if this behavior change causes problems it's going to be quite hard to backtrack to this change in the middle of all the other refactoring.
Also fix the thrown exception to report valid syntaxes without assuming the user intent (for example "0.5c" would say it's not an int...)
b3ee1a0
to
43eac66
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Just a few nits.
maven-artifact/pom.xml
Outdated
<artifactId>commons-lang3</artifactId> | ||
</dependency> | ||
</dependencies> | ||
<dependencies /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need the empty element or can we just drop it?
@@ -90,7 +88,9 @@ private String loadMavenVersion() { | |||
|
|||
@Override | |||
public boolean isMavenVersion(String versionRange) { | |||
Validate.notBlank(versionRange, "versionRange can neither be null, empty nor blank"); | |||
if (!(versionRange != null && !versionRange.isEmpty())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slightly clearer:
if (versionRange == null || versionRange.isEmpty())
@@ -90,7 +88,9 @@ private String loadMavenVersion() { | |||
|
|||
@Override | |||
public boolean isMavenVersion(String versionRange) { | |||
Validate.notBlank(versionRange, "versionRange can neither be null, empty nor blank"); | |||
if (!(versionRange != null && !versionRange.isEmpty())) { | |||
throw new IllegalArgumentException("versionRange can neither be null nor empty"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to use a NullPointerException for null. The tests below suggest this was the existing behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've always disliked throwing NPE explicitly and this will complicate the code as the test need to be split... Imho, in all cases, those are illegal arguments...
I'm going to commit the following:
if (Objects.requireNonNull(versionRange, "versionRange cannot be null").isEmpty()) {
throw new IllegalArgumentException("versionRange cannot be empty");
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works :-)
deecf96
to
10a2e87
Compare
https://issues.apache.org/jira/browse/MNG-7756 and https://issues.apache.org/jira/browse/MNG-6825