Copilot commented on code in PR #12504:
URL: https://github.com/apache/maven/pull/12504#discussion_r3608749117
##########
pom.xml:
##########
@@ -144,7 +144,7 @@ under the License.
<securityDispatcherVersion>2.0</securityDispatcherVersion>
<cipherVersion>2.0</cipherVersion>
<jxpathVersion>1.4.0</jxpathVersion>
- <resolverVersion>2.0.20</resolverVersion>
+ <resolverVersion>2.0.21-SNAPSHOT</resolverVersion>
Review Comment:
The PR title/issue says “Update to Resolver 2.0.21”, but the property is set
to a snapshot (2.0.21-SNAPSHOT). This makes the build depend on snapshot
artifacts and also reads as a mismatch with the stated goal. Please either
switch to the released 2.0.21 (if available) or adjust the PR title/description
to explicitly call out the snapshot dependency.
##########
maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/metadata/ValidatingMetadataXpp3Reader.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.repository.internal.metadata;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import org.apache.maven.artifact.repository.metadata.Metadata;
+import org.apache.maven.artifact.repository.metadata.Versioning;
+import
org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.util.PathUtils;
+
+/**
+ * Validating metadata reader.
+ *
+ * @since 3.10.0
+ */
+public final class ValidatingMetadataXpp3Reader {
+ private final MetadataXpp3Reader mr = new MetadataXpp3Reader();
+
+ /**
+ * Delegates to {@link MetadataXpp3Reader#read(Reader, boolean)}
+ */
+ public Metadata read(Reader reader, boolean strict) throws IOException,
XmlPullParserException {
+ return validate(mr.read(reader, strict));
+ }
+
+ /**
+ * Delegates to {@link MetadataXpp3Reader#read(InputStream, boolean)}
+ */
+ public Metadata read(InputStream in, boolean strict) throws IOException,
XmlPullParserException {
+ return validate(mr.read(in, strict));
+ }
+
+ /**
+ * Validates {@link Metadata}.
+ */
+ public static Metadata validate(Metadata metadata) {
+ if (metadata != null) {
+ PathUtils.validatePathComponent(metadata.getVersion(), "version");
+ Versioning versioning = metadata.getVersioning();
+ if (versioning != null) {
Review Comment:
New metadata validation logic is introduced here, but there are no
accompanying tests to assert that valid metadata parses successfully and
invalid version/path components are rejected (and how the failure is surfaced).
Adding tests would help prevent regressions and document the intended
validation rules.
##########
maven-core/src/main/java/org/apache/maven/internal/aether/MavenValidator.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.aether;
+
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.graph.Dependency;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.spi.validator.Validator;
+import org.eclipse.aether.util.PathUtils;
+
+/**
+ * Simplest Maven specific validator that is meant to prevent un-interpolated
+ * elements enter resolver; if it does, is most likely some bug.
+ * <p>
+ * Note: {@link org.eclipse.aether.repository.RemoteRepository} is not
validated here,
+ * see <a href="https://github.com/apache/maven/issues/7398">GH-7398</a> for
details,
+ * and to keep very same behavior as Maven 3 did so far. If you want more,
upgrade to Maven 4 ;)
+ */
+public class MavenValidator implements Validator {
+ protected boolean containsPlaceholder(String value) {
+ return value != null && value.contains("${");
+ }
+
+ @Override
+ public void validateArtifact(Artifact artifact) throws
IllegalArgumentException {
+ if (containsPlaceholder(artifact.getGroupId())
+ || containsPlaceholder(artifact.getArtifactId())
+ || containsPlaceholder(artifact.getVersion())
+ || containsPlaceholder(artifact.getClassifier())
+ || containsPlaceholder(artifact.getExtension())) {
+ throw new IllegalArgumentException("Not fully interpolated
artifact " + artifact);
+ }
+ PathUtils.validateArtifactComponents(artifact);
+ }
Review Comment:
This introduces a new Resolver Validator implementation, but there are no
tests verifying the placeholder detection and the expected
IllegalArgumentException behavior for artifacts/metadata/dependencies. Adding
unit tests would ensure the validator enforces the intended contract and stays
compatible with future resolver changes.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]