1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.ui.tests.dynamicplugins;
15 
16 import java.io.IOException;
17 import java.net.URL;
18 
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.ui.tests.TestPlugin;
21 import org.osgi.framework.Bundle;
22 import org.osgi.framework.BundleException;
23 
24 public class DynamicUtils {
25 
installPlugin(String pluginName)26 	public static final Bundle installPlugin(String pluginName)
27 			throws IOException, BundleException {
28 		// Programmatically install a new plugin
29 		TestPlugin plugin = TestPlugin.getDefault();
30 		if (plugin == null) {
31 			throw new IllegalStateException(
32 					"TestPlugin default reference is null");
33 		}
34 		String pluginLocation = null;
35 		URL dataURL = Platform.resolve(plugin.getBundle().getEntry(pluginName));
36 		pluginLocation = "reference:" + dataURL.toExternalForm();
37 		return TestInstallUtil.installBundle(pluginLocation);
38 	}
39 
uninstallPlugin(Bundle bundle)40 	public static void uninstallPlugin(Bundle bundle) throws BundleException {
41 		TestInstallUtil.uninstallBundle(bundle);
42 	}
43 
44 }
45