blob: 86e8411c0b3017569d2bf020a7c9a88eb5bc7ec5 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wtp.releng.tools.component.dependency;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.IBundleGroup;
import org.eclipse.core.runtime.IBundleGroupProvider;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
public class PluginDependencyScanner
{
public Map execute()
{
Map plugins = new HashMap();
IBundleGroupProvider[] providers = Platform.getBundleGroupProviders();
for (int i = 0; i < providers.length; i++)
{
IBundleGroup[] groups = providers[i].getBundleGroups();
for (int j = 0; j < groups.length; j++)
{
Bundle[] bundles = groups[j].getBundles();
for (int k = 0; k < bundles.length; k++)
{
String id = bundles[k].getSymbolicName();
Plugin plugin = getPlugin(plugins, id);
Dictionary headers = bundles[k].getHeaders();
String requiredBundles = (String)headers.get(Constants.REQUIRE_BUNDLE);
if (requiredBundles != null)
{
StringTokenizer st = new StringTokenizer(requiredBundles, ",");
while (st.hasMoreTokens())
{
String token = st.nextToken();
int semicolon = token.indexOf(';');
if (semicolon != -1)
token = token.substring(0, semicolon);
Plugin require = getPlugin(plugins, token);
plugin.addRequire(require);
require.addDependent(plugin);
}
}
}
}
}
return plugins;
}
private Plugin getPlugin(Map plugins, String id)
{
if (plugins.containsKey(id))
return (Plugin)plugins.get(id);
else
{
Plugin plugin = new Plugin();
plugin.setId(id);
plugins.put(id, plugin);
return plugin;
}
}
}