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

chesnay pushed a commit to branch release-1.16
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 8318717a3eb53f47bbf3222093224618281c083e
Author: Chesnay Schepler <[email protected]>
AuthorDate: Wed Oct 5 16:15:46 2022 +0200

    [FLINK-29510][tests] Test deploy-plugin parsing
---
 .../tools/ci/licensecheck/NoticeFileChecker.java   | 36 +----------
 .../flink/tools/ci/utils/deploy/DeployParser.java  | 74 ++++++++++++++++++++++
 .../tools/ci/utils/deploy/DeployParserTest.java    | 60 ++++++++++++++++++
 3 files changed, 136 insertions(+), 34 deletions(-)

diff --git 
a/tools/ci/flink-ci-tools/src/main/java/org/apache/flink/tools/ci/licensecheck/NoticeFileChecker.java
 
b/tools/ci/flink-ci-tools/src/main/java/org/apache/flink/tools/ci/licensecheck/NoticeFileChecker.java
index 59741264dc3..bea843d3b3d 100644
--- 
a/tools/ci/flink-ci-tools/src/main/java/org/apache/flink/tools/ci/licensecheck/NoticeFileChecker.java
+++ 
b/tools/ci/flink-ci-tools/src/main/java/org/apache/flink/tools/ci/licensecheck/NoticeFileChecker.java
@@ -20,6 +20,7 @@ package org.apache.flink.tools.ci.licensecheck;
 
 import org.apache.flink.annotation.VisibleForTesting;
 import org.apache.flink.tools.ci.utils.dependency.DependencyParser;
+import org.apache.flink.tools.ci.utils.deploy.DeployParser;
 import org.apache.flink.tools.ci.utils.notice.NoticeContents;
 import org.apache.flink.tools.ci.utils.notice.NoticeParser;
 import org.apache.flink.tools.ci.utils.shared.Dependency;
