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.



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

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



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

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

#lib(libs) ⇒ Object



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

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

#output(target) ⇒ Object



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

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.



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

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.



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

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

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



179
180
181
182
183
184
185
186
187
# File 'lib/buildr/ide/eclipse.rb', line 179

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

#write(&block) ⇒ Object



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

def write &block
  @xml.classpath &block
end