Releases: jwharm/java-gi
0.13.1
Java-GI 0.13.1 is a bugfix release.
Fixes
- A bug that crashed the
java-gicommand-line tool has been fixed (#309, thanks to @Daru-san for reporting), and the tool has been updated so that the generatedmodule-info.javaandbuild.gradlefiles work with the new domain name and module structure introduced in Java-GI 0.13.0. - The
org.javagi.util.Intlclass, introduced with Java-GI 0.13.0, was not usable with the GNOME Flatpak runtime because it couldn't findlibgettextlib.so. This has also been fixed.
Availability and dependencies:
- The new release is available on Maven Central.
- Java-GI requires OpenJDK 22 or later.
- The bindings are based on the GNOME 48 libraries. These need to be installed.
Full Changelog: 0.13.0...0.13.1
0.13.0
Java-GI 0.13.0 is a major new feature and bugfix release. There were no changes since 0.13.0-RC1.
All changes, fixes and other improvements in this release are listed in the release notes of Java-GI 0.13.0-RC1.
Availability and dependencies:
- The new release is available on Maven Central.
- Java-GI requires OpenJDK 22 or later.
- The bindings are based on the GNOME 48 libraries. These need to be installed.
Full Changelog: 0.12.2...0.13.0
0.13.0-RC1
Java-GI 0.13.0-RC1 contains a number of enhancements and bugfixes. It is the first release candidate for the upcoming 0.13.0 release.
Highlights
New domain name
One of the most visible changes in this release is the new java-gi.org domain name (#238). The Maven artifact coordinates have a new group-id, and all Java-GI packages and modules have a new name. This will break the code for all existing users, but should be easy to fix:
- Change the Maven group-id from
io.github.jwharm.javagitoorg.java-gi(mind the dash) in your dependency declarations; - Change all import statements starting of
io.github.jwharm.javagitoorg.javagi.
Reorganized modules & packages
#270: Many packages have been combined in modules:
- GLib, GObject, GIO and GModule are now bundled in one module
org.gnome.glib - Gsk, Gdk, Graphene and Gtk are bundled in
org.gnome.gtk - All GStreamer modules are in
org.freedesktop.gstreamer - All WebKit modules are in
org.webkitgtk - All regression test modules are in
org.gnome.gobjectintrospectiontests
#259: The package names of WebKitGTK bindings have been changed from org.gnome.webkit to org.webkitgtk. Users of the Java-GI WebkitGTK bindings will have to update the package names as described in #259.
Last but not least, there are new bindings for LibRsvg, GstApp and LibSecret.
GNOME version
The bindings of Java-GI 0.13.0-RC1 are based on GNOME 48 (the same as the previous release 0.12.2).
An update to GNOME 49 will follow in a future release.
Improvements
- Java-GI will now read the input value of an
Out<>parameter in Java, and set it as the initial value of the out-parameter of a native function.- This should be completely null-safe and automatically unbox primitive values, but still, if you encounter any issues with this, please log a GitHub issue.
- Java-GI now builds "library" and "test" modules. The "library" modules are published to Maven Central, while the "test" modules generate and compile Java bindings for the GObject-Introspection regression tests (GIMarshallingtests, Regress), and run JUnit testcases for these bindings.
- #234, #254, #257: A metadata parser was added to Java-GI, to make it easier to "patch" the GIR data. The metadata format is inspired by the Gir metadata format used by Vala.
- #237:
GObject.notify_(),Icon.toString_()andSocketConnectable.toString_()have been renamed. - #238: The package and module names have been renamed from
io.github.javagitoorg.javagiand the Maven group-id toorg.java-gi. - #253: Specified the actual ListModel element type, instead of the generic
<T extends GObject>, of several classes that implement ListModel. - #256: GString has been replaced in Java by
java.lang.String: java-gi will automatically marshal Java Strings from and to native GStrings when applicable. The classorg.gnome.glib.GStringis no longer generated. - #259: The package names of Webkit, JavaScriptCore and Webkit-Webprocessextension were wrong for multiple reasons, so they have been changed.
- #260, #261: Java-GI now registers boxed, enum and flags types in the internal TypeCache, enabling automatically conversion of GValues with boxed, enum and flags values from and to Java objects. #260 also added conversion of GValues with GStrv from and to Java
String[]values. - #264: It is now possible to pack and unpack GVariants from and to Java objects with the new
pack(),unpack()andunpackRecursive()methods of theorg.gnome.glib.Variantclass. - #267: The runtime platform checks have been removed. The checks didn't add much value, but complicated the code generator. Calling a function that is unavailable on your runtime platform will now throw
NullPointerException(instead of the oldUnsupportedPlatformException). - #271: Added GstApp-1.0 to the gstreamer module.
- #275: Added bindings for LibRsvg
- #281: Added a utility class to use GNU Gettext-based translations from Java
- #285: Added bindings for LibSecret
Fixes
NB. Several fixes don't have a linked issue; most of these were found while working on the regression tests.
- #222 & #224: Run cleanable immediately when calling yieldOwnership (thanks to @BwackNinja)
- #225: Fixed a race condition during cleanup of short-lived callback functions
- #223 & #227: Use a single upcall stub for all ToggleRefFinalizers to fix an out-of-memory error (thanks to @BwackNinja)
- Fix handling of a
void*alias that is used in an out-parameter - Fix handling of virtual methods with different parameter names than its invoker method
- For variadic callback functions, Java-GI used to generate incorrect code that didn't compile. The compile error has been fixed (but this type of callback function is not supported.)
- Treat alias of
va_listas an opaque pointer - Recognize a
GDestroyNotify*out-parameter - Added a couple temporary patches for missing out-parameter annotations in GstVideo gir data, to be submitted upstream
- Handle GObject properties of type
uchar - Fix the
writeXXX()method that is generated for GObject properties with a pointer to a primitive value (the method will now expect a MemorySegment value in Java) - Renamed
Implclasses that Java-GI uses internally for interfaces and abstract classes (such asFile.FileImpl) to$Implto prevent name clashes with types that actually have a name ending with "Impl" - Added support for marshaling zero-terminated
float[]arrays - Fix conversion of parameter names that start with an underscore
- #239: Fixed handling of constant declarations with suffixes
- Apply the "deprecated" annotation on all types where it is set in the Gir file, not only on methods
- Changed the return type of
GObject.connect()to a generic SignalConnection - #243: Fixed issues with array out-parameters
- #244: Various small fixes
- #245: Added missing Deprecated annotations on deprecated constant fields and enum members
- #246: Fixed an issue with displaying images in Javadoc for GskPath
- Many small fixes for array marshalling and proper memory allocation of arrays
- #250 Implemented a
malloc-based SegmentAllocator for memory that is freed by native code, but allocated in Java. - #251 Added support for struct/union parameters and return values that are passed by value, not by reference.
- #255 Improved handling of boxed types
- #268 Fixed ownership bugs of GError parameters
- #277: Fixed reading and writing to and from fixed-size array (SequenceLayout) fields in a struct
- #290: Added a runtime warning for a missing MemorySegment-constructor
- #296: Fixed signal argument handling for structs that are passed by value
Miscellanious
- Updated the dependency of cairo-java-bindings to 1.18.4.2
- Updated JUnit-Jupiter, com.vanniktech.maven.publish and GitHub actions dependencies
- #258: GIR files are now loaded by version and filename. Previously, java-gi only used the name (for example, "Gtk") to find a gir file. Now it uses the name and version (like "Gtk-4.0") to prevent conflicts when multiple versions of the same library have a gir file available in the same directory.
- #286: The
addressfield of the ProxyInstance class has been marked as deprecated. This field was set to public visibility in Java-GI 0.12, but that will be changed back toprivatein a future release. The deprecation will provide some time to update impacted code. - #287: Improved documentation about icon usage in templates (thanks to @Nyeksenn)
Availability and dependencies:
- The new release is available on Maven Central.
- Java-GI requires OpenJDK 22 or later.
- The bindings are based on the GNOME 48 libraries. These need to be installed.
Full Changelog: 0.12.2...0.13.0-RC1
0.12.2
Java-GI 0.12.2 is a bugfix release.
Fixes
- #216 & #219: Rework library loading with a focus on cross-platform support (thanks to @JFronny for the PR)
- #221 LibAdwaita 1.7 API not available: wrong versions of gir files were used to generate bindings
Availability and dependencies:
- The new release is available on Maven Central.
- Java-GI requires OpenJDK 22 or later.
- The bindings are based on the GNOME 48 libraries. These need to be installed.
Full Changelog: 0.12.1...0.12.2
0.12.1
Java-GI 0.12.1 is a bugfix release. There were no changes since 0.12.1-RC1.
Availability and dependencies:
- The new release is available on Maven Central.
- Java-GI requires OpenJDK 22 or later.
- The bindings are based on the GNOME 48 libraries. These need to be installed.
Full Changelog: 0.12.0...0.12.1
0.12.1-RC1
Java-GI 0.12.1-RC1 is the first release candidate of the upcoming 0.12.1 release.
What's Changed
Fixes
- #212 Subclassing opaque classes in Java works again, fixing a regression in release 0.12.0. Please be aware that these subclasses only exist in Java: it is not possible to register a GType for them.
- #215 The new
constructor(Object... propertyNamesAndValues)that is generated in all GObject-derived classes since Java-GI 0.12.0 has been changed to a no-argument constructor. See issue #213 for more information. It is still possible to construct GObjects with varargs property names and values: UseGObject.newInstance(Class, Object... propertyNamesAndValues)instead.
Contributors
Thanks to @JFronny, @MMarco94 and @esiqveland for reporting issues.
Full Changelog: 0.12.0...0.12.1-RC1
0.12.0
Java-GI 0.12.0 is a major new feature and bugfix release.
What's Changed
Upgrades
The published bindings have been upgraded to GNOME Platform 48. Read all about GNOME 48 on the What's new for developers page on the GNOME website!
Improvements
- #194: GListStore now supports mutation methods of the Java List interface:
ListStore store = ...; store.removeAt(2); // direct binding to `g_list_store_remove(int)`, already worked store.remove(2); // List.remove(int) used to throw UnsupportedOperationException, but now works too
- #195: GObject construction has been significantly improved:
- All GObject-derived classes can now be constructed with
ClassName(Object... properties). Thepropertiesargument is variadic, so it can be left out, or used to set pairs of property names and values:var button = new Button("label", "_Click me", "use-underline", true);
- When creating your own GObject-derived Java class, you can override this constructor and call
super(...)to construct the native instance:public class MyApplication extends Application { public MyApplication() { super("application-id", "org.example.App"); } public void activate() { // ... } }
- As shown in the above example, the
MemorySegmentconstructor does not need to be explicitly overridden anymore. This constructor is used by Java-GI to create a Java proxy instance for native objects returned from native code, but when your own Java classes will not be returned like that, it can be safely omitted. - The
super()call above to the newClassName(Object... properties)constructor, creates a Java proxy instance and then callsg_object_new(). As a result, a GObject initialization method can be run on the Java instance. This used to only be possible with a static factory method to create the new instance:public class Foo extends GObject { public Foo() { super(); } @InstanceInit public void initialize() { // GObject initializer function. // This is automatically called by `g_object_new()`, during the `super()` call above. } }
- Registration of Java classes in the GType system has been automated whenever possible. When a GType isn't available for a Java class, it will be registered on-the-fly. The mandatory call to
Types.register()(orTemplateTypes.register()for Gtk template classes) has now become optional in almost all cases.
- All GObject-derived classes can now be constructed with
- #199: All occurences of
GBytesare now available asbyte[]values in Java. Java-GI allocates and destroyesGBytesbehind the scenes automatically. - #206: Added the new
<doc:format>Gir element to the Gir parser (but not using it for anything yet). - #209: All Gir
versionattributes are now translated to Javadoc@sincetags. Please be aware that this is the native library version, not the Java-GI version.
Fixes
- #183: Do not free GList or GSList instances when ownership is "none".
- #184: Generate static factory methods instead of constructors in abstract classes, fixing an issue with GstGLContext. This also changes the existing constructors in GtkMediaFile and SoupAuth to factory methods. This should not impact existing users, because the old constructors were unusable.
- #196: Do not generate a
builder()method in abstract classes. These classes are not supposed to be constructed directly. - #197: Fix double
ref()in static factory methods. - Automatically sink initially floating references to newly constructed GClosure, GVariant and GParamSpec.
- #198: Cache callback parameters, to preserve state of custom Java classes from native code (by GtkBuilder, for example).
- Fix support for properties with GObject-derived object types.
- When a
@Property-annotated method has no obvious property name, do not throw anIllegalArgumentException, but use the method name itself as a fallback. - #201: Refactored the code generation dealing with return values and out-parameters. As a result, return values are now always stored in a local variable before they are returned. This provides room for "post-processing statements" that were already generated for out-parameters, and now for return values as well. It also fixes a memory leak that occured in some functions with out-parameters.
- Handle callbacks with variadic arguments (not really supported yet, but the code generator at least doesn't crash anymore)
- A couple GHashTable-related fixes: handle GObject properties where the value is a GHashTable, handle GHashTable where the key or value is an enumeration or flag type.
- #204: Fixed a crash related to callback functions with "notified" and "async" scope (for example
GLib.idleAdd) when called from a different thread than the application main loop. - #205: Reimplemented
GLib.idleAddOnce,timeoutAddOnceandtimeoutAddSecondsOncein Java to avoid memory leaks.
Miscellanious
- #182: Added a section in the docs about using SVG icons in Gtk.
- #188, #189: The GitHub CI action to build Windows native Gtk DLLs and executables has been extended with LibAdwaita.
- The 'javagi' command-line tool (to generate bindings from a Gir file) has a new
--stacktraceoption to print the stacktrace for all exceptions. - Fixed build issues in the Flatpak manifest of the HelloTemplate example project.
Contributors
Thanks to @BwackNinja, @leinardi, @Ombrelin, @JFronny, @esiqveland and @mrlem for their contributions and issue reports!
Full Changelog: 0.11.2...0.12.0
0.11.2
Java-GI 0.11.2 is a minor feature and bugfix release.
What's Changed
API changes
- The deprecated class
io.github.jwharm.javagi.gtk.types.Typeshas been removed. This class was renamed fromTypestoTemplateTypesin an earlier version of Java-GI. - The generic type parameters on the method signature of
Types.register()have been removed. Kotlin users might have to fix a compile error when usingTypes.register<MyClass, ParentClass>(MyClass::class.java); to fix it, remove the generic arguments.
Improvements
-
#163: Added support for registering Java interfaces and enums in the GObject type system:
- You can now create an interface in Java (complete with signals and property definitions), and register it in the GObject type system just like it was already possible for classes, with one simple call:
Types.register(MyInterface.class). You can optionally specify prerequisites in the@RegisteredTypeannotation. - For custom enums, few practical use cases exist. But in case anyone needs them anyway, they will be happy to discover that the
Types.register()API recognizes Java enums and will register a GObject enum or flags type (when annotated as@Flags).
- You can now create an interface in Java (complete with signals and property definitions), and register it in the GObject type system just like it was already possible for classes, with one simple call:
-
#164: Added an internal mapping of Java classes to GTypes. As a result, the declaration of a
public static Type getType()method has now become redundant, and it is now possible to construct new instances usingGObject.newInstance(Foo.class). This means the GType has (for most use cases) been moved "behind the scenes" and Java developers can simply work with the class itself!An example of the new, shorter way to register a class and construct new instances:
public class Foo extends GObject { static { Types.register(Foo.class); } public static Foo newInstance() { return GObject.newInstance(Foo.class); } public Foo(MemorySegment address) { super(address); } }
-
#165: Getter and setter method pairs in Java will automatically be recognized as GObject properties when the class is registered as a GType. If your class follows the usual get/set naming convention, the
@Propertyannotation can be omitted. (@Propertycan still be used to set flags and override the property name.)// Will result in a "max-speed" property of type "int" public int getMaxSpeed() { ... } public void setMaxSpeed(int maxSpeed) { ... }
For boolean properties, you can also use
isFoo()/setFoo()pairs.
Kotlin creates get- and set-methods for Kotlin properties automatically, so in practice a Kotlin property will be registered as a GObject property. -
#168: Extended the
@Propertyannotation to allow setting a minimum, maximum and default value for GObject properties in a GObject-derived Java class, that will be set in theGParamSpec:@Property(minimumValue = "1", maximumValue = "12", defaultValue = "1") public void setMonth(int month) { this.month = month; }
-
#170: Added
toString()methods for GType and GVariant, to ease printing and debugging. -
#171: Added support for mutable ListModels, and allows patches to pick implementation classes for generics where appropriate (like
StringListnow implementsListModel<StringObject>as its documentation suggests). Thanks to @JFronny for the PR. -
#178: Created a unified way to add
toString()methods to generated classes using the existing patch-mechanism, to replace the custom code for GType, GVariant, GValue, StringFilter and others. Thanks again to @JFronny for implementing most of this.
Fixes
- #160: Removed the automatic override of the return type of named constructor functions. (It is now only overridden for Gtk Widgets.) This fixes an issue in bindings generated for ICal-GLib.
- #162: Changed the
generateSourcesGradle task to make it compatible with the Gradle configuration cache, and enabled the configuration cache. - #169: Generate methods for
<union>GIR types. As a result, a couple missing GMutex methods are now available. (Thanks to @leinardi for reporting) - #172: Allow extending
GstMapFlagswith additional flags, such asGstGL.MAP_GL. (Thanks to @BwackNinja for reporting) - #173: Generate missing accessors for fields containing a GList or GSList, for example in
Pango.LayoutLine. (Thanks to @BwackNinja for reporting) - Fixed the build script of the GstPbutils module so it generates bindings from the correct gir file.
- #175: Compare parameter types of virtual methods and their invoker methods, and only combine them in one Java method when the parameter types match exactly. This fixes a compile error in bindings generated for GstGL (thanks again to @BwackNinja for reporting)
Miscellanious
- Two Scala example applications (a "Hello world" app and a simple image viewer) were added to the java-gi-examples collection, and the Calculator example was ported from Java to Kotlin. (Thanks to @poach3r for the contribution)
Full Changelog: 0.11.1...0.11.2
0.11.1
Java-GI 0.11.1 is a minor feature and bugfix release.
What's Changed
Improvements:
#150: Java-GI can now be used as a command-line tool to generate Java bindings manually from a GObject-Introspection repository (gir) file. Download the zip file below, extract it, and run java-gi <filename.gir> to generate bindings. More info is available on the Java-GI website, or run java-gi --help.
Fixes:
#151: Added missing support for the gir <doc-stability> element.
#153: Fixed the MemoryCleaner functionality to automatically free struct/union types.
#154: Added support for array aliases (thanks to @leinardi for reporting)
#155: Fixed an issue where internal GdkModifierKey flags caused Java-GI to throw an exception (thanks to @poach3r for reporting)
#156: Various fixes to generate Java bindings for Libical (thanks to @tintou for reporting)
#159: Fixed an issue in the new command-line tool (thanks to @poach3r for reporting)
#161: Fixed an issue with passing signal arguments to Java methods from GtkBuilder ui files (thanks to @Nyeksenn for reporting)
Availability and dependencies:
- The new release is available on Maven Central.
- Java-GI requires OpenJDK 22 or later.
- The bindings are based on the GNOME 47 libraries. These need to be installed.
Full Changelog: 0.11.0...0.11.1
0.11.0
Java-GI 0.11.0 features a lot of improvements and bugfixes all over the board.
What's Changed
Improvements:
- Java-GI 0.11.0 upgrades the Java bindings to the GNOME 47 platform versions. Read the What's new for developers section of the GNOME 47 Release Notes for an overview of the changes in this GNOME release.
- The GListModel interface has been made generic in Java:
ListModel<T extends GObject>. The entire hierarchy of classes and interfaces that implement GListModel is now generic as well. - Furthermore, the ListModel interface now extends
java.util.List, so all list models can now be used as a Java collection (enhanced for loop, process withstream(), ...). - #123: An additional no-argument constructor has been added to classes that have ambiguity between the default MemorySegment-constructor and another constructor with one (optional) parameter, when passing
null. To passnull, users had to cast it. The new constructors resolve this. (Thanks to David Goodenough for reporting this.) Example:
// Old
var frame = new Frame((String) null);
// New
var frame = new Frame();- #126: It is now possible to connect signals from Builder objects. For example:
var button = Button.builder()
.setLabel("Close")
.onClicked(window::close)
.build;- The Gtk functions
StyleContext.addProviderForDisplayandremoveProviderForDisplayhave been copied toGtk.styleContextAddProviderForDisplayandGtk.styleContextRemoveProviderForDisplaybecause theStyleContextclass is deprecated. The functions can now be called from theGtkclass to avoid deprecation warnings. - Gtk composite template classes are now registered with
TemplateTypes.register(class)instead of the oldTypes.register(class). In previous java-gi versions, there were twoTypesclasses, one in GObject and one in Gtk (to register template classes), and users had to carefully import the correct one. Renaming the GtkTypesclass toTemplateTypeswill make the distinction clear. The old class is still available in this release, but has been deprecated and will be removed in an upcoming release. - Many functions that required closure parameters now expect callback methods (or lambdas). This makes much more sense in a statically-typed language like Java. (Technically this means that when regular functions in GObject-Introspection are "shadowed by" a
_with_closuresfunction, we ignore the "shadowed by" annotation.) - #129: A new API has been added to create GObject property bindings with transformations. It works the same as in Gtk-rs: The second example on this page would look like this in Java:
button1.<Integer, Integer>bindProperty("number", button2, "number")
.transformTo(n -> n + 1)
.transformFrom(n -> n - 1)
.bidirectional()
.syncCreate()
.build();- #131: Java-GI now contains a custom
org.gnome.glib.HashTablewrapper class for GHashTable that implements thejava.util.Map<K,V>interface. The keys and values can be strings, pointers (MemorySegments in Java), or heap-allocated classes/structs (i.e. anything that implements the Java-GIProxyinterface). The class is not meant to be used instead ofjava.util.HashMap, but will help Java developers work with native functions that return or expect a GHashTable. - #139: The API to manually override a GObject virtual method with a Java lambda has been removed. It is still possible to override a virtual method with a
java.lang.reflect.Methodparameter (as used byTypes.register(classname)). Furthermore, no accessors will be generated anymore to directly get/set theparent_classfield of typeclasses. These APIs were unsafe to use (to put it mildly) and with these changes, the amount of generated code in Java-GI has been reduced significantly. - #140: Trailing flag parameters can now be set with either a
Setor varargs. For example, to create a new application, use one of these two constructors:
public Application(@Nullable String applicationId, Set<ApplicationFlags> flags);
public Application(@Nullable String applicationId, ApplicationFlags... flags);- #141: It is now possible to specify the name of the namespace for your own GObject-derived classes in
package-info.javawith the new@Namespace(name="...")annotation. The namespace name will be prefixed to the class name. - Improved parameter references in generated Javadoc.
- All code examples on the website are now available in both Java and Kotlin.
Fixes:
- #106: The different length of
longnative data types on Windows (longis 32-bit) versus Linux and macOS (longis 64-bit) is now fully implemented in Java-GI. The generated Java API supports the lowest common denominator (int), and casts to the correct native datatype at runtime. Classes, interfaces and structs withlongfields use two separateMemoryLayouts in Java internally that contain the correct alignment and padding for the applicable platform. - #117: Fixed a ClassCastException when casting the ListModel items returned by
File.openMultipleFinish()toFile. (Thanks @SudoDios for reporting this.) - The wrapper classes for GList and GSList now properly free the list items after use.
- #120: Fixed a crash when using variadic functions on macOS.
- Improved the MemoryLayout generator to correctly handle nested structs and unions.
- #124: Copy structs and boxed types when returned from a native function without ownership transfer. This will call the
copyorreffunction defined for that type (org_boxed_copyfor boxed types). This prevents a segfault when the struct is disposed somewhere else while Java is still using it. - #125: Improve memory management for methods with callback parameters that have a DestroyNotify callback.
Miscellanious:
- The
allocate()factory methods on struct/boxed types have been removed. These methods were replaced by constructors and had already been deprecated in the previous release. - The Gtk "Getting Started" guide has been ported to Java, and is now available on the Java-GI website, with all example code.
- Two new examples were added to the java-gi-examples repository: ColumnViewDatagrid and Spacewar.
Availability and dependencies:
- The new release is available on Maven Central.
- Java-GI requires OpenJDK 22 or later.
- The bindings are based on the GNOME 47 libraries. These need to be installed.
Full Changelog: 0.10.2...0.11.0