[gnome-builder] plugins/gradle: port gradle plugin to C
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/gradle: port gradle plugin to C
- Date: Tue, 12 Jul 2022 06:39:16 +0000 (UTC)
commit 4265a4989ad4822673cea54fa7e0bc9fa2399605
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 11 22:50:52 2022 -0700
plugins/gradle: port gradle plugin to C
.../gradle/gbp-gradle-build-system-discovery.c | 47 ++++
.../gradle/gbp-gradle-build-system-discovery.h | 31 +++
src/plugins/gradle/gbp-gradle-build-system.c | 166 +++++++++++++
src/plugins/gradle/gbp-gradle-build-system.h | 33 +++
src/plugins/gradle/gbp-gradle-pipeline-addin.c | 123 ++++++++++
src/plugins/gradle/gbp-gradle-pipeline-addin.h | 31 +++
.../gradle/gbp-gradle-run-command-provider.c | 229 +++++++++++++++++
.../gradle/gbp-gradle-run-command-provider.h | 31 +++
src/plugins/gradle/gradle-plugin.c | 49 ++++
src/plugins/gradle/gradle.gresource.xml | 6 +
src/plugins/gradle/gradle.plugin | 9 +-
src/plugins/gradle/gradle_plugin.py | 272 ---------------------
src/plugins/gradle/meson.build | 22 +-
13 files changed, 764 insertions(+), 285 deletions(-)
---
diff --git a/src/plugins/gradle/gbp-gradle-build-system-discovery.c
b/src/plugins/gradle/gbp-gradle-build-system-discovery.c
new file mode 100644
index 000000000..1daa089a5
--- /dev/null
+++ b/src/plugins/gradle/gbp-gradle-build-system-discovery.c
@@ -0,0 +1,47 @@
+/* gbp-gradle-build-system-discovery.c
+ *
+ * Copyright 2016-2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-gradle-build-system-discovery"
+
+#include "config.h"
+
+#include "gbp-gradle-build-system-discovery.h"
+
+struct _GbpGradleBuildSystemDiscovery
+{
+ IdeSimpleBuildSystemDiscovery parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (GbpGradleBuildSystemDiscovery, gbp_gradle_build_system_discovery,
IDE_TYPE_SIMPLE_BUILD_SYSTEM_DISCOVERY)
+
+static void
+gbp_gradle_build_system_discovery_class_init (GbpGradleBuildSystemDiscoveryClass *klass)
+{
+}
+
+static void
+gbp_gradle_build_system_discovery_init (GbpGradleBuildSystemDiscovery *self)
+{
+ g_object_set (self,
+ "glob", "build.gradle",
+ "hint", "gradle",
+ "priority", 2000,
+ NULL);
+}
diff --git a/src/plugins/gradle/gbp-gradle-build-system-discovery.h
b/src/plugins/gradle/gbp-gradle-build-system-discovery.h
new file mode 100644
index 000000000..032c472b3
--- /dev/null
+++ b/src/plugins/gradle/gbp-gradle-build-system-discovery.h
@@ -0,0 +1,31 @@
+/* gbp-gradle-build-system-discovery.h
+ *
+ * Copyright 2016-2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-foundry.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_GRADLE_BUILD_SYSTEM_DISCOVERY (gbp_gradle_build_system_discovery_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpGradleBuildSystemDiscovery, gbp_gradle_build_system_discovery, GBP,
GRADLE_BUILD_SYSTEM_DISCOVERY, IdeSimpleBuildSystemDiscovery)
+
+G_END_DECLS
diff --git a/src/plugins/gradle/gbp-gradle-build-system.c b/src/plugins/gradle/gbp-gradle-build-system.c
new file mode 100644
index 000000000..bdbc61de7
--- /dev/null
+++ b/src/plugins/gradle/gbp-gradle-build-system.c
@@ -0,0 +1,166 @@
+/* gbp-gradle-build-system.c
+ *
+ * Copyright 2016-2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-gradle-build-system"
+
+#include "config.h"
+
+#include "gbp-gradle-build-system.h"
+
+struct _GbpGradleBuildSystem
+{
+ IdeObject parent_instance;
+ GFile *project_file;
+};
+
+enum {
+ PROP_0,
+ PROP_PROJECT_FILE,
+ N_PROPS
+};
+
+static char *
+gbp_gradle_build_system_get_id (IdeBuildSystem *build_system)
+{
+ return g_strdup ("gradle");
+}
+
+static char *
+gbp_gradle_build_system_get_display_name (IdeBuildSystem *build_system)
+{
+ return g_strdup ("Gradle");
+}
+
+static int
+gbp_gradle_build_system_get_priority (IdeBuildSystem *build_system)
+{
+ return 2000;
+}
+
+static void
+build_system_iface_init (IdeBuildSystemInterface *iface)
+{
+ iface->get_id = gbp_gradle_build_system_get_id;
+ iface->get_display_name = gbp_gradle_build_system_get_display_name;
+ iface->get_priority = gbp_gradle_build_system_get_priority;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpGradleBuildSystem, gbp_gradle_build_system, IDE_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_BUILD_SYSTEM, build_system_iface_init))
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+gbp_gradle_build_system_dispose (GObject *object)
+{
+ GbpGradleBuildSystem *self = (GbpGradleBuildSystem *)object;
+
+ g_clear_object (&self->project_file);
+
+ G_OBJECT_CLASS (gbp_gradle_build_system_parent_class)->dispose (object);
+}
+
+static void
+gbp_gradle_build_system_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GbpGradleBuildSystem *self = GBP_GRADLE_BUILD_SYSTEM (object);
+
+ switch (prop_id)
+ {
+ case PROP_PROJECT_FILE:
+ g_value_set_object (value, self->project_file);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gbp_gradle_build_system_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GbpGradleBuildSystem *self = GBP_GRADLE_BUILD_SYSTEM (object);
+
+ switch (prop_id)
+ {
+ case PROP_PROJECT_FILE:
+ g_set_object (&self->project_file, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gbp_gradle_build_system_class_init (GbpGradleBuildSystemClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = gbp_gradle_build_system_dispose;
+ object_class->get_property = gbp_gradle_build_system_get_property;
+ object_class->set_property = gbp_gradle_build_system_set_property;
+
+ properties [PROP_PROJECT_FILE] =
+ g_param_spec_object ("project-file",
+ "Project File",
+ "The project file (Gradle.toml)",
+ G_TYPE_FILE,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+gbp_gradle_build_system_init (GbpGradleBuildSystem *self)
+{
+}
+
+char *
+gbp_gradle_build_system_get_project_dir (GbpGradleBuildSystem *self)
+{
+ g_autoptr(GFile) workdir = NULL;
+ g_autofree char *base = NULL;
+ IdeContext *context;
+
+ g_return_val_if_fail (GBP_IS_GRADLE_BUILD_SYSTEM (self), NULL);
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ workdir = ide_context_ref_workdir (context);
+
+ if (self->project_file == NULL)
+ return g_strdup (g_file_peek_path (workdir));
+
+ base = g_file_get_basename (self->project_file);
+
+ if (strcasecmp (base, "build.gradle") == 0)
+ {
+ g_autoptr(GFile) parent = g_file_get_parent (self->project_file);
+ return g_file_get_path (parent);
+ }
+
+ return g_file_get_path (self->project_file);
+}
diff --git a/src/plugins/gradle/gbp-gradle-build-system.h b/src/plugins/gradle/gbp-gradle-build-system.h
new file mode 100644
index 000000000..c8d22b09c
--- /dev/null
+++ b/src/plugins/gradle/gbp-gradle-build-system.h
@@ -0,0 +1,33 @@
+/* gbp-gradle-build-system.h
+ *
+ * Copyright 2016-2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-foundry.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_GRADLE_BUILD_SYSTEM (gbp_gradle_build_system_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpGradleBuildSystem, gbp_gradle_build_system, GBP, GRADLE_BUILD_SYSTEM, IdeObject)
+
+char *gbp_gradle_build_system_get_project_dir (GbpGradleBuildSystem *self);
+
+G_END_DECLS
diff --git a/src/plugins/gradle/gbp-gradle-pipeline-addin.c b/src/plugins/gradle/gbp-gradle-pipeline-addin.c
new file mode 100644
index 000000000..68db08dea
--- /dev/null
+++ b/src/plugins/gradle/gbp-gradle-pipeline-addin.c
@@ -0,0 +1,123 @@
+/* gbp-gradle-pipeline-addin.c
+ *
+ * Copyright 2018 danigm <danigm wadobo com>
+ * Copyright 2018 Alberto Fanjul <albfan gnome org>
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-gradle-pipeline-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-foundry.h>
+
+#include "gbp-gradle-build-system.h"
+#include "gbp-gradle-pipeline-addin.h"
+
+struct _GbpGradlePipelineAddin
+{
+ IdeObject parent_instance;
+};
+
+static void
+query_cb (IdePipelineStage *stage,
+ IdePipeline *pipeline,
+ GPtrArray *targets,
+ GCancellable *cancellable,
+ gpointer user_data)
+{
+ g_assert (IDE_IS_PIPELINE_STAGE (stage));
+ g_assert (IDE_IS_PIPELINE (pipeline));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ /* Always defer to gradle to check if build is needed */
+ ide_pipeline_stage_set_completed (stage, FALSE);
+}
+
+static void
+gbp_gradle_pipeline_addin_load (IdePipelineAddin *addin,
+ IdePipeline *pipeline)
+{
+ g_autoptr(IdeSubprocessLauncher) wrapper_launcher = NULL;
+ g_autoptr(IdeSubprocessLauncher) build_launcher = NULL;
+ g_autoptr(IdeSubprocessLauncher) clean_launcher = NULL;
+ g_autoptr(IdePipelineStage) wrapper_stage = NULL;
+ g_autoptr(IdePipelineStage) build_stage = NULL;
+ IdeBuildSystem *build_system;
+ const char *srcdir;
+ IdeContext *context;
+ guint id;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_GRADLE_PIPELINE_ADDIN (addin));
+ g_assert (IDE_IS_PIPELINE (pipeline));
+
+ context = ide_object_get_context (IDE_OBJECT (addin));
+ build_system = ide_build_system_from_context (context);
+ srcdir = ide_pipeline_get_srcdir (pipeline);
+
+ if (!GBP_IS_GRADLE_BUILD_SYSTEM (build_system))
+ IDE_EXIT;
+
+ wrapper_launcher = ide_pipeline_create_launcher (pipeline, NULL);
+ ide_subprocess_launcher_set_cwd (wrapper_launcher, srcdir);
+ ide_subprocess_launcher_push_args (wrapper_launcher, IDE_STRV_INIT ("gradle", "wrapper"));
+ wrapper_stage = ide_pipeline_stage_launcher_new (context, wrapper_launcher);
+ ide_pipeline_stage_set_name (wrapper_stage, _("Bootstrapping project"));
+ id = ide_pipeline_attach (pipeline, IDE_PIPELINE_PHASE_AUTOGEN, 0, wrapper_stage);
+ ide_pipeline_addin_track (addin, id);
+
+ build_launcher = ide_pipeline_create_launcher (pipeline, NULL);
+ ide_subprocess_launcher_set_cwd (build_launcher, srcdir);
+ ide_subprocess_launcher_push_args (build_launcher, IDE_STRV_INIT ("./gradlew", "build"));
+
+ clean_launcher = ide_pipeline_create_launcher (pipeline, NULL);
+ ide_subprocess_launcher_set_cwd (clean_launcher, srcdir);
+ ide_subprocess_launcher_push_args (clean_launcher, IDE_STRV_INIT ("./gradlew", "clean"));
+
+ build_stage = ide_pipeline_stage_launcher_new (context, build_launcher);
+ ide_pipeline_stage_set_name (build_stage, _("Building project"));
+ ide_pipeline_stage_launcher_set_clean_launcher (IDE_PIPELINE_STAGE_LAUNCHER (build_stage), clean_launcher);
+ g_signal_connect (build_stage, "query", G_CALLBACK (query_cb), NULL);
+ id = ide_pipeline_attach (pipeline, IDE_PIPELINE_PHASE_BUILD, 0, build_stage);
+ ide_pipeline_addin_track (addin, id);
+
+ IDE_EXIT;
+}
+
+static void
+pipeline_addin_iface_init (IdePipelineAddinInterface *iface)
+{
+ iface->load = gbp_gradle_pipeline_addin_load;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpGradlePipelineAddin, gbp_gradle_pipeline_addin, IDE_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_PIPELINE_ADDIN, pipeline_addin_iface_init))
+
+static void
+gbp_gradle_pipeline_addin_class_init (GbpGradlePipelineAddinClass *klass)
+{
+}
+
+static void
+gbp_gradle_pipeline_addin_init (GbpGradlePipelineAddin *self)
+{
+}
diff --git a/src/plugins/gradle/gbp-gradle-pipeline-addin.h b/src/plugins/gradle/gbp-gradle-pipeline-addin.h
new file mode 100644
index 000000000..548a65a85
--- /dev/null
+++ b/src/plugins/gradle/gbp-gradle-pipeline-addin.h
@@ -0,0 +1,31 @@
+/* gbp-gradle-pipeline-addin.h
+ *
+ * Copyright 2016-2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_GRADLE_PIPELINE_ADDIN (gbp_gradle_pipeline_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpGradlePipelineAddin, gbp_gradle_pipeline_addin, GBP, GRADLE_PIPELINE_ADDIN,
IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/gradle/gbp-gradle-run-command-provider.c
b/src/plugins/gradle/gbp-gradle-run-command-provider.c
new file mode 100644
index 000000000..264301a6e
--- /dev/null
+++ b/src/plugins/gradle/gbp-gradle-run-command-provider.c
@@ -0,0 +1,229 @@
+/* gbp-gradle-run-command-provider.c
+ *
+ * Copyright 2016-2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-gradle-run-command-provider"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-foundry.h>
+#include <libide-threading.h>
+
+#include "gbp-gradle-build-system.h"
+#include "gbp-gradle-run-command-provider.h"
+
+struct _GbpGradleRunCommandProvider
+{
+ IdeObject parent_instance;
+};
+
+static void
+find_test_files_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GFile *basedir = (GFile *)object;
+ g_autoptr(GPtrArray) files = NULL;
+ g_autoptr(IdeTask) task = user_data;
+ g_autoptr(GError) error = NULL;
+ GListStore *store;
+ const char *srcdir;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (G_IS_FILE (basedir));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (IDE_IS_TASK (task));
+
+ store = ide_task_get_task_data (task);
+ srcdir = g_object_get_data (G_OBJECT (task), "SRCDIR");
+
+ g_assert (G_IS_LIST_STORE (store));
+ g_assert (srcdir != NULL);
+
+ if (!(files = ide_g_file_find_finish (basedir, result, &error)))
+ {
+ g_debug ("Failed to find test files: %s", error->message);
+ IDE_GOTO (failure);
+ }
+
+ for (guint i = 0; i < files->len; i++)
+ {
+ GFile *file = g_ptr_array_index (files, i);
+ g_autofree char *contents = NULL;
+ IdeLineReader reader;
+ char *line;
+ gsize line_len;
+ gsize len;
+
+ if (!g_file_load_contents (file, NULL, &contents, &len, NULL, NULL))
+ continue;
+
+ /* Obviously this isn't a great way to find tests, but it
+ * does allow for skipping any sort of introspection. Mostly
+ * just copying what the python plugin did.
+ */
+ ide_line_reader_init (&reader, contents, len);
+ while ((line = ide_line_reader_next (&reader, &line_len)))
+ {
+ g_autoptr(IdeRunCommand) run_command = NULL;
+ g_autofree char *class_name = NULL;
+ g_autofree char *full_name = NULL;
+ g_autofree char *id = NULL;
+ char *dot;
+ char *name;
+ char *paren;
+
+ line[line_len] = 0;
+
+ if (!(name = strstr (line, "public void")))
+ continue;
+
+ if (!(paren = strchr (name, '(')))
+ continue;
+
+ *paren = 0;
+ name += strlen ("public void");
+ g_strstrip (name);
+
+ class_name = g_file_get_basename (file);
+ if ((dot = strrchr (class_name, '.')))
+ *dot = 0;
+
+ full_name = g_strconcat (class_name, ".", name, NULL);
+ id = g_strdup_printf ("gradle:%s", name);
+
+ run_command = ide_run_command_new ();
+ ide_run_command_set_id (run_command, id);
+ ide_run_command_set_display_name (run_command, name);
+ ide_run_command_set_kind (run_command, IDE_RUN_COMMAND_KIND_TEST);
+ ide_run_command_set_argv (run_command, IDE_STRV_INIT ("./gradlew", "test", "--tests", full_name));
+ ide_run_command_set_cwd (run_command, srcdir);
+
+ g_list_store_append (store, run_command);
+ }
+ }
+
+failure:
+ ide_task_return_pointer (task, g_object_ref (store), g_object_unref);
+
+ IDE_EXIT;
+}
+
+static void
+gbp_gradle_run_command_provider_list_commands_async (IdeRunCommandProvider *provider,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GbpGradleRunCommandProvider *self = (GbpGradleRunCommandProvider *)provider;
+ g_autoptr(IdeRunCommand) run_command = NULL;
+ g_autoptr(GListStore) store = NULL;
+ g_autoptr(IdeTask) task = NULL;
+ g_autoptr(GFile) testdir = NULL;
+ g_autofree char *project_dir = NULL;
+ IdeBuildSystem *build_system;
+ IdeContext *context;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_GRADLE_RUN_COMMAND_PROVIDER (self));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ store = g_list_store_new (IDE_TYPE_RUN_COMMAND);
+
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, gbp_gradle_run_command_provider_list_commands_async);
+ ide_task_set_task_data (task, g_object_ref (store), g_object_unref);
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ build_system = ide_build_system_from_context (context);
+
+ if (!GBP_IS_GRADLE_BUILD_SYSTEM (build_system))
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "Not a gradle build system");
+ IDE_EXIT;
+ }
+
+ project_dir = gbp_gradle_build_system_get_project_dir (GBP_GRADLE_BUILD_SYSTEM (build_system));
+ testdir = g_file_new_build_filename (project_dir, "src", "test", "java", NULL);
+
+ g_object_set_data_full (G_OBJECT (task),
+ "SRCDIR",
+ g_strdup (project_dir),
+ g_free);
+
+ run_command = ide_run_command_new ();
+ ide_run_command_set_id (run_command, "gradle:run");
+ ide_run_command_set_priority (run_command, -500);
+ ide_run_command_set_display_name (run_command, _("Gradle Run"));
+ ide_run_command_set_cwd (run_command, project_dir);
+ ide_run_command_set_argv (run_command, IDE_STRV_INIT ("./gradlew", "run"));
+ g_list_store_append (store, run_command);
+
+ ide_g_file_find_with_depth_async (testdir, "*.java", 5,
+ NULL,
+ find_test_files_cb,
+ g_object_ref (provider));
+
+ IDE_EXIT;
+}
+
+static GListModel *
+gbp_gradle_run_command_provider_list_commands_finish (IdeRunCommandProvider *provider,
+ GAsyncResult *result,
+ GError **error)
+{
+ GListModel *ret;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_GRADLE_RUN_COMMAND_PROVIDER (provider));
+ g_assert (IDE_IS_TASK (result));
+
+ ret = ide_task_propagate_pointer (IDE_TASK (result), error);
+
+ IDE_RETURN (ret);
+}
+
+static void
+run_command_provider_iface_init (IdeRunCommandProviderInterface *iface)
+{
+ iface->list_commands_async = gbp_gradle_run_command_provider_list_commands_async;
+ iface->list_commands_finish = gbp_gradle_run_command_provider_list_commands_finish;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpGradleRunCommandProvider, gbp_gradle_run_command_provider, IDE_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_RUN_COMMAND_PROVIDER,
run_command_provider_iface_init))
+
+static void
+gbp_gradle_run_command_provider_class_init (GbpGradleRunCommandProviderClass *klass)
+{
+}
+
+static void
+gbp_gradle_run_command_provider_init (GbpGradleRunCommandProvider *self)
+{
+}
diff --git a/src/plugins/gradle/gbp-gradle-run-command-provider.h
b/src/plugins/gradle/gbp-gradle-run-command-provider.h
new file mode 100644
index 000000000..807909fb3
--- /dev/null
+++ b/src/plugins/gradle/gbp-gradle-run-command-provider.h
@@ -0,0 +1,31 @@
+/* gbp-gradle-run-command-provider.h
+ *
+ * Copyright 2016-2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_GRADLE_RUN_COMMAND_PROVIDER (gbp_gradle_run_command_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpGradleRunCommandProvider, gbp_gradle_run_command_provider, GBP,
GRADLE_RUN_COMMAND_PROVIDER, IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/gradle/gradle-plugin.c b/src/plugins/gradle/gradle-plugin.c
new file mode 100644
index 000000000..a2b54497e
--- /dev/null
+++ b/src/plugins/gradle/gradle-plugin.c
@@ -0,0 +1,49 @@
+/* gradle-plugin.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gradle-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+
+#include <libide-foundry.h>
+
+#include "gbp-gradle-build-system.h"
+#include "gbp-gradle-build-system-discovery.h"
+#include "gbp-gradle-pipeline-addin.h"
+#include "gbp-gradle-run-command-provider.h"
+
+_IDE_EXTERN void
+_gbp_gradle_register_types (PeasObjectModule *module)
+{
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_BUILD_SYSTEM,
+ GBP_TYPE_GRADLE_BUILD_SYSTEM);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_BUILD_SYSTEM_DISCOVERY,
+ GBP_TYPE_GRADLE_BUILD_SYSTEM_DISCOVERY);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_PIPELINE_ADDIN,
+ GBP_TYPE_GRADLE_PIPELINE_ADDIN);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_RUN_COMMAND_PROVIDER,
+ GBP_TYPE_GRADLE_RUN_COMMAND_PROVIDER);
+}
diff --git a/src/plugins/gradle/gradle.gresource.xml b/src/plugins/gradle/gradle.gresource.xml
new file mode 100644
index 000000000..c5ed2b343
--- /dev/null
+++ b/src/plugins/gradle/gradle.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/plugins/gradle">
+ <file>gradle.plugin</file>
+ </gresource>
+</gresources>
diff --git a/src/plugins/gradle/gradle.plugin b/src/plugins/gradle/gradle.plugin
index 17ae6807d..420d124ba 100644
--- a/src/plugins/gradle/gradle.plugin
+++ b/src/plugins/gradle/gradle.plugin
@@ -1,12 +1,11 @@
[Plugin]
Authors=Alberto Fanjul Alonso <albfan gnome org>
Builtin=true
-Copyright=Copyright © 2018 Alberto Fanjul Alonso
+Copyright=Copyright © 2018 Alberto Fanjul Alonso, Copyright © 2022 Christian Hergert
Description=Provides integration with the Gradle build tool
-Hidden=true
-Loader=python3
-Module=gradle_plugin
+Embedded=_gbp_gradle_register_types
+Module=gradle
Name=Gradle
+X-Category=buildsystems
X-Project-File-Filter-Name=Gradle (build.gradle)
X-Project-File-Filter-Pattern=build.gradle
-X-Builder-ABI=@PACKAGE_ABI@
diff --git a/src/plugins/gradle/meson.build b/src/plugins/gradle/meson.build
index 3566abb01..5001ebddd 100644
--- a/src/plugins/gradle/meson.build
+++ b/src/plugins/gradle/meson.build
@@ -1,13 +1,19 @@
if get_option('plugin_gradle')
-install_data('gradle_plugin.py', install_dir: plugindir)
-
-configure_file(
- input: 'gradle.plugin',
- output: 'gradle.plugin',
- configuration: config_h,
- install: true,
- install_dir: plugindir,
+plugins_sources += files([
+ 'gradle-plugin.c',
+ 'gbp-gradle-build-system-discovery.c',
+ 'gbp-gradle-build-system.c',
+ 'gbp-gradle-pipeline-addin.c',
+ 'gbp-gradle-run-command-provider.c',
+])
+
+plugin_gradle_resources = gnome.compile_resources(
+ 'gradle-resources',
+ 'gradle.gresource.xml',
+ c_name: 'gbp_gradle',
)
+plugins_sources += plugin_gradle_resources
+
endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]