6c088e
From be3d32fe7a2b59f682e27022931a27fa552d052d Mon Sep 17 00:00:00 2001
6c088e
From: Jakub Filak <jfilak@redhat.com>
6c088e
Date: Tue, 17 Jun 2014 14:51:08 +0200
6c088e
Subject: [PATCH] Add abrt-java-connector bits
6c088e
6c088e
Honor JAVACMD_OPTS with a path to the abrt connector agent when:
6c088e
  1. JAVA_ABRT environment variable does not hold 'off'
6c088e
  2. the connector's library exists
6c088e
  3. abrtd is running
6c088e
6c088e
We have to use JAVACMD_OTPS variable instead of FLAGS and OPTIONS
6c088e
because applications (i.e. ant) migth use the following workflow:
6c088e
  . /usr/share/java-utils/java-functions
6c088e
  set_javacmd
6c088e
  $JAVACMD MyClass
6c088e
6c088e
FLAGS and OPTIONS variables are used only from run() function.
6c088e
6c088e
Use architecture-independent location of abrt-java-connector
6c088e
6c088e
The connector's library has been moved to architecture-independent
6c088e
directory /usr/lib/abrt-java-connector/, because Java does not
6c088e
officially support multilib and having the connector installed the arch
6c088e
specific directory was causing us problems if Java package doesn't match
6c088e
host architecture (e.g. Java i386 on host x86_64).
6c088e
6c088e
Signed-off-by: Jakub Filak <jfilak@redhat.com>
6c088e
6c088e
Use wrapper script to inject extra JVM arguments (rhbz#1153652)
6c088e
6c088e
Add JAVA_ABRT=off to java.conf template
6c088e
6c088e
Log injecting ABRT agent
6c088e
---
6c088e
 build                     |  2 ++
6c088e
 configure                 |  6 ++++++
6c088e
 etc/java.conf             |  4 ++++
6c088e
 install                   |  1 +
6c088e
 java-utils/java-functions | 22 ++++++++++++++++++++--
6c088e
 java-utils/java-wrapper   |  8 ++++++++
6c088e
 6 files changed, 41 insertions(+), 2 deletions(-)
6c088e
 create mode 100644 java-utils/java-wrapper
6c088e
6c088e
diff --git a/build b/build
6c088e
index 23cbb90..4e974c0 100755
6c088e
--- a/build
6c088e
+++ b/build
6c088e
@@ -61,7 +61,9 @@ expand()
6c088e
         -e "s|%{jvmdir}|${jvmdir}|" \
6c088e
         -e "s|%{m2home}|${m2home}|" \
6c088e
         -e "s|%{prefix}|${prefix}|" \
6c088e
+        -e "s|%{rundir}|${rundir}|" \
6c088e
         -e "s|%{sysconfdir}|${sysconfdir}|" \
6c088e
+        -e "s|%{abrtlibdir}|${abrtlibdir}|" \
6c088e
         "${1}" >"${target}"
6c088e
 }
6c088e
 
6c088e
diff --git a/configure b/configure
6c088e
index 3288fda..4f22ceb 100755
6c088e
--- a/configure
6c088e
+++ b/configure
6c088e
@@ -35,8 +35,10 @@ set -e
6c088e
 vars="
6c088e
 bindir
6c088e
 datadir
6c088e
+localstatedir
6c088e
 mandir
6c088e
 prefix
6c088e
+rundir
6c088e
 sysconfdir
6c088e
 rpmconfigdir
6c088e
 
6c088e
@@ -58,6 +60,7 @@ jvmsysconfdir
6c088e
 mavendepmapdir
6c088e
 mavendepmapfragdir
6c088e
 mavenpomdir
6c088e
+abrtlibdir
6c088e
 "
6c088e
 
6c088e
 vars_re=$(echo $vars | sed 's/ /\\|/g')
