Skip to content

Commit

Permalink
Fixed ability to write documentation in packaged DC environment
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspersorensen committed Apr 28, 2015
1 parent 1623a0d commit 8d16f31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import org.datacleaner.descriptors.ConfiguredPropertyDescriptor;
import org.datacleaner.util.IconUtils;

import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
Expand Down Expand Up @@ -71,7 +73,9 @@ public ComponentDocumentationBuilder() {
public ComponentDocumentationBuilder(boolean breadcrumbs) {
_breadcrumbs = breadcrumbs;
_freemarkerConfiguration = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
_freemarkerConfiguration.setClassForTemplateLoading(this.getClass(), ".");

final TemplateLoader templateLoader = new ClassTemplateLoader(this.getClass(), "");
_freemarkerConfiguration.setTemplateLoader(templateLoader);
try {
_template = _freemarkerConfiguration.getTemplate("template.html");
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public boolean writeDocumentationToDirectory(File directory) {

public boolean writeDocumentationToRepositoryFolder(RepositoryFolder folder) {
boolean success = true;
final RepositoryFile indexFile = folder.createFile("index.html", new Action<OutputStream>() {
final RepositoryFile indexFile = createOrUpdateFile(folder, "index.html", new Action<OutputStream>() {
@Override
public void run(OutputStream out) throws Exception {
IndexDocumentationBuilder index = new IndexDocumentationBuilder(_descriptorProvider);
Expand All @@ -69,7 +69,7 @@ public void run(OutputStream out) throws Exception {
for (final ComponentDescriptor<?> componentDescriptor : componentDescriptors) {
try {
final String filename = IndexDocumentationBuilder.getFilename(componentDescriptor);
final RepositoryFile file = folder.createFile(filename, new Action<OutputStream>() {
final RepositoryFile file = createOrUpdateFile(folder, filename, new Action<OutputStream>() {
@Override
public void run(OutputStream out) throws Exception {
componentDocumentationBuilder.write(componentDescriptor, out);
Expand All @@ -85,4 +85,15 @@ public void run(OutputStream out) throws Exception {

return success;
}

private RepositoryFile createOrUpdateFile(RepositoryFolder folder, String filename, Action<OutputStream> writeAction) {
RepositoryFile file = folder.getFile(filename);
if (file == null) {
file = folder.createFile(filename, writeAction);
} else {
file.writeFile(writeAction);
}

return file;
}
}

0 comments on commit 8d16f31

Please sign in to comment.