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

Signed-off-by: olivier lamy <olamy@apache.org>
This commit is contained in:
olivier lamy 2020-06-04 06:29:33 +10:00
parent 9d793585ae
commit bb1b892144
8 changed files with 276 additions and 7 deletions

View File

@ -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 );

View File

@ -51,7 +51,6 @@ public class MavenITmng5338FileOptionToDirectory
protected void tearDown()
throws Exception
{
super.tearDown();
}

View File

@ -0,0 +1,135 @@
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 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() ) )
{
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();
assertEquals("deployedJarArtifactNumber: " + deployedJarArtifactNumber, 1, deployedJarArtifactNumber );
}
}

View File

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

View File

@ -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!" );
}
}

View File

@ -52,7 +52,7 @@ public abstract class AbstractRepoMojo
* @readonly
* @required
*/
protected Collection attachedArtifacts;
protected Collection<Artifact> attachedArtifacts;
/**
* The packaging of the project.

View File

@ -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 );
}

View File

@ -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 );
}
}