Bug 27079 - Improvements for javavmwrapper?
Summary: Improvements for javavmwrapper?
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Greg Lewis
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-05-04 15:30 UTC by Ernst de Haan
Modified: 2004-11-11 19:21 UTC (History)
0 users

See Also:


Attachments
mypatch.diff (2.86 KB, patch)
2004-05-21 15:17 UTC, Hervé Quiroz
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ernst de Haan 2001-05-04 15:30:01 UTC
As I expressed before, I really like the concept of javavmwrapper, but I'm still struggling to make effective use of it. When I install a JDK from the ports, the javavmwrapper port is installed as well. This allows me to use multiple Java VMs and to switch between them. The 'current' Java runtime can be called using 'javavm'. Problem is that most programs that use Java expect the command 'java' to point to the Java runtime, 'javac' to the Java compiler and 'javadoc' to the Javadoc documentation generation tool (to name a few). And they also expect the JAVA_HOME environment variable to have a sensible value. The javavmwrapper system still doesn't provide this level of transparency.

Fix: 

My suggestion: Make sure that none of the JDKs install a 'java', 'javah', 'javadoc' (etc) executable in /usr/local/bin/ but make javavmwrapper install these in /usr/local/bin/. They may all be symlinks to the same shell script. Now make sure these scripts work as expected, similar to the current 'javavm' shell script, written by Maxim Sobolev.
If this idea is appreciated, *and* if Maxim would like me to, then I could have a look at this and try to come up with a first attempt to implement this approach.
How-To-Repeat: Install a JDK. Run 'javac' or 'javadoc' or 'javah' after that.
Comment 1 Maxim Sobolev freebsd_committer freebsd_triage 2001-05-04 15:48:54 UTC
> As I expressed before, I really like the concept of javavmwrapper, but I'm
> still struggling to make effective use of it. When I install a JDK from the
> ports, the javavmwrapper port is installed as well. This allows me to use
> multiple Java VMs and to switch between them. The 'current' Java runtime
> can be called using 'javavm'. Problem is that most programs that use Java
> expect the command 'java' to point to the Java runtime, 'javac' to the Java
> compiler and 'javadoc' to the Javadoc documentation generation tool (to name
> a few). And they also expect the JAVA_HOME environment variable to have a
> sensible value. The javavmwrapper system still doesn't provide this level
> of transparency.
>
> >How-To-Repeat:
> Install a JDK. Run 'javac' or 'javadoc' or 'javah' after that.
> >Fix:
> My suggestion: Make sure that none of the JDKs install a 'java', 'javah',
> 'javadoc' (etc) executable in /usr/local/bin/ but make javavmwrapper install
> these in /usr/local/bin/. They may all be symlinks to the same shell script.
> Now make sure these scripts work as expected, similar to the current 'javavm'
> shell script, written by Maxim Sobolev.
> If this idea is appreciated, *and* if Maxim would like me to, then I could
> have a look at this and try to come up with a first attempt to implement
> this approach.

Hehe, great minds think alike ;). This idea has been already implemented by me.
I've rewrote javavmwrapper in plain old C with support for all above mentioned
features plus several others, including a possibility to set/modify per-VM
environment variables, command line options etc.

The only thing my new wrapped is lacking is the documentation, and that
is why it is not announced yet. Therefore, if you have some free time and
willing to help me out then you could take this piece of work.

Please drop me a note if you could help with that.

-Maxim
Comment 2 Ying-Chieh Liao freebsd_committer freebsd_triage 2001-05-23 07:51:28 UTC
Responsible Changed
From-To: freebsd-ports->sobomax

over to maintainer
Comment 3 Hervé Quiroz 2003-09-05 13:22:23 UTC
I was about to submit a port for a similar tool of mine (jdk_wrapper)
that just handles the sort of features you speak of. Browsing through
the PRs, I found this one still open so I decided to "merge" my tool
with javavmwrapper.

The added features are the following:

Now you may use java/javac/javah/rmid/... commands and javavm decides
from which JDK the command should be run. I also changed the way javavm
handles JAVA_HOME. Instead of unsetting it, it first tries to execute
the command in the path specified by JAVA_HOME (so any user may install
a JDK of its own, which is good for testing purpose) and then fall back
to the former javavm behaviour ($JAVAVM and then $PREFIX/etc/javavms).
The main difference is that JAVAVM lists the location of the 'java'
command of each JDK and JAVA_HOME list the location of each JDK home.
But each one is handled separately so there's no problem.

I have no any of what sort of documentation should be included with this
port... IMHO it's pretty self-contained with each of the JDK port (as
each JDK command has its -help option). It would probably be better to
add something in the FreeBSD Handbook.

