Skip to content

Instantly share code, notes, and snippets.

@c650
Last active September 20, 2016 23:37
Show Gist options
  • Save c650/ea26564325d08e79b1e6f8e8519c9303 to your computer and use it in GitHub Desktop.
Save c650/ea26564325d08e79b1e6f8e8519c9303 to your computer and use it in GitHub Desktop.
converts directory of java files into an eclipse project
#! /usr/bin/ruby
# by charles bailey (@c650)
# under MIT License
# 9.20.16
require 'fileutils'
if ARGV.length != 4
puts "Usage: ./program [code dir] [new project dir] [example dir] [project name]"
exit(1)
end
puts "Starting to make Eclipse folder..."
code_dir = File.expand_path(ARGV[0])
new_project_dir = File.expand_path(ARGV[1])
example_dir = File.expand_path(ARGV[2])
# Start initializing directories...
FileUtils.mkdir_p(new_project_dir)
src_dir = new_project_dir+"/src"
FileUtils.mkdir_p(src_dir)
bin_dir = new_project_dir+"/bin"
FileUtils.mkdir_p(bin_dir)
# copy stuff into new directory
puts "Copying All Java Files to #{new_project_dir}/src..."
Dir.chdir(code_dir)
FileUtils.cp_r(Dir.glob("*.java"), src_dir)
puts "Copying Hidden Configuration Files..."
Dir.chdir(example_dir)
FileUtils.cp_r(["./.classpath", "./.settings", "./.project"], new_project_dir)
Dir.chdir(new_project_dir)
project_file = new_project_dir+"/.project"
puts "Naming project to #{ARGV[3]}"
f = File.read(project_file).gsub("PROJECT_NAME", ARGV[3])
File.open(project_file, "w") do |file|
file.puts f
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment