Eclipse Zone is brought to you in partnership with:

Nick Boldt is a release engineer, formerly with IBM Rational Software Canada. As a committer for the Eclipse Modeling Project, he's automated build processes, integrated web & build systems, and designed build tools to simply and streamline building, testing, and releasing project code. Nick is a DZone MVB and is not an employee of DZone and has posted 14 posts at DZone. View Full User Profile

HOWTO: Find OSGi Dependencies in Features

  • submit to reddit

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

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

o quickly verify where this dependency is coming from, you can go look into the feature.xml for the 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, 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


Published at DZone with permission of Nick Boldt, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Thomas Kern replied on Thu, 2012/09/06 - 10:51am

Hey Nick,
how do you manage, the you use the syntaxt highlighter in the blog, but the code is shown correctly on the planet?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.