java-gobject-introspection r79 - in trunk: src src/org/gnome/gir/compiler src/org/gnome/gir/gobject src/org/gnome/gir/repository stub-examples
- From: walters svn gnome org
- To: svn-commits-list gnome org
- Subject: java-gobject-introspection r79 - in trunk: src src/org/gnome/gir/compiler src/org/gnome/gir/gobject src/org/gnome/gir/repository stub-examples
- Date: Wed, 15 Oct 2008 00:29:54 +0000 (UTC)
Author: walters
Date: Wed Oct 15 00:29:54 2008
New Revision: 79
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=79&view=rev
Log:
Update for a versioned world
Modified:
trunk/src/jgir-compile-all.in
trunk/src/org/gnome/gir/compiler/CodeFactory.java
trunk/src/org/gnome/gir/gobject/GType.java
trunk/src/org/gnome/gir/repository/GIntrospectionAPI.java
trunk/src/org/gnome/gir/repository/Repository.java
trunk/stub-examples/Test.java
Modified: trunk/src/jgir-compile-all.in
==============================================================================
--- trunk/src/jgir-compile-all.in (original)
+++ trunk/src/jgir-compile-all.in Wed Oct 15 00:29:54 2008
@@ -1,2 +1,27 @@
-#!/bin/sh
-exec ${DEBUG} java ${JAVA_OPTS} -cp "@CLASSPATH@" org.gnome.gir.compiler.CodeFactory "$@"
\ No newline at end of file
+#!/usr/bin/python
+import os,sys,subprocess
+
+classpath="@CLASSPATH@"
+datadirs = os.environ.get('XDG_DATA_DIRS', '/usr/share')
+nsversions = []
+for dirname in datadirs.split(':'):
+ repodir = os.path.join(dirname, 'girepository')
+ if not os.access(repodir, os.W_OK):
+ continue
+ for name in os.listdir(repodir):
+ if not name.endswith('.typelib'):
+ continue
+ base,_ = os.path.splitext(name)
+ nsversions.append(base)
+ print "%r" % (base, )
+ ns,version = base.rsplit('-', 1)
+ subprocess.check_call(['java', '-cp', classpath, 'org.gnome.gir.compiler.CodeFactory', ns, version],
+ stdout=sys.stdout,
+ stderr=sys.stderr,
+ close_fds=True)
+subprocess.check_call(['java', '-cp', classpath, 'org.gnome.gir.compiler.CodeFactory',
+ '--verify', ','.join(nsversions)],
+ stdout=sys.stdout,
+ stderr=sys.stderr,
+ close_fds=True)
+
Modified: trunk/src/org/gnome/gir/compiler/CodeFactory.java
==============================================================================
--- trunk/src/org/gnome/gir/compiler/CodeFactory.java (original)
+++ trunk/src/org/gnome/gir/compiler/CodeFactory.java Wed Oct 15 00:29:54 2008
@@ -152,7 +152,6 @@
}
private Type typeFromInfo(BaseInfo info) {
- requireNamespaceOf(info);
/* Unfortunately, flags are best mapped as plain Integer for now */
if (info instanceof FlagsInfo)
return Type.getObjectType("java/lang/Integer");
@@ -234,6 +233,8 @@
public static Type toJavaRef(TypeTag tag) {
Type t = toJava(tag);
+ if (t == null)
+ return null;
if (t.equals(Type.INT_TYPE))
return Type.getType(IntByReference.class);
if (t.equals(Type.LONG_TYPE))
@@ -286,10 +287,7 @@
private Type getCallableReturn(CallableInfo callable) {
TypeInfo info = callable.getReturnType();
if (info.getTag().equals(TypeTag.INTERFACE)) {
- if (!requireNamespaceOf(info.getInterface()))
- return Type.getType(Pointer.class);
- else
- return typeFromInfo(info);
+ return typeFromInfo(info);
}
return toJava(info.getTag());
}
@@ -316,12 +314,14 @@
private static abstract class ClassCompilation {
String namespace;
+ String nsversion;
String baseName;
String internalName;
ClassVisitor writer;
private ClassWriter realWriter;
public ClassCompilation(String namespace, String baseName) {
this.namespace = namespace;
+ this.nsversion = Repository.getDefault().getNamespaceVersion(namespace);
this.baseName = baseName;
this.internalName = GType.getInternalName(namespace, baseName);
this.realWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
@@ -1078,7 +1078,6 @@
BaseInfo parent = info.getParent();
String parentInternalName;
- requireNamespaceOf(parent);
parentInternalName = getInternalNameMapped(parent);
String[] interfaces = null;
@@ -1338,7 +1337,7 @@
logger.warning(String.format("Unhandled argument %s in callable %s", arg, si.getIdentifier()));
return null;
}
- if (tag.equals(TypeTag.ARRAY)) {
+ if (tag.equals(TypeTag.ARRAY) && arg.getDirection().equals(Direction.IN)) {
int lenIdx = arg.getType().getArrayLength();
if (lenIdx >= 0) {
/* FIXME - remove this hack when the repository is fixed */
@@ -1908,15 +1907,11 @@
compilation.close();
}
- private boolean requireNamespaceOf(BaseInfo info) {
- return requireNamespace(info.getNamespace());
- }
-
- private boolean requireNamespace(String namespace) {
+ private boolean requireNamespace(String namespace, String version) {
if (alreadyCompiled.contains(namespace))
return true;
try {
- repo.require(namespace);
+ repo.require(namespace, version);
} catch (GErrorException e) {
if (!loadFailed.contains(namespace)) {
logger.log(Level.SEVERE, "Failed to load namespace=" + namespace, e);
@@ -2018,6 +2013,9 @@
fv = internals.writer.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "namespace", "Ljava/lang/String;", null, globals.namespace);
fv.visitEnd();
+
+ fv = internals.writer.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "nsversion", "Ljava/lang/String;", null, globals.nsversion);
+ fv.visitEnd();
fv = internals.writer.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "invocationOptions",
"Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/Object;Ljava/lang/Object;>;", null);
@@ -2086,16 +2084,18 @@
mv.visitMethodInsn(INVOKESTATIC, "org/gnome/gir/repository/Repository", "getDefault", "()Lorg/gnome/gir/repository/Repository;");
mv.visitLdcInsn(globals.namespace);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/gnome/gir/repository/Repository", "requireNoFail", "(Ljava/lang/String;)V");
+ mv.visitLdcInsn(globals.nsversion);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/gnome/gir/repository/Repository", "requireNoFail",
+ Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { getType(String.class), getType(String.class) }));
globals.clinit = mv;
}
- private void compileNamespaceSingle(String namespace) {
+ private void compileNamespaceSingle(String namespace, String version) {
alreadyCompiled.add(namespace);
try {
- repo.require(namespace);
+ repo.require(namespace, version);
logger.info("Loaded typelib from " + repo.getTypelibPath(namespace));
} catch (GErrorException e) {
throw new RuntimeException(e);
@@ -2118,8 +2118,8 @@
global.close();
}
- private List<ClassCompilation> compileNamespace(String namespace) {
- compileNamespaceSingle(namespace);
+ private List<ClassCompilation> compileNamespace(String namespace, String version) {
+ compileNamespaceSingle(namespace, version);
return finish();
}
@@ -2141,8 +2141,8 @@
while (pendingCompilation.size() > 0) {
String pending = pendingCompilation.iterator().next();
logger.info("Namespace: " + pending);
- requireNamespace(pending);
- compileNamespaceSingle(pending);
+ requireNamespace(pending, null);
+ compileNamespaceSingle(pending, null);
pendingCompilation.remove(pending);
}
logger.info("Compiled " + writers.size() + " info objects");
@@ -2170,9 +2170,9 @@
}
}
- public static List<ClassCompilation> compile(Repository repo, String namespace) {
+ public static List<ClassCompilation> compile(Repository repo, String namespace, String version) {
CodeFactory cf = new CodeFactory(repo);
- return cf.compileNamespace(namespace);
+ return cf.compileNamespace(namespace, version);
}
public static ClassLoader getLoader(List<ClassCompilation> stubs) {
@@ -2194,17 +2194,17 @@
};
}
- public static File generateJar(String namespace, String version) throws GErrorException, IOException {
+ public static File compile(String namespace, String version) throws GErrorException, IOException {
Repository repo = Repository.getDefault();
File destFile = null;
- repo.require(namespace);
+ repo.require(namespace, version);
String typelibPathName = repo.getTypelibPath(namespace);
File typelibPath = new File(typelibPathName);
long typelibLastModified = typelibPath.lastModified();
if (destFile == null) {
- destFile = new File(typelibPath.getParent(), namespace+".jar");
+ destFile = getJarPath(namespace);
logger.info("Will install to: " + destFile);
}
@@ -2213,9 +2213,9 @@
return destFile;
}
- logger.info("Compiling namespace: " + namespace);
+ logger.info(String.format("Compiling namespace: %s version: %s", namespace, version));
List<ClassCompilation> stubs;
- stubs = CodeFactory.compile(repo, namespace);
+ stubs = CodeFactory.compile(repo, namespace, version);
Set<String> classNames = new HashSet<String>();
ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(destFile));
@@ -2235,10 +2235,10 @@
public static void verifyJarFiles(Set<File> jarPaths) throws Exception {
List<URL> urls = new ArrayList<URL>();
Map<String, InputStream> allClassnames = new HashMap<String, InputStream>();
- logger.info("Verifying " + jarPaths.size() + " jar paths");
List<ZipFile> zips = new ArrayList<ZipFile>();
for (File jarPath : jarPaths) {
urls.add(jarPath.toURI().toURL());
+ logger.info("Verifing " + jarPath);
ZipFile zf = new ZipFile(jarPath);
for (Enumeration<? extends ZipEntry> e = zf.entries(); e.hasMoreElements();) {
ZipEntry entry = e.nextElement();
@@ -2282,42 +2282,51 @@
logger.info(String.format("Verified %d classes", nClasses));
}
- public static Set<File> compileAll() throws Exception {
- /* Freedesktop/Unix specific */
- String datadirsPath = System.getenv("XDG_DATA_DIRS");
- String dataDirs[];
- if (datadirsPath != null)
- dataDirs = datadirsPath.split(":");
- else
- dataDirs = new String[] { "/usr/share" };
- Set<File> jarPaths = new HashSet<File>();
- for (String dir : dataDirs) {
- File typelibsDir = new File(dir, "girepository");
- if (!typelibsDir.canWrite()) // Exists and writable
+ public static File getJarPath(String namespace) {
+ File typelibPath = new File(Repository.getDefault().getTypelibPath(namespace));
+ String version = Repository.getDefault().getNamespaceVersion(namespace);
+ return new File(typelibPath.getParent(), String.format("%s-%s.jar", namespace, version));
+ }
+
+ private static boolean namespaceIsExcluded(String namespace) {
+ return namespace.equals("GLib") || namespace.equals("GObject");
+ }
+
+ public static void verifyAll(String[] nsversions) throws Exception {
+ for (String nsversion : nsversions) {
+ int dashIdx = nsversion.lastIndexOf('-');
+ String namespace = nsversion.substring(0, dashIdx);
+ String version = nsversion.substring(dashIdx+1);
+
+ if (namespaceIsExcluded(namespace))
continue;
- for (String filename : typelibsDir.list()) {
- String namespace;
- String version = null;
- int dashIdx = filename.lastIndexOf('-');
- int dot = filename.lastIndexOf('.'); // for typelib
- if (dashIdx < 0)
- namespace = filename.substring(0, dot);
- else {
- namespace = filename.substring(0, dashIdx);
- version = filename.substring(dashIdx+1, dot);
- }
- /* Skip GObject+below for now, we manually bind */
- if (!(namespace.equals("GLib") || namespace.equals("GObject"))) {
- jarPaths.add(generateJar(namespace, version));
+ Set<File> jarPaths = new HashSet<File>();
+
+ Repository.getDefault().require(namespace, version);
+ jarPaths.add(getJarPath(namespace));
+
+ String[] deps = Repository.getDefault().getDependencies(namespace);
+ if (deps != null) {
+ for (String dep : deps) {
+ String depNamespace = dep.substring(0, dep.lastIndexOf('-'));
+ if (!namespaceIsExcluded(depNamespace))
+ jarPaths.add(getJarPath(depNamespace));
}
}
+ verifyJarFiles(jarPaths);
}
- return jarPaths;
}
public static void main(String[] args) throws Exception {
GObjectAPI.gobj.g_type_init();
- verifyJarFiles(compileAll());
+ if (args[0].equals("--verify"))
+ verifyAll(args[1].split(","));
+ else {
+ String namespace = args[0];
+ String version = args[1];
+ if (!namespaceIsExcluded(namespace))
+ compile(namespace, version);
+ }
}
}
Modified: trunk/src/org/gnome/gir/gobject/GType.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GType.java (original)
+++ trunk/src/org/gnome/gir/gobject/GType.java Wed Oct 15 00:29:54 2008
@@ -89,10 +89,10 @@
String[] glibPointerUnmapped = new String[] { "Mutex", "Cond", "FreeFunc", "DestroyNotify", "MarkupParser",
"SpawnChildSetupFunc", "SourceFunc", "Node", "CompareFunc", "KeyFile", "PtrArray", "Func",
- "ThreadPool", "Source", "CompareDataFunc", "Array", "Data", "DataSet" };
+ "ThreadPool", "Source", "CompareDataFunc", "Array", "Data", "DataSet", "Date", "IOChannel" };
for (String unmapped : glibPointerUnmapped)
put("GLib." + unmapped, "com/sun/jna/Pointer");
- String[] glibIntegerUnmapped = new String[] { "SpawnFlags", "SeekType", };
+ String[] glibIntegerUnmapped = new String[] { "SpawnFlags", "SeekType", "IOCondition" };
for (String unmapped : glibIntegerUnmapped)
put("GLib." + unmapped, "java/lang/Integer");
Modified: trunk/src/org/gnome/gir/repository/GIntrospectionAPI.java
==============================================================================
--- trunk/src/org/gnome/gir/repository/GIntrospectionAPI.java (original)
+++ trunk/src/org/gnome/gir/repository/GIntrospectionAPI.java Wed Oct 15 00:29:54 2008
@@ -29,8 +29,6 @@
import org.gnome.gir.gobject.GType;
import org.gnome.gir.gobject.GTypeMapper;
-import org.gnome.gir.gobject.ZeroTerminatedArray;
-import org.gnome.gir.gobject.annotation.RepositoryId;
import com.sun.jna.Library;
import com.sun.jna.Native;
@@ -49,10 +47,12 @@
Repository g_irepository_get_default();
int g_irepository_get_n_infos(Repository repo, String namespace);
boolean g_irepository_is_registered (Repository repository, String namespace);
- boolean g_irepository_require(Repository repo, String namespace, int flags, PointerByReference error);
+ boolean g_irepository_require(Repository repo, String namespace, String version, int flags, PointerByReference error);
BaseInfo g_irepository_find_by_name(Repository repo, String namespace, String name);
BaseInfo g_irepository_find_by_gtype(Repository repository, NativeLong g_type);
- @RepositoryId(namespace="girepository", name="get_namespaces") ZeroTerminatedArray<String> g_irepository_get_namespaces(Repository repo);
+ String[] g_irepository_get_namespaces(Repository repo);
+ String[] g_irepository_get_dependencies(Repository repo, String namespace);
+ String g_irepository_get_version(Repository repo, String namespace);
BaseInfo g_irepository_get_info(Repository repo, String namespace, int idx);
String g_irepository_get_shared_library(Repository repository, String namespace);
String g_irepository_get_typelib_path(Repository repository, String namespace);
Modified: trunk/src/org/gnome/gir/repository/Repository.java
==============================================================================
--- trunk/src/org/gnome/gir/repository/Repository.java (original)
+++ trunk/src/org/gnome/gir/repository/Repository.java Wed Oct 15 00:29:54 2008
@@ -1,11 +1,8 @@
package org.gnome.gir.repository;
-import java.util.List;
-
import org.gnome.gir.gobject.GErrorException;
import org.gnome.gir.gobject.GErrorStruct;
import org.gnome.gir.gobject.GObjectGlobals;
-import org.gnome.gir.gobject.ZeroTerminatedArray;
import com.sun.jna.NativeLong;
import com.sun.jna.PointerType;
@@ -21,16 +18,16 @@
return GIntrospectionAPI.gi.g_irepository_find_by_gtype(this, g_type);
}
- public void require(String namespace) throws GErrorException {
+ public void require(String namespace, String version) throws GErrorException {
PointerByReference error = new PointerByReference(null);
- if (!GIntrospectionAPI.gi.g_irepository_require(this, namespace, 0, error)) {
+ if (!GIntrospectionAPI.gi.g_irepository_require(this, namespace, version, 0, error)) {
throw new GErrorException(new GErrorStruct(error.getValue()));
}
}
- public void requireNoFail(String namespace) {
+ public void requireNoFail(String namespace, String version) {
try {
- require(namespace);
+ require(namespace, version);
} catch (GErrorException e) {
throw new RuntimeException(e);
}
@@ -49,20 +46,21 @@
return GIntrospectionAPI.gi.g_irepository_get_shared_library(this, namespace);
}
+ public String[] getDependencies(String namespace) {
+ return GIntrospectionAPI.gi.g_irepository_get_dependencies(this, namespace);
+ }
+
public String getTypelibPath(String namespace) {
return GIntrospectionAPI.gi.g_irepository_get_typelib_path(this, namespace);
- }
-
- public List<String> getNamespaces() {
- ZeroTerminatedArray<String> z = GIntrospectionAPI.gi.g_irepository_get_namespaces(this);
- List<String> ret = z.convert(String.class);
- z.dispose(Transfer.EVERYTHING);
- return ret;
}
public boolean isRegistered(String targetNamespace) {
return GIntrospectionAPI.gi.g_irepository_is_registered(this, targetNamespace);
- }
+ }
+
+ public String getNamespaceVersion(String namespace) {
+ return GIntrospectionAPI.gi.g_irepository_get_version(this, namespace);
+ }
static GIntrospectionAPI getNativeLibrary() {
return GIntrospectionAPI.gi;
Modified: trunk/stub-examples/Test.java
==============================================================================
--- trunk/stub-examples/Test.java (original)
+++ trunk/stub-examples/Test.java Wed Oct 15 00:29:54 2008
@@ -119,6 +119,7 @@
public static final NativeLibrary library = NativeLibrary.getInstance("gtk-2.0");
public static final Repository repo = Repository.getDefault();
public static final String namespace = "Gtk";
+ public static final String nsversion = "2.0";
public static final Map<Object,Object> invocationOptions = new HashMap<Object,Object>() {
private static final long serialVersionUID = 1L;
@@ -128,7 +129,7 @@
};
static {
- Repository.getDefault().requireNoFail(namespace);
+ Repository.getDefault().requireNoFail(namespace, nsversion);
}
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]