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-analyser.git


The following commit(s) were added to refs/heads/master by this push:
     new 42ce6f9  SLING-9815 : Add analyser to check for unused bundles
42ce6f9 is described below

commit 42ce6f91bcfc077b1abffa05ef0c7d80d0f6fb61
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Tue Oct 13 08:58:38 2020 +0200

    SLING-9815 : Add analyser to check for unused bundles
---
 .../feature/analyser/task/impl/CheckUnusedBundles.java     | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckUnusedBundles.java
 
b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckUnusedBundles.java
index 8dd1937..8b4c767 100644
--- 
a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckUnusedBundles.java
+++ 
b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckUnusedBundles.java
@@ -49,6 +49,8 @@ public class CheckUnusedBundles implements AnalyserTask {
 
                 final Set<PackageInfo> exports = new 
HashSet<>(info.getExportedPackages());
                 
+                final Set<String> optionalImports = new HashSet<>();
+
                 // find importing bundle
                 for(final BundleDescriptor inner : 
ctx.getFeatureDescriptor().getBundleDescriptors()) {
                     if ( inner == info ) {
@@ -64,7 +66,11 @@ public class CheckUnusedBundles implements AnalyserTask {
                             
                             if ( expPck.getName().equals(impPck.getName())) {
                                 if ( impPck.getVersion() == null || 
impPck.getPackageVersionRange().includes(expPck.getPackageVersion()) ) {
-                                    found = true;
+                                    if ( impPck.isOptional() ) {
+                                        optionalImports.add(impPck.getName());
+                                    } else {
+                                        found = true;
+                                    }
                                     break;
                                 }
                             }
@@ -82,7 +88,11 @@ public class CheckUnusedBundles implements AnalyserTask {
                 }
 
                 if ( exports.size() == info.getExportedPackages().size() ) {
-                    ctx.reportWarning("Exports from bundle 
".concat(info.getArtifact().getId().toMvnId()).concat(" are not imported by any 
other bundle."));
+                    if ( !optionalImports.isEmpty() ) {
+                        ctx.reportWarning("Exports from bundle 
".concat(info.getArtifact().getId().toMvnId()).concat(" are only imported 
optionally by other bundles."));
+                    } else {
+                        ctx.reportWarning("Exports from bundle 
".concat(info.getArtifact().getId().toMvnId()).concat(" are not imported by any 
other bundle."));
+                    }
                 }
 
             }

Reply via email to