Parse the external package declaration, as declared in package.ini

Return a map of ExternalPackage organized by the short package name, as used in imports from Nit code.

Property definitions

nitc :: nitpm_shared $ Text :: parse_import
	# Parse the external package declaration, as declared in package.ini
	#
	# Return a map of `ExternalPackage` organized by the short package name,
	# as used in imports from Nit code.
	fun parse_import: Map[String, ExternalPackage]
	do
		var res = new Map[String, ExternalPackage]
		var ids = self.split(",")
		for id in ids do
			id = id.chomp
			if id.is_empty then continue

			# Check version suffix (e.g. gamnit=1.0)
			var match = id.search_last("=")
			var package_name
			var version = null
			if match != null then
				# There's a version suffix
				package_name = id.substring(0, match.from)
				version = id.substring_from(match.after)
				id = package_name
			else
				package_name = id
			end

			# Extract a package name from a Git address
			if not package_name.is_package_name then
				# Assume it's a Git repository
				var git_name = package_name.git_name
				if git_name == null then
					# Invalid name
					# TODO report error only when used by the parser
					continue
				end
				package_name = git_name
			end

			res[package_name] = new ExternalPackage(id, package_name, version)
		end
		return res
	end
src/nitpm_shared.nit:76,2--116,4