private Plugin installPlugin()

in taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginManagerImpl.java [289:337]


	private Plugin installPlugin(JarFile jarFile) throws PluginException {
		PluginInfo pluginInfo = getPluginInfo(jarFile);

		PluginImpl plugin = new PluginImpl(this, new File(jarFile.getName()), pluginInfo);

		// check bundles exist in jar
		for (BundleInfo bundleInfo : pluginInfo.getBundle()) {
			// find the bundle in the plugin jar
			JarEntry entry = jarFile.getJarEntry(bundleInfo.getFileName());
			if (entry == null) {
				throw new PluginException(String.format(
						"Plugin file '%1$s' does not contain bundle file '%2$s'.",
						jarFile.getName(), bundleInfo.getFileName()));
			}
		}

		// install plugin bundles
		Set<Bundle> pluginBundles = plugin.getBundles();
		for (BundleInfo bundleInfo : pluginInfo.getBundle()) {
			Bundle installedBundle = getInstalledBundle(bundleInfo);
			if (installedBundle == null) {
				// install the bundle from the jar
				JarEntry entry = jarFile.getJarEntry(bundleInfo.getFileName());
				String bundleURL = jarEntryToURL(jarFile, entry);
				try {
					Bundle bundle = bundleContext.installBundle(bundleURL);
					pluginBundles.add(bundle);
					installedBundles.add(bundle);
					System.out.println("Add " + bundle.getSymbolicName());
				} catch (BundleException e) {
					// clean up by removing bundles already installed
					for (Bundle bundle : pluginBundles) {
						try {
							bundle.uninstall();
							installedBundles.remove(bundle);
						} catch (BundleException ex) {
							logger.warn("Error unistalling bundle", ex);
						}
					}
					throw new PluginException(String.format("Error installing bundle file %1$s",
							bundleURL), e);
				}
			} else {
				pluginBundles.add(installedBundle);
			}
		}
		plugin.setState(State.INSTALLED);
		return plugin;
	}