Java Code Examples for org.eclipse.core.runtime.Platform#getBundle()

The following examples show how to use org.eclipse.core.runtime.Platform#getBundle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FelixLogsModelTest.java    From tesb-studio-se with Apache License 2.0 7 votes vote down vote up
/**
 * Test method for {@link org.talend.designer.esb.runcontainer.logs.FelixLogsModel#toString()}.
 *
 * @throws Exception
 */
@Test
public void testToString() throws Exception {

    Bundle b = Platform.getBundle("org.talend.esb.designer.esb.runcontainer.test");
    URL url = FileLocator.toFileURL(FileLocator.find(b, new Path("resources"), null)); //$NON-NLS-1$
    File responseFile = new File(url.getPath() + "/FelixLogsModelTest.json"); //$NON-NLS-1$
    Assert.assertTrue(responseFile.exists());
    String json = new String(Files.readAllBytes(responseFile.toPath()));
    String data = "\"data\":";
    int dataPos = json.indexOf(data) + 7;
    String line = json.substring(dataPos, json.length());
    ObjectMapper mapper = new ObjectMapper();
    FelixLogsModel[] logs = mapper.readValue(line, FelixLogsModel[].class);
    Assert.assertEquals(logs.length, 100);

}
 
Example 2
Source File: SelfBaseHelpSystem.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public static void runLiveHelp(String pluginID, String className, String arg) {	
	Bundle bundle = Platform.getBundle(pluginID);
	if (bundle == null) {
		return;
	}

	try {
		Class c = bundle.loadClass(className);
		Object o = c.newInstance();
		//Runnable runnable = null;
		if (o != null && o instanceof ILiveHelpAction) {
			ILiveHelpAction helpExt = (ILiveHelpAction) o;
			if (arg != null)
				helpExt.setInitializationString(arg);
			Thread runnableLiveHelp = new Thread(helpExt);
			runnableLiveHelp.setDaemon(true);
			runnableLiveHelp.start();
		}
	} catch (ThreadDeath td) {
		throw td;
	} catch (Exception e) {
	}
}
 
Example 3
Source File: CommonFunction.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 当程序开始运行时,检查 qa 插件是否存在,如果不存在,则不执行任何操作,如果存在,则检查 configuration\net.heartsome.cat.ts.ui\hunspell 
 * 下面是否有 hunspell 运行所需要的词典以及运行函数库。如果没有,则需要从 qa 插件中进行获取,并且解压到上述目录下。
 * robert	2013-02-28
 */
public static void unZipHunspellDics() throws Exception{
	Bundle bundle = Platform.getBundle("net.heartsome.cat.ts.ui.qa");
	if (bundle == null) {
		return;
	}
	
	// 查看解压的 hunspell词典 文件夹是否存在
	String configHunspllDicFolder = Platform.getConfigurationLocation().getURL().getPath() 
			+ "net.heartsome.cat.ts.ui" + System.getProperty("file.separator") + "hunspell"
			+ System.getProperty("file.separator") + "hunspellDictionaries";
	if (!new File(configHunspllDicFolder).exists()) {
		new File(configHunspllDicFolder).mkdirs();
		String hunspellDicZipPath = FileLocator.toFileURL(bundle.getEntry("hunspell/hunspellDictionaries.zip")).getPath();
		upZipFile(hunspellDicZipPath, configHunspllDicFolder);
	}
}
 
Example 4
Source File: AbstractDocumentationHover.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads the hover style sheet.
 */
protected static String loadStyleSheet(String cssPath)
{
	Bundle bundle = Platform.getBundle(UIEplPlugin.PLUGIN_ID);
	if (bundle == null)
	{
		return StringUtil.EMPTY;
	}
	URL styleSheetURL = bundle.getEntry(cssPath);
	if (styleSheetURL != null)
	{
		try
		{
			return IOUtil.read(styleSheetURL.openStream());
		}
		catch (IOException ex)
		{
			IdeLog.logError(UIEplPlugin.getDefault(), "Documentation hover - Error loading the style-sheet", ex); //$NON-NLS-1$
			return StringUtil.EMPTY;
		}
	}
	return StringUtil.EMPTY;
}
 
Example 5
Source File: UIUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return Report Designer UI plugin installation directory as OS string.
 */
public static String getFragmentDirectory( )
{
	Bundle bundle = Platform.getBundle( IResourceLocator.FRAGMENT_RESOURCE_HOST );
	if ( bundle == null )
	{
		return null;
	}
	URL url = bundle.getEntry( "/" ); //$NON-NLS-1$
	if ( url == null )
	{
		return null;
	}
	String directory = null;
	try
	{
		directory = FileLocator.resolve( url ).getPath( );
	}
	catch ( IOException e )
	{
		logger.log( Level.SEVERE, e.getMessage( ), e );
	}
	return directory;
}
 
Example 6
Source File: DBConfig.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public DBConfig(URL dbconfig, MetaData metaData){
	this.metaData = metaData;
	try {
		SAXReader reader = new SAXReader();
		Document doc = reader.read(dbconfig);
		root = doc.getRootElement();
		
		Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
		URL defaultUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
		SAXReader defaultReader = new SAXReader();
		Document defaultDoc = defaultReader.read(defaultUrl);
		defaultRoot = defaultDoc.getRootElement();
	} catch (DocumentException e) {
		logger.warn("", e);
	}
}
 
Example 7
Source File: UtilitiesTest.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Test
public void newLibraryEntry_precomputedPath_nullJavadocMapping() {
	//
	Bundle bundle = Platform.getBundle("io.sarl.lang.core");
	Assume.assumeNotNull(bundle);
	//
	IPath precomputedPath = BundleUtil.getBundlePath(bundle);
	//
	IClasspathEntry entry = Utilities.newLibraryEntry(bundle, precomputedPath, null);
	assertNotNull(entry);
	assertEquals(IClasspathEntry.CPE_LIBRARY, entry.getEntryKind());
	assertEquals(IPackageFragmentRoot.K_BINARY, entry.getContentKind());
	assertEquals(precomputedPath, entry.getPath());
	assertEquals(BundleUtil.getSourceBundlePath(bundle, BundleUtil.getBundlePath(bundle)), entry.getSourceAttachmentPath());
	IClasspathAttribute[] extras = entry.getExtraAttributes();
	assertNotNull(extras);
	if (isEclipseRuntimeEnvironment()) {
		assertEquals(1, extras.length);
		assertEquals("javadoc_location", extras[0].getName());
		assertTrue(extras[0].getValue().endsWith("io.sarl.lang.core/"));
	} else {
		assertEquals(0, extras.length);
	}
}
 
Example 8
Source File: AnnotationClasspathInitializer.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void initialize(String variable) {
    Bundle bundle = Platform.getBundle(FindbugsPlugin.PLUGIN_ID);
    if (bundle == null) {
        return;
    }
    String fullPath = getLibraryPath(bundle, FINDBUGS_LIBRARY);
    setVariable(fullPath, FINDBUGS_ANNOTATIONS);
    fullPath = getLibraryPath(bundle, JSR305_LIBRARY);
    setVariable(fullPath, JSR305_ANNOTATIONS);
}
 
Example 9
Source File: Activator.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
protected void initializeImageRegistry(ImageRegistry registry) {
   imageNames = new ArrayList<String>();
   Bundle bundle = Platform.getBundle(Constants.PLUGIN_ID);
   OS os = Utils.getOS();
   for (String imageId : Category.getImageIdsAsList()) {
       String imagePath = Constants.IMAGE_PATH + os.getId() + "/" + imageId + Constants.IMAGE_EXT;
       URL url = bundle.getEntry(imagePath);
       if (url == null) {
           imagePath = Constants.IMAGE_PATH + imageId + Constants.IMAGE_EXT;
       }
       addImageToRegistry(registry, bundle, imagePath, imageId);
   }
   addImageToRegistry(registry, bundle, Constants.IMAGE_PATH + Constants.IMAGE_EASYSHELL + Constants.IMAGE_EXT, Constants.IMAGE_EASYSHELL);
   addImageToRegistry(registry, bundle, Constants.IMAGE_PATH + Constants.IMAGE_ECLIPSE + Constants.IMAGE_EXT, Constants.IMAGE_ECLIPSE);
}
 
Example 10
Source File: SwitchRepositoryMenuCreator.java    From ADT_Frontend with MIT License 5 votes vote down vote up
/**
 * Get image for my repositories
 */
private ImageDescriptor getMyRepositoryImageDescriptor() {
	if (this.myRepositoryImageDescriptor == null) {
		Bundle actionShowMyReposBundle = Platform.getBundle("com.sap.adt.projectexplorer.ui"); //$NON-NLS-1$
		if (actionShowMyReposBundle != null) {
			URL actionShowMyReposImgUrl = FileLocator.find(actionShowMyReposBundle, new Path("icons/obj/package_obj_user.png"), null); //$NON-NLS-1$
			this.myRepositoryImageDescriptor = ImageDescriptor.createFromURL(actionShowMyReposImgUrl);
		}
	}
	return this.myRepositoryImageDescriptor;
}
 
