Remove agent from further handling if hard fail when accepting container

This commit is contained in:
Mumfrey committed 2019-11-21 18:07:07 +00:00
1 parent be3f944af1
commit c986828aff
8 files changed
+66 -31

No files matched your search

@@ -38,6 +38,29 @@ import org.spongepowered.asm.launch.platform.container.IContainerHandle;
*/
public interface IMixinPlatformAgent {
/**
* Result type returned from {@link IMixinPlatformAgent#accept}
*/
public enum AcceptResult {
/**
* The container was accepted
*/
ACCEPTED,
/**
* The container was rejected
*/
REJECTED,
/**
* The agent encountered an error and no further containers should be
* offered
*/
INVALID;
}
/**
* Accept and bind to a container handle. This method is called for agents
* hosted by {@link MixinContainer} and the agent should react accordingly.
@@ -47,11 +70,10 @@ public interface IMixinPlatformAgent {
*
* @param manager platform manager instance
* @param handle handle to container
* @return true if this agent can accept a container of the supplied type,
* false if the agent cannot handle the container (in which case it
* will be discarded)
* @return AcceptResult representing this agent's acceptance of the supplied
* container
*/
public abstract boolean accept(MixinPlatformManager manager, IContainerHandle handle);
public abstract AcceptResult accept(MixinPlatformManager manager, IContainerHandle handle);
/**
* Get the phase provider for this agent
@@ -28,6 +28,7 @@ import java.util.Collection;
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.util.Constants;
import org.spongepowered.asm.util.IConsumer;
/**
@@ -43,7 +44,10 @@ public interface IMixinPlatformServiceAgent extends IMixinPlatformAgent {
public abstract void init();
/**
* Attempt to determine the side name from the current environment
* Attempt to determine the side name from the current environment. Return
* <tt>null</tt> if the side name cannot be determined by this agent. Return
* side name or {@link Constants#SIDE_UNKNOWN} if the agent is able to
* determine the side.
*/
public abstract String getSideName();
@@ -26,11 +26,13 @@ package org.spongepowered.asm.launch.platform;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.launch.GlobalProperties;
import org.spongepowered.asm.launch.platform.IMixinPlatformAgent.AcceptResult;
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
import org.spongepowered.asm.service.MixinService;
@@ -59,22 +61,25 @@ public class MixinContainer {
public MixinContainer(MixinPlatformManager manager, IContainerHandle handle) {
this.handle = handle;
for (String agentClass : MixinContainer.agentClasses) {
for (Iterator<String> iter = MixinContainer.agentClasses.iterator(); iter.hasNext();) {
String agentClass = iter.next();
try {
@SuppressWarnings("unchecked")
Class<IMixinPlatformAgent> clazz = (Class<IMixinPlatformAgent>)Class.forName(agentClass);
String simpleName = clazz.getSimpleName();
String acceptAction = "rejected";
MixinContainer.logger.debug("Instancing new {} for {}", simpleName, this.handle);
IMixinPlatformAgent agent = clazz.newInstance();
if (agent.accept(manager, this.handle)) {
AcceptResult acceptAction = agent.accept(manager, this.handle);
if (acceptAction == AcceptResult.ACCEPTED) {
this.agents.add(agent);
acceptAction = "accepted";
} else if (acceptAction == AcceptResult.INVALID) {
iter.remove();
continue;
}
MixinContainer.logger.debug("{} {} container {}", simpleName, acceptAction, this.handle);
MixinContainer.logger.debug("{} {} container {}", simpleName, acceptAction.name().toLowerCase(), this.handle);
} catch (InstantiationException ex) {
Throwable cause = ex.getCause();
if (cause instanceof RuntimeException) {
@@ -56,10 +56,10 @@ public abstract class MixinPlatformAgentAbstract implements IMixinPlatformAgent
}
@Override
public boolean accept(MixinPlatformManager manager, IContainerHandle handle) {
public AcceptResult accept(MixinPlatformManager manager, IContainerHandle handle) {
this.manager = manager;
this.handle = handle;
return true;
return AcceptResult.ACCEPTED;
}
@Override