<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> - initial implementation.
 *******************************************************************************/

package ilg.gnumcueclipse.packs.core;

import java.io.File;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;

/**
 * Class used to initialise default preference values.
 */
public class PreferencesInitializer extends AbstractPreferenceInitializer {

	public void initializeDefaultPreferences() {

		// System.out
		// .println("PreferenceInitializer.initializeDefaultPreferences()");

		// Get workspace
		IWorkspace workspace = ResourcesPlugin.getWorkspace();

		// Compute workspace/../Packages
		IPath workspacePath = workspace.getRoot().getLocation();
		IPath workspaceParentPath = workspacePath.removeLastSegments(1);
		IPath packagesPath = workspaceParentPath.append("Packages");
		// System.out.println(packagesPath.toOSString());

		IPreferenceStore store = Preferences.getPreferenceStore();
		store.setDefault(Preferences.PACKS_FOLDER_PATH, packagesPath.toOSString());
		store.setDefault(Preferences.PACKS_MACRO_NAME, Preferences.DEFAULT_MACRO_NAME);
		
		// Read back the actual value.
		String folderPath = store.getString(Preferences.PACKS_FOLDER_PATH);

		File packagesFolder = new File(folderPath);
		if (!packagesFolder.exists()) {
			packagesFolder.mkdir();
			if (Activator.getInstance().isDebugging()) {
			  System.out.println(packagesFolder + " created");
			}
		}
	}
}<commit_msg>[#357]: Change the CMSIS Packs default location<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> - initial implementation.
 *******************************************************************************/

package ilg.gnumcueclipse.packs.core;

import java.io.File;
import java.util.Map;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;

import ilg.gnumcueclipse.core.EclipseUtils;
import ilg.gnumcueclipse.core.XpackUtils;

/**
 * Class used to initialise default preference values.
 */
public class PreferencesInitializer extends AbstractPreferenceInitializer {

	public void initializeDefaultPreferences() {

		if (Activator.getInstance().isDebugging()) {
			System.out.println("PreferenceInitializer.initializeDefaultPreferences()");
		}
		
		// Get workspace
		IWorkspace workspace = ResourcesPlugin.getWorkspace();

		IPath packagesPath = null;

		Map<String, String> env = System.getenv();
		String envFolder = env.get("CMSIS_PACKS_FOLDER");
		if (envFolder != null) {
			IPath path = new Path(envFolder);
			if (path.toFile().isDirectory()) {
				packagesPath = path;
			} else {
				Activator.log("\"" + envFolder + "\" not a folder, ignored.");
			}
		}

		// For compatibility reasons, if workspace/../Packages exists, use it.
		if (packagesPath == null) {
			IPath workspacePath = workspace.getRoot().getLocation();
			IPath workspaceParentPath = workspacePath.removeLastSegments(1);
			IPath path = workspaceParentPath.append("Packages");
			// System.out.println(packagesPath.toOSString());
			File packagesFolder = new File(path.toOSString());
			if (packagesFolder.isDirectory()) {
				packagesPath = path;
			}
		}

		if (packagesPath == null) {
			packagesPath = XpackUtils.getRepoBasePath();
			if (EclipseUtils.isLinux()) {
				packagesPath = packagesPath.append("cmsis-packs");
			} else {
				packagesPath = packagesPath.append("CMSIS-Packs");
			}
		}
		
		IPreferenceStore store = Preferences.getPreferenceStore();
		store.setDefault(Preferences.PACKS_FOLDER_PATH, packagesPath.toOSString());
		store.setDefault(Preferences.PACKS_MACRO_NAME, Preferences.DEFAULT_MACRO_NAME);

		// Read back the actual value.
		String folderPath = store.getString(Preferences.PACKS_FOLDER_PATH);

		File packagesFolder = new File(folderPath);
		if (!packagesFolder.exists()) {
			packagesFolder.mkdir();
			System.out.println("Folder \"" + packagesFolder + "\" created");
		} if (!packagesFolder.isDirectory()) {
			Activator.log("\"" + folderPath + "\" present, but not a folder; not good.");
		}
	}
}
{'fraction_non_alphanumeric': 0.17190531625921615, 'fraction_numerical': 0.004074505238649592, 'mean_word_length': 4.987224157955866, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '4337870', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1395, 'n_words': 308}