Class: Distil::Project

Inherits:
Configurable show all
Includes:
ErrorReporter
Defined in:
lib/distil/project.rb

Direct Known Subclasses

DistilProject, ExternalProject, RemoteProject

Instance Attribute Summary

Attributes inherited from Configurable

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ErrorReporter

#error, error, #ignore_warnings, #ignore_warnings=, #report, warning, #warning

Methods inherited from Configurable

#get_option, #get_options, #initialize, option

Constructor Details

This class inherits a constructor from Configurable

Class Method Details

.fetch_project_using_git(options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/distil/project.rb', line 24

def self.fetch_project_using_git(options = {})
  uri= options["repository"]
  path= options["path"]
  
  begin
    `git --version 2>/dev/null`
  rescue
    nil
  end
  if $?.nil? || !$?.success?
    raise ValidationError.new("The git version control tool is required to pull this repository: #{uri}")
  end
  
  FileUtils.mkdir_p(path)
  Dir.chdir path do
    init_cmd = "git init"
    init_cmd+= " -q"
    # init_cmd += " -q" if options[:quiet] and not $verbose
    # puts init_cmd if $verbose
    system(init_cmd)
    # base_cmd = "git pull --depth 1 #{uri}"
    base_cmd = "git pull #{uri}"
    base_cmd+= " -q"
    # base_cmd += " -q" if options[:quiet] and not $verbose
    base_cmd += " #{options["version"]}" if options["version"]
    # puts base_cmd if $verbose
    if system(base_cmd)
      # puts "removing: .git .gitignore" if $verbose
      # FileUtils.rm_rf %w(.git .gitignore)
    else
      # rm_rf path
    end
  end
end

.from_config(config, parent = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/distil/project.rb', line 59

def self.from_config(config, parent=nil)

  if config.is_a?(String)
    string= config
    uri= URI.parse(string)
    
    config= { "name" => File.basename(config, ".*") }
    
    case
    when ['.js', '.css'].include?(File.extname(uri.path))
      config["href"]= uri.to_s
    when uri.scheme
      config["repository"]= uri.to_s
    else
      config["path"]= uri.to_s
    
      full_path= File.expand_path(config["path"])
    
      if File.exist?(full_path) && File.file?(full_path)
        config["path"]= File.dirname(full_path)
      else
        config["path"]= full_path
      end
    end
  end

  if !config["name"]
    case when config["repository"]
      uri= URI.parse(config["repository"])
      config["name"]= File.basename(uri.path, ".*")
    when config["path"]
      config["name"]= File.basename(config["path"], ".*")
    else
      raise ValidationError.new("External project has neither name, path nor repository")
    end
  end

  if config["href"]
    return RemoteProject.new(config, parent)
  end
  
  config["path"]||= "ext/#{config["name"]}"

  if config["repository"] && !File.directory?(config["path"])
    fetch_project_using_git(config)
  end
  
  config["mode"]||= parent.mode if parent
    
  path= config["path"]
  if !path
    ErrorReporter.error "No path for project: #{config["name"]}"
    return nil
  end
  
  if !File.directory?(path)
    ErrorReporter.error "Path is not valid for project: #{config["name"]}"
    return nil
  end
  
  basename= File.basename(path)
  
  case
  when exist?(path, "#{basename}.jsproj")
    project_file= File.join(path, "#{basename}.jsproj")
    project_info= YAML.load_file(project_file)
    project_info.merge!(config)
    project_info["path"]= path
    project= ExternalProject.new(project_info, parent)
    if parent
      project.build_command ||= "distil --mode=#{parent.mode} --force=#{parent.force}"
    else
      project.build_command ||= "distil"
    end
  when exist?(path, "Makefile") || exist?(path, "makefile")
    project= ExternalProject.new(config, parent)
    project.build_command ||= "make"
  when exist?(path, "Rakefile") || exist?(path, "rakefile")
    project= ExternalProject.new(config, parent)
    project.build_command ||= "rake"
  when exist?(path, "Jakefile") || exist?(path, "jakefile")
    project= ExternalProject.new(config, parent)
    project.build_command ||= "jake"
  else
    ErrorReporter.error "Could not determine type for project: #{config["name"]}"
  end
  return project
  
end

Instance Method Details

#buildObject



18
19
# File 'lib/distil/project.rb', line 18

def build
end

#cleanObject



21
22
# File 'lib/distil/project.rb', line 21

def clean
end

#up_to_dateObject



14
15
16
# File 'lib/distil/project.rb', line 14

def up_to_date
  true
end