[MNG-7740] Remove old temporary consumer*pom files from buildDir (#263)


Co-authored-by: Giovanni van der Schelde <Giovanni.vanderSchelde@infosupport.com>
Co-authored-by: Giovanni van der Schelde <gvdschelde@gmail.com>
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7740ConsumerBuildShouldCleanUpOldFilesTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7740ConsumerBuildShouldCleanUpOldFilesTest.java
new file mode 100644
index 0000000..b84c5c0
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7740ConsumerBuildShouldCleanUpOldFilesTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+/*
+ * 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 java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.maven.shared.verifier.Verifier;
+import org.apache.maven.shared.verifier.util.ResourceExtractor;
+import org.junit.jupiter.api.Test;
+
+class MavenITmng7740ConsumerBuildShouldCleanUpOldFilesTest extends AbstractMavenIntegrationTestCase {
+
+    protected MavenITmng7740ConsumerBuildShouldCleanUpOldFilesTest() {
+        super("[4.0.0-alpha-6,)");
+    }
+
+    @Test
+    void testConsumerBuildShouldCleanUpOldConsumerFiles() throws Exception {
+        File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7740-consumer-files");
+
+        Verifier verifier = newVerifier(testDir.getAbsolutePath());
+        verifier.addCliArgument("validate");
+
+        verifier.execute();
+
+        verifier.verifyErrorFreeLog();
+
+        try (Stream<Path> stream = Files.walk(testDir.toPath())) {
+            final List<Path> consumerFiles = stream.filter(
+                            path -> path.getFileName().toString().contains("consumer")
+                                    && path.getFileName().toString().contains("pom"))
+                    .collect(Collectors.toList());
+            assertTrue("Expected no consumer pom file.", consumerFiles.size() == 0);
+        }
+    }
+}
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
index d6fddd6..eb82334 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
@@ -120,6 +120,7 @@
          * the tests are to finishing. Newer tests are also more likely to fail, so this is
          * a fail fast technique as well.
          */
+        suite.addTestSuite(MavenITmng7740ConsumerBuildShouldCleanUpOldFilesTest.class);
         suite.addTestSuite(MavenITmng7587Jsr330.class);
         suite.addTestSuite(MavenITmng7038RootdirTest.class);
         suite.addTestSuite(MavenITmng7697PomWithEmojiTest.class);
diff --git a/core-it-suite/src/test/resources/mng-7740-consumer-files/pom.xml b/core-it-suite/src/test/resources/mng-7740-consumer-files/pom.xml
new file mode 100644
index 0000000..82a6abd
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7740-consumer-files/pom.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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.mng7740</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+</project>