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

luigidemasi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kit.git

commit 13c2b9bbf982a071eac11a1c3c1e82004e29dee7
Author: Luigi De Masi <[email protected]>
AuthorDate: Tue Dec 1 13:24:47 2026 +0100

    Reject unused binary license records
    
    Fail packaging when a reviewed license row no longer matches a runtime
    JAR. Account for native variants declared in inactive Maven OS profiles
    and check their pinned versions and supplemental license headings.
    
    Co-authored-by: OpenAI Codex <[email protected]>
---
 docs/modules/ROOT/pages/contributing.adoc |  4 +++
 tools/BundleLicenses.java                 | 44 ++++++++++++++++++++++++++-----
 tools/pom-licenses.ftl                    | 14 ++++++++++
 tools/test_bundle_licenses.py             | 23 ++++++++++++++++
 4 files changed, 78 insertions(+), 7 deletions(-)

diff --git a/docs/modules/ROOT/pages/contributing.adoc 
b/docs/modules/ROOT/pages/contributing.adoc
index 5b7cc30a..a2f57f90 100644
--- a/docs/modules/ROOT/pages/contributing.adoc
+++ b/docs/modules/ROOT/pages/contributing.adoc
@@ -74,6 +74,10 @@ list `Apache-2.0` plus any reviewed alternative licenses. 
Maven reads the
 effective POM, including inherited licenses. A version bump passes when the 
resolved
 version declares the same licenses. Missing declarations or a changed license 
set
 stop packaging. A new dependency without a license file still needs its own 
row.
+Remove its row when you remove the dependency. Packaging rejects unused rows.
+It recognizes dependencies declared by inactive Maven OS profiles, so a Linux 
build
+can retain the records for the Windows and macOS variants. Pinned versions and
+supplementary LICENSE sections are checked for those variants too.
 
 For dependencies with supplementary terms, pin the reviewed artifact version,
 reproduce the terms in `src/main/legal/LICENSE` and name the section in the 
table.
diff --git a/tools/BundleLicenses.java b/tools/BundleLicenses.java
index 22d2ee56..6a403c68 100644
--- a/tools/BundleLicenses.java
+++ b/tools/BundleLicenses.java
@@ -13,6 +13,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.TreeSet;
 import java.util.jar.JarFile;
 import java.util.regex.Pattern;
 
@@ -28,23 +29,42 @@ class BundleLicenses {
     private static final Pattern APACHE_URL = 
Pattern.compile("https?://(?:www\\.apache\\.org/licenses/LICENSE-2\\.0(?:\\.txt)?"
             + "|repository\\.jboss\\.org/licenses/apache-2\\.0\\.txt)");
 
-    private static Map<String, Set<String>> declaredLicenses(Path report) 
throws IOException {
-        Map<String, Set<String>> declarations = new HashMap<>();
+    private static void readPomReport(Path report, Map<String, Set<String>> 
declarations,
+            Map<String, Set<String>> inactiveOsDependencies) throws 
IOException {
         for (String line : Files.readAllLines(report)) {
             String[] fields = line.split("\\t", -1);
-            if (fields.length != 3) {
+            if (fields.length != 3
+                    || (fields[0].equals("@inactive-os") && 
(fields[1].isBlank() || fields[2].isBlank()))) {
                 throw new IllegalArgumentException("Invalid Maven license 
declaration in " + report + ": " + line);
             }
+            if (fields[0].equals("@inactive-os")) {
+                inactiveOsDependencies.computeIfAbsent(fields[1], ignored -> 
new HashSet<>()).add(fields[2]);
+                continue;
+            }
             String name = fields[1];
             String url = fields[2];
             String license = APACHE_NAME.matcher(name).matches() && 
APACHE_URL.matcher(url).matches()
                     ? "Apache-2.0" : name + " <" + url + ">";
             declarations.computeIfAbsent(fields[0], ignored -> new 
HashSet<>()).add(license);
         }
-        return declarations;
     }
 
     private record ReviewedLicense(String version, String section) {
+        String heading() {
+            return section.replace("{version}", version);
+        }
+
+        Set<String> expectedPomLicenses() {
+            return Set.of(section.split(" \\| "));
+        }
+
+        boolean coversInactiveOsDependency(Set<String> versions, String 
supplement) {
+            if (version.equals("*")) {
+                return !versions.isEmpty() && 
expectedPomLicenses().contains("Apache-2.0");
+            }
+            return versions.equals(Set.of(version)) && 
supplement.contains(heading());
+        }
+
         String verify(String id, String[] coordinate, Path jar, String 
supplement, Path legal,
                 Map<String, Set<String>> declarations) {
             String classifier = coordinate.length == 4 ? "-" + coordinate[3] : 
"";
@@ -57,7 +77,7 @@ class BundleLicenses {
                 }
                 String resolved = filename.substring(prefix.length(), 
filename.length() - suffix.length());
                 String gav = coordinate[0] + ":" + coordinate[1] + ":" + 
resolved;
-                Set<String> expected = Set.of(section.split(" \\| "));
+                Set<String> expected = expectedPomLicenses();
                 Set<String> actual = declarations.getOrDefault(gav, Set.of());
                 if (!expected.contains("Apache-2.0") || 
!actual.equals(expected)) {
                     throw new IllegalArgumentException("Review " + legal + " 
for " + gav + ": expected POM licenses "
@@ -66,7 +86,7 @@ class BundleLicenses {
                 return "Apache-2.0";
             }
             String filename = coordinate[1] + "-" + version + classifier + 
".jar";
-            String heading = section.replace("{version}", version);
+            String heading = heading();
             if (!jar.getFileName().toString().equals(filename)
                     || !supplement.contains(heading)) {
                 throw new IllegalArgumentException("Review " + legal + " for " 
+ id + " (" + jar.getFileName()
@@ -101,7 +121,10 @@ class BundleLicenses {
         Path legal = module.resolve("src/main/legal");
         String supplement = Files.readString(legal.resolve("LICENSE"));
         Map<String, ReviewedLicense> reviewed = readReviewedLicenses(legal);
-        Map<String, Set<String>> declarations = 
declaredLicenses(Path.of(args[7]));
+        Map<String, Set<String>> declarations = new HashMap<>();
+        Map<String, Set<String>> inactiveOsDependencies = new HashMap<>();
+        readPomReport(Path.of(args[7]), declarations, inactiveOsDependencies);
+        Set<String> unused = new TreeSet<>(reviewed.keySet());
         Properties artifacts = new Properties();
         try (var in = Files.newInputStream(Path.of(args[6]))) {
             artifacts.load(in);
@@ -127,6 +150,7 @@ class BundleLicenses {
             inventory.append("\n").append(path.getFileName()).append("\n");
             ReviewedLicense record = reviewed.get(id);
             if (record != null) {
+                unused.remove(id);
                 String section = record.verify(id, parts, path, supplement, 
legal, declarations);
                 inventory.append("  Reviewed license: 
").append(section).append("\n");
             }
@@ -170,6 +194,12 @@ class BundleLicenses {
                         + ") has no primary license. Review its terms and 
record them in " + legal);
             }
         }
+        unused.removeIf(id -> reviewed.get(id).coversInactiveOsDependency(
+                inactiveOsDependencies.getOrDefault(id, Set.of()), 
supplement));
+        if (!unused.isEmpty()) {
+            throw new IllegalArgumentException("Unused or stale license 
records in "
+                    + legal.resolve("dependencies.tsv") + ": " + unused);
+        }
         StringBuilder attribution = new 
StringBuilder(projectNotice).append("\n");
         if (Files.exists(extraNotice)) {
             
attribution.append("\n").append(Files.readString(extraNotice).strip()).append("\n");
diff --git a/tools/pom-licenses.ftl b/tools/pom-licenses.ftl
index 5795544f..53ea531a 100644
--- a/tools/pom-licenses.ftl
+++ b/tools/pom-licenses.ftl
@@ -1,6 +1,20 @@
+<#function runtimeJar dep>
+<#return dep.type == "jar" && !dep.isOptional() && ["", "compile", 
"runtime"]?seq_contains(dep.scope!"")>
+</#function>
 <#list dependencyMap as entry>
 <#assign project = entry.getKey()>
 <#list project.licenses as license>
 ${project.groupId}:${project.artifactId}:${project.version}    
${(license.name!"")?trim?replace(r"\s+", " ", "r")}     
${(license.url!"")?trim?replace(r"\s+", " ", "r")}
 </#list>
+<#assign activeProfiles = project.activeProfiles?map(p -> p.id)>
+<#assign selectedDependencies = project.dependencies?filter(runtimeJar)?map(d 
-> d.managementKey)>
+<#list project.model.profiles as profile>
+<#if (profile.activation.os)?? && !activeProfiles?seq_contains(profile.id)>
+<#list profile.dependencies?filter(runtimeJar) as dep>
+<#if (dep.version)?has_content && 
!selectedDependencies?seq_contains(dep.managementKey)>
+@inactive-os   ${dep.groupId}:${dep.artifactId}<#if 
(dep.classifier)?has_content>:${dep.classifier}</#if>      ${dep.version}
+</#if>
+</#list>
+</#if>
+</#list>
 </#list>
diff --git a/tools/test_bundle_licenses.py b/tools/test_bundle_licenses.py
index 0fd924a6..9083a62b 100644
--- a/tools/test_bundle_licenses.py
+++ b/tools/test_bundle_licenses.py
@@ -86,6 +86,29 @@ class BundleLicensesTest(unittest.TestCase):
         self.assertNotEqual(result.returncode, 0)
         self.assertIn("has no primary license", result.stderr)
 
+    def test_reports_all_records_without_a_bundled_jar(self):
+        record = "\n".join(("example:fixture\t1.0\tFixture {version}, MIT",
+                            "gone:pinned\t1.0\tMissing section", 
"gone:plain\t*\tApache-2.0"))
+        declaration = 
"gone:plain:1.0\tApache-2.0\thttps://www.apache.org/licenses/LICENSE-2.0\n";
+        result = self.assemble({}, record, declarations=declaration)
+        self.assertNotEqual(result.returncode, 0)
+        self.assertIn("Unused or stale license records", result.stderr)
+        self.assertIn("[gone:pinned, gone:plain]", result.stderr)
+
+    def 
test_inactive_os_variant_requires_matching_coordinate_version_and_terms(self):
+        record = "example:native:windows\t1.0\tFixture {version}, MIT"
+        profile = "@inactive-os\texample:native:windows\t1.0\n"
+        files = {"LICENSE": "Upstream terms"}
+        result = self.assemble(files, record, declarations=profile)
+        self.assertEqual(result.returncode, 0, result.stderr)
+        self.assertNotIn("Reviewed license:", (self.root / 
"output/LICENSE").read_text())
+        for row, report in ((record, ""), (record, profile.replace("windows", 
"linux")),
+                            (record, profile.replace("1.0", "2.0")), 
(record.replace("MIT", "BSD"), profile)):
+            with self.subTest(row=row, report=report):
+                result = self.assemble(files, row, declarations=report)
+                self.assertNotEqual(result.returncode, 0)
+                self.assertIn("[example:native:windows]", result.stderr)
+
     def test_keeps_third_party_notice_from_a_nested_bundle(self):
         project = (ROOT / "NOTICE").read_text().strip()
         result = self.assemble({"LICENSE": "Upstream terms", "NOTICE": project 
+ "\n\nA third-party notice"})

Reply via email to