Unfortunately, I broke the 'javavm' former behaviour so people used to
it might experience some problems. I could fix it if you want but I
think there is no point in using the 'javavm' command with this new
version, as the 'java' command itself is available.

Speaking of version, I bumped the PORT_VERSION to 1.5 but maybe it could
be 2.0 as this is a major change in behaviour... although only a few
lines of code have actually been altered ;-)

AFAIK it works. I updated the port as well and portlint'ed it fine.

Regards,

Herve


diff -ur javavmwrapper.original/Makefile javavmwrapper/Makefile
--- javavmwrapper.original/Makefile	Fri Sep  5 01:01:15 2003
+++ javavmwrapper/Makefile	Fri Sep  5 01:43:48 2003
@@ -8,7 +8,7 @@
 #

 PORTNAME=	javavmwrapper
-PORTVERSION=	1.4
+PORTVERSION=	1.5
 CATEGORIES=	java
 MASTER_SITES=	# none
 DISTFILES=	# none
@@ -21,6 +21,9 @@

 SRC=		${.CURDIR}/src

+JAVA_COMMANDS= appletviewer idlj jar jarsigner java javac javadoc javah javap jdb orbd rmic rmid rmiregistry tnameserv
+JAVAVMWRAPPER_COMMANDS= registervm unregistervm
+
 do-fetch:
 	@${DO_NADA}

@@ -30,7 +33,8 @@

 do-install:
 	${INSTALL_SCRIPT} ${WRKDIR}/javavmwrapper.sh ${PREFIX}/bin/javavm
-	${LN} -sf ${PREFIX}/bin/javavm ${PREFIX}/bin/registervm
-	${LN} -sf ${PREFIX}/bin/javavm ${PREFIX}/bin/unregistervm
+.for COMMAND in ${JAVA_COMMANDS} ${JAVAVMWRAPPER_COMMANDS}
+	${LN} -sf ${PREFIX}/bin/javavm ${PREFIX}/bin/${COMMAND}
+.endfor

 .include <bsd.port.mk>
diff -ur javavmwrapper.original/pkg-plist javavmwrapper/pkg-plist
--- javavmwrapper.original/pkg-plist	Fri Sep  5 01:01:15 2003
+++ javavmwrapper/pkg-plist	Fri Sep  5 01:07:41 2003
@@ -1,3 +1,18 @@
 bin/javavm
 bin/registervm
 bin/unregistervm
+bin/appletviewer
+bin/idlj
+bin/jar
+bin/jarsigner
+bin/java
+bin/javac
+bin/javadoc
+bin/javah
+bin/javap
+bin/jdb
+bin/orbd
+bin/rmic
+bin/rmid
+bin/rmiregistry
+bin/tnameserv
diff -ur javavmwrapper.original/src/javavmwrapper.sh javavmwrapper/src/javavmwrapper.sh
--- javavmwrapper.original/src/javavmwrapper.sh	Fri Sep  5 01:01:15 2003
+++ javavmwrapper/src/javavmwrapper.sh	Fri Sep  5 01:39:35 2003
@@ -22,13 +22,16 @@
 PREFIX="%%PREFIX%%"
 CONF="${PREFIX}/etc/javavms"
 IAM=`basename "${0}"`
+COMMAND_ARGS=${@}

