[
https://issues.apache.org/jira/browse/MNG-8023?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17808779#comment-17808779
]
ASF GitHub Bot commented on MNG-8023:
-------------------------------------
gnodet commented on code in PR #1387:
URL: https://github.com/apache/maven/pull/1387#discussion_r1459536810
##########
api/maven-api-core/src/main/java/org/apache/maven/api/Project.java:
##########
@@ -37,24 +37,103 @@
@Experimental
public interface Project {
+ /**
+ * Returns the project groupId.
+ */
@Nonnull
String getGroupId();
+ /**
+ * Returns the project artifactId.
+ */
@Nonnull
String getArtifactId();
+ /**
+ * Returns the project version.
+ */
@Nonnull
String getVersion();
+ /**
+ * Returns the project packaging.
+ * <p>
+ * Note: unlike in legacy code, logical checks against string representing
packaging (returned by this method)
+ * are NOT recommended (code like {@code
"pom".equals(project.getPackaging)} must be avoided). Use method
+ * {@link #getArtifacts()} to gain access to POM or build artifact.
+ *
+ * @see #getArtifacts()
+ */
@Nonnull
String getPackaging();
+ /**
+ * 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).
+ *
+ * @see org.apache.maven.api.services.ArtifactManager#getPath(Artifact)
+ */
+ @Nonnull
+ 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
+ * as the one returned by {@link #getPomArtifact()}, if the project is
actually not producing any main artifact.
+ * The existence of artifact backing file depends on which lifecycle step
this method was invoked, as the file
+ * may not yet be built.
+ * <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. For non-POM
+ * artifacts one would filter for results having two elements, and would
consume second element of the list.
+ *
+ * @see #getArtifacts()
+ * @see org.apache.maven.api.services.ArtifactManager#getPath(Artifact)
+ */
+ @Nonnull
+ default Artifact getArtifact() {
+ List<Artifact> artifacts = getArtifacts();
+ return artifacts.get(artifacts.size() - 1);
+ }
+
+ /**
+ * Returns the project artifacts which are the project POM artifact and
the artifact produced by this project build.
+ * The list may have one or two elements (never less than 1, never more
than 2), depending on project packaging.
+ * <p>
+ * The list's first element is ALWAYS the project POM artifact. Presence
of second element in the list depends
+ * solely on this project packaging.
+ *
+ * @see #getPackaging()
+ * @see org.apache.maven.api.services.ArtifactManager#getPath(Artifact)
+ */
@Nonnull
- Artifact getArtifact();
+ List<Artifact> getArtifacts();
+
+ /**
+ * 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();
Review Comment:
This field is mutable. Do we want to add such methods to data objects ?
This is actually similar to `getRemoteProjectRepositories()`.
If we think that's ok, I think we need to get rid of the `getXxx()` on the
`ProjectManager` and only keep it with the modification methods only.
Thoughts ?
> New method for project artifacts
> --------------------------------
>
> Key: MNG-8023
> URL: https://issues.apache.org/jira/browse/MNG-8023
> Project: Maven
> Issue Type: Task
> Components: API
> Reporter: Tamas Cservenak
> Assignee: Tamas Cservenak
> Priority: Major
> Fix For: 4.0.0, 4.0.0-alpha-13
>
>
> Introduce a new method on API Project object that exposes "main artifacts" of
> project. The method can return 1 or 2 artifacts (never less than 1 and never
> more than 2). These are NOT the attached artifacts! (see ProjectManager for
> that).
> In short: projects with packaging "pom", "bom" (that produce only one
> artifact) will on this method return 1 artifact, while projects for example
> with packaging "jar" will return 2 artifacts (as they produce, install,
> deploy two artifacts, the POM and the JAR/WAR/etc).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)