jicarilla-suf/scripts create-ibiblio-mirror.rb,NONE,1.1 findbuildfiles.sh,NONE,1.1 ibiblio-contents-finder.rb,NONE,1.1 project.xml-to-dependencies.list.rb,NONE,1.1 projectlistfinder.sh,NONE,1.1 projectpopulator.sh,NONE,1.1

Leo Simons <[email protected]> Sun, 11 Apr 2004 19:42:57 +0000
Newsgroups gmane.comp.java.jicarilla.cvs
Message-ID <[email protected]>
Update of /cvsroot/jicarilla/jicarilla-suf/scripts
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12210/scripts

Added Files:
	create-ibiblio-mirror.rb findbuildfiles.sh 
	ibiblio-contents-finder.rb project.xml-to-dependencies.list.rb 
	projectlistfinder.sh projectpopulator.sh 
Log Message:
various useful tools

--- NEW FILE: ibiblio-contents-finder.rb ---
require "net/http"

HOST = "www.ibiblio.org"
PATH = "/maven/"
SP = ' '

def getGroups()
  connection = Net::HTTP.new(HOST)
  response, data = connection.get(PATH)
  
  if response.code != "200"
    puts "Can't connect to " + HOST + "!"
    exit 1
  end
  
  list = []
  
  groups = data.scan( /\<a href[^>]+\>([^<>]+)\/\<\/a\>/i )
  groups.each{ |group|
    group.each { |val|
      list << val
    }
  }
  puts "Artifact groups: \n"
  list.each{ |group|
    puts "    " + group
  }
  return list
end

def getArtifactsWithVersion( group )
  connection = Net::HTTP.new(HOST)
  
  path = PATH + group + "/jars/" 
  
  response, data = connection.get(path)
  
  if response.code != "200"
    puts "Can't find " + path + ", skipping"
    return []
  end
  
  return data.scan( /\<a href[^>]+\>([^<>]+)-([^<>-]+).jar\<\/a\>/i )
end

def getAllArtifacts( target )
  groups = getGroups()
  
  allJars = []
  
  puts "Artifacts: \n"
  
  groups.each { |group|
    artifacts = getArtifactsWithVersion( group )
    artifacts.each { |artifact|
      allJars << [group, artifact[0], artifact[1]]
      puts "    " + artifact[0] + SP + artifact[1] + SP + group
      target.puts artifact[0] + SP + artifact[1] + SP + group
    }
  }
  
  return allJars
end

def main()
  contents = File.open( "ibiblio-contents.txt", 'w' )
  getAllArtifacts( contents )
  contents.close
end

main()

--- NEW FILE: findbuildfiles.sh ---
find . -name build.xml ! -path './template/build.xml' ! -path './build.xml' | sed -r 's/\/build.xml//g'

--- NEW FILE: project.xml-to-dependencies.list.rb ---
def strip( xml )
  result = xml.gsub( /<[^>]+>[^<>]*<\/[^>]+>/m, '' )
  result.gsub!( /<[^>]+>/m, '' )
  result.gsub!( /[\n\t ]/, '' )
  
  return result
end

def extractArtifactId( dependency )
    id = ''
    if dependency.include? "artifactId" then
      id = dependency.gsub( /\<artifactId\>([^<>]*)\<\/artifactId\>/, '\1' )
    else
      id = dependency.gsub( /\<id\>([^<>]*)\<\/id\>/, '\1' )
    end
    
    return strip( id )
end

def extractGroupId( dependency )
    id = ''
    if dependency.include? "groupId" then
      id = dependency.gsub( /\<groupId\>([^<>]*)\<\/groupId\>/, '\1' )
    else
      id = dependency.gsub( /\<id\>([^<>]*)\<\/id\>/, '\1' )
    end
    
    return strip( id )
end

def extractVersion( dependency )
    version = dependency.gsub( /\<version\>([^<>]*)\<\/version\>/, '\1' )
    return strip( version )
end

def getDepList( project )
    result = ''

    dependencies = project[/\<dependencies\>.*\<\/dependencies\>/m]
    
    if ! dependencies
      return result
    end
    
    dependencies.gsub!( /\<\!--.*?--\>/m, '' )
    
    dependencies.split( /\<\/dependency\>/ ).each { |dependency|
    
      artifact = extractArtifactId( dependency )
      group = extractGroupId( dependency )
      version = extractVersion( dependency )
      
      if artifact.empty?
        next
      end
     
      default = '-'
      sep = ' '

      if( artifact == group ) then
        group = default 
      end
      if( version == 'SNAPSHOT' ) then
        version = default
      end
      
      line = artifact + sep + \
             version + sep + \
             group + sep + \
             default + sep + # repository \
             default + sep + # gump id \
             'runtime,inherit=runtime' # gump options
      
      result = result + line + "\n"
    }
    
    return result
end

def processFile( projectFile, depFile )
    puts "processing " + projectFile + " into " + depFile
    
    source = File.open( projectFile, 'r' )
    dest = File.open( depFile, 'w' )
    
    project = source.read
    
    depList = getDepList( project )
    
    dest.puts "# Dependencies
#
# artifact-id version groupid repository gumpid gumpopts
#
"
    
    dest.puts depList
end

def processAll( files )
    count = 0
    files.each { |path|
      projectFile = path.gsub( /\n/, "" )
      projectFile.gsub!( /\.\//, "" )
      
      depFile = projectFile.gsub( /project\.xml/, 'dependencies.list' )
      
      if FileTest.exist?( depFile )
        depFile = depFile + ".new"
      end
      
      processFile( projectFile, depFile )
      count = count + 1
    }
    return count
end

 # runs the processor
 def main()
     files = `find . -type f -name 'project.xml'`
     count = processAll( files )
 
     puts "transformed #{count} files.\n"
 end
 
 main()
 
--- NEW FILE: projectpopulator.sh ---
LIST=`sh projectlistfinder.sh`

for i in $LIST; do
  cp template/* ./template;
done

# find . -name build.xml -or -name dependencies.list -or -name NOTICE.txt -or \
#     -name project.properties -or -name LICENSE.txt | xargs cvs -q add

--- NEW FILE: create-ibiblio-mirror.rb ---
require "ftools"
require "net/http"

REPO_BASE = "repository"
HOST = "www.ibiblio.org"
PATH = "/maven/"
SP = ' '

$handled = []

def getLicenses( group )
  path = PATH + group + "/licenses/" 

  connection = Net::HTTP.new(HOST)
  response, data = connection.get(path)
  
  if response.code != "200"
    puts "Can't find " + path + ", skipping"
    return []
  end
  
  list = []
  
  licenses = data.scan( /\<a href[^>]+\>(license[^<>]+)\<\/a\>/i )
  licenses.each{ |license|
    license.each { |val|
      list << val
    }
  }
  
  return list
end

def download( fileName )
  localFile = REPO_BASE + '/' + fileName
  remoteFile = PATH + '/' + fileName
  
  if FileTest.exist?( localFile )
    return
  end
  
  connection = Net::HTTP.new(HOST)
  response, data = connection.get(remoteFile)
  
  if response.code != "200"
    puts "WARNING: can't retrieve " + fileName + "!"
    return
  end
  
  puts "retrieved: " + fileName
  
  file = File.open(localFile, 'w')
  file.write( response )
  file.close
end

def downloadJar( id, version, group )
  download( group + "/jars/" + id + "-" + version + ".jar" )
end

def downloadLicenses( group )
  licenses = getLicenses( group )
  licenses.each { |license|
    download( group + "/licenses/" + license )
  }
end

def newGroup( group )
  File.makedirs( REPO_BASE + '/' + group + "/jars/" ) 
  File.makedirs( REPO_BASE + '/' + group + "/licenses/" )
  downloadLicenses( group )
  $handled << group 
end

def downloadAll( list )
  list.each{ |artifact|
    artifact, version, group = artifact.split( ' ' )
  
    if ! $handled.detect { |test| test == group }
      newGroup( group )
    end
    downloadJar( artifact, version, group )
  }
end

def main()
  contents = File.open( "ibiblio-contents.txt", 'r' )
  downloadAll( contents )
  contents.close
end

main()

--- NEW FILE: projectlistfinder.sh ---
find . -type d -name src | sed -r "s/\/src//g"



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click