You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by bo...@apache.org on 2010/01/23 20:22:24 UTC
svn commit: r902466 - /buildr/trunk/lib/buildr/ide/eclipse.rb
Author: boisvert
Date: Sat Jan 23 19:22:23 2010
New Revision: 902466
URL: http://svn.apache.org/viewvc?rev=902466&view=rev
Log:
The recent fix for BUILDR-361 (e8629e000de2bc75232cda31f6c9acb8986758aa) has
subtlely broken core features by calling project.projects during load phase
of the buildfile, leading to harmful side-effects on project definition order.
I'm adding a task enhance call to delay the eclipse task execution until after
the project definition has completed. Hopefully this is good enough.
Modified:
buildr/trunk/lib/buildr/ide/eclipse.rb
Modified: buildr/trunk/lib/buildr/ide/eclipse.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/ide/eclipse.rb?rev=902466&r1=902465&r2=902466&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/ide/eclipse.rb (original)
+++ buildr/trunk/lib/buildr/ide/eclipse.rb Sat Jan 23 19:22:23 2010
@@ -191,93 +191,97 @@
end
after_define(:eclipse => :package) do |project|
- eclipse = project.task('eclipse')
- # We don't create the .project and .classpath files if the project contains projects.
- if project.projects.empty?
-
- eclipse.enhance [ file(project.path_to('.classpath')), file(project.path_to('.project')) ]
-
- # The only thing we need to look for is a change in the Buildfile.
- file(project.path_to('.classpath')=>Buildr.application.buildfile) do |task|
- if (project.eclipse.natures.reject { |x| x.is_a?(Symbol) }.size > 0)
- info "Writing #{task.name}"
+ # Need to enhance because using project.projects during load phase of the
+ # buildfile has harmful side-effects on project definition order
+ project.enhance do
+ eclipse = project.task('eclipse')
+ # We don't create the .project and .classpath files if the project contains projects.
+ if project.projects.empty?
+
+ eclipse.enhance [ file(project.path_to('.classpath')), file(project.path_to('.project')) ]
+
+ # The only thing we need to look for is a change in the Buildfile.
+ file(project.path_to('.classpath')=>Buildr.application.buildfile) do |task|
+ if (project.eclipse.natures.reject { |x| x.is_a?(Symbol) }.size > 0)
+ info "Writing #{task.name}"
+
+ m2repo = Buildr::Repositories.instance.local
+
+ File.open(task.name, 'w') do |file|
+ classpathentry = ClasspathEntryWriter.new project, file
+ classpathentry.write do
+ # Note: Use the test classpath since Eclipse compiles both "main" and "test" classes using the same classpath
+ cp = project.test.compile.dependencies.map(&:to_s) - [ project.compile.target.to_s, project.resources.target.to_s ]
+ cp = cp.uniq
+
+ # Convert classpath elements into applicable Project objects
+ cp.collect! { |path| Buildr.projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path }
+
+ # Remove excluded libs
+ cp -= project.eclipse.exclude_libs.map(&:to_s)
+
+ # project_libs: artifacts created by other projects
+ project_libs, others = cp.partition { |path| path.is_a?(Project) }
+
+ # Separate artifacts under known classpath variable paths
+ # including artifacts located in local Maven2 repository
+ vars = []
+ project.eclipse.classpath_variables.merge(project.eclipse.options.m2_repo_var => m2repo).each do |name, path|
+ matching, others = others.partition { |f| File.expand_path(f.to_s).index(path) == 0 }
+ matching.each do |m|
+ vars << [m, name, path]
+ end
+ end
- m2repo = Buildr::Repositories.instance.local
+ # Generated: Any non-file classpath elements in the project are assumed to be generated
+ libs, generated = others.partition { |path| File.file?(path.to_s) }
- File.open(task.name, 'w') do |file|
- classpathentry = ClasspathEntryWriter.new project, file
- classpathentry.write do
- # Note: Use the test classpath since Eclipse compiles both "main" and "test" classes using the same classpath
- cp = project.test.compile.dependencies.map(&:to_s) - [ project.compile.target.to_s, project.resources.target.to_s ]
- cp = cp.uniq
-
- # Convert classpath elements into applicable Project objects
- cp.collect! { |path| Buildr.projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path }
-
- # Remove excluded libs
- cp -= project.eclipse.exclude_libs.map(&:to_s)
-
- # project_libs: artifacts created by other projects
- project_libs, others = cp.partition { |path| path.is_a?(Project) }
-
- # Separate artifacts under known classpath variable paths
- # including artifacts located in local Maven2 repository
- vars = []
- project.eclipse.classpath_variables.merge(project.eclipse.options.m2_repo_var => m2repo).each do |name, path|
- matching, others = others.partition { |f| File.expand_path(f.to_s).index(path) == 0 }
- matching.each do |m|
- vars << [m, name, path]
+ classpathentry.src project.compile.sources + generated
+ classpathentry.src project.resources
+
+ if project.test.compile.target
+ classpathentry.src project.test.compile
+ classpathentry.src project.test.resources
end
- end
- # Generated: Any non-file classpath elements in the project are assumed to be generated
- libs, generated = others.partition { |path| File.file?(path.to_s) }
+ # Classpath elements from other projects
+ classpathentry.src_projects project_libs
- classpathentry.src project.compile.sources + generated
- classpathentry.src project.resources
+ classpathentry.output project.compile.target if project.compile.target
+ classpathentry.lib libs
+ classpathentry.var vars
- if project.test.compile.target
- classpathentry.src project.test.compile
- classpathentry.src project.test.resources
+ project.eclipse.classpath_containers.each { |container|
+ classpathentry.con container
+ }
end
-
- # Classpath elements from other projects
- classpathentry.src_projects project_libs
-
- classpathentry.output project.compile.target if project.compile.target
- classpathentry.lib libs
- classpathentry.var vars
-
- project.eclipse.classpath_containers.each { |container|
- classpathentry.con container
- }
end
end
end
- end
- # The only thing we need to look for is a change in the Buildfile.
- file(project.path_to('.project')=>Buildr.application.buildfile) do |task|
- info "Writing #{task.name}"
- File.open(task.name, 'w') do |file|
- xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
- xml.projectDescription do
- xml.name project.id
- xml.projects
- unless project.eclipse.builders.empty?
- xml.buildSpec do
- project.eclipse.builders.each { |builder|
- xml.buildCommand do
- xml.name builder
- end
- }
+ # The only thing we need to look for is a change in the Buildfile.
+ file(project.path_to('.project')=>Buildr.application.buildfile) do |task|
+ info "Writing #{task.name}"
+ File.open(task.name, 'w') do |file|
+ xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
+ xml.projectDescription do
+ xml.name project.id
+ xml.projects
+ unless project.eclipse.builders.empty?
+ xml.buildSpec do
+ project.eclipse.builders.each { |builder|
+ xml.buildCommand do
+ xml.name builder
+ end
+ }
+ end
end
- end
- unless project.eclipse.natures.empty?
- xml.natures do
- project.eclipse.natures.each { |nature|
- xml.nature nature unless nature.is_a? Symbol
- }
+ unless project.eclipse.natures.empty?
+ xml.natures do
+ project.eclipse.natures.each { |nature|
+ xml.nature nature unless nature.is_a? Symbol
+ }
+ end
end
end
end