public void bake(final JBakeConfiguration config) { final Oven oven = new Oven(config); oven.bake(); final List<Throwable> errors = oven.getErrors(); if (!errors.isEmpty()) { final StringBuilder msg = new StringBuilder(); // TODO: decide, if we want the all errors here msg.append( MessageFormat.format("JBake failed with {0} errors:\n", errors.size())); int errNr = 1; for (final Throwable error : errors) { msg.append(MessageFormat.format("{0}. {1}\n", errNr, error.getMessage())); ++errNr; } throw new JBakeException(msg.toString(), errors.get(0)); } } }
/** * Create an Oven instance with given {@link Utensils} * * @param utensils All Utensils necessary to bake */ public Oven(Utensils utensils) { checkConfiguration(utensils.getConfiguration()); this.utensils = utensils; }
@Test public void shouldInstantiateNeededUtensils() throws Exception { configuration.setTemplateFolder( folder.newFolder("template") ); configuration.setContentFolder( folder.newFolder("content") ); configuration.setAssetFolder( folder.newFolder("assets") ); Oven oven = new Oven(configuration); assertThat(oven.getUtensils().getContentStore()).isNotNull(); assertThat(oven.getUtensils().getCrawler()).isNotNull(); assertThat(oven.getUtensils().getRenderer()).isNotNull(); assertThat(oven.getUtensils().getAsset()).isNotNull(); assertThat(oven.getUtensils().getConfiguration()).isEqualTo(configuration); }
orient.startup(); final Oven oven = new Oven(source, destination, new CompositeConfiguration() {{ final CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new MapConfiguration(new HashMap<String, Object>() {{ addConfiguration(config); }}, true); oven.setupPaths(); oven.bake();
@Test(expected = JBakeException.class) public void shouldThrowExceptionIfSourceFolderDoesNotExist() { configuration.setSourceFolder(new File(folder.getRoot(),"none")); new Oven(configuration); }
/** * Responsible for incremental baking, typically a single file at a time. * * @param fileToBake The file to bake */ public void bake(File fileToBake) { Asset asset = utensils.getAsset(); if(asset.isAssetFile(fileToBake)) { LOGGER.info("Baking a change to an asset [" + fileToBake.getPath() + "]"); asset.copySingleFile(fileToBake); } else { LOGGER.info("Playing it safe and running a full bake..."); bake(); } }
LOGGER.info("Baking has started..."); contentStore.startup(); updateDocTypesFromConfiguration(); contentStore.updateSchema(); contentStore.updateAndClearCacheIfNeeded(config.getClearCache(), config.getTemplateFolder()); renderContent();
/** * Iterates over the configuration, searching for keys like "template.index.file=..." * in order to register new document types. */ private void updateDocTypesFromConfiguration() { resetDocumentTypesAndExtractors(); JBakeConfiguration config = utensils.getConfiguration(); ModelExtractorsDocumentTypeListener listener = new ModelExtractorsDocumentTypeListener(); DocumentTypes.addListener(listener); for (String docType : config.getDocumentTypes()) { DocumentTypes.addDocumentType(docType); } }
@Test public void shouldCrawlRenderAndCopyAssets() throws Exception { configuration.setTemplateFolder( folder.newFolder("template") ); configuration.setContentFolder( folder.newFolder("content") ); configuration.setAssetFolder( folder.newFolder("assets") ); contentStore = spy(new ContentStore("memory", "documents"+ System.currentTimeMillis())); Crawler crawler = mock(Crawler.class); Renderer renderer = mock(Renderer.class); Asset asset = mock(Asset.class); Utensils utensils = new Utensils(); utensils.setConfiguration(configuration); utensils.setContentStore(contentStore); utensils.setRenderer(renderer); utensils.setCrawler(crawler); utensils.setAsset(asset); Oven oven = new Oven(utensils); oven.bake(); verify(contentStore, times(1)).startup(); verify(renderer,atLeastOnce()).renderIndex(anyString()); verify(crawler,times(1)).crawl(); verify(asset,times(1)).copy(); } }
@Test(expected = JBakeException.class) public void shouldInspectConfigurationDuringInstantiationFromUtils() { configuration.setSourceFolder(new File(folder.getRoot(),"none")); Utensils utensils = new Utensils(); utensils.setConfiguration(configuration); new Oven(utensils); }
/** * Responsible for incremental baking, typically a single file at a time. * * @param fileToBake The file to bake */ public void bake(File fileToBake) { Asset asset = utensils.getAsset(); if(asset.isAssetFile(fileToBake)) { LOGGER.info("Baking a change to an asset [" + fileToBake.getPath() + "]"); asset.copySingleFile(fileToBake); } else { LOGGER.info("Playing it safe and running a full bake..."); bake(); } }
LOGGER.info("Baking has started..."); contentStore.startup(); updateDocTypesFromConfiguration(); contentStore.updateSchema(); contentStore.updateAndClearCacheIfNeeded(config.getClearCache(), config.getTemplateFolder()); renderContent();
/** * Iterates over the configuration, searching for keys like "template.index.file=..." * in order to register new document types. */ private void updateDocTypesFromConfiguration() { resetDocumentTypesAndExtractors(); JBakeConfiguration config = utensils.getConfiguration(); ModelExtractorsDocumentTypeListener listener = new ModelExtractorsDocumentTypeListener(); DocumentTypes.addListener(listener); for (String docType : config.getDocumentTypes()) { DocumentTypes.addDocumentType(docType); } }
@Test public void bakeWithAbsolutePaths() { configuration.setTemplateFolder( new File(sourceFolder, "freemarkerTemplates") ); configuration.setContentFolder( new File(sourceFolder, "content") ); configuration.setAssetFolder( new File(sourceFolder, "assets") ); final Oven oven = new Oven(configuration); oven.bake(); assertThat(oven.getErrors()).isEmpty(); }
/** * Create an Oven instance with given {@link Utensils} * * @param utensils All Utensils necessary to bake */ public Oven(Utensils utensils) { checkConfiguration(utensils.getConfiguration()); this.utensils = utensils; }
public void bake(final JBakeConfiguration config) { final Oven oven = new Oven(config); oven.bake(); final List<Throwable> errors = oven.getErrors(); if (!errors.isEmpty()) { final StringBuilder msg = new StringBuilder(); // TODO: decide, if we want the all errors here msg.append( MessageFormat.format("JBake failed with {0} errors:\n", errors.size())); int errNr = 1; for (final Throwable error : errors) { msg.append(MessageFormat.format("{0}. {1}\n", errNr, error.getMessage())); ++errNr; } throw new JBakeException(msg.toString(), errors.get(0)); } } }