Class: Chrysalis::Project

Inherits:
Object show all
Defined in:
lib/chrysalis/project.rb

Overview

Represents a software development project, typically an application or library.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Project

Returns a new instance of Project.

Yields:

  • (_self)

Yield Parameters:



17
18
19
20
21
22
23
24
# File 'lib/chrysalis/project.rb', line 17

def initialize
  Chrysalis::Manifest.instance << self
  
  @working_copy = nil
  @tasks = {}
  @dependencies = []
  yield self if block_given?
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/chrysalis/project.rb', line 13

def name
  @name
end

#versionObject

Returns the value of attribute version.



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

def version
  @version
end

#working_copyObject

Returns the value of attribute working_copy.



15
16
17
# File 'lib/chrysalis/project.rb', line 15

def working_copy
  @working_copy
end

Instance Method Details

#dependency(url, params = {}) ⇒ Object Also known as: dependency=

Add a dependency, located at url, to the project.



31
32
33
# File 'lib/chrysalis/project.rb', line 31

def dependency(url, params = {})
  @dependencies << [url, params]
end

#graph(g = GRATR::Digraph.new) ⇒ Object



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
# File 'lib/chrysalis/project.rb', line 88

def graph(g = GRATR::Digraph.new)
  @dependencies.each do |url, params|
    raise "Illegal declaration of dependency on self." if self.url == url
    
    # If an arc has already been connected between a project and a
    # dependency, a cycle has been induced.  This needs to be detected to
    # prevent this function from looping indefinately.
    #
    # For example:
    #  libone ---depends-on--> libtwo
    #  libtwo ---depends-on--> libone
    #
    # Would graph as follows:
    #  libone --> libtwo
    #    ^           |
    #    '-----------'
    #
    # If not prevented this will keep adding edges from libone -> libtwo ->
    # libone -> libtwo -> libone, and on and on and on, ad infinitum.
    if !g.edge?(self.url, url)
      g.add_edge!(self.url, url)
      
      # Build the graph recursively, by telling the dependency to construct
      # its portion.
      dep = Chrysalis::Manifest.instance[url]
      dep.graph(g) if !dep.nil?
    end
  end
  
  return g.add_vertex!(self.url)
end

#infoObject



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/chrysalis/project.rb', line 74

def info
  n = (@name ? @name : "<Unknown Name>")
  v = (@version ? "(#{@version})" : "")
  
  printf "- %s %s\n", n, v
  puts   "  #{self.url}" if self.url.is_a?(String)

  if Rake.application.options.trace
    @tasks.each do |name, comment|
      printf "     %-18s # %s\n", name, comment
    end
  end
end

#retrieveObject

Retrieve all dependencies required by the project.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/chrysalis/project.rb', line 48

def retrieve
  # A project can be declared as a dependency multiple times, which is a
  # common occurance for shared libraries.  After the initial retrieval, the
  # retrieved flag is set.  Subsequent retrievals are unnessesary.
  return if @retrieved
  @retrieved = true
  
  FileUtils.mkdir_p(Chrysalis.options.prefix)
  
  # Retrieve each direct dependency from its repository, and load it into
  # the manifest.
  @dependencies.each do |url, params|
    # If the URL of the project is already in the manifest, it has already
    # been loaded.
    if !Chrysalis::Manifest.instance[url]
      working_copy = Repository.retrieve(url, Chrysalis.options.prefix, params)
      Chrysalis::Loader.instance.load(url, working_copy)
    end
  end
  
  # Transitively retrieve dependencies.
  @dependencies.each do |url, params|
    Chrysalis::Manifest.instance[url].retrieve
  end
end

#task(name, comment) ⇒ Object



37
38
39
40
41
# File 'lib/chrysalis/project.rb', line 37

def task(name, comment)
  desc = (@tasks.has_key?(name) ? @tasks[name] : '')
  desc.concat_sep(comment, " / ")
  @tasks[name] = desc
end

#task?(name) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/chrysalis/project.rb', line 43

def task?(name)
  @tasks.has_key? name
end

#task_exec_orderObject



120
121
122
123
124
125
# File 'lib/chrysalis/project.rb', line 120

def task_exec_order
  g = graph
  raise "Cyclic dependency detected." if g.cyclic?
  
  g.topsort.reverse
end

#urlObject



26
27
28
# File 'lib/chrysalis/project.rb', line 26

def url
  Chrysalis::Manifest.instance[self]
end