-tryrunVM () {
+tryrunJavaCommand () {
     if [ -x "${1}" ]; then
-        exec "${@}"
+        COMMAND=`echo "${1}" | sed "s|java$|${IAM}|"`
+        echo running \'${COMMAND} ${COMMAND_ARGS}\'
+        exec "${COMMAND}" "${COMMAND_ARGS}"
     fi

-    /bin/echo "${IAM}: warning: couldn't start specified JavaVM - \"${1}\"" >&2
+    /bin/echo "${IAM}: warning: couldn't run using the specified JavaVM - \"${1}\"" >&2
 }

 registerVM () {
@@ -97,11 +100,17 @@

 # Main ()

+# First check if JAVA_HOME environment variable is set
+if [ x"${JAVA_HOME}" != x"" ]; then
+    tryrunJavaCommand "${JAVA_HOME}/bin/java"
+fi
+
+# Else unset JAVA_HOME
 unset JAVA_HOME

 # First check if JAVAVM environment variable is set
 if [ x"${JAVAVM}" != x"" ]; then
-    tryrunVM "${JAVAVM}" "${@}"
+    tryrunJavaCommand "${JAVAVM}"
 fi

 # Then try to make sure that ${CONF} exists
@@ -115,7 +124,7 @@

 # Finally try to run one of the ${VMS}
 for JAVAVM in ${VMS}; do
-    tryrunVM "${JAVAVM}" "${@}";
+    tryrunJavaCommand "${JAVAVM}"
 done

 echo "${IAM}: error: no suitable JavaVMs found" >&2
Only in javavmwrapper.original: work
Comment 4 ernst.dehaan 2003-09-08 09:01:06 UTC
Herve,

Very nice work indeed!

IMHO documentation and backwards compatibility are key issues, though. So I 
suggest the following:

* request Maxim Sobolev for his opinion, perhaps we should merge with his
  javavm modifications
* guarantee backwards compatibility (should be fairly simple)
* set version to 2.0, indeed, because this is a major change
* write a small article for the FreeBSD handbook
* wait for the 4.9 release and commit after that, around the same time as
  bsd.java.mk 2.0
* change all ports that expect the old javavm behaviour to use 2.0
* remove backwards compatibility

Ernst

On vrijdag 5 september 2003 14:22, Herve Quiroz wrote:
> I was about to submit a port for a similar tool of mine (jdk_wrapper)
> that just handles the sort of features you speak of. Browsing through
> the PRs, I found this one still open so I decided to "merge" my tool
> with javavmwrapper.
>
> The added features are the following:
>
> Now you may use java/javac/javah/rmid/... commands and javavm decides
> from which JDK the command should be run. I also changed the way javavm
> handles JAVA_HOME. Instead of unsetting it, it first tries to execute
> the command in the path specified by JAVA_HOME (so any user may install
> a JDK of its own, which is good for testing purpose) and then fall back
> to the former javavm behaviour ($JAVAVM and then $PREFIX/etc/javavms).
> The main difference is that JAVAVM lists the location of the 'java'
> command of each JDK and JAVA_HOME list the location of each JDK home.
> But each one is handled separately so there's no problem.
>
> I have no any of what sort of documentation should be included with this
> port... IMHO it's pretty self-contained with each of the JDK port (as
> each JDK command has its -help option). It would probably be better to
> add something in the FreeBSD Handbook.
>
> Unfortunately, I broke the 'javavm' former behaviour so people used to
> it might experience some problems. I could fix it if you want but I
> think there is no point in using the 'javavm' command with this new
> version, as the 'java' command itself is available.
>
> Speaking of version, I bumped the PORT_VERSION to 1.5 but maybe it could
> be 2.0 as this is a major change in behaviour... although only a few
> lines of code have actually been altered ;-)
>
> AFAIK it works. I updated the port as well and portlint'ed it fine.
>
> Regards,
>
> Herve
>
>
> diff -ur javavmwrapper.original/Makefile javavmwrapper/Makefile
> --- javavmwrapper.original/Makefile	Fri Sep  5 01:01:15 2003
> +++ javavmwrapper/Makefile	Fri Sep  5 01:43:48 2003
> @@ -8,7 +8,7 @@
>  #
>
>  PORTNAME=	javavmwrapper
> -PORTVERSION=	1.4
> +PORTVERSION=	1.5
>  CATEGORIES=	java
>  MASTER_SITES=	# none
>  DISTFILES=	# none
> @@ -21,6 +21,9 @@
>
>  SRC=		${.CURDIR}/src
>
> +JAVA_COMMANDS= appletviewer idlj jar jarsigner java javac javadoc javah
> javap jdb orbd rmic rmid rmiregistry tnameserv +JAVAVMWRAPPER_COMMANDS=
> registervm unregistervm
> +
>  do-fetch:
>  	@${DO_NADA}
>
> @@ -30,7 +33,8 @@
>
>  do-install:
>  	${INSTALL_SCRIPT} ${WRKDIR}/javavmwrapper.sh ${PREFIX}/bin/javavm
> -	${LN} -sf ${PREFIX}/bin/javavm ${PREFIX}/bin/registervm
> -	${LN} -sf ${PREFIX}/bin/javavm ${PREFIX}/bin/unregistervm
> +.for COMMAND in ${JAVA_COMMANDS} ${JAVAVMWRAPPER_COMMANDS}
> +	${LN} -sf ${PREFIX}/bin/javavm ${PREFIX}/bin/${COMMAND}
> +.endfor
>
>  .include <bsd.port.mk>
> diff -ur javavmwrapper.original/pkg-plist javavmwrapper/pkg-plist
> --- javavmwrapper.original/pkg-plist	Fri Sep  5 01:01:15 2003
> +++ javavmwrapper/pkg-plist	Fri Sep  5 01:07:41 2003
> @@ -1,3 +1,18 @@
>  bin/javavm
>  bin/registervm
>  bin/unregistervm
> +bin/appletviewer
> +bin/idlj
> +bin/jar
> +bin/jarsigner
> +bin/java
> +bin/javac
> +bin/javadoc
> +bin/javah
> +bin/javap
> +bin/jdb
> +bin/orbd
> +bin/rmic
> +bin/rmid
> +bin/rmiregistry
> +bin/tnameserv
> diff -ur javavmwrapper.original/src/javavmwrapper.sh
> javavmwrapper/src/javavmwrapper.sh ---
> javavmwrapper.original/src/javavmwrapper.sh	Fri Sep  5 01:01:15 2003 +++
> javavmwrapper/src/javavmwrapper.sh	Fri Sep  5 01:39:35 2003
> @@ -22,13 +22,16 @@
>  PREFIX="%%PREFIX%%"
>  CONF="${PREFIX}/etc/javavms"
>  IAM=`basename "${0}"`
> +COMMAND_ARGS=${@}
>
> -tryrunVM () {
> +tryrunJavaCommand () {
>      if [ -x "${1}" ]; then
> -        exec "${@}"
> +        COMMAND=`echo "${1}" | sed "s|java$|${IAM}|"`
> +        echo running \'${COMMAND} ${COMMAND_ARGS}\'
> +        exec "${COMMAND}" "${COMMAND_ARGS}"
>      fi
>
> -    /bin/echo "${IAM}: warning: couldn't start specified JavaVM -
> \"${1}\"" >&2 +    /bin/echo "${IAM}: warning: couldn't run using the
> specified JavaVM - \"${1}\"" >&2 }
>
>  registerVM () {
> @@ -97,11 +100,17 @@
>
>  # Main ()
>
> +# First check if JAVA_HOME environment variable is set
> +if [ x"${JAVA_HOME}" != x"" ]; then
> +    tryrunJavaCommand "${JAVA_HOME}/bin/java"
> +fi
> +
> +# Else unset JAVA_HOME
>  unset JAVA_HOME
>
>  # First check if JAVAVM environment variable is set
>  if [ x"${JAVAVM}" != x"" ]; then
> -    tryrunVM "${JAVAVM}" "${@}"
> +    tryrunJavaCommand "${JAVAVM}"
>  fi
>
>  # Then try to make sure that ${CONF} exists
> @@ -115,7 +124,7 @@
>
>  # Finally try to run one of the ${VMS}
>  for JAVAVM in ${VMS}; do
> -    tryrunVM "${JAVAVM}" "${@}";
> +    tryrunJavaCommand "${JAVAVM}"
>  done
>
>  echo "${IAM}: error: no suitable JavaVMs found" >&2
> Only in javavmwrapper.original: work
Comment 5 Hervé Quiroz 2003-09-10 14:47:23 UTC
Ernst,

On Mon, 8 Sep 2003, Ernst de Haan wrote:

> * guarantee backwards compatibility (should be fairly simple)
> * set version to 2.0, indeed, because this is a major change

Done. Here is the ChangeLog concerned:

2003-09-09:
  - added backward compatibility with version 1.4 (support for 'javavm' command)
  - fixed a bug when running a command with no parameter (the "" dummy parameter bug)
  - increased port version to 2.0

And here comes the patch (from the former java/javavmwrapper port):


diff -ur javavmwrapper.original/Makefile javavmwrapper/Makefile
--- javavmwrapper.original/Makefile	Wed Sep 10 04:36:48 2003
+++ javavmwrapper/Makefile	Wed Sep 10 04:46:29 2003
@@ -8,7 +8,7 @@
 #

 PORTNAME=	javavmwrapper
-PORTVERSION=	1.4
+PORTVERSION=	2.0
 CATEGORIES=	java
 MASTER_SITES=	# none
 DISTFILES=	# none
@@ -21,6 +21,9 @@

 SRC=		${.CURDIR}/src

+JAVA_COMMANDS= appletviewer idlj jar jarsigner java javac javadoc javah javap jdb orbd rmic rmid rmiregistry tnameserv
+JAVAVMWRAPPER_COMMANDS= registervm unregistervm
+
 do-fetch:
 	@${DO_NADA}

@@ -30,7 +33,8 @@

 do-install:
 	${INSTALL_SCRIPT} ${WRKDIR}/javavmwrapper.sh ${PREFIX}/bin/javavm
-	${LN} -sf ${PREFIX}/bin/javavm ${PREFIX}/bin/registervm
-	${LN} -sf ${PREFIX}/bin/javavm ${PREFIX}/bin/unregistervm
+.for COMMAND in ${JAVA_COMMANDS} ${JAVAVMWRAPPER_COMMANDS}
+	${LN} -sf ${PREFIX}/bin/javavm ${PREFIX}/bin/${COMMAND}
+.endfor

 .include <bsd.port.mk>
Only in javavmwrapper: Makefile.orig
diff -ur javavmwrapper.original/pkg-plist javavmwrapper/pkg-plist
--- javavmwrapper.original/pkg-plist	Wed Sep 10 04:36:48 2003
+++ javavmwrapper/pkg-plist	Wed Sep 10 04:37:11 2003
@@ -1,3 +1,18 @@
 bin/javavm
 bin/registervm
 bin/unregistervm
+bin/appletviewer
+bin/idlj
+bin/jar
+bin/jarsigner
+bin/java
+bin/javac
+bin/javadoc
+bin/javah
+bin/javap
+bin/jdb
+bin/orbd
+bin/rmic
+bin/rmid
+bin/rmiregistry
+bin/tnameserv
Only in javavmwrapper: pkg-plist.orig
diff -ur javavmwrapper.original/src/javavmwrapper.sh javavmwrapper/src/javavmwrapper.sh
--- javavmwrapper.original/src/javavmwrapper.sh	Wed Sep 10 04:36:48 2003
+++ javavmwrapper/src/javavmwrapper.sh	Wed Sep 10 04:45:48 2003
@@ -22,13 +22,20 @@
 PREFIX="%%PREFIX%%"
 CONF="${PREFIX}/etc/javavms"
 IAM=`basename "${0}"`
+COMMAND_ARGS=${@}

-tryrunVM () {
+tryrunJavaCommand () {
+    if [ "${IAM}" = "javavm" ]; then
+        JAVACMD=java
+    else
+        JAVACMD=${IAM}
+    fi
     if [ -x "${1}" ]; then
-        exec "${@}"
+        COMMAND=`echo "${1}" | sed "s|java$|${JAVACMD}|"`
+        exec "${COMMAND}" ${COMMAND_ARGS}
     fi

-    /bin/echo "${IAM}: warning: couldn't start specified JavaVM - \"${1}\"" >&2
+    /bin/echo "${IAM}: warning: couldn't run using the specified JavaVM - \"${1}\"" >&2
 }

 registerVM () {
@@ -97,11 +104,17 @@

 # Main ()

+# First check if JAVA_HOME environment variable is set
+if [ x"${JAVA_HOME}" != x"" ]; then
+    tryrunJavaCommand "${JAVA_HOME}/bin/java"
+fi
+
+# Else unset JAVA_HOME
 unset JAVA_HOME

 # First check if JAVAVM environment variable is set
 if [ x"${JAVAVM}" != x"" ]; then
-    tryrunVM "${JAVAVM}" "${@}"
+    tryrunJavaCommand "${JAVAVM}"
 fi

 # Then try to make sure that ${CONF} exists
@@ -115,7 +128,7 @@

 # Finally try to run one of the ${VMS}
 for JAVAVM in ${VMS}; do
-    tryrunVM "${JAVAVM}" "${@}";
+    tryrunJavaCommand "${JAVAVM}"
 done

 echo "${IAM}: error: no suitable JavaVMs found" >&2
Only in javavmwrapper/src: javavmwrapper.sh.orig
Comment 6 Hervé Quiroz 2004-03-30 14:30:44 UTC
Ernst,

Did you have any feedback from Maxim Sobolev? If this is not the case,
is there something such as "maintainer timeout" for PRs?

I would really like to have this commited because I coded it a long time
ago (6-7 months aproximatively) and it seemed to me that the patch was
working and was backward-compatible with the existing port...

Herve
Comment 7 Hervé Quiroz 2004-04-09 09:36:51 UTC
Ernst,

I just realized that Maxim is not the maintainer anymore (he dropped
maintainership months ago apparently).

If you want, I can takeover maintainership as I provided this patch to
implement features you and Maxim were speaking of. Anyway, what
interests me here is more the commit (or a clear disapproval) of this my
patch rather than maintainership.

Herve
Comment 8 Hervé Quiroz 2004-05-21 15:17:54 UTC
Here is a new version.

- Removed pkg-plist using PLIST_FILES
- Patch works against latest version of the port (1.5)

Herve
Comment 9 Greg Lewis freebsd_committer freebsd_triage 2004-06-10 19:48:32 UTC
Responsible Changed
From-To: sobomax->glewis

With Maxim's permission I've taken this PR and will look into the improvements 
that Herve has made.
Comment 10 Greg Lewis freebsd_committer freebsd_triage 2004-11-11 19:20:41 UTC
State Changed
From-To: open->closed

Committed an updated javavmwrapper based in part on Herve's work here.