<commit_before>/**
 * Copyright (c) 2011, 2014 Eurotech and/or its affiliates
 *
 *  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:
 *   Eurotech
 */
package org.eclipse.kura.core.configuration;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.kura.configuration.metatype.OCD;
import org.eclipse.kura.core.configuration.util.CollectionsUtil;
import org.eclipse.kura.core.configuration.util.ComponentUtil;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.util.tracker.BundleTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * BundleTracker to track all the Service which have defaults in MetaType.
 * When the ConfigurableComponet is found it is then registered to the ConfigurationService.
 */
public class ComponentMetaTypeBundleTracker extends BundleTracker<Bundle>
{
	private static final Logger s_logger = LoggerFactory.getLogger(ComponentMetaTypeBundleTracker.class);

	private BundleContext m_context;
	private ConfigurationAdmin m_configurationAdmin;
	private ConfigurationServiceImpl m_configurationService;

	public ComponentMetaTypeBundleTracker(BundleContext context,
										  ConfigurationAdmin configurationAdmin,
										  ConfigurationServiceImpl configurationService) 
		throws InvalidSyntaxException 
	{
		super(context, Bundle.ACTIVE, null);		
		m_context = context;
		m_configurationAdmin = configurationAdmin;
		m_configurationService = configurationService;
	}


	// ----------------------------------------------------------------
	//
	//   Override APIs
	//
	// ----------------------------------------------------------------

	@Override
	public void open() 
	{
		s_logger.info("Opening ComponentMetaTypeBundleTracker...");
		super.open();
				
		Bundle[] bundles = m_context.getBundles();
		if (bundles != null) {
			for (Bundle bundle : bundles) {
				processBundleMetaType(bundle);	
			}
		}
	};
	
	@Override
	public Bundle addingBundle(Bundle bundle, BundleEvent event) 
	{
		Bundle bnd = super.addingBundle(bundle, event);
		processBundleMetaType(bundle);
		return bnd;
	}


	// ----------------------------------------------------------------
	//
	//   Private APIs
	//
	// ----------------------------------------------------------------
	
	private void processBundleMetaType(Bundle bundle) 
	{<commit_msg>don't invoke the processBundleMetaType() twice (from the open() and addingBundle() methods)<commit_after>/**
 * Copyright (c) 2011, 2014 Eurotech and/or its affiliates
 *
 *  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:
 *   Eurotech
 */
package org.eclipse.kura.core.configuration;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.kura.configuration.metatype.OCD;
import org.eclipse.kura.core.configuration.util.CollectionsUtil;
import org.eclipse.kura.core.configuration.util.ComponentUtil;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.util.tracker.BundleTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * BundleTracker to track all the Service which have defaults in MetaType.
 * When the ConfigurableComponet is found it is then registered to the ConfigurationService.
 */
public class ComponentMetaTypeBundleTracker extends BundleTracker<Bundle>
{
	private static final Logger s_logger = LoggerFactory.getLogger(ComponentMetaTypeBundleTracker.class);

	private BundleContext m_context;
	private ConfigurationAdmin m_configurationAdmin;
	private ConfigurationServiceImpl m_configurationService;

	public ComponentMetaTypeBundleTracker(BundleContext context,
										  ConfigurationAdmin configurationAdmin,
										  ConfigurationServiceImpl configurationService) 
		throws InvalidSyntaxException 
	{
		super(context, Bundle.ACTIVE, null);		
		m_context = context;
		m_configurationAdmin = configurationAdmin;
		m_configurationService = configurationService;
	}


	// ----------------------------------------------------------------
	//
	//   Override APIs
	//
	// ----------------------------------------------------------------

	@Override
	public void open() 
	{
		s_logger.info("Opening ComponentMetaTypeBundleTracker...");
		super.open();
		/*	<IAB> commented out	
		Bundle[] bundles = m_context.getBundles();
		if (bundles != null) {
			for (Bundle bundle : bundles) {
				processBundleMetaType(bundle);	
			}
		}
		*/
	};
	
	@Override
	public Bundle addingBundle(Bundle bundle, BundleEvent event) 
	{
		Bundle bnd = super.addingBundle(bundle, event);
		processBundleMetaType(bundle);
		return bnd;
	}


	// ----------------------------------------------------------------
	//
	//   Private APIs
	//
	// ----------------------------------------------------------------
	
	private void processBundleMetaType(Bundle bundle) 
	{
{'fraction_non_alphanumeric': 0.17423423423423423, 'fraction_numerical': 0.005045045045045045, 'mean_word_length': 2.849514563106796, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '3757492', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1424, 'n_words': 357}