# File lib/buildr/ide/idea.rb, line 230 def main_dependencies @main_dependencies ||= buildr_project.compile.dependencies end
IdeaModule represents an .iml file
# File lib/buildr/ide/idea.rb, line 174 def initialize super() @type = DEFAULT_TYPE end
# File lib/buildr/ide/idea.rb, line 360 def add_ejb_facet(options = {}) name = options[:name] || "EJB" default_ejb_xml = buildr_project._(:source, :main, :resources, "WEB-INF/ejb-jar.xml") ejb_xml = options[:ejb_xml] || default_ejb_xml ejb_roots = options[:ejb_roots] || [buildr_project.compile.sources, buildr_project.resources.sources].flatten add_facet(name, "ejb") do |facet| facet.configuration do |c| c.descriptors do |d| if File.exist?(ejb_xml) || default_ejb_xml != ejb_xml d.deploymentDescriptor :name => 'ejb-jar.xml', :url => file_path(ejb_xml) end end c.ejbRoots do |e| ejb_roots.each do |ejb_root| e.root :url => file_path(ejb_root) end end end end end
# File lib/buildr/ide/idea.rb, line 238 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
# File lib/buildr/ide/idea.rb, line 254 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
# File lib/buildr/ide/idea.rb, line 334 def add_jpa_facet(options = {}) name = options[:name] || "JPA" factory_entry = options[:factory_entry] || buildr_project.name.to_s validation_enabled = options[:validation_enabled].nil? ? true : options[:validation_enabled] provider_enabled = options[:provider_enabled] || 'Hibernate' default_persistence_xml = buildr_project._(:source, :main, :resources, "META-INF/persistence.xml") persistence_xml = options[:persistence_xml] || default_persistence_xml default_orm_xml = buildr_project._(:source, :main, :resources, "META-INF/orm.xml") orm_xml = options[:orm_xml] || default_orm_xml add_facet(name, "jpa") do |f| f.configuration do |c| c.setting :name => "validation-enabled", :value => validation_enabled c.setting :name => "provider-name", :value => provider_enabled c.tag!('datasource-mapping') do |ds| ds.tag!('factory-entry', :name => factory_entry) end if File.exist?(persistence_xml) || default_persistence_xml != persistence_xml c.deploymentDescriptor :name => 'persistence.xml', :url => file_path(persistence_xml) end if File.exist?(orm_xml) || default_orm_xml != orm_xml c.deploymentDescriptor :name => 'orm.xml', :url => file_path(orm_xml) end end end end
# File lib/buildr/ide/idea.rb, line 324 def add_jruby_facet(options = {}) name = options[:name] || "JRuby" jruby_version = options[:jruby_version] || "jruby-1.5.2-p249" add_facet(name, "JRUBY") do |f| f.configuration(:number => 0) do |c| c.JRUBY_FACET_CONFIG_ID :NAME => "JRUBY_SDK_NAME", :VALUE => jruby_version end end end
# File lib/buildr/ide/idea.rb, line 299 def add_web_facet(options = {}) name = options[:name] || "Web" url_base = options[:url_base] || "/" default_webroots = [buildr_project._(:source, :main, :webapp)] webroots = options[:webroots] || default_webroots default_web_xml = "#{buildr_project._(:source, :main, :webapp)}/WEB-INF/web.xml" web_xml = options[:web_xml] || default_web_xml version = options[:version] || "3.0" add_facet(name, "web") do |f| f.configuration do |c| c.descriptors do |d| if File.exist?(web_xml) || default_web_xml != web_xml d.deploymentDescriptor :name => 'web.xml', :url => file_path(web_xml), :optional => "true", :version => version end end c.webroots do |w| webroots.each do |webroot| w.root :url => file_path(webroot), :relative => url_base end end end end end
# File lib/buildr/ide/idea.rb, line 179 def buildr_project=(buildr_project) @id = nil @facets = [] @skip_content = false @buildr_project = buildr_project end
# File lib/buildr/ide/idea.rb, line 208 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
# File lib/buildr/ide/idea.rb, line 190 def extension "iml" end
# File lib/buildr/ide/idea.rb, line 186 def jdk_version @jdk_version || buildr_project.compile.options.source || "1.6" end
# File lib/buildr/ide/idea.rb, line 230 def main_dependencies @main_dependencies ||= buildr_project.compile.dependencies end
# File lib/buildr/ide/idea.rb, line 220 def main_output_dir @main_output_dir ||= buildr_project._(:target, :main, :idea, :classes) end
# File lib/buildr/ide/idea.rb, line 194 def main_source_directories @main_source_directories ||= [ buildr_project.compile.sources, buildr_project.resources.sources ].flatten.compact end
# File lib/buildr/ide/idea.rb, line 250 def skip_content! @skip_content = true end
# File lib/buildr/ide/idea.rb, line 246 def skip_content? !!@skip_content end
# File lib/buildr/ide/idea.rb, line 234 def test_dependencies @test_dependencies ||= buildr_project.test.compile.dependencies end
# File lib/buildr/ide/idea.rb, line 226 def test_output_dir @test_output_dir ||= buildr_project._(:target, :test, :idea, :classes) end
# File lib/buildr/ide/idea.rb, line 201 def test_source_directories @test_source_directories ||= [ buildr_project.test.compile.sources, buildr_project.test.resources.sources ].flatten.compact end
# File lib/buildr/ide/idea.rb, line 400 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
# File lib/buildr/ide/idea.rb, line 410 def default_components [ lambda { module_root_component }, lambda { facet_component } ] end
# File lib/buildr/ide/idea.rb, line 417 def facet_component create_composite_component("FacetManager", self.facets) end
# File lib/buildr/ide/idea.rb, line 476 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
# File lib/buildr/ide/idea.rb, line 482 def generate_content(xml) xml.content(:url => "file://$MODULE_DIR$") do # Source folders { :main => self.main_source_directories, :test => self.test_source_directories }.each do |kind, directories| directories.map { |dir| dir.to_s }.compact.sort.uniq.each do |dir| xml.sourceFolder :url => file_path(dir), :isTestSource => (kind == :test ? 'true' : 'false') 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
# File lib/buildr/ide/idea.rb, line 508 def generate_initial_order_entries(xml) xml.orderEntry :type => "sourceFolder", :forTests => "false" xml.orderEntry :type => "jdk", :jdkName => jdk_version, :jdkType => "JavaSDK" end
# File lib/buildr/ide/idea.rb, line 443 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
# File lib/buildr/ide/idea.rb, line 520 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
# File lib/buildr/ide/idea.rb, line 513 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
# File lib/buildr/ide/idea.rb, line 406 def initial_components [] end
# File lib/buildr/ide/idea.rb, line 460 def jar_path(path) "jar://#{resolve_path(path)}!/" end
# File lib/buildr/ide/idea.rb, line 421 def module_root_component create_component("NewModuleRootManager", "inherit-compiler-output" => "false") do |xml| generate_compile_output(xml) generate_content(xml) unless skip_content? generate_initial_order_entries(xml) project_dependencies = [] self.test_dependency_details.each do |dependency_path, export, source_path| next unless export generate_lib(xml, dependency_path, export, source_path, project_dependencies) end 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 xml.orderEntryProperties end end
Don’t exclude things that are subdirectories of other excluded things
# File lib/buildr/ide/idea.rb, line 540 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
# File lib/buildr/ide/idea.rb, line 504 def relative_dir_inside_dir?(dir) !dir.include?("../") end
# File lib/buildr/ide/idea.rb, line 472 def resolve_path(path) resolve_path_from_base(path, "$MODULE_DIR$") end
# File lib/buildr/ide/idea.rb, line 384 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
# File lib/buildr/ide/idea.rb, line 464 def url_for_path(path) if path =~ /jar$/ jar_path(path) else file_path(path) end end