<commit_before>/**
 * AsciidocTools by Worldline
 *
 * Copyright (C) 2016 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.asciidoctools.builder;

import java.util.Iterator;

import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.eclipse.core.resources.IProject;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.IMavenProjectFacade;

/**
 * 
 * Asciidoc Project Configuration pojo. Contains information about the
 * source/resources location, where to put generated doc etc...
 * 
 * @author mvanbesien <<EMAIL>>
 * @since 0.1
 *
 */
public class AsciidocConfiguration {

	private String sourcesPath = "src/main/asciidoc";

	private String resourcesPath = "src/main/doc-resources";

	private String targetPath = "target/generated-docs";

	private String stylesheetPath = "css/stylesheet.css";

	private String backend = "html";

	public String getBackend() {
		return backend;
	}

	public void setBackend(String backend) {
		this.backend = backend;
	}

	public String getSourcesPath() {
		return sourcesPath;
	}

	public void setSourcesPath(String sourcesPath) {
		this.sourcesPath = sourcesPath;
	}

	public String getResourcesPath() {
		return resourcesPath;
	}

	public void setResourcesPath(String resourcesPath) {
		this.resourcesPath = resourcesPath;
	}

	public String getTargetPath() {
		return targetPath;
	}

	public void setTargetPath(String targetPath) {
		this.targetPath = targetPath;
	}

	public String getStylesheetPath() {
		return stylesheetPath;
	}

	public void setStylesheetPath(String stylesheetPath) {
		this.stylesheetPath = stylesheetPath;
	}

	public static AsciidocConfiguration getConfiguration(IProject project) {
		AsciidocConfiguration configuration = new AsciidocConfiguration();
		if (!updateConfigurationFromMaven(configuration, project)) {
			updateConfigurationFromSettings(configuration, project);
		}
		return configuration;
	}

	private static void updateConfigurationFromSettings(AsciidocConfiguration configuration, IProject project) {
		// TODO Auto-generated method stub
		
	}

