From 24f25a0a712b1f8e0d702da74245483d6daf77e0 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 21 Jun 2023 14:36:58 +0200 Subject: [PATCH] [MNG-7819] Add IT that excercise the bug (#271) Template/reproducer: https://gist.github.com/cstamas/3f15775bd4785a5f4b157399f52af6fc While local repo is empty. --- https://issues.apache.org/jira/browse/MNG-7819 --- ...ITmng7819FileLockingWithSnapshotsTest.java | 105 ++++++++++++++++++ .../apache/maven/it/TestSuiteOrdering.java | 1 + .../pom.xml | 16 +++ .../dependency-1.0.0-20221014.203717-12.jar | 1 + .../dependency-1.0.0-20221014.203717-12.pom | 13 +++ .../1.0.0-SNAPSHOT/maven-metadata.xml | 26 +++++ .../parent/1.0.0-SNAPSHOT/maven-metadata.xml | 21 ++++ .../parent-1.0.0-20221014.203717-12.pom | 8 ++ .../settings-template.xml | 60 ++++++++++ 9 files changed, 251 insertions(+) create mode 100644 its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7819FileLockingWithSnapshotsTest.java create mode 100644 its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/pom.xml create mode 100644 its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/dependency/1.0.0-SNAPSHOT/dependency-1.0.0-20221014.203717-12.jar create mode 100644 its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/dependency/1.0.0-SNAPSHOT/dependency-1.0.0-20221014.203717-12.pom create mode 100644 its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/dependency/1.0.0-SNAPSHOT/maven-metadata.xml create mode 100644 its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/parent/1.0.0-SNAPSHOT/maven-metadata.xml create mode 100644 its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/parent/1.0.0-SNAPSHOT/parent-1.0.0-20221014.203717-12.pom create mode 100644 its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/settings-template.xml diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7819FileLockingWithSnapshotsTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7819FileLockingWithSnapshotsTest.java new file mode 100644 index 0000000000..e55201e317 --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7819FileLockingWithSnapshotsTest.java @@ -0,0 +1,105 @@ +/* + * 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. + */ +package org.apache.maven.it; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.FileUtils; +import org.apache.maven.shared.verifier.Verifier; +import org.apache.maven.shared.verifier.util.ResourceExtractor; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.NetworkConnector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.HandlerList; +import org.eclipse.jetty.server.handler.ResourceHandler; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class MavenITmng7819FileLockingWithSnapshotsTest extends AbstractMavenIntegrationTestCase { + + private Server server; + + private int port; + + protected MavenITmng7819FileLockingWithSnapshotsTest() { + // broken: maven 3.9.2 and 4.0.0-alpha-5 + super("[3.9.0,3.9.2),(3.9.2,3.999.999],[4.0.0-alpha-6,)"); + } + + @BeforeEach + protected void setUp() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7819-file-locking-with-snapshots"); + server = new Server(0); + ResourceHandler resourceHandler = new ResourceHandler(); + resourceHandler.setWelcomeFiles(new String[] {"index.html"}); + resourceHandler.setDirectoriesListed(true); + resourceHandler.setResourceBase(new File(testDir, "repo").getAbsolutePath()); + HandlerList handlerList = new HandlerList(); + handlerList.setHandlers(new Handler[] {resourceHandler}); + 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); + } + + @AfterEach + protected void tearDown() throws Exception { + if (server != null) { + server.stop(); + server.join(); + } + } + + @Test + void testFileLockingAndSnapshots() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7819-file-locking-with-snapshots"); + + Verifier verifier = newVerifier(testDir.getAbsolutePath()); + verifier.setForkJvm(true); + + // produce required precondition state: local repository must not have any of the org.apache.maven.its.mng7819 + // artifacts + String path = verifier.getArtifactPath("org.apache.maven.its.mng7819", "dependency", "1.0.0-SNAPSHOT", "pom"); + File groupDirectory = new File(path).getParentFile().getParentFile().getParentFile(); + FileUtils.deleteDirectory(groupDirectory); + + Map properties = new HashMap<>(); + properties.put("@port@", Integer.toString(port)); + verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8", properties); + + verifier.addCliArgument("-e"); + verifier.addCliArgument("-s"); + verifier.addCliArgument(new File(testDir, "settings.xml").getAbsolutePath()); + verifier.addCliArgument("-Pmaven-core-it-repo"); + + verifier.addCliArgument("-Daether.syncContext.named.nameMapper=file-gav"); + verifier.addCliArgument("-Daether.syncContext.named.factory=file-lock"); + verifier.addCliArgument("package"); + + verifier.execute(); + + verifier.verifyErrorFreeLog(); + } +} diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java index c8ed837600..443492d4c0 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java @@ -120,6 +120,7 @@ public class TestSuiteOrdering implements ClassOrderer { * the tests are to finishing. Newer tests are also more likely to fail, so this is * a fail fast technique as well. */ + suite.addTestSuite(MavenITmng7819FileLockingWithSnapshotsTest.class); suite.addTestSuite(MavenITmng5600DependencyManagementImportExclusionsTest.class); suite.addTestSuite(MavenITmng7740ConsumerBuildShouldCleanUpOldFilesTest.class); suite.addTestSuite(MavenITmng7587Jsr330.class); diff --git a/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/pom.xml b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/pom.xml new file mode 100644 index 0000000000..94921b5391 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + + org.apache.maven.its.mng7819 + test + 1.0.0-SNAPSHOT + + + + org.apache.maven.its.mng7819 + dependency + 1.0.0-SNAPSHOT + + + diff --git a/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/dependency/1.0.0-SNAPSHOT/dependency-1.0.0-20221014.203717-12.jar b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/dependency/1.0.0-SNAPSHOT/dependency-1.0.0-20221014.203717-12.jar new file mode 100644 index 0000000000..01ce9e1e14 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/dependency/1.0.0-SNAPSHOT/dependency-1.0.0-20221014.203717-12.jar @@ -0,0 +1 @@ +FAKEJAR \ No newline at end of file diff --git a/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/dependency/1.0.0-SNAPSHOT/dependency-1.0.0-20221014.203717-12.pom b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/dependency/1.0.0-SNAPSHOT/dependency-1.0.0-20221014.203717-12.pom new file mode 100644 index 0000000000..cbec4fac43 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/dependency/1.0.0-SNAPSHOT/dependency-1.0.0-20221014.203717-12.pom @@ -0,0 +1,13 @@ + + + 4.0.0 + + + org.apache.maven.its.mng7819 + parent + 1.0.0-SNAPSHOT + + + dependency + 1.0.0-SNAPSHOT + diff --git a/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/dependency/1.0.0-SNAPSHOT/maven-metadata.xml b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/dependency/1.0.0-SNAPSHOT/maven-metadata.xml new file mode 100644 index 0000000000..907bb69f02 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/dependency/1.0.0-SNAPSHOT/maven-metadata.xml @@ -0,0 +1,26 @@ + + + + org.apache.maven.its.mng7819 + dependency + 1.0.0-SNAPSHOT + + + 20221014.203717 + 12 + + 20221014203717 + + + jar + 1.0.0-20221014.203717-12 + 20221014203717 + + + pom + 1.0.0-20221014.203717-12 + 20221014203717 + + + + diff --git a/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/parent/1.0.0-SNAPSHOT/maven-metadata.xml b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/parent/1.0.0-SNAPSHOT/maven-metadata.xml new file mode 100644 index 0000000000..19be14d49b --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/parent/1.0.0-SNAPSHOT/maven-metadata.xml @@ -0,0 +1,21 @@ + + + + org.apache.maven.its.mng7819 + parent + 1.0.0-SNAPSHOT + + + 20221014.203717 + 12 + + 20221014203717 + + + pom + 1.0.0-20221014.203717-12 + 20221014203717 + + + + diff --git a/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/parent/1.0.0-SNAPSHOT/parent-1.0.0-20221014.203717-12.pom b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/parent/1.0.0-SNAPSHOT/parent-1.0.0-20221014.203717-12.pom new file mode 100644 index 0000000000..25fa0db34c --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/repo/org/apache/maven/its/mng7819/parent/1.0.0-SNAPSHOT/parent-1.0.0-20221014.203717-12.pom @@ -0,0 +1,8 @@ + + + 4.0.0 + + org.apache.maven.its.mng7819 + dependency + 1.0.0-SNAPSHOT + diff --git a/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/settings-template.xml b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/settings-template.xml new file mode 100644 index 0000000000..b3230ae675 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-7819-file-locking-with-snapshots/settings-template.xml @@ -0,0 +1,60 @@ + + + + + + + + maven-core-it-repo + + + maven-core-it + http://localhost:@port@ + + true + ignore + never + + + true + ignore + never + + + + + + maven-core-it + http://localhost:@port@ + + true + ignore + never + + + true + ignore + never + + + + + +