1
1
package software .coley .recaf .services .mapping ;
2
2
3
3
import jakarta .annotation .Nonnull ;
4
- import jakarta .inject . Inject ;
4
+ import jakarta .annotation . Nullable ;
5
5
import org .objectweb .asm .ClassReader ;
6
6
import org .objectweb .asm .ClassVisitor ;
7
7
import org .objectweb .asm .ClassWriter ;
8
- import software .coley .recaf .cdi .WorkspaceScoped ;
9
8
import software .coley .recaf .info .JvmClassInfo ;
10
9
import software .coley .recaf .info .properties .builtin .HasMappedReferenceProperty ;
11
10
import software .coley .recaf .info .properties .builtin .OriginalClassNameProperty ;
12
11
import software .coley .recaf .info .properties .builtin .RemapOriginTaskProperty ;
13
- import software .coley .recaf .services .Service ;
14
12
import software .coley .recaf .services .inheritance .InheritanceGraph ;
15
- import software .coley .recaf .services .inheritance .InheritanceGraphService ;
16
13
import software .coley .recaf .services .mapping .aggregate .AggregateMappingManager ;
14
+ import software .coley .recaf .services .workspace .WorkspaceManager ;
17
15
import software .coley .recaf .util .threading .ThreadPoolFactory ;
18
16
import software .coley .recaf .util .threading .ThreadUtil ;
19
17
import software .coley .recaf .util .visitors .IllegalSignatureRemovingVisitor ;
22
20
import software .coley .recaf .workspace .model .resource .WorkspaceResource ;
23
21
24
22
import java .util .Collection ;
25
- import java .util .Objects ;
26
23
import java .util .concurrent .ExecutorService ;
27
24
import java .util .stream .Stream ;
28
25
33
30
* @author Matt Coley
34
31
* @see MappingResults
35
32
*/
36
- @ WorkspaceScoped
37
- public class MappingApplier implements Service {
38
- public static final String SERVICE_ID = "mapping-applier" ;
39
- private static final ExecutorService applierThreadPool = ThreadPoolFactory .newFixedThreadPool (SERVICE_ID );
33
+ public class MappingApplier {
34
+ private static final ExecutorService applierThreadPool = ThreadPoolFactory .newFixedThreadPool (MappingApplierService .SERVICE_ID );
40
35
private final InheritanceGraph inheritanceGraph ;
41
36
private final AggregateMappingManager aggregateMappingManager ;
42
37
private final MappingListeners listeners ;
43
38
private final Workspace workspace ;
44
- private final MappingApplierConfig config ;
45
-
46
- @ Inject
47
- public MappingApplier (@ Nonnull MappingApplierConfig config ,
48
- @ Nonnull InheritanceGraphService graphService ,
49
- @ Nonnull AggregateMappingManager aggregateMappingManager ,
50
- @ Nonnull MappingListeners listeners ,
51
- @ Nonnull Workspace workspace ) {
52
- this .inheritanceGraph = Objects .requireNonNull (graphService .getCurrentWorkspaceInheritanceGraph (), "Graph not created" );
39
+
40
+ /**
41
+ * @param workspace
42
+ * Workspace to apply mappings in.
43
+ * @param inheritanceGraph
44
+ * Inheritance graph for the given workspace.
45
+ * @param listeners
46
+ * Application mapping listeners
47
+ * <i>(If the target workspace is the {@link WorkspaceManager#getCurrent() current one})</i>
48
+ * @param aggregateMappingManager
49
+ * Aggregate mappings for tracking applications in the current workspace
50
+ * <i>(If the target workspace is the {@link WorkspaceManager#getCurrent() current one})</i>
51
+ */
52
+ public MappingApplier (@ Nonnull Workspace workspace ,
53
+ @ Nonnull InheritanceGraph inheritanceGraph ,
54
+ @ Nullable MappingListeners listeners ,
55
+ @ Nullable AggregateMappingManager aggregateMappingManager ) {
56
+ this .inheritanceGraph = inheritanceGraph ;
53
57
this .aggregateMappingManager = aggregateMappingManager ;
54
58
this .listeners = listeners ;
55
59
this .workspace = workspace ;
56
- this .config = config ;
57
60
}
58
61
59
62
/**
@@ -76,8 +79,10 @@ public MappingResults applyToClasses(@Nonnull Mappings mappings,
76
79
@ Nonnull JvmClassBundle bundle ,
77
80
@ Nonnull Collection <JvmClassInfo > classes ) {
78
81
mappings = enrich (mappings );
79
- MappingResults results = new MappingResults (mappings , listeners .createBundledMappingApplicationListener ())
80
- .withAggregateManager (aggregateMappingManager );
82
+ MappingApplicationListener listener = listeners == null ? null : listeners .createBundledMappingApplicationListener ();
83
+ MappingResults results = new MappingResults (mappings , listener );
84
+ if (aggregateMappingManager != null )
85
+ results .withAggregateManager (aggregateMappingManager );
81
86
82
87
// Apply mappings to the provided classes, collecting into the results model.
83
88
Mappings finalMappings = mappings ;
@@ -101,14 +106,15 @@ public MappingResults applyToClasses(@Nonnull Mappings mappings,
101
106
@ Nonnull
102
107
public MappingResults applyToPrimaryResource (@ Nonnull Mappings mappings ) {
103
108
mappings = enrich (mappings );
104
- WorkspaceResource resource = workspace . getPrimaryResource ();
105
-
106
- MappingResults results = new MappingResults ( mappings , listeners . createBundledMappingApplicationListener () )
107
- .withAggregateManager (aggregateMappingManager );
109
+ MappingApplicationListener listener = listeners == null ? null : listeners . createBundledMappingApplicationListener ();
110
+ MappingResults results = new MappingResults ( mappings , listener );
111
+ if ( aggregateMappingManager != null )
112
+ results .withAggregateManager (aggregateMappingManager );
108
113
109
114
// Apply mappings to all classes in the primary resource, collecting into the results model.
110
115
Mappings finalMappings = mappings ;
111
116
ExecutorService service = ThreadUtil .phasingService (applierThreadPool );
117
+ WorkspaceResource resource = workspace .getPrimaryResource ();
112
118
Stream .concat (resource .jvmClassBundleStream (), resource .versionedJvmClassBundleStream ()).forEach (bundle -> {
113
119
bundle .forEach (classInfo -> {
114
120
service .execute (() -> dumpIntoResults (results , workspace , resource , bundle , classInfo , finalMappings ));
@@ -199,16 +205,4 @@ private static void dumpIntoResults(@Nonnull MappingResults results,
199
205
results .add (workspace , resource , bundle , classInfo , updatedInfo );
200
206
}
201
207
}
202
-
203
- @ Nonnull
204
- @ Override
205
- public String getServiceId () {
206
- return SERVICE_ID ;
207
- }
208
-
209
- @ Nonnull
210
- @ Override
211
- public MappingApplierConfig getServiceConfig () {
212
- return config ;
213
- }
214
208
}
0 commit comments