Class: Distil::DistilProject

Inherits:
Project show all
Defined in:
lib/distil/project/distil-project.rb

Instance Attribute Summary collapse

Attributes inherited from Configurable

#options

Instance Method Summary collapse

Methods inherited from Project

fetch_project_using_git, from_config

Methods included from ErrorReporter

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

Methods inherited from Configurable

#get_option, #get_options, option

Constructor Details

#initialize(project_file, settings = {}, parent = nil) ⇒ DistilProject

Returns a new instance of DistilProject.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/distil/project/distil-project.rb', line 13

def initialize(project_file, settings={}, parent=nil)
  
  begin

    @project_file= File.expand_path(project_file)
    @projects_by_name={}

    project_info= YAML.load_file(@project_file)
    project_info["path"]= File.dirname(@project_file)

    super(project_info, parent)
    get_options(settings, parent)

    FileUtils.mkdir_p(output_folder)

    load_external_projects
    find_targets
    load_distileries
    
  rescue ValidationError => err
    puts "#{APP_NAME}: #{SourceFile.path_relative_to_folder(project_file, Dir.pwd)}: #{err.message}\n"
    exit 1
  end
  
end

Instance Attribute Details

#project_fileObject (readonly)

Returns the value of attribute project_file.



5
6
7
# File 'lib/distil/project/distil-project.rb', line 5

def project_file
  @project_file
end

#targetsObject (readonly)

Returns the value of attribute targets.



5
6
7
# File 'lib/distil/project/distil-project.rb', line 5

def targets
  @targets
end

Instance Method Details

#buildObject



119
120
121
122
# File 'lib/distil/project/distil-project.rb', line 119

def build
  build_external_projects
  build_targets
end

#build_external_projectsObject



124
125
126
127
128
# File 'lib/distil/project/distil-project.rb', line 124

def build_external_projects
  external_projects.each { |project|
    project.build
  }
end

#build_targetsObject



130
131
132
133
134
# File 'lib/distil/project/distil-project.rb', line 130

def build_targets
  targets.each { |target|
    target.build
  }
end

#cleanObject



112
113
114
115
116
117
# File 'lib/distil/project/distil-project.rb', line 112

def clean
  # clean_external_projects
  targets.each { |target|
    target.clean
  }
end

#external_project_with_name(name) ⇒ Object



67
68
69
# File 'lib/distil/project/distil-project.rb', line 67

def external_project_with_name(name)
  @projects_by_name[name]
end

#find_file(file, source_file = nil) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/distil/project/distil-project.rb', line 136

def find_file(file, source_file=nil)
  return nil if external_projects.nil?
  
  parts= file.split(File::SEPARATOR)
  project_name= parts[0]

  external_project= external_project_with_name(project_name)
  return nil if !external_project

  if 1==parts.length
    return SourceFile::from_path(external_project.product_name(:import, source_file.extension))
  else
    return SourceFile::from_path(File.join(external_project.output_folder, *parts[1..-1]))
  end
end

#find_targetsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/distil/project/distil-project.rb', line 39

def find_targets
  @targets= []
  target_list= @extras['targets']

  if !target_list
    @targets << Target.new(@extras.clone, self)
    return @targets
  end

  @targets= target_list.map { |target|
    Target.new(target, self)
  }
end

#launchObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/distil/project/distil-project.rb', line 71

def launch
  build if !up_to_date
  
  require 'webrick'
  config= {
    :Port => 8888
  }

  server= WEBrick::HTTPServer.new(config)
  server.mount("/", WEBrick::HTTPServlet::FileHandler, output_folder)

  ['INT', 'TERM'].each { |signal|
     trap(signal){ server.shutdown} 
  }
  b= Browser.new
  b.open("http://localhost:8888/")
  server.start
end

#load_distileriesObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/distil/project/distil-project.rb', line 90

def load_distileries
  return if distileries.nil?

  distileries.each { |d|
    if (File.exists?(d))
      require d
      next
    end
    path= Gem.required_location(d, 'distilery.rb')
    if (path.nil?)
      puts "Missing distilery: #{d}"
    end
    next if path.nil?
    require path
  }
end

#load_external_projectsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/distil/project/distil-project.rb', line 53

def load_external_projects
  return if !external_projects
  projects= []
  
  external_projects.each { |config|
    project= Project.from_config(config, self)
    next if !project
    projects << project
    @projects_by_name[project.name]= project
  }
  
  self.external_projects= projects
end

#up_to_dateObject



107
108
109
110
# File 'lib/distil/project/distil-project.rb', line 107

def up_to_date
  return false if !external_projects.all?{ |project| project.up_to_date }
  return targets.all? { |target| target.up_to_date }
end