<commit_before>/*******************************************************************************
 * Copyright (c) 2014 <NAME>.
 * 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:
 *     <NAME> <<EMAIL>> - initial API and implementation
 ******************************************************************************/
package com.buzzcoders.yasw.widgets.map;

import java.io.IOException;
import java.net.URL;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

import com.buzzcoders.yasw.widgets.map.messages.Messages;

/**
 * The activator class controls the plug-in life cycle
 */
public class MapActivator extends AbstractUIPlugin {

	public static final String FIND_BTN_IMG = "FIND_BTN"; //$NON-NLS-1$

	// The plug-in ID
	public static final String PLUGIN_ID = "com.buzzcoders.yasw.widgets.map"; //$NON-NLS-1$

	// The shared instance
	private static MapActivator plugin;
	
	/**
	 * The constructor
	 */
	public MapActivator() {
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
		// trick used to unpack the dir content to filesystem
		getFileLocation("mapfiles/gmaps_library/"); //$NON-NLS-1$
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		plugin = null;
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static MapActivator getDefault() {
		return plugin;
	}
	
	/**
	 * Logs an error message and an optional exception for the current bundle.
	 * 
	 * @param message
	 *            a human-readable message
	 * @param exception
	 *            a low-level exception, or <code>null</code> if not applicable
	 */
	public static void logError(String message, Throwable exception) {
		Platform.getLog(getDefault().getBundle()).log(
				new Status(IStatus.ERROR, PLUGIN_ID, message, exception));
	}

	/**
	 * Gets the full path name for a resource located inside the current bundle.
	 * 
	 * @param path
	 *            the path of the internal resource
	 * @return the string corresponding to the full path
	 * @throws IOException
	 *             if a problem occurs during conversion
	 */
	public static String getFileLocation(String path) {
		Assert.isNotNull(path);
		Bundle bundle = getDefault().getBundle();
		String fullPath = null;
		try {
			if (bundle != null) {
				fullPath = FileLocator.toFileURL(bundle.getEntry(path)).getPath();
			}
		}
		catch (IOException ex) {
			logError(Messages.MapActivator_FileError, ex);
		}
		return fullPath;
	}
	
	@Override
	protected void initializeImageRegistry(ImageRegistry reg) {
		Bundle bundle = Platform.getBundle(PLUGIN_ID);
		IPath path = new Path("icons/find-20.png"); //$NON-NLS-1$
		URL url = FileLocator.find(bundle, path, null);
		ImageDescriptor desc = ImageDescriptor.createFromURL(url);
		reg.put(FIND_BTN_IMG, desc);
	}
	
}<commit_msg>Fixed file locating API. Issues verified on Windows: an additional starting slash was present in the returned path.<commit_after>/*******************************************************************************
 * Copyright (c) 2014 <NAME>.
 * 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:
 *     <NAME> <<EMAIL>> - initial API and implementation
 ******************************************************************************/
package com.buzzcoders.yasw.widgets.map;

import java.io.IOException;
import java.net.URL;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

import com.buzzcoders.yasw.widgets.map.messages.Messages;

/**
 * The activator class controls the plug-in life cycle
 */
public class MapActivator extends AbstractUIPlugin {

	public static final String FIND_BTN_IMG = "FIND_BTN"; //$NON-NLS-1$

	// The plug-in ID
	public static final String PLUGIN_ID = "com.buzzcoders.yasw.widgets.map"; //$NON-NLS-1$

	// The shared instance
	private static MapActivator plugin;
	
	/**
	 * The constructor
	 */
	public MapActivator() {
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
		// trick used to unpack the dir content to filesystem
		getFileLocation("mapfiles/gmaps_library/"); //$NON-NLS-1$
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		plugin = null;
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static MapActivator getDefault() {
		return plugin;
	}
	
	/**
	 * Logs an error message and an optional exception for the current bundle.
	 * 
	 * @param message
	 *            a human-readable message
	 * @param exception
	 *            a low-level exception, or <code>null</code> if not applicable
	 */
	public static void logError(String message, Throwable exception) {
		Platform.getLog(getDefault().getBundle()).log(
				new Status(IStatus.ERROR, PLUGIN_ID, message, exception));
	}

	/**
	 * Gets the full path name for a resource located inside the current bundle.
	 * 
	 * @param path
	 *            the path of the internal resource
	 * @return the string corresponding to the full path
	 * @throws IOException
	 *             if a problem occurs during conversion
	 */
	public static String getFileLocation(String path) {
		Assert.isNotNull(path);
		Bundle bundle = getDefault().getBundle();
		String fullPath = null;
		try {
			if (bundle != null) {
				fullPath = new Path(FileLocator.toFileURL(bundle.getEntry(path)).getPath()).toOSString();
			}
		}
		catch (IOException ex) {
			logError(Messages.MapActivator_FileError, ex);
		}
		return fullPath;
	}
	
	@Override
	protected void initializeImageRegistry(ImageRegistry reg) {
		Bundle bundle = Platform.getBundle(PLUGIN_ID);
		IPath path = new Path("icons/find-20.png"); //$NON-NLS-1$
		URL url = FileLocator.find(bundle, path, null);
		ImageDescriptor desc = ImageDescriptor.createFromURL(url);
		reg.put(FIND_BTN_IMG, desc);
	}
	
}
{'fraction_non_alphanumeric': 0.14795313939713045, 'fraction_numerical': 0.0036856653942345663, 'mean_word_length': 3.9921156373193165, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6821657', 'n_tokens_mistral': 2398, 'n_tokens_neox': 2209, 'n_words': 596}