1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 02:15:31 +02:00

Clean up API around getting Bundles to find template files.

This commit is contained in:
Doug Schaefer 2016-04-23 21:13:53 -04:00
parent af4fd8ed84
commit 5917bd9534

View file

@ -52,7 +52,6 @@ import freemarker.template.TemplateException;
public abstract class FMGenerator implements TemplateLoader { public abstract class FMGenerator implements TemplateLoader {
private final Configuration templateConfig; private final Configuration templateConfig;
private Bundle bundle;
private String manifestPath; private String manifestPath;
private TemplateManifest manifest; private TemplateManifest manifest;
private List<IFile> filesToOpen = new ArrayList<>(); private List<IFile> filesToOpen = new ArrayList<>();
@ -62,10 +61,8 @@ public abstract class FMGenerator implements TemplateLoader {
templateConfig.setTemplateLoader(this); templateConfig.setTemplateLoader(this);
} }
public void setBundle(Bundle bundle) { public abstract Bundle getSourceBundle();
this.bundle = bundle;
}
public void setTemplateManifestPath(String manifestPath) { public void setTemplateManifestPath(String manifestPath) {
this.manifestPath = manifestPath; this.manifestPath = manifestPath;
} }
@ -79,9 +76,14 @@ public abstract class FMGenerator implements TemplateLoader {
} }
public void generate(Map<String, Object> model, IProgressMonitor monitor) throws CoreException { public void generate(Map<String, Object> model, IProgressMonitor monitor) throws CoreException {
// If no manifest, just return
if (manifestPath == null) {
return;
}
// load manifest file
manifest = null; manifest = null;
try { try {
// load manifest file
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
loadFile(manifestPath, model, writer); // $NON-NLS-1$ loadFile(manifestPath, model, writer); // $NON-NLS-1$
JAXBContext xmlContext = JAXBContext.newInstance(getManifestClass()); JAXBContext xmlContext = JAXBContext.newInstance(getManifestClass());
@ -103,7 +105,7 @@ public abstract class FMGenerator implements TemplateLoader {
generateFile(fileTemplate.getSrc(), model, file, monitor); generateFile(fileTemplate.getSrc(), model, file, monitor);
} else { } else {
try { try {
URL url = FileLocator.find(bundle, new Path(fileTemplate.getSrc()), null); URL url = FileLocator.find(getSourceBundle(), new Path(fileTemplate.getSrc()), null);
try (InputStream in = url.openStream()) { try (InputStream in = url.openStream()) {
createParent(file, monitor); createParent(file, monitor);
if (file.exists()) { if (file.exists()) {
@ -185,7 +187,7 @@ public abstract class FMGenerator implements TemplateLoader {
@Override @Override
public Object findTemplateSource(String name) throws IOException { public Object findTemplateSource(String name) throws IOException {
return FileLocator.find(bundle, new Path(name), null); return FileLocator.find(getSourceBundle(), new Path(name), null);
} }
@Override @Override