diff --git a/recaf-core/src/main/java/software/coley/recaf/services/mapping/MappingApplier.java b/recaf-core/src/main/java/software/coley/recaf/services/mapping/MappingApplier.java index 260d5564b..285c22368 100644 --- a/recaf-core/src/main/java/software/coley/recaf/services/mapping/MappingApplier.java +++ b/recaf-core/src/main/java/software/coley/recaf/services/mapping/MappingApplier.java @@ -1,19 +1,17 @@ package software.coley.recaf.services.mapping; import jakarta.annotation.Nonnull; -import jakarta.inject.Inject; +import jakarta.annotation.Nullable; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassWriter; -import software.coley.recaf.cdi.WorkspaceScoped; import software.coley.recaf.info.JvmClassInfo; import software.coley.recaf.info.properties.builtin.HasMappedReferenceProperty; import software.coley.recaf.info.properties.builtin.OriginalClassNameProperty; import software.coley.recaf.info.properties.builtin.RemapOriginTaskProperty; -import software.coley.recaf.services.Service; import software.coley.recaf.services.inheritance.InheritanceGraph; -import software.coley.recaf.services.inheritance.InheritanceGraphService; import software.coley.recaf.services.mapping.aggregate.AggregateMappingManager; +import software.coley.recaf.services.workspace.WorkspaceManager; import software.coley.recaf.util.threading.ThreadPoolFactory; import software.coley.recaf.util.threading.ThreadUtil; import software.coley.recaf.util.visitors.IllegalSignatureRemovingVisitor; @@ -22,7 +20,6 @@ import software.coley.recaf.workspace.model.resource.WorkspaceResource; import java.util.Collection; -import java.util.Objects; import java.util.concurrent.ExecutorService; import java.util.stream.Stream; @@ -33,27 +30,33 @@ * @author Matt Coley * @see MappingResults */ -@WorkspaceScoped -public class MappingApplier implements Service { - public static final String SERVICE_ID = "mapping-applier"; - private static final ExecutorService applierThreadPool = ThreadPoolFactory.newFixedThreadPool(SERVICE_ID); +public class MappingApplier { + private static final ExecutorService applierThreadPool = ThreadPoolFactory.newFixedThreadPool(MappingApplierService.SERVICE_ID); private final InheritanceGraph inheritanceGraph; private final AggregateMappingManager aggregateMappingManager; private final MappingListeners listeners; private final Workspace workspace; - private final MappingApplierConfig config; - - @Inject - public MappingApplier(@Nonnull MappingApplierConfig config, - @Nonnull InheritanceGraphService graphService, - @Nonnull AggregateMappingManager aggregateMappingManager, - @Nonnull MappingListeners listeners, - @Nonnull Workspace workspace) { - this.inheritanceGraph = Objects.requireNonNull(graphService.getCurrentWorkspaceInheritanceGraph(), "Graph not created"); + + /** + * @param workspace + * Workspace to apply mappings in. + * @param inheritanceGraph + * Inheritance graph for the given workspace. + * @param listeners + * Application mapping listeners + * (If the target workspace is the {@link WorkspaceManager#getCurrent() current one}) + * @param aggregateMappingManager + * Aggregate mappings for tracking applications in the current workspace + * (If the target workspace is the {@link WorkspaceManager#getCurrent() current one}) + */ + public MappingApplier(@Nonnull Workspace workspace, + @Nonnull InheritanceGraph inheritanceGraph, + @Nullable MappingListeners listeners, + @Nullable AggregateMappingManager aggregateMappingManager) { + this.inheritanceGraph = inheritanceGraph; this.aggregateMappingManager = aggregateMappingManager; this.listeners = listeners; this.workspace = workspace; - this.config = config; } /** @@ -76,8 +79,10 @@ public MappingResults applyToClasses(@Nonnull Mappings mappings, @Nonnull JvmClassBundle bundle, @Nonnull Collection classes) { mappings = enrich(mappings); - MappingResults results = new MappingResults(mappings, listeners.createBundledMappingApplicationListener()) - .withAggregateManager(aggregateMappingManager); + MappingApplicationListener listener = listeners == null ? null : listeners.createBundledMappingApplicationListener(); + MappingResults results = new MappingResults(mappings, listener); + if (aggregateMappingManager != null) + results.withAggregateManager(aggregateMappingManager); // Apply mappings to the provided classes, collecting into the results model. Mappings finalMappings = mappings; @@ -101,14 +106,15 @@ public MappingResults applyToClasses(@Nonnull Mappings mappings, @Nonnull public MappingResults applyToPrimaryResource(@Nonnull Mappings mappings) { mappings = enrich(mappings); - WorkspaceResource resource = workspace.getPrimaryResource(); - - MappingResults results = new MappingResults(mappings, listeners.createBundledMappingApplicationListener()) - .withAggregateManager(aggregateMappingManager); + MappingApplicationListener listener = listeners == null ? null : listeners.createBundledMappingApplicationListener(); + MappingResults results = new MappingResults(mappings, listener); + if (aggregateMappingManager != null) + results.withAggregateManager(aggregateMappingManager); // Apply mappings to all classes in the primary resource, collecting into the results model. Mappings finalMappings = mappings; ExecutorService service = ThreadUtil.phasingService(applierThreadPool); + WorkspaceResource resource = workspace.getPrimaryResource(); Stream.concat(resource.jvmClassBundleStream(), resource.versionedJvmClassBundleStream()).forEach(bundle -> { bundle.forEach(classInfo -> { service.execute(() -> dumpIntoResults(results, workspace, resource, bundle, classInfo, finalMappings)); @@ -199,16 +205,4 @@ private static void dumpIntoResults(@Nonnull MappingResults results, results.add(workspace, resource, bundle, classInfo, updatedInfo); } } - - @Nonnull - @Override - public String getServiceId() { - return SERVICE_ID; - } - - @Nonnull - @Override - public MappingApplierConfig getServiceConfig() { - return config; - } } diff --git a/recaf-core/src/main/java/software/coley/recaf/services/mapping/MappingApplierConfig.java b/recaf-core/src/main/java/software/coley/recaf/services/mapping/MappingApplierConfig.java index d17011245..b5b231729 100644 --- a/recaf-core/src/main/java/software/coley/recaf/services/mapping/MappingApplierConfig.java +++ b/recaf-core/src/main/java/software/coley/recaf/services/mapping/MappingApplierConfig.java @@ -7,7 +7,7 @@ import software.coley.recaf.services.ServiceConfig; /** - * Config for {@link MappingApplier} + * Config for {@link MappingApplierService} * * @author Matt Coley */ @@ -15,6 +15,6 @@ public class MappingApplierConfig extends BasicConfigContainer implements ServiceConfig { @Inject public MappingApplierConfig() { - super(ConfigGroups.SERVICE_MAPPING, MappingApplier.SERVICE_ID + CONFIG_SUFFIX); + super(ConfigGroups.SERVICE_MAPPING, MappingApplierService.SERVICE_ID + CONFIG_SUFFIX); } } \ No newline at end of file diff --git a/recaf-core/src/main/java/software/coley/recaf/services/mapping/MappingApplierService.java b/recaf-core/src/main/java/software/coley/recaf/services/mapping/MappingApplierService.java new file mode 100644 index 000000000..eb5215729 --- /dev/null +++ b/recaf-core/src/main/java/software/coley/recaf/services/mapping/MappingApplierService.java @@ -0,0 +1,85 @@ +package software.coley.recaf.services.mapping; + +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import software.coley.recaf.services.Service; +import software.coley.recaf.services.inheritance.InheritanceGraph; +import software.coley.recaf.services.inheritance.InheritanceGraphService; +import software.coley.recaf.services.mapping.aggregate.AggregateMappingManager; +import software.coley.recaf.services.workspace.WorkspaceManager; +import software.coley.recaf.util.threading.ThreadPoolFactory; +import software.coley.recaf.workspace.model.Workspace; + +import java.util.Objects; +import java.util.concurrent.ExecutorService; + +/** + * Service offering the creation of {@link MappingApplier mapping appliers} for workspaces. + * + * @author Matt Coley + * @see MappingApplier + */ +@ApplicationScoped +public class MappingApplierService implements Service { + public static final String SERVICE_ID = "mapping-applier"; + private static final ExecutorService applierThreadPool = ThreadPoolFactory.newFixedThreadPool(SERVICE_ID); + private final InheritanceGraphService inheritanceGraphService; + private final AggregateMappingManager aggregateMappingManager; + private final MappingListeners listeners; + private final WorkspaceManager workspaceManager; + private final MappingApplierConfig config; + + @Inject + public MappingApplierService(@Nonnull MappingApplierConfig config, + @Nonnull InheritanceGraphService inheritanceGraphService, + @Nonnull AggregateMappingManager aggregateMappingManager, + @Nonnull MappingListeners listeners, + @Nonnull WorkspaceManager workspaceManager) { + this.inheritanceGraphService = inheritanceGraphService; + this.aggregateMappingManager = aggregateMappingManager; + this.listeners = listeners; + this.workspaceManager = workspaceManager; + this.config = config; + } + + /** + * @param workspace + * Workspace to apply mappings in. + * + * @return Applier for the given workspace. + */ + @Nonnull + public MappingApplier inWorkspace(@Nonnull Workspace workspace) { + if (workspace == workspaceManager.getCurrent()) + return Objects.requireNonNull(inCurrentWorkspace(), "Failed to access current workspace for mapping application"); + return new MappingApplier(workspace, inheritanceGraphService.newInheritanceGraph(workspace), null, null); + } + + /** + * @return Applier for the current workspace, or {@code null} if no workspace is open. + */ + @Nullable + public MappingApplier inCurrentWorkspace() { + Workspace workspace = workspaceManager.getCurrent(); + if (workspace == null) + return null; + InheritanceGraph currentWorkspaceInheritanceGraph = inheritanceGraphService.getCurrentWorkspaceInheritanceGraph(); + if (currentWorkspaceInheritanceGraph == null) + return null; + return new MappingApplier(workspace, currentWorkspaceInheritanceGraph, listeners, aggregateMappingManager); + } + + @Nonnull + @Override + public String getServiceId() { + return SERVICE_ID; + } + + @Nonnull + @Override + public MappingApplierConfig getServiceConfig() { + return config; + } +} diff --git a/recaf-core/src/test/java/software/coley/recaf/services/comment/CommentManagerTest.java b/recaf-core/src/test/java/software/coley/recaf/services/comment/CommentManagerTest.java index 4e6d6a55b..d2b0db612 100644 --- a/recaf-core/src/test/java/software/coley/recaf/services/comment/CommentManagerTest.java +++ b/recaf-core/src/test/java/software/coley/recaf/services/comment/CommentManagerTest.java @@ -1,12 +1,16 @@ package software.coley.recaf.services.comment; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import software.coley.recaf.info.JvmClassInfo; import software.coley.recaf.path.ClassPathNode; import software.coley.recaf.services.decompile.DecompileResult; import software.coley.recaf.services.decompile.DecompilerManager; import software.coley.recaf.services.mapping.IntermediateMappings; -import software.coley.recaf.services.mapping.MappingApplier; +import software.coley.recaf.services.mapping.MappingApplierService; import software.coley.recaf.services.mapping.MappingResults; import software.coley.recaf.services.workspace.WorkspaceManager; import software.coley.recaf.test.TestBase; @@ -26,7 +30,7 @@ class CommentManagerTest extends TestBase { static CommentManager commentManager; static CommentManagerConfig commentManagerConfig; static DecompilerManager decompilerManager; - static MappingApplier mappingApplier; + static MappingApplierService mappingApplierService; static JvmClassInfo classToDecompile; static Workspace workspace; @@ -41,7 +45,7 @@ static void setup() throws IOException { commentManager = recaf.get(CommentManager.class); commentManagerConfig = recaf.get(CommentManagerConfig.class); decompilerManager = recaf.get(DecompilerManager.class); - mappingApplier = recaf.get(MappingApplier.class); + mappingApplierService = recaf.get(MappingApplierService.class); } @Test @@ -97,7 +101,7 @@ void testCommentsGetMigratedAfterRemapping() { mappings.addMethod(classToDecompile.getName(), "()V", "methodWithLocalVariables", "fizz"); // Apply the mappings - MappingResults results = mappingApplier.applyToPrimaryResource(mappings); + MappingResults results = mappingApplierService.inCurrentWorkspace().applyToPrimaryResource(mappings); ClassPathNode postMappingPath = results.getPostMappingPath(classToDecompile.getName()); assertNotNull(postMappingPath, "Post-mapping path does not exist in mapping results"); results.apply(); diff --git a/recaf-core/src/test/java/software/coley/recaf/services/inheritance/InheritanceAndRenamingTest.java b/recaf-core/src/test/java/software/coley/recaf/services/inheritance/InheritanceAndRenamingTest.java index 255a2eaf7..6c4bc20f5 100644 --- a/recaf-core/src/test/java/software/coley/recaf/services/inheritance/InheritanceAndRenamingTest.java +++ b/recaf-core/src/test/java/software/coley/recaf/services/inheritance/InheritanceAndRenamingTest.java @@ -7,6 +7,7 @@ import software.coley.recaf.info.builder.JvmClassInfoBuilder; import software.coley.recaf.services.mapping.IntermediateMappings; import software.coley.recaf.services.mapping.MappingApplier; +import software.coley.recaf.services.mapping.MappingApplierService; import software.coley.recaf.services.mapping.MappingResults; import software.coley.recaf.test.TestBase; import software.coley.recaf.test.TestClassUtils; @@ -26,7 +27,7 @@ class InheritanceAndRenamingTest extends TestBase { static Workspace workspace; static InheritanceGraph inheritanceGraph; - static MappingApplier mappingApplier; + static MappingApplierService mappingApplierService; static JvmClassInfo[] generatedClasses; @BeforeAll @@ -48,7 +49,7 @@ static void setup() { inheritanceGraph.toString(); // Force immediate init. // Get mapping applier - mappingApplier = recaf.get(MappingApplier.class); + mappingApplierService = recaf.get(MappingApplierService.class); } @Test @@ -64,7 +65,7 @@ void test() { IntermediateMappings mappings = new IntermediateMappings(); for (int i = 1; i <= 5; i++) mappings.addClass("I" + i, "R" + i); - MappingResults results = mappingApplier.applyToPrimaryResource(mappings); + MappingResults results = mappingApplierService.inCurrentWorkspace().applyToPrimaryResource(mappings); results.apply(); // Very old classes are removed from the graph diff --git a/recaf-core/src/test/java/software/coley/recaf/services/mapping/MappingApplierTest.java b/recaf-core/src/test/java/software/coley/recaf/services/mapping/MappingApplierTest.java index 57468c403..b7a8b59cf 100644 --- a/recaf-core/src/test/java/software/coley/recaf/services/mapping/MappingApplierTest.java +++ b/recaf-core/src/test/java/software/coley/recaf/services/mapping/MappingApplierTest.java @@ -43,7 +43,7 @@ class MappingApplierTest extends TestBase { WorkspaceResource resource; AggregateMappingManager aggregateMappingManager; InheritanceGraph inheritanceGraph; - MappingApplier mappingApplier; + MappingApplierService mappingApplierService; @BeforeAll static void setupGenerator() { @@ -74,7 +74,7 @@ void prepareWorkspace() throws IOException { aggregateMappingManager = recaf.get(AggregateMappingManager.class); inheritanceGraph = recaf.get(InheritanceGraphService.class).getCurrentWorkspaceInheritanceGraph(); mappingGenerator = recaf.get(MappingGenerator.class); - mappingApplier = recaf.get(MappingApplier.class); + mappingApplierService = recaf.get(MappingApplierService.class); } @Test @@ -105,7 +105,7 @@ public boolean shouldMapMethod(@Nonnull ClassInfo owner, @Nonnull MethodMember m }); // Preview the mapping operation - MappingResults results = mappingApplier.applyToPrimaryResource(mappings); + MappingResults results = mappingApplierService.inCurrentWorkspace().applyToPrimaryResource(mappings); // The supplier class we define should be remapped. // The runner class (AnonymousLambda) itself should not be remapped, but should be updated to point to @@ -160,7 +160,7 @@ public boolean shouldMapMethod(@Nonnull ClassInfo owner, @Nonnull MethodMember m }); // Preview the mapping operation - MappingResults results = mappingApplier.applyToPrimaryResource(mappings); + MappingResults results = mappingApplierService.inCurrentWorkspace().applyToPrimaryResource(mappings); // The enum class we define should be remapped. // The runner class (DummyEnumPrinter) itself should not be remapped, but should be updated to point to @@ -199,7 +199,7 @@ public boolean shouldMapClass(@Nonnull ClassInfo info) { }); // Preview the mapping operation - MappingResults results = mappingApplier.applyToPrimaryResource(mappings); + MappingResults results = mappingApplierService.inCurrentWorkspace().applyToPrimaryResource(mappings); // The annotation class we define should be remapped. // The user class (ClassWithAnnotation) itself should not be remapped, @@ -254,7 +254,7 @@ public boolean shouldMapMethod(@Nonnull ClassInfo owner, @Nonnull MethodMember m }); // Preview the mapping operation - MappingResults results = mappingApplier.applyToPrimaryResource(mappings); + MappingResults results = mappingApplierService.inCurrentWorkspace().applyToPrimaryResource(mappings); assertNotNull(mappings.getMappedClassName(overlapInterfaceAName), "OverlapInterfaceA should be remapped"); assertNotNull(mappings.getMappedClassName(overlapInterfaceBName), "OverlapInterfaceB should be remapped"); diff --git a/recaf-ui/src/main/java/software/coley/recaf/services/navigation/Actions.java b/recaf-ui/src/main/java/software/coley/recaf/services/navigation/Actions.java index 9eebf5365..3fb79b669 100644 --- a/recaf-ui/src/main/java/software/coley/recaf/services/navigation/Actions.java +++ b/recaf-ui/src/main/java/software/coley/recaf/services/navigation/Actions.java @@ -41,6 +41,7 @@ import software.coley.recaf.services.inheritance.InheritanceGraph; import software.coley.recaf.services.mapping.IntermediateMappings; import software.coley.recaf.services.mapping.MappingApplier; +import software.coley.recaf.services.mapping.MappingApplierService; import software.coley.recaf.services.mapping.MappingResults; import software.coley.recaf.services.window.WindowFactory; import software.coley.recaf.ui.control.FontIconView; @@ -130,8 +131,8 @@ public class Actions implements Service { private final IconProviderService iconService; private final CellConfigurationService cellConfigurationService; private final PathExportingManager pathExportingManager; + private final MappingApplierService mappingApplierService; private final Instance inheritanceGraphProvider; - private final Instance applierProvider; private final Instance jvmPaneProvider; private final Instance androidPaneProvider; private final Instance binaryXmlPaneProvider; @@ -158,6 +159,7 @@ public Actions(@Nonnull ActionsConfig config, @Nonnull IconProviderService iconService, @Nonnull CellConfigurationService cellConfigurationService, @Nonnull PathExportingManager pathExportingManager, + @Nonnull MappingApplierService mappingApplierService, @Nonnull Instance inheritanceGraphProvider, @Nonnull Instance applierProvider, @Nonnull Instance jvmPaneProvider, @@ -183,8 +185,8 @@ public Actions(@Nonnull ActionsConfig config, this.iconService = iconService; this.cellConfigurationService = cellConfigurationService; this.pathExportingManager = pathExportingManager; + this.mappingApplierService = mappingApplierService; this.inheritanceGraphProvider = inheritanceGraphProvider; - this.applierProvider = applierProvider; this.jvmPaneProvider = jvmPaneProvider; this.androidPaneProvider = androidPaneProvider; this.binaryXmlPaneProvider = binaryXmlPaneProvider; @@ -795,7 +797,7 @@ public void moveClass(@Nonnull Workspace workspace, } // Apply the mappings. - MappingApplier applier = applierProvider.get(); + MappingApplier applier = mappingApplierService.inWorkspace(workspace); MappingResults results = applier.applyToPrimaryResource(mappings); results.apply(); }) @@ -889,7 +891,7 @@ public void movePackage(@Nonnull Workspace workspace, } // Apply the mappings. - MappingApplier applier = applierProvider.get(); + MappingApplier applier = mappingApplierService.inWorkspace(workspace); MappingResults results = applier.applyToPrimaryResource(mappings); results.apply(); }).withTitle(Lang.getBinding("dialog.title.move-package")) @@ -1033,7 +1035,7 @@ public void renameClass(@Nonnull Workspace workspace, } // Apply the mappings. - MappingApplier applier = applierProvider.get(); + MappingApplier applier = mappingApplierService.inWorkspace(workspace); MappingResults results = applier.applyToPrimaryResource(mappings); results.apply(); }; @@ -1102,7 +1104,7 @@ public void renameField(@Nonnull Workspace workspace, mappings.addField(declaringClass.getName(), field.getDescriptor(), originalName, newName); // Apply the mappings. - MappingApplier applier = applierProvider.get(); + MappingApplier applier = mappingApplierService.inWorkspace(workspace); MappingResults results = applier.applyToPrimaryResource(mappings); results.apply(); }; @@ -1171,7 +1173,7 @@ public void renameMethod(@Nonnull Workspace workspace, mappings.addMethod(declaringClass.getName(), method.getDescriptor(), originalName, newName); // Apply the mappings. - MappingApplier applier = applierProvider.get(); + MappingApplier applier = mappingApplierService.inWorkspace(workspace); MappingResults results = applier.applyToPrimaryResource(mappings); results.apply(); }; @@ -1359,7 +1361,7 @@ public void renamePackage(@Nonnull Workspace workspace, // Apply mappings to create copies of the affected classes, using the provided name. // Then dump the mapped classes into bundle. - MappingApplier applier = applierProvider.get(); + MappingApplier applier = mappingApplierService.inWorkspace(workspace); MappingResults results = applier.applyToPrimaryResource(mappings); results.apply(); }).withInitialPathName(packageName) @@ -1406,7 +1408,7 @@ public void copyClass(@Nonnull Workspace workspace, // Apply mappings to create copies of the affected classes, using the provided name. // Then dump the mapped classes into bundle. - MappingApplier applier = applierProvider.get(); + MappingApplier applier = mappingApplierService.inWorkspace(workspace); MappingResults results = applier.applyToClasses(mappings, resource, bundle, classesToCopy); for (ClassPathNode mappedClassPath : results.getPostMappingPaths().values()) { JvmClassInfo mappedClass = mappedClassPath.getValue().asJvmClass(); @@ -1551,7 +1553,7 @@ public void copyPackage(@Nonnull Workspace workspace, // Apply mappings to create copies of the affected classes, using the provided name. // Then dump the mapped classes into bundle. - MappingApplier applier = applierProvider.get(); + MappingApplier applier = mappingApplierService.inWorkspace(workspace); MappingResults results = applier.applyToClasses(mappings, resource, bundle, classesToCopy); for (ClassPathNode mappedClassPath : results.getPostMappingPaths().values()) { JvmClassInfo mappedClass = mappedClassPath.getValue().asJvmClass(); diff --git a/recaf-ui/src/main/java/software/coley/recaf/ui/menubar/MappingMenu.java b/recaf-ui/src/main/java/software/coley/recaf/ui/menubar/MappingMenu.java index dc333c8fb..b0bd34991 100644 --- a/recaf-ui/src/main/java/software/coley/recaf/ui/menubar/MappingMenu.java +++ b/recaf-ui/src/main/java/software/coley/recaf/ui/menubar/MappingMenu.java @@ -13,6 +13,7 @@ import software.coley.recaf.analytics.logging.Logging; import software.coley.recaf.services.mapping.IntermediateMappings; import software.coley.recaf.services.mapping.MappingApplier; +import software.coley.recaf.services.mapping.MappingApplierService; import software.coley.recaf.services.mapping.MappingResults; import software.coley.recaf.services.mapping.aggregate.AggregateMappingManager; import software.coley.recaf.services.mapping.aggregate.AggregatedMappings; @@ -55,7 +56,7 @@ public MappingMenu(@Nonnull WindowManager windowManager, @Nonnull WorkspaceManager workspaceManager, @Nonnull AggregateMappingManager aggregateMappingManager, @Nonnull MappingFormatManager formatManager, - @Nonnull MappingApplier mappingApplier, + @Nonnull MappingApplierService mappingApplierService, @Nonnull Instance generatorPaneInstance, @Nonnull RecentFilesConfig recentFiles) { super(workspaceManager); @@ -88,7 +89,7 @@ public MappingMenu(@Nonnull WindowManager windowManager, IntermediateMappings parsedMappings = format.parse(mappingsText); logger.info("Loaded mappings from {} in {} format", file.getName(), formatName); - MappingResults results = mappingApplier.applyToPrimaryResource(parsedMappings); + MappingResults results = mappingApplierService.inCurrentWorkspace().applyToPrimaryResource(parsedMappings); results.apply(); logger.info("Applied mappings from {} - Updated {} classes", file.getName(), results.getPostMappingPaths().size()); } catch (Exception ex) { diff --git a/recaf-ui/src/main/java/software/coley/recaf/ui/pane/MappingGeneratorPane.java b/recaf-ui/src/main/java/software/coley/recaf/ui/pane/MappingGeneratorPane.java index 71ebf7dc5..db9583f9a 100644 --- a/recaf-ui/src/main/java/software/coley/recaf/ui/pane/MappingGeneratorPane.java +++ b/recaf-ui/src/main/java/software/coley/recaf/ui/pane/MappingGeneratorPane.java @@ -53,6 +53,7 @@ import software.coley.recaf.services.inheritance.InheritanceGraphService; import software.coley.recaf.services.mapping.IntermediateMappings; import software.coley.recaf.services.mapping.MappingApplier; +import software.coley.recaf.services.mapping.MappingApplierService; import software.coley.recaf.services.mapping.MappingResults; import software.coley.recaf.services.mapping.Mappings; import software.coley.recaf.services.mapping.aggregate.AggregateMappingManager; @@ -121,7 +122,7 @@ public class MappingGeneratorPane extends StackPane { private final ConfigComponentManager componentManager; private final InheritanceGraph inheritanceGraph; private final ModalPane modal = new ModalPane(); - private final MappingApplier mappingApplier; + private final MappingApplierService mappingApplierService; private final Pane previewGroup; @Inject @@ -132,7 +133,7 @@ public MappingGeneratorPane(@Nonnull Workspace workspace, @Nonnull ConfigComponentManager componentManager, @Nonnull InheritanceGraphService graphService, @Nonnull AggregateMappingManager aggregateMappingManager, - @Nonnull MappingApplier mappingApplier, + @Nonnull MappingApplierService mappingApplierService, @Nonnull Instance searchBarProvider) { this.workspace = workspace; @@ -141,7 +142,7 @@ public MappingGeneratorPane(@Nonnull Workspace workspace, this.mappingGenerator = mappingGenerator; this.componentManager = componentManager; this.inheritanceGraph = Objects.requireNonNull(graphService.getCurrentWorkspaceInheritanceGraph(), "Graph not created"); - this.mappingApplier = mappingApplier; + this.mappingApplierService = mappingApplierService; // Cache text matchers. stringPredicates = stringPredicateProvider.getBiStringMatchers().keySet().stream().sorted().toList(); @@ -256,15 +257,19 @@ public void generate() { private void apply() { Mappings mappings = mappingsToApply.get(); + if (mappings == null) + return; + + MappingApplier applier = mappingApplierService.inCurrentWorkspace(); + if (applier == null) + return; // Apply the mappings - if (mappings != null) { - MappingResults results = mappingApplier.applyToPrimaryResource(mappings); - results.apply(); + MappingResults results = applier.applyToPrimaryResource(mappings); + results.apply(); - // Clear property now that the mappings have been applied - mappingsToApply.set(null); - } + // Clear property now that the mappings have been applied + mappingsToApply.set(null); } @Nonnull