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

:nodoc:



323
324
325
326
327
328
# File 'lib/buildr/ide/eclipse.rb', line 323

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



334
335
336
# File 'lib/buildr/ide/eclipse.rb', line 334

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

#lib(libs) ⇒ Object



338
339
340
341
342
# File 'lib/buildr/ide/eclipse.rb', line 338

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

#output(target) ⇒ Object



362
363
364
# File 'lib/buildr/ide/eclipse.rb', line 362

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.



346
347
348
349
350
351
352
# File 'lib/buildr/ide/eclipse.rb', line 346

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. Accept an array of projects.



356
357
358
359
360
# File 'lib/buildr/ide/eclipse.rb', line 356

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) ⇒ 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')



371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/buildr/ide/eclipse.rb', line 371

def var(libs)
  libs.each do |lib_path, var_name, var_value|
    lib_artifact = file(lib_path)
    relative_lib_path = lib_path.sub(var_value, var_name.to_s)
    if lib_artifact.respond_to? :sources_artifact
      source_path = lib_artifact.sources_artifact.to_s
      relative_source_path = source_path.sub(var_value, var_name)
      @xml.classpathentry :kind=>'var', :path=>relative_lib_path, :sourcepath=>relative_source_path
    else
      @xml.classpathentry :kind=>'var', :path=>relative_lib_path
    end
  end
end

#write(&block) ⇒ Object



330
331
332
# File 'lib/buildr/ide/eclipse.rb', line 330

def write &block
  @xml.classpath &block
end