[gnome-builder: 100/139] maven: port to libide-foundry



commit f5451f948fcad66da1342af13d23a47031aa470d
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 17:28:47 2019 -0800

    maven: port to libide-foundry

 src/plugins/maven/maven.plugin    | 15 ++++++-----
 src/plugins/maven/maven_plugin.py | 53 +++++++++++++--------------------------
 src/plugins/maven/meson.build     |  4 +--
 3 files changed, 28 insertions(+), 44 deletions(-)
---
diff --git a/src/plugins/maven/maven.plugin b/src/plugins/maven/maven.plugin
index afc3953f3..a306895b4 100644
--- a/src/plugins/maven/maven.plugin
+++ b/src/plugins/maven/maven.plugin
@@ -1,10 +1,13 @@
 [Plugin]
-Module=maven_plugin
-Name=Maven
-Loader=python3
-Description=Provides integration with the Maven build tool
 Authors=Alberto Fanjul Alonso <albfan gnome org>
-Copyright=Copyright © 2018 Alberto Fanjul Alonso
 Builtin=true
-X-Project-File-Filter-Pattern=pom.xml
+Copyright=Copyright © 2018 Alberto Fanjul Alonso
+Description=Provides integration with the Maven build tool
+Depends=editor;buildui;
+Hidden=true
+Loader=python3
+Module=maven_plugin
+Name=Maven
+X-Builder-ABI=@PACKAGE_ABI@
 X-Project-File-Filter-Name=Maven (pom.xml)
+X-Project-File-Filter-Pattern=pom.xml
diff --git a/src/plugins/maven/maven_plugin.py b/src/plugins/maven/maven_plugin.py
index 546ca3e25..c0c7db4b8 100755
--- a/src/plugins/maven/maven_plugin.py
+++ b/src/plugins/maven/maven_plugin.py
@@ -19,12 +19,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-import gi
 import threading
 import os
 
-gi.require_version('Ide', '1.0')
-
 from gi.repository import Gio
 from gi.repository import GLib
 from gi.repository import GObject
@@ -38,7 +35,14 @@ _ATTRIBUTES = ",".join([
     Gio.FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON,
 ])
 
-class MavenBuildSystem(Ide.Object, Ide.BuildSystem, Gio.AsyncInitable):
+class MavenBuildSystemDiscovery(Ide.SimpleBuildSystemDiscovery):
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.props.glob = 'pom.xml'
+        self.props.hint = 'maven_plugin'
+        self.props.priority = 2000
+
+class MavenBuildSystem(Ide.Object, Ide.BuildSystem):
     project_file = GObject.Property(type=Gio.File)
 
     def do_get_id(self):
@@ -47,32 +51,8 @@ class MavenBuildSystem(Ide.Object, Ide.BuildSystem, Gio.AsyncInitable):
     def do_get_display_name(self):
         return 'Maven'
 
-    def do_init_async(self, io_priority, cancellable, callback, data):
-        task = Ide.Task.new(self, cancellable, callback)
-
-        try:
-            # Maybe this is a pom.xml
-            if self.props.project_file.get_basename() in ('pom.xml',):
-                task.return_boolean(True)
-                return
-
-            # Maybe this is a directory with a pom.xml
-            if self.props.project_file.query_file_type(0) == Gio.FileType.DIRECTORY:
-                child = self.props.project_file.get_child('pom.xml')
-                if child.query_exists(None):
-                    self.props.project_file = child
-                    task.return_boolean(True)
-                    return
-        except Exception as ex:
-            task.return_error(ex)
-
-        task.return_error(Ide.NotSupportedError())
-
-    def do_init_finish(self, task):
-        return task.propagate_boolean()
-
     def do_get_priority(self):
-        return 400
+        return 2000
 
 class MavenPipelineAddin(Ide.Object, Ide.BuildPipelineAddin):
     """
@@ -82,7 +62,7 @@ class MavenPipelineAddin(Ide.Object, Ide.BuildPipelineAddin):
 
     def do_load(self, pipeline):
         context = self.get_context()
-        build_system = context.get_build_system()
+        build_system = Ide.BuildSystem.from_context(context)
 
         if type(build_system) != MavenBuildSystem:
             return
@@ -156,7 +136,7 @@ class MavenBuildTargetProvider(Ide.Object, Ide.BuildTargetProvider):
         task.set_priority(GLib.PRIORITY_LOW)
 
         context = self.get_context()
-        build_system = context.get_build_system()
+        build_system = Ide.BuildSystem.from_context(context)
 
         if type(build_system) != MavenBuildSystem:
             task.return_error(GLib.Error('Not maven build system',
@@ -178,7 +158,7 @@ class MavenIdeTestProvider(Ide.TestProvider):
         task.set_priority(GLib.PRIORITY_LOW)
 
         context = self.get_context()
-        build_system = context.get_build_system()
+        build_system = Ide.BuildSystem.from_context(context)
 
         if type(build_system) != MavenBuildSystem:
             task.return_error(GLib.Error('Not maven build system',
@@ -226,14 +206,14 @@ class MavenIdeTestProvider(Ide.TestProvider):
     def do_reload(self):
 
         context = self.get_context()
-        build_system = context.get_build_system()
+        build_system = Ide.BuildSystem.from_context(context)
 
         if type(build_system) != MavenBuildSystem:
             return
 
         # find all files in test directory
         # http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
-        build_manager = context.get_build_manager()
+        build_manager = Ide.BuildManager.from_context(context)
         pipeline = build_manager.get_pipeline()
         srcdir = pipeline.get_srcdir()
         test_suite = Gio.File.new_for_path(os.path.join(srcdir, 'src/test/java'))
@@ -260,8 +240,9 @@ class MavenIdeTestProvider(Ide.TestProvider):
                                                     self.on_enumerator_loaded,
                                                     None)
                 else:
-                    #TODO Ask java through introspection for classes with TestCase and its public void 
methods 
-                    # or Annotation @Test methods
+                    # TODO: Ask java through introspection for classes with
+                    # TestCase and its public void methods or Annotation @Test
+                    # methods
                     result, contents, etag = gfile.load_contents()
                     tests = [x for x in str(contents).split('\\n') if 'public void' in x]
                     tests = [v.replace("()", "").replace("public void","").strip() for v in tests]
diff --git a/src/plugins/maven/meson.build b/src/plugins/maven/meson.build
index f174eb853..fc1a059d8 100644
--- a/src/plugins/maven/meson.build
+++ b/src/plugins/maven/meson.build
@@ -1,11 +1,11 @@
-if get_option('with_maven')
+if get_option('plugin_maven')
 
 install_data('maven_plugin.py', install_dir: plugindir)
 
 configure_file(
           input: 'maven.plugin',
          output: 'maven.plugin',
-           copy: true,
+  configuration: config_h,
         install: true,
     install_dir: plugindir,
 )


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