Class: Winter::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/winter/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DSL

Returns a new instance of DSL.



30
31
32
33
34
35
36
37
38
39
# File 'lib/winter/dsl.rb', line 30

def initialize( options={} )
  @name         = 'default'
  @groups       = []
  @repositories = []
  @dependencies = []
  @options      = options
  @config       = {}
  @directives   = {}
  @felix        = nil
end

Class Method Details

.evaluate(winterfile, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/winter/dsl.rb', line 41

def self.evaluate( winterfile, options={} )
  # Must create instance for instance_eval to have correct scope
  if !File.exists?(winterfile)
    raise "#{winterfile} not found."
  end
  dsl = DSL.new options
  res = dsl.eval_winterfile winterfile
  validate(res)
end

.validate(res) ⇒ Object



72
73
74
75
# File 'lib/winter/dsl.rb', line 72

def self.validate( res )
  raise "Must have at least one service name." if res[:config]['service'].nil?
  res
end

Instance Method Details

#bundle(group, artifact, version = 'LATEST', *args) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/winter/dsl.rb', line 110

def bundle( group, artifact, version='LATEST', *args )
  options = Hash === args.last ? args.pop : {}
  dep = Dependency.new
  dep.artifact      = artifact
  dep.group         = group
  dep.version       = version
  dep.repositories  = @repositories
  dep.package       = options[:package] || 'jar'
  dep.offline       = @options['local'] || @options['local'] == 'true'
  dep.transative    = false
  dep.destination   = File.join(Dir.getwd,RUN_DIR,@name,BUNDLES_DIR)
  #dep.verbose       = true

  @dependencies.push dep
  dep
end

#conf(dir) ⇒ Object



146
147
148
149
150
# File 'lib/winter/dsl.rb', line 146

def conf( dir )
  #We strip off the final / to normalize the input.
  #If we don't do that then process_templates will end up with crazy file names. 
  process_templates( dir.sub(/\/$/,""), File.join(WINTERFELL_DIR,RUN_DIR,@name,'conf') )
end

#directive(key, value = nil) ⇒ Object



89
90
91
# File 'lib/winter/dsl.rb', line 89

def directive( key, value=nil )
  @directives[key] = value
end

#eval_winterfile(winterfile, contents = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/winter/dsl.rb', line 51

def eval_winterfile( winterfile, contents=nil )
  contents ||= File.open(winterfile.to_s, "rb"){|f| f.read}
  
  # set CWD to where the winterfile is located
  Dir.chdir(File.split(winterfile.to_s)[0]) do
    instance_eval(contents)
  end
  
  # add default felix in context
  if !@felix   #TODO Move default version somewhere
    @felix = lib('org.apache.felix', 'org.apache.felix.main', '4.0.2')
  end

  {
    :config       => @config,
    :dependencies => @dependencies,
    :felix        => @felix,
    :directives   => @directives
  }
end

#felix(group, artifact, version = 'LATEST', *args) ⇒ Object



127
128
129
# File 'lib/winter/dsl.rb', line 127

def felix( group, artifact, version='LATEST', *args )
  @felix = lib( group, artifact, version, args )
end

#group(*args, &blk) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/winter/dsl.rb', line 160

def group(*args, &blk)
  @groups.concat args
  #$LOG.info @options['group'].split(",")
  #$LOG.info "in group " << @groups.join("::")
  if( @options['group'] \
     && @options['group'].split(",").include?(@groups.join("::")) )
    yield
  end
ensure
  args.each { @groups.pop }
end

#info(msg = nil) ⇒ Object



85
86
87
# File 'lib/winter/dsl.rb', line 85

def info( msg=nil )
  $LOG.info msg
end

#lib(group, artifact, version = 'LATEST', *args) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/winter/dsl.rb', line 93

def lib( group, artifact, version='LATEST', *args )
  options = Hash === args.last ? args.pop : {}
  dep = Dependency.new
  dep.artifact      = artifact
  dep.group         = group
  dep.version       = version
  dep.repositories  = @repositories
  dep.package       = options[:package] || 'jar'
  dep.offline       = @options['local'] || @options['local'] == 'true'
  dep.transative    = false
  dep.destination   = File.join(Dir.getwd,RUN_DIR,@name,LIBS_DIR)
  #dep.verbose       = true

  @dependencies.push dep
  dep
end

#name(name) ⇒ Object

************************************************************************** Winterfile DSL spec **************************************************************************



81
82
83
# File 'lib/winter/dsl.rb', line 81

def name( name )
  @name = @config['service'] = name
end

#pom(pom, *args) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/winter/dsl.rb', line 131

def pom( pom, *args )
  if pom.is_a?(Symbol)
    raise "Poms must be URLs, paths to poms, or Strings"
  end

  pom_file = MavenPom.fetch(pom)
  pom_spec = MavenPom.parse_pom(pom_file)
  pom_spec.dependencies.each do |dep|
    $LOG.debug dep
    if dep[:scope] == 'provided'
      lib( dep[:group], dep[:artifact], dep[:version] ) 
    end
  end
end

#read(file) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/winter/dsl.rb', line 152

def read( file )
  if File.exist?(file)
    @config.merge!( JSON.parse(File.read file ))
  else
    $LOG.warn "#{file} could not be found."
  end
end

#repository(url) ⇒ Object Also known as: repo



172
173
174
# File 'lib/winter/dsl.rb', line 172

def repository( url )
  @repositories.push url
end