lib/buildr/ide/idea7x.rb in vic-buildr-1.3.1 vs lib/buildr/ide/idea7x.rb in vic-buildr-1.3.3

- old
+ new

@@ -47,13 +47,10 @@ idea7x = project.task("idea7x") # We need paths relative to the top project's base directory. root_path = lambda { |p| f = lambda { |p| p.parent ? f[p.parent] : p.base_dir }; f[p] }[project] - sources = Buildr.application.build_files.map { |file| File.expand_path(file) }.select { |file| File.exist?(file) } - sources << File.expand_path(Buildr.application.buildfile, root_path) if Buildr.application.buildfile - # Find a path relative to the project's root directory. relative = lambda { |path| Util.relative_path(File.expand_path(path.to_s), project.path_to) } m2repo = Buildr::Repositories.instance.local excludes = [ '**/.svn/', '**/CVS/' ].join('|') @@ -61,11 +58,11 @@ # Only for projects that are packageable. task_name = project.path_to("#{project.name.gsub(':', '-')}#{IML_SUFFIX}") idea7x.enhance [ file(task_name) ] # The only thing we need to look for is a change in the Buildfile. - file(task_name=>sources) do |task| + file(task_name=>Buildr.application.buildfile) do |task| # Note: Use the test classpath since Eclipse compiles both "main" and "test" classes using the same classpath deps = project.test.compile.dependencies.map(&:to_s) - [ project.compile.target.to_s ] # Convert classpath elements into applicable Project objects deps.collect! { |path| Buildr.projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path } @@ -74,40 +71,39 @@ project_libs, others = deps.partition { |path| path.is_a?(Project) } # Separate artifacts from Maven2 repository m2_libs, others = others.partition { |path| path.to_s.index(m2repo) == 0 } - # Generated: classpath elements in the project are assumed to be generated - generated, libs = others.partition { |path| path.to_s.index(project.path_to.to_s) == 0 } - # Project type is going to be the first package type if package = project.packages.first - puts "Writing #{task.name}" if verbose + info "Writing #{task.name}" File.open(task.name, "w") do |file| xml = Builder::XmlMarkup.new(:target=>file, :indent=>2) xml.module(:version=>"4", :relativePaths=>"true", :type=>"JAVA_MODULE") do xml.component(:name=>"NewModuleRootManager", "inherit-compiler-output"=>"false") do Buildr::Idea7x.generate_compile_output(project, xml, relative) - Buildr::Idea7x.generate_content(project, xml, generated, relative) + Buildr::Idea7x.generate_content(project, xml, relative) Buildr::Idea7x.generate_order_entries(project_libs, xml) - ext_libs = libs.map {|path| "#{MODULE_DIR}/#{path.to_s}" } + m2_libs.map { |path| path.to_s.sub(m2repo, "$M2_REPO$") } + ext_libs = m2_libs.map { |path| "jar://#{path.to_s.sub(m2repo, "$M2_REPO$")}!/" } + ext_libs << "#{MODULE_DIR_URL}/#{relative[project.test.resources.target.to_s]}" if project.test.resources.target + ext_libs << "#{MODULE_DIR_URL}/#{relative[project.resources.target.to_s]}" if project.resources.target + Buildr::Idea7x.generate_module_libs(xml, ext_libs) - xml.orderEntryProperties end end end end end # Root project aggregates all the subprojects. if project.parent == nil - Buildr::Idea7x.generate_ipr(project, idea7x, sources) + Buildr::Idea7x.generate_ipr(project, idea7x, Buildr.application.buildfile) end end # after_define class << self @@ -122,17 +118,18 @@ end end def generate_compile_output(project, xml, relative) xml.output(:url=>"#{MODULE_DIR_URL}/#{relative[project.compile.target.to_s]}") if project.compile.target - xml.tag!("output-test", :url=>"#{MODULE_DIR_URL}/#{relative[project.test.compile.target.to_s]}") if project.test.compile.target + xml.tag!("output-test", :url=>"#{MODULE_DIR_URL}/#{relative[project.test.compile.target.to_s]}") if project.test.compile.target + xml.tag!("exclude-output") end - def generate_content(project, xml, generated, relative) + def generate_content(project, xml, relative) xml.content(:url=>"#{MODULE_DIR_URL}") do unless project.compile.sources.empty? - srcs = project.compile.sources.map { |src| relative[src.to_s] } + generated.map { |src| relative[src.to_s] } + srcs = project.compile.sources.map { |src| relative[src.to_s] } srcs.sort.uniq.each do |path| xml.sourceFolder :url=>"#{MODULE_DIR_URL}/#{path}", :isTestSource=>"false" end end unless project.test.compile.sources.empty? @@ -140,28 +137,29 @@ test_sources.each do |paths| paths.sort.uniq.each do |path| xml.sourceFolder :url=>"#{MODULE_DIR_URL}/#{path}", :isTestSource=>"true" end end - end + end [project.resources=>false, project.test.resources=>true].each do |resources, test| resources.each do |path| path[0].sources.each do |srcpath| xml.sourceFolder :url=>"#{FILE_PATH_PREFIX}#{srcpath}", :isTestSource=>path[1].to_s end end end - xml.excludeFolder :url=>"#{MODULE_DIR_URL}/#{relative[project.compile.target.to_s]}" if project.compile.target + xml.excludeFolder :url=>"#{MODULE_DIR_URL}/#{relative[project.resources.target.to_s]}" if project.resources.target + xml.excludeFolder :url=>"#{MODULE_DIR_URL}/#{relative[project.test.resources.target.to_s]}" if project.test.resources.target end end def generate_module_libs(xml, ext_libs) ext_libs.each do |path| xml.orderEntry :type=>"module-library" do xml.library do xml.CLASSES do - xml.root :url=>"jar://#{path}!/" + xml.root :url=> path end xml.JAVADOC xml.SOURCES end end @@ -170,11 +168,11 @@ def generate_ipr(project, idea7x, sources) task_name = project.path_to("#{project.name.gsub(':', '-')}-7x.ipr") idea7x.enhance [ file(task_name) ] file(task_name=>sources) do |task| - puts "Writing #{task.name}" if verbose + info "Writing #{task.name}" # Generating just the little stanza that chanages from one project to another partial = StringIO.new xml = Builder::XmlMarkup.new(:target=>partial, :indent=>2) xml.component(:name=>"ProjectModuleManager") do @@ -194,10 +192,12 @@ # Loading the whole fairly constant crap template_xml = REXML::Document.new(File.open(File.join(File.dirname(__FILE__), IPR_TEMPLATE))) include_xml = REXML::Document.new(partial.string) template_xml.root.add_element(include_xml.root) - template_xml.write(File.new(task.name, "w")) + File.open task.name, 'w' do |file| + template_xml.write file + end end end end