From d699d3ffd2ff7f9b13f0e07fe181e0a5734d59ce Mon Sep 17 00:00:00 2001 From: dmitry Date: Mon, 26 Mar 2018 17:50:08 -0700 Subject: [PATCH] Make the budle start level property configurable. * Bundles below this start level are ignored. --- .../vivosys/osgi/deps/OsgiDepsActivator.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/vivosys/osgi/deps/OsgiDepsActivator.java b/src/main/java/com/vivosys/osgi/deps/OsgiDepsActivator.java index de93c1d..52c60c5 100644 --- a/src/main/java/com/vivosys/osgi/deps/OsgiDepsActivator.java +++ b/src/main/java/com/vivosys/osgi/deps/OsgiDepsActivator.java @@ -11,10 +11,19 @@ import java.io.FileWriter; import java.io.Writer; +/** + * Create dependency graph for all the bundles with start level specified by + * the system property "com.vivosys.min.startlevel.depends.graph". + * + * The default level is 1. + */ public class OsgiDepsActivator implements BundleActivator { private static final Logger logger = LoggerFactory.getLogger(OsgiDepsActivator.class); + public static final String MIN_START_LEVEL_PROPERTY = "com.vivosys.min.startlevel.depends.graph"; + private static final int DEFAULT_MIN_START_LEVEL = 1; + public void start(BundleContext bundleContext) throws Exception { Graph graph; try { @@ -26,7 +35,9 @@ public void start(BundleContext bundleContext) throws Exception { // to make names shorter, given prefix text can be stripped from service names builder.addStripFromServiceName("org.springframework.data.mongodb."); builder.addStripFromServiceName("org.springframework.integration."); - graph = builder.buildGraph(bundleContext, 50); + + int minStartLevel = loadMinStartLevel(); + graph = builder.buildGraph(bundleContext, minStartLevel); } catch (Exception e) { logger.error("Error building graph.", e); throw e; @@ -49,4 +60,20 @@ public void start(BundleContext bundleContext) throws Exception { public void stop(BundleContext bundleContext) throws Exception { } + private static int loadMinStartLevel() { + String minStartLevel = System.getProperty(MIN_START_LEVEL_PROPERTY); + Integer retVal = DEFAULT_MIN_START_LEVEL; + + logger.info("Loading property {} to specify minimal relevant start level for OSGi deps graph", MIN_START_LEVEL_PROPERTY); + + if (minStartLevel != null) { + try { + retVal = Integer.parseInt(minStartLevel); + } catch (NumberFormatException e) { + logger.error("Property {} not in numeric format: {}", MIN_START_LEVEL_PROPERTY, minStartLevel); + } + } + logger.info("Building deps graph for start levels {} or above", retVal); + return retVal; + } }