[gnome-builder] plugins/maven: port to C



commit d9eac7f96fb3789b84d841cf66c54a023180ae0d
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jul 11 23:04:27 2022 -0700

    plugins/maven: port to C

 .../maven/gbp-maven-build-system-discovery.c       |  47 ++++
 .../maven/gbp-maven-build-system-discovery.h       |  31 +++
 src/plugins/maven/gbp-maven-build-system.c         | 166 ++++++++++++
 src/plugins/maven/gbp-maven-build-system.h         |  33 +++
 src/plugins/maven/gbp-maven-pipeline-addin.c       | 123 +++++++++
 src/plugins/maven/gbp-maven-pipeline-addin.h       |  31 +++
 src/plugins/maven/gbp-maven-run-command-provider.c | 256 +++++++++++++++++++
 src/plugins/maven/gbp-maven-run-command-provider.h |  31 +++
 src/plugins/maven/maven-plugin.c                   |  49 ++++
 src/plugins/maven/maven.gresource.xml              |   6 +
 src/plugins/maven/maven.plugin                     |  12 +-
 src/plugins/maven/maven_plugin.py                  | 277 ---------------------
 src/plugins/maven/meson.build                      |  22 +-
 13 files changed, 792 insertions(+), 292 deletions(-)
---
diff --git a/src/plugins/maven/gbp-maven-build-system-discovery.c 
b/src/plugins/maven/gbp-maven-build-system-discovery.c
new file mode 100644
index 000000000..57f2ea69a
--- /dev/null
+++ b/src/plugins/maven/gbp-maven-build-system-discovery.c
@@ -0,0 +1,47 @@
+/* gbp-maven-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-maven-build-system-discovery"
+
+#include "config.h"
+
+#include "gbp-maven-build-system-discovery.h"
+
+struct _GbpMavenBuildSystemDiscovery
+{
+  IdeSimpleBuildSystemDiscovery parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (GbpMavenBuildSystemDiscovery, gbp_maven_build_system_discovery, 
IDE_TYPE_SIMPLE_BUILD_SYSTEM_DISCOVERY)
+
+static void
+gbp_maven_build_system_discovery_class_init (GbpMavenBuildSystemDiscoveryClass *klass)
+{
+}
+
+static void
+gbp_maven_build_system_discovery_init (GbpMavenBuildSystemDiscovery *self)
+{
+  g_object_set (self,
+                "glob", "pom.xml",
+                "hint", "maven",
+                "priority", 2000,
+                NULL);
+}
diff --git a/src/plugins/maven/gbp-maven-build-system-discovery.h 
b/src/plugins/maven/gbp-maven-build-system-discovery.h
new file mode 100644
index 000000000..904bf65f6
--- /dev/null
+++ b/src/plugins/maven/gbp-maven-build-system-discovery.h
@@ -0,0 +1,31 @@
+/* gbp-maven-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_MAVEN_BUILD_SYSTEM_DISCOVERY (gbp_maven_build_system_discovery_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpMavenBuildSystemDiscovery, gbp_maven_build_system_discovery, GBP, 
MAVEN_BUILD_SYSTEM_DISCOVERY, IdeSimpleBuildSystemDiscovery)
+
+G_END_DECLS
diff --git a/src/plugins/maven/gbp-maven-build-system.c b/src/plugins/maven/gbp-maven-build-system.c
new file mode 100644
index 000000000..dd762ec1f
--- /dev/null
+++ b/src/plugins/maven/gbp-maven-build-system.c
@@ -0,0 +1,166 @@
+/* gbp-maven-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-maven-build-system"
+
+#include "config.h"
+
+#include "gbp-maven-build-system.h"
+
+struct _GbpMavenBuildSystem
+{
+  IdeObject  parent_instance;
+  GFile     *project_file;
+};
+
+enum {
+  PROP_0,
+  PROP_PROJECT_FILE,
+  N_PROPS
+};
+
+static char *
+gbp_maven_build_system_get_id (IdeBuildSystem *build_system)
+{
+  return g_strdup ("maven");
+}
+
+static char *
+gbp_maven_build_system_get_display_name (IdeBuildSystem *build_system)
+{
+  return g_strdup ("Maven");
+}
+
+static int
+gbp_maven_build_system_get_priority (IdeBuildSystem *build_system)
+{
+  return 2000;
+}
+
+static void
+build_system_iface_init (IdeBuildSystemInterface *iface)
+{
+  iface->get_id = gbp_maven_build_system_get_id;
+  iface->get_display_name = gbp_maven_build_system_get_display_name;
+  iface->get_priority = gbp_maven_build_system_get_priority;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpMavenBuildSystem, gbp_maven_build_system, IDE_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_BUILD_SYSTEM, build_system_iface_init))
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+gbp_maven_build_system_dispose (GObject *object)
+{
+  GbpMavenBuildSystem *self = (GbpMavenBuildSystem *)object;
+
+  g_clear_object (&self->project_file);
+
+  G_OBJECT_CLASS (gbp_maven_build_system_parent_class)->dispose (object);
+}
+
+static void
+gbp_maven_build_system_get_property (GObject    *object,
+                                     guint       prop_id,
+                                     GValue     *value,
+                                     GParamSpec *pspec)
+{
+  GbpMavenBuildSystem *self = GBP_MAVEN_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_maven_build_system_set_property (GObject      *object,
+                                     guint         prop_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec)
+{
+  GbpMavenBuildSystem *self = GBP_MAVEN_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_maven_build_system_class_init (GbpMavenBuildSystemClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = gbp_maven_build_system_dispose;
+  object_class->get_property = gbp_maven_build_system_get_property;
+  object_class->set_property = gbp_maven_build_system_set_property;
+
+  properties [PROP_PROJECT_FILE] =
+    g_param_spec_object ("project-file",
+                         "Project File",
+                         "The project file (Maven.toml)",
+                         G_TYPE_FILE,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+gbp_maven_build_system_init (GbpMavenBuildSystem *self)
+{
+}
+
+char *
+gbp_maven_build_system_get_project_dir (GbpMavenBuildSystem *self)
+{
+  g_autoptr(GFile) workdir = NULL;
+  g_autofree char *base = NULL;
+  IdeContext *context;
+
+  g_return_val_if_fail (GBP_IS_MAVEN_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, "pom.xml") == 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/maven/gbp-maven-build-system.h b/src/plugins/maven/gbp-maven-build-system.h
new file mode 100644
index 000000000..03fd0e92a
--- /dev/null
+++ b/src/plugins/maven/gbp-maven-build-system.h
@@ -0,0 +1,33 @@
+/* gbp-maven-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_MAVEN_BUILD_SYSTEM (gbp_maven_build_system_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpMavenBuildSystem, gbp_maven_build_system, GBP, MAVEN_BUILD_SYSTEM, IdeObject)
+
+char *gbp_maven_build_system_get_project_dir (GbpMavenBuildSystem *self);
+
+G_END_DECLS
diff --git a/src/plugins/maven/gbp-maven-pipeline-addin.c b/src/plugins/maven/gbp-maven-pipeline-addin.c
new file mode 100644
index 000000000..926490113
--- /dev/null
+++ b/src/plugins/maven/gbp-maven-pipeline-addin.c
@@ -0,0 +1,123 @@
+/* gbp-maven-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-maven-pipeline-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-foundry.h>
+
+#include "gbp-maven-build-system.h"
+#include "gbp-maven-pipeline-addin.h"
+
+struct _GbpMavenPipelineAddin
+{
+  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 maven to check if build is needed */
+  ide_pipeline_stage_set_completed (stage, FALSE);
+}
+
+static void
+gbp_maven_pipeline_addin_load (IdePipelineAddin *addin,
+                               IdePipeline      *pipeline)
+{
+  g_autoptr(IdeSubprocessLauncher) build_launcher = NULL;
+  g_autoptr(IdeSubprocessLauncher) clean_launcher = NULL;
+  g_autoptr(IdeSubprocessLauncher) install_launcher = NULL;
+  g_autoptr(IdePipelineStage) build_stage = NULL;
+  g_autoptr(IdePipelineStage) install_stage = NULL;
+  IdeBuildSystem *build_system;
+  const char *srcdir;
+  IdeContext *context;
+  guint id;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_MAVEN_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_MAVEN_BUILD_SYSTEM (build_system))
+    IDE_EXIT;
+
+  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 ("mvn", "compile"));
+
+  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 ("mvn", "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);
+
+  install_launcher = ide_pipeline_create_launcher (pipeline, NULL);
+  ide_subprocess_launcher_set_cwd (install_launcher, srcdir);
+  ide_subprocess_launcher_push_args (install_launcher, IDE_STRV_INIT ("mvn", "install", 
"-Dmaven.test.skip=true"));
+  install_stage = ide_pipeline_stage_launcher_new (context, install_launcher);
+  ide_pipeline_stage_set_name (install_stage, _("Installing project"));
+  id = ide_pipeline_attach (pipeline, IDE_PIPELINE_PHASE_INSTALL, 0, install_stage);
+  ide_pipeline_addin_track (addin, id);
+
+  IDE_EXIT;
+}
+
+static void
+pipeline_addin_iface_init (IdePipelineAddinInterface *iface)
+{
+  iface->load = gbp_maven_pipeline_addin_load;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpMavenPipelineAddin, gbp_maven_pipeline_addin, IDE_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_PIPELINE_ADDIN, pipeline_addin_iface_init))
+
+static void
+gbp_maven_pipeline_addin_class_init (GbpMavenPipelineAddinClass *klass)
+{
+}
+
+static void
+gbp_maven_pipeline_addin_init (GbpMavenPipelineAddin *self)
+{
+}
diff --git a/src/plugins/maven/gbp-maven-pipeline-addin.h b/src/plugins/maven/gbp-maven-pipeline-addin.h
new file mode 100644
index 000000000..12d60afac
--- /dev/null
+++ b/src/plugins/maven/gbp-maven-pipeline-addin.h
@@ -0,0 +1,31 @@
+/* gbp-maven-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_MAVEN_PIPELINE_ADDIN (gbp_maven_pipeline_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpMavenPipelineAddin, gbp_maven_pipeline_addin, GBP, MAVEN_PIPELINE_ADDIN, IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/maven/gbp-maven-run-command-provider.c 
b/src/plugins/maven/gbp-maven-run-command-provider.c
new file mode 100644
index 000000000..afc9aa4f5
--- /dev/null
+++ b/src/plugins/maven/gbp-maven-run-command-provider.c
@@ -0,0 +1,256 @@
+/* gbp-maven-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-maven-run-command-provider"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-foundry.h>
+#include <libide-threading.h>
+
+#include "gbp-maven-build-system.h"
+#include "gbp-maven-run-command-provider.h"
+
+struct _GbpMavenRunCommandProvider
+{
+  IdeObject parent_instance;
+};
+
+static void
+find_test_files_cb (GObject      *object,
+                    GAsyncResult *result,
+                    gpointer      user_data)
+{
+  GFile *basedir = (GFile *)object;
+  g_autoptr(IdeTask) task = user_data;
+  g_autoptr(GPtrArray) files = NULL;
+  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 *d_test = 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_strconcat ("maven:%s", full_name, NULL);
+
+          /*
+           * http://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html
+           * it has to be junit 4.x
+           */
+          d_test = g_strconcat ("-Dtest=", full_name, NULL);
+
+          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 ("mvn", d_test, "test"));
+          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_maven_run_command_provider_list_commands_async (IdeRunCommandProvider *provider,
+                                                    GCancellable          *cancellable,
+                                                    GAsyncReadyCallback    callback,
+                                                    gpointer               user_data)
+{
+  GbpMavenRunCommandProvider *self = (GbpMavenRunCommandProvider *)provider;
+  g_autoptr(IdeRunCommand) run_command = NULL;
+  g_autoptr(GStrvBuilder) builder = NULL;
+  g_autoptr(GListStore) store = NULL;
+  g_autoptr(IdeTask) task = NULL;
+  g_autofree char *project_dir = NULL;
+  IdeConfigManager *config_manager;
+  IdeBuildSystem *build_system;
+  g_autoptr(GFile) testdir = NULL;
+  g_auto(GStrv) run_argv = NULL;
+  g_auto(GStrv) args = NULL;
+  const char *run_opts;
+  IdeContext *context;
+  IdeConfig *config;
+  int run_argc;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_MAVEN_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_maven_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);
+  config_manager = ide_config_manager_from_context (context);
+  config = ide_config_manager_get_current (config_manager);
+  run_opts = ide_config_get_run_opts (config);
+
+  if (!GBP_IS_MAVEN_BUILD_SYSTEM (build_system))
+    {
+      ide_task_return_new_error (task,
+                                 G_IO_ERROR,
+                                 G_IO_ERROR_NOT_SUPPORTED,
+                                 "Not a maven build system");
+      IDE_EXIT;
+    }
+
+  project_dir = gbp_maven_build_system_get_project_dir (GBP_MAVEN_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, "maven:run");
+  ide_run_command_set_priority (run_command, -500);
+  ide_run_command_set_display_name (run_command, _("Maven Run"));
+  ide_run_command_set_cwd (run_command, project_dir);
+
+  /*
+   * This requires an argument -Dexec.mainClass="my.package.MainClass"
+   * Use run-opts in your config/manifest/etc.
+   */
+  builder = g_strv_builder_new ();
+  g_strv_builder_add_many (builder, "mvn", "exec:java", NULL);
+  if (g_shell_parse_argv (run_opts, &run_argc, &run_argv, NULL))
+    g_strv_builder_addv (builder, (const char **)run_argv);
+  args = g_strv_builder_end (builder);
+  ide_run_command_set_argv (run_command, (const char * const *)args);
+  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_maven_run_command_provider_list_commands_finish (IdeRunCommandProvider  *provider,
+                                                     GAsyncResult           *result,
+                                                     GError                **error)
+{
+  GListModel *ret;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_MAVEN_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_maven_run_command_provider_list_commands_async;
+  iface->list_commands_finish = gbp_maven_run_command_provider_list_commands_finish;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpMavenRunCommandProvider, gbp_maven_run_command_provider, IDE_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_RUN_COMMAND_PROVIDER, 
run_command_provider_iface_init))
+
+static void
+gbp_maven_run_command_provider_class_init (GbpMavenRunCommandProviderClass *klass)
+{
+}
+
+static void
+gbp_maven_run_command_provider_init (GbpMavenRunCommandProvider *self)
+{
+}
diff --git a/src/plugins/maven/gbp-maven-run-command-provider.h 
b/src/plugins/maven/gbp-maven-run-command-provider.h
new file mode 100644
index 000000000..22a06b4c0
--- /dev/null
+++ b/src/plugins/maven/gbp-maven-run-command-provider.h
@@ -0,0 +1,31 @@
+/* gbp-maven-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_MAVEN_RUN_COMMAND_PROVIDER (gbp_maven_run_command_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpMavenRunCommandProvider, gbp_maven_run_command_provider, GBP, 
MAVEN_RUN_COMMAND_PROVIDER, IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/maven/maven-plugin.c b/src/plugins/maven/maven-plugin.c
new file mode 100644
index 000000000..28de83970
--- /dev/null
+++ b/src/plugins/maven/maven-plugin.c
@@ -0,0 +1,49 @@
+/* maven-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 "maven-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+
+#include <libide-foundry.h>
+
+#include "gbp-maven-build-system.h"
+#include "gbp-maven-build-system-discovery.h"
+#include "gbp-maven-pipeline-addin.h"
+#include "gbp-maven-run-command-provider.h"
+
+_IDE_EXTERN void
+_gbp_maven_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_BUILD_SYSTEM,
+                                              GBP_TYPE_MAVEN_BUILD_SYSTEM);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_BUILD_SYSTEM_DISCOVERY,
+                                              GBP_TYPE_MAVEN_BUILD_SYSTEM_DISCOVERY);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_PIPELINE_ADDIN,
+                                              GBP_TYPE_MAVEN_PIPELINE_ADDIN);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_RUN_COMMAND_PROVIDER,
+                                              GBP_TYPE_MAVEN_RUN_COMMAND_PROVIDER);
+}
diff --git a/src/plugins/maven/maven.gresource.xml b/src/plugins/maven/maven.gresource.xml
new file mode 100644
index 000000000..6352fd3a5
--- /dev/null
+++ b/src/plugins/maven/maven.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/plugins/maven">
+    <file>maven.plugin</file>
+  </gresource>
+</gresources>
diff --git a/src/plugins/maven/maven.plugin b/src/plugins/maven/maven.plugin
index a306895b4..8c4aa6f44 100644
--- a/src/plugins/maven/maven.plugin
+++ b/src/plugins/maven/maven.plugin
@@ -1,13 +1,11 @@
 [Plugin]
 Authors=Alberto Fanjul Alonso <albfan gnome org>
 Builtin=true
-Copyright=Copyright © 2018 Alberto Fanjul Alonso
-Description=Provides integration with the Maven build tool
-Depends=editor;buildui;
-Hidden=true
-Loader=python3
-Module=maven_plugin
+Copyright=Copyright © 2018 Alberto Fanjul Alonso, Copyright © 2022 Christian Hergert
+Description=Provides integration with the Maven build system
+Embedded=_gbp_maven_register_types
+Module=maven
 Name=Maven
-X-Builder-ABI=@PACKAGE_ABI@
+X-Category=buildsystems
 X-Project-File-Filter-Name=Maven (pom.xml)
 X-Project-File-Filter-Pattern=pom.xml
diff --git a/src/plugins/maven/meson.build b/src/plugins/maven/meson.build
index fc1a059d8..a9a7a565c 100644
--- a/src/plugins/maven/meson.build
+++ b/src/plugins/maven/meson.build
@@ -1,13 +1,19 @@
 if get_option('plugin_maven')
 
-install_data('maven_plugin.py', install_dir: plugindir)
-
-configure_file(
-          input: 'maven.plugin',
-         output: 'maven.plugin',
-  configuration: config_h,
-        install: true,
-    install_dir: plugindir,
+plugins_sources += files([
+  'maven-plugin.c',
+  'gbp-maven-build-system-discovery.c',
+  'gbp-maven-build-system.c',
+  'gbp-maven-pipeline-addin.c',
+  'gbp-maven-run-command-provider.c',
+])
+
+plugin_maven_resources = gnome.compile_resources(
+  'maven-resources',
+  'maven.gresource.xml',
+  c_name: 'gbp_maven',
 )
 
+plugins_sources += plugin_maven_resources
+
 endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]