[
https://issues.apache.org/jira/browse/MNG-7741?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17703070#comment-17703070
]
ASF GitHub Bot commented on MNG-7741:
-------------------------------------
grgrzybek commented on code in PR #1058:
URL: https://github.com/apache/maven/pull/1058#discussion_r1142976951
##########
maven-core/src/main/java/org/apache/maven/internal/aether/ReverseTreeRepositoryListener.java:
##########
@@ -49,45 +56,128 @@ class ReverseTreeRepositoryListener extends
AbstractRepositoryListener {
public void artifactResolved(RepositoryEvent event) {
requireNonNull(event, "event cannot be null");
- if (!isLocalRepositoryArtifact(event.getSession(),
event.getArtifact())) {
+ if (!isLocalRepositoryArtifactOrMissing(event.getSession(),
event.getArtifact())) {
return;
}
- CollectStepData collectStepTrace =
lookupCollectStepData(event.getTrace());
- if (collectStepTrace == null) {
- return;
+ RequestTrace trace = event.getTrace();
+
+ CollectStepData collectStepTrace = null;
+ ArtifactRequest artifactRequest = null;
+ ArtifactDescriptorRequest artifactDescriptorRequest = null;
+ Plugin plugin = null;
+
+ while (trace != null) {
+ Object data = trace.getData();
+ if (data instanceof CollectStepData) {
+ collectStepTrace = (CollectStepData) data;
+ } else if (data instanceof ArtifactDescriptorRequest) {
+ artifactDescriptorRequest = (ArtifactDescriptorRequest) data;
+ } else if (data instanceof ArtifactRequest) {
+ artifactRequest = (ArtifactRequest) data;
+ } else if (data instanceof Plugin) {
+ plugin = (Plugin) data;
+ }
+ trace = trace.getParent();
}
- Artifact resolvedArtifact = event.getArtifact();
- Artifact nodeArtifact = collectStepTrace.getNode().getArtifact();
-
- if (isInScope(resolvedArtifact, nodeArtifact)) {
- Dependency node = collectStepTrace.getNode();
- ArrayList<String> trackingData = new ArrayList<>();
- trackingData.add(node + " (" + collectStepTrace.getContext() +
")");
- String indent = "";
- ListIterator<DependencyNode> iter = collectStepTrace
- .getPath()
- .listIterator(collectStepTrace.getPath().size());
- while (iter.hasPrevious()) {
- DependencyNode curr = iter.previous();
+ Path trackingDir;
+ boolean missing = event.getFile() == null;
+ if (missing) {
+ // missing artifact - let's track the path anyway
+ File dir = event.getSession().getLocalRepository().getBasedir();
+ dir = new File(
+ dir,
event.getSession().getLocalRepositoryManager().getPathForLocalArtifact(event.getArtifact()));
+ trackingDir = dir.getParentFile().toPath().resolve(".tracking");
+ } else {
+ trackingDir =
event.getFile().getParentFile().toPath().resolve(".tracking");
+ }
+
+ String baseName;
+ String ext = missing ? ".miss" : ".dep";
+ Path trackingFile = null;
+
+ String indent = "";
+ ArrayList<String> trackingData = new ArrayList<>();
+
+ if (collectStepTrace == null && plugin != null) {
+ ext = ".plugin";
+ baseName = plugin.getGroupId() + "_" + plugin.getArtifactId() +
"_" + plugin.getVersion();
+ trackingFile = trackingDir.resolve(baseName + ext);
+ if (Files.exists(trackingFile)) {
+ return;
+ }
+
+ if (event.getArtifact() != null) {
+ trackingData.add(indent + event.getArtifact());
+ indent += " ";
+ }
+ trackingData.add(indent + plugin.getGroupId() + ":" +
plugin.getArtifactId() + ":" + plugin.getVersion());
+ indent += " ";
+
+ InputLocation location = plugin.getLocation("");
+ if (location != null && location.getSource() != null) {
+ trackingData.add(indent + location.getSource().getModelId() +
" (implicit)");
indent += " ";
- trackingData.add(indent + curr + " (" +
collectStepTrace.getContext() + ")");
}
- try {
- Path trackingDir =
-
resolvedArtifact.getFile().getParentFile().toPath().resolve(".tracking");
- Files.createDirectories(trackingDir);
- Path trackingFile = trackingDir.resolve(collectStepTrace
+ } else if (collectStepTrace != null) {
+ baseName =
+
collectStepTrace.getPath().get(0).getArtifact().toString().replace(":", "_");
Review Comment:
Hmm, `org.eclipse.aether.artifact.AbstractArtifact#toString()` also uses
extension and classifier, but
`org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper#getArtifactName()`
does not (and it's private, but using `nameLocks()` sounds like mixing
concepts here - I don't deal with locks...)
Is there any other sanitizing method?
> Add more information when using -Dmaven.repo.local.recordReverseTree=true
> -------------------------------------------------------------------------
>
> Key: MNG-7741
> URL: https://issues.apache.org/jira/browse/MNG-7741
> Project: Maven
> Issue Type: Improvement
> Reporter: Grzegorz Grzybek
> Priority: Major
>
> I much appreciate adding {{-Dmaven.repo.local.recordReverseTree=true}} option
> to Maven Core (supported by new resolver features).
> After initial idea, I added few more options to
> https://github.com/grgrzybek/tracking-maven-extension and I'd be happy to see
> these in {{org.apache.maven.internal.aether.ReverseTreeRepositoryListener}}.
> I did some experiments locally and I have improvement ready which:
> h5. tracks information about missing dependencies
> when using non-existing dependency (like {{org.slf4j:slf4j-apix}}), I can see
> {{~/.m2/repository/org/slf4j/slf4j-apix/1.7.36/.tracking/grgr_simplest_jar_1.0.miss}}
> file with:
> {noformat}
> org.slf4j:slf4j-apix:pom:1.7.36
> org.slf4j:slf4j-apix:jar:1.7.36 (compile) (project)
> grgr:simplest:jar:1.0 (project)
> Configured repositories:
> - central : https://repo.maven.apache.org/maven2
> {noformat}
> h5. tracks information about actual repository information (in
> {{_remote.repositories}} we have only the ID)
> For example
> {noformat}
> org.apache.maven.plugins:maven-compiler-plugin:pom:3.10.1
> org.apache.maven.plugins:maven-compiler-plugin:3.10.1
> org.apache.maven:maven-core:3.9.1:default-lifecycle-bindings (implicit)
> Repository: central (https://repo.maven.apache.org/maven2, default, releases)
> {noformat}
> h5. tracks information where only POM is downloaded
> For example with
> {{~/.m2/repository/com/google/guava/guava-parent/16.0.1/.tracking/org.apache.maven.plugins_maven-surefire-plugin_jar_3.0.0.dep}}:
> {noformat}
> com.google.guava:guava-parent:pom:16.0.1
> com.google.guava:guava:jar:16.0.1 (compile) (plugin)
> org.sonatype.sisu:sisu-guice:jar:no_aop:3.2.3 (compile) (plugin)
> org.apache.maven:maven-core:jar:3.2.5 (provided) (plugin)
> org.apache.maven.shared:maven-common-artifact-filters:jar:3.1.1
> (compile) (plugin)
> org.apache.maven.surefire:maven-surefire-common:jar:3.0.0 (compile)
> (plugin)
> org.apache.maven.plugins:maven-surefire-plugin:jar:3.0.0 ()
> (plugin)
> Repository: central (https://repo.maven.apache.org/maven2, default, releases)
> {noformat}
> h5. tracks reverse trees originating from plugins (also implicit ones)
> {noformat}
> org.apache:apache:pom:26
> org.apache.maven.plugins:maven-resources-plugin:3.3.0
> org.apache.maven:maven-core:3.9.1:default-lifecycle-bindings (implicit)
> Repository: central (https://repo.maven.apache.org/maven2, default, releases)
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)