Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the budle start level property configurable, not hardcoded. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/main/java/com/vivosys/osgi/deps/OsgiDepsActivator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

I prefer a coding style without the single-return retVal in general, see https://softwareengineering.stackexchange.com/questions/118703/where-did-the-notion-of-one-return-only-come-from. Please update accordingly.

}
}