lib/buildr/ide/eclipse.rb in vic-buildr-1.3.3 vs lib/buildr/ide/eclipse.rb in vic-buildr-1.3.4
- old
+ new
@@ -23,38 +23,39 @@
include Extension
first_time do
# Global task "eclipse" generates artifacts for all projects.
- desc "Generate Eclipse artifacts for all projects"
- Project.local_task "eclipse"=>"artifacts"
+ desc 'Generate Eclipse artifacts for all projects'
+ Project.local_task 'eclipse'=>'artifacts'
end
before_define do |project|
- project.recursive_task("eclipse")
+ project.recursive_task('eclipse')
end
after_define do |project|
- eclipse = project.task("eclipse")
+ eclipse = project.task('eclipse')
# Check if project has scala facet
scala = project.compile.language == :scala
# Only for projects that we support
supported_languages = [:java, :scala]
supported_packaging = %w(jar war rar mar aar)
- if (supported_languages.include? project.compile.language ||
+ if (supported_languages.include?(project.compile.language) ||
+ supported_languages.include?(project.test.compile.language) ||
project.packages.detect { |pkg| supported_packaging.include?(pkg.type.to_s) })
- eclipse.enhance [ file(project.path_to(".classpath")), file(project.path_to(".project")) ]
+ 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|
+ file(project.path_to('.classpath')=>Buildr.application.buildfile) do |task|
info "Writing #{task.name}"
m2repo = Buildr::Repositories.instance.local
- File.open(task.name, "w") do |file|
+ 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
@@ -80,42 +81,42 @@
end
# Classpath elements from other projects
classpathentry.src_projects project_libs
- classpathentry.output project.compile.target
+ classpathentry.output project.compile.target if project.compile.target
classpathentry.lib libs
classpathentry.var m2_libs, 'M2_REPO', m2repo
classpathentry.con 'ch.epfl.lamp.sdt.launching.SCALA_CONTAINER' if scala
classpathentry.con 'org.eclipse.jdt.launching.JRE_CONTAINER'
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|
+ file(project.path_to('.project')=>Buildr.application.buildfile) do |task|
info "Writing #{task.name}"
- File.open(task.name, "w") do |file|
+ File.open(task.name, 'w') do |file|
xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
xml.projectDescription do
xml.name project.id
xml.projects
xml.buildSpec do
if scala
xml.buildCommand do
- xml.name "ch.epfl.lamp.sdt.core.scalabuilder"
+ xml.name 'ch.epfl.lamp.sdt.core.scalabuilder'
end
else
xml.buildCommand do
- xml.name "org.eclipse.jdt.core.javabuilder"
+ xml.name 'org.eclipse.jdt.core.javabuilder'
end
end
end
xml.natures do
- xml.nature "ch.epfl.lamp.sdt.core.scalanature" if scala
- xml.nature "org.eclipse.jdt.core.javanature"
+ xml.nature 'ch.epfl.lamp.sdt.core.scalanature' if scala
+ xml.nature 'org.eclipse.jdt.core.javanature'
end
end
end
end
end
@@ -147,33 +148,42 @@
@xml.classpathentry :kind=>'lib', :path=>path
end
end
# Write a classpathentry of kind 'src'.
- # Accepts an array of absolute paths or a task.
+ # Accept an array of absolute paths or a task.
def src arg
if [:sources, :target].all? { |message| arg.respond_to?(message) }
src_from_task arg
else
src_from_absolute_paths arg
end
end
# Write a classpathentry of kind 'src' for dependent projects.
- # Accepts an array of projects.
+ # Accept an array of projects.
def src_projects project_libs
project_libs.map(&:id).sort.uniq.each do |project_id|
- @xml.classpathentry :kind=>'src', :combineaccessrules=>"false", :path=>"/#{project_id}"
+ @xml.classpathentry :kind=>'src', :combineaccessrules=>'false', :path=>"/#{project_id}"
end
end
def output target
@xml.classpathentry :kind=>'output', :path=>relative(target)
end
+ # Write a classpathentry of kind 'var' (variable) for a library in a local repo.
+ # * +libs+ is an array of library paths.
+ # * +var_name+ is a variable name as defined in Eclipse (e.g., 'M2_REPO').
+ # * +var_value+ is the value of this variable (e.g., '/home/me/.m2').
+ # E.g., <tt>var([lib1, lib2], 'M2_REPO', '/home/me/.m2/repo')</tt>
def var libs, var_name, var_value
- libs.map { |lib| lib.to_s.sub(var_value, var_name) }.sort.uniq.each do |path|
- @xml.classpathentry :kind=>'var', :path=>path
+ libs.each do |lib_path|
+ lib_artifact = file(lib_path)
+ source_path = lib_artifact.sources_artifact.to_s
+ relative_lib_path = lib_path.sub(var_value, var_name)
+ relative_source_path = source_path.sub(var_value, var_name)
+ @xml.classpathentry :kind=>'var', :path=>relative_lib_path, :sourcepath=>relative_source_path
end
end
private