Module: Tetra::Scriptable

Included in:
Package
Defined in:
lib/tetra/packages/scriptable.rb

Overview

generates a package build script from bash_history

Instance Method Summary collapse

Instance Method Details

#_to_script(project) ⇒ Object

returns a build script for this package



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tetra/packages/scriptable.rb', line 7

def _to_script(project)
  project.from_directory do
    script_lines = [
      "#!/bin/bash",
      "set -xe",
      "PROJECT_PREFIX=`readlink -e .`",
      "cd #{project.latest_dry_run_directory}"
    ] + script_body(project)

    new_content = script_lines.join("\n") + "\n"

    result_dir = File.join(project.packages_dir, project.name)
    FileUtils.mkdir_p(result_dir)
    result_path = File.join(result_dir, "build.sh")
    conflict_count = project.merge_new_content(new_content, result_path, "Build script generated",
                                               "script")

    [result_path, conflict_count]
  end
end

#script_body(project) ⇒ Object

returns the script body by taking the last dry-run’s build script lines and adjusting mvn and ant’s paths



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tetra/packages/scriptable.rb', line 30

def script_body(project)
  lines = project.build_script_lines

  kit = Tetra::Kit.new(project)
  ant_path = kit.find_executable("ant")
  ant_commandline = Tetra::Ant.commandline("$PROJECT_PREFIX", ant_path)

  mvn_path = kit.find_executable("mvn")
  mvn_commandline = Tetra::Mvn.commandline("$PROJECT_PREFIX", mvn_path)

  lines.map do |line|
    if line =~ /^ant( .*)?$/
      line.gsub(/^ant/, ant_commandline)
    elsif line =~ /^mvn( .*)?$/
      line.gsub(/^mvn/, "#{mvn_commandline} -o")
    else
      line
    end
  end
end