class Buildr::IntellijIdea::IdeaModule

IdeaModule represents an .iml file

Constants

DEFAULT_TYPE

Attributes

facets[R]
group[RW]
jdk_version[W]
main_output_dir[W]
test_output_dir[W]
type[RW]

Public Class Methods

new() click to toggle source
Calls superclass method Buildr::IntellijIdea::IdeaFile.new
# File lib/buildr/ide/idea.rb, line 195
def initialize
 super()
 @type = DEFAULT_TYPE
end

Public Instance Methods

add_ejb_facet(options = {}) click to toggle source
# File lib/buildr/ide/idea.rb, line 442
def add_ejb_facet(options = {})
 name = options[:name] || 'EJB'
 default_ejb_roots = [buildr_project.iml.main_source_directories, buildr_project.compile.sources, buildr_project.resources.sources].flatten.compact
 ejb_roots = options[:ejb_roots] || default_ejb_roots
 default_deployment_descriptors = []
 ['ejb-jar.xml', 'glassfish-ejb-jar.xml', 'ibm-ejb-jar-bnd.xml', 'ibm-ejb-jar-ext-pme.xml', 'ibm-ejb-jar-ext.xml',
 'jboss.xml', 'jbosscmp-jdbc.xml', 'openejb-jar.xml', 'sun-cmp-mapping.xml', 'sun-ejb-jar.xml',
 'weblogic-cmp-rdbms-jar.xml', 'weblogic-ejb-jar.xml'].
 each do |descriptor|
 ejb_roots.each do |path|
 d = "#{path}/WEB-INF/#{descriptor}"
 default_deployment_descriptors << d if File.exist?(d)
 d = "#{path}/META-INF/#{descriptor}"
 default_deployment_descriptors << d if File.exist?(d)
 end
 end
 deployment_descriptors = options[:deployment_descriptors] || default_deployment_descriptors
 add_facet(name, 'ejb') do |facet|
 facet.configuration do |c|
 c.descriptors do |d|
 deployment_descriptors.each do |deployment_descriptor|
 d.deploymentDescriptor :name => File.basename(deployment_descriptor), :url => file_path(deployment_descriptor)
 end
 end
 c.ejbRoots do |e|
 ejb_roots.each do |ejb_root|
 e.root :url => file_path(ejb_root)
 end
 end
 end
 end
end
add_facet(name, type) { |xml| ... } click to toggle source
# File lib/buildr/ide/idea.rb, line 277
def add_facet(name, type)
 add_to_composite_component(self.facets) do |xml|
 xml.facet(:name => name, :type => type) do |xml|
 yield xml if block_given?
 end
 end
end
add_gwt_facet(modules = {}, options = {}) click to toggle source
# File lib/buildr/ide/idea.rb, line 293
def add_gwt_facet(modules = {}, options = {})
 name = options[:name] || 'GWT'
 detected_gwt_version = nil
 if options[:gwt_dev_artifact]
 a = Buildr.artifact(options[:gwt_dev_artifact])
 a.invoke
 detected_gwt_version = a.to_s
 end
 settings =
 {
 :webFacet => 'Web',
 :compilerMaxHeapSize => '512',
 :compilerParameters => '-draftCompile -localWorkers 2 -strict',
 :gwtScriptOutputStyle => 'PRETTY'
 }.merge(options[:settings] || {})
 buildr_project.compile.dependencies.each do |d|
 if d.to_s =~ /\/com\/google\/gwt\/gwt-dev\/(.*)\//
 detected_gwt_version = d.to_s
 break
 end
 end unless detected_gwt_version
 if detected_gwt_version
 settings[:gwtSdkUrl] = resolve_path(File.dirname(detected_gwt_version))
 settings[:gwtSdkType] = 'maven'
 else
 settings[:gwtSdkUrl] = 'file://$GWT_TOOLS$'
 end
 add_facet(name, 'gwt') do |f|
 f.configuration do |c|
 settings.each_pair do |k, v|
 c.setting :name => k.to_s, :value => v.to_s
 end
 c.packaging do |d|
 modules.each_pair do |k, v|
 d.module :name => k, :enabled => v
 end
 end
 end
 end
end
add_jpa_facet(options = {}) click to toggle source
# File lib/buildr/ide/idea.rb, line 395
def add_jpa_facet(options = {})
 name = options[:name] || 'JPA'
 source_roots = [buildr_project.iml.main_source_directories, buildr_project.compile.sources, buildr_project.resources.sources].flatten.compact
 default_deployment_descriptors = []
 ['orm.xml', 'persistence.xml'].
 each do |descriptor|
 source_roots.each do |path|
 d = "#{path}/META-INF/#{descriptor}"
 default_deployment_descriptors << d if File.exist?(d)
 end
 end
 deployment_descriptors = options[:deployment_descriptors] || default_deployment_descriptors
 factory_entry = options[:factory_entry] || buildr_project.name.to_s
 validation_enabled = options[:validation_enabled].nil? ? true : options[:validation_enabled]
 if options[:provider_enabled]
 provider = options[:provider_enabled]
 else
 provider = nil
 {'org.hibernate.ejb.HibernatePersistence' => 'Hibernate',
 'org.eclipse.persistence.jpa.PersistenceProvider' => 'EclipseLink'}.
 each_pair do |match, candidate_provider|
 deployment_descriptors.each do |descriptor|
 if File.exist?(descriptor) && /#{Regexp.escape(match)}/ =~ IO.read(descriptor)
 provider = candidate_provider
 end
 end
 end
 end
 add_facet(name, 'jpa') do |f|
 f.configuration do |c|
 if provider
 c.setting :name => 'validation-enabled', :value => validation_enabled
 c.setting :name => 'provider-name', :value => provider
 end
 c.tag!('datasource-mapping') do |ds|
 ds.tag!('factory-entry', :name => factory_entry)
 end
 deployment_descriptors.each do |descriptor|
 c.deploymentDescriptor :name => File.basename(descriptor), :url => file_path(descriptor)
 end
 end
 end
end
add_jruby_facet(options = {}) click to toggle source
# File lib/buildr/ide/idea.rb, line 380
def add_jruby_facet(options = {})
 name = options[:name] || 'JRuby'
 ruby_version_file = buildr_project._('.ruby-version')
 default_jruby_version = File.exist?(ruby_version_file) ? "rbenv: #{IO.read(ruby_version_file).strip}" : 'jruby-1.6.7.2'
 jruby_version = options[:jruby_version] || default_jruby_version
 add_facet(name, 'JRUBY') do |f|
 f.configuration do |c|
 c.JRUBY_FACET_CONFIG_ID :NAME => 'JRUBY_SDK_NAME', :VALUE => jruby_version
 c.LOAD_PATH :number => '0'
 c.I18N_FOLDERS :number => '0'
 end
 end
end
add_web_facet(options = {}) click to toggle source
# File lib/buildr/ide/idea.rb, line 338
def add_web_facet(options = {})
 name = options[:name] || 'Web'
 default_webroots = {}
 default_webroots[buildr_project._(:source, :main, :webapp)] = '/' if File.exist?(buildr_project._(:source, :main, :webapp))
 buildr_project.assets.paths.each {|p| default_webroots[p] = '/' }
 webroots = options[:webroots] || default_webroots
 default_deployment_descriptors = []
 ['web.xml', 'sun-web.xml', 'glassfish-web.xml', 'jetty-web.xml', 'geronimo-web.xml',
 'context.xml', 'weblogic.xml',
 'jboss-deployment-structure.xml', 'jboss-web.xml',
 'ibm-web-bnd.xml', 'ibm-web-ext.xml', 'ibm-web-ext-pme.xml'].
 each do |descriptor|
 webroots.each_pair do |path, relative_url|
 next unless relative_url == '/'
 d = "#{path}/WEB-INF/#{descriptor}"
 default_deployment_descriptors << d if File.exist?(d)
 end
 end
 deployment_descriptors = options[:deployment_descriptors] || default_deployment_descriptors
 add_facet(name, 'web') do |f|
 f.configuration do |c|
 c.descriptors do |d|
 deployment_descriptors.each do |deployment_descriptor|
 d.deploymentDescriptor :name => File.basename(deployment_descriptor), :url => file_path(deployment_descriptor)
 end
 end
 c.webroots do |w|
 webroots.each_pair do |webroot, relative_url|
 w.root :url => file_path(webroot), :relative => relative_url
 end
 end
 end
 default_enable_jsf = webroots.keys.any?{|webroot| File.exist?("#{webroot}/WEB-INF/faces-config.xml")}
 enable_jsf = options[:enable_jsf].nil? ? default_enable_jsf : options[:enable_jsf]
 enable_jsf = false if buildr_project.root_project.ipr? && buildr_project.root_project.ipr.version >= '13'
 f.facet(:type => 'jsf', :name => 'JSF') do |jsf|
 jsf.configuration
 end if enable_jsf
 end