Example 11
Source File: TMDatabaseImpl.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 构造函数
 */
public TMDatabaseImpl() {
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
}
 
Example 12
Source File: InvasiveThemeHijacker.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
protected void applyThemeToEclipseEditors(Theme theme, boolean revertToDefaults, IProgressMonitor monitor)
{
	// Set prefs for all editors
	setHyperlinkValues(theme, EclipseUtil.instanceScope().getNode("org.eclipse.ui.workbench"), revertToDefaults); //$NON-NLS-1$
	setHyperlinkValues(theme, EclipseUtil.instanceScope().getNode(ThemePlugin.PLUGIN_ID), revertToDefaults);

	// FIXME only set these if egit or mercurial are installed!
	setGitAndMercurialValues(theme,
			EclipseUtil.instanceScope().getNode("org.eclipse.ui.workbench"), revertToDefaults); //$NON-NLS-1$

	setGeneralEditorValues(theme,
			EclipseUtil.instanceScope().getNode("org.eclipse.ui.texteditor"), revertToDefaults); //$NON-NLS-1$
	setEditorValues(theme, EclipseUtil.instanceScope().getNode("org.eclipse.ui.editors"), revertToDefaults); //$NON-NLS-1$

	if (monitor.isCanceled())
	{
		return;
	}

	// PDE
	Bundle pde = Platform.getBundle(ORG_ECLIPSE_PDE_UI);
	if (pde != null)
	{
		IEclipsePreferences pdePrefs = EclipseUtil.instanceScope().getNode(ORG_ECLIPSE_PDE_UI);
		setGeneralEditorValues(theme, pdePrefs, revertToDefaults);
		setPDEEditorValues(theme, pdePrefs, revertToDefaults);
	}

	if (monitor.isCanceled())
	{
		return;
	}

	// Ant
	Bundle ant = Platform.getBundle(ORG_ECLIPSE_ANT_UI);
	if (ant != null)
	{
		IEclipsePreferences antPrefs = EclipseUtil.instanceScope().getNode(ORG_ECLIPSE_ANT_UI);
		setGeneralEditorValues(theme, antPrefs, revertToDefaults);
		setAntEditorValues(theme, antPrefs, revertToDefaults);
	}
	if (monitor.isCanceled())
	{
		return;
	}

	// JDT
	Bundle jdt = Platform.getBundle(ORG_ECLIPSE_JDT_UI);
	if (jdt != null)
	{
		applyThemetoJDT(theme, revertToDefaults);
	}

	// WST
	Bundle wstBundle = Platform.getBundle(ORG_ECLIPSE_WST_JSDT_UI);
	if (wstBundle != null)
	{
		applyThemetoWST(theme, revertToDefaults);
	}
}
 
Example 13
Source File: NodePackageManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private IStatus runNpmInstaller(String packageName, String displayName, boolean global, char[] password,
		IPath workingDirectory, String command, IProgressMonitor monitor) throws CoreException, IOException,
		InterruptedException
{
	SubMonitor sub = SubMonitor.convert(monitor,
			MessageFormat.format(Messages.NodePackageManager_InstallingTaskName, displayName), 100);
	try
	{
		List<String> args = getNpmSudoArgs(global, password);
		CollectionsUtil.addToList(args, command, packageName, COLOR, FALSE);

		Map<String, String> environment;
		if (PlatformUtil.isWindows())
		{
			environment = new HashMap<String, String>(System.getenv());
		}
		else
		{
			environment = ShellExecutable.getEnvironment();
		}
		args.addAll(proxySettings(environment));
		environment.put(IProcessRunner.REDIRECT_ERROR_STREAM, StringUtil.EMPTY);

		// HACK for TISTUD-4101
		if (PlatformUtil.isWindows())
		{
			IPath pythonExe = ExecutableUtil.find("pythonw.exe", false, null); //$NON-NLS-1$
			if (pythonExe == null)
			{
				// Add python to PATH
				Bundle bundle = Platform.getBundle("com.appcelerator.titanium.python.win32"); //$NON-NLS-1$
				if (bundle != null)
				{
					// Windows is wonderful, it sometimes stores in "Path" and "PATH" doesn't work
					String pathName = "PATH"; //$NON-NLS-1$
					if (!environment.containsKey(pathName))
					{
						pathName = "Path"; //$NON-NLS-1$
					}
					String path = environment.get(pathName);

					IPath relative = new Path("."); //$NON-NLS-1$
					URL bundleURL = FileLocator.find(bundle, relative, null);
					URL fileURL = FileLocator.toFileURL(bundleURL);
					File f = new File(fileURL.getPath());
					if (f.exists())
					{
						path = path + File.pathSeparator + new File(f, "python").getCanonicalPath(); //$NON-NLS-1$
						environment.put(pathName, path);
					}
				}
			}
		}

		return getProcessRunner().run(workingDirectory, environment, password, args, sub.newChild(100));
	}
	finally
	{
		sub.done();
	}
}
 
