maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [maven] michael-o commented on a change in pull request #358: [MNG-5868] No duplicate artifacts in attached artifacts
Date Mon, 01 Jun 2020 22:13:11 GMT

michael-o commented on a change in pull request #358:
URL: https://github.com/apache/maven/pull/358#discussion_r433517838



##########
File path: maven-core/src/main/java/org/apache/maven/project/MavenProject.java
##########
@@ -921,12 +926,20 @@ public void setInjectedProfileIds( String source, List<String>
injectedProfileId
      * coordinates.
      *
      * @param artifact the artifact to add or replace.
-     * @throws DuplicateArtifactAttachmentException
+     * @deprecated Please use {@link MavenProjectHelper}
+     * @throws DuplicateArtifactAttachmentException not used anymore but leave it for backward
compatibility
      */
     public void addAttachedArtifact( Artifact artifact )
         throws DuplicateArtifactAttachmentException
     {
-        getAttachedArtifacts().add( artifact );
+        // if already there we remove it and add again
+        int index = attachedArtifacts.indexOf( artifact );
+        if ( index > 0 )
+        {
+            LOGGER.warn( "artifact {} already attached, remove previous instance and add
again" );

Review comment:
       So we decide to have last wins?

##########
File path: maven-core/src/main/java/org/apache/maven/project/MavenProject.java
##########
@@ -921,12 +926,20 @@ public void setInjectedProfileIds( String source, List<String>
injectedProfileId
      * coordinates.
      *
      * @param artifact the artifact to add or replace.
-     * @throws DuplicateArtifactAttachmentException
+     * @deprecated Please use {@link MavenProjectHelper}
+     * @throws DuplicateArtifactAttachmentException not used anymore but leave it for backward
compatibility
      */
     public void addAttachedArtifact( Artifact artifact )
         throws DuplicateArtifactAttachmentException
     {
-        getAttachedArtifacts().add( artifact );
+        // if already there we remove it and add again
+        int index = attachedArtifacts.indexOf( artifact );

Review comment:
       This will incur a complexity of `O(n)`. Would it make sense to work with a set/map
to make that test?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message