|
|
|
@ -34,6 +34,9 @@ import @COLLECTIONS@.HashMap; |
|
|
|
|
import @COLLECTIONS@.Iterator; |
|
|
|
|
import @COLLECTIONS@.List; |
|
|
|
|
import @COLLECTIONS@.ArrayList; |
|
|
|
|
import @COLLECTIONS@.Random; |
|
|
|
|
import @COLLECTIONS@.Arrays; |
|
|
|
|
import @COLLECTIONS@.Collections; |
|
|
|
|
|
|
|
|
|
public class PackageIdentifier extends Identifier { |
|
|
|
|
ClassBundle bundle; |
|
|
|
@ -43,6 +46,8 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
|
|
|
|
|
boolean loadOnDemand; |
|
|
|
|
Map loadedClasses; |
|
|
|
|
List swappedClasses; |
|
|
|
|
Random rand = new Random(); |
|
|
|
|
|
|
|
|
|
public PackageIdentifier(ClassBundle bundle, |
|
|
|
|
PackageIdentifier parent, |
|
|
|
@ -84,6 +89,7 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
PackageIdentifier ident = new PackageIdentifier |
|
|
|
|
(bundle, this, subFull, subclazz); |
|
|
|
|
loadedClasses.put(subclazz, ident); |
|
|
|
|
swappedClasses = null; |
|
|
|
|
ident.setLoadOnDemand(); |
|
|
|
|
} else { |
|
|
|
|
ClassIdentifier ident = new ClassIdentifier |
|
|
|
@ -93,6 +99,7 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
GlobalOptions.err.println("preloading Class " |
|
|
|
|
+ subFull); |
|
|
|
|
loadedClasses.put(subclazz, ident); |
|
|
|
|
swappedClasses = null; |
|
|
|
|
bundle.addClassIdentifier(ident); |
|
|
|
|
((ClassIdentifier) ident).initClass(); |
|
|
|
|
} |
|
|
|
@ -132,6 +139,7 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
PackageIdentifier pack |
|
|
|
|
= new PackageIdentifier(bundle, this, subFull, name); |
|
|
|
|
loadedClasses.put(name, pack); |
|
|
|
|
swappedClasses = null; |
|
|
|
|
pack.setLoadOnDemand(); |
|
|
|
|
ident = pack; |
|
|
|
|
} else if (!ClassInfo.exists(subFull)) { |
|
|
|
@ -142,6 +150,7 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
ident = new ClassIdentifier(this, subFull, name, |
|
|
|
|
ClassInfo.forName(subFull)); |
|
|
|
|
loadedClasses.put(name, ident); |
|
|
|
|
swappedClasses = null; |
|
|
|
|
bundle.addClassIdentifier(ident); |
|
|
|
|
((ClassIdentifier) ident).initClass(); |
|
|
|
|
} |
|
|
|
@ -159,6 +168,7 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
pack = new PackageIdentifier(bundle, this, |
|
|
|
|
subFull, subpack); |
|
|
|
|
loadedClasses.put(subpack, pack); |
|
|
|
|
swappedClasses = null; |
|
|
|
|
if (loadOnDemand) |
|
|
|
|
pack.setLoadOnDemand(); |
|
|
|
|
} |
|
|
|
@ -184,6 +194,7 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
ident = new PackageIdentifier(bundle, this, |
|
|
|
|
subFull, component); |
|
|
|
|
loadedClasses.put(component, ident); |
|
|
|
|
swappedClasses = null; |
|
|
|
|
if (loadOnDemand) |
|
|
|
|
((PackageIdentifier) ident).setLoadOnDemand(); |
|
|
|
|
} else if (ClassInfo.exists(subFull)) { |
|
|
|
@ -193,6 +204,7 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
ClassInfo.forName(subFull)); |
|
|
|
|
if (loadOnDemand || matcher.matches(ident)) { |
|
|
|
|
loadedClasses.put(component, ident); |
|
|
|
|
swappedClasses = null; |
|
|
|
|
bundle.addClassIdentifier(ident); |
|
|
|
|
((ClassIdentifier) ident).initClass(); |
|
|
|
|
} |
|
|
|
@ -232,6 +244,7 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
PackageIdentifier ident = new PackageIdentifier |
|
|
|
|
(bundle, this, subFull, subclazz); |
|
|
|
|
loadedClasses.put(subclazz, ident); |
|
|
|
|
swappedClasses = null; |
|
|
|
|
if (loadOnDemand || matcher.matches(ident)) |
|
|
|
|
ident.setLoadOnDemand(); |
|
|
|
|
} else { |
|
|
|
@ -244,6 +257,7 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
GlobalOptions.err.println("loading Class " |
|
|
|
|
+ subFull); |
|
|
|
|
loadedClasses.put(subclazz, ident); |
|
|
|
|
swappedClasses = null; |
|
|
|
|
bundle.addClassIdentifier(ident); |
|
|
|
|
((ClassIdentifier) ident).initClass(); |
|
|
|
|
} |
|
|
|
@ -284,10 +298,14 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
*/ |
|
|
|
|
public String getFullAlias() { |
|
|
|
|
if (parent != null) { |
|
|
|
|
if (parent.getFullAlias().length() > 0) |
|
|
|
|
return parent.getFullAlias() + "." + getAlias(); |
|
|
|
|
else |
|
|
|
|
return getAlias(); |
|
|
|
|
String parentAlias = parent.getFullAlias(); |
|
|
|
|
String alias = getAlias(); |
|
|
|
|
if (alias.length() == 0) |
|
|
|
|
return parentAlias; |
|
|
|
|
else if (parentAlias.length() == 0) |
|
|
|
|
return alias; |
|
|
|
|
else |
|
|
|
|
return parentAlias + "." + alias; |
|
|
|
|
} |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
@ -313,7 +331,7 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void doTransformations() { |
|
|
|
|
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) { |
|
|
|
|
for (Iterator i = getChilds(); i.hasNext(); ) { |
|
|
|
|
Identifier ident = (Identifier) i.next(); |
|
|
|
|
if (ident instanceof ClassIdentifier) { |
|
|
|
|
((ClassIdentifier) ident).doTransformations(); |
|
|
|
@ -333,17 +351,6 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void writeTable(Map table) { |
|
|
|
|
if (parent != null) |
|
|
|
|
table.put(getFullAlias(), getName()); |
|
|
|
|
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) { |
|
|
|
|
Identifier ident = (Identifier) i.next(); |
|
|
|
|
if ((Main.stripping & Main.STRIP_UNREACH) == 0 |
|
|
|
|
|| ident.isReachable()) |
|
|
|
|
ident.writeTable(table); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Identifier getParent() { |
|
|
|
|
return parent; |
|
|
|
|
} |
|
|
|
@ -357,11 +364,19 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Iterator getChilds() { |
|
|
|
|
return loadedClasses.values().iterator(); |
|
|
|
|
/* Since loadedClasses is somewhat sorted by the hashcode |
|
|
|
|
* of the _original_ names, swap it here to prevent to guess |
|
|
|
|
* even parts of the names. |
|
|
|
|
*/ |
|
|
|
|
if (swappedClasses == null) { |
|
|
|
|
swappedClasses = Arrays.asList(loadedClasses.values().toArray()); |
|
|
|
|
Collections.shuffle(swappedClasses, rand); |
|
|
|
|
} |
|
|
|
|
return swappedClasses.iterator(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void storeClasses(ZipOutputStream zip) { |
|
|
|
|
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) { |
|
|
|
|
for (Iterator i = getChilds(); i.hasNext(); ) { |
|
|
|
|
Identifier ident = (Identifier) i.next(); |
|
|
|
|
if ((Main.stripping & Main.STRIP_UNREACH) != 0 |
|
|
|
|
&& !ident.isReachable()) { |
|
|
|
@ -399,7 +414,7 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
GlobalOptions.err.println("Could not create directory " |
|
|
|
|
+newDest.getPath()+", check permissions."); |
|
|
|
|
} |
|
|
|
|
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) { |
|
|
|
|
for (Iterator i = getChilds(); i.hasNext(); ) { |
|
|
|
|
Identifier ident = (Identifier) i.next(); |
|
|
|
|
if ((Main.stripping & Main.STRIP_UNREACH) != 0 |
|
|
|
|
&& !ident.isReachable()) { |
|
|
|
@ -442,12 +457,23 @@ public class PackageIdentifier extends Identifier { |
|
|
|
|
public boolean contains(String newAlias, Identifier except) { |
|
|
|
|
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) { |
|
|
|
|
Identifier ident = (Identifier)i.next(); |
|
|
|
|
if (((Main.stripping & Main.STRIP_UNREACH) == 0 |
|
|
|
|
|| ident.isReachable()) |
|
|
|
|
&& ident != except |
|
|
|
|
&& ident.getAlias().equals(newAlias)) |
|
|
|
|
return true; |
|
|
|
|
if (ident != except) { |
|
|
|
|
if (((Main.stripping & Main.STRIP_UNREACH) == 0 |
|
|
|
|
|| ident.isReachable()) |
|
|
|
|
&& ident.getAlias().equalsIgnoreCase(newAlias)) |
|
|
|
|
return true; |
|
|
|
|
if (ident instanceof PackageIdentifier |
|
|
|
|
&& ident.getAlias().length() == 0 |
|
|
|
|
&& (((PackageIdentifier) ident) |
|
|
|
|
.contains(newAlias, this))) |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (getAlias().length() == 0 |
|
|
|
|
&& parent != null |
|
|
|
|
&& parent != except |
|
|
|
|
&& parent.contains(newAlias, this)) |
|
|
|
|
return true; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|