Made CardScanner classloader aware.

This commit is contained in:
Lymia Aluysia 2016-09-24 12:14:20 -05:00
parent 3c2dd8d335
commit ad5b23aa06
No known key found for this signature in database
GPG key ID: DB2E204C989251F7

View file

@ -29,7 +29,10 @@
package mage.cards.repository;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.ExpansionSet;
@ -55,15 +58,19 @@ public class CardScanner {
scanned = true;
List<CardInfo> cardsToAdd = new ArrayList<>();
List<String> packages = new ArrayList<>();
Map<ClassLoader, List<String>> packageMap = new HashMap<>();
for (ExpansionSet set : Sets.getInstance().values()) {
ClassLoader cl = set.getClass().getClassLoader();
if(!packageMap.containsKey(cl)) packageMap.put(cl, new ArrayList<String>());
List<String> packages = packageMap.get(cl);
packages.add(set.getPackageName());
ExpansionRepository.instance.add(new ExpansionInfo(set));
}
ExpansionRepository.instance.setContentVersion(ExpansionRepository.instance.getContentVersionConstant());
for (Class c : ClassScanner.findClasses(null, packages, CardImpl.class)) {
for (ClassLoader cl : packageMap.keySet()) {
for (Class c : ClassScanner.findClasses(cl, packageMap.get(cl), CardImpl.class)) {
if (!CardRepository.instance.cardExists(c.getCanonicalName())) {
Card card = CardImpl.createCard(c);
if (card != null) {
@ -76,6 +83,7 @@ public class CardScanner {
}
}
}
}
if (!cardsToAdd.isEmpty()) {
logger.info("Cards need storing in DB: " + cardsToAdd.size());
CardRepository.instance.addCards(cardsToAdd);