You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2023/04/04 20:08:01 UTC
[GitHub] [maven] gnodet opened a new pull request, #1080: [MNG-6825] Get rid of commons-lang
gnodet opened a new pull request, #1080:
URL: https://github.com/apache/maven/pull/1080
Following this checklist to help us incorporate your
contribution quickly and easily:
- [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/MNG) filed
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
- [ ] Each commit in the pull request should have a meaningful subject line and body.
- [ ] Format the pull request title like `[MNG-XXX] SUMMARY`,
where you replace `MNG-XXX` and `SUMMARY` with the appropriate JIRA issue.
- [ ] Also format the first line of the commit message like `[MNG-XXX] SUMMARY`.
Best practice is to use the JIRA issue title in both the pull request title and in the first line of the commit message.
- [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [ ] Run `mvn clean verify` to make sure basic checks pass. A more thorough check will
be performed on your pull request automatically.
- [ ] You have run the [Core IT][core-its] successfully.
If your pull request is about ~20 lines of code you don't need to sign an
[Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
you have to acknowledge this by using the following check-box.
- [ ] 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)
- [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
[core-its]: https://maven.apache.org/core-its/core-it-suite/
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158128883
##########
maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java:
##########
@@ -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"));
Review Comment:
I can't, 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1157757583
##########
maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java:
##########
@@ -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"));
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1157766172
##########
maven-core/src/main/java/org/apache/maven/internal/StringUtils.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.internal;
Review Comment:
All inlined...
##########
maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java:
##########
@@ -89,10 +88,15 @@ public static String key(String groupId, String artifactId, String version) {
}
private static void notBlank(String str, String message) {
- int c = str != null && str.length() > 0 ? str.charAt(0) : 0;
- if ((c < '0' || c > '9') && (c < 'a' || c > 'z')) {
- Validate.notBlank(str, message);
+ final int strLen = str != null ? str.length() : 0;
Review Comment:
I don't understand, you mean:
```
final int strLen = str != null && !str.isEmpty() ? str.length() : 0;
```
I kinda fail to see how adding an addition condition makes things more straightforward, but I guess that's a matter of taste, as a lot of things when we go to that level.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] elharo commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158836557
##########
maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java:
##########
@@ -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");
Review Comment:
better to use a NullPointerException for null. The tests below suggest this was the existing behavior.
##########
maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java:
##########
@@ -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())) {
Review Comment:
slightly clearer:
```
if (versionRange == null || versionRange.isEmpty())
```
##########
maven-artifact/pom.xml:
##########
@@ -30,12 +30,7 @@ under the License.
<name>Maven Artifact</name>
- <dependencies>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </dependency>
- </dependencies>
+ <dependencies />
Review Comment:
do we need the empty element or can we just drop it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158128883
##########
maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java:
##########
@@ -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"));
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] elharo commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158349551
##########
maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java:
##########
@@ -102,7 +102,9 @@ public boolean isMavenVersion(String versionRange) {
Version current;
try {
String mavenVersion = getMavenVersion();
- Validate.validState(StringUtils.isNotEmpty(mavenVersion), "Could not determine current Maven version");
+ if (!(mavenVersion != null && !mavenVersion.isEmpty())) {
Review Comment:
Remove double negative for clarity. That is,
```
if (mavenVersion == null || mavenVersion.isEmpty())
```
In this specific case, I'm tempted to drop the null check and just let the resulting NullPointerException signal the problem, and I do wonder if getMavenVersion might be guaranteed non-nullable here.
##########
maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java:
##########
@@ -40,7 +42,10 @@ public class ArtifactHandlerTest {
public void testAptConsistency() throws Exception {
File apt = getTestFile("src/site/apt/artifact-handlers.apt");
- List<String> lines = FileUtils.readLines(apt);
+ List<String> lines;
+ try (Stream<String> l = Files.lines(apt.toPath())) {
Review Comment:
Use Files.readAllLines instead, since this stream is immediately converted into a list.
This probably needs a charset too.
##########
maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java:
##########
@@ -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"));
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] elharo commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158893137
##########
maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java:
##########
@@ -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");
Review Comment:
That works :-)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158127500
##########
maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java:
##########
@@ -89,10 +88,15 @@ public static String key(String groupId, String artifactId, String version) {
}
private static void notBlank(String str, String message) {
- int c = str != null && str.length() > 0 ? str.charAt(0) : 0;
- if ((c < '0' || c > '9') && (c < 'a' || c > 'z')) {
- Validate.notBlank(str, message);
+ final int strLen = str != null ? str.length() : 0;
Review Comment:
The point is that the length is used after, so we need it anyway. I think the current version is the optimal one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158376329
##########
maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java:
##########
@@ -40,7 +42,10 @@ public class ArtifactHandlerTest {
public void testAptConsistency() throws Exception {
File apt = getTestFile("src/site/apt/artifact-handlers.apt");
- List<String> lines = FileUtils.readLines(apt);
+ List<String> lines;
+ try (Stream<String> l = Files.lines(apt.toPath())) {
Review Comment:
Thx, not sure how I missed that one !
I don't think a charset is needed: `Files.readAllLines` uses `UTF-8` which is the encoding used in the `artifact-handlers.apt` file.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] elharo commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1157734330
##########
maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java:
##########
@@ -89,10 +88,15 @@ public static String key(String groupId, String artifactId, String version) {
}
private static void notBlank(String str, String message) {
- int c = str != null && str.length() > 0 ? str.charAt(0) : 0;
- if ((c < '0' || c > '9') && (c < 'a' || c > 'z')) {
- Validate.notBlank(str, message);
+ final int strLen = str != null ? str.length() : 0;
Review Comment:
str != null && !str.isEmpty()
seems a little more straight-forward
##########
maven-core/src/main/java/org/apache/maven/internal/StringUtils.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.internal;
Review Comment:
This is what we should avoid. Apache commons already does this and pays more attention to it. Let's not add yet another variant of these classes
##########
maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java:
##########
@@ -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"));
Review Comment:
I don't understand why this changed here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #1080:
URL: https://github.com/apache/maven/pull/1080#issuecomment-1497298619
> Great to see these changes! I think the `is(Not)Empty` cases to move away from utils can also be reflected in an automated migration if you'd like me to roll that out across all of Maven. I think that was the most common use of utils.
>
> 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 `split` methods take a separator as a literal, rather than the regex it can be for `String.split`. We can explore what we can replace with JDK calls already, now, and I'll hold off on further Commons Lang changes while we do so.
>
> 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 `split` calls can be translated directly when the separator is a one-char string. Other cases may need to be handled differently.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158372332
##########
maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java:
##########
@@ -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"));
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158888542
##########
maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java:
##########
@@ -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");
Review Comment:
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");
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] timtebeek commented on pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "timtebeek (via GitHub)" <gi...@apache.org>.
timtebeek commented on PR #1080:
URL: https://github.com/apache/maven/pull/1080#issuecomment-1497290936
Great to see these changes! I think the `is(Not)Empty` cases to move away from utils can also be reflected in an automated migration if you'd like me to roll that out across all of Maven. I think that was the most common use of utils.
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 `split` methods take a separator as a literal, rather than the regex it can be for `String.split`. We can explore what we can replace with JDK calls already, now, and I'll hold off on further Commons Lang changes while we do so.
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158519203
##########
maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java:
##########
@@ -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"));
Review Comment:
I've splitted in two commits (not to be squashed) and two JIRA issues...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet merged pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet merged PR #1080:
URL: https://github.com/apache/maven/pull/1080
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158377618
##########
maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java:
##########
@@ -102,7 +102,9 @@ public boolean isMavenVersion(String versionRange) {
Version current;
try {
String mavenVersion = getMavenVersion();
- Validate.validState(StringUtils.isNotEmpty(mavenVersion), "Could not determine current Maven version");
+ if (!(mavenVersion != null && !mavenVersion.isEmpty())) {
Review Comment:
`getMavenVersion` is guaranteed to return a non null string (though it could be empty), so simplifying to `if (mavenVersion.isEmpty()) {` looks a good idea.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158128883
##########
maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java:
##########
@@ -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"));
Review Comment:
I can't, 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1158128883
##########
maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java:
##########
@@ -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"));
Review Comment:
I can't, because that one now passes, as `2.` is a legit float number according to the `Float.parseFloat` which is now used to validate the syntax.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] elharo commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1157809106
##########
maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java:
##########
@@ -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"));
Review Comment:
OK, so it's an extra test. That's fine, but I suggest also keeping
```
assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2.C"));
```
##########
maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java:
##########
@@ -89,10 +88,15 @@ public static String key(String groupId, String artifactId, String version) {
}
private static void notBlank(String str, String message) {
- int c = str != null && str.length() > 0 ? str.charAt(0) : 0;
- if ((c < '0' || c > '9') && (c < 'a' || c > 'z')) {
- Validate.notBlank(str, message);
+ final int strLen = str != null ? str.length() : 0;
Review Comment:
I was simply thinking
```
if (str != null && !str.isEmpty())
```
but this works too. Not a big deal.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1080: [MNG-6825] Get rid of commons-lang
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1080:
URL: https://github.com/apache/maven/pull/1080#discussion_r1157760976
##########
maven-core/src/main/java/org/apache/maven/internal/StringUtils.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.internal;
Review Comment:
I would challenge the _more attention_. The code has not changed in 16 years: https://github.com/apache/commons-lang/blob/LANG_2_0/src/java/org/apache/commons/lang/StringUtils.java#L221-L223. Again, I would agree if we were talking about any kind of substantial piece of code, but not one-liner functions...
Anyway, I'll get rid of `isNotBlank` as I think the usage of this method (only 2 locations) is incoherent with all other checks in Maven. And I'll ask my editor to inline the other methods.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org