mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-19 16:29:45 +00:00
Add min compat and max compat to service, warn when exceeding max compat
This commit is contained in:
1 parent
b00992e411
commit
b8638b2340
6 files changed
+123
-13
No files matched your search
@@ -673,12 +673,17 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
public static final int NESTING = 4;
|
||||
|
||||
/**
|
||||
* Native nesting
|
||||
* Dynamic constants
|
||||
*/
|
||||
public static final int DYNAMIC_CONSTANTS = 8;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Default compatibility level to use if not specified by the service
|
||||
*/
|
||||
public static CompatibilityLevel DEFAULT = CompatibilityLevel.JAVA_6;
|
||||
|
||||
private final int ver;
|
||||
|
||||
private final int classVersion;
|
||||
@@ -693,11 +698,6 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
this.languageFeatures = languageFeatures;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void setMaxCompatibleLevel(CompatibilityLevel maxCompatibleLevel) {
|
||||
this.maxCompatibleLevel = maxCompatibleLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this compatibility level is supported in the current
|
||||
* environment
|
||||
@@ -746,6 +746,16 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
return level == null || this.ver >= level.ver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this level is less than the specified level
|
||||
*
|
||||
* @param level level to compare to
|
||||
* @return true if this level is less than the supplied level
|
||||
*/
|
||||
public boolean isLessThan(CompatibilityLevel level) {
|
||||
return level == null || this.ver < level.ver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this level can be elevated to the specified level
|
||||
*
|
||||
@@ -857,7 +867,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
/**
|
||||
* Current compatibility level
|
||||
*/
|
||||
private static CompatibilityLevel compatibility = Option.DEFAULT_COMPATIBILITY_LEVEL.<CompatibilityLevel>getEnumValue(CompatibilityLevel.JAVA_6);
|
||||
private static CompatibilityLevel compatibility;
|
||||
|
||||
/**
|
||||
* Show debug header info on first environment construction
|
||||
@@ -966,7 +976,8 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
printer.add("SpongePowered MIXIN%s", verbose ? " (Verbose debugging enabled)" : "").centre().hr();
|
||||
printer.kv("Code source", codeSource);
|
||||
printer.kv("Internal Version", version);
|
||||
printer.kv("Java Versions Supported", CompatibilityLevel.getSupportedVersions()).hr();
|
||||
printer.kv("Java Versions Supported", CompatibilityLevel.getSupportedVersions());
|
||||
printer.kv("Current Compatibility Level", MixinEnvironment.getCompatibilityLevel()).hr();
|
||||
printer.kv("Service Name", serviceName);
|
||||
printer.kv("Mixin Service Class", this.service.getClass().getName());
|
||||
printer.kv("Global Property Service Class", MixinService.getGlobalPropertyService().getClass().getName()).hr();
|
||||
@@ -1343,9 +1354,19 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
* Get the current compatibility level
|
||||
*/
|
||||
public static CompatibilityLevel getCompatibilityLevel() {
|
||||
if (MixinEnvironment.compatibility == null) {
|
||||
CompatibilityLevel minLevel = MixinEnvironment.getMinCompatibilityLevel();
|
||||
CompatibilityLevel optionLevel = Option.DEFAULT_COMPATIBILITY_LEVEL.<CompatibilityLevel>getEnumValue(minLevel);
|
||||
MixinEnvironment.compatibility = optionLevel.isAtLeast(minLevel) ? optionLevel : minLevel;
|
||||
}
|
||||
return MixinEnvironment.compatibility;
|
||||
}
|
||||
|
||||
private static CompatibilityLevel getMinCompatibilityLevel() {
|
||||
CompatibilityLevel minLevel = MixinService.getService().getMinCompatibilityLevel();
|
||||
return minLevel == null ? CompatibilityLevel.DEFAULT : minLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set desired compatibility level for the entire environment
|
||||
*
|
||||
@@ -1360,10 +1381,18 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
MixinEnvironment.logger.warn("MixinEnvironment::setCompatibilityLevel is deprecated and will be removed. Set level via config instead!");
|
||||
}
|
||||
|
||||
if (level != MixinEnvironment.compatibility && level.isAtLeast(MixinEnvironment.compatibility)) {
|
||||
CompatibilityLevel currentLevel = MixinEnvironment.getCompatibilityLevel();
|
||||
if (level != currentLevel && level.isAtLeast(currentLevel)) {
|
||||
if (!level.isSupported()) {
|
||||
throw new IllegalArgumentException("The requested compatibility level " + level + " could not be set. Level is not supported");
|
||||
}
|
||||
|
||||
IMixinService service = MixinService.getService();
|
||||
CompatibilityLevel maxLevel = service.getMaxCompatibilityLevel();
|
||||
if (maxLevel != null && maxLevel.isLessThan(level)) {
|
||||
MixinEnvironment.logger.warn("The requested compatibility level {} is higher than the level supported by the active subsystem '{}'"
|
||||
+ " which supports {}. This is not a supported configuration and instability may occur.", level, service.getName(), maxLevel);
|
||||
}
|
||||
|
||||
MixinEnvironment.compatibility = level;
|
||||
MixinEnvironment.logger.info("Compatibility level set to {}", level);
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.util.ReEntranceLock;
|
||||
|
||||
@@ -176,5 +177,25 @@ public interface IMixinService {
|
||||
* Get the detected side name for this environment
|
||||
*/
|
||||
public abstract String getSideName();
|
||||
|
||||
/**
|
||||
* Get the minimum compatibility level supported by this service. Can return
|
||||
* <tt>null</tt> if the service has no specific minimum compatibility level,
|
||||
* however if a value is returned, it will be used as the minimum
|
||||
* compatibility level and no lower levels will be supported.
|
||||
*
|
||||
* @return minimum supported {@link CompatibilityLevel} or null
|
||||
*/
|
||||
public abstract CompatibilityLevel getMinCompatibilityLevel();
|
||||
|
||||
/**
|
||||
* Get the maximum compatibility level supported by this service. Can return
|
||||
* <tt>null</tt> if the service has no specific maximum compatibility level.
|
||||
* If a value is returned, a warning will be raised if a configuration
|
||||
* attempts to se a higher compatibility level.
|
||||
*
|
||||
* @return minimum supported {@link CompatibilityLevel} or null
|
||||
*/
|
||||
public abstract CompatibilityLevel getMaxCompatibilityLevel();
|
||||
|
||||
}
|
||||
@@ -24,8 +24,10 @@
|
||||
*/
|
||||
package org.spongepowered.asm.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
@@ -33,6 +35,8 @@ import java.util.Set;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
/**
|
||||
* Provides access to the service layer which connects the mixin transformer to
|
||||
* a particular host environment. Host environments are implemented as services
|
||||
@@ -79,15 +83,17 @@ public final class MixinService {
|
||||
|
||||
private void runBootServices() {
|
||||
this.bootstrapServiceLoader = ServiceLoader.<IMixinServiceBootstrap>load(IMixinServiceBootstrap.class, this.getClass().getClassLoader());
|
||||
for (IMixinServiceBootstrap bootService : this.bootstrapServiceLoader) {
|
||||
Iterator<IMixinServiceBootstrap> iter = this.bootstrapServiceLoader.iterator();
|
||||
while (iter.hasNext()) {
|
||||
try {
|
||||
IMixinServiceBootstrap bootService = iter.next();
|
||||
bootService.bootstrap();
|
||||
this.bootedServices.add(bootService.getServiceClassName());
|
||||
} catch (ServiceInitialisationException ex) {
|
||||
// Expected if service cannot start
|
||||
MixinService.logger.debug("Mixin bootstrap service {} is not available: {}", bootService.getClass().getName(), ex.getMessage());
|
||||
MixinService.logger.error("Mixin bootstrap service {} is not available: {}", ex.getStackTrace()[0].getClassName(), ex.getMessage());
|
||||
} catch (Throwable th) {
|
||||
MixinService.logger.throwing(th);
|
||||
MixinService.logger.debug("Catching {}:{} initialising service", th.getClass().getName(), th.getMessage(), th);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,6 +130,7 @@ public final class MixinService {
|
||||
private IMixinService initService() {
|
||||
this.serviceLoader = ServiceLoader.<IMixinService>load(IMixinService.class, this.getClass().getClassLoader());
|
||||
Iterator<IMixinService> iter = this.serviceLoader.iterator();
|
||||
List<String> rejectedServices = new ArrayList<String>();
|
||||
while (iter.hasNext()) {
|
||||
try {
|
||||
IMixinService service = iter.next();
|
||||
@@ -133,13 +140,14 @@ public final class MixinService {
|
||||
if (service.isValid()) {
|
||||
return service;
|
||||
}
|
||||
rejectedServices.add(service.getName());
|
||||
} catch (ServiceConfigurationError serviceError) {
|
||||
// serviceError.printStackTrace();
|
||||
} catch (Throwable th) {
|
||||
// th.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new ServiceNotAvailableError("No mixin host service is available");
|
||||
throw new ServiceNotAvailableError("No mixin host service is available. Rejected services: " + Joiner.on(", ").join(rejectedServices));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.launch.platform.IMixinPlatformAgent;
|
||||
import org.spongepowered.asm.launch.platform.IMixinPlatformServiceAgent;
|
||||
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.IConsumer;
|
||||
@@ -71,19 +72,50 @@ public abstract class MixinServiceAbstract implements IMixinService {
|
||||
*/
|
||||
private String sideName;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IMixinService#prepare()
|
||||
*/
|
||||
@Override
|
||||
public void prepare() {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IMixinService#getInitialPhase()
|
||||
*/
|
||||
@Override
|
||||
public Phase getInitialPhase() {
|
||||
return Phase.PREINIT;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IMixinService
|
||||
* #getMinCompatibilityLevel()
|
||||
*/
|
||||
@Override
|
||||
public CompatibilityLevel getMinCompatibilityLevel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IMixinService
|
||||
* #getMaxCompatibilityLevel()
|
||||
*/
|
||||
@Override
|
||||
public CompatibilityLevel getMaxCompatibilityLevel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IMixinService#beginPhase()
|
||||
*/
|
||||
@Override
|
||||
public void beginPhase() {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IMixinService
|
||||
* #checkEnv(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void checkEnv(Object bootSource) {
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user