<commit_before>package de.ptb.epics.eve.editor;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.xml.sax.SAXException;

import de.ptb.epics.eve.data.measuringstation.IMeasuringStation;
import de.ptb.epics.eve.data.measuringstation.MeasuringStation;
import de.ptb.epics.eve.data.measuringstation.processors.MeasuringStationLoader;
import de.ptb.epics.eve.preferences.PreferenceConstants;
import de.ptb.epics.eve.data.measuringstation.filter.ExcludeFilter;
import de.ptb.epics.eve.editor.logging.EclipseLogListener;

/**
 * The activator class controls the plug-in life cycle
 */
public class Activator extends AbstractUIPlugin {
	
	/** 
	 * The unique identifier of the plug in 
	 */
	public static final String PLUGIN_ID = "de.ptb.epics.eve.editor";
	
	// The shared instance
	private static Activator plugin;
	
	private static Logger logger = Logger.getLogger(Activator.class.getName());
	
	/*
	 * Listener for the Eclipse Logger. catches logs of eclipse and forwards 
	 * them to the log4j logger. (only logs with level 
	 * org.eclipse.core.runtime.IStatus.WARNING or
	 * org.eclipse.core.runtime.IStatus.ERROR are forwarded).
	 */
	private ILogListener logListener;
	
	private IMeasuringStation measuringStation;
	private ExcludeFilter excludeFilter;
	
	private File schemaFile;
	private String rootDir;
	private boolean debug;
	
	private final String defaultWindowTitle = "Control System Studio";
	
	private EveEditorPerspectiveListener eveEditorPerspectiveListener;
	
	/**
	 * The constructor
	 */
	public Activator() {
		plugin = this;
		eveEditorPerspectiveListener = new EveEditorPerspectiveListener();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void start(final BundleContext context) throws Exception {
		super.start(context);
		
		readStartupParameters();
		if(!checkRootDir()) {
			context.getBundle().stop();
			context.getBundle().uninstall();
			return;
		}
		configureLogging();
		loadMeasuringStation();
		startupReport();

		PlatformUI.getWorkbench().getActiveWorkbenchWindow().
				addPerspectiveListener(eveEditorPerspectiveListener);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void stop(final BundleContext context) throws Exception {
		PlatformUI.getWorkbench().getActiveWorkbenchWindow().
			removePerspectiveListener(eveEditorPerspectiveListener);
		eveEditorPerspectiveListener = null;
		
		Platform.removeLogListener(logListener);
		logListener = null;
		plugin = null;
		
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static Activator getDefault() {
		return plugin;
	}
	
	/**
	 * Returns the root directory the plug in is working on.
	 * 
	 * @return the root directory the plug in is working on
	 */
	public String getRootDirectory() {
		return rootDir;
	}
	
	/**
	 * <commit_msg>removed command (not needed) which caused a null pointer exception when closing the application<commit_after>package de.ptb.epics.eve.editor;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.xml.sax.SAXException;

import de.ptb.epics.eve.data.measuringstation.IMeasuringStation;
import de.ptb.epics.eve.data.measuringstation.MeasuringStation;
import de.ptb.epics.eve.data.measuringstation.processors.MeasuringStationLoader;
import de.ptb.epics.eve.preferences.PreferenceConstants;
import de.ptb.epics.eve.data.measuringstation.filter.ExcludeFilter;
import de.ptb.epics.eve.editor.logging.EclipseLogListener;

/**
 * The activator class controls the plug-in life cycle
 */
public class Activator extends AbstractUIPlugin {
	
	/** 
	 * The unique identifier of the plug in 
	 */
	public static final String PLUGIN_ID = "de.ptb.epics.eve.editor";
	
	// The shared instance
	private static Activator plugin;
	
	private static Logger logger = Logger.getLogger(Activator.class.getName());
	
	/*
	 * Listener for the Eclipse Logger. catches logs of eclipse and forwards 
	 * them to the log4j logger. (only logs with level 
	 * org.eclipse.core.runtime.IStatus.WARNING or
	 * org.eclipse.core.runtime.IStatus.ERROR are forwarded).
	 */
	private ILogListener logListener;
	
	private IMeasuringStation measuringStation;
	private ExcludeFilter excludeFilter;
	
	private File schemaFile;
	private String rootDir;
	private boolean debug;
	
	private final String defaultWindowTitle = "Control System Studio";
	
	private EveEditorPerspectiveListener eveEditorPerspectiveListener;
	
	/**
	 * The constructor
	 */
	public Activator() {
		plugin = this;
		eveEditorPerspectiveListener = new EveEditorPerspectiveListener();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void start(final BundleContext context) throws Exception {
		super.start(context);
		
		readStartupParameters();
		if(!checkRootDir()) {
			context.getBundle().stop();
			context.getBundle().uninstall();
			return;
		}
		configureLogging();
		loadMeasuringStation();
		startupReport();

		PlatformUI.getWorkbench().getActiveWorkbenchWindow().
				addPerspectiveListener(eveEditorPerspectiveListener);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void stop(final BundleContext context) throws Exception {
		Platform.removeLogListener(logListener);
		logListener = null;
		plugin = null;
		
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static Activator getDefault() {
		return plugin;
	}
	
	/**
	 * Returns the root directory the plug in is working on.
	 * 
	 * @return the root directory the plug in is working on
	 */
	public String getRootDirectory() {
		return rootDir;
	}
	
	/**
	 * 
{'fraction_non_alphanumeric': 0.09943890274314214, 'fraction_numerical': 0.0009351620947630922, 'mean_word_length': 4.494006849315069, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '6276577', 'n_tokens_mistral': 2044, 'n_tokens_neox': 1851, 'n_words': 445}