Example 14
Source File: TypesExecutableExtensionFactory.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected Bundle getBundle() {
	return Platform.getBundle(TypesActivator.PLUGIN_ID);
}
 
Example 15
Source File: ExtensionContextInjectionFactory.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private Bundle getDeclaringBundle(final IConfigurationElement element) {
    return Platform.getBundle(element.getDeclaringExtension().getNamespaceIdentifier());
}
 
Example 16
Source File: Bug360834TestLanguageExecutableExtensionFactory.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected Bundle getBundle() {
	return Platform.getBundle(TestsActivator.PLUGIN_ID);
}
 
Example 17
Source File: CrossReferenceProposalTestLanguageExecutableExtensionFactory.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected Bundle getBundle() {
	return Platform.getBundle(TestsActivator.PLUGIN_ID);
}
 
Example 18
Source File: TmfTraceTypeUIUtils.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Get the Event Table type specified by the trace type's extension point,
 * if there is one.
 *
 * @param trace
 *            The trace for which we want the events table.
 * @param parent
 *            The parent composite that the event table will have
 * @param cacheSize
 *            The cache size to use with this event table. Should be defined
 *            by the trace type.
 * @return The corresponding Event Table, or 'null' if this trace type did
 *         not specify any.
 */
public static @Nullable TmfEventsTable getEventTable(ITmfTrace trace, Composite parent, int cacheSize) {
    final String traceType = getTraceType(trace);
    if (traceType == null) {
        return null;
    }

    TraceElementType elType = (trace instanceof TmfExperiment) ? TraceElementType.EXPERIMENT : TraceElementType.TRACE;
    for (final IConfigurationElement ce : TmfTraceTypeUIUtils.getTypeUIElements(elType)) {
        if (ce.getAttribute(TmfTraceTypeUIUtils.TRACETYPE_ATTR).equals(traceType)) {
            final IConfigurationElement[] eventsTableTypeCE = ce.getChildren(TmfTraceTypeUIUtils.EVENTS_TABLE_TYPE_ELEM);

            if (eventsTableTypeCE.length != 1) {
                break;
            }
            final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceTypeUIUtils.CLASS_ATTR);
            final boolean useTraceAspects = Boolean.parseBoolean(eventsTableTypeCE[0].getAttribute(TmfTraceTypeUIUtils.USE_TRACE_ASPECTS_ATTR));

            if ((eventsTableType == null) || eventsTableType.isEmpty()) {
                break;
            }
            try {
                final Bundle bundle = Platform.getBundle(ce.getContributor().getName());
                final Class<?> c = bundle.loadClass(eventsTableType);
                Class<?>[] constructorArgs = null;
                Object[] args = null;
                if (useTraceAspects) {
                    args = new Object[] { parent, cacheSize, trace.getEventAspects() };
                    constructorArgs = new Class[] { Composite.class, int.class, Iterable.class };
                } else {
                    args = new Object[] { parent, cacheSize };
                    constructorArgs = new Class[] { Composite.class, int.class };
                }
                final Constructor<?> constructor = c.getConstructor(constructorArgs);
                return (TmfEventsTable) constructor.newInstance(args);
            } catch (NoSuchMethodException | ClassNotFoundException | InstantiationException |
                    IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                return null;
            }
        }
    }
    return null;
}
 
Example 19
Source File: PureXbaseExecutableExtensionFactory.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected Bundle getBundle() {
	return Platform.getBundle(PurexbaseActivator.PLUGIN_ID);
}
 
Example 20
Source File: TestFactory.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
@Test
public void testName() {
	Bundle odaBundle = Platform.getBundle("org.openntf.domino");
	String name = odaBundle.getHeaders().get("Bundle-Name");
	assertEquals("Name should match OSGi's info", name, Factory.getTitle());
}