summaryrefslogtreecommitdiff
path: root/src/create-extension
blob: dcf27fd2a866615a9f66ad3bc138f1acbaee81d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash

function show_extension_points () {
	echo "Valid extension points are:"
	echo
	for point in $V_EX_POINTS; do
		echo "   ${point}"
	done
	echo
}

function find_extension_points () {
	for file in $(find -iname '*addin.xml'); do
		points=$(grep '<ExtensionPoint' $file | \
			awk 'BEGIN { FS="=" } { print $2 }' | \
			sed 's,[>"],,g')

		id=$(awk 'BEGIN { FS="id=\"" } { print $2 }' < $file | \
			awk 'BEGIN { FS="\" " } { print $1 }')
		
		[[ -z $points || -z $id ]] && continue

		for point in $points; do
			V_EX_POINTS="${V_EX_POINTS} ${point}"
			V_EX_POINTS_IDS="${V_EX_POINTS_IDS} ${point},${id}"
		done
	done
}

function usage () {
	echo "Usage: $0 <name> <path> [<extension-point> ...]"
	echo
	echo "Example: ./create-extension Banshee.InternetRadio Extensions/"
	echo
	show_extension_points
	exit 1
}

find_extension_points

EX_NAME=$1; test -z $EX_NAME && usage || shift
EX_PATH="Extensions"

case "$1" in
	\/*) ;;
	*) test -z $1 || EX_PATH="$1"; shift ;;
esac

if test ! -d "${EX_PATH}"; then
	echo "Extension root path \`${EX_PATH}' does not exist."
	exit 1
fi

EX_PATH="${EX_PATH}/${EX_NAME}"
TEMPLATE_PATH="Extensions/Template"

if test ! -d $TEMPLATE_PATH; then
	echo "Extension template path \`${TEMPLATE_PATH}' does not exist."
	echo "This script must be run from the src/ directory of a Banshee checkout"
	exit 1
fi

if test -d "${EX_PATH}"; then
	echo "Extension \`${EX_PATH}' already exists."
	exit 1
fi

for point in $@; do
	found=0
	for v_point in $V_EX_POINTS; do
		if [ "x$point" = "x$v_point" ]; then
			found=1
			break
		fi
	done
	if [ $found -eq 0 ]; then
		echo "Extension point \`${point}' is not valid."
		echo
		show_extension_points
		exit 1
	fi
done

echo "Creating Extension ($EX_PATH)..."

for point in $@; do
	for v_point in $V_EX_POINTS_IDS; do
		if [ "$point" = "${v_point%,*}" ]; then
			dependency="${v_point##*,}"
			dep_found=0
			for dep_added in $deps_added; do
				if test "x${dependency}" = "x${dep_added}"; then
					dep_found=1
					break
				fi
			done

			if [ $dep_found -eq 0 ]; then
				deps_added="${deps_added} ${dependency}"
				EX_DEPS="${EX_DEPS}    <Addin id=\"${dependency}\" version=\"1.0\"/>^"
			fi

			name="${point##*/}"
			EX_NODES="${EX_NODES}  <Extension path=\"${point}\">^    <${name} class=\"\"/>^  </Extension>^^"

			echo "  Added extension node \`${name}' at path \`${point}'"
		fi
	done
done

EX_DEPS="  <Dependencies>^${EX_DEPS}^  </Dependencies>"

mkdir -p "${EX_PATH}/${EX_NAME}"
cp ${TEMPLATE_PATH}/Template.mdp "${EX_PATH}/${EX_NAME}.mdp"
cp ${TEMPLATE_PATH}/Template.addin.xml "${EX_PATH}/${EX_NAME}.addin.xml"
cp ${TEMPLATE_PATH}/Makefile.am "${EX_PATH}"

pushd "${EX_PATH}" &>/dev/null

for file in *; do
	sed -e "s/\@EXTENSION_NAME\@/${EX_NAME}/g" < $file > $file.tmp &&
		mv $file.tmp $file
	sed -e "s,\@EXTENSION_DEPS\@,${EX_DEPS},g" < $file | 
		sed -r 's,[\^]+,\^,g' | tr ^ '\n' > $file.tmp &&
		mv $file.tmp $file
	sed -e "s,\@EXTENSION_NODES\@,${EX_NODES},g" < $file | 
		tr ^ '\n' > $file.tmp &&
		mv $file.tmp $file
done

popd &>/dev/null

echo "Done."
echo "You will need to fix the generated Makefile.am, .addins.xml file, "
echo "and add an entry to ../configure.ac, then run autogen.sh again."