[meta-java,2/2] openjdk-common: Define JAVA_HOME by default

Submitted by Fang Jia on Nov. 29, 2018, 10:48 a.m. | Patch ID: 156733

Details

Message ID 1543488504-15595-2-git-send-email-fang.jia@windriver.com
State Superseded
Delegated to: Richard Leitner
Headers show

Commit Message

Fang Jia Nov. 29, 2018, 10:48 a.m.
Use postinst script to set the JAVA_HOME by default.

Signed-off-by: Fang Jia <fang.jia@windriver.com>
---
 recipes-core/openjdk/openjdk-common.inc | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Patch hide | download patch | download mbox

diff --git a/recipes-core/openjdk/openjdk-common.inc b/recipes-core/openjdk/openjdk-common.inc
index 01a0a2a..aaf81f6 100644
--- a/recipes-core/openjdk/openjdk-common.inc
+++ b/recipes-core/openjdk/openjdk-common.inc
@@ -5,3 +5,17 @@  JDK_ARCH = "${@openjdk_build_helper_get_jdk_arch(d)}"
 
 # Provides the target architecture to the configure script.
 export LLVM_CONFIGURE_ARCH="${@openjdk_build_helper_get_llvm_configure_arch(d)}"
+
+pkg_postinst_${PN}() {
+	cat >> $D${sysconfdir}/profile << EOT
+JAVA_HOME=""
+for dir in ${libdir}/jvm/*; do
+        if [ -x "\${dir}/bin/java" ]; then
+                [ -z "\${JAVA_HOME}" ] && JAVA_HOME="\${dir}"
+        fi
+done
+if [ -n "\${JAVA_HOME}" ]; then
+        export JAVA_HOME=\${JAVA_HOME}
+fi
+EOT
+}

Comments

Richard Leitner Dec. 17, 2018, 1:45 p.m.
Hi,
thanks for the patch!

Just one question: what happens when the package gets removed?
Is there any mechanism to remove the JAVA_HOME definition again?

If not: may you please implement one? Thanks!

regards;Richard.L

On 29.11.18 11:48, Fang Jia wrote:
> Use postinst script to set the JAVA_HOME by default.
> 
> Signed-off-by: Fang Jia <fang.jia@windriver.com>
> ---
>  recipes-core/openjdk/openjdk-common.inc | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/recipes-core/openjdk/openjdk-common.inc b/recipes-core/openjdk/openjdk-common.inc
> index 01a0a2a..aaf81f6 100644
> --- a/recipes-core/openjdk/openjdk-common.inc
> +++ b/recipes-core/openjdk/openjdk-common.inc
> @@ -5,3 +5,17 @@ JDK_ARCH = "${@openjdk_build_helper_get_jdk_arch(d)}"
>  
>  # Provides the target architecture to the configure script.
>  export LLVM_CONFIGURE_ARCH="${@openjdk_build_helper_get_llvm_configure_arch(d)}"
> +
> +pkg_postinst_${PN}() {
> +	cat >> $D${sysconfdir}/profile << EOT
> +JAVA_HOME=""
> +for dir in ${libdir}/jvm/*; do
> +        if [ -x "\${dir}/bin/java" ]; then
> +                [ -z "\${JAVA_HOME}" ] && JAVA_HOME="\${dir}"
> +        fi
> +done
> +if [ -n "\${JAVA_HOME}" ]; then
> +        export JAVA_HOME=\${JAVA_HOME}
> +fi
> +EOT
> +}
>
André Draszik Jan. 2, 2019, 8:06 p.m.
On Thu, 2018-11-29 at 18:48 +0800, Fang Jia wrote:
> Use postinst script to set the JAVA_HOME by default.
> 
> Signed-off-by: Fang Jia <fang.jia@windriver.com>
> ---
>  recipes-core/openjdk/openjdk-common.inc | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/recipes-core/openjdk/openjdk-common.inc b/recipes-
> core/openjdk/openjdk-common.inc
> index 01a0a2a..aaf81f6 100644
> --- a/recipes-core/openjdk/openjdk-common.inc
> +++ b/recipes-core/openjdk/openjdk-common.inc
> @@ -5,3 +5,17 @@ JDK_ARCH = "${@openjdk_build_helper_get_jdk_arch(d)}"
>  
>  # Provides the target architecture to the configure script.
>  export LLVM_CONFIGURE_ARCH="${@openjdk_build_helper_get_llvm_configure_ar
> ch(d)}"
> +
> +pkg_postinst_${PN}() {
> +	cat >> $D${sysconfdir}/profile << EOT
> +JAVA_HOME=""
> +for dir in ${libdir}/jvm/*; do
> +        if [ -x "\${dir}/bin/java" ]; then
> +                [ -z "\${JAVA_HOME}" ] && JAVA_HOME="\${dir}"
> +        fi
> +done
> +if [ -n "\${JAVA_HOME}" ]; then
> +        export JAVA_HOME=\${JAVA_HOME}
> +fi
> +EOT
> +}

I'd say this should be done via adding a file to ${sysconfdir}/profile.d/
instead. Have a look at e.g. the DistCC recipe
 poky.git/meta/recipes-devtools/devel-config/distcc-config.bb


Cheers,
Andre'
André Draszik Jan. 3, 2019, 8:11 a.m.
On Thu, 2018-11-29 at 18:48 +0800, Fang Jia wrote:
> Use postinst script to set the JAVA_HOME by default.
> 
> Signed-off-by: Fang Jia <fang.jia@windriver.com>
> ---
>  recipes-core/openjdk/openjdk-common.inc | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/recipes-core/openjdk/openjdk-common.inc b/recipes-
> core/openjdk/openjdk-common.inc
> index 01a0a2a..aaf81f6 100644
> --- a/recipes-core/openjdk/openjdk-common.inc
> +++ b/recipes-core/openjdk/openjdk-common.inc

What about all the other Java providers that could be installed in the
system instead? The original did take care of that, whereas this only does
the right thing now if OpenJDK-8 is installed...

Cheers,
Andre'