Class: Buildr::Eclipse::ClasspathEntryWriter
- 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
- #con(path) ⇒ Object
-
#initialize(project, target) ⇒ ClasspathEntryWriter
constructor
:nodoc:.
- #lib(libs) ⇒ Object
- #output(target) ⇒ Object
-
#src(arg) ⇒ Object
Write a classpathentry of kind ‘src’.
-
#src_projects(project_libs) ⇒ Object
Write a classpathentry of kind ‘src’ for dependent projects.
-
#var(libs) ⇒ Object
Write a classpathentry of kind ‘var’ (variable) for a library in a local repo.
- #write(&block) ⇒ Object
Constructor Details
#initialize(project, target) ⇒ ClasspathEntryWriter
:nodoc:
310 311 312 313 314 315 |
# File 'lib/buildr/ide/eclipse.rb', line 310 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
321 322 323 |
# File 'lib/buildr/ide/eclipse.rb', line 321 def con path @xml.classpathentry :kind=>'con', :path=>path end |
#lib(libs) ⇒ Object
325 326 327 328 329 |
# File 'lib/buildr/ide/eclipse.rb', line 325 def lib libs libs.map(&:to_s).sort.uniq.each do |path| @xml.classpathentry :kind=>'lib', :path=>relative(path) end end |
#output(target) ⇒ Object
349 350 351 |
# File 'lib/buildr/ide/eclipse.rb', line 349 def output target @xml.classpathentry :kind=>'output', :path=>relative(target) end |
#src(arg) ⇒ Object
Write a classpathentry of kind ‘src’. Accept an array of absolute paths or a task.
333 334 335 336 337 338 339 |
# File 'lib/buildr/ide/eclipse.rb', line 333 def src arg if [:sources, :target].all? { || arg.respond_to?() } 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. Accept an array of projects.
343 344 345 346 347 |
# File 'lib/buildr/ide/eclipse.rb', line 343 def src_projects project_libs project_libs.map { |project| project.eclipse.name }.sort.uniq.each do |eclipse_name| @xml.classpathentry :kind=>'src', :combineaccessrules=>'false', :path=>"/#{eclipse_name}" end end |
#var(libs) ⇒ Object
Write a classpathentry of kind ‘var’ (variable) for a library in a local repo.
-
libs
is an array of library paths. -
var_name
is a variable name as defined in Eclipse (e.g., ‘M2_REPO’). -
var_value
is the value of this variable (e.g., ‘/home/me/.m2’).
E.g., var([lib1, lib2], 'M2_REPO', '/home/me/.m2/repo')
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/buildr/ide/eclipse.rb', line 358 def var(libs) libs.each do |lib_path, var_name, var_value| lib_artifact = file(lib_path) attribs = { :kind => 'var', :path => lib_path } if lib_artifact.respond_to? :sources_artifact attribs[:sourcepath] = lib_artifact.sources_artifact end if lib_artifact.respond_to? :javadoc_artifact attribs[:javadocpath] = lib_artifact.javadoc_artifact end # make all paths relative attribs.each_key do |k| attribs[k] = attribs[k].to_s.sub(var_value, var_name.to_s) if k.to_s =~ /path/ end @xml.classpathentry attribs end end |