You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2020/06/03 20:30:04 UTC

[maven-integration-testing] branch MNG-5868-no_duplicate_artifacts_in_attached_artifacts created (now 3e2a2c8)

This is an automated email from the ASF dual-hosted git repository.

olamy pushed a change to branch MNG-5868-no_duplicate_artifacts_in_attached_artifacts
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git.


      at 3e2a2c8  [MNG-5868] Adding serval times the same artifact via MavenProjectHelper (attachArtifact) keep adding to the List duplicate artifacts

This branch includes the following new commits:

     new 3e2a2c8  [MNG-5868] Adding serval times the same artifact via MavenProjectHelper (attachArtifact) keep adding to the List duplicate artifacts

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-integration-testing] 01/01: [MNG-5868] Adding serval times the same artifact via MavenProjectHelper (attachArtifact) keep adding to the List duplicate artifacts

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch MNG-5868-no_duplicate_artifacts_in_attached_artifacts
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git

commit 3e2a2c8748d96ad8e52338c48e09f566fcca851b
Author: olivier lamy <ol...@apache.org>
AuthorDate: Thu Jun 4 06:29:33 2020 +1000

    [MNG-5868] Adding serval times the same artifact via MavenProjectHelper (attachArtifact) keep adding to the List duplicate artifacts
    
    Signed-off-by: olivier lamy <ol...@apache.org>
---
 .../org/apache/maven/it/IntegrationTestSuite.java  |   2 +-
 .../it/MavenITmng5338FileOptionToDirectory.java    |   1 -
 ...MavenITmng5868NoDuplicateAttachedArtifacts.java | 139 +++++++++++++++++++++
 core-it-suite/src/test/resources/mng-5868/pom.xml  | 105 ++++++++++++++++
 .../java/org/apache/maven/its/mng5338/App.java     |  32 +++++
 .../maven/plugin/coreit/AbstractRepoMojo.java      |   2 +-
 .../org/apache/maven/plugin/coreit/DeployMojo.java |   3 +-
 .../apache/maven/plugin/coreit/InstallMojo.java    |   3 +-
 8 files changed, 280 insertions(+), 7 deletions(-)

