Class: FlutterRb::GradleParser

Inherits:
Object
  • Object
show all
Defined in:
lib/flutter_rb/project/specs/android/gradle.rb

Overview

This class is responsible for parsing Gradle project information.

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ GradleParser

Initializes a new GradleParser instance.

Parameters:

  • path (String)

    The path to the Gradle project.



33
34
35
# File 'lib/flutter_rb/project/specs/android/gradle.rb', line 33

def initialize(path)
  @path = path
end

Instance Method Details

#parseGradle

Parses the Gradle project information.

Executes the ‘prepareInfo’ task in the Gradle project and reads the generated JSON file. If the JSON file does not exist, it raises an error.

Returns:

  • (Gradle)

    An instance of Gradle with the parsed information.



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/flutter_rb/project/specs/android/gradle.rb', line 43

def parse
  `gradle -p #{@path} -q prepareInfo` # Execute the 'prepareInfo' task in the Gradle project
  info_file_path = "#{@path}/flutter_rb_gradle_plugin_output.json" # Path to the JSON file

  unless File.exist?(info_file_path) # Check if the JSON file exists
    raise "Could not find Gradle info file at #{info_file_path}" # Raise an error if the JSON file does not exist
  end

  info_file = File.read info_file_path # Read the JSON file
  info = JSON.parse info_file # Parse the JSON content

  Gradle.new(@path, info['version']) # Create a new Gradle instance with the parsed information
end