Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow different mapping for reflection #3470

Merged
merged 8 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/launch/java/org/spongepowered/common/launch/Launch.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.spongepowered.api.plugin.PluginManager;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.common.applaunch.plugin.PluginPlatform;
import org.spongepowered.common.launch.mapping.SpongeMappingManager;
import org.spongepowered.common.launch.plugin.SpongePluginManager;
import org.spongepowered.plugin.PluginContainer;
import java.util.ArrayList;
Expand Down Expand Up @@ -75,6 +76,8 @@ public final String id() {

public abstract SpongePluginManager pluginManager();

public abstract SpongeMappingManager mappingManager();

public final Logger logger() {
return this.logger;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.launch.mapping;

/**
* A mapping manager provide the necessary tool to convert
* from Mojang mapping to the current runtime mapping. This
* is intended to facility the reflection across different
* mapping.
*/
public interface SpongeMappingManager {
String toRuntimeClassName(String srcName);

String toRuntimeFieldName(Class<?> owner, String srcName);

String toRuntimeMethodName(Class<?> owner, String srcName, Class<?> ...params);
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static boolean doesMethodExist(
final String methodName,
final Class<?>[] methodParameters
) {
final String targetMethodForEnvironment = Launch.instance().developerEnvironment() ? methodName : methodName;
final String targetMethodForEnvironment = Launch.instance().mappingManager().toRuntimeMethodName(targetClass, methodName, methodParameters);
try {
final Class<?> declaringClass = targetClass.getMethod(targetMethodForEnvironment, methodParameters).getDeclaringClass();
return !ignoredClass.equals(declaringClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
import org.spongepowered.common.inject.SpongeCommonModule;
import org.spongepowered.common.inject.SpongeModule;
import org.spongepowered.common.launch.Launch;
import org.spongepowered.common.launch.mapping.SpongeMappingManager;
import org.spongepowered.common.launch.plugin.DummyPluginContainer;
import org.spongepowered.plugin.PluginContainer;
import org.spongepowered.plugin.jvm.locator.JVMPluginResourceLocatorService;
import org.spongepowered.plugin.metadata.PluginMetadata;
import org.spongepowered.plugin.metadata.util.PluginMetadataHelper;
import org.spongepowered.vanilla.applaunch.plugin.VanillaPluginPlatform;
import org.spongepowered.vanilla.launch.inject.SpongeVanillaModule;
import org.spongepowered.vanilla.launch.mapping.VanillaMappingManager;
import org.spongepowered.vanilla.launch.plugin.VanillaPluginManager;

import java.io.IOException;
Expand All @@ -54,12 +56,14 @@ public abstract class VanillaLaunch extends Launch {

private final Stage injectionStage;
private final VanillaPluginManager pluginManager;
private final VanillaMappingManager mappingManager;
private PluginContainer vanillaPlugin;

protected VanillaLaunch(final VanillaPluginPlatform pluginPlatform, final Stage injectionStage) {
super(pluginPlatform);
this.injectionStage = injectionStage;
this.pluginManager = new VanillaPluginManager();
this.mappingManager = new VanillaMappingManager();
}

@Override
Expand Down Expand Up @@ -95,6 +99,11 @@ public final VanillaPluginManager pluginManager() {
return this.pluginManager;
}

@Override
public SpongeMappingManager mappingManager() {
return this.mappingManager;
}

@Override
public Injector createInjector() {
final List<Module> modules = Lists.newArrayList(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.vanilla.launch.mapping;

import org.spongepowered.common.launch.mapping.SpongeMappingManager;

public class VanillaMappingManager implements SpongeMappingManager {
LogicFan marked this conversation as resolved.
Show resolved Hide resolved
@Override
public String toRuntimeClassName(String srcName) {
LogicFan marked this conversation as resolved.
Show resolved Hide resolved
return srcName;
}

@Override
public String toRuntimeFieldName(Class<?> owner, String srcName) {
return srcName;
LogicFan marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public String toRuntimeMethodName(Class<?> owner, String srcName, Class<?>... params) {
return srcName;
}
}