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 d269e22b30c0758e905ebc3262c4463949df54e6
Author: Chesnay Schepler <[email protected]>
AuthorDate: Wed Oct 5 13:57:52 2022 +0200

    [FLINK-29508][legal] Improve detection of non-deployed modules that need a 
NOTICE
---
 .../tools/ci/licensecheck/NoticeFileChecker.java   | 31 ++++++++++++++++++--
 .../ci/licensecheck/NoticeFileCheckerTest.java     | 33 ++++++++++++++++++++++
 2 files changed, 62 insertions(+), 2 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 4747899c513..8a9461a5d5d 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
@@ -126,7 +126,34 @@ public class NoticeFileChecker {
         final Set<String> modulesSkippingDeployment =
                 new HashSet<>(modulesWithBundledDependencies.keySet());
         modulesSkippingDeployment.removeAll(deployedModules);
-        
modulesSkippingDeployment.forEach(modulesWithBundledDependencies::removeAll);
+
+        LOG.debug(
+                "The following {} modules are skipping deployment: {}",
+                modulesSkippingDeployment.size(),
+                modulesSkippingDeployment.stream()
+                        .sorted()
+                        .collect(Collectors.joining("\n\t", "\n\t", "")));
+
+        for (String moduleSkippingDeployment : modulesSkippingDeployment) {
+            // TODO: this doesn't work for modules requiring a NOTICE that are 
bundled indirectly
+            // TODO: via another non-deployed module
+            boolean bundledByDeployedModule =
+                    modulesWithBundledDependencies.entries().stream()
+                            .filter(
+                                    entry ->
+                                            entry.getValue()
+                                                    .getArtifactId()
+                                                    
.equals(moduleSkippingDeployment))
+                            .anyMatch(entry -> 
!modulesSkippingDeployment.contains(entry.getKey()));
+
+            if (!bundledByDeployedModule) {
+                
modulesWithBundledDependencies.removeAll(moduleSkippingDeployment);
+            } else {
+                LOG.debug(
+                        "Including module {} in license checks, despite not 
being deployed, because it is bundled by another deployed module.",
+                        moduleSkippingDeployment);
+            }
+        }
 
         // check that all required NOTICE files exists
         severeIssueCount +=
@@ -265,7 +292,7 @@ public class NoticeFileChecker {
                                     dependency ->
                                             
!dependency.getGroupId().equals("org.apache.flink"))
                             .collect(Collectors.toList());
-            ;
+
             for (Dependency expectedDependency : expectedDependencies) {
                 if (!declaredDependencies.contains(expectedDependency)) {
                     addProblem(
diff --git 
a/tools/ci/flink-ci-tools/src/test/java/org/apache/flink/tools/ci/licensecheck/NoticeFileCheckerTest.java
 
b/tools/ci/flink-ci-tools/src/test/java/org/apache/flink/tools/ci/licensecheck/NoticeFileCheckerTest.java
index cbf09b46f0d..381db7e1275 100644
--- 
a/tools/ci/flink-ci-tools/src/test/java/org/apache/flink/tools/ci/licensecheck/NoticeFileCheckerTest.java
+++ 
b/tools/ci/flink-ci-tools/src/test/java/org/apache/flink/tools/ci/licensecheck/NoticeFileCheckerTest.java
@@ -22,11 +22,14 @@ import 
org.apache.flink.tools.ci.utils.notice.NoticeContents;
 import org.apache.flink.tools.ci.utils.shared.Dependency;
 
 import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
 import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 
@@ -107,6 +110,36 @@ class NoticeFileCheckerTest {
                 .isEqualTo(0);
     }
 
+    @Test
+    void testRunIncludesBundledNonDeployedModules() throws IOException {
+        final Multimap<String, Dependency> bundledDependencies = 
ArrayListMultimap.create();
+        final Map<String, Optional<NoticeContents>> notices = new HashMap<>();
+
+        // a module that is not deployed but bundles another dependency with 
an empty NOTICE
+        final String nonDeployedModuleName = "nonDeployed";
+        final Dependency nonDeployedDependency = Dependency.create("a", 
nonDeployedModuleName, "c");
+        final Dependency bundledDependency = Dependency.create("a", "b", "c");
+        bundledDependencies.put(nonDeployedModuleName, bundledDependency);
+        // this would usually not be a problem, but since the module is not 
bundled it's not OK!
+        final Optional<NoticeContents> emptyNotice =
+                Optional.of(new NoticeContents(nonDeployedModuleName, 
Collections.emptyList()));
+        notices.put(nonDeployedModuleName, emptyNotice);
+
+        // a module that is deploys and bundles the above
+        final String bundlingModule = "bundling";
+        bundledDependencies.put(bundlingModule, nonDeployedDependency);
+        final Optional<NoticeContents> correctNotice =
+                Optional.of(
+                        new NoticeContents(
+                                bundlingModule, 
Collections.singletonList(nonDeployedDependency)));
+        notices.put(bundlingModule, correctNotice);
+
+        final Set<String> deployedModules = 
Collections.singleton(bundlingModule);
+
+        assertThat(NoticeFileChecker.run(bundledDependencies, deployedModules, 
notices))
+                .isEqualTo(1);
+    }
+
     @Test
     void testCheckNoticeFileHappyPath() {
         final String moduleName = "test";

Reply via email to