Auditing changes, report unapplied classes as errors, closes #114

This commit is contained in:
Mumfrey committed 2016-04-20 16:09:17 +01:00
1 parent 3ca55a3a5c
commit 505981e302
2 files changed
+68 -5

No files matched your search

@@ -0,0 +1,53 @@
/*
* This file is part of Mixin, 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.asm.mixin.audit;
import org.spongepowered.asm.mixin.MixinException;
/**
* Exception raised when a class was loaded before mixins were able to be
* applied.
*/
public class ClassAlreadyLoadedException extends MixinException {
private static final long serialVersionUID = 1L;
public ClassAlreadyLoadedException(String message) {
super(message);
}
public ClassAlreadyLoadedException(Throwable cause) {
super(cause);
}
public ClassAlreadyLoadedException(String message, Throwable cause) {
super(message, cause);
}
}
@@ -51,6 +51,7 @@ import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.mixin.MixinException;
import org.spongepowered.asm.mixin.audit.ClassAlreadyLoadedException;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinErrorHandler;
import org.spongepowered.asm.mixin.extensibility.IMixinErrorHandler.ErrorAction;
@@ -363,13 +364,22 @@ public class MixinTransformer extends TreeTransformer {
for (MixinConfig config : this.configs) {
unhandled.addAll(config.getUnhandledTargets());
}
for (String nextClass : unhandled) {
Logger auditLogger = LogManager.getLogger("mixin/audit");
for (String target : unhandled) {
try {
this.logger.info("Force-loading class {}", nextClass);
Class.forName(nextClass, true, Launch.classLoader);
auditLogger.info("Force-loading class {}", target);
Class.forName(target, true, Launch.classLoader);
} catch (ClassNotFoundException ex) {
throw new Error("Could not force-load " + nextClass);
auditLogger.error("Could not force-load " + target, ex);
}
}
for (MixinConfig config : this.configs) {
for (String target : config.getUnhandledTargets()) {
ClassAlreadyLoadedException ex = new ClassAlreadyLoadedException(target + " was already classloaded");
auditLogger.error("Could not force-load " + target, ex);
}
}
}