protected InputStream getTemplateResource(GeneratorContext context, JClassType toGenerate, TreeLogger l,
String markerPath) throws UnableToCompleteException {
// look for a local file first
// TODO remove this assumption
String path = slashify(toGenerate.getPackage().getName()) + "/" + markerPath;
Resource res = context.getResourcesOracle().getResourceMap().get(path);
// if not a local path, try an absolute one
if (res == null) {
URL url = Thread.currentThread().getContextClassLoader().getResource(markerPath);
if (url == null) {
return null;
}
try {
return url.openStream();
} catch (IOException e) {
logger.log(Type.ERROR, "IO Exception occured", e);
throw new UnableToCompleteException();
}
}
try {
return res.openContents();
} catch (Exception e) {
logger.log(Type.ERROR, "Exception occured reading " + path, e);
throw new UnableToCompleteException();
}
}