diff --git a/devel/libreadline-java/Makefile b/devel/libreadline-java/Makefile index 259cf4d95c99..7d8840e91d07 100644 --- a/devel/libreadline-java/Makefile +++ b/devel/libreadline-java/Makefile @@ -1,58 +1,52 @@ # Created by: Martin Kammerhofer # $FreeBSD$ PORTNAME= libreadline-java PORTVERSION= 0.8.0 DISTVERSIONSUFFIX= -src -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= devel java MASTER_SITES= SF/java-readline/java-readline/${PORTVERSION} MAINTAINER= mkamm@gmx.net COMMENT= JNI wrapper around GNU Readline / libedit / libgetline BUILD_DEPENDS= ${LOCALBASE}/include/editline/readline.h:${PORTSDIR}/devel/libedit RUN_DEPENDS= ${LOCALBASE}/include/editline/readline.h:${PORTSDIR}/devel/libedit ALL_TARGET= # empty MAKE_ENV= JAVA_HOME="${JAVA_HOME}" JAVA="${JAVA}" JAVAC="${JAVAC}" \ JAVAH="${JAVAH}" JAR_="${JAR}" -PKGMESSAGE= ${WRKDIR}/pkg-message +SUB_FILES= pkg-message jython.sh PLIST_FILES= %%JAVAJARDIR%%/libreadline-java.jar lib/libJavaReadline.so \ lib/libJavaEditline.so lib/libJavaGetline.so -.if !defined(NOPORTDOCS) -PLIST_FILES+= %%DOCSDIR%%/README.1st %%DOCSDIR%%/README \ - %%DOCSDIR%%/jython.sh %%DOCSDIR%%/JReadlineCompleter.py \ - @dirrm\ %%DOCSDIR%% -.endif -USE_GMAKE= yes +PORTDOCS= README.1st README jython.sh JReadlineCompleter.py +USES= gmake USE_JAVA= yes USE_LDCONFIG= yes WRKSRC= ${WRKDIR}/${PORTNAME}-${PORTVERSION} MAKE_JOBS_UNSAFE= yes -NO_STAGE= yes +OPTIONS_DEFINE= DOCS + +.include + do-install: - ${INSTALL_DATA} ${WRKSRC}/libreadline-java.jar ${JAVAJARDIR} - ${INSTALL_DATA} ${WRKSRC}/libJavaReadline.so ${PREFIX}/lib - ${INSTALL_DATA} ${WRKSRC}/libJavaEditline.so ${PREFIX}/lib - ${INSTALL_DATA} ${WRKSRC}/libJavaGetline.so ${PREFIX}/lib -.if !defined(NOPORTDOCS) - ${MKDIR} ${DOCSDIR} - ${INSTALL_DATA} ${WRKSRC}/README.1st ${DOCSDIR} - ${INSTALL_DATA} ${WRKSRC}/README ${DOCSDIR} - ${INSTALL_DATA} ${FILESDIR}/jython.sh ${DOCSDIR} - ${INSTALL_DATA} ${FILESDIR}/JReadlineCompleter.py ${DOCSDIR} + ${INSTALL_DATA} ${WRKSRC}/libreadline-java.jar ${STAGEDIR}${JAVAJARDIR} + ${INSTALL_DATA} ${WRKSRC}/libJavaReadline.so ${STAGEDIR}${PREFIX}/lib + ${INSTALL_DATA} ${WRKSRC}/libJavaEditline.so ${STAGEDIR}${PREFIX}/lib + ${INSTALL_DATA} ${WRKSRC}/libJavaGetline.so ${STAGEDIR}${PREFIX}/lib +.if ${PORT_OPTIONS:MDOCS} + @${MKDIR} ${STAGEDIR}${DOCSDIR} + ${INSTALL_DATA} ${WRKSRC}/README.1st ${STAGEDIR}${DOCSDIR} + ${INSTALL_DATA} ${WRKSRC}/README ${STAGEDIR}${DOCSDIR} + ${INSTALL_DATA} ${WRKDIR}/jython.sh ${STAGEDIR}${DOCSDIR} + ${INSTALL_DATA} ${FILESDIR}/JReadlineCompleter.py ${STAGEDIR}${DOCSDIR} .endif -post-install: - @${SED} -e 's|%%JAVAJARDIR%%|${JAVAJARDIR}|g' -- \ - ${.CURDIR}/pkg-message >${PKGMESSAGE} - @${CAT} ${PKGMESSAGE} - .if !defined(BATCH) test: cd ${WRKSRC} && ${MAKE_ENV} ${GMAKE} test # Now type something! .endif .include diff --git a/devel/libreadline-java/files/JReadlineCompleter.py b/devel/libreadline-java/files/JReadlineCompleter.py index 9eccfe314aaf..355543428f74 100644 --- a/devel/libreadline-java/files/JReadlineCompleter.py +++ b/devel/libreadline-java/files/JReadlineCompleter.py @@ -1,194 +1,202 @@ # (X)Emacs: -*- mode: python; coding: latin-1; -*- # TAB-Completion for Jython with org.python.util.ReadlineConsole. # JReadlineCompleter.py,v 1.1 2007/09/28 08:18:43 martin Exp # # This is rlcompleter.py from CPython 2.5.1 adapted for Jython # and libreadline-java. +# +# NOTE: Jython >= 2.5 already includes rlcompleter, +# see http://www.jython.org/docs/library/rlcompleter.html +# This is useful for older Jython versions only! """TAB-completion for Jython + libreadline-java The completer completes keywords, built-ins and globals in a selectable namespace (which defaults to __main__); when completing NAME.NAME..., it evaluates (!) the expression up to the last dot and completes its attributes. It's very cool to do "import sys" type "sys.", hit the completion key (twice), and see the list of names defined by the sys module! Notes: - Exceptions raised by the completer function are *ignored* (and generally cause the completion to fail). This is a feature -- since readline sets the tty device in raw (or cbreak) mode, printing a traceback wouldn't work well without some complicated hoopla to save, reset and restore the tty state. - The evaluation of the NAME.NAME... form may cause arbitrary application defined code to be executed if an object with a __getattr__ hook is found. Since it is the responsibility of the application (or the user) to enable this feature, I consider this an acceptable risk. More complicated expressions (e.g. function calls or indexing operations) are *not* evaluated. This module is a hacked version of the CPython 2.5 module rlcompleter. It is under the PSF (Python Software Foundation) license. """ # CAUTION: Licensing issues may arise when changing the backend # library to "GnuReadline" which is under the GPL. DEFAULTLIB = "Editline" # Try to give useful hints for any import failure here: import sys if not sys.platform.startswith("java"): raise EnvironmentError("Module %s is to be used with Jython only!" % (__name__ == "__main__" and __file__ or __name__)) if sys.registry["python.console"] != "org.python.util.ReadlineConsole": raise EnvironmentError("You need to set python.console=org.python.util.ReadlineConsole in your ~/.jython file!") try: from org.gnu.readline import Readline, ReadlineLibrary, ReadlineCompleter except ImportError: raise ImportError("Make sure you have libreadline-java.jar in classpath!") import __builtin__ import atexit import keyword import os import re __all__ = ["PyCompleter", "JvCompleter"] Readline.load( getattr(ReadlineLibrary, sys.registry["python.console.readlinelib"], "") or DEFAULTLIB) histfile = os.path.join(os.environ["HOME"], ".jyhist") try: Readline.readHistoryFile(histfile) except: print >> sys.stderr, histfile, "not available!" atexit.register(Readline.writeHistoryFile, histfile) class PyCompleter: def __init__(self, namespace = None): """Create a new completer for the command line. PyCompleter([namespace]) -> completer instance. If unspecified, the default namespace where completions are performed is __main__ (technically, __main__.__dict__). Namespaces should be given as dictionaries. """ if namespace and not isinstance(namespace, dict): raise TypeError,'namespace must be a dictionary' # Don't bind to namespace quite yet, but flag whether the user wants a # specific namespace or to use __main__.__dict__. This will allow us # to bind to __main__.__dict__ at completion time, not now. if namespace is None: self.use_main_ns = 1 else: self.use_main_ns = 0 self.namespace = namespace def complete(self, text, state): """Return the next possible completion for 'text'. This is called successively with state == 0, 1, 2, ... until it returns None. The completion should begin with 'text'. """ if self.use_main_ns: import __main__ self.namespace = __main__.__dict__ try: if state == 0: if "." in text: - self.matches = self.attr_matches(text) + matches = self.attr_matches(text) else: - self.matches = self.global_matches(text) + matches = self.global_matches(text) + # remove duplicates and sort + matches = list(set(matches)) + matches.sort() + self.matches = matches return self.matches[state] except (AttributeError, IndexError, NameError): return None def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ matches = [] n = len(text) for list in [keyword.kwlist, __builtin__.__dict__, self.namespace]: for word in list: if word[:n] == text and word != "__builtins__": matches.append(word) return matches def attr_matches(self, text): """Compute matches when text contains a dot. Assuming the text is of the form NAME.NAME....[NAME], and is evaluatable in self.namespace, it will be evaluated and its attributes (as revealed by dir()) are used as possible completions. (For class instances, class members are also considered.) WARNING: this can still invoke arbitrary C code, if an object with a __getattr__ hook is evaluated. """ m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text) if not m: return expr, attr = m.group(1, 3) object = eval(expr, self.namespace) words = dir(object) if hasattr(object,'__class__'): words.append('__class__') words = words + get_class_members(object.__class__) matches = [] n = len(attr) for word in words: if word[:n] == attr and word != "__builtins__": matches.append("%s.%s" % (expr, word)) return matches def get_class_members(klass): ret = dir(klass) if hasattr(klass,'__bases__'): for base in klass.__bases__: ret = ret + get_class_members(base) return ret class JvCompleter(ReadlineCompleter): """Create a new completer for the command line. JvCompleter([completion_callable]) -> completer instance. JvCompleter instances should be used as the completion mechanism of Readline via the setCompleter() call. """ def __init__(self, realcompleter): self.realcompleter = realcompleter def completer(self, text, state): return self.realcompleter(text, state) pycompleter = PyCompleter() jvcompleter = JvCompleter(pycompleter.complete) Readline.setCompleter(jvcompleter) Readline.parseAndBind("tab: complete") try: Readline.setCompletionAppendCharacter('\0') except: pass # Method only available from my java-readline patch. if __name__ == '__main__': print "Sorry, no unit tests yet!" #EOF# diff --git a/devel/libreadline-java/files/jython.sh b/devel/libreadline-java/files/jython.sh.in similarity index 57% rename from devel/libreadline-java/files/jython.sh rename to devel/libreadline-java/files/jython.sh.in index 631dffbfc651..6356a48b7717 100644 --- a/devel/libreadline-java/files/jython.sh +++ b/devel/libreadline-java/files/jython.sh.in @@ -1,48 +1,56 @@ #!/bin/sh # Invoke Jython. # jython.sh,v 1.5 2007/09/28 09:13:55 martin Exp # -# The path names below are for Jython 2.2 on FreeBSD. +# The path names below are for Jython 2.5.3 on FreeBSD. # +# NOTE: Jython >= 2.5 already includes rlcompleter, +# see http://www.jython.org/docs/library/rlcompleter.html +# This is useful for older Jython versions only! -CP="/usr/local/lib/jython22/jython.jar" +if [ -d "%%LOCALBASE%%/lib/jython22" ] ; then + _ver=22 +else + _ver= +fi +CP="%%LOCALBASE%%/lib/jython${_ver}/jython.jar" defs= wrapper= case "${JYTHON_CONSOLE:-Editline}" in *[Ee]dit[Ll]ine) - CP="$CP:/usr/local/share/java/classes/libreadline-java.jar" + CP="$CP:%%LOCALBASE%%/share/java/classes/libreadline-java.jar" defs="-Dpython.console=org.python.util.ReadlineConsole" defs="$defs -Dpython.console.readlinelib=Editline" ;; *[Gg]et[Ll]ine) - CP="$CP:/usr/local/share/java/classes/libreadline-java.jar" + CP="$CP:%%LOCALBASE%%/share/java/classes/libreadline-java.jar" defs="-Dpython.console=org.python.util.ReadlineConsole" defs="$defs -Dpython.console.readlinelib=Getline" ;; *[Jj][Ll]ine) - CP="$CP:/usr/local/share/java/classes/jline.jar" + CP="$CP:%%LOCALBASE%%/share/java/classes/jline.jar" defs="-Dpython.console=" wrapper=jline.ConsoleRunner ;; *[Rr]ead[Ll]ine) - CP="$CP:/usr/local/share/java/classes/libreadline-java.jar" + CP="$CP:%%LOCALBASE%%/share/java/classes/libreadline-java.jar" defs="-Dpython.console=org.python.util.ReadlineConsole" defs="$defs -Dpython.console.readlinelib=GnuReadline" ;; *) echo >&2 "$0: illegal value of JYTHON_CONSOLE: $JYTHON_CONSOLE" exit 64 ;; esac if [ -n "$CLASSPATH" ]; then CP="$CP:$CLASSPATH" fi -exec java -Dpython.home="/usr/local/lib/jython22" \ +exec java -Dpython.home="%%LOCALBASE%%/lib/jython${_ver}" \ -Dpython.cachedir="${HOME}/.jython-cachedir" \ -classpath "$CP" $wrapper org.python.util.jython $defs "$@" #EOF# diff --git a/devel/libreadline-java/files/patch-src-native-Makefile b/devel/libreadline-java/files/patch-src-native-Makefile index e12715ec5f38..781fff283a7b 100644 --- a/devel/libreadline-java/files/patch-src-native-Makefile +++ b/devel/libreadline-java/files/patch-src-native-Makefile @@ -1,55 +1,63 @@ ---- src/native/Makefile.orig 2003-01-07 07:14:35.000000000 -0300 -+++ src/native/Makefile 2008-02-16 18:53:37.000000000 -0300 -@@ -44,10 +44,12 @@ +--- src/native/Makefile.orig 2003-01-07 11:14:35.000000000 +0100 ++++ src/native/Makefile 2013-12-13 08:29:23.000000000 +0100 +@@ -38,25 +38,28 @@ + INCLUDES = -I "c:/Programme/DevStudio/VC/include" \ + -I $(JAVAINCLUDE) -I $(JAVANATINC) + LIB = "c:/Programme/DevStudio/VC/lib" +-CC = cl ++#CC = gcc + OBJ_EXT := obj + LIB_PRE := LIB_EXT := dll CFLAGS=-DWIN32=$(WIN32) -D__IBMC__ else -INCLUDES = -I $(JAVAINCLUDE) -I $(JAVANATINC) -LIBPATH = -L/usr/lib/termcap +INCLUDES = -I $(JAVAINCLUDE) -I $(JAVANATINC) -I $(LOCALBASE)/include +ifeq (JavaEditline,$(TG)) +LIBPATH = -L$(LOCALBASE)/lib -rpath $(LOCALBASE)/lib +endif JavaReadline_LIBS = -lreadline -ltermcap -lhistory -JavaEditline_LIBS = -ledit -ltermcap +JavaEditline_LIBS = $(LOCALBASE)/lib/libedit.so -ltermcap ifeq (cygwin,$(WIN32)) JavaGetline_LIBS = -lcygwin endif -@@ -55,8 +57,9 @@ +-CC = gcc ++CC = cc OBJ_EXT := o LIB_PRE := lib LIB_EXT := so -CFLAGS=-fPIC -DPOSIX +CFLAGS+=-fPIC -DPOSIX endif +JAVAH ?= javah OBJECTS := org_gnu_readline_Readline.$(OBJ_EXT) @@ -69,13 +72,13 @@ lib: $(ROOTDIR)/$(LIB_PRE)$(TG).$(LIB_EXT) JavaReadline: - make TG=$@ lib + $(MAKE) TG=$@ lib JavaEditline: - make TG=$@ lib + $(MAKE) TG=$@ lib JavaGetline: - make TG=$@ lib + $(MAKE) TG=$@ lib $(ROOTDIR)/$(LIB_PRE)$(TG).$(LIB_EXT): $(OBJECTS) ifeq (MSC,$(WIN32)) @@ -110,7 +113,7 @@ -c org_gnu_readline_Readline.c org_gnu_readline_Readline.h: $(BUILDDIR)/org/gnu/readline/Readline.class - javah -classpath $(BUILDDIR) -jni org.gnu.readline.Readline + $(JAVAH) -classpath $(BUILDDIR) -jni org.gnu.readline.Readline touch org_gnu_readline_Readline.h clean: diff --git a/devel/libreadline-java/files/patch-src-native-org_gnu_readline_Readline.c b/devel/libreadline-java/files/patch-src-native-org_gnu_readline_Readline.c index 6389e13dbd5c..f7dda9011c7e 100644 --- a/devel/libreadline-java/files/patch-src-native-org_gnu_readline_Readline.c +++ b/devel/libreadline-java/files/patch-src-native-org_gnu_readline_Readline.c @@ -1,24 +1,33 @@ --- src/native/org_gnu_readline_Readline.c.orig 2003-01-07 11:14:35.000000000 +0100 -+++ src/native/org_gnu_readline_Readline.c 2007-09-27 09:21:14.000000000 +0200 ++++ src/native/org_gnu_readline_Readline.c 2013-12-12 20:40:36.000000000 +0100 +@@ -430,7 +430,7 @@ + jtext = (*jniEnv)->NewStringUTF(jniEnv,text); + + if (jniMethodId == 0) { +- return; ++ return 0; + } + + completion = (*jniEnv)->CallObjectMethod(jniEnv, jniObject, @@ -560,6 +560,21 @@ #endif /* -------------------------------------------------------------------------- */ +/* Sets/gets rl_completion_append_character */ +/* -------------------------------------------------------------------------- */ + +#ifndef JavaGetline +JNIEXPORT jchar JNICALL +Java_org_gnu_readline_Readline_setCompletionAppendCharacterImpl +(JNIEnv * env, jclass class, jchar appendCharacter) { + int previous_setting = rl_completion_append_character; + + rl_completion_append_character = (int)appendCharacter; + return (jchar)previous_setting; +} +#endif + +/* -------------------------------------------------------------------------- */ /* Convert utf8-string to ucs1-string . */ /* -------------------------------------------------------------------------- */ diff --git a/devel/libreadline-java/pkg-message b/devel/libreadline-java/files/pkg-message.in similarity index 100% rename from devel/libreadline-java/pkg-message rename to devel/libreadline-java/files/pkg-message.in