Over a million developers have joined DZone.
Platinum Partner

HOWTO: Find OSGi Dependencies in Features

· Java Zone

The Java Zone is brought to you in partnership with AppDynamics. Discover how AppDynamics steps in to upgrade your performance game and prevent your enterprise from these top 10 Java performance problems.

 Say you're trying to build something with Tycho & Maven 3 and while resolving dependencies before compilation, you're told:

[INFO] [Software being installed:
org.eclipse.tm.terminal.local.feature.group 0.1.0.v201006041240-10-7w312117152433,
Missing requirement:
org.eclipse.tm.terminal.local 0.1.0.v201006041322
'bundle org.eclipse.cdt.core 5.2.0'
but it could not be found,
Cannot satisfy dependency:
org.eclipse.tm.terminal.local.feature.group 0.1.0.v201006041240-10-7w312117152433
depends on:
org.eclipse.tm.terminal.local [0.1.0.v201006041322]]

o quickly verify where this dependency is coming from, you can go look into the feature.xml for the org.eclipse.tm.terminal.local feature jar... but if you don't have it installed, this is somewhat more cumbersome; besides, you then have to unpack the jar before you can look inside it.

And maybe that feature contains a number of OTHER dependencies that you'll also need to resolve in your target platform when building. Sure, there are UI tools to do this within Eclipse, but when you're working on remote servers sometimes UI isn't available.

Workaround? Assuming you have a mirror of the update site(s) from which you're trying to resolve the dependency (eg., Helios) or can ssh to dev.eclipse.org, you can simply run a quick shell script to do the investigative work for you:

$ cd ~/downloads/releases/helios/201009240900/aggregate/; ~/bin/findDepInFeature "*tm*" cdt

<import feature="org.eclipse.cdt.platform" version="7.0.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.cdt.core" version="5.2.0" match="compatible"/>
<import plugin="org.eclipse.core.runtime"/>

Where the script looks like this: 

# find plugins/feature deps by searching in some folder for feature jars, and searching through their feature.xml files for dependencies

# 1 - featurePattern - pattern of features to search (eg., "org.eclipse.tptp" or "\*" for all features)
# 2 - dependencyPattern - pattern of plugins/feature deps for which to search (eg., "org.eclipse.tptp.platform.instrumentation.ui")
# 3 - location - directory in which to search, if not "."

if [[ ! $1 ]]; then
echo "Usage: $0 <featurePattern> <dependencyPattern> <location>"
echo ""
echo "Example: $0 tm.terminal cdt"
exit 1

# if no location, look in current dir (.)
if [[ $3 ]]; then location="$3"; else location="."; fi

# if no featurePattern, search all features for dependencyPattern
if [[ ! $2 ]]; then featurePattern="*"; dependencyPattern="$1"; else dependencyPattern="$2"; featurePattern="$1"; fi

rm -fr /tmp/findinfeature/; mkdir -p /tmp/findinfeature/features/
for f in $(find "$location" -type f -name "*${featurePattern}*" | egrep -v "pack.gz|source" | grep features | egrep "${featurePattern}"); do
#echo "$f [$featurePattern, $dependencyPattern]"
unzip -q $f -d /tmp/findinfeature/ feature.xml
# <import feature="org.eclipse.cdt.platform" version="7.0.0" match="greaterOrEqual"/>
# <import plugin="org.eclipse.cdt.core" version="5.2.0" match="compatible"/>
if [[ ! $(cat /tmp/findinfeature/feature.xml | egrep "<import" -A3 | egrep "plugin=|feature=" -A1 -B1 | egrep "\".*${dependencyPattern}[^\"]*\"" -A1 -B1) ]]; then
rm -fr /tmp/findinfeature/feature.xml
mv /tmp/findinfeature/feature.xml /tmp/findinfeature/${f}_feature.xml
echo "${f}"
cat /tmp/findinfeature/${f}_feature.xml | egrep "<import" -A3 | egrep "plugin=|feature=" -A1 -B1 | egrep "\".*${dependencyPattern}[^\"]*\"" -A1 -B1
echo ""
rm -fr /tmp/findinfeature/feature.xml

From http://divby0.blogspot.com/2011/02/howto-find-osgi-dependencies-in.html

The Java Zone is brought to you in partnership with AppDynamics. AppDynamics helps you gain the fundamentals behind application performance, and implement best practices so you can proactively analyze and act on performance problems as they arise, and more specifically with your Java applications. Start a Free Trial.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}