Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve API doc for ArtifactHandler #1193

Merged
merged 3 commits into from
Aug 22, 2023
Merged

Improve API doc for ArtifactHandler #1193

merged 3 commits into from
Aug 22, 2023

Conversation

elharo
Copy link
Contributor

@elharo elharo commented Jul 2, 2023

Noticed this was a unclear and out of date

Noticed this was a unclear and out of date
@elharo elharo requested a review from gnodet July 2, 2023 12:02
@elharo elharo changed the title Rewrite API doc Rewrite API doc for ArtifactHandler Jul 2, 2023
@hboutemy hboutemy changed the title Rewrite API doc for ArtifactHandler Improve API doc for ArtifactHandler Jul 3, 2023
Copy link
Member

@hboutemy hboutemy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on packaging field, i think this is the most confusing parameter that lead to misunderstandings for year: packaging field is the "probable" packaging that created the artifact (if there is any probable one, as any packaging may create a source or javadoc artifact): I'm sure this API is unused; because I don't see how it can be reasonably used

on directory, I don't know at all what the intent was

everything I wrote in the documentation (like https://maven.apache.org/ref/3.9.3/maven-core/artifact-handlers.html) is based on years of thoughts trying to understand the initial intent of the code, that was written before i was involved...

thanks for helping digging into it

@@ -41,7 +42,7 @@ public interface ArtifactHandler {
String getDirectory();

/**
* Get the classifier associated to the dependency type.
* Returns the classifier of the dependency.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while we are at clarifying, it is the default classifier: user may override the value in his pom.xml dependency (by defining a classifier)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this is the classifier from the artifact's own pom.xml?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ArtifactHandler is unrelated to the artifact's own pom.xml.
The ArtifactHandler is used to determine a few informations about a dependency. It is retrieved based on the dependency type. But the Dependency can define a classifier, which takes precedence over the default one provided by the artifact handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking through the code, I think this is the default classifier:only if the dependency element doesn't specify one, and tbhat's the empty string (o null?). This should only be set if the dependency element explicitly sets it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, classifier -> default classifier

@@ -19,7 +19,7 @@
package org.apache.maven.artifact.handler;

/**
* An artifact handler defines for a dependency type, defined as Plexus role:<ul>
* An artifact handler provides metadata for an artifact derived from the dependency element that references the artifact:<ul>
* <li>extension and classifier, to be able to download the file,</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we talk about default extension and classifier as those can always be further specified when actually adding a dependency to those artifacts ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this always provide the info from the artifact's own pom.xml?

I'm a little confused because if the classifier is used to download the file as seen in the first bullet point then it has to come from the dependency element that loads the artifact, not the artifact's own pom.xml. Maybe the first bullet point is wrong?

Copy link
Contributor

@gnodet gnodet Jul 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below, the artifact's own pom.xml is not used at all here afaik.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on extension, there is no way to override it: then it's directly the extension
that's one reason why most people are confused by the (lack of) difference between type and extension, while there is a difference between the default classifier and the effective classifier

@@ -41,7 +42,7 @@ public interface ArtifactHandler {
String getDirectory();

/**
* Get the classifier associated to the dependency type.
* Returns the classifier of the dependency.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is wrong, the previous wording was better imho, as the handler does not define a dependency, but a dependency type.
So maybe something like Returns the default classifier used for dependencies of that type. or something like that ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure there is such a thing as a "dependency type" and I'd prefer to avoid that term completely. If it's confusing us, it will certainly confuse end users. I think there are three things in play here:

  1. The binary artifact served from the repository, such as a jar file, a signature file, or a pom.xml file

  2. The pom.xml for the artifact. For a jar file this is the pom.xml from which the jar was built, though I'm not sure this is meaningful for anything but the regular jar containing .class files. I'm not sure if it makes sense for javadoc or source jars or non-jars. This is the pom found in the same directory as the jar.

  3. The pom.xml that imports the artifact using a dependency element.

This dependency can declare a different packaging and other properties of the artifact.

So does ArtifactHandler report number 3 or number 2 if both are present? Or does the answer to this question depend on which property we're looking at?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2 is not used with ArtifactHandler afaik. The ArtifactHandler is used to compute #3 in case it is not explicitly set in the pom.

I think the concept of type leaks throughout the API. It was present in the v3 api and in the model. However, this api is somewhat flawed because the Artifact is used as both an artifact and a dependency. The v4 api tries to clear things a bit by splitting Artifact, ArtifactCoordinate, Dependency and DependencyCoordinate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, if Artifact in Maven core did not mix features from Artifact and Dependency (as Maven Resolver documented and solved 10 years later), this ArtifactHandler should have been named DependencyHandler
Because it's what that class does: define how to handle a dependency
IMHO, saying "artifact/dependency handler" in the javadoc could help understand reality

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the v4 api provides Type as an equivalent to v3 ArtifactHandler, directly accessible using Dependency#getType(). Maybe the api could be improved at the same time (replace artifact type with dependency type as a first step for example).

Copy link
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make it more explicit that the artifact handler provides default values.

@@ -19,10 +19,10 @@
package org.apache.maven.artifact.handler;

/**
* An artifact handler defines for a dependency type, defined as Plexus role:<ul>
* <li>extension and classifier, to be able to download the file,</li>
* An artifact handler contains metadata derived from the dependency element that references the artifact:<ul>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's true.
The metadata is not derived from the dependency element. The set of artifact handlers is reduced and provides metadata related to the dependency type.

* An artifact handler defines for a dependency type, defined as Plexus role:<ul>
* <li>extension and classifier, to be able to download the file,</li>
* An artifact handler contains metadata derived from the dependency element that references the artifact:<ul>
* <li>extension and classifier, to be able to download the file</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extension and classifier -> défaut extension and classifier

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally, it's more extension and default classifier

* <li>information on how to use the artifact: whether to add it to the classpath, or to take into account its
* dependencies.</li>
* dependencies</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the . and add , at the end of the previous <li>.

@@ -41,7 +42,7 @@ public interface ArtifactHandler {
String getDirectory();

/**
* Get the classifier associated to the dependency type.
* Returns the classifier of the dependency.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, classifier -> default classifier

Copy link
Contributor Author

@elharo elharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL

@elharo elharo dismissed hboutemy’s stale review August 22, 2023 11:52

I think the comments are no longer aplicable to the current version, but if they are we can make further changes

@elharo elharo merged commit 421a23a into master Aug 22, 2023
20 of 21 checks passed
@elharo elharo deleted the elharo-patch-1 branch August 22, 2023 11:52
@gnodet gnodet added this to the 4.0.0-alpha-8 milestone Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants