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