Provide some refmap status information in log and relevant exceptions

fixes #202
This commit is contained in:
Mumfrey committed 2017-08-02 18:53:33 +01:00
1 parent 9caa1eb5e5
commit c0e2e5c4dd
4 files changed
+62 -8

No files matched your search

@@ -190,7 +190,7 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
members.add(targetMember);
} catch (InvalidMemberDescriptorException ex) {
throw new InvalidInjectionException(this, type + " annotation on " + this.method.name + ", has invalid target descriptor: \""
+ method + "\"");
+ method + "\". " + this.mixin.getReferenceMapper().getStatus());
}
}
return members;
@@ -64,7 +64,7 @@ public final class ReferenceMapper implements Serializable {
/**
* Passthrough mapper, used as failover
*/
public static final ReferenceMapper DEFAULT_MAPPER = new ReferenceMapper(true);
public static final ReferenceMapper DEFAULT_MAPPER = new ReferenceMapper(true, "invalid");
/**
* "Default" mappings. The set of mappings to use as "default" is specified
@@ -90,11 +90,16 @@ public final class ReferenceMapper implements Serializable {
*/
private transient String context = null;
/**
* Resource name this refmap was loaded from (if available)
*/
private transient String resource;
/**
* Create an empty refmap
*/
public ReferenceMapper() {
this(false);
this(false, ReferenceMapper.DEFAULT_RESOURCE);
}
/**
@@ -102,10 +107,46 @@ public final class ReferenceMapper implements Serializable {
*
* @param readOnly flag to indicate read-only
*/
private ReferenceMapper(boolean readOnly) {
private ReferenceMapper(boolean readOnly, String resource) {
this.readOnly = readOnly;
this.resource = resource;
}
/**
* Get whether this mapper is defaulted. Use this flag rather than reference
* comparison to {@link #DEFAULT_MAPPER} because of classloader shenanigans
*
* @return true if this mapper is a defaulted mapper
*/
public boolean isDefault() {
return this.readOnly;
}
private void setResourceName(String resource) {
if (!this.readOnly) {
this.resource = resource != null ? resource : "<unknown resource>";
}
}
/**
* Get the resource name this refmap was loaded from (if available).
*
* @return name of the resource
*/
public String getResourceName() {
return this.resource;
}
/**
* Get a user-readable "status" string for this refmap for use in error
* messages
*
* @return status message
*/
public String getStatus() {
return this.isDefault() ? "No refMap loaded" : "Using refmap " + this.getResourceName();
}
/**
* Get the current context
*
@@ -225,7 +266,9 @@ public final class ReferenceMapper implements Serializable {
InputStream resource = Launch.classLoader.getResourceAsStream(resourcePath);
if (resource != null) {
reader = new InputStreamReader(resource);
return ReferenceMapper.readJson(reader);
ReferenceMapper mapper = ReferenceMapper.readJson(reader);
mapper.setResourceName(resourcePath);
return mapper;
}
} catch (JsonParseException ex) {
logger.error("Invalid REFMAP JSON in " + resourcePath + ": " + ex.getClass().getName() + " " + ex.getMessage());
@@ -242,11 +285,14 @@ public final class ReferenceMapper implements Serializable {
* Read a new refmap instance from the specified reader
*
* @param reader Reader to read from
* @param name Name of the resource being read from
* @return new refmap
*/
public static ReferenceMapper read(Reader reader) {
public static ReferenceMapper read(Reader reader, String name) {
try {
return ReferenceMapper.readJson(reader);
ReferenceMapper mapper = ReferenceMapper.readJson(reader);
mapper.setResourceName(name);
return mapper;
} catch (Exception ex) {
return ReferenceMapper.DEFAULT_MAPPER;
}
@@ -449,18 +449,26 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
this.mixinPackage += ".";
}
boolean suppressRefMapWarning = false;
if (this.refMapperConfig == null) {
if (this.plugin != null) {
this.refMapperConfig = this.plugin.getRefMapperConfig();
}
if (this.refMapperConfig == null) {
suppressRefMapWarning = true;
this.refMapperConfig = ReferenceMapper.DEFAULT_RESOURCE;
}
}
this.refMapper = ReferenceMapper.read(this.refMapperConfig);
this.verboseLogging |= this.env.getOption(Option.DEBUG_VERBOSE);
if (!suppressRefMapWarning && this.refMapper.isDefault() && !this.env.getOption(Option.DISABLE_REFMAP)) {
this.logger.warn("Reference map '{}' for {} could not be read. If this is a development environment you can ignore this message",
this.refMapperConfig, this);
}
}
/**
@@ -361,7 +361,7 @@ class MixinPreProcessorStandard {
target = context.findRemappedMethod(mixinMethod);
if (target == null) {
throw new InvalidMixinException(this.mixin, type + " method " + mixinMethod.name + " in " + this.mixin
+ " was not located in the target class");
+ " was not located in the target class." + context.getReferenceMapper().getStatus());
}
mixinMethod.name = method.renameTo(target.name);
}