Commit fc21efea authored by Bryan Kearney's avatar Bryan Kearney

Port the code to JNA. This will remove the C code in favor of java mappings....

Port the code to JNA. This will remove the C code in favor of java mappings. As part of this patch, the code will be required to run on java 1.6. The API remains mostly the same.
parent bdbbce9c
.classpath
.project
.settings
target
README
......@@ -6,3 +6,4 @@ Patches provided by:
Daniel Schwager <Daniel.Schwager@dtnet.de>
Thomas Fricke <libvirt@thomasfricke.de>
David Lively <dlively@virtualiron.com>
Bryan Kearney <bkearney@redhat.com>
Wed Jul 29 2009 Bryan Kearney <bkearney@redhat.com>
* refactored the code to use jna (https://jna.dev.java.net/)
Mon May 11 10:49:54 CEST 2009 Daniel Veillard <veillard@redhat.com>
* src/jni/org_libvirt_Domain.c: fix a cut and paste bug pointed out
......
The current build procedure is based on the
classic:
tar xvzf libvirt-java-xxx.tar.gz
cd libvirt-java
./configure [--prefix=/usr] ; make ; make install
The current build procedure is based on ant. You can build
the code by
cd libvirt-java
ant build
Type in ant -projecthelp to see all the tasks you can execute
with the build script.
You will need a Java Development Kit accepting the version 1.5
of the language since the bindings use enums which were added
in that version.
You will need a Java Development Kit accepting the version 1.6
of the language since the bindings use enums as well as the new
for loop syntax
You can select the Java Development Kit to use by providing
a --with-java-home=path_to_jdk_directory configure argument
or by using the JAVA_HOME environment variable. This can
be useful if you have multiple JDK installed or if it is
installed in a non standard path.
You can select the Java Development Kit by using the JAVA_HOME
environment variable. This can be useful if you have multiple
JDK installed or if it is installed in a non standard path.
Please report any compatibility problem to the libvirt
mailing list at:
https://www.redhat.com/mailman/listinfo/libvir-list
Of course if provided, ant based XML config files or
Eclipse one will be integrated to the source distribution
but they are not yet available.
When building from a CVS checkout you need instead to
run autogen.sh [--prefix=/usr] to build the configure,
since it's a generated file it's not commited in CVS.
Daniel Veillard
veillard@redhat.com
SUBDIRS=src doc
EXTRA_DIST = \
libvirt-java.pc.in \
libvirt-java.spec.in \
libvirt-java.spec \
autogen.sh \
INSTALL \
README.in \
README
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libvirt-java.pc
cleantar:
@(rm -f libxml*.tar.gz && rm -f COPYING && cp COPYING.LIB COPYING)
rpm: clean cleantar
@(unset CDPATH ; $(MAKE) dist && rpmbuild -ta $(distdir).tar.gz)
News file for libvirt-java
--------------------------
Jul 29 2009:
Release of 0.3.0:
- refactored the code to use jna (https://jna.dev.java.net/)
Aug 8 2008:
Release of 0.2.1:
- clean up leaks, refactoring of JNI bindings
......
This is the java binding to the libvirt library.
To use it, your program needs to access both the java library (.jar file),
and the JNI library (.so file)
1. You must have the libvirt.jar file in your classpath.
By default the installs it to /usr/share/java/libvirt-0.2.1.jar
2. You must have the libvirt_jni.so accessible by the dynamic linker.
By default the RPM installs it to /usr/lib or /usr/lib64, so the linker will
find it automatically. If it's in a different location, you have to set
the LD_LIBRARY_PATH variable to the directory containing the libvirt_jni.so
file.
There is a rudimentary functional test program that the libvirt-java-devel
installs put it into /usr/share/doc/libvirt-java-devel-0.2.1/test.java
To run it, first copy the test.java file to writeable directory
cp /usr/share/doc/libvirt-java-devel-0.2.1/test.java ~
Compile the java file to a class:
javac -classpath /usr/share/java/libvirt-0.2.1.jar test.java
Then run the program:
java -classpath .:/usr/share/java/libvirt-0.2.1.jar test
There is full javadoc for the API in /usr/share/javadoc/libvirt-java-0.2.1/
This is the java binding to the libvirt library.
To use it, your program needs to access both the java library (.jar file),
and the JNI library (.so file)
and the JNA library (.jar file)
1. You must have the libvirt.jar file in your classpath.
By default the installs it to @prefix@/share/java/libvirt-@VERSION@.jar
2. You must have the libvirt_jni.so accessible by the dynamic linker.
By default the RPM installs it to /usr/lib or /usr/lib64, so the linker will
find it automatically. If it's in a different location, you have to set
the LD_LIBRARY_PATH variable to the directory containing the libvirt_jni.so
file.
By default the installs it to /usr/share/java/@version@.jar
There is a rudimentary functional test program that the libvirt-java-devel
installs put it into @prefix@/share/doc/libvirt-java-devel-@VERSION@/test.java
installs put it into /usr/share/doc/libvirt-java-devel-@version@/test.java
To run it, first copy the test.java file to writeable directory
cp @prefix@/share/doc/libvirt-java-devel-@VERSION@/test.java ~
cp /usr/share/doc/libvirt-java-devel-@version@/test.java ~
Compile the java file to a class:
javac -classpath @prefix@/share/java/libvirt-@VERSION@.jar test.java
javac -classpath /usr/share/java/libvirt-@version@.jar test.java
Then run the program:
java -classpath .:@prefix@/share/java/libvirt-@VERSION@.jar test
java -classpath .:/usr/share/java/jna.jar:/usr/share/java/libvirt-@version@.jar test
There is full javadoc for the API in @prefix@/share/javadoc/libvirt-java-@VERSION@/
There is full javadoc for the API in /usr/share/javadoc/libvirt-java-@version@/
#!/bin/sh
# Run this to generate all the initial makefiles, etc.
srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.
THEDIR=`pwd`
cd $srcdir
DIE=0
AUTOMAKE=automake
if [ "`uname`" = "SunOs" ] ; then
AUTOMAKE=automake-1.10
fi
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile libvirt-java."
echo "Download the appropriate package for your distribution,"
echo "or see http://www.gnu.org/software/autoconf"
DIE=1
}
(libtool --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have libtool installed to compile libvirt-java."
echo "Download the appropriate package for your distribution,"
echo "or see http://www.gnu.org/software/libtool"
DIE=1
}
($AUTOMAKE --version) < /dev/null > /dev/null 2>&1 || {
echo
DIE=1
echo "You must have automake installed to compile libvirt."
echo "Download the appropriate package for your distribution,"
echo "or see http://www.gnu.org/software/automake"
}
if test "$DIE" -eq 1; then
exit 1
fi
test -f src/jni/org_libvirt_Domain.c || {
echo "You must run this script in the top-level libvirt directory"
exit 1
}
if test -z "$*"; then
echo "I am going to run ./configure with no arguments - if you wish "
echo "to pass any to it, please specify them on the $0 command line."
fi
libtoolize --copy --force
aclocal
autoheader
automake --add-missing
autoconf
cd $THEDIR
if test x$OBJ_DIR != x; then
mkdir -p "$OBJ_DIR"
cd "$OBJ_DIR"
fi
$srcdir/configure "$@" && {
echo
echo "Now type 'make' to compile libvirt."
}
version=0.3.0
libvirt.required=0.4.1
java.required=1:1.6.0
rpm.topdir=/home/bkearney/rpmbuild
<?xml version="1.0" encoding="UTF-8"?>
<project name="Libvirt Java Bindings" default="build">
<property file="build.properties"/>
<property name="jar" value="libvirt-${version}"/>
<property name="jar.file" value="target/${jar}.jar"/>
<property name="src" value="libvirt-java-${version}"/>
<property name="src.file" value="target/${src}.tar.gz"/>
<property name="spec" value="libvirt-java.spec"/>
<property name="spec.file" value="target/${spec}"/>
<path id="compile.classpath">
<fileset dir="/usr/share/java">
<include name="jna.jar"/>
</fileset>
</path>
<path id="test.classpath">
<fileset dir="/usr/share/java">
<include name="jna.jar"/>
</fileset>
<pathelement location="target/classes"/>
</path>
<target name="init">
<mkdir dir="target/classes"/>
<mkdir dir="target/testclasses"/>
<copy file="README.in"
tofile="README"
overwrite="true"
filtering="true">
<filterset filtersfile="build.properties"/>
</copy>
</target>
<target name="clean" description="cleans up all created artifacts">
<delete dir="target"/>
</target>
<target name="build" depends="init" description="builds the code and jar files">
<javac srcdir="src/main/java"
includes="**/*.java"
classpathref="compile.classpath"
destdir="target/classes"/>
<javac srcdir="src/test/java"
includes="**/*.java"
classpathref="test.classpath"
destdir="target/testclasses"/>
<jar destfile="${jar.file}"
basedir="target/classes"/>
</target>
<target name="docs" depends="build" description="builds the javadoc">
<mkdir dir="target/javadoc"/>
<javadoc sourcepath="src/main/java"
classpathref="compile.classpath"
destdir="target/javadoc"/>
</target>
<target name="src" depends="init" description="creates a src tarball">
<mkdir dir="target/libvirt-java-${version}"/>
<copy todir="target/libvirt-java-${version}">
<fileset dir="." excludes="target/**,.gitignore,.git/**,.*,.*/**"/>
</copy>
<tar basedir="target"
includes="libvirt-java-${version}/**"
compression="gzip"
destfile="${src.file}"/>
</target>
<target name="spec" depends="init" description="generates the spec file">
<copy file="libvirt-java.spec.in"
tofile="${spec.file}"
overwrite="true"
filtering="true">
<filterset filtersfile="build.properties"/>
</copy>
</target>
<target name="package" depends="src,build,docs,spec" description="builds the rpms">
<copy file="${src.file}" todir="${rpm.topdir}/SOURCES"/>
<copy file="${spec.file}" todir="${rpm.topdir}/SPECS"/>
<rpm specfile="${spec}"
command="-ba"
topdir="${rpm.topdir}"/>
</target>
</project>
/* config.h.in. Generated from configure.in by autoheader. */
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
#undef NO_MINUS_C_MINUS_O
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Version number of package */
#undef VERSION
dnl
dnl configure file for libvirt java bindings
dnl Process this file with autoconf to produce a configure script.
dnl
dnl Copyright (C) Red Hat, Inc.
dnl
dnl See COPYING.LIB for the License of this software
dnl
dnl Daniel Veillard <veillard@redhat.com>
dnl
AC_INIT([libvirt-java], [0.2.1])
AC_CONFIG_SRCDIR([src/jni/org_libvirt_Domain.c])
AC_CONFIG_AUX_DIR(.)
AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE([-Wno-portability])
AC_CANONICAL_HOST
LIBVIRT_REQUIRED="0.4.1"
JNI_MAJOR_VERSION=`echo $VERSION | awk -F. '{print $1}'`
JNI_MINOR_VERSION=`echo $VERSION | awk -F. '{print $2}'`
JNI_MICRO_VERSION=`echo $VERSION | awk -F. '{print $3}'`
JNI_VERSION_INFO=`expr $JNI_MAJOR_VERSION + $JNI_MINOR_VERSION`:$JNI_MICRO_VERSION:$JNI_MINOR_VERSION
JNI_VERSION_NUMBER=`expr $JNI_MAJOR_VERSION \* 1000000 + $JNI_MINOR_VERSION \* 1000 + $JNI_MICRO_VERSION`
AC_SUBST([JNI_MAJOR_VERSION])
AC_SUBST([JNI_MINOR_VERSION])
AC_SUBST([JNI_MICRO_VERSION])
AC_SUBST([JNI_VERSION])
AC_SUBST([JNI_VERSION_INFO])
AC_SUBST([JNI_VERSION_NUMBER])
AC_SUBST([LIBVIRT_REQUIRED])
AC_PROG_CC
AC_PROG_INSTALL
AM_PROG_CC_C_O
AC_DISABLE_STATIC
dnl Support building Win32 DLLs (must appear *before* AM_PROG_LIBTOOL)
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
INSTALLED_JAR_DIR=\${prefix}/share/java
INSTALLED_JNI_DIR=\${prefix}/lib/
AC_SUBST(INSTALLED_JAR_DIR)
AC_SUBST(INSTALLED_JNI_DIR)
PKG_CHECK_MODULES(LIBVIRT, libvirt >= $LIBVIRT_REQUIRED)
AC_SUBST(LIBVIRT_CFLAGS)
AC_SUBST(LIBVIRT_LIBS)
dnl
dnl allow the user to specify the version of java either with
dnl --with-java-home or with JAVA_HOME env variable.
dnl
AC_ARG_WITH(java_home,
[ --with-java-home=DIR path to the Java Development Kit directory(/usr/lib/jvm/java)])
if test x"$with_java_home" != x"no" -a x"$with_java_home" != x"yes" ; then
if test -d $with_java_home ; then
JAVA_HOME=$with_java_home
else
AC_MSG_ERROR([provided JAVA_HOME $with_java_home is not a directory])
fi
fi
if test x"$JAVA_HOME" == x"" ; then
JAVA_HOME=/usr/lib/jvm/java
fi
AC_MSG_CHECKING(for JDK in $JAVA_HOME)
if test ! -d $JAVA_HOME ; then
AC_MSG_ERROR([JAVA_HOME $JAVA_HOME is not a directory])
fi
if test ! -x $JAVA_HOME/bin/java ; then
AC_MSG_ERROR([missing $JAVA_HOME/bin/java binary])
else
JAVA=$JAVA_HOME/bin/java
fi
if test ! -x $JAVA_HOME/bin/javac ; then
AC_MSG_ERROR([missing $JAVA_HOME/bin/javac binary])
else
JAVAC=$JAVA_HOME/bin/javac
fi
if test ! -x $JAVA_HOME/bin/javah ; then
AC_MSG_ERROR([missing $JAVA_HOME/bin/javah binary])
else
JAVAH=$JAVA_HOME/bin/javah
fi
if test ! -x $JAVA_HOME/bin/javadoc ; then
AC_MSG_ERROR([missing $JAVA_HOME/bin/javadoc binary])
else
JAVADOC=$JAVA_HOME/bin/javadoc
fi
if test ! -x $JAVA_HOME/bin/jar ; then
AC_MSG_ERROR([missing $JAVA_HOME/bin/jar binary])
else
JAR=$JAVA_HOME/bin/jar
fi
java_version=`java -version 2>&1 | grep version`
AC_MSG_RESULT(found $java_version)
AC_SUBST(JAVA_HOME)
AC_SUBST(JAVA)
AC_SUBST(JAVAH)
AC_SUBST(JAVAC)
AC_SUBST(JAVADOC)
AC_SUBST(JAR)
dnl
dnl then find the jni.h include file usually in the include subdir
dnl
JNI_CFLAGS=
if test -f $JAVA_HOME/include/jni.h ; then
JNI_CFLAGS="-I$JAVA_HOME/include"
else
if test "`find $JAVA_HOME -name jni.h`" != "" ; then
head=`find $JAVA_HOME -name jni.h | tail -1`
dir=`dirname $head`
JNI_CFLAGS="-I$dir"
fi
fi
dnl
dnl then one need to find jni_md.h too usually in a system specific subdir
dnl
case "$build_os" in
*linux*)
system="linux"
;;
*SunOS*)
system="solaris"
;;
*cygwin*)
system="win32"
;;
*)
system="$build_os"
;;
esac
if test -f $JAVA_HOME/include/$system/jni_md.h ; then
JNI_CFLAGS="$JNI_CFLAGS -I$JAVA_HOME/include/$system"
else
if test "`find $JAVA_HOME -name jni_md.h`" != "" ; then
head=`find $JAVA_HOME -name jni_md.h | tail -1`
dir=`dirname $head`
JNI_CFLAGS="$JNI_CFLAGS -I$dir"
fi
fi
AC_SUBST(JNI_CFLAGS)
dnl
dnl Depending on the JAVAC version used one may need additional version flag
dnl
JAVAC_FLAGS=
javac_version=`$JAVAC -version 2>&1`
case "$javac_version" in
*Eclipse*)
JAVAC_FLAGS="-source 1.5"
;;
esac
AC_SUBST(JAVAC_FLAGS)
# very annoying
rm -f COPYING
cp COPYING.LIB COPYING
AC_OUTPUT(Makefile README src/Makefile src/jni/Makefile doc/Makefile libvirt-java.pc libvirt-java.spec)
docdir = $(datadir)/doc/libvirt-java-$(VERSION)
javadocdir = $(datadir)/javadoc/libvirt-java-$(VERSION)
doc_DATA = $(top_srcdir)/AUTHORS $(top_srcdir)/COPYING.LIB \
$(top_srcdir)/NEWS $(top_srcdir)/README
all-local: docs
docs:
@(cd ../src && $(MAKE) docs)
all_dest_javadoc_html_files = $(shell (find api/ -type f | sed 's+api/++'))
dest_javadoc_dirs = $(shell (find api -mindepth 1 -type d | sed 's+api/++'))
install-data-hook:
$(mkinstalldirs) $(DESTDIR)$(docdir)
@for dir in $(dest_javadoc_dirs); do \
$(mkinstalldirs) $(DESTDIR)$(javadocdir)/$${dir}; done
@for file in $(all_dest_javadoc_html_files); do \
$(INSTALL_DATA) api/$${file} $(DESTDIR)$(javadocdir)/$${file}; done
CLEANFILES = \
api/resources/inherit.gif \
api/package-list \
api/stylesheet.css \
$(shell find api -name '*.html') \
../src/doc-stamps
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libvirt-java
Description: Libvirt library Java bindings
Version: @VERSION@
classpath=@INSTALLED_CLASSPATH@
jnilibs=-L@libdir@ -lvirt-jni
Libs: -L@libdir@ -lvirt-java
Cflags:
Summary: Java bindings for the libvirt virtualization API
Name: libvirt-java
Version: @VERSION@
Version: @version@
Prefix: libvirt
Release: 1%{?dist}
License: LGPLv2+
BuildArch: noarch
Group: Development/Libraries
Source: http://libvirt.org/sources/java/libvirt-java-%{version}.tar.gz
Source: http://libvirt.org/sources/java/%{name}-%{version}.tar.gz
URL: http://libvirt.org/
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Requires: libvirt >= @LIBVIRT_REQUIRED@
Requires: java >= 1.5.0
Requires: jna
Requires: libvirt >= @libvirt.required@
Requires: java >= @java.required@
Requires: jpackage-utils
BuildRequires: libvirt-devel >= @LIBVIRT_REQUIRED@
BuildRequires: java-devel >= 1.5.0
BuildRequires: pkgconfig
BuildRequires: ant
BuildRequires: jna
BuildRequires: java-devel >= @java.required@
BuildRequires: jpackage-utils
#
......@@ -25,20 +28,19 @@ BuildRequires: jpackage-utils
%description
Libvirt-java is a base framework allowing to use libvirt, the virtualization
API though the Java programming language.
It requires libvirt >= @LIBVIRT_REQUIRED@
It requires libvirt >= @libvirt.required@
%package devel
Summary: Compressed Java source files for %{name}
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
Requires: libvirt-devel >= @LIBVIRT_REQUIRED@
Requires: pkgconfig
%package devel
Summary: Compressed Java source files for %{name}
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
%description devel
%description devel
Libvirt-java is a base framework allowing to use libvirt, the virtualization
API though the Java programming language. This is the development part needed
to build applications with Libvirt-java.
%package javadoc
Summary: Java documentation for %{name}
Group: Development/Documentation
......@@ -51,24 +53,17 @@ API documentation for %{name}.
%setup -q
%build
%configure --with-java-home=%{java_home}
# javac call is not parallelizable, as a result the same command is
# run N times in parallel if %{?_smp_mflags} is set up
make
# fix up the modification date of generated documentation
find doc -type f -newer ChangeLog | xargs touch -r ChangeLog
ant build docs
%install
rm -fr %{buildroot}
install -d -m0755 %{buildroot}%{_javadir}
install -d -m0755 %{buildroot}%{_javadocdir}/%{name}-%{version}
cp target/%{prefix}-%{version}.jar %{buildroot}%{_javadir}
%{__ln_s} %{_javadir}/%{prefix}-%{version}.jar %{buildroot}%{_javadir}/%{prefix}.jar
cp -r target/javadoc %{buildroot}%{_javadocdir}/%{name}-%{version}
make %{?_smp_mflags} DESTDIR=$RPM_BUILD_ROOT install
rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
rm -f $RPM_BUILD_ROOT%{_libdir}/*.a
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%clean
rm -rf %{buildroot}
......@@ -76,20 +71,21 @@ rm -rf %{buildroot}
%files
%defattr(-,root,root)
%doc AUTHORS COPYING NEWS README INSTALL
%{_libdir}/libvirt_jni*.so.*
%{_datadir}/java/*.jar
%{_javadir}/*.jar
%files devel
%defattr(-,root,root)
%doc src/*.java
%{_libdir}/libvirt_jni*.so
%{_libdir}/pkgconfig/*.pc
%doc src/test/java/test.java
%files javadoc
%defattr(-,root,root)
/usr/share/javadoc/%{name}-%{version}
%{_javadocdir}/%{name}-%{version}
%changelog
* Wed Jul 29 2009 Bryan Kearney <bkearney@redhat.com> - 0.3.0-1
- refactored the code to use jna (https://jna.dev.java.net/)
* Fri Jul 18 2008 Daniel Veillard <veillard@redhat.com> - 0.2.0-1
- new release 0.2.0
- finished cleanup of APIs
......
# Build must be done in org first
SUBDIRS=. jni
java_libvirt_source_files = \
org/libvirt/LibvirtException.java \
org/libvirt/Connect.java \
org/libvirt/ConnectAuthDefault.java \
org/libvirt/ConnectAuth.java \
org/libvirt/DomainBlockStats.java \
org/libvirt/DomainInfo.java \
org/libvirt/DomainInterfaceStats.java \
org/libvirt/Domain.java \
org/libvirt/ErrorException.java \
org/libvirt/Error.java \
org/libvirt/Network.java \
org/libvirt/NodeInfo.java \
org/libvirt/SchedBooleanParameter.java \
org/libvirt/SchedDoubleParameter.java \