summaryrefslogtreecommitdiff
blob: 447e09b6a3387b20ab90a502ffb50d387442ebec (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
137
138
139
140
141
142
#!/bin/bash
# Copyright (C) 2006 Petteri Räty <betelgeuse@gentoo.org>
# Copyright (C) 2006 Miroslav Šulc <fordfrog@gentoo.org>
# Licensed under GPL v2 or later

usage() {
	prog=$(basename "${0}")
	echo "Usage:"
	echo "  ${prog} (ebuild|jar) (ebuild|jar|pkg)"
	echo ""
	echo "For example:"
	echo "  apicheck foobar-1.0.ebuild foobar-1.1.ebuild"
	echo "  apicheck foobar-1.0.ebuild foobar.1.0.jar"
	echo "  apicheck bundledjar.jar gentoopackage"
	exit 1
}

debug() {
	if [[ "${DEBUG}" ]]; then
		return 0
	else
		return 1
	fi
}

if [[ $# -ne 2 ]]; then
	usage
fi

oldarg="${1}"
newarg="${2}"

if [[ -d /usr/share/${newarg} ]]; then
	pkg=true
fi

if ! [[ -e "${oldarg}" && ( -e "${newarg}" || ${pkg} ) ]]; then
	usage
fi

TMP_DIR="$(mktemp -d /tmp/$(basename ${0})-XXXXXX || exit 1)"
old="${TMP_DIR}/old.japi.gz"
new="${TMP_DIR}/new.japi.gz"
touch $old

end() {
	rm -v ${TMP_DIR}/*.japi.gz
	rmdir -v ${TMP_DIR}
	exit ${1}
}

getpkgtemp() {
	echo "${portagetmp}/$(sed -e "s%.*[/]%%" <<< sed -e "s/\.ebuild$//" <<< ${1})/"
}

getjars() {
	find "${1}/image" -name '*.jar' || end 1
}

generate_japi() {
	file=${1}
	shift
	debug && echo japize as ${file} packages $(java-config -r | tr : " ") "${@}"
	japize as ${file} packages $(java-config -r | tr : " " | xargs ls -1 2>/dev/null) "${@}" || end 1
}

listpackages() {
	packages=""
	for file in "${@}"; do
		newpackages=`jar tf ${file} | grep .class | sed -e "s%[/][^/]*\.class$%%g" | sed -e "s%/%.%g" | sort | uniq | sed -e "s/^/\+/"`
		if [[ ! -z "${newpackages}" ]]; then
			if [[ -z "${packages}" ]]; then
				packages=${newpackages}
			else
				packages="${packages} ${newpackages}"
			fi
		fi
	done
	packages=`echo ${packages} | sort | uniq`
	sed -e "s/\n/ /g" <<< ${packages}
}

getdepjars() {
	env=$(find ${1} -name "package.env")
	grep 'GENERATION=1' ${env} > /dev/null || source ${env}

	if [[ "${GENERATION}" = "2" && "${DEPEND}" ]]; then
		# parsing DEPEND for java-config -p call
		# after that removing colons
		java-config --classpath=$(echo ${DEPEND} \
			| sed -e 's/:/,/g' -e 's/^[^@]*@//' -re 's/(,)[^@]*@/\1/g') | \
		sed -e "s/:/ /g"
	fi
}

if [[ ${oldarg} = *ebuild ]]; then
	oldebuild=${oldarg}
	category=$(basename $(dirname $(dirname $(readlink -f ${oldebuild}))))
	portagetmp="$(portageq envvar PORTAGE_TMPDIR || end 1)/portage/${category}/"

	ebuild "${oldebuild}" install || end 1

	pkgtmp="$(getpkgtemp ${oldebuild})"
	[[ "${DEBUG}" ]] && echo ${pkgtmp}

	oldjars="$(getjars ${pkgtmp})"
else
	oldjars="${oldarg}"
fi

tocheck="$(listpackages ${oldjars})"

if [[ ${oldebuild} ]]; then
	debug && getdepjars "${pkgtmp}/image"
	generate_japi "${old}" ${oldjars} $(getdepjars "${pkgtmp}/image") ${tocheck}
elif [[ ${pkg} ]]; then
	generate_japi "${old}" ${oldjars} $(getdepjars "/usr/share/${newarg}") ${tocheck}
else
	generate_japi "${old}" ${oldjars} ${tocheck}
fi

if [[ ${newarg} = *ebuild ]]; then
	newebuild="${newarg}"
	ebuild "${newebuild}" install || end 1
	pkgtmp="$(getpkgtemp ${newebuild})"
	newjars="$(getjars ${pkgtmp})"
	debug && echo $pkgtmp
elif [[ ${pkg} ]]; then
	newjars=$(java-config -dp ${newarg} | tr : " ")
else
	newjars="${newarg}"
fi

if [[ ${newebuild} ]]; then
	generate_japi ${new} ${newjars} $(getdepjars "${pkgtmp}/image") ${tocheck}
else
	generate_japi ${new} ${newjars} ${tocheck}
fi

japicompat ${old} ${new}

end $?