/** * Create default {@link Utensils} by a given {@link JBakeConfiguration} * @param config a {@link JBakeConfiguration} * @return a default {@link Utensils} instance */ public static Utensils createDefaultUtensils(JBakeConfiguration config) { JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(config); inspector.inspect(); Utensils utensils = new Utensils(); utensils.setConfiguration(config); ContentStore contentStore = DBUtil.createDataStore(config); utensils.setContentStore(contentStore); utensils.setCrawler(new Crawler(contentStore, config)); utensils.setRenderer(new Renderer(contentStore, config)); utensils.setAsset(new Asset(config)); return utensils; } }
ContentStore contentStore = utensils.getContentStore(); JBakeConfiguration config = utensils.getConfiguration(); Crawler crawler = utensils.getCrawler(); Asset asset = utensils.getAsset();
/** * Load {@link RenderingTool} instances and delegate rendering of documents to them */ private void renderContent() { JBakeConfiguration config = utensils.getConfiguration(); Renderer renderer = utensils.getRenderer(); ContentStore contentStore = utensils.getContentStore(); for (RenderingTool tool : ServiceLoader.load(RenderingTool.class)) { try { renderedCount += tool.render(renderer, contentStore, config); } catch (RenderingException e) { errors.add(e); } } }
/** * 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(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(); } }
@Deprecated public CompositeConfiguration getConfig() { return ((DefaultJBakeConfiguration) utensils.getConfiguration()).getCompositeConfiguration(); }
/** * 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(); } }
@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 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); }
/** * Load {@link RenderingTool} instances and delegate rendering of documents to them */ private void renderContent() { JBakeConfiguration config = utensils.getConfiguration(); Renderer renderer = utensils.getRenderer(); ContentStore contentStore = utensils.getContentStore(); for (RenderingTool tool : ServiceLoader.load(RenderingTool.class)) { try { renderedCount += tool.render(renderer, contentStore, config); } catch (RenderingException e) { errors.add(e); } } }
@Deprecated public void setConfig(final CompositeConfiguration config) { ((DefaultJBakeConfiguration) utensils.getConfiguration()).setCompositeConfiguration(config); }
/** * Create default {@link Utensils} by a given {@link JBakeConfiguration} * @param config a {@link JBakeConfiguration} * @return a default {@link Utensils} instance */ public static Utensils createDefaultUtensils(JBakeConfiguration config) { JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(config); inspector.inspect(); Utensils utensils = new Utensils(); utensils.setConfiguration(config); ContentStore contentStore = DBUtil.createDataStore(config); utensils.setContentStore(contentStore); utensils.setCrawler(new Crawler(contentStore, config)); utensils.setRenderer(new Renderer(contentStore, config)); utensils.setAsset(new Asset(config)); return utensils; } }
ContentStore contentStore = utensils.getContentStore(); JBakeConfiguration config = utensils.getConfiguration(); Crawler crawler = utensils.getCrawler(); Asset asset = utensils.getAsset();
/** * 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); } }
/** * 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; }
@Deprecated public CompositeConfiguration getConfig() { return ((DefaultJBakeConfiguration) utensils.getConfiguration()).getCompositeConfiguration(); }
@Deprecated public void setConfig(final CompositeConfiguration config) { ((DefaultJBakeConfiguration) utensils.getConfiguration()).setCompositeConfiguration(config); }
/** * 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); } }