#!/usr/bin/ruby
require 'find'
#-------------------------------------------------------------------------------
# Russ 17 Mar 2005
# parse all src,test,and target/leaflet/leafmd/domain directories and add
# to Jane libraries. Optional entire Maven repository library creation.
#
# script is *really* rough, but it works--could be polished up
# apologies to the Windows guys that I hard-coded the path separators instead
# of File::SEPARATOR
#
# lastly, it's probably a good idea to increase the Jedit heap size for
# performance benefits (/usr/bin/jedit). Also, for this to work nicely, you'll need
# Norm's build of Jane.
#-------------------------------------------------------------------------------
#INSTRUCTIONS:
# change the following as necessary for your system
Jane_Libraries="/home/russ/.jedit/libraries"
Unity_Home = "/home/russ/UnityHome"
Leaf_Home = "/home/russ/LeafHome"
Maven_Repository = "/home/russ/.maven/repository"
#leave the rest of the script alone ;)
#---------------Begin globals and class/function defs--------------------------#
$javaSrcDir = []
$javaSrcName = []
$javaJar = []
$javaJarName = []
$cntr = 0
#thanks to Massimiliano Mirra for this beauty below
class Dir
def Dir.visit(dir = '.', files_first = false, &block)
if files_first
paths = []
Find.find(dir) { |path| paths << path }
paths.reverse_each {|path| yield path}
else
Find.find(dir, &block)
end
end
def Dir.rm_rf(dir)
Dir.visit(dir, true) do |path|
if FileTest.directory?(path)
Dir.unlink(path)
else
File.unlink(path)
end
end
end
end
def addLeafSrcsToJane(dirPath)
aDirectory = Dir.open(dirPath)
begin
for file in aDirectory
next if file == "." or file== ".."
if file=="src" then
puts "Found a source " + file
else
File.directory?(file)
temp = aDirectory.path + "/" + file
if File.directory?(temp) then
secondDir = Dir.open(temp)
if File.directory?(secondDir.path + "/src") then
srcBaseDir = Dir.open(secondDir.path + "/src")
temp2 = srcBaseDir.path + "/java"
if File.directory?(temp2) then
$javaSrcDir<<Dir.open(temp2).path
$javaSrcName<<file
puts "added " + Dir.open(temp2).path
end
temp3 = srcBaseDir.path + "/test"
if File.directory?(temp3) then
$javaSrcDir<<Dir.open(temp3).path
$javaSrcName<<file + " test src"
puts "added " + Dir.open(temp3).path
end
end
leafmd = secondDir.path + "/target/leaflet/leafmd/domain"
if File.directory?(leafmd) then
$javaSrcDir<<Dir.open(leafmd).path
$javaSrcName<<file + " leaf domain"
puts "added " + Dir.open(leafmd).path
end
end
end
end
end
end
def addMavenJarsToJane(mavenRepository)
mavenRepoDir = Dir.open(mavenRepository)
puts mavenRepoDir.path
begin
for projDir in mavenRepoDir
next if projDir == "." or projDir== ".."
tempJarDir = mavenRepoDir.path + "/" + projDir +"/jars"
puts tempJarDir
if File.directory?(tempJarDir) then
jarDir = Dir.open(tempJarDir)
#if File.directory?(jarDir.path) then
for file in jarDir
next if file =="." or file == ".." or file.to_s.index("md5")!=nil or file.to_s.index("rar")!=nil
#puts "found jar #{File.expand_path(file)}"
#puts file.to_s
$javaJar<<jarDir.path + "/" + file
puts jarDir.path + "/" + file
$javaJarName<<file
end
#end
end
end
end
end
#-----------------End globals and class/function defs--------------------------#
addMavenJarsToJane(Maven_Repository)
puts "This script will wax your current Jane libraries, are you sure you want to continue? (yes | no)"
gets
if (($_<=> "yes")==1) then
Dir.rm_rf(Jane_Libraries)
Dir.mkdir(Jane_Libraries)
addLeafSrcsToJane(Unity_Home)
addLeafSrcsToJane(Leaf_Home)
f = File.open(Jane_Libraries + "/libraries.properties","w")
cntr2 = 0
for el in $javaSrcDir
f.puts "library.#{cntr2}.class-path="
f.puts "library.#{cntr2}.parse-type=-1"
f.puts "library.#{cntr2}.cache-type=jane.cache.SimpleClassCache"
f.puts "library.#{cntr2}.doc-path="
f.puts "library.#{cntr2}.name=#{$javaSrcName[cntr2]}"
f.puts "library.#{cntr2}.source-path=#{el}"
tempstr = Jane_Libraries + "/" + $javaSrcName[cntr2]
Dir.mkdir(tempstr)
cntr2+=1
end
puts "Add Maven repository jars as classpaths ?"
gets
if (($_<=> "yes")==1) then
addMavenJarsToJane("/home/russ/.maven/repository")
cntr2 = 0
for el in $javaJar
tempstr = Jane_Libraries + "/" + $javaJarName[cntr2] + "dir"
name = $javaJarName[cntr2]
next if File.directory?(tempstr)
Dir.mkdir(tempstr)
f.puts "library.#{cntr2}.class-path=#{el}"
f.puts "library.#{cntr2}.parse-type=-1"
f.puts "library.#{cntr2}.cache-type=jane.cache.SimpleClassCache"
f.puts "library.#{cntr2}.doc-path="
f.puts "library.#{cntr2}.name=#{name}"
f.puts "library.#{cntr2}.source-path="
cntr2+=1
end
end
f.close
else
puts "operation terminated"
end
Thursday, March 17, 2005
Ruby script for generating Jane entries
The first post of this is *extremely* scoped for what I'm doing at work. So, while it will work to build Jane library entries for everything in your maven repository, it may take some minor tweaking to do only that. Hand in hand with the Jane Stackoverflow fix we made, this is awesome with CodeAid--complete the code from the source.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment