public Repackager(String repackageSpecs) {
_fromPackages = new ArrayList();
_toPackages = new ArrayList();
List repackages = splitPath( repackageSpecs, ';' );
// Sort the repackage spec so that longer from's are first to match
// longest package first
for ( ; ; )
{
boolean swapped = false;
for ( int i = 1 ; i < repackages.size() ; i++ )
{
String spec1 = (String) repackages.get( i - 1 );
String spec2 = (String) repackages.get( i );
if (spec1.indexOf( ':' ) < spec2.indexOf( ':' ))
{
repackages.set( i - 1, spec2 );
repackages.set( i, spec1 );
swapped = true;
}
}
if (!swapped)
break;
}
for ( int i = 0 ; i < repackages.size() ; i++ )
{
String spec = (String) repackages.get( i );
int j = spec.indexOf( ':' );
if (j < 0 || spec.indexOf( ':', j + 1 ) >= 0)
throw new RuntimeException( "Illegal repackage specification: " + spec );
String from = spec.substring( 0, j );
String to = spec.substring( j + 1 );
_fromPackages.add( Repackager.splitPath( from, '.' ) );
_toPackages.add( Repackager.splitPath( to, '.' ) );
}
_fromMatchers = new Matcher [ _fromPackages.size() * 2 ];
_toPackageNames = new String [ _fromPackages.size() * 2 ];
addPatterns( '.', 0 );
addPatterns( '/', _fromPackages.size() );
}
|