summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/Enigma.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/Enigma.java')
-rw-r--r--src/main/java/cuchaz/enigma/Enigma.java29
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 @@
12package cuchaz.enigma; 12package cuchaz.enigma;
13 13
14import com.google.common.base.Preconditions; 14import com.google.common.base.Preconditions;
15import com.google.common.collect.ImmutableList;
16import com.google.common.collect.ImmutableListMultimap;
15import com.google.common.collect.ImmutableMap; 17import com.google.common.collect.ImmutableMap;
18import com.google.common.collect.ImmutableMultimap;
16import cuchaz.enigma.analysis.ClassCache; 19import cuchaz.enigma.analysis.ClassCache;
17import cuchaz.enigma.analysis.index.JarIndex; 20import cuchaz.enigma.analysis.index.JarIndex;
18import cuchaz.enigma.api.EnigmaPlugin; 21import cuchaz.enigma.api.EnigmaPlugin;
@@ -24,6 +27,10 @@ import cuchaz.enigma.api.service.JarIndexerService;
24 27
25import java.io.IOException; 28import java.io.IOException;
26import java.nio.file.Path; 29import java.nio.file.Path;
30import java.util.ArrayList;
31import java.util.HashMap;
32import java.util.List;
33import java.util.Map;
27import java.util.ServiceLoader; 34import java.util.ServiceLoader;
28 35
29public class Enigma { 36public 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() {