Skip to content

Commit

Permalink
Merge pull request #417 from dtrebbien/misc-fixes
Browse files Browse the repository at this point in the history
Misc. fixes and code cleanup
  • Loading branch information
manikmagar authored Mar 1, 2018
2 parents 5300a31 + 71d5f20 commit 27b9981
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 36 deletions.
8 changes: 2 additions & 6 deletions src/main/java/org/jbake/app/Asset.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,11 @@ private void copy(File sourceFolder, File targetFolder, final FileFilter filter)
for (File asset : assets) {
final File target = new File(targetFolder, asset.getName());
if (asset.isFile()) {
final StringBuilder sb = new StringBuilder();
sb.append("Copying [").append(asset.getPath()).append("]... ");
try {
FileUtils.copyFile(asset, target);
sb.append("done!");
LOGGER.info(sb.toString());
LOGGER.info("Copying [{}]... done!", asset.getPath());
} catch (IOException e) {
sb.append("failed!");
LOGGER.error(sb.toString(), e);
LOGGER.error("Copying [{}]... failed!", asset.getPath(), e);
errors.add(e);
}
} else if (asset.isDirectory()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jbake/app/ConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ public static CompositeConfiguration load(File source, boolean isRunServer) thro
public static void displayLegacyConfigFileWarningIfRequired() {
if (LEGACY_CONFIG_FILE_EXISTS) {
if (!LEGACY_CONFIG_FILE_WARNING_SHOWN) {
LOGGER.warn(String.format("You have defined a part of your JBake configuration in %s", LEGACY_CONFIG_FILE));
LOGGER.warn(String.format("Usage of this file is being deprecated, please rename this file to: %s to remove this warning", CONFIG_FILE));
LOGGER.warn("You have defined a part of your JBake configuration in " + LEGACY_CONFIG_FILE);
LOGGER.warn("Usage of this file is being deprecated, please rename this file to: " + CONFIG_FILE + " to remove this warning");
LEGACY_CONFIG_FILE_WARNING_SHOWN = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jbake/app/Crawler.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void crawl(File path) {
if (process) { // new or updated
crawlSourceFile(sourceFile, sha1, uri);
}
LOGGER.info(sb.toString());
LOGGER.info("{}", sb);
}
if (sourceFile.isDirectory()) {
crawl(sourceFile);
Expand Down Expand Up @@ -208,7 +208,7 @@ private void crawlSourceFile(final File sourceFile, final String sha1, final Str

ODocument doc = new ODocument(documentType);
doc.fromMap(fileContents);
boolean cached = fileContents.get(DocumentAttributes.CACHED) != null ? Boolean.valueOf((String) fileContents.get(DocumentAttributes.CACHED)) : true;
boolean cached = fileContents.get(String.valueOf(DocumentAttributes.CACHED)) != null ? Boolean.valueOf((String) fileContents.get(String.valueOf(DocumentAttributes.CACHED))) : true;
doc.field(String.valueOf(DocumentAttributes.CACHED), cached);
doc.save();
} else {
Expand Down
29 changes: 10 additions & 19 deletions src/main/java/org/jbake/app/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,17 @@ public void render(Map<String, Object> content) throws Exception {
}

File outputFile = new File(outputFilename + FileUtil.findExtension(config, docType));
StringBuilder sb = new StringBuilder();
sb.append("Rendering [").append(outputFile).append("]... ");
Map<String, Object> model = new HashMap<String, Object>();
model.put("content", content);
model.put("renderer", renderingEngine);

try {
Writer out = createWriter(outputFile);
renderingEngine.renderDocument(model, findTemplateName(docType), out);
out.close();
sb.append("done!");
LOGGER.info(sb.toString());
try (Writer out = createWriter(outputFile)) {
renderingEngine.renderDocument(model, findTemplateName(docType), out);
}
LOGGER.info("Rendering [{}]... done!", outputFile);
} catch (Exception e) {
sb.append("failed!");
LOGGER.error(sb.toString(), e);
LOGGER.error("Rendering [{}]... failed!", outputFile, e);
throw new Exception("Failed to render file " + outputFile.getAbsolutePath() + ". Cause: " + e.getMessage(), e);
}
}
Expand All @@ -228,18 +224,13 @@ private Writer createWriter(File file) throws IOException {

private void render(RenderingConfig renderConfig) throws Exception {
File outputFile = renderConfig.getPath();
StringBuilder sb = new StringBuilder();
sb.append("Rendering ").append(renderConfig.getName()).append(" [").append(outputFile).append("]...");

try {
Writer out = createWriter(outputFile);
renderingEngine.renderDocument(renderConfig.getModel(), renderConfig.getTemplate(), out);
out.close();
sb.append("done!");
LOGGER.info(sb.toString());
try (Writer out = createWriter(outputFile)) {
renderingEngine.renderDocument(renderConfig.getModel(), renderConfig.getTemplate(), out);
}
LOGGER.info("Rendering {} [{}]... done!", renderConfig.getName(), outputFile);
} catch (Exception e) {
sb.append("failed!");
LOGGER.error(sb.toString(), e);
LOGGER.error("Rendering {} [{}]... failed!", renderConfig.getName(), outputFile, e);
throw new Exception("Failed to render " + renderConfig.getName(), e);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jbake/launcher/CustomFSChangeListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ public CustomFSChangeListener(LaunchOptions res, CompositeConfiguration config)

@Override
public void fileCreated(FileChangeEvent event) throws Exception {
LOGGER.info("File created event detected: " + event.getFile().getURL());
LOGGER.info("File created event detected: {}", event.getFile().getURL());
exec();
}

@Override
public void fileDeleted(FileChangeEvent event) throws Exception {
LOGGER.info("File deleted event detected: " + event.getFile().getURL());
LOGGER.info("File deleted event detected: {}", event.getFile().getURL());
exec();
}

@Override
public void fileChanged(FileChangeEvent event) throws Exception {
LOGGER.info("File changed event detected: " + event.getFile().getURL());
LOGGER.info("File changed event detected: {}", event.getFile().getURL());
exec();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jbake/parser/Engines.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static void registerEngine(String className, String... extensions) {
register(extension, engine);
}
if (engine instanceof ErrorEngine) {
LOGGER.warn("Unable to load a suitable rendering engine for extensions {}", Arrays.toString(extensions));
LOGGER.warn("Unable to load a suitable rendering engine for extensions {}", (Object) extensions);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jbake/parser/MarkupEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Map<String, Object> parse(Configuration config, File file, String content
is = new FileInputStream(file);
fileContents = IOUtils.readLines(is, config.getString(Keys.RENDER_ENCODING));
} catch (IOException e) {
LOGGER.error("Error while opening file {}: {}", file, e);
LOGGER.error("Error while opening file {}", file, e);

return null;
} finally {
Expand Down Expand Up @@ -125,7 +125,7 @@ public Map<String, Object> parse(Configuration config, File file, String content
if (validate(context)) {
processBody(context);
} else {
LOGGER.error("Incomplete source file ({}) for markup engine:", file, getClass().getSimpleName());
LOGGER.error("Incomplete source file ({}) for markup engine: {}", file, getClass().getSimpleName());
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jbake/template/ModelExtractors.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public Set<String> keySet() {
public void registerExtractorsForCustomTypes(String docType) {
String pluralizedDoctype = DocumentTypeUtils.pluralize(docType);
if (!containsKey(pluralizedDoctype)) {
LOGGER.info("register new extractors for document type: " + docType);
LOGGER.info("register new extractors for document type: {}", docType);
registerEngine(pluralizedDoctype, new TypedDocumentsExtractor());
registerEngine("published_" + pluralizedDoctype, new PublishedCustomExtractor(docType));
}
Expand Down

0 comments on commit 27b9981

Please sign in to comment.