<commit_before>package com.techdm.aem.vltsync.impl;

import java.io.File;
import java.io.FileFilter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.NotFileFilter;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.framework.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import aQute.bnd.annotation.component.Deactivate;

/**
 * Creates the necessary vlt sync config files and associates a filesystem path
 * to one or more paths in the JCR (similar to 'vlt sync register' command).
 * 
 * @author <NAME>
 *
 */
@Component(policy = ConfigurationPolicy.REQUIRE, configurationFactory = true, metatype = true, immediate = true)
public class InitialRegistrationImpl {

	private static final boolean DEFAULT_OVERWRITE_CONFIG_FILES = false;

	@Property(label = "Filter Roots", description = "JCR paths to be added as roots in the filter file.[Required]", unbounded = PropertyUnbounded.ARRAY)
	protected static final String PROP_FILTER_ROOTS = "filter.roots";

	@Property(label = "Local Path", description = "Filesystem local path to be added as sync root.[Required]")
	protected static final String PROP_LOCAL_PATH = "local.path";

	@Property(label = "Overwrite Config Files", boolValue = false, description = "Overwrite the vlt sync config files"
			+ " if they already exist?[Optional] [Default: " + DEFAULT_OVERWRITE_CONFIG_FILES + "]")
	protected static final String PROP_OVERWRITE_CONFIG_FILES = "overwrite.config.files";

	@Property(value = "Local path: {" + PROP_LOCAL_PATH + "}")
	private static final String PROP_WEBCONSOLE_NAME_HINT = "webconsole.configurationFactory.nameHint";

	/* Logger instance. */
	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Reference
	private ServiceSettingsImpl serviceSettings;

	private String[] filterRoots = null;

	private File localDir = null;

	private Boolean overwriteConfigFiles = null;

	@Activate
	protected void activate(final Map<String, Object> props) throws ServiceException {
		logger.debug("activate(): props = {}", props);

		this.filterRoots = PropertiesUtil.toStringArray(props.get(PROP_FILTER_ROOTS), null);
		if (this.filterRoots == null) {
			throw new ServiceException(PROP_FILTER_ROOTS + " is mandatory!");
		}
		
		final String localDirValue = PropertiesUtil.toString(props.get(PROP_LOCAL_PATH), null);
		if (localDirValue == null) {
			throw new ServiceException(PROP_LOCAL_PATH + " is mandatory!");
		}

		this.localDir = new File(localDirValue);
		this.overwriteConfigFiles = PropertiesUtil.toBoolean(props.get(PROP_OVERWRITE_CONFIG_FILES),
				DEFAULT_OVERWRITE_CONFIG_FILES);

		generateFiles();

		this.serviceSettings.addSyncRoot(this.localDir);
	}

	@Deactivate
	protected void deactivate() {
		if (this.localDir != null) {
			this.serviceSettings.removeSyncRoot(this.localDir);
		}

		this.filterRoots = null;
		this.localDir = null;
		this.overwriteConfigFiles = null;
	}<commit_msg>Added meta info for configMgr<commit_after>package com.techdm.aem.vltsync.impl;

import java.io.File;
import java.io.FileFilter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.NotFileFilter;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.framework.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import aQute.bnd.annotation.component.Deactivate;

/**
 * Creates the necessary vlt sync config files and associates a filesystem path
 * to one or more paths in the JCR (similar to 'vlt sync register' command).
 * 
 * @author <NAME>
 *
 */
@Component(policy = ConfigurationPolicy.REQUIRE, configurationFactory = true, metatype = true, immediate = true, label = "TechDM - "
		+ "VLT Sync Initial Registration", description = "Component for initial registration of sync folders")
public class InitialRegistrationImpl {

	private static final boolean DEFAULT_OVERWRITE_CONFIG_FILES = false;

	@Property(label = "Filter Roots", description = "JCR paths to be added as roots in the filter file.[Required]", unbounded = PropertyUnbounded.ARRAY)
	protected static final String PROP_FILTER_ROOTS = "filter.roots";

	@Property(label = "Local Path", description = "Filesystem local path to be added as sync root.[Required]")
	protected static final String PROP_LOCAL_PATH = "local.path";

	@Property(label = "Overwrite Config Files", boolValue = false, description = "Overwrite the vlt sync config files"
			+ " if they already exist?[Optional] [Default: " + DEFAULT_OVERWRITE_CONFIG_FILES + "]")
	protected static final String PROP_OVERWRITE_CONFIG_FILES = "overwrite.config.files";

	@Property(value = "Local path: {" + PROP_LOCAL_PATH + "}")
	private static final String PROP_WEBCONSOLE_NAME_HINT = "webconsole.configurationFactory.nameHint";

	/* Logger instance. */
	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Reference
	private ServiceSettingsImpl serviceSettings;

	private String[] filterRoots = null;

	private File localDir = null;

	private Boolean overwriteConfigFiles = null;

	@Activate
	protected void activate(final Map<String, Object> props) throws ServiceException {
		logger.debug("activate(): props = {}", props);

		this.filterRoots = PropertiesUtil.toStringArray(props.get(PROP_FILTER_ROOTS), null);
		if (this.filterRoots == null) {
			throw new ServiceException(PROP_FILTER_ROOTS + " is mandatory!");
		}

		final String localDirValue = PropertiesUtil.toString(props.get(PROP_LOCAL_PATH), null);
		if (localDirValue == null) {
			throw new ServiceException(PROP_LOCAL_PATH + " is mandatory!");
		}

		this.localDir = new File(localDirValue);
		this.overwriteConfigFiles = PropertiesUtil.toBoolean(props.get(PROP_OVERWRITE_CONFIG_FILES),
				DEFAULT_OVERWRITE_CONFIG_FILES);

		generateFiles();

		this.serviceSettings.addSyncRoot(this.localDir);
	}

	@Deactivate
	protected void deactivate() {
		if (this.localDir != null) {
			this.serviceSettings.removeSyncRoot(this.localDir);
		}

		this.filterRoots = null;
		this.localDir = null;
		this.overwriteConfigFiles = null;
	}
{'fraction_non_alphanumeric': 0.10478999859530833, 'fraction_numerical': 0.0005618766680713583, 'mean_word_length': 5.502283105022831, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3753601', 'n_tokens_mistral': 2203, 'n_tokens_neox': 2068, 'n_words': 516}