[
https://issues.apache.org/jira/browse/MRESOLVER-465?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17807712#comment-17807712
]
ASF GitHub Bot commented on MRESOLVER-465:
------------------------------------------
gnodet commented on code in PR #407:
URL: https://github.com/apache/maven-resolver/pull/407#discussion_r1455436530
##########
maven-resolver-util/src/main/java/org/eclipse/aether/util/version/GenericVersionConstraint.java:
##########
@@ -28,6 +28,8 @@
/**
* A constraint on versions for a dependency.
+ * <p>
+ * Despite its name, this class is generic in a sense it works with any {@link
Version}.
Review Comment:
Who cares if the classes are protected and final ?
This only makes sense if these implementation classes are made `public`.
##########
maven-resolver-util/src/main/java/org/eclipse/aether/util/version/VersionSchemeSupport.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.eclipse.aether.util.version;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.aether.version.InvalidVersionSpecificationException;
+import org.eclipse.aether.version.VersionRange;
+import org.eclipse.aether.version.VersionScheme;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * A version scheme support class. A new implementation should extend this
class and would receive full support for
+ * ranges and constraints. The new implementation should implement {@link
org.eclipse.aether.version.Version} and
+ * the one missing method in this class, the {@link #parseVersion(String)}.
+ *
+ * @since 2.0.0
+ */
+public abstract class VersionSchemeSupport implements VersionScheme {
+ @Override
+ public GenericVersionRange parseVersionRange(final String range) throws
InvalidVersionSpecificationException {
+ return new GenericVersionRange(this, range);
+ }
+
+ @Override
+ public GenericVersionConstraint parseVersionConstraint(final String
constraint)
+ throws InvalidVersionSpecificationException {
+ String process = requireNonNull(constraint, "constraint cannot be
null");
+
+ Collection<VersionRange> ranges = new ArrayList<>();
+
+ while (process.startsWith("[") || process.startsWith("(")) {
+ int index1 = process.indexOf(')');
+ int index2 = process.indexOf(']');
+
+ int index = index2;
+ if (index2 < 0 || (index1 >= 0 && index1 < index2)) {
+ index = index1;
+ }
+
+ if (index < 0) {
+ throw new InvalidVersionSpecificationException(constraint,
"Unbounded version range " + constraint);
+ }
+
+ VersionRange range = parseVersionRange(process.substring(0, index
+ 1));
+ ranges.add(range);
+
+ process = process.substring(index + 1).trim();
+
+ if (process.startsWith(",")) {
+ process = process.substring(1).trim();
+ }
+ }
+
+ if (!process.isEmpty() && !ranges.isEmpty()) {
+ throw new InvalidVersionSpecificationException(
+ constraint, "Invalid version range " + constraint + ",
expected [ or ( but got " + process);
+ }
+
+ GenericVersionConstraint result;
+ if (ranges.isEmpty()) {
+ result = new GenericVersionConstraint(parseVersion(constraint));
+ } else {
+ result = new
GenericVersionConstraint(UnionVersionRange.from(ranges));
+ }
+
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ return obj != null && getClass().equals(obj.getClass());
+ }
+
+ @Override
+ public int hashCode() {
Review Comment:
Useless
##########
maven-resolver-util/src/main/java/org/eclipse/aether/util/version/VersionSchemeSupport.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.eclipse.aether.util.version;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.aether.version.InvalidVersionSpecificationException;
+import org.eclipse.aether.version.VersionRange;
+import org.eclipse.aether.version.VersionScheme;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * A version scheme support class. A new implementation should extend this
class and would receive full support for
+ * ranges and constraints. The new implementation should implement {@link
org.eclipse.aether.version.Version} and
+ * the one missing method in this class, the {@link #parseVersion(String)}.
+ *
+ * @since 2.0.0
+ */
+public abstract class VersionSchemeSupport implements VersionScheme {
+ @Override
+ public GenericVersionRange parseVersionRange(final String range) throws
InvalidVersionSpecificationException {
+ return new GenericVersionRange(this, range);
+ }
+
+ @Override
+ public GenericVersionConstraint parseVersionConstraint(final String
constraint)
Review Comment:
Same.
This should even cause a warning as `GenericVersionConstraint` is exported
outside it's visibility.
##########
maven-resolver-util/src/main/java/org/eclipse/aether/util/version/GenericVersionRange.java:
##########
@@ -23,13 +23,17 @@
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version;
import org.eclipse.aether.version.VersionRange;
+import org.eclipse.aether.version.VersionScheme;
import static java.util.Objects.requireNonNull;
/**
* A version range inspired by mathematical range syntax. For example,
"[1.0,2.0)", "[1.0,)" or "[1.0]".
+ * <p>
+ * Despite its name, this class is generic in a sense it works with any {@link
Version}
Review Comment:
Same
##########
maven-resolver-util/src/main/java/org/eclipse/aether/util/version/VersionSchemeSupport.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.eclipse.aether.util.version;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.aether.version.InvalidVersionSpecificationException;
+import org.eclipse.aether.version.VersionRange;
+import org.eclipse.aether.version.VersionScheme;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * A version scheme support class. A new implementation should extend this
class and would receive full support for
+ * ranges and constraints. The new implementation should implement {@link
org.eclipse.aether.version.Version} and
+ * the one missing method in this class, the {@link #parseVersion(String)}.
+ *
+ * @since 2.0.0
+ */
+public abstract class VersionSchemeSupport implements VersionScheme {
+ @Override
+ public GenericVersionRange parseVersionRange(final String range) throws
InvalidVersionSpecificationException {
+ return new GenericVersionRange(this, range);
+ }
+
+ @Override
+ public GenericVersionConstraint parseVersionConstraint(final String
constraint)
+ throws InvalidVersionSpecificationException {
+ String process = requireNonNull(constraint, "constraint cannot be
null");
+
+ Collection<VersionRange> ranges = new ArrayList<>();
+
+ while (process.startsWith("[") || process.startsWith("(")) {
+ int index1 = process.indexOf(')');
+ int index2 = process.indexOf(']');
+
+ int index = index2;
+ if (index2 < 0 || (index1 >= 0 && index1 < index2)) {
+ index = index1;
+ }
+
+ if (index < 0) {
+ throw new InvalidVersionSpecificationException(constraint,
"Unbounded version range " + constraint);
+ }
+
+ VersionRange range = parseVersionRange(process.substring(0, index
+ 1));
+ ranges.add(range);
+
+ process = process.substring(index + 1).trim();
+
+ if (process.startsWith(",")) {
+ process = process.substring(1).trim();
+ }
+ }
+
+ if (!process.isEmpty() && !ranges.isEmpty()) {
+ throw new InvalidVersionSpecificationException(
+ constraint, "Invalid version range " + constraint + ",
expected [ or ( but got " + process);
+ }
+
+ GenericVersionConstraint result;
+ if (ranges.isEmpty()) {
+ result = new GenericVersionConstraint(parseVersion(constraint));
+ } else {
+ result = new
GenericVersionConstraint(UnionVersionRange.from(ranges));
+ }
+
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
Review Comment:
Does it make sense at all ? This isn't a data object. If there's a need,
they should be identified by a name imho.
> Make room for new version scheme implementations
> ------------------------------------------------
>
> Key: MRESOLVER-465
> URL: https://issues.apache.org/jira/browse/MRESOLVER-465
> Project: Maven Resolver
> Issue Type: Improvement
> Components: Resolver
> Reporter: Tamas Cservenak
> Assignee: Tamas Cservenak
> Priority: Major
> Fix For: 2.0.0, 2.0.0-alpha-7
>
>
> Since eons Resolver had the "generic" scheme implementing the {{Version}},
> {{VersionRange}} and {{VersionConstraint}} API interfaces.
> Interesting fact: {{GenericVersionRange}} and {{GenericVersionConstraint}}
> are NOT tied in any way to {{GenericVersion}} implementation, they are happy
> with plain {{Version}} interface as well, they are truly "generic".
> This means, that a scheme needs really only to provide {{Version}}
> implementation (currently in form of {{GenericVersion}}) and a "factory" for
> it (currently in a form of {{GenericVersionScheme}}).
> Refactor a bit, and make room for alternate {{Version}} implementations.
> Fact: the change can be done in source and binary compatible way, and is
> enforced by japicmp.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)