end
buildr_project=(buildr_project) click to toggle source
# File lib/buildr/ide/idea.rb, line 200
def buildr_project=(buildr_project)
 @id = nil
 @facets = []
 @skip_content = false
 @buildr_project = buildr_project
end
excluded_directories() click to toggle source
# File lib/buildr/ide/idea.rb, line 247
def excluded_directories
 @excluded_directories ||= [
 buildr_project.resources.target,
 buildr_project.test.resources.target,
 buildr_project.path_to(:target, :main),
 buildr_project.path_to(:target, :test),
 buildr_project.path_to(:reports)
 ].flatten.compact
end
extension() click to toggle source
# File lib/buildr/ide/idea.rb, line 211
def extension
 'iml'
end
jdk_version() click to toggle source
# File lib/buildr/ide/idea.rb, line 207
def jdk_version
 @jdk_version || buildr_project.compile.options.source || '1.7'
end
main_dependencies() click to toggle source
# File lib/buildr/ide/idea.rb, line 269
def main_dependencies
 @main_dependencies ||= buildr_project.compile.dependencies.dup
end
main_generated_resource_directories() click to toggle source
# File lib/buildr/ide/idea.rb, line 227
def main_generated_resource_directories
 @main_generated_resource_directories ||= []
end
main_generated_source_directories() click to toggle source
# File lib/buildr/ide/idea.rb, line 223
def main_generated_source_directories
 @main_generated_source_directories ||= []
end
main_output_dir() click to toggle source
# File lib/buildr/ide/idea.rb, line 259
def main_output_dir
 @main_output_dir ||= buildr_project._(:target, :main, :idea, :classes)
end
main_resource_directories() click to toggle source
# File lib/buildr/ide/idea.rb, line 219
def main_resource_directories
 @main_resource_directories ||= [buildr_project.resources.sources].flatten.compact
end
main_source_directories() click to toggle source
# File lib/buildr/ide/idea.rb, line 215
def main_source_directories
 @main_source_directories ||= [buildr_project.compile.sources].flatten.compact
end
skip_content!() click to toggle source
# File lib/buildr/ide/idea.rb, line 289
def skip_content!
 @skip_content = true
end
skip_content?() click to toggle source
# File lib/buildr/ide/idea.rb, line 285
def skip_content?
 !!@skip_content
end
test_dependencies() click to toggle source
# File lib/buildr/ide/idea.rb, line 273
def test_dependencies
 @test_dependencies ||= buildr_project.test.compile.dependencies.dup
end
test_generated_resource_directories() click to toggle source
# File lib/buildr/ide/idea.rb, line 243
def test_generated_resource_directories
 @test_generated_resource_directories ||= []
end
test_generated_source_directories() click to toggle source
# File lib/buildr/ide/idea.rb, line 239
def test_generated_source_directories
 @test_generated_source_directories ||= []
end
test_output_dir() click to toggle source
# File lib/buildr/ide/idea.rb, line 265
def test_output_dir
 @test_output_dir ||= buildr_project._(:target, :test, :idea, :classes)
end
test_resource_directories() click to toggle source
# File lib/buildr/ide/idea.rb, line 235
def test_resource_directories
 @test_resource_directories ||= [buildr_project.test.resources.sources].flatten.compact
end
test_source_directories() click to toggle source
# File lib/buildr/ide/idea.rb, line 231
def test_source_directories
 @test_source_directories ||= [buildr_project.test.compile.sources].flatten.compact
end

Protected Instance Methods

base_document() click to toggle source
# File lib/buildr/ide/idea.rb, line 511
def base_document
 target = StringIO.new
 Builder::XmlMarkup.new(:target => target).module(:version => '4', :relativePaths => 'true', :type => self.type)
 Buildr::IntellijIdea.new_document(target.string)
end
default_components() click to toggle source
# File lib/buildr/ide/idea.rb, line 521
def default_components
 [
 lambda { module_root_component },
 lambda { facet_component }
 ]
