<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~~~~~~licensing~~~~~~
  core
  ==========
  Copyright (C) 2020 - 2021 EmDev LLC
  ==========
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
       http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  ~~~~~~/licensing~~~~~~
  -->


<features name="entaxy-platform-core-${project.version}"
          xmlns="http://karaf.apache.org/xmlns/features/v1.3.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.3.0 http://karaf.apache.org/xmlns/features/v1.3.0">

    <repository>mvn:ru.entaxy.esb.platform.runtime/base/${project.version}/xml/features</repository>
	<repository>mvn:ru.entaxy.esb.underlying/entaxy-underlying-features/${project.version}/xml/features</repository>

	<!-- legacy repo -->
	<repository>mvn:ru.entaxy.esb.system/system-parent/${project.version}/xml/features</repository>

	<feature name="entaxy-platform-core" version="${project.version}">
		<feature version="${project.version}" prerequisite="true">entaxy-platform-base</feature>
		<feature version="${project.version}">entaxy-platform-core-hc</feature>
		<feature version="${project.version}">entaxy-init-manager</feature>
		<feature version="${project.version}">entaxy-cluster</feature>
		<feature version="${project.version}">entaxy-artifact-management</feature>
		<feature version="${project.version}">entaxy-object-producing</feature>
		<feature version="${project.version}">entaxy-object-implementation</feature>
		<feature version="${project.version}">entaxy-initializers</feature>
		<feature version="${project.version}">entaxy-management</feature>
		<feature version="${project.version}">entaxy-cluster-management</feature>
		<feature version="${project.version}">entaxy-schema</feature>
		<feature version="${project.version}">entaxy-management-adapters</feature>
	</feature>

	<feature name="entaxy-platform-core-hc" version="${project.version}">
		<configfile finalname="${karaf.etc}/org.apache.felix.hc.generalchecks.HttpRequestsCheck-repositories.cfg" override="true">
			mvn:ru.entaxy.esb.platform.runtime/core/${project.version}/cfg/org.apache.felix.hc.generalchecks.HttpRequestsCheck-repositories
		</configfile> 
		<configfile finalname="${karaf.etc}/org.apache.felix.hc.generalchecks.ServicesCheck-connections.cfg" override="true">
			mvn:ru.entaxy.esb.platform.runtime/core/${project.version}/cfg/org.apache.felix.hc.generalchecks.ServicesCheck-connections
		</configfile> 
	</feature>

	<feature name="entaxy-cluster" version="${project.version}">
		<feature prerequisite="true">cellar</feature>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.cluster/cluster-persistence-service/${project.version}</bundle>
	</feature>

	<feature name="entaxy-artifact-management" version="${project.version}">
		<feature version="${project.version}" prerequisite="true">entaxy-init-manager</feature>
        <configfile finalname="${karaf.etc}/ru.entaxy.esb.artifact.repositories.cfg" override="false">
            mvn:ru.entaxy.esb.platform.runtime.core/artifact-management/${project.version}/cfg/ru.entaxy.esb.artifact.repositories
        </configfile>
        <bundle>mvn:ru.entaxy.esb.platform.runtime.core/artifact-management/${project.version}</bundle>
	</feature>

	<feature name="entaxy-object-producing" version="${project.version}">
		<feature version="${project.version}" prerequisite="true">objects-base</feature>
		<feature version="${project.version}" prerequisite="true">entaxy-artifact-management</feature>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.object-producing/object-producer-api/${project.version}</bundle>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.object-producing/object-producer-core/${project.version}</bundle>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.object-producing/object-producing-shell/${project.version}</bundle>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.object-producing/object-producing-management/${project.version}</bundle>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.object-producing/object-producing-config-support/${project.version}</bundle>
	</feature>

	<feature name="entaxy-object-implementation" version="${project.version}">
		<feature version="${project.version}" prerequisite="true">objects-base</feature>
		<feature version="${project.version}" prerequisite="true">entaxy-artifact-management</feature>
		<feature version="${project.version}" prerequisite="true">entaxy-object-producing</feature>
		<feature version="${project.version}">entaxy-legacy-system-api</feature>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.objects-implementations.profile-implementation/profile-producing/${project.version}</bundle>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.objects-implementations.profile-implementation/profile-storage/${project.version}</bundle>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.objects-implementations.connection-implementation/connection-producing/${project.version}</bundle>
	</feature>

    <feature name="entaxy-initializers" version="${project.version}">
        <feature version="${project.version}">entaxy-datasources-initializer</feature>
        <feature version="${project.version}">entaxy-core-initializer</feature>
        <feature version="${project.version}">entaxy-connection-initializer</feature>
        <feature version="${project.version}">entaxy-storage-initializer</feature>
    </feature>

	<feature name="entaxy-init-manager" version="${project.version}">
        <bundle>mvn:ru.entaxy.esb.platform.runtime.core.initializer/init-manager/${project.version}</bundle>
	</feature>

	<feature name="entaxy-datasources-initializer" version="${project.version}">
		<feature prerequisite="true">entaxy-init-manager</feature>

		<!-- datasources config templates for PostgreSQL -->
        <configfile finalname="${karaf.etc}/org.ops4j.datasource-entaxy.esb.cache.cfg.pg" override="false">
            mvn:ru.entaxy.esb.platform.runtime.core.initializer/datasources-initializer/${project.version}/cfg.pg/datasource-cache
        </configfile>
        <configfile finalname="${karaf.etc}/org.ops4j.datasource-entaxy.esb.storage.cfg.pg" override="false">
            mvn:ru.entaxy.esb.platform.runtime.core.initializer/datasources-initializer/${project.version}/cfg.pg/datasource-storage
        </configfile>

		<!-- datasources config templates for H2 -->
        <configfile finalname="${karaf.etc}/org.ops4j.datasource-entaxy.esb.cache.cfg.h2" override="false">
            mvn:ru.entaxy.esb.platform.runtime.core.initializer/datasources-initializer/${project.version}/cfg.h2/datasource-cache
        </configfile>
        <configfile finalname="${karaf.etc}/org.ops4j.datasource-entaxy.esb.storage.cfg.h2" override="false">
            mvn:ru.entaxy.esb.platform.runtime.core.initializer/datasources-initializer/${project.version}/cfg.h2/datasource-storage
        </configfile>

		<!-- use H2 by default -->
        <configfile finalname="${karaf.etc}/org.ops4j.datasource-entaxy.esb.cache.cfg" override="false">
            mvn:ru.entaxy.esb.platform.runtime.core.initializer/datasources-initializer/${project.version}/cfg.h2/datasource-cache
        </configfile>
        <configfile finalname="${karaf.etc}/org.ops4j.datasource-entaxy.esb.storage.cfg" override="false">
            mvn:ru.entaxy.esb.platform.runtime.core.initializer/datasources-initializer/${project.version}/cfg.h2/datasource-storage
        </configfile>
        
        <capability>
            osgi.service;effective:=active;objectClass=javax.sql.DataSource;osgi.jndi.service.name=entaxy.esb.cache;
        </capability>
        <capability>
            osgi.service;effective:=active;objectClass=javax.sql.DataSource;osgi.jndi.service.name=entaxy.esb.storage;
        </capability>
        
        <!-- why do we need the following? -->
        <!-- 
        
        <capability>
            osgi.service;objectClass=javax.sql.DataSource;osgi.jndi.service.name=entaxy.esb.cache-connector;
        </capability>
        
        
         -->
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.initializer/datasources-initializer/${project.version}</bundle>
    </feature>
    
	<feature name="entaxy-core-initializer" version="${project.version}" >
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.initializer/core-initializer/${project.version}</bundle>
    </feature>

	<feature name="entaxy-connection-initializer" version="${project.version}">
		<configfile finalname="${karaf.etc}/init/entaxy-platform-connections.json" override="false">
			mvn:ru.entaxy.esb.platform.runtime.core.initializer/connection-initializer/${project.version}/json/init-config
		</configfile>
		<configfile finalname="${karaf.etc}/init/file-connections.json" override="false">
			mvn:ru.entaxy.esb.platform.runtime.core.initializer/connection-initializer/${project.version}/json/init-config-files
		</configfile>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.initializer/connection-initializer/${project.version}</bundle>
    </feature>

	<feature name="entaxy-storage-initializer" version="${project.version}">
		<feature prerequisite="true">entaxy-karaf-liquibase-support</feature>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.initializer.storage.initializer/liquibase-updater/${project.version}</bundle>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.initializer.storage.initializer/storage-esb_entaxy/${project.version}</bundle>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.initializer.storage.initializer/storage-cache/${project.version}</bundle>
    </feature>
	
	<feature name="entaxy-blueprint-generator" version="${project.version}">
        <bundle>mvn:ru.entaxy.esb.platform.runtime.core.management/blueprint-generator-service/${project.version}</bundle>
	</feature>
	
    <feature name="entaxy-management" version="${project.version}">
    	<feature version="${project.version}">entaxy-blueprint-generator</feature>
        <bundle>mvn:ru.entaxy.esb.platform.runtime.core.management/connection-manager/${project.version}</bundle>
        <bundle>mvn:ru.entaxy.esb.platform.runtime.core.management/connection-management/${project.version}</bundle>
        <bundle>mvn:ru.entaxy.esb.platform.runtime.core.management/profile-management/${project.version}</bundle>
        <bundle>mvn:ru.entaxy.esb.platform.runtime.core.management/node-management/${project.version}</bundle>
        
        <!-- 
        	We need the following to avoid exception
        		[
					Unable to resolve root: missing requirement [root] 
					osgi.identity; osgi.identity=entaxy-platform-core; type=karaf.feature; version="[1.8.2.SNAPSHOT,1.8.2.SNAPSHOT]"; filter:="(&(osgi.identity=entaxy-platform-core)(type=karaf.feature)(version>=1.8.2.SNAPSHOT)(version<=1.8.2.SNAPSHOT))" 
					[caused by: Unable to resolve entaxy-platform-core/1.8.2.SNAPSHOT: missing requirement [entaxy-platform-core/1.8.2.SNAPSHOT] osgi.identity; osgi.identity=entaxy-cluster-management; type=karaf.feature; version="[1.8.2.SNAPSHOT,1.8.2.SNAPSHOT]" 
					[caused by: Unable to resolve entaxy-cluster-management/1.8.2.SNAPSHOT: missing requirement [entaxy-cluster-management/1.8.2.SNAPSHOT] osgi.identity; osgi.identity=ru.entaxy.esb.platform.runtime.core.management.cluster-node-management; type=osgi.bundle; version="[1.8.2.SNAPSHOT,1.8.2.SNAPSHOT]"; resolution:=mandatory 
					[caused by: Unable to resolve ru.entaxy.esb.platform.runtime.core.management.cluster-node-management/1.8.2.SNAPSHOT: 
						missing requirement 
							[ru.entaxy.esb.platform.runtime.core.management.cluster-node-management/1.8.2.SNAPSHOT] 
							osgi.service; effective:=active;filter:="(objectClass=ru.entaxy.esb.platform.core.management.node.LocalNodeMBean)"]]]        		
        		]
        	while installing "entaxy-cluster-management" feature
        -->
        <!-- 
        	@TODO find out why we get exception on feature:install
        	while bundle:install works fine
         --> 
        <capability>
        	osgi.service; effective:=active;objectClass=ru.entaxy.esb.platform.core.management.node.LocalNodeMBean
        </capability>
    </feature>

	<feature name="entaxy-cluster-management" version="${project.version}">
		<feature prerequisite="true">cellar</feature>
		<feature prerequisite="true" version="${project.version}">entaxy-management</feature>
		<bundle>mvn:ru.entaxy.esb.platform.runtime.core.management/cluster-node-management/${project.version}</bundle>
	</feature>

	<feature name="entaxy-management-adapters" version="${project.version}">
		<feature version="${project.version}" prerequisite="true">entaxy-platform-base</feature>
		<feature prerequisite="true">entaxy-artifact-management</feature>
    	<feature prerequisite="true">entaxy-legacy-system-api</feature>
    	<feature prerequisite="true">entaxy-legacy-connectors</feature>
    	<feature prerequisite="true">entaxy-legacy-profile-commons</feature>
    	<feature prerequisite="true">entaxy-legacy-management-connectors</feature>
    	<feature prerequisite="true">entaxy-legacy-management</feature>
    	<feature prerequisite="true">entaxy-management</feature>
        <bundle>mvn:ru.entaxy.esb.platform.runtime.core.management/profile-management-service-adapters/${project.version}</bundle>
	</feature>

    <feature name="entaxy-schema" version="${project.version}">
        <feature version="${project.version}" prerequisite="true">entaxy-datasources-initializer</feature>
        <feature prerequisite="true">entaxy-legacy-basic-auth</feature>
        <!-- system-entaxy-db -->

        <configfile finalname="${karaf.etc}/ru.entaxy.esb.platform.runtime.core.infrastructure.schema.cfg" override="false">
            mvn:ru.entaxy.esb.platform.runtime.core.infrastructure.schema/schema-soap/${project.version}/cfg/ru.entaxy.esb.platform.runtime.core.infrastructure.schema
        </configfile>

        <bundle>mvn:ru.entaxy.esb.platform.runtime.core.infrastructure.schema/schema-api/${project.version}</bundle>
        <bundle>mvn:ru.entaxy.esb.platform.runtime.core.infrastructure.schema/schema-impl/${project.version}</bundle>
        <bundle>mvn:ru.entaxy.esb.platform.runtime.core.infrastructure.schema/schema-soap/${project.version}</bundle>
        <bundle>mvn:ru.entaxy.esb.platform.runtime.core.infrastructure.schema/schema-component/${project.version}</bundle>
        <capability>
            osgi.service;objectClass=org.hibernate.SessionFactory;effective:=active;
        </capability>
    </feature>

</features>