Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GIR java-gnome WIP - week 29-30
diff --git a/build/faster b/build/faster
index dfb9f11..886d852 100755
--- a/build/faster
+++ b/build/faster
@@ -394,7 +394,7 @@ def generateTranslationAndJniLayers():
if not verbose:
redirect = "> /dev/null"
- runJavaClass("BindingsGenerator", "tmp/generator/:"+ config['XOM_JARS']+":"+config['JAXEN_JARS'], redirect)
+ runJavaClass("BindingsGenerator", "tmp/generator/:"+ config['XOM_JARS']+":"+config['JAXEN_JARS'], config['GIR_FILES']+" "+redirect)
touchFile(stamp)
diff --git a/configure b/configure
index ce13833..6b810dc 100755
--- a/configure
+++ b/configure
@@ -224,6 +224,56 @@ sub check_prereq (\@$$@) {
push (@$jararrayref, $found);
}
+sub check_multi_prereq (\@$$@) {
+ my ($jararrayref, $item, $package, @files) = @_;
+
+ output " - ".$item;
+
+ my $str;
+ my $tries = "";
+ my $notfound = "";
+
+ foreach my $file ( @files ) {
+ if ( ! -f "$file" ) {
+ $notfound = $file;
+ } else {
+ push(@$jararrayref, $file);
+ }
+ $tries .= ($tries ? ", or" : "" ) . "\n\t". basename($file) . "\t(looked in ".dirname($file).")";
+ }
+
+ if ( "$notfound" ) {
+ $str = "In order to build java-gnome, you need\n".$tries;
+ $str .= "\n\nwhich is part of the $item Java library.\n";
+ $str .= "On a ".ucfirst($os)." system, you should be able to get this requirement by doing:\n\n";
+ $str .= " # ";
+
+ if ($os eq "gentoo") {
+ $str .= "emerge";
+ } elsif ($os eq "debian") {
+ $str .= "apt-get install";
+ } elsif ($os eq "fedora") {
+ $str .= "yum install";
+ } elsif ($os eq "suse") {
+ $str .= "zypper install";
+ } elsif ($os eq "arch") {
+ $str .= "pacman -S";
+ } elsif ($os eq "mandriva") {
+ $str .= "urpmi";
+ } elsif ($os eq "solaris") {
+ $str .= "pkgadd";
+ } elsif ($os eq "slackware") {
+ $str .= "slackpkg install";
+ } else {
+ $str .= "[FIXME fetch and install command for this OS]";
+ }
+ $str .= " $package";
+
+ bail "not found!", $str;
+ }
+ print "found\n";
+}
+
# if we return without setting the variable pointed at by scalarref, its being
# empty will be used later to indicate that this compiler wasn't present /
# usable.
@@ -754,7 +804,6 @@ if ($os eq "gentoo") {
"junit",
"/usr/share/java/junit.jar");
-
} elsif ($os eq "solaris") {
check_prereq(@junit_jars,
@@ -776,7 +825,6 @@ if ($os eq "gentoo") {
"junit",
"/usr/share/java/junit.jar");
-
} else {
bail "failed!", "This OS not configured with defaults!\nTHIS IS AN INTERNAL ERROR, PLEASE FILE A BUG.";
}
@@ -786,6 +834,7 @@ if ($os eq "gentoo") {
# Paths mentioned here, are relative to the prefix.
my @gnomedev_libs;
+my @gir_files;
output "\nCheck for required system libraries:\n";
@@ -907,6 +956,23 @@ if ($os eq "gentoo") {
# "GtkSpell",
# "libgtkspell-dev");
+ check_system_library(@gnomedev_libs,
+ "gobject-introspection-1.0",
+ "GObject Introspection",
+ "libgirepository1.0-dev");
+
+ check_multi_prereq(@gir_files,
+ "GObject Introspection files",
+ "libgirepository1.0-dev",
+ "/usr/share/gir-1.0/Atk-1.0.gir",
+ "/usr/share/gir-1.0/cairo-1.0.gir",
+ "/usr/share/gir-1.0/Gdk-3.0.gir",
+ "/usr/share/gir-1.0/GdkPixbuf-2.0.gir",
+ "/usr/share/gir-1.0/GLib-2.0.gir",
+ "/usr/share/gir-1.0/Gtk-3.0.gir",
+ "/usr/share/gir-1.0/Notify-0.7.gir",
+ "/usr/share/gir-1.0/Pango-1.0.gir",
+ "/usr/share/gir-1.0/Rsvg-2.0.gir");
} elsif ($os eq "arch") {
check_system_library(@gnomedev_libs,
@@ -1099,6 +1165,7 @@ HERE
print CONFIG "JUNIT_JARS=".join(":",@junit_jars)."\n";
print CONFIG "XOM_JARS=".join(":",@xom_jars)."\n";
print CONFIG "JAXEN_JARS=".join(":",@jaxen_jars)."\n";
+print CONFIG "GIR_FILES=".join(" ",@gir_files)."\n";
output "\n";
diff --git a/src/generator/BindingsGenerator.java b/src/generator/BindingsGenerator.java
index c65e9e0..bcea838 100644
--- a/src/generator/BindingsGenerator.java
+++ b/src/generator/BindingsGenerator.java
@@ -117,8 +117,8 @@ public class BindingsGenerator
private static final boolean USE_INTROSPECTION = true;
public static void main(String[] args) throws IOException {
- if (USE_INTROSPECTION) {
- runGeneratorOutputIntrospectionToFiles(new File("src/gir/"), new File("generated/bindings/"));
+ if (USE_INTROSPECTION && (args.length >= 1)) {
+ runGeneratorOutputIntrospectionToFiles(args, new File("generated/bindings/"));
} else {
runGeneratorOutputToFiles(new File("src/defs/"), new File("generated/bindings/"));
}
@@ -244,7 +244,8 @@ public class BindingsGenerator
* parser and subsequent runs of the bindings code generators, but it is
* still an intermediate form.
*/
- private static void runGeneratorOutputIntrospectionToFiles(final File sourceDir, final File outputDir) {
+ private static void runGeneratorOutputIntrospectionToFiles(final String[] introspectionFiles,
+ final File outputDir) {
final File[] files;
final Map<String, DefsFile> all;
IntrospectionParser parser;
@@ -252,11 +253,10 @@ public class BindingsGenerator
DefsFile data;
PrintWriter typeMapping;
- files = sourceDir.listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.endsWith(".gir");
- }
- });
+ files = new File[introspectionFiles.length];
+ for (int i = 0; i < files.length; i++) {
+ files[i] = new File(introspectionFiles[i]);
+ }
all = new HashMap<String, DefsFile>();
diff --git a/src/generator/com/operationaldynamics/defsparser/IntrospectionParser.java b/src/generator/com/operationaldynamics/defsparser/IntrospectionParser.java
index 82a30f0..5900cbf 100644
--- a/src/generator/com/operationaldynamics/defsparser/IntrospectionParser.java
+++ b/src/generator/com/operationaldynamics/defsparser/IntrospectionParser.java
@@ -1,5 +1,3 @@
-package com.operationaldynamics.defsparser;
-
/*
* java-gnome, a UI library for writing GTK and GNOME programs from Java!
*
@@ -18,6 +16,7 @@ package com.operationaldynamics.defsparser;
* see http://www.gnu.org/licenses/. The authors of this program may be
* contacted through http://java-gnome.sourceforge.net/.
*/
+package com.operationaldynamics.defsparser;
/*
* This code started life as prototype written during the Google Summer of Code
@@ -26,9 +25,10 @@ package com.operationaldynamics.defsparser;
* .defs parser being used by java-gnome for several years.
*/
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -43,6 +43,8 @@ import nu.xom.Elements;
import nu.xom.ParsingException;
import nu.xom.ValidityException;
+import com.operationaldynamics.codegen.BlacklistedThing;
+import com.operationaldynamics.codegen.Thing;
import com.operationaldynamics.driver.DefsFile;
import com.operationaldynamics.driver.ImproperDefsFileException;
@@ -66,6 +68,10 @@ public class IntrospectionParser
private static final Properties packageOverrides;
+ private static final Properties nameOverrides;
+
+ private static final List<String> whitelist;
+
private File introspectionFile;
static {
@@ -76,11 +82,19 @@ public class IntrospectionParser
packageOverrides = new Properties();
try {
packageOverrides.load(new FileInputStream("src/generator/packages-override.properties"));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
} catch (IOException e) {
- e.printStackTrace();
+ System.err.println("How come we can't open a file for reading?\n" + e);
+ }
+
+ nameOverrides = new Properties();
+ try {
+ nameOverrides.load(new FileInputStream("src/generator/names-override.properties"));
+ } catch (IOException e) {
+ System.err.println("How come we can't open a file for reading?\n" + e);
}
+
+ whitelist = new ArrayList<String>();
+ loadWhitelist();
}
/**
@@ -95,6 +109,36 @@ public class IntrospectionParser
}
/**
+ * Load the whitelist of objects/enumerations/flags/boxeds/interfaces that
+ * we want to use.
+ */
+ private static final void loadWhitelist() {
+ final BufferedReader reader;
+ String line;
+
+ try {
+ reader = new BufferedReader(new FileReader("src/generator/whitelist.txt"));
+
+ while ((line = reader.readLine()) != null) {
+ whitelist.add(line);
+ }
+ } catch (IOException e) {
+ System.err.println("How come we can't open a file for reading?\n" + e);
+ }
+ }
+
+ /**
+ * Return whether the given object is whitelisted.
+ *
+ * @param cName
+ * the C name of the object.
+ * @return true if the object is whitelisted or false.
+ */
+ private static final boolean isWhitelisted(String cName) {
+ return whitelist.contains(cName);
+ }
+
+ /**
* Return the Java package name to use for the given namespace.
*
* @param introspectionNamespace
@@ -110,6 +154,21 @@ public class IntrospectionParser
}
/**
+ * Return the Java name to use for the given object name.
+ *
+ * @param name
+ * the GObject name.
+ * @return the Java name to use.
+ */
+ private static final String getActualJavaName(String name) {
+ final String javaName;
+
+ javaName = nameOverrides.getProperty(name);
+
+ return ((javaName == null) ? name : javaName);
+ }
+
+ /**
* Return a String representation of the parent of the given object.
*
* @param object
@@ -379,10 +438,18 @@ public class IntrospectionParser
final Elements constructors, methods, signals;
final List<Block> blocks;
final List<String[]> characteristics;
+ final String cName;
object = objects.get(objectIndex);
blocks = new ArrayList<Block>();
characteristics = new ArrayList<String[]>();
+ cName = object.getAttributeValue("type", C_NAMESPACE) == null ? object.getAttributeValue(
+ "type-name", GLIB_NAMESPACE) : object.getAttributeValue("type", C_NAMESPACE);
+
+ if (!isWhitelisted(cName)) {
+ Thing.register(new BlacklistedThing(cName));
+ continue;
+ }
/*
* Retrieve constructors, methods and signals.
@@ -407,8 +474,7 @@ public class IntrospectionParser
});
characteristics.add(new String[] {
"c-name",
- object.getAttributeValue("type", C_NAMESPACE) == null ? object.getAttributeValue(
- "type-name", GLIB_NAMESPACE) : object.getAttributeValue("type", C_NAMESPACE)
+ cName
});
/*
@@ -421,7 +487,8 @@ public class IntrospectionParser
* Build the object blocks based on the info we have.
*/
- blocks.add(new ObjectBlock(object.getAttributeValue("name"), characteristics, null));
+ blocks.add(new ObjectBlock(getActualJavaName(object.getAttributeValue("name")),
+ characteristics, null));
/*
* Parse all constructors data.
@@ -562,7 +629,7 @@ public class IntrospectionParser
* Generate the defs file definition for the given object.
*/
- defs.put(object.getAttributeValue("name"),
+ defs.put(getActualJavaName(object.getAttributeValue("name")),
new DefsFile(blocks.toArray(new Block[0])));
} catch (ImproperDefsFileException e) {
e.printStackTrace();
@@ -578,10 +645,17 @@ public class IntrospectionParser
final Elements methods, signals;
final List<Block> blocks;
final List<String[]> characteristics;
+ final String cName;
interfaze = interfaces.get(interfaceIndex);
blocks = new ArrayList<Block>();
characteristics = new ArrayList<String[]>();
+ cName = interfaze.getAttributeValue("type", C_NAMESPACE);
+
+ if (!isWhitelisted(cName)) {
+ Thing.register(new BlacklistedThing(cName));
+ continue;
+ }
/*
* Retrieve constructors, methods and signals.
@@ -601,14 +675,15 @@ public class IntrospectionParser
});
characteristics.add(new String[] {
"c-name",
- interfaze.getAttributeValue("type", C_NAMESPACE)
+ cName
});
/*
* Build the object blocks based on the info we have.
*/
- blocks.add(new InterfaceBlock(interfaze.getAttributeValue("name"), characteristics));
+ blocks.add(new InterfaceBlock(getActualJavaName(interfaze.getAttributeValue("name")),
+ characteristics));
/*
* Parse all methods data.
@@ -693,7 +768,7 @@ public class IntrospectionParser
* Generate the defs file definition for the given object.
*/
- defs.put(interfaze.getAttributeValue("name"),
+ defs.put(getActualJavaName(interfaze.getAttributeValue("name")),
new DefsFile(blocks.toArray(new Block[0])));
} catch (ImproperDefsFileException e) {
e.printStackTrace();
@@ -709,12 +784,19 @@ public class IntrospectionParser
final Elements valuesList;
final List<Block> blocks;
final List<String[]> characteristics, values;
+ final String cName;
enumeration = enumerations.get(enumerationIndex);
valuesList = enumeration.getChildElements("member", CORE_NAMESPACE);
blocks = new ArrayList<Block>();
characteristics = new ArrayList<String[]>();
values = new ArrayList<String[]>();
+ cName = enumeration.getAttributeValue("type", C_NAMESPACE);
+
+ if (!isWhitelisted(cName)) {
+ Thing.register(new BlacklistedThing(cName));
+ continue;
+ }
/*
* Get object first characteristics: module it belongs to and
@@ -727,7 +809,7 @@ public class IntrospectionParser
});
characteristics.add(new String[] {
"c-name",
- enumeration.getAttributeValue("type", C_NAMESPACE)
+ cName
});
for (int valueIndex = 0; valueIndex < valuesList.size(); valueIndex++) {
@@ -758,15 +840,16 @@ public class IntrospectionParser
});
}
- blocks.add(new EnumBlock(enumeration.getAttributeValue("name"), characteristics, values));
+ blocks.add(new EnumBlock(getActualJavaName(enumeration.getAttributeValue("name")),
+ characteristics, values));
try {
/*
* Generate the defs file definition for the given object.
*/
- defs.put(enumeration.getAttributeValue("name"),
- new DefsFile(blocks.toArray(new Block[0])));
+ defs.put(getActualJavaName(enumeration.getAttributeValue("name")), new DefsFile(
+ blocks.toArray(new Block[0])));
} catch (ImproperDefsFileException e) {
e.printStackTrace();
}
@@ -781,12 +864,19 @@ public class IntrospectionParser
final Elements valuesList;
final List<Block> blocks;
final List<String[]> characteristics, values;
+ final String cName;
flag = flags.get(flagIndex);
valuesList = flag.getChildElements("member", CORE_NAMESPACE);
blocks = new ArrayList<Block>();
characteristics = new ArrayList<String[]>();
values = new ArrayList<String[]>();
+ cName = flag.getAttributeValue("type", C_NAMESPACE);
+
+ if (!isWhitelisted(cName)) {
+ Thing.register(new BlacklistedThing(cName));
+ continue;
+ }
/*
* Get object first characteristics: module it belongs to and
@@ -799,7 +889,7 @@ public class IntrospectionParser
});
characteristics.add(new String[] {
"c-name",
- flag.getAttributeValue("type", C_NAMESPACE)
+ cName
});
for (int valueIndex = 0; valueIndex < valuesList.size(); valueIndex++) {
@@ -824,7 +914,8 @@ public class IntrospectionParser
}
if (values.size() > 0) {
- blocks.add(new FlagsBlock(flag.getAttributeValue("name"), characteristics, values));
+ blocks.add(new FlagsBlock(getActualJavaName(flag.getAttributeValue("name")),
+ characteristics, values));
try {
/*
@@ -832,7 +923,7 @@ public class IntrospectionParser
* object.
*/
- defs.put(flag.getAttributeValue("name"),
+ defs.put(getActualJavaName(flag.getAttributeValue("name")),
new DefsFile(blocks.toArray(new Block[0])));
} catch (ImproperDefsFileException e) {
e.printStackTrace();
@@ -849,13 +940,20 @@ public class IntrospectionParser
final Elements methods;
final List<Block> blocks;
final List<String[]> characteristics;
- final String boxedName;
+ final String boxedName, cName;
boxed = boxeds.get(boxedIndex);
boxedName = boxed.getAttributeValue("name");
+ cName = boxed.getAttributeValue("type", C_NAMESPACE);
+
+ if (!isWhitelisted(cName)) {
+ Thing.register(new BlacklistedThing(cName));
+ continue;
+ }
/*
- * If this boxed thing is internal just ignore it.
+ * If this boxed thing is internal or must be skipped just
+ * ignore it.
*/
if (boxedName.endsWith("Class") || boxedName.endsWith("Private")) {
@@ -877,10 +975,10 @@ public class IntrospectionParser
});
characteristics.add(new String[] {
"c-name",
- boxed.getAttributeValue("type", C_NAMESPACE)
+ cName
});
- blocks.add(new BoxedBlock(boxedName, characteristics));
+ blocks.add(new BoxedBlock(getActualJavaName(boxedName), characteristics));
/*
* Retrieve all info about methods.
@@ -935,7 +1033,7 @@ public class IntrospectionParser
* Generate the defs file definition for the given boxed.
*/
- defs.put(boxedName, new DefsFile(blocks.toArray(new Block[0])));
+ defs.put(getActualJavaName(boxedName), new DefsFile(blocks.toArray(new Block[0])));
} catch (ImproperDefsFileException e) {
e.printStackTrace();
}
diff --git a/src/generator/packages-override.properties b/src/generator/packages-override.properties
index d9e3aaf..9e50d25 100644
--- a/src/generator/packages-override.properties
+++ b/src/generator/packages-override.properties
@@ -4,8 +4,5 @@
# namespace_name = new_namespace_name
GdkPixbuf = Gdk
-GdkX11 = Gdk
-GtkSource = Sourceview
-PangoCairo = Cairo
-PangoFT2 = Pango
-PangoXft = Pango
\ No newline at end of file
+GLib = Glib
+GtkSource = Sourceview
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.