@@ -42,7 +43,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -68,19 +68,6 @@ public class NoticeFileChecker {
     private static final Pattern SHADE_INCLUDE_MODULE_PATTERN =
             Pattern.compile(".*Including ([^:]+):([^:]+):jar:([^ ]+) in the 
shaded jar");
 
-    // Examples:
-    //
-    // Deployment on CI with alternative repo
-    // [INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ 
flink-parent ---
-    // [INFO] Using alternate deployment 
repository.../tmp/flink-validation-deployment
-    //
-    // Skipped deployment:
-    // [INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ 
flink-parent ---
-    // [INFO] Skipping artifact deployment
-    private static final Pattern DEPLOY_MODULE_PATTERN =
-            Pattern.compile(
-                    ".maven-deploy-plugin:.*:deploy .* @ (?<module>[^ 
_]+)(_[0-9.]+)? --.*");
-
     // Examples:
     // "- org.apache.htrace:htrace-core:3.1.0-incubating"
     // or
@@ -96,7 +83,7 @@ public class NoticeFileChecker {
                         parseModulesFromBuildResult(buildResult),
                         
DependencyParser.parseDependencyCopyOutput(buildResult.toPath()));
 
-        final Set<String> deployedModules = 
parseDeployedModulesFromBuildResult(buildResult);
+        final Set<String> deployedModules = 
DeployParser.parseDeployOutput(buildResult);
 
         LOG.info(
                 "Extracted "
@@ -372,25 +359,6 @@ public class NoticeFileChecker {
         return result;
     }
 
-    private static Set<String> parseDeployedModulesFromBuildResult(File 
buildResult)
-            throws IOException {
-        final Set<String> deployedModules = new HashSet<>();
-        try (Stream<String> linesStream = Files.lines(buildResult.toPath())) {
-            final Iterator<String> lines = linesStream.iterator();
-            while (lines.hasNext()) {
-                final String line = lines.next();
-                final Matcher matcher = DEPLOY_MODULE_PATTERN.matcher(line);
-                if (matcher.find()) {
-                    final String module = matcher.group("module");
-                    if (lines.hasNext() && !lines.next().contains("Skipping 
artifact deployment")) {
-                        deployedModules.add(module);
-                    }
-                }
-            }
-        }
-        return deployedModules;
-    }
-
     private static List<String> loadFromResources(String fileName) {
         try {
             try (BufferedReader bufferedReader =
diff --git 
a/tools/ci/flink-ci-tools/src/main/java/org/apache/flink/tools/ci/utils/deploy/DeployParser.java
 
b/tools/ci/flink-ci-tools/src/main/java/org/apache/flink/tools/ci/utils/deploy/DeployParser.java
new file mode 100644
index 00000000000..e2bf3361df7
--- /dev/null
+++ 
b/tools/ci/flink-ci-tools/src/main/java/org/apache/flink/tools/ci/utils/deploy/DeployParser.java
@@ -0,0 +1,74 @@
+/*
+ * 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.flink.tools.ci.utils.deploy;
+
+import org.apache.flink.annotation.VisibleForTesting;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Stream;
+
+/** Parsing utils for the Maven deploy plugin. */
+public class DeployParser {
+
+    // Examples:
+    //
+    // Deployment on CI with alternative repo
+    // [INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ 
flink-parent ---
+    // [INFO] Using alternate deployment 
repository.../tmp/flink-validation-deployment
+    //
+    // Skipped deployment:
+    // [INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ 
flink-parent ---
+    // [INFO] Skipping artifact deployment
+    private static final Pattern DEPLOY_MODULE_PATTERN =
+            Pattern.compile(
+                    ".maven-deploy-plugin:.*:deploy .* @ (?<module>[^ 
_]+)(?:_[0-9.]+)? --.*");
+
+    /**
+     * Parses the output of a Maven build where {@code deploy:deploy} was 
used, and returns a set of
+     * deployed modules.
+     */
+    public static Set<String> parseDeployOutput(File buildResult) throws 
IOException {
+        try (Stream<String> linesStream = Files.lines(buildResult.toPath())) {
+            return parseDeployOutput(linesStream.iterator());
+        }
+    }
+
+    @VisibleForTesting
+    static Set<String> parseDeployOutput(Iterator<String> lines) {
+        final Set<String> deployedModules = new HashSet<>();
+        while (lines.hasNext()) {
+            final String line = lines.next();
+            final Matcher matcher = DEPLOY_MODULE_PATTERN.matcher(line);
+            if (matcher.find()) {
+                final String module = matcher.group("module");
+                if (lines.hasNext() && !lines.next().contains("Skipping 
artifact deployment")) {
+                    deployedModules.add(module);
+                }
+            }
+        }
+        return deployedModules;
+    }
+}
diff --git 
a/tools/ci/flink-ci-tools/src/test/java/org/apache/flink/tools/ci/utils/deploy/DeployParserTest.java
 
b/tools/ci/flink-ci-tools/src/test/java/org/apache/flink/tools/ci/utils/deploy/DeployParserTest.java
new file mode 100644
index 00000000000..ffa2fc97c3c
--- /dev/null
+++ 
b/tools/ci/flink-ci-tools/src/test/java/org/apache/flink/tools/ci/utils/deploy/DeployParserTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.flink.tools.ci.utils.deploy;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class DeployParserTest {
+    @Test
+    void testParseDeployOutputDetectsDeployment() {
+        assertThat(
+                        DeployParser.parseDeployOutput(
+                                Arrays.asList(
+                                                "[INFO] --- 
maven-deploy-plugin:2.8.2:deploy (default-deploy) @ flink-parent ---",
+                                                "[INFO] ")
+                                        .iterator()))
+                .containsExactly("flink-parent");
+    }
+
+    @Test
+    void testParseDeployOutputDetectsDeploymentWithAltRepository() {
+        assertThat(
+                        DeployParser.parseDeployOutput(
+                                Arrays.asList(
+                                                "[INFO] --- 
maven-deploy-plugin:2.8.2:deploy (default-deploy) @ flink-parent ---",
+                                                "[INFO] Using alternate 
deployment repository.../tmp/flink-validation-deployment")
+                                        .iterator()))
+                .containsExactly("flink-parent");
+    }
+
+    @Test
+    void testParseDeployOutputDetectsSkippedDeployments() {
+        assertThat(
+                        DeployParser.parseDeployOutput(
+                                Arrays.asList(
+                                                "[INFO] --- 
maven-deploy-plugin:2.8.2:deploy (default-deploy) @ flink-parent ---",
+                                                "[INFO] Skipping artifact 
deployment")
+                                        .iterator()))
+                .isEmpty();
+    }
+}

Reply via email to