-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move GenerateSources, PackageNames and GLibCompileResources classes t…
…o other packages
- Loading branch information
Showing
9 changed files
with
199 additions
and
373 deletions.
There are no files selected for viewing
97 changes: 0 additions & 97 deletions
97
buildSrc/src/main/groovy/io/github/jwharm/javagi/generator/GenerateSources.groovy
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
buildSrc/src/main/groovy/io/github/jwharm/javagi/generator/PackageNames.groovy
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
buildSrc/src/main/java/io/github/jwharm/javagi/GenerateSources.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* Java-GI - Java language bindings for GObject-Introspection-based libraries | ||
* Copyright (C) 2022-2023 Jan-Willem Harmannij | ||
* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.github.jwharm.javagi; | ||
|
||
import io.github.jwharm.javagi.generator.*; | ||
import io.github.jwharm.javagi.model.Repository; | ||
import io.github.jwharm.javagi.model.Module; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.file.Directory; | ||
import org.gradle.api.file.DirectoryProperty; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.tasks.*; | ||
import org.xml.sax.SAXException; | ||
|
||
import javax.xml.parsers.ParserConfigurationException; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* GenerateSources is a Gradle task that will parse a GIR file (and all included GIR files) | ||
* and generate Java source files for the types defined in the GIR file. | ||
*/ | ||
public abstract class GenerateSources extends DefaultTask { | ||
|
||
@InputDirectory | ||
abstract DirectoryProperty getInputDirectory(); | ||
|
||
@OutputDirectory | ||
abstract DirectoryProperty getOutputDirectory(); | ||
|
||
@Input | ||
abstract Property<String> getGirFile(); | ||
|
||
@Input @Optional | ||
abstract Property<String> getUrlPrefix(); | ||
|
||
@Input @Optional | ||
abstract Property<Patch> getPatch(); | ||
|
||
@TaskAction | ||
void execute() { | ||
try { | ||
Module windows = parse(Platform.WINDOWS, getInputDirectory().get(), getGirFile().get(), | ||
getUrlPrefix().getOrElse(null), getPatch().getOrElse(null)); | ||
Module linux = parse(Platform.LINUX, getInputDirectory().get(), getGirFile().get(), | ||
getUrlPrefix().getOrElse(null), getPatch().getOrElse(null)); | ||
Module macos = parse(Platform.MACOS, getInputDirectory().get(), getGirFile().get(), | ||
getUrlPrefix().getOrElse(null), getPatch().getOrElse(null)); | ||
|
||
Module module = new Merge().merge(windows, linux, macos); | ||
|
||
for (Repository repository : module.repositories.values()) { | ||
if (repository.generate) { | ||
Path basePath = getOutputDirectory().get().file(repository.namespace.pathName).getAsFile().toPath(); | ||
repository.generate(basePath); | ||
} | ||
} | ||
} catch (Exception e) { | ||
throw new TaskExecutionException(this, e); | ||
} | ||
} | ||
|
||
private static Module parse(Platform platform, Directory sourceDirectory, String girFile, String urlPrefix, Patch patch) | ||
throws SAXException, ParserConfigurationException { | ||
Module module = new Module(platform); | ||
Directory girPath = sourceDirectory.dir(platform.name().toLowerCase()); | ||
if (! girPath.getAsFile().exists()) { | ||
System.out.println("Not found: " + girPath); | ||
return null; | ||
} | ||
GirParser parser = new GirParser(girPath.getAsFile().toPath(), module); | ||
|
||
// Parse the GI files into Repository objects | ||
try { | ||
// Parse the file | ||
Repository r = parser.parse(girFile); | ||
|
||
// Check if this one has already been parsed | ||
if (module.repositories.containsKey(r.namespace.name)) { | ||
r = module.repositories.get(r.namespace.name); | ||
} else { | ||
// Add the repository to the module | ||
module.repositories.put(r.namespace.name, r); | ||
} | ||
|
||
r.urlPrefix = urlPrefix; | ||
|
||
// Flag unsupported va_list methods so they will not be generated | ||
module.flagVaListFunctions(); | ||
|
||
// Apply patch | ||
if (patch != null) { | ||
patch.patch(r); | ||
} | ||
|
||
} catch (IOException ignored) { | ||
// Gir file not found for this platform: This will generate code with UnsupportedPlatformExceptions | ||
} | ||
|
||
// Link the type references to the GIR type definition across the GI repositories | ||
module.link(); | ||
|
||
return module; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
buildSrc/src/main/java/io/github/jwharm/javagi/configuration/PackageNames.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* Java-GI - Java language bindings for GObject-Introspection-based libraries | ||
* Copyright (C) 2022-2023 Jan-Willem Harmannij | ||
* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.github.jwharm.javagi.configuration; | ||
|
||
import java.util.Map; | ||
|
||
import static java.util.Map.entry; | ||
|
||
/** | ||
* The PackageNames class defines the mapping between GIR namespaces | ||
* and Java package names. | ||
*/ | ||
public class PackageNames { | ||
|
||
public static Map<String, String> getMap() { | ||
return Map.ofEntries( | ||
entry("GLib", "org.gnome.glib"), | ||
entry("GObject", "org.gnome.gobject"), | ||
entry("GModule", "org.gnome.gmodule"), | ||
entry("Gio", "org.gnome.gio"), | ||
entry("cairo", "org.freedesktop.cairo"), | ||
entry("freetype2", "org.freedesktop.freetype"), | ||
entry("HarfBuzz", "org.freedesktop.harfbuzz"), | ||
entry("Pango", "org.gnome.pango"), | ||
entry("PangoCairo", "org.gnome.pango.cairo"), | ||
entry("GdkPixbuf", "org.gnome.gdkpixbuf"), | ||
entry("Gdk", "org.gnome.gdk"), | ||
entry("Graphene", "org.gnome.graphene"), | ||
entry("Gsk", "org.gnome.gsk"), | ||
entry("Gtk", "org.gnome.gtk"), | ||
entry("GtkSource", "org.gnome.gtksourceview"), | ||
entry("Adw", "org.gnome.adw"), | ||
entry("Soup", "org.gnome.soup"), | ||
entry("JavaScriptCore", "org.gnome.webkit.jsc"), | ||
entry("WebKit", "org.gnome.webkit"), | ||
entry("WebKitWebProcessExtension", "org.gnome.webkit.wpe"), | ||
entry("Gst", "org.freedesktop.gstreamer"), | ||
entry("GstBase", "org.freedesktop.gstreamer.base"), | ||
entry("GstAudio", "org.freedesktop.gstreamer.audio"), | ||
entry("GstPbutils", "org.freedesktop.gstreamer.pbutils"), | ||
entry("GstVideo", "org.freedesktop.gstreamer.video") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.