end
facet_component() click to toggle source
# File lib/buildr/ide/idea.rb, line 528
def facet_component
 create_composite_component('FacetManager', {}, self.facets)
end
generate_compile_output(xml) click to toggle source
# File lib/buildr/ide/idea.rb, line 601
def generate_compile_output(xml)
 xml.output(:url => file_path(self.main_output_dir.to_s))
 xml.tag!('output-test', :url => file_path(self.test_output_dir.to_s))
 xml.tag!('exclude-output')
end
generate_content(xml) click to toggle source
# File lib/buildr/ide/idea.rb, line 607
def generate_content(xml)
 xml.content(:url => 'file://$MODULE_DIR$') do
 # Source folders
 [
 {:dirs => (self.main_source_directories.dup - self.main_generated_source_directories)},
 {:dirs => self.main_generated_source_directories, :generated => true},
 {:type => 'resource', :dirs => (self.main_resource_directories.dup - self.main_generated_resource_directories)},
 {:type => 'resource', :dirs => self.main_generated_resource_directories, :generated => true},
 {:test => true, :dirs => (self.test_source_directories - self.test_generated_source_directories)},
 {:test => true, :dirs => self.test_generated_source_directories, :generated => true},
 {:test => true, :type => 'resource', :dirs => (self.test_resource_directories - self.test_generated_resource_directories)},
 {:test => true, :type => 'resource', :dirs => self.test_generated_resource_directories, :generated => true},
 ].each do |content|
 content[:dirs].map { |dir| dir.to_s }.compact.sort.uniq.each do |dir|
 options = {}
 options[:url] = file_path(dir)
 options[:isTestSource] = (content[:test] ? 'true' : 'false') if content[:type] != 'resource'
 options[:type] = 'java-resource' if content[:type] == 'resource' && !content[:test]
 options[:type] = 'java-test-resource' if content[:type] == 'resource' && content[:test]
 options[:generated] = 'true' if content[:generated]
 xml.sourceFolder options
 end
 end
 # Exclude target directories
 self.net_excluded_directories.
 collect { |dir| file_path(dir) }.
 select { |dir| relative_dir_inside_dir?(dir) }.
 sort.each do |dir|
 xml.excludeFolder :url => dir
 end
 end
end
generate_initial_order_entries(xml) click to toggle source
# File lib/buildr/ide/idea.rb, line 645
def generate_initial_order_entries(xml)
 xml.orderEntry :type => 'sourceFolder', :forTests => 'false'
 xml.orderEntry :type => 'jdk', :jdkName => jdk_version, :jdkType => 'JavaSDK'
end
generate_lib(xml, dependency_path, export, source_path, project_dependencies) click to toggle source
# File lib/buildr/ide/idea.rb, line 568
def generate_lib(xml, dependency_path, export, source_path, project_dependencies)
 project_for_dependency = Buildr.projects.detect do |project|
 [project.packages, project.compile.target, project.resources.target, project.test.compile.target, project.test.resources.target].flatten.
 detect { |artifact| artifact.to_s == dependency_path }
 end
 if project_for_dependency
 if project_for_dependency.iml? &&
 !project_dependencies.include?(project_for_dependency) &&
 project_for_dependency != self.buildr_project
 generate_project_dependency(xml, project_for_dependency.iml.name, export, !export)
 end
 project_dependencies << project_for_dependency
 else
 generate_module_lib(xml, url_for_path(dependency_path), export, (source_path ? url_for_path(source_path) : nil), !export)
 end
end
generate_module_lib(xml, path, export, source_path, test = false) click to toggle source
# File lib/buildr/ide/idea.rb, line 657
def generate_module_lib(xml, path, export, source_path, test = false)
 attribs = {:type => 'module-library'}
 attribs[:exported] = '' if export
 attribs[:scope] = 'TEST' if test
 xml.orderEntry attribs do
 xml.library do
 xml.CLASSES do
 xml.root :url => path
 end
 xml.JAVADOC
 xml.SOURCES do
 if source_path
 xml.root :url => source_path
 end
 end
 end
 end
end
generate_project_dependency(xml, other_project, export, test = false) click to toggle source
# File lib/buildr/ide/idea.rb, line 650
def generate_project_dependency(xml, other_project, export, test = false)
 attribs = {:type => 'module', 'module-name' => other_project}
 attribs[:exported] = '' if export
 attribs[:scope] = 'TEST' if test
 xml.orderEntry attribs