6c088e
@@ -68,11 +71,14 @@ eval $(for _; do echo "$_"; done |
6c088e
 test -z "${prefix}" && prefix="/usr/local"
6c088e
 test -z "${bindir}" && bindir="${prefix}/bin"
6c088e
 test -z "${datadir}" && datadir="${prefix}/share"
6c088e
+test -z "${localstatedir}" && localstatedir="${prefix}/var"
6c088e
 test -z "${mandir}" && mandir="${datadir}/man"
6c088e
+test -z "${rundir}" && rundir="${localstatedir}/run"
6c088e
 test -z "${sysconfdir}" && sysconfdir="${prefix}/etc"
6c088e
 test -z "${rpmconfigdir}" && rpmconfigdir="${prefix}/lib/rpm"
6c088e
 
6c088e
 test -z "${m2home}" && m2home="${datadir}/xmvn"
6c088e
+test -z "${abrtlibdir}" && abrtlibdir="${prefix}/lib/abrt-java-connector"
6c088e
 
6c088e
 eval $(sed -n 's/^%_\('"$vars_re"'\)\ *\(.*\)$/\1="\2"/;T;s/%{_\(.*}\)/${\1/;p' etc/macros.jpackage)
6c088e
 
6c088e
diff --git a/etc/java.conf b/etc/java.conf
6c088e
index fa0a989..042e9ad 100644
6c088e
--- a/etc/java.conf
6c088e
+++ b/etc/java.conf
6c088e
@@ -22,3 +22,7 @@ JVM_ROOT=%{jvmdir}
6c088e
 
6c088e
 # Options to pass to the java interpreter
6c088e
 #JAVACMD_OPTS=
6c088e
+
6c088e
+# You can disable ABRT Java Connector by setting JAVA_ABRT to "off".
6c088e
+# See: https://github.com/jfilak/abrt-java-connector/
6c088e
+#JAVA_ABRT=off
6c088e
diff --git a/install b/install
6c088e
index d0b941a..33690ed 100755
6c088e
--- a/install
6c088e
+++ b/install
6c088e
@@ -118,6 +118,7 @@ inst_config etc/font.properties "${javaconfdir}"
6c088e
 inst_config target/java.conf "${javaconfdir}"
6c088e
 
6c088e
 inst_data target/java-functions "${javadir}-utils"
6c088e
+inst_exec java-utils/java-wrapper "${javadir}-utils"
6c088e
 inst_data java-utils/maven_depmap.py "${javadir}-utils"
6c088e
 inst_data java-utils/pom_editor.sh "${javadir}-utils"
6c088e
 
6c088e
diff --git a/java-utils/java-functions b/java-utils/java-functions
6c088e
index dc8aa1b..e9a763a 100644
6c088e
--- a/java-utils/java-functions
6c088e
+++ b/java-utils/java-functions
6c088e
@@ -109,6 +109,14 @@ _load_java_conf()
6c088e
     if [ -n "${java_opts_save}" ]; then
6c088e
 	JAVACMD_OPTS="${java_opts_save}"
6c088e
     fi
6c088e
+
6c088e
+    if [ "_${JAVA_ABRT}" != "_off" -a -f "%{abrtlibdir}/libabrt-java-connector.so" -a -f "%{rundir}/abrt/abrtd.pid" ]; then
6c088e
+	_log "ABRT Java connector was enabled"
6c088e
+	_log "Using ABRT Java agent: %{abrtlibdir}/libabrt-java-connector.so"
6c088e
+	JAVACMD_OPTS="${JAVACMD_OPTS} -agentpath:%{abrtlibdir}/libabrt-java-connector.so=abrt=on"
6c088e
+    else
6c088e
+	_log "ABRT Java connector is disabled"
6c088e
+    fi
6c088e
 }
6c088e
 
6c088e
 
6c088e
@@ -224,7 +232,12 @@ set_javacmd()
6c088e
 	JAVACMD="${JAVA_HOME}/${cmd}"
6c088e
 	if [ -x "${JAVACMD}" ]; then
6c088e
 	    _log "Using configured JAVACMD: $JAVACMD"
6c088e
-	    JAVACMD="${JAVACMD}${JAVACMD_OPTS:+ }${JAVACMD_OPTS}"
6c088e
+	    if [ -n "${JAVACMD_OPTS}" ]; then
6c088e
+		_log "Using java-wrapper with extra options: ${JAVACMD_OPTS}"
6c088e
+		export _JP_JAVACMD="${JAVACMD}"
6c088e
+		export _JP_JAVACMD_OPTS="${JAVACMD_OPTS}"
6c088e
+		JAVACMD="%{javadir}-utils/java-wrapper"
6c088e
+	    fi
6c088e
 	    return 0
6c088e
 	fi
6c088e
     done
6c088e
@@ -232,7 +245,12 @@ set_javacmd()
6c088e
     JAVACMD=$(which java 2>/dev/null || :)
6c088e
     if [ -x "${JAVACMD}" ]; then
6c088e
 	_log "Using JAVACMD from PATH: $JAVACMD"
6c088e
-	JAVACMD="${JAVACMD}${JAVACMD_OPTS:+ }${JAVACMD_OPTS}"
6c088e
+	if [ -n "${JAVACMD_OPTS}" ]; then
6c088e
+	    _log "Using java-wrapper with extra options: ${JAVACMD_OPTS}"
6c088e
+	    export _JP_JAVACMD="${JAVACMD}"
6c088e
+	    export _JP_JAVACMD_OPTS="${JAVACMD_OPTS}"
6c088e
+	    JAVACMD="%{javadir}-utils/java-wrapper"
6c088e
+	fi
6c088e
 	return 0
6c088e
     fi
6c088e
 
6c088e
diff --git a/java-utils/java-wrapper b/java-utils/java-wrapper
6c088e
new file mode 100644
6c088e
index 0000000..29b3143
6c088e
--- /dev/null
6c088e
+++ b/java-utils/java-wrapper
6c088e
@@ -0,0 +1,8 @@
6c088e
+#!/bin/sh
6c088e
+
6c088e
+JAVACMD="${_JP_JAVACMD}"
6c088e
+JAVACMD_OPTS="${_JP_JAVACMD_OPTS}"
6c088e
+unset _JP_JAVACMD
6c088e
+unset _JP_JAVACMD_OPTS
6c088e
+
6c088e
+exec "${JAVACMD}" ${JAVACMD_OPTS} "${@}"
6c088e
-- 
6c088e
2.4.3
6c088e