diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/Enigma.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/Enigma.java | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/main/java/cuchaz/enigma/Enigma.java b/src/main/java/cuchaz/enigma/Enigma.java index fd23b47..4522ed7 100644 --- a/src/main/java/cuchaz/enigma/Enigma.java +++ b/src/main/java/cuchaz/enigma/Enigma.java | |||
| @@ -12,7 +12,10 @@ | |||
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import com.google.common.base.Preconditions; | 14 | import com.google.common.base.Preconditions; |
| 15 | import com.google.common.collect.ImmutableList; | ||
| 16 | import com.google.common.collect.ImmutableListMultimap; | ||
| 15 | import com.google.common.collect.ImmutableMap; | 17 | import com.google.common.collect.ImmutableMap; |
| 18 | import com.google.common.collect.ImmutableMultimap; | ||
| 16 | import cuchaz.enigma.analysis.ClassCache; | 19 | import cuchaz.enigma.analysis.ClassCache; |
| 17 | import cuchaz.enigma.analysis.index.JarIndex; | 20 | import cuchaz.enigma.analysis.index.JarIndex; |
| 18 | import cuchaz.enigma.api.EnigmaPlugin; | 21 | import cuchaz.enigma.api.EnigmaPlugin; |
| @@ -24,6 +27,10 @@ import cuchaz.enigma.api.service.JarIndexerService; | |||
| 24 | 27 | ||
| 25 | import java.io.IOException; | 28 | import java.io.IOException; |
| 26 | import java.nio.file.Path; | 29 | import java.nio.file.Path; |
| 30 | import java.util.ArrayList; | ||
| 31 | import java.util.HashMap; | ||
| 32 | import java.util.List; | ||
| 33 | import java.util.Map; | ||
| 27 | import java.util.ServiceLoader; | 34 | import java.util.ServiceLoader; |
| 28 | 35 | ||
| 29 | public class Enigma { | 36 | public class Enigma { |
| @@ -47,9 +54,7 @@ public class Enigma { | |||
| 47 | ClassCache classCache = ClassCache.of(path); | 54 | ClassCache classCache = ClassCache.of(path); |
| 48 | JarIndex jarIndex = classCache.index(progress); | 55 | JarIndex jarIndex = classCache.index(progress); |
| 49 | 56 | ||
| 50 | services.get(JarIndexerService.TYPE).ifPresent(indexer -> { | 57 | services.get(JarIndexerService.TYPE).forEach(indexer -> indexer.acceptJar(classCache, jarIndex)); |
| 51 | indexer.acceptJar(classCache, jarIndex); | ||
| 52 | }); | ||
| 53 | 58 | ||
| 54 | return new EnigmaProject(this, classCache, jarIndex); | 59 | return new EnigmaProject(this, classCache, jarIndex); |
| 55 | } | 60 | } |
| @@ -95,7 +100,7 @@ public class Enigma { | |||
| 95 | private static class PluginContext implements EnigmaPluginContext { | 100 | private static class PluginContext implements EnigmaPluginContext { |
| 96 | private final EnigmaProfile profile; | 101 | private final EnigmaProfile profile; |
| 97 | 102 | ||
| 98 | private final ImmutableMap.Builder<EnigmaServiceType<?>, EnigmaService> services = ImmutableMap.builder(); | 103 | private final ImmutableListMultimap.Builder<EnigmaServiceType<?>, EnigmaService> services = ImmutableListMultimap.builder(); |
| 99 | 104 | ||
| 100 | PluginContext(EnigmaProfile profile) { | 105 | PluginContext(EnigmaProfile profile) { |
| 101 | this.profile = profile; | 106 | this.profile = profile; |
| @@ -103,13 +108,15 @@ public class Enigma { | |||
| 103 | 108 | ||
| 104 | @Override | 109 | @Override |
| 105 | public <T extends EnigmaService> void registerService(String id, EnigmaServiceType<T> serviceType, EnigmaServiceFactory<T> factory) { | 110 | public <T extends EnigmaService> void registerService(String id, EnigmaServiceType<T> serviceType, EnigmaServiceFactory<T> factory) { |
| 106 | EnigmaProfile.Service serviceProfile = profile.getServiceProfile(serviceType); | 111 | List<EnigmaProfile.Service> serviceProfiles = profile.getServiceProfiles(serviceType); |
| 107 | 112 | ||
| 108 | // if this service type is not configured, or it is configured to use a different service id, skip | 113 | for (EnigmaProfile.Service serviceProfile : serviceProfiles) { |
| 109 | if (serviceProfile == null || !serviceProfile.matches(id)) return; | 114 | if (serviceProfile.matches(id)) { |
| 110 | 115 | T service = factory.create(serviceProfile::getArgument); | |
| 111 | T service = factory.create(serviceProfile::getArgument); | 116 | services.put(serviceType, service); |
| 112 | services.put(serviceType, service); | 117 | break; |
| 118 | } | ||
| 119 | } | ||
| 113 | } | 120 | } |
| 114 | 121 | ||
| 115 | EnigmaServices buildServices() { | 122 | EnigmaServices buildServices() { |