diff --git a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
index 01fdb89..45f1d38 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
@@ -106,7 +106,7 @@ public class IntegrationTestSuite
         // Tests that don't run stable and need to be fixed
         // -------------------------------------------------------------------------------------------------------------
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
-
+        suite.addTestSuite( MavenITmng5868NoDuplicateAttachedArtifacts.class );
         suite.addTestSuite( MavenITmng5937MavenWrapper.class );
         suite.addTestSuite( MavenITmng4660ResumeFromTest.class );
         suite.addTestSuite( MavenITmng4660OutdatedPackagedArtifact.class );
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5338FileOptionToDirectory.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5338FileOptionToDirectory.java
index 9051a42..c5da6f9 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5338FileOptionToDirectory.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5338FileOptionToDirectory.java
@@ -51,7 +51,6 @@ public class MavenITmng5338FileOptionToDirectory
     protected void tearDown()
         throws Exception
     {
-
         super.tearDown();
     }
 
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5868NoDuplicateAttachedArtifacts.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5868NoDuplicateAttachedArtifacts.java
new file mode 100644
index 0000000..9e828cf
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5868NoDuplicateAttachedArtifacts.java
@@ -0,0 +1,139 @@
+package org.apache.maven.it;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.it.util.ResourceExtractor;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.NetworkConnector;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.server.handler.HandlerList;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+
+/**
+ * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-5868">MNG-5868</a>.
+ *
+ * @author Olivier Lamy
+ */
+public class MavenITmng5868NoDuplicateAttachedArtifacts
+    extends AbstractMavenIntegrationTestCase
+{
+
+    private File testDir;
+
+    private Server server;
+
+    private int port;
+
+    private boolean deployed;
+
+    private int deployedJarArtifactNumber = 0;
+
+    public MavenITmng5868NoDuplicateAttachedArtifacts()
+    {
+        super( "[3.7.0,)" );
+    }
+
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+        testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5868" );
+
+        Handler repoHandler = new AbstractHandler()
+        {
+            @Override
+            public void handle( String target, Request baseRequest, HttpServletRequest request,
+                                HttpServletResponse response )
+            {
+                System.out.println( "Handling " + request.getMethod() + " " + request.getRequestURL() );
+
+                if ( "PUT".equalsIgnoreCase( request.getMethod() ) )
+                {
+                    deployed = true;
+                    String uri = request.getRequestURI();
+                    if (uri.startsWith( "/repo/org/apache/maven/its/mng5868/mng5868/1.0-SNAPSHOT/mng5868-1.0" ) && uri.endsWith( "-run.jar" ))
+                    {
+                        deployedJarArtifactNumber++;
+                    }
+                    response.setStatus( HttpServletResponse.SC_OK );
+                }
+                else
+                {
+                    response.setStatus( HttpServletResponse.SC_NOT_FOUND );
+                }
+
+                ( (Request) request ).setHandled( true );
+            }
+        };
+
+        server = new Server( 0 );
+
+        HandlerList handlerList = new HandlerList();
+        handlerList.addHandler( repoHandler );
+
+        server.setHandler( handlerList );
+        server.start();
+        if ( server.isFailed() )
+        {
+            fail( "Couldn't bind the server socket to a free port!" );
+        }
+        port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
+        System.out.println( "Bound server socket to the port " + port );
+    }
+
+    @Override
+    protected void tearDown()
+        throws Exception
+    {
+        if ( server != null )
+        {
+            server.stop();
+            server.join();
+        }
+    }
+
+    public void testNoDeployNotDuplicate()
+        throws Exception
+    {
+        Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+        Path tmp = Files.createTempFile( testDir.toPath(), "FOO", "txt");
+
+        verifier.setAutoclean( false );
+        verifier.deleteDirectory( "target" );
+        verifier.deleteArtifacts( "org.apache.maven.its.mng5868" );
+        verifier.addCliOption( "-Dartifact.attachedFile=" + tmp.toFile().getCanonicalPath() );
+        verifier.addCliOption( "-DdeploymentPort=" + port );
+        verifier.displayStreamBuffers();
+        verifier.executeGoals( Arrays.asList("org.apache.maven.its.plugins:maven-it-plugin-artifact:2.1-SNAPSHOT:attach", "deploy" ) );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+        assertTrue( deployed );
+        assertEquals("deployedJarArtifactNumber: " + deployedJarArtifactNumber, 1, deployedJarArtifactNumber );
+    }
+
+}
diff --git a/core-it-suite/src/test/resources/mng-5868/pom.xml b/core-it-suite/src/test/resources/mng-5868/pom.xml
new file mode 100644
index 0000000..13bb490
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5868/pom.xml
@@ -0,0 +1,105 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.mng5868</groupId>
+  <artifactId>mng5868</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>mng5338</name>
+  <url>https://issues.apache.org/jira/browse/MNG-5868</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <distributionManagement>
+    <repository>
+      <id>maven-core-it-mng-5868</id>
+      <url>http://localhost:${deploymentPort}/repo</url>
+    </repository>
+  </distributionManagement>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.its.plugins</groupId>
+          <artifactId>maven-it-plugin-artifact</artifactId>
+          <version>2.1-SNAPSHOT</version>
+          <configuration>
+            <artifactType>jar</artifactType>
+            <artifactClassifier>run</artifactClassifier>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.its.plugins</groupId>
+        <artifactId>maven-it-plugin-artifact</artifactId>
+        <executions>
+          <execution>
+            <id>attach-artifacts</id>
+            <phase>verify</phase>
+            <goals>
+              <goal>attach</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <profiles>
+    <profile>
+      <id>again</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.its.plugins</groupId>
+            <artifactId>maven-it-plugin-artifact</artifactId>
+            <executions>
+              <execution>
+                <id>again-attach</id>
+                <phase>process-classes</phase>
+                <goals>
+                  <goal>attach</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    <profile>
+      <id>and-again</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.its.plugins</groupId>
+            <artifactId>maven-it-plugin-artifact</artifactId>
+            <executions>
+              <execution>
+                <id>and-again-attach</id>
+                <phase>process-sources</phase>
+                <goals>
+                  <goal>attach</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.2</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-5868/src/main/java/org/apache/maven/its/mng5338/App.java b/core-it-suite/src/test/resources/mng-5868/src/main/java/org/apache/maven/its/mng5338/App.java
new file mode 100644
index 0000000..fd3f646
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5868/src/main/java/org/apache/maven/its/mng5338/App.java
@@ -0,0 +1,32 @@
+package org.apache.maven.its.mng5338;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Hello world!
+ *
+ */
+public class App 
+{
+    public static void main( String[] args )
+    {
+        System.out.println( "Hello World!" );
+    }
+}
diff --git a/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/AbstractRepoMojo.java b/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/AbstractRepoMojo.java
index 0cfc74e..79ebb88 100644
--- a/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/AbstractRepoMojo.java
+++ b/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/AbstractRepoMojo.java
@@ -52,7 +52,7 @@ public abstract class AbstractRepoMojo
      * @readonly
      * @required
      */
-    protected Collection attachedArtifacts;
+    protected Collection<Artifact> attachedArtifacts;
 
     /**
      * The packaging of the project.
diff --git a/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/DeployMojo.java b/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/DeployMojo.java
index 2b67299..44b24a4 100644
--- a/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/DeployMojo.java
+++ b/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/DeployMojo.java
@@ -75,9 +75,8 @@ public class DeployMojo
 
             if ( attachedArtifacts != null )
             {
-                for ( Object attachedArtifact1 : attachedArtifacts )
+                for ( Artifact attachedArtifact : attachedArtifacts )
                 {
-                    Artifact attachedArtifact = (Artifact) attachedArtifact1;
                     deployer.deploy( attachedArtifact.getFile(), attachedArtifact, deploymentRepository,
                                      localRepository );
                 }
diff --git a/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/InstallMojo.java b/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/InstallMojo.java
index be07137..150d2c3 100644
--- a/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/InstallMojo.java
+++ b/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/InstallMojo.java
@@ -65,9 +65,8 @@ public class InstallMojo
 
             if ( attachedArtifacts != null )
             {
-                for ( Object attachedArtifact1 : attachedArtifacts )
+                for ( Artifact attachedArtifact : attachedArtifacts )
                 {
-                    Artifact attachedArtifact = (Artifact) attachedArtifact1;
                     installer.install( attachedArtifact.getFile(), attachedArtifact, localRepository );
                 }
             }