+

+ class Buildr::IntellijIdea::IdeaFile +

+ +
+ +

Abstract base class for IdeaModule and IdeaProject

+ +
+ + + + +
+ + + + + +
+
+

Constants

+
+
+ +
DEFAULT_LOCAL_REPOSITORY_ENV_OVERRIDE + +
+ + +
DEFAULT_PREFIX + +
+ + +
DEFAULT_SUFFIX + +
+ + +
+
+ + + +
+
+

Attributes

+
+ + +
+
+ buildr_project[R] +
+ +
+ + + +
+
+ +
+
+ id[W] +
+ +
+ + + +
+
+ +
+
+ local_repository_env_override[RW] +
+ +
+ + + +
+
+ +
+
+ prefix[W] +
+ +
+ + + +
+
+ +
+
+ suffix[W] +
+ +
+ + + +
+
+ +
+
+ template[RW] +
+ +
+ + + +
+
+ +
+ + + +
+
+

Public Class Methods

+
+ + +
+ +
+ new() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 35
+def initialize
+  @local_repository_env_override = DEFAULT_LOCAL_REPOSITORY_ENV_OVERRIDE
+end
+
+ +
+ + + + +
+ + +
+ +
+
+

Public Instance Methods

+
+ + +
+ +
+ add_component(name, attrs = {}, &xml) + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 55
+def add_component(name, attrs = {}, &xml)
+  self.components << create_component(name, attrs, &xml)
+end
+
+ +
+ + + + +
+ + +
+ +
+ add_component_from_artifact(artifact) + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 66
+def add_component_from_artifact(artifact)
+  self.components << lambda do
+    a = Buildr.artifact(artifact)
+    a.invoke
+    Buildr::IntellijIdea.new_document(IO.read(a.to_s)).root
+  end
+end
+
+ +
+ + + + +
+ + +
+ +
+ add_component_from_file(filename) + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 59
+def add_component_from_file(filename)
+  self.components << lambda do
+    raise "Unable to locate file #{filename} adding component to idea file" unless File.exist?(filename)
+    Buildr::IntellijIdea.new_document(IO.read(filename)).root
+  end
+end
+
+ +
+ + + + +
+ + +
+ +
+ filename() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 47
+def filename
+  buildr_project.path_to("#{name}.#{extension}")
+end
+
+ +
+ + + + +
+ + +
+ +
+ id() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 51
+def id
+  @id ||= buildr_project.name.split(':').last
+end
+
+ +
+ + + + +
+ + +
+ +
+ name() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 80
+def name
+  "#{prefix}#{self.id}#{suffix}"
+end
+
+ +
+ + + + +
+ + +
+ +
+ prefix() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 39
+def prefix
+  @prefix ||= DEFAULT_PREFIX
+end
+
+ +
+ + + + +
+ + +
+ +
+ suffix() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 43
+def suffix
+  @suffix ||= DEFAULT_SUFFIX
+end
+
+ +
+ + + + +
+ + +
+ +
+ write(f) + + click to toggle source + +
+ + +
+ +

IDEA can not handle text content with indents so need to removing indenting +Can not pass true as third argument as the ruby library seems broken

+ + + + +
+
# File lib/buildr/ide/idea.rb, line 76
+def write(f)
+  document.write(f, -1, false, true)
+end
+
+ +
+ + + + +
+ + +
+ +
+
+

Protected Instance Methods

+
+ + +
+ +
+ add_to_composite_component(components) { |xml_markup(:target => target, :indent => 2)| ... } + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 134
+def add_to_composite_component(components)
+  components << lambda do
+    target = StringIO.new
+    yield Builder::XmlMarkup.new(:target => target, :indent => 2)
+    Buildr::IntellijIdea.new_document(target.string).root
+  end
+end
+
+ +
+ + + + +
+ + +
+ +
+ base_directory() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 90
+def base_directory
+  buildr_project.path_to
+end
+
+ +
+ + + + +
+ + +
+ +
+ components() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 120
+def components
+  @components ||= []
+end
+
+ +
+ + + + +
+ + +
+ +
+ create_component(name, attrs = {}) { |xml| ... } + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 112
+def create_component(name, attrs = {})
+  target = StringIO.new
+  Builder::XmlMarkup.new(:target => target, :indent => 2).component({:name => name}.merge(attrs)) do |xml|
+    yield xml if block_given?
+  end
+  Buildr::IntellijIdea.new_document(target.string).root
+end
+
+ +
+ + + + +
+ + +
+ +
+ create_composite_component(name, attrs, components) + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 124
+def create_composite_component(name, attrs, components)
+  return nil if components.empty?
+  component = self.create_component(name, attrs)
+  components.each do |element|
+    element = element.call if element.is_a?(Proc)
+    component.add_element element
+  end
+  component
+end
+
+ +
+ + + + +
+ + +
+ +
+ document() + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 146
+def document
+  if File.exist?(self.filename)
+    doc = load_document(self.filename)
+  else
+    doc = base_document
+    inject_components(doc, self.initial_components)
+  end
+  if self.template
+    template_doc = load_document(self.template)
+    REXML::XPath.each(template_doc, '//component') do |element|
+      inject_component(doc, element)
+    end
+  end
+  inject_components(doc, self.default_components.compact + self.components)
+
+  # Sort the components in the same order the idea sorts them
+  sorted = doc.root.get_elements('//component').sort { |s1, s2| s1.attribute('name').value <=> s2.attribute('name').value }
+  doc = base_document
+  sorted.each do |element|
+    doc.root.add_element element
+  end
+
+  doc
+end
+
+ +
+ + + + +
+ + +
+ +
+ file_path(path) + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 108
+def file_path(path)
+  "file://#{resolve_path(path)}"
+end
+
+ +
+ + + + +
+ + +
+ +
+ inject_component(doc, component) + + click to toggle source + +
+ + +
+ +

replace overridden component (if any) with specified component

+ + + + +
+
# File lib/buildr/ide/idea.rb, line 180
+def inject_component(doc, component)
+  doc.root.delete_element("//component[@name='#{component.attributes['name']}']")
+  doc.root.add_element component
+end
+
+ +
+ + + + +
+ + +
+ +
+ inject_components(doc, components) + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 171
+def inject_components(doc, components)
+  components.each do |component|
+    # execute deferred components
+    component = component.call if Proc === component
+    inject_component(doc, component) if component
+  end
+end
+
+ +
+ + + + +
+ + +
+ +
+ load_document(filename) + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 142
+def load_document(filename)
+  Buildr::IntellijIdea.new_document(File.read(filename))
+end
+
+ +
+ + + + +
+ + +
+ +
+ relative(path) + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 86
+def relative(path)
+  ::Buildr::Util.relative_path(File.expand_path(path.to_s), self.base_directory)
+end
+
+ +
+ + + + +
+ + +
+ +
+ resolve_path_from_base(path, base_variable) + + click to toggle source + +
+ + +
+ + + + + + +
+
# File lib/buildr/ide/idea.rb, line 94
+def resolve_path_from_base(path, base_variable)
+  m2repo = Buildr::Repositories.instance.local
+  if path.to_s.index(m2repo) == 0 && !self.local_repository_env_override.nil?
+    return path.sub(m2repo, "$#{self.local_repository_env_override}$")
+  else
+    begin
+      return "#{base_variable}/#{relative(path)}"
+    rescue ArgumentError
+      # ArgumentError happens on windows when self.base_directory and path are on different drives
+      return path
+    end
+  end
+end
+
+ +
+ + + + +
+ + +
+ +
+