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

[MNG-8023] New method + javadoc on Project #1387

Merged
merged 20 commits into from
Jan 23, 2024
Merged
38 changes: 36 additions & 2 deletions api/maven-api-core/src/main/java/org/apache/maven/api/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,31 @@ public interface Project {
String getPackaging();

/**
* Returns the project artifact, that is the artifact produced by this project build.
* Returns the project POM artifact, that is the artifact of the POM of this project. Every project have POM
* artifact, while the existence of backing POM file is NOT a requirement (i.e. for some transient projects).
Copy link
Contributor

@gnodet gnodet Jan 19, 2024

Choose a reason for hiding this comment

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

Returns the project POM artifact, which is the artifact of the POM of this project. Every project have a POM
artifact, even if the existence of backing POM file is NOT a requirement (i.e. for some transient projects).

Copy link
Contributor

Choose a reason for hiding this comment

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

While we're at it, we're missing a paragraph to explain the behaviour in case a ModelParser is used (for example to parse a POM in a different syntax/language). I'll need to have a look at that.

Copy link
Member Author

Choose a reason for hiding this comment

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

K, will wait for your evaluation...

*
* @see org.apache.maven.api.services.ArtifactManager#getPath(Artifact)
*/
@Nonnull
Artifact getArtifact();
default Artifact getPomArtifact() {
return getArtifacts().get(0);
}

/**
* Returns the project artifact, that is the artifact produced by this project build. This artifact MAY be same
cstamas marked this conversation as resolved.
Show resolved Hide resolved
* as the one returned by {@link #getPomArtifact()}, if the project is actually not producing any main artifact.
* <p>
* If only non-POM artifacts are needed, better use {@link #getArtifacts()} method: if that method returns list
* having one element, the methods {@link #getPomArtifact()} and this one will return same artifact.
*
* @see #getArtifacts()
* @see org.apache.maven.api.services.ArtifactManager#getPath(Artifact)
*/
@Nonnull
michael-o marked this conversation as resolved.
Show resolved Hide resolved
default Artifact getArtifact() {
List<Artifact> artifacts = getArtifacts();
return artifacts.get(artifacts.size() - 1);
michael-o marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Returns the project artifacts which are the project POM artifact and the artifact produced by this project build.
Expand All @@ -88,6 +107,21 @@ public interface Project {
@Nonnull
List<Artifact> getArtifacts();
michael-o marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns project's all artifacts. The list contains all artifacts, even the attached ones, if any. Hence, the
* list returned by this method depends on which lifecycle step of the build was it invoked. The head of returned
* list is result of {@link #getArtifacts()} method, so same applies here: the list can have minimum of one
* element. The maximum number of elements is in turn dependent on build configuration and lifecycle phase when
* this method was invoked (i.e. is javadoc jar built and attached, is sources jar built attached, are all the
* artifact signed, etc.).
* <p>
* This method is shorthand for {@link #getArtifacts()} and
* {@link org.apache.maven.api.services.ProjectManager#getAttachedArtifacts(Project)} methods.
*
* @see org.apache.maven.api.services.ArtifactManager#getPath(Artifact)
*/
List<Artifact> getAllArtifacts();
gnodet marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns the project model.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.model.DependencyManagement;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.services.ProjectManager;
import org.apache.maven.api.services.TypeRegistry;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.ProjectArtifact;
Expand Down Expand Up @@ -69,12 +70,6 @@ public String getVersion() {
return project.getVersion();
}

@Nonnull
@Override
public Artifact getArtifact() {
return session.getArtifact(RepositoryUtils.toArtifact(project.getArtifact()));
}

@Nonnull
@Override
public List<Artifact> getArtifacts() {
Expand All @@ -89,6 +84,14 @@ public List<Artifact> getArtifacts() {
return result;
}

@Override
public List<Artifact> getAllArtifacts() {
ArrayList<Artifact> result = new ArrayList<>(2);
result.addAll(getArtifacts());
result.addAll(session.getService(ProjectManager.class).getAttachedArtifacts(this));
return result;
}

@Nonnull
@Override
public String getPackaging() {
Expand Down