You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "cstamas (via GitHub)" <gi...@apache.org> on 2024/02/01 16:49:20 UTC
[PR] Apply similar pattern as for relocation source [maven]
cstamas opened a new pull request, #1397:
URL: https://github.com/apache/maven/pull/1397
Keep legacy/deprecated, but given it was marked as "work in progress" we may also just remove it.
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
Re: [PR] Apply similar pattern as for relocation source [maven]
Posted by "gnodet (via GitHub) via issues" <is...@maven.apache.org>.
gnodet commented on code in PR #1397:
URL: https://github.com/apache/maven/pull/1397#discussion_r4798297023
##########
maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java:
##########
@@ -99,7 +100,7 @@ public DefaultArtifactDescriptorReader(
this.modelCacheFactory = Objects.requireNonNull(modelCacheFactory, "modelCacheFactory cannot be null");
this.artifactRelocationSources =
Objects.requireNonNull(artifactRelocationSources, "artifactRelocationSources cannot be null");
- this.delegate = new ArtifactDescriptorReaderDelegate();
+ this.artifactDescriptorReaderSources = artifactDescriptorReaderSources;
Review Comment:
**Missing null check for artifactDescriptorReaderSources parameter**
The new constructor parameter `artifactDescriptorReaderSources` is not null-checked, unlike all other parameters in the constructor. This could lead to a NullPointerException later when the code iterates over `.values()`.
**Suggestion:**
```java
this.artifactDescriptorReaderSources =
Objects.requireNonNull(artifactDescriptorReaderSources, "artifactDescriptorReaderSources cannot be null");
```
##########
maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java:
##########
@@ -110,14 +111,24 @@ public ArtifactDescriptorResult readArtifactDescriptor(
Model model = loadPom(session, request, result);
if (model != null) {
Map<String, Object> config = session.getConfigProperties();
- ArtifactDescriptorReaderDelegate delegate =
- (ArtifactDescriptorReaderDelegate) config.get(ArtifactDescriptorReaderDelegate.class.getName());
+ // similar logic as before: if configuration contains ArtifactDescriptorReaderSource, use that
+ ArtifactDescriptorReaderSource delegate =
+ (ArtifactDescriptorReaderSource) config.get(ArtifactDescriptorReaderSource.class.getName());
if (delegate == null) {
- delegate = this.delegate;
+ // fallback to legacy
+ delegate =
+ (ArtifactDescriptorReaderSource) config.get(ArtifactDescriptorReaderDelegate.class.getName());
}
- delegate.populateResult(session, result, model);
+ if (delegate != null) {
+ delegate.populateResult(session, result, model);
+ } else {
+ // the "normal" way is to ask all to populate
+ for (ArtifactDescriptorReaderSource source : artifactDescriptorReaderSources.values()) {
Review Comment:
**Multiple concerns with the sources iteration:**
1. **Map iteration order doesn't respect @Priority annotations** - The code iterates over `artifactDescriptorReaderSources.values()`, but Map iteration order doesn't respect the `@Priority` annotations on implementations (CoreArtifactDescriptorReaderSource has priority 5, CorePluginArtifactDescriptorReaderSource has priority 15). If processing order matters, consider using a sorted collection.
2. **Exception handling: fail-fast behavior** - If one source throws an `ArtifactDescriptorException`, the loop terminates and subsequent sources won't be called. Is this intended? Should all sources be attempted?
3. **Behavior change with empty sources** - If the injected map is empty, no sources will be called. This differs from the previous implementation which always called the delegate. This could cause issues if no implementations are found during component scanning.
##########
maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/reader/CorePluginArtifactDescriptorReaderSource.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.reader;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.apache.maven.model.*;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.ArtifactProperties;
+import org.eclipse.aether.resolution.ArtifactDescriptorResult;
+import org.eclipse.sisu.Priority;
+
+/**
+ * The core source, that kicks in ONLY when Maven Core is resolving a maven-plugin as part of the build: it populates
+ * the current Maven Runtime dependency Management.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named(CorePluginArtifactDescriptorReaderSource.NAME)
+@Priority(15)
+public class CorePluginArtifactDescriptorReaderSource extends ArtifactDescriptorReaderSourceSupport {
+ public static final String NAME = "corePlugin";
+
+ @Override
+ public void populateResult(RepositorySystemSession session, ArtifactDescriptorResult result, Model model) {
+ String context = result.getRequest().getRequestContext();
+ String type = result.getRequest().getArtifact().getProperty(ArtifactProperties.TYPE, "");
+ // augment PluginDependenciesResolver with Maven Core constituents
+ if (context != null && context.startsWith("plugin") && type.equals("maven-plugin")) {
Review Comment:
**Incomplete implementation with TODO**
This source is registered as a component but currently does nothing except check conditions and has a TODO. This means it will be invoked for every artifact descriptor read operation but provides no value.
**Consider:**
1. Remove this class until the feature is ready to implement
2. Keep it but add a clear comment explaining it's a placeholder for future work
3. Implement the TODO in this PR
As-is, it adds unnecessary overhead to every artifact resolution without providing functionality.
--
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