<commit_before>/**
 * I18N Tools
 *
 * Copyright (C) 2014 Worldline or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */
package com.worldline.awltech.i18ntools.wizard.core.ui;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.osgi.service.prefs.BackingStoreException;

import com.worldline.awltech.i18ntools.wizard.core.Activator;
import com.worldline.awltech.i18ntools.wizard.core.RefactoringWizardMessages;

/**
 * Refactoring graphical wizard Configuration.
 * 
 * Such configuration is stored locally in the .settings folder. Hence, it is
 * adapted to the current project's internationalization process and can be
 * shared to other developers through SCMs.
 * 
 * @author mvanbesien
 * 
 */
public class RefactoringWizardConfiguration {

	private static final String SRC_MAIN_RESOURCES = "src/main/resources";

	private static final String SRC = "src";

	private static final String SRC_MAIN_JAVA = "src/main/java";

	private static final String RESBUNDLE_NAME = "ResourceBundleName";

	private static final String LAST_LITERAL_NAME = "LastLiteralPrefix";

	private static final String RESBUNDLE_DEFAULT = "Messages";

	private static final String LAST_LITERAL_DEFAULT = "STUB";

	private static final String RESBUNDLE_PACK_NAME = "ResourceBundlePackage";

	private static final String RESBUNDLE_PACK_DEFAULT = "com.acme";

	private static final String JAVA_SOURCE_FOLDER_NAME = "JavaSourceFolder";

	private static final String RESOURCES_SOURCE_FOLDER_NAME = "ResourceSourceFolder";

	private final IEclipsePreferences preferences;

	private final IProject project;

	public RefactoringWizardConfiguration(final IProject project) {
		final IScopeContext projectScope = new ProjectScope(project);
		this.preferences = projectScope.getNode(Activator.PLUGIN_ID);
		this.project = project;
	}

	public String getResourceBundlePackage() {
		return this.preferences.get(RefactoringWizardConfiguration.RESBUNDLE_PACK_NAME,
				RefactoringWizardConfiguration.RESBUNDLE_PACK_DEFAULT);
	}

	public String getResourceBundleName() {
		return this.preferences.get(RefactoringWizardConfiguration.RESBUNDLE_NAME,
				RefactoringWizardConfiguration.RESBUNDLE_DEFAULT);
	}

	public String getLastLiteralPrefix() {
		return this.preferences.get(RefactoringWizardConfiguration.LAST_LITERAL_NAME,
				RefactoringWizardConfiguration.LAST_LITERAL_DEFAULT);
	}

	public String getJavaSourceFolder() {
		return this.preferences.get(RefactoringWizardConfiguration.JAVA_SOURCE_FOLDER_NAME, this.getSourceFolder(
				RefactoringWizardConfiguration.SRC_MAIN_JAVA, RefactoringWizardConfiguration.SRC, null));
	}

	public String getResourceSourceFolder() {
		return this.preferences.get(RefactoringWizardConfiguration.RESOURCES_SOURCE_FOLDER_NAME, this.getSourceFolder(
				RefactoringWizardConfiguration.SRC_MAIN_RESOURCES, RefactoringWizardConfiguration.SRC, null));
	}

	/**
	 * Returns the first source folder available in the list. The last one
	 * should be a default value that can be returned if none is found. If last
	 * one is null, the first source folder found in the project will be
	 * returned.
	 * 
	 * @param sourceFolders
	 * @return
	 */
	private String getSourceFolder(final String... sourceFolders) {

		// We look for all the source folders specified, except the last one.<commit_msg>Added new case for "resources" source folder support.<commit_after>/**
 * I18N Tools
 *
 * Copyright (C) 2014 Worldline or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */
package com.worldline.awltech.i18ntools.wizard.core.ui;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.osgi.service.prefs.BackingStoreException;

import com.worldline.awltech.i18ntools.wizard.core.Activator;
import com.worldline.awltech.i18ntools.wizard.core.RefactoringWizardMessages;

/**
 * Refactoring graphical wizard Configuration.
 * 
 * Such configuration is stored locally in the .settings folder. Hence, it is
 * adapted to the current project's internationalization process and can be
 * shared to other developers through SCMs.
 * 
 * @author mvanbesien
 * 
 */
public class RefactoringWizardConfiguration {

	private static final String SRC_MAIN_RESOURCES = "src/main/resources";

	private static final String SRC = "src";

	private static final String SRC_MAIN_JAVA = "src/main/java";

	private static final String RESOURCES = "resources";

	private static final String RESBUNDLE_NAME = "ResourceBundleName";

	private static final String LAST_LITERAL_NAME = "LastLiteralPrefix";

	private static final String RESBUNDLE_DEFAULT = "Messages";

	private static final String LAST_LITERAL_DEFAULT = "STUB";

	private static final String RESBUNDLE_PACK_NAME = "ResourceBundlePackage";

	private static final String RESBUNDLE_PACK_DEFAULT = "com.acme";

	private static final String JAVA_SOURCE_FOLDER_NAME = "JavaSourceFolder";

	private static final String RESOURCES_SOURCE_FOLDER_NAME = "ResourceSourceFolder";

	private final IEclipsePreferences preferences;

	private final IProject project;

	public RefactoringWizardConfiguration(final IProject project) {
		final IScopeContext projectScope = new ProjectScope(project);
		this.preferences = projectScope.getNode(Activator.PLUGIN_ID);
		this.project = project;
	}

	public String getResourceBundlePackage() {
		return this.preferences.get(RefactoringWizardConfiguration.RESBUNDLE_PACK_NAME,
				RefactoringWizardConfiguration.RESBUNDLE_PACK_DEFAULT);
	}

	public String getResourceBundleName() {
		return this.preferences.get(RefactoringWizardConfiguration.RESBUNDLE_NAME,
				RefactoringWizardConfiguration.RESBUNDLE_DEFAULT);
	}

	public String getLastLiteralPrefix() {
		return this.preferences.get(RefactoringWizardConfiguration.LAST_LITERAL_NAME,
				RefactoringWizardConfiguration.LAST_LITERAL_DEFAULT);
	}

	public String getJavaSourceFolder() {
		return this.preferences.get(RefactoringWizardConfiguration.JAVA_SOURCE_FOLDER_NAME, this.getSourceFolder(
				RefactoringWizardConfiguration.SRC_MAIN_JAVA, RefactoringWizardConfiguration.SRC, null));
	}

	public String getResourceSourceFolder() {
		return this.preferences.get(RefactoringWizardConfiguration.RESOURCES_SOURCE_FOLDER_NAME, this.getSourceFolder(
				RefactoringWizardConfiguration.SRC_MAIN_RESOURCES, RefactoringWizardConfiguration.RESOURCES,
				RefactoringWizardConfiguration.SRC, null));
	}

	/**
	 * Returns the first source folder available in the list. The last one
	 * should be a default value that can be returned if none is found. If last
	 * one is null, the first source folder found in the project will be
	 * returned.
	 * 
	 * @param sourceFolders
	 * @return
	 */
	private String getSourceFolder(final String... sourceFolders) {

		// We look for all the source folders specified, except the last one.
{'fraction_non_alphanumeric': 0.07175507600722866, 'fraction_numerical': 0.005315190815350271, 'mean_word_length': 5.331090174966353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1897716', 'n_tokens_mistral': 2799, 'n_tokens_neox': 2620, 'n_words': 791}