lib/java/eclipse.rb in buildr-0.20.0 vs lib/java/eclipse.rb in buildr-0.21.0
- old
+ new
@@ -35,35 +35,74 @@
relative = lambda do |path|
msg = [:to_path, :to_str, :to_s].find { |msg| path.respond_to? msg }
path = path.__send__(msg)
Pathname.new(path).relative_path_from(Pathname.new(project.path_to)).to_s
end
+
m2repo = Buildr::Repositories.instance.local
+ excludes = [ '**/.svn/', '**/CVS/' ].join('|')
File.open(task.name, "w") do |file|
xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
xml.classpath do
- # Internal: projects that create artifacts we find on the classpath.
- # External: other artifacts, typically from the local repository.
- internal, external = project.compile.classpath.map(&:to_s).
- map { |path| projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path }.
- partition { |path| path.is_a?(Project) }
- vars, libs = external.partition { |path| path.to_s.index(m2repo) == 0 }
- generated, libs = libs.partition { |path| path.to_s.index(project.path_to.to_s) == 0 }
+ # Note: Use the test classpath since Eclipse compiles both "main" and "test" classes using the same classpath
+ cp = project.test.compile.classpath.map(&:to_s) - [ project.compile.target.to_s ]
+
+ # Convert classpath elements into applicable Project objects
+ cp.collect! { |path| projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path }
+
+ # project_libs: artifacts created by other projects
+ project_libs, others = cp.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 }
+
xml.classpathentry :kind=>'con', :path=>'org.eclipse.jdt.launching.JRE_CONTAINER'
- # Collect all the classpaths, key is the kind, value is
- # string or array (or anything responding to to_a).
- { :src => project.compile.sources.map { |src| relative[src] } + generated.map { |src| relative[src] },
- :output => relative[project.compile.target],
+
+ srcs = project.compile.sources.map { |src| relative[src] } + generated.map { |src| relative[src] }
+ srcs.sort.uniq.each do |path|
+ xml.classpathentry :kind=>'src', :path=>path, :excluding=>excludes
+ end
+
+ { :output => relative[project.compile.target],
:lib => libs.map(&:to_s),
- :var => vars.map { |path| path.to_s.sub(m2repo, 'M2_REPO') }
+ :var => m2_libs.map { |path| path.to_s.sub(m2repo, 'M2_REPO') }
}.each do |kind, paths|
paths.sort.uniq.each do |path|
xml.classpathentry :kind=>kind, :path=>path
end
end
- internal.map(&:name).sort.uniq.each do |prj_name|
- xml.classpathentry :kind=>"src", :combineaccessrules=>"false", :path=>"/#{prj_name}"
+
+ # Classpath elements from other projects
+ project_libs.map(&:name).sort.uniq.each do |prj_name|
+ xml.classpathentry :kind=>'src', :combineaccessrules=>"false", :path=>"/#{prj_name}"
+ end
+
+ # Main resources implicitly copied into project.compile.target
+ # TODO: find solution that uses project.test.resources.filter.sources
+ [ "src/main/resources" ].each do |path|
+ if File.exist? project.path_to(path)
+ xml.classpathentry :kind=>'src', :path=>path, :excluding=>excludes
+ end
+ end
+
+ # Test classes are generated in a separate output directory
+ test_sources = project.test.compile.sources.map { |src| relative[src] }
+ test_sources.each do |paths|
+ paths.sort.uniq.each do |path|
+ xml.classpathentry :kind=>'src', :path=>path, :output => relative[project.test.compile.target], :excluding=>excludes
+ end
+ end
+
+ # Test resources go in separate output directory as well
+ # TODO: find solution that uses project.test.resources.filter.sources
+ [ "src/test/resources" ].each do |path|
+ if File.exist? project.path_to(path)
+ xml.classpathentry :kind=>'src', :path=>path, :output => relative[project.test.compile.target], :excluding=>excludes
+ end
end
end
end
end