Class: Buildr::Eclipse::ClasspathEntryWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/buildr/ide/eclipse.rb

Overview

Writes ‘classpathentry’ tags in an xml file. It converts tasks to paths. It converts absolute paths to relative paths. It ignores duplicate directories.

Instance Method Summary collapse

Constructor Details

#initialize(project, target) ⇒ ClasspathEntryWriter

Returns a new instance of ClasspathEntryWriter.



130
131
132
133
134
135
# File 'lib/buildr/ide/eclipse.rb', line 130

def initialize project, target
  @project = project
  @xml = Builder::XmlMarkup.new(:target=>target, :indent=>2)
  @excludes = [ '**/.svn/', '**/CVS/' ].join('|')
  @paths_written = []
end

Instance Method Details

#con(path) ⇒ Object



141
142
143
# File 'lib/buildr/ide/eclipse.rb', line 141

def con path
  @xml.classpathentry :kind=>'con', :path=>path
end

#lib(libs) ⇒ Object



145
146
147
148
149
# File 'lib/buildr/ide/eclipse.rb', line 145

def lib libs
  libs.map(&:to_s).sort.uniq.each do |path|
    @xml.classpathentry :kind=>'lib', :path=>path
  end
end

#output(target) ⇒ Object



169
170
171
# File 'lib/buildr/ide/eclipse.rb', line 169

def output target
  @xml.classpathentry :kind=>'output', :path=>relative(target)
end

#src(arg) ⇒ Object

Write a classpathentry of kind ‘src’. Accepts an array of absolute paths or a task.



153
154
155
156
157
158
159
# File 'lib/buildr/ide/eclipse.rb', line 153

def src arg
  if [:sources, :target].all? { |message| arg.respond_to?(message) }
    src_from_task arg
  else
    src_from_absolute_paths arg
  end
end

#src_projects(project_libs) ⇒ Object

Write a classpathentry of kind ‘src’ for dependent projects. Accepts an array of projects.



163
164
165
166
167
# File 'lib/buildr/ide/eclipse.rb', line 163

def src_projects project_libs
  project_libs.map(&:id).sort.uniq.each do |project_id|
    @xml.classpathentry :kind=>'src', :combineaccessrules=>"false", :path=>"/#{project_id}"
  end
end

#var(libs, var_name, var_value) ⇒ Object



173
174
175
176
177
# File 'lib/buildr/ide/eclipse.rb', line 173

def var libs, var_name, var_value
  libs.map { |lib| lib.to_s.sub(var_value, var_name) }.sort.uniq.each do |path|
    @xml.classpathentry :kind=>'var', :path=>path
  end
end

#write(&block) ⇒ Object



137
138
139
# File 'lib/buildr/ide/eclipse.rb', line 137

def write &block
  @xml.classpath &block
end