C0 code coverage information
Generated on Wed Oct 07 08:34:00 -0700 2009 with rcov 0.8.2.1
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with this
3 # work for additional information regarding copyright ownership. The ASF
4 # licenses this file to you under the Apache License, Version 2.0 (the
5 # "License"); you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations under
14 # the License.
15
16
17 require 'buildr/core/project'
18 require 'buildr/packaging'
19 require 'stringio'
20
21
22 module Buildr
23 module Idea #:nodoc:
24
25 include Extension
26
27 first_time do
28 # Global task "idea" generates artifacts for all projects.
29 desc "Generate Idea artifacts for all projects"
30 Project.local_task "idea"=>"artifacts"
31 end
32
33 before_define do |project|
34 project.recursive_task("idea")
35 end
36
37 after_define do |project|
38 idea = project.task("idea")
39 # We need paths relative to the top project's base directory.
40 root_path = lambda { |p| f = lambda { |p| p.parent ? f[p.parent] : p.base_dir }; f[p] }[project]
41
42 # Find a path relative to the project's root directory.
43 relative = lambda { |path| Util.relative_path(path.to_s, project.path_to) }
44
45 m2repo = Buildr::Repositories.instance.local
46 excludes = [ '**/.svn/', '**/CVS/' ].join('|')
47
48 # Only for projects that are packageable.
49 task_name = project.path_to("#{project.name.gsub(':', '-')}.iml")
50 idea.enhance [ file(task_name) ]
51
52 # The only thing we need to look for is a change in the Buildfile.
53 file(task_name=>Buildr.application.buildfile) do |task|
54 info "Writing #{task.name}"
55
56 # Idea handles modules slightly differently if they're WARs
57 idea_types = Hash.new("JAVA_MODULE")
58 idea_types["war"] = "J2EE_WEB_MODULE"
59
60 # Note: Use the test classpath since Eclipse compiles both "main" and "test" classes using the same classpath
61 deps = project.test.compile.dependencies.map(&:to_s) - [ project.compile.target.to_s ]
62
63 # Convert classpath elements into applicable Project objects
64 deps.collect! { |path| Buildr.projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path }
65
66 # project_libs: artifacts created by other projects
67 project_libs, others = deps.partition { |path| path.is_a?(Project) }
68
69 # Separate artifacts from Maven2 repository
70 m2_libs, others = others.partition { |path| path.to_s.index(m2repo) == 0 }
71
72 # Generated: classpath elements in the project are assumed to be generated
73 generated, libs = others.partition { |path| path.to_s.index(project.path_to.to_s) == 0 }
74
75 # Project type is going to be the first package type
76 if package = project.packages.first
77 File.open(task.name, "w") do |file|
78 xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
79
80 xml.module(:version=>"4", :relativePaths=>"false", :type=>idea_types[package.type.to_s]) do
81 xml.component :name=>"ModuleRootManager"
82 xml.component "name"=>"NewModuleRootManager", "inherit-compiler-output"=>"false" do
83 has_compile_sources = project.compile.target.to_s.size > 0
84 xml.output :url=>"file://$MODULE_DIR$/#{relative[project.compile.target.to_s]}" if has_compile_sources
85 xml.tag! "exclude-output"
86
87 # TODO project.test.target isn't recognized, what's the proper way to get the test compile path?
88 xml.tag! "output-test", :url=>"file://$MODULE_DIR$/target/test-classes"
89
90 xml.content(:url=>"file://$MODULE_DIR$") do
91 if has_compile_sources
92 srcs = project.compile.sources.map { |src| relative[src.to_s] } + generated.map { |src| relative[src.to_s] }
93 srcs.sort.uniq.each do |path|
94 xml.sourceFolder :url=>"file://$MODULE_DIR$/#{path}", :isTestSource=>"false"
95 end
96
97 test_sources = project.test.compile.sources.map { |src| relative[src.to_s] }
98 test_sources.each do |paths|
99 paths.sort.uniq.each do |path|
100 xml.sourceFolder :url=>"file://$MODULE_DIR$/#{path}", :isTestSource=>"true"
101 end
102 end
103 end
104 [project.resources=>false, project.test.resources=>true].each do |resources, test|
105 resources.each do |path|
106 path[0].sources.each do |srcpath|
107 xml.sourceFolder :url=>"file://#{srcpath}", :isTestSource=>path[1].to_s
108 end
109 end
110 end
111 xml.excludeFolder :url=>"file://$MODULE_DIR$/#{relative[project.compile.target.to_s]}" if has_compile_sources
112 end
113
114 xml.orderEntry :type=>"sourceFolder", :forTests=>"false"
115 xml.orderEntry :type=>"inheritedJdk"
116
117 # Classpath elements from other projects
118 project_libs.map(&:id).sort.uniq.each do |project_id|
119 xml.orderEntry :type=>'module', "module-name"=>project_id
120 end
121
122 # Libraries
123 ext_libs = libs.map {|path| "$MODULE_DIR$/#{path.to_s}" } +
124 m2_libs.map { |path| path.to_s.sub(m2repo, "$M2_REPO$") }
125 ext_libs.each do |path|
126 xml.orderEntry :type=>"module-library" do
127 xml.library do
128 xml.CLASSES do
129 xml.root :url=>"jar://#{path}!/"
130 end
131 xml.JAVADOC
132 xml.SOURCES do
133 xml.root :url=>"jar://#{path.sub(/\.jar$/, "-sources.jar")}!/"
134 end
135 end
136 end
137 end
138
139 xml.orderEntryProperties
140 end
141 end
142 end
143 end
144 end
145
146 # Root project aggregates all the subprojects.
147 if project.parent == nil
148 task_name = project.path_to("#{project.name.gsub(':', '-')}.ipr")
149 idea.enhance [ file(task_name) ]
150
151 file(task_name=>Buildr.application.buildfile) do |task|
152 info "Writing #{task.name}"
153
154 # Generating just the little stanza that chanages from one project to another
155 partial = StringIO.new
156 xml = Builder::XmlMarkup.new(:target=>partial, :indent=>2)
157 xml.component(:name=>"ProjectModuleManager") do
158 xml.modules do
159 project.projects.each do |subp|
160 module_name = subp.name.gsub(":", "-")
161 module_path = subp.name.split(":"); module_path.shift
162 module_path = module_path.join("/")
163 path = "#{module_path}/#{module_name}.iml"
164 xml.module :fileurl=>"file://$PROJECT_DIR$/#{path}", :filepath=>"$PROJECT_DIR$/#{path}"
165 end
166 if package = project.packages.first
167 xml.module :fileurl=>"file://$PROJECT_DIR$/#{project.name}.iml", :filepath=>"$PROJECT_DIR$/#{project.name}.iml"
168 end
169 end
170 end
171
172 # Loading the whole fairly constant crap
173 template_xml = REXML::Document.new(File.open(File.dirname(__FILE__)+"/idea.ipr.template"))
174 include_xml = REXML::Document.new(partial.string)
175 template_xml.root.add_element(include_xml.root)
176 File.open task.name, 'w' do |file|
177 template_xml.write file
178 end
179 end
180 end
181
182 end #after define
183
184 end #module Idea
185 end # module Buildr
186
187
188 class Buildr::Project
189 include Buildr::Idea
190 end
Generated using the rcov code coverage analysis tool for Ruby
version 0.8.2.1.