summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pipping <sping@gentoo.org>2015-09-06 04:29:09 +0200
committerSebastian Pipping <sping@gentoo.org>2015-09-06 04:35:17 +0200
commit3a259fd6172aa5714d4a205d191cc48136ebcdfe (patch)
treefb6872cc3974ec2fd77e34111ad0e719a6170647 /apicheck
parentZero (diff)
downloadjava-apicheck-3a259fd6172aa5714d4a205d191cc48136ebcdfe.tar.gz
java-apicheck-3a259fd6172aa5714d4a205d191cc48136ebcdfe.tar.bz2
java-apicheck-3a259fd6172aa5714d4a205d191cc48136ebcdfe.zip
Resurrect apicheck
Diffstat (limited to 'apicheck')
-rw-r--r--apicheck145
1 files changed, 145 insertions, 0 deletions
diff --git a/apicheck b/apicheck
new file mode 100644
index 0000000..fab6795
--- /dev/null
+++ b/apicheck
@@ -0,0 +1,145 @@
+#!/bin/bash
+
+usage() {
+ prog=$(basename "${0}")
+ echo "Usage:"
+ echo "${prog} <ebuild|jar> <ebuild|jar|pkg> <depends>"
+ echo "depends: in the format given to java-config"
+ echo ""
+ echo "For generation 2 ebuilds the depends are taken"
+ echo "automatically from package.env."
+ 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 [[ $# -lt 2 ]]; then
+ usage
+fi
+
+oldarg="${1}"
+newarg="${2}"
+
+depends="${3}"
+
+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 : " ") "${@}" || 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 $?