end
initial_components() click to toggle source
# File lib/buildr/ide/idea.rb, line 517
def initial_components
 []
end
jar_path(path) click to toggle source
# File lib/buildr/ide/idea.rb, line 585
def jar_path(path)
 "jar://#{resolve_path(path)}!/"
end
main_dependency_details() click to toggle source
# File lib/buildr/ide/idea.rb, line 480
def main_dependency_details
 target_dir = buildr_project.compile.target.to_s
 main_dependencies.select { |d| d.to_s != target_dir }.collect do |d|
 dependency_path = d.to_s
 export = true
 source_path = nil
 if d.respond_to?(:to_spec_hash)
 source_spec = d.to_spec_hash.merge(:classifier => 'sources')
 source_path = Buildr.artifact(source_spec).to_s
 source_path = nil unless File.exist?(source_path)
 end
 [dependency_path, export, source_path]
 end
end
module_root_component() click to toggle source
# File lib/buildr/ide/idea.rb, line 532
def module_root_component
 options = { 'inherit-compiler-output' => 'false' }
 options['LANGUAGE_LEVEL'] = "JDK_#{jdk_version.gsub(/\./, '_')}" unless jdk_version == buildr_project.root_project.compile.options.source
 create_component('NewModuleRootManager', options) do |xml|
 generate_compile_output(xml)
 generate_content(xml) unless skip_content?
 generate_initial_order_entries(xml)
 project_dependencies = []
 # If a project dependency occurs as a main dependency then add it to the list
 # that are excluded from list of test modules
 self.main_dependency_details.each do |dependency_path, export, source_path|
 next unless export
 project_for_dependency = Buildr.projects.detect do |project|
 [project.packages, project.compile.target, project.resources.target, project.test.compile.target, project.test.resources.target].flatten.
 detect { |artifact| artifact.to_s == dependency_path }
 end
 project_dependencies << project_for_dependency if project_for_dependency
 end
 main_project_dependencies = project_dependencies.dup
 self.test_dependency_details.each do |dependency_path, export, source_path|
 next if export
 generate_lib(xml, dependency_path, export, source_path, project_dependencies)
 end
 test_project_dependencies = project_dependencies - main_project_dependencies
 self.main_dependency_details.each do |dependency_path, export, source_path|
 next unless export
 generate_lib(xml, dependency_path, export, source_path, test_project_dependencies)
 end
 xml.orderEntryProperties
 end
end
net_excluded_directories() click to toggle source

Don't exclude things that are subdirectories of other excluded things

# File lib/buildr/ide/idea.rb, line 677
def net_excluded_directories
 net = []
 all = self.excluded_directories.map { |dir| buildr_project._(dir.to_s) }.sort_by { |d| d.size }
 all.each_with_index do |dir, i|
 unless all[0 ... i].find { |other| dir =~ /^#{other}/ }
 net << dir
 end
 end
 net
end
relative_dir_inside_dir?(dir) click to toggle source
# File lib/buildr/ide/idea.rb, line 641
def relative_dir_inside_dir?(dir)
 !dir.include?('../')
end
resolve_path(path) click to toggle source
# File lib/buildr/ide/idea.rb, line 597
def resolve_path(path)
 resolve_path_from_base(path, '$MODULE_DIR$')
end
test_dependency_details() click to toggle source
# File lib/buildr/ide/idea.rb, line 495
def test_dependency_details
 main_dependencies_paths = main_dependencies.map(&:to_s)
 target_dir = buildr_project.compile.target.to_s
 test_dependencies.select { |d| d.to_s != target_dir }.collect do |d|
 dependency_path = d.to_s
 export = main_dependencies_paths.include?(dependency_path)
 source_path = nil
 if d.respond_to?(:to_spec_hash)
 source_spec = d.to_spec_hash.merge(:classifier => 'sources')
 source_path = Buildr.artifact(source_spec).to_s
 source_path = nil unless File.exist?(source_path)
 end
 [dependency_path, export, source_path]
 end
end
url_for_path(path) click to toggle source
# File lib/buildr/ide/idea.rb, line 589
def url_for_path(path)
 if path =~ /jar$/i
 jar_path(path)
 else
 file_path(path)
 end
end