	private static boolean updateConfigurationFromMaven(AsciidocConfiguration configuration, IProject project) {
		// Get the asciidoc configuration
		IMavenProjectFacade MavenProjectFacade = MavenPlugin.getMavenProjectRegistry().getProject(project);
		if (MavenProjectFacade == null) {
			return false;
		}

		Plugin asciidocPlugin = null;
		Plugin antCopyPlugin = null;
		if (MavenProjectFacade != null && MavenProjectFacade.getMavenProject() != null) {
			Model model = MavenProjectFacade.getMavenProject().getModel();
			if (model.getBuild() != null) {
				for (Iterator<Plugin> iterator = model.getBuild().getPlugins().iterator(); iterator.hasNext()
						&& (asciidocPlugin == null || antCopyPlugin == null);) {
					Plugin plugin = iterator.next();
					if ("org.asciidoctor".equals(plugin.getGroupId())
							&& "asciidoctor-maven-plugin".equals(plugin.getArtifactId())) {
						asciidocPlugin = plugin;
					}
					if ("org.apache.maven.plugins".equals(plugin.getGroupId())
							&& "maven-antrun-plugin".equals(plugin.getArtifactId())) {
						antCopyPlugin = plugin;<commit_msg>Support for local settings as configuration elements.<commit_after>/**
 * AsciidocTools by Worldline
 *
 * Copyright (C) 2016 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.asciidoctools.builder;

import java.util.Iterator;

import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.osgi.service.prefs.BackingStoreException;

import com.worldline.asciidoctools.builder.internal.Activator;

/**
 * 
 * Asciidoc Project Configuration pojo. Contains information about the
 * source/resources location, where to put generated doc etc...
 * 
 * @author mvanbesien <<EMAIL>>
 * @since 0.1
 *
 */
public class AsciidocConfiguration {

	private String sourcesPath = "src/main/asciidoc";

	private String resourcesPath = "src/main/doc-resources";

	private String targetPath = "target/generated-docs";

	private String stylesheetPath = "css/stylesheet.css";

	private String backend = "html";

	public String getBackend() {
		return backend;
	}

	public void setBackend(String backend) {
		this.backend = backend;
	}

	public String getSourcesPath() {
		return sourcesPath;
	}

	public void setSourcesPath(String sourcesPath) {
		this.sourcesPath = sourcesPath;
	}

	public String getResourcesPath() {
		return resourcesPath;
	}

	public void setResourcesPath(String resourcesPath) {
		this.resourcesPath = resourcesPath;
	}

	public String getTargetPath() {
		return targetPath;
	}

	public void setTargetPath(String targetPath) {
		this.targetPath = targetPath;
	}

	public String getStylesheetPath() {
		return stylesheetPath;
	}

	public void setStylesheetPath(String stylesheetPath) {
		this.stylesheetPath = stylesheetPath;
	}

	public static AsciidocConfiguration getConfiguration(IProject project) {
		AsciidocConfiguration configuration = new AsciidocConfiguration();
		if (!updateConfigurationFromMaven(configuration, project)) {
			if (!updateConfigurationFromSettings(configuration, project)) {
				updateConfigurationFromProperties(configuration, project);
			}
		}
		return configuration;
	}

	private static void updateConfigurationFromProperties(AsciidocConfiguration configuration, IProject project) {
		// TODO Auto-generated method stub

	}

	private static boolean updateConfigurationFromSettings(AsciidocConfiguration configuration, IProject project) {
		final IScopeContext projectScope = new ProjectScope(project);
		IEclipsePreferences preferences = projectScope.getNode(Activator.PLUGIN_ID);
		try {
			if (preferences.keys().length == 0) {
				preferences.put("backend", "html");
				preferences.put("resourcesPath", "src/main/doc-resources");
				preferences.put("sourcesPath", "src/main/asciidoc");
				preferences.put("stylesheetPath", "css/stylesheet.css");
				preferences.put("targetPath", "target/generated-docs");
				preferences.flush();
			}
			configuration.setBackend(preferences.get("backend", "html"));
			configuration.setResourcesPath(preferences.get("resourcesPath", "src/main/doc-resources"));
			configuration.setSourcesPath(preferences.get("sourcesPath", "src/main/asciidoc"));
			configuration.setStylesheetPath(preferences.get("stylesheetPath", "css/stylesheet.css"));
			configuration.setTargetPath(preferences.get("targetPath", "target/generated-docs"));
		} catch (BackingStoreException e) {
			return false;
		}
		return true;
	}

	private static boolean updateConfigurationFromMaven(AsciidocConfiguration configuration, IProject project) {
		// Get the asciidoc configuration
		IMavenProjectFacade MavenProjectFacade = MavenPlugin.getMavenProjectRegistry().getProject(project);
		if (MavenProjectFacade == null) {
			return false;
		}

		Plugin asciidocPlugin = null;
		Plugin antCopyPlugin = null;
		if (MavenProjectFacade != null && MavenProjectFacade.getMavenProject() != null) {
			Model model = MavenProjectFacade.getMavenProject().getModel();
			if (model.getBuild() != null) {
				for (Iterator<Plugin> iterator = model.getBuild().getPlugins().iterator(); iterator.hasNext()
						&& (asciidocPlugin == null || antCopyPlugin == null);) {
					Plugin plugin = iterator.next();
					if ("org.asciidoctor".equals(plugin.getGroupId())
							&& "asciidoctor-maven-plugin".equals(plugin.getArtifactId())) {
						asciidocPlugin = plugin;
					}
					if ("org.apache.maven.plugins".equals(plugin.getGroupId())
							&& "maven-antrun-plugin".equals(plugin.getArtifactId())) {
						antCopyPlugin = plugin;
{'fraction_non_alphanumeric': 0.09892717144625542, 'fraction_numerical': 0.004642046626779452, 'mean_word_length': 4.8019150209455415, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6726442', 'n_tokens_mistral': 2964, 'n_tokens_neox': 2695, 'n_words': 739}