// Path: osgi.enroute.base/src/osgi/enroute/configurer/api/ConfigurationDone.java
// public interface ConfigurationDone {
// 	String	CONFIGURATION_DONE	= "configuration.done";
// }


import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.coordinator.Coordination;
import org.osgi.service.coordinator.Coordinator;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.BundleTracker;
import osgi.enroute.configurer.api.ConfigurationDone;
import osgi.enroute.configurer.api.ProvideConfigurerExtender;
import aQute.lib.collections.ExtList;
import aQute.lib.converter.Converter;
import aQute.lib.converter.TypeReference;
import aQute.lib.io.IO;
import aQute.lib.json.JSONCodec;
import aQute.lib.settings.Settings;
import aQute.libg.sed.ReplacerAdapter;
package osgi.configurer.provider;




/**
 * This component is an extender that reads {@link #CONFIGURATION_LOC} file.
 * These files are JSON formatted, though they do support comments.
 * Additionally, if the enRoute.configurer System property is set, it is also
 * read.
 * <p>
 * This configurer also supports profiles. The default profile is "debug",
 * profiles can be set with the --profile option in the command line (if an
 * appropriate launcher is used), or setting the enRoute.configurer.profile
 * System property is set.
 * <p>
 * Macros are fully supported. The variable order is configuration, system
 * properties, settings in ~/.enRoute/settings.json.
 * <p>
 * The configurer can also refer to binary resources with @{resource-path}. This
 * pattern requires a resource path inside the bundle. This resource is copied
 * to the local file system and the macro is replaced with the corresponding
 * path.
 * <p>
 * The configurer reads
 */
@ProvideConfigurerExtender
@Component(service = {
		ConfigurationDone.class, Object.class
}, immediate = true)
public class Configurer implements ConfigurationDone {
	private static final String		LOGICAL_PID_KEY		= "._osgi.enroute.pid";
	private static final String		BUNDLE_KEY			= "._osgi.enroute.bundle";
	private static final String		EN_ROUTE_PROFILE	= "enRoute.profile";
	private static final String		CONFIGURER_EXTRA	= "enRoute.configurer.extra";
	private static final String		CONFIGURATION_LOC	= "configuration/configuration.json";

	public static final JSONCodec	codec				= new JSONCodec();
	public static final Converter	converter			= new Converter();
	static Pattern					PROFILE_PATTERN		= Pattern.compile("\\[([a-zA-Z0-9]+)\\](.*)");
	Settings						settings			= new Settings("~/.enRoute/settings.json");
	LogService						log;
	BundleTracker< ? >				tracker;
	ConfigurationAdmin				cm;
	String							profile;
	File							dir;
	Map<String,String>				base;
	Bundle							currentBundle;
	private Coordinator				coordinator;

	/*
	 * Track all bundles and read their configuration.
	 */
// Path: osgi.enroute.base/src/osgi/enroute/configurer/api/ConfigurationDone.java
// public interface ConfigurationDone {
// 	String	CONFIGURATION_DONE	= "configuration.done";
// }


// Path: osgi.configurer.provider/src/osgi/configurer/provider/Configurer.java
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.coordinator.Coordination;
import org.osgi.service.coordinator.Coordinator;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.BundleTracker;
import osgi.enroute.configurer.api.ConfigurationDone;
import osgi.enroute.configurer.api.ProvideConfigurerExtender;
import aQute.lib.collections.ExtList;
import aQute.lib.converter.Converter;
import aQute.lib.converter.TypeReference;
import aQute.lib.io.IO;
import aQute.lib.json.JSONCodec;
import aQute.lib.settings.Settings;
import aQute.libg.sed.ReplacerAdapter;

package osgi.configurer.provider;




/**
 * This component is an extender that reads {@link #CONFIGURATION_LOC} file.
 * These files are JSON formatted, though they do support comments.
 * Additionally, if the enRoute.configurer System property is set, it is also
 * read.
 * <p>
 * This configurer also supports profiles. The default profile is "debug",
 * profiles can be set with the --profile option in the command line (if an
 * appropriate launcher is used), or setting the enRoute.configurer.profile
 * System property is set.
 * <p>
 * Macros are fully supported. The variable order is configuration, system
 * properties, settings in ~/.enRoute/settings.json.
 * <p>
 * The configurer can also refer to binary resources with @{resource-path}. This
 * pattern requires a resource path inside the bundle. This resource is copied
 * to the local file system and the macro is replaced with the corresponding
 * path.
 * <p>
 * The configurer reads
 */
@ProvideConfigurerExtender
@Component(service = {
		ConfigurationDone.class, Object.class
}, immediate = true)
public class Configurer implements ConfigurationDone {
	private static final String		LOGICAL_PID_KEY		= "._osgi.enroute.pid";
	private static final String		BUNDLE_KEY			= "._osgi.enroute.bundle";
	private static final String		EN_ROUTE_PROFILE	= "enRoute.profile";
	private static final String		CONFIGURER_EXTRA	= "enRoute.configurer.extra";
	private static final String		CONFIGURATION_LOC	= "configuration/configuration.json";

	public static final JSONCodec	codec				= new JSONCodec();
	public static final Converter	converter			= new Converter();
	static Pattern					PROFILE_PATTERN		= Pattern.compile("\\[([a-zA-Z0-9]+)\\](.*)");
	Settings						settings			= new Settings("~/.enRoute/settings.json");
	LogService						log;
	BundleTracker< ? >				tracker;
	ConfigurationAdmin				cm;
	String							profile;
	File							dir;
	Map<String,String>				base;
	Bundle							currentBundle;
	private Coordinator				coordinator;

	/*
	 * Track all bundles and read their configuration.
	 */
	@Activate