_version = $1
_versionFormatted = ($_version replaceAll '-' '.')

if { NOT { "noHeader" equals $2 } } {

	# print header
	# ID:20 Version:20 Type:12 Status:20 Repository:
	echo "         ID         \|      Version       \|    Type    \|       Status       \|     Repository     "
	echo " -------------------------------------------------------------------------------------------------- "

}


__printLine = {

	# $1 - list of data	
	# $2 - list of lengths	
	# $3 - list of prefixes	

	_result = ""
	i = 0
	_lengths = $2
	_prefixes = $3

#	echo "__printLine"
#	echo (${i} getClass)

	t = ($_lengths get ${i})
#	echo $t

	each $1 {
		_length = ($_lengths get ${i})
		_prefix = ($_prefixes get $i)
		_value = ((($.context bundle) loadClass java.lang.String) format "\%-${_length}s" "${_prefix}${it}" )

#		echo $_value

		if { NOT { $_result equals ''} } {
			_result = "${_result}\|"
		}		
		_result = "${_result}${_value}"
#		echo (${i} getClass)
		%(i+=1)
#		echo (${i} getClass)
	}

#	_id = ((($.context bundle) loadClass java.lang.String) format "\%-20s" $2 ) 
#	_version = ((($.context bundle) loadClass java.lang.String) format "\%-20s" $3 ) 
#	_status = ((($.context bundle) loadClass java.lang.String) format "\%-16s" $4 ) 
#	_repo = ((($.context bundle) loadClass java.lang.String) format "\%-20s" $5 ) 

#	echo "${_id}\|${_version}\|${_status}\|${_repo}"
	echo $_result
}

_pid = "entaxy.update.$_versionFormatted"
_configExists = config:exists $_pid

if { $_configExists } {

	featuresService = (service:get org.apache.karaf.features.FeaturesService)
	configService = (service:get org.osgi.service.cm.ConfigurationAdmin)
	configuration = ($configService getConfiguration $_pid)
	properties = ($configuration getProperties)

	_configFeature = ($featuresService getFeature "entaxy-update-configuration" $_version)

	_values = [($properties get 'update.id') ($properties get "update.version") ($properties get "update.type") ($properties get "update.status") ($properties get "update.repo")]
	_lengths = [20 20 12 20 10]
	_prefixes = [' ' ' ' ' ' ' ' ' '] 

	__printLine $_values $_lengths $_prefixes 

	_components = ( config:property-get -p $_pid "components") toString
	_componentsList = $_components split ","	

	_prefixes = ['  - ' ' * ' ' ' ' ' ' '] 	

	each $_componentsList {
		_component = (${it}) trim
		_values = [($properties get "${_component}.feature") ($properties get "${_component}.current.version") "" ($properties get "${_component}.status") ($properties get "${_component}.update.repo")]
		__printLine $_values $_lengths $_prefixes 
	}
}