Skip to content

Instantly share code, notes, and snippets.

@blaxter
Created March 26, 2009 09:14
Show Gist options
  • Save blaxter/85982 to your computer and use it in GitHub Desktop.
Save blaxter/85982 to your computer and use it in GitHub Desktop.
rake aptana:aptana task for generating both .loadpath and .projects file to load a rails project into eclipse aptana IDE
namespace :aptana do
RAILS_APPDIR = RAILS_ROOT.sub("/config/..","")
LIBS = %w{rails activerecord actionmailer actionpack
actionwebservice activeresource activesupport}
def project_name
Pathname.new(RAILS_APPDIR).basename.to_s
end
def project_file(name)
<<END
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>#{name}</name>
<comment>Project #{name} with ruby on rails</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.rubypeople.rdt.core.rubybuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.rubypeople.rdt.core.rubynature</nature>
<nature>org.radrails.rails.core.railsnature</nature>
</natures>
</projectDescription>
END
end
def loadpath_file(excludes, libs)
content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<loadpath>\n"
content << "\t<pathentry "
content << "excluding=\"" << excludes.join('|') << '" '
content << 'path="" type="src"/>'
content << "\n\t"
content << '<pathentry path="org.rubypeople.rdt.launching.RUBY_CONTAINER" type="con" />'
content << "\n"
pathentry = proc {|l| "\t<pathentry path=\"GEM_LIB/#{l}/lib\" type=\"var\"/>\n"}
libs.each {|lib| content << pathentry.call(lib)}
content << '</loadpath>'
end
task :aptana => :environment do
FileUtils.chdir(RAILS_APPDIR)
File.open(".loadpath", 'w') do |f|
includes = []
excludes = []
Gem.path.each do |gem_path_base|
FileUtils.cd( gem_path_base )
FileUtils.cd( 'gems' )
gems = Pathname.new('.')
LIBS.each do |lib|
gems.entries.each do |e|
gem_lib = File.basename(e)
if gem_lib == "#{lib}-#{RAILS_GEM_VERSION}"
includes << File.basename(e)
end
end
end
FileUtils.cd(RAILS_APPDIR); FileUtils.cd('vendor')
vendors = Pathname.new('.')
vendors.entries.each do |e|
name = File.basename(e)
if e.symlink? and name.index('rails') == 0
FileUtils.rm(e)
else
unless name.index('plugin') == 0 || name.index('.') == 0
excludes << 'vendor' + File::SEPARATOR + name
end
end
end
end
f.write loadpath_file(excludes, includes)
end
FileUtils.chdir(RAILS_APPDIR)
File.open(".project", 'w+') do |f|
f.write project_file(project_name)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment