Home > Uncategorized > GNU Trove 2.x to 3.x migration

GNU Trove 2.x to 3.x migration

Based on this this post, here is a script to help migration from GNU Trove version 2.x to 3.x.

#! /usr/bin/python
import sys
import re
import tempfile
import os
import shutil

trove2_to_trove3={
 "TObjectHashingStrategy": "strategy.HashingStrategy",
 "PrimeFinder": "impl.PrimeFinder"}
def do_a_file(filename):
    in_file=open(filename)
    output, output_name = tempfile.mkstemp()
    output = os.fdopen(output, "w")
    rawstr = r"""import gnu\.trove\.(.*);"""
    compile_obj = re.compile(rawstr)
    for l in in_file:
        match_obj = compile_obj.search(l)
        if match_obj != None and len(match_obj.groups()) > 0:
            clazz=match_obj.group(1)
            if clazz[:1].islower():
                new_class=clazz
            elif trove2_to_trove3.has_key(clazz):
                new_class=trove2_to_trove3[clazz]
            elif clazz.endswith("ArrayList"):
                new_class="list.array."+clazz
            elif clazz.endswith("HashMap"):
                new_class="map.hash."+clazz
            elif clazz.endswith("HashSet"):
                new_class="set.hash."+clazz
            elif clazz.endswith("Iterator"):
                new_class="iterator."+clazz
            elif clazz.endswith("Procedure"):
                new_class="procedure."+clazz
            else:
                new_class=clazz
            output.write("import gnu.trove."+new_class+";\n")
        else:
            output.write(l)
    in_file.close()
    output.close()
    shutil.move(output_name, filename)

for root, subFolders, files in os.walk(sys.argv[1]):
    for file in files:
        if file.endswith(".java"):
            do_a_file(os.path.join(root,file))
Advertisements
Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: