You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2021/12/07 17:32:01 UTC

[sling-org-apache-sling-feature-extension-apiregions] branch master updated: SLING-10977 : Exclude JDK packages from version range checks

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

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-extension-apiregions.git


The following commit(s) were added to refs/heads/master by this push:
     new 507b375  SLING-10977 : Exclude JDK packages from version range checks
507b375 is described below

commit 507b375b141f8d57d97259432d0b09613b092ae9
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Dec 7 18:28:35 2021 +0100

    SLING-10977 : Exclude JDK packages from version range checks
---
 .../CheckApiRegionsBundleExportsImports.java        | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsBundleExportsImports.java b/src/main/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsBundleExportsImports.java
index 39d64bb..5ce1635 100644
--- a/src/main/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsBundleExportsImports.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsBundleExportsImports.java
@@ -21,6 +21,7 @@ package org.apache.sling.feature.extension.apiregions.analyser;
 import java.io.IOException;
 import java.util.AbstractMap;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -52,6 +53,9 @@ public class CheckApiRegionsBundleExportsImports implements AnalyserTask {
     private static final String NO_REGION = " __NO_REGION__ ";
     private static final String OWN_FEATURE = " __OWN_FEATURE__ ";
 
+    /** Ignore JDK packages */
+    private static final List<String> IGNORED_IMPORT_PREFIXES = Arrays.asList("java.", "javax.", "org.w3c.", "org.xml.");
+
     @Override
     public String getName() {
         return "Bundle Import/Export Check";
@@ -100,16 +104,21 @@ public class CheckApiRegionsBundleExportsImports implements AnalyserTask {
         }
     }
 
+    private boolean ignoreImportPackage(final String name) {
+        for(final String prefix : IGNORED_IMPORT_PREFIXES) {
+            if ( name.startsWith(prefix) ) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
     private void checkForVersionOnImportingPackages(final AnalyserTaskContext ctx, final Map<BundleDescriptor, Report> reports) {
         for(final BundleDescriptor info : ctx.getFeatureDescriptor().getBundleDescriptors()) {
             if ( info.getImportedPackages() != null ) {
                 for(final PackageInfo i : info.getImportedPackages()) {
-                    if ( i.getVersion() == null ) {
-                        // don't report for javax, org.xml. and org.w3c. packages (TODO)
-                        if ( !i.getName().startsWith("javax.")
-                                && !i.getName().startsWith("org.w3c.") && !i.getName().startsWith("org.xml.")) {
-                            getReport(reports, info).importWithoutVersion.add(i);
-                        }
+                    if ( i.getVersion() == null && !ignoreImportPackage(i.getName()) ) {
+                        getReport(reports, info).importWithoutVersion.add(i);
                     }
                 }
             }