class Buildr::IntellijIdea::IdeaProject

IdeaModule represents an .ipr file

Attributes

artifacts[RW]
configurations[RW]
extra_modules[RW]
jdk_version[W]

Public Class Methods

new(buildr_project) click to toggle source
Calls superclass method Buildr::IntellijIdea::IdeaFile.new
# File lib/buildr/ide/idea.rb, line 559
def initialize(buildr_project)
  super()
  @buildr_project = buildr_project
  @extra_modules = []
  @artifacts = []
  @configurations = []
end

Public Instance Methods

add_artifact(name, type, build_on_make = false) { |xml| ... } click to toggle source
# File lib/buildr/ide/idea.rb, line 571
def add_artifact(name, type, build_on_make = false)
  add_to_composite_component(self.artifacts) do |xml|
    xml.artifact(:name => name, :type => type, :"build-on-make" => build_on_make) do |xml|
      yield xml if block_given?
    end
  end
end
add_configuration(name, type, factory_name, default = false) { |xml| ... } click to toggle source
# File lib/buildr/ide/idea.rb, line 579
def add_configuration(name, type, factory_name, default = false)
  add_to_composite_component(self.configurations) do |xml|
    xml.configuration(:name => name, :type => type, :factoryName => factory_name, :default => default) do |xml|
      yield xml if block_given?
    end
  end
end
add_exploded_ear_artifact(project, options ={}) click to toggle source
# File lib/buildr/ide/idea.rb, line 646
def add_exploded_ear_artifact(project, options ={})

  artifact_name = options[:name] || project.iml.id
  build_on_make = options[:build_on_make].nil? ? true : options[:build_on_make]

  add_artifact(artifact_name, "exploded-ear", build_on_make) do |xml|
    dependencies = (options[:dependencies] || ([project] + project.compile.dependencies)).flatten
    libraries, projects = partition_dependencies(dependencies)

    ## The content here can not be indented
    output_dir = options[:output_dir] || project._(:artifacts, artifact_name)
    xml.tag!('output-path', output_dir)

    xml.root :id => "root" do

      xml.element :id => "module-output", :name => project.iml.id

      projects.each do |p|
        xml.element :id => "directory", :name => p.iml.id do
          xml.element :id => "module-output", :name => p.iml.id
        end
      end

      xml.element :id => "directory", :name => "lib" do
        libraries.each(&:invoke).map(&:to_s).each do |dependency_path|
          xml.element :id => "file-copy", :path => resolve_path(dependency_path)
        end
      end

    end
  end
end
add_exploded_ejb_artifact(project, options = {}) click to toggle source
# File lib/buildr/ide/idea.rb, line 679
def add_exploded_ejb_artifact(project, options = {})

  artifact_name = options[:name] || project.iml.id
  build_on_make = options[:build_on_make].nil? ? true : options[:build_on_make]

  add_artifact(artifact_name, "exploded-ejb", build_on_make) do |xml|
    dependencies = (options[:dependencies] || ([project] + project.compile.dependencies)).flatten
    libraries, projects = partition_dependencies(dependencies)

    ## The content here can not be indented
    output_dir = options[:output_dir] || project._(:artifacts, artifact_name)
    xml.tag!('output-path', output_dir)

    xml.root :id => "root" do

      xml.element :id => "module-output", :name => project.iml.id

      if options[:enable_jpa]
        module_names = options[:jpa_module_names] || [project.iml.id]
        module_names.each do |module_name|
          facet_name = options[:jpa_facet_name] || "JPA"
          xml.element :id => "jpa-descriptors", :facet => "#{module_name}/jpa/#{facet_name}"
        end
      end

      if options[:enable_ejb].nil? || options[:enable_ejb]
        module_names = options[:ejb_module_names] || [project.iml.id]
        module_names.each do |module_name|
          facet_name = options[:ejb_facet_name] || "EJB"
          xml.element :id => "javaee-facet-resources", :facet => "#{module_name}/ejb/#{facet_name}"
        end
      end

    end
  end
end
add_exploded_war_artifact(project, options = {}) click to toggle source
# File lib/buildr/ide/idea.rb, line 587
def add_exploded_war_artifact(project, options = {})
  artifact_name = options[:name] || project.iml.id
  build_on_make = options[:build_on_make].nil? ? false : options[:build_on_make]

  add_artifact(artifact_name, "exploded-war", build_on_make) do |xml|
    dependencies = (options[:dependencies] || ([project] + project.compile.dependencies)).flatten
    libraries, projects = partition_dependencies(dependencies)

    ## The content here can not be indented
    output_dir = options[:output_dir] || project._(:artifacts, artifact_name)
    xml.tag!('output-path', output_dir)

    xml.root :id => "root" do
      xml.element :id => "directory", :name => "WEB-INF" do
        xml.element :id => "directory", :name => "classes" do
          projects.each do |p|
            xml.element :id => "module-output", :name => p.iml.id
          end
          if options[:enable_jpa]
            module_names = options[:jpa_module_names] || [project.iml.id]
            module_names.each do |module_name|
              facet_name = options[:jpa_facet_name] || "JPA"
              xml.element :id => "jpa-descriptors", :facet => "#{module_name}/jpa/#{facet_name}"
            end
          end
          if options[:enable_ejb]
            module_names = options[:ejb_module_names] || [project.iml.id]
            module_names.each do |module_name|
              facet_name = options[:ejb_facet_name] || "EJB"
              xml.element :id => "javaee-facet-resources", :facet => "#{module_name}/ejb/#{facet_name}"
            end
          end
        end
        xml.element :id => "directory", :name => "lib" do
          libraries.each(&:invoke).map(&:to_s).each do |dependency_path|
            xml.element :id => "file-copy", :path => resolve_path(dependency_path)
          end
        end
      end

      if options[:enable_war].nil? || options[:enable_war]
        module_names = options[:war_module_names] || [project.iml.id]
        module_names.each do |module_name|
          facet_name = options[:war_facet_name] || "Web"
          xml.element :id => "javaee-facet-resources", :facet => "#{module_name}/web/#{facet_name}"
        end
      end

      if options[:enable_gwt]
        module_names = options[:gwt_module_names] || [project.iml.id]
        module_names.each do |module_name|
          facet_name = options[:gwt_facet_name] || "GWT"
          xml.element :id => "gwt-compiler-output", :facet => "#{module_name}/gwt/#{facet_name}"
        end
      end
    end
  end
end
add_gwt_configuration(launch_page, project, options = {}) click to toggle source
# File lib/buildr/ide/idea.rb, line 717
def add_gwt_configuration(launch_page, project, options = {})
  name = options[:name] || "Run #{launch_page}"
  shell_parameters = options[:shell_parameters] || ""
  vm_parameters = options[:vm_parameters] || "-Xmx512m"

  add_configuration(name, "GWT.ConfigurationType", "GWT Configuration") do |xml|
    xml.module(:name => project.iml.id)
    xml.option(:name => "RUN_PAGE", :value => launch_page)
    xml.option(:name => "SHELL_PARAMETERS", :value => shell_parameters)
    xml.option(:name => "VM_PARAMETERS", :value => vm_parameters)

    xml.RunnerSettings(:RunnerId => "Run")
    xml.ConfigurationWrapper(:RunnerId => "Run")
    xml.method()
  end
end
jdk_version() click to toggle source
# File lib/buildr/ide/idea.rb, line 567
def jdk_version
  @jdk_version ||= buildr_project.compile.options.source || "1.6"
end

Protected Instance Methods

artifacts_component() click to toggle source
# File lib/buildr/ide/idea.rb, line 843
def artifacts_component
  create_composite_component("ArtifactManager", self.artifacts)
end
base_document() click to toggle source
# File lib/buildr/ide/idea.rb, line 740
def base_document
  target = StringIO.new
  Builder::XmlMarkup.new(:target => target).project(:version => "4")
  Buildr::IntellijIdea.new_document(target.string)
end
configurations_component() click to toggle source
# File lib/buildr/ide/idea.rb, line 847
def configurations_component
  create_composite_component("ProjectRunConfigurationManager", self.configurations)
end
default_components() click to toggle source
# File lib/buildr/ide/idea.rb, line 746
def default_components
  [
    lambda { modules_component },
    vcs_component,
    artifacts_component,
    configurations_component,
    lambda { framework_detection_exclusion_component }
  ]
end
extension() click to toggle source
# File lib/buildr/ide/idea.rb, line 736
def extension
  "ipr"
end
framework_detection_exclusion_component() click to toggle source
# File lib/buildr/ide/idea.rb, line 756
def framework_detection_exclusion_component
  create_component('FrameworkDetectionExcludesConfiguration') do |xml|
    xml.file :url => file_path(buildr_project._(:artifacts))
  end
end
initial_components() click to toggle source
# File lib/buildr/ide/idea.rb, line 762
def initial_components
  [
    lambda { project_root_manager_component },
    lambda { project_details_component }
  ]
end
modules_component() click to toggle source
# File lib/buildr/ide/idea.rb, line 788
def modules_component
  create_component("ProjectModuleManager") do |xml|
    xml.modules do
      buildr_project.projects.select { |subp| subp.iml? }.each do |subproject|
        module_path = subproject.base_dir.gsub(/^#{buildr_project.base_dir}\//, '')
        path = "#{module_path}/#{subproject.iml.name}.iml"
        attribs = {:fileurl => "file://$PROJECT_DIR$/#{path}", :filepath => "$PROJECT_DIR$/#{path}"}
        if subproject.iml.group == true
          attribs[:group] = subproject.parent.name.gsub(':', '/')
        elsif !subproject.iml.group.nil?
          attribs[:group] = subproject.iml.group.to_s
        end
        xml.module attribs
      end
      self.extra_modules.each do |iml_file|
        xml.module :fileurl => "file://$PROJECT_DIR$/#{iml_file}",
                   :filepath => "$PROJECT_DIR$/#{iml_file}"
      end
      if buildr_project.iml?
        xml.module :fileurl => "file://$PROJECT_DIR$/#{buildr_project.iml.name}.iml",
                   :filepath => "$PROJECT_DIR$/#{buildr_project.iml.name}.iml"
      end
    end
  end
end
project_details_component() click to toggle source
# File lib/buildr/ide/idea.rb, line 782
def project_details_component
  create_component("ProjectDetails") do |xml|
    xml.option("name" => "projectName", "value" => self.name)
  end
end
project_root_manager_component() click to toggle source
# File lib/buildr/ide/idea.rb, line 769
def project_root_manager_component
  attribs = {}
  attribs["version"] = "2"
  attribs["languageLevel"] = "JDK_#{self.jdk_version.gsub('.', '_')}"
  attribs["assert-keyword"] = "true"
  attribs["jdk-15"] = "true"
  attribs["project-jdk-name"] = self.jdk_version
  attribs["project-jdk-type"] = "JavaSDK"
  create_component("ProjectRootManager", attribs) do |xml|
    xml.output("url" => "file://$PROJECT_DIR$/out")
  end
end
resolve_path(path) click to toggle source
# File lib/buildr/ide/idea.rb, line 851
def resolve_path(path)
  resolve_path_from_base(path, "$PROJECT_DIR$")
end
vcs_component() click to toggle source
# File lib/buildr/ide/idea.rb, line 814
def vcs_component
  project_directories = buildr_project.projects.select { |p| p.iml? }.collect { |p| p.base_dir }
  project_directories << buildr_project.base_dir
  # Guess the iml file is in the same dir as base dir
  project_directories += self.extra_modules.collect { |p| File.dirname(p) }

  project_directories = project_directories.sort.uniq

  mappings = {}

  project_directories.each do |dir|
    if File.directory?("#{dir}/.git")
      mappings[dir] = "Git"
    elsif File.directory?("#{dir}/.svn")
      mappings[dir] = "svn"
    end
  end

  if mappings.size > 1
    create_component("VcsDirectoryMappings") do |xml|
      mappings.each_pair do |dir, vcs_type|
        resolved_dir = resolve_path(dir)
        mapped_dir = resolved_dir == '$PROJECT_DIR$/.' ? buildr_project.base_dir : resolved_dir
        xml.mapping :directory => mapped_dir, :vcs => vcs_type
      end
    end
  end
end