private void ensureContentFolder() { File path = configuration.getContentFolder(); checkRequiredFolderExists(configuration.getContentFolderName(), path); }
private String assetSubPath(File asset) throws IOException { // First, strip asset folder from file path String targetFolder = asset.getCanonicalPath().replace(config.getAssetFolder().getCanonicalPath() + File.separatorChar, ""); // And just to be sure, let's also remove the content folder, as some assets are copied from here. targetFolder = targetFolder.replace(config.getContentFolder().getCanonicalPath() + File.separatorChar, ""); return targetFolder; }
@Test public void shouldThrowExceptionIfContentFolderDoesNotExist() throws Exception { String contentFolderName = "content"; String templateFolderName = "template"; File templateFolder = TestUtils.newFolder(folder.toFile(), templateFolderName); File contentFolder = new File(folder.toFile(), contentFolderName); JBakeConfiguration configuration = mock(JBakeConfiguration.class); when(configuration.getSourceFolder()).thenReturn(folder.toFile()); when(configuration.getTemplateFolder()).thenReturn(templateFolder); when(configuration.getTemplateFolderName()).thenReturn(templateFolderName); when(configuration.getContentFolder()).thenReturn(contentFolder); when(configuration.getContentFolderName()).thenReturn(contentFolderName); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); try { inspector.inspect(); fail("should throw a JBakeException"); } catch (JBakeException e) { assertThat(e.getMessage()).isEqualTo("Error: Required folder cannot be found! Expected to find [" + contentFolderName + "] at: " + contentFolder.getAbsolutePath()); } }
static public String getUriPathToContentRoot(JBakeConfiguration config, File sourceFile) { return getPathToRoot(config, config.getContentFolder(), sourceFile); }
@Test public void shouldCreateDestinationFolderIfNotExists() throws Exception { String contentFolderName = "content"; String templateFolderName = "template"; String destinationFolderName = "output"; File templateFolder = TestUtils.newFolder(folder.toFile(), templateFolderName); File contentFolder = TestUtils.newFolder(folder.toFile(), contentFolderName); File destinationFolder = new File(folder.toFile(), destinationFolderName); JBakeConfiguration configuration = mock(JBakeConfiguration.class); when(configuration.getSourceFolder()).thenReturn(folder.toFile()); when(configuration.getTemplateFolder()).thenReturn(templateFolder); when(configuration.getTemplateFolderName()).thenReturn(templateFolderName); when(configuration.getContentFolder()).thenReturn(contentFolder); when(configuration.getContentFolderName()).thenReturn(contentFolderName); when(configuration.getDestinationFolder()).thenReturn(destinationFolder); when(configuration.getAssetFolder()).thenReturn(destinationFolder); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); inspector.inspect(); assertThat(destinationFolder).exists(); }
public void crawl() { crawl(config.getContentFolder()); LOGGER.info("Content detected:"); for (String docType : DocumentTypes.getDocumentTypes()) { long count = db.getDocumentCount(docType); if (count > 0) { LOGGER.info("Parsed {} files of type: {}", count, docType); } } }
@Test public void shouldLogWarningIfAssetFolderDoesNotExist() throws Exception { String contentFolderName = "content"; String templateFolderName = "template"; String destinationFolderName = "output"; String assetFolderName = "assets"; File templateFolder = TestUtils.newFolder(folder.toFile(), templateFolderName); File contentFolder = TestUtils.newFolder(folder.toFile(), contentFolderName); File destinationFolder = TestUtils.newFolder(folder.toFile(), destinationFolderName); File assetFolder = new File(folder.toFile(), assetFolderName); JBakeConfiguration configuration = mock(JBakeConfiguration.class); when(configuration.getSourceFolder()).thenReturn(folder.toFile()); when(configuration.getTemplateFolder()).thenReturn(templateFolder); when(configuration.getTemplateFolderName()).thenReturn(templateFolderName); when(configuration.getContentFolder()).thenReturn(contentFolder); when(configuration.getContentFolderName()).thenReturn(contentFolderName); when(configuration.getDestinationFolder()).thenReturn(destinationFolder); when(configuration.getAssetFolder()).thenReturn(assetFolder); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); inspector.inspect(); verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture()); LoggingEvent loggingEvent = captorLoggingEvent.getValue(); assertThat(loggingEvent.getMessage()).isEqualTo("No asset folder '{}' was found!"); assertThat(loggingEvent.getFormattedMessage()).isEqualTo("No asset folder '" + assetFolder.getAbsolutePath() + "' was found!"); }
private String buildURI(final File sourceFile) { String uri = FileUtil.asPath(sourceFile).replace(FileUtil.asPath(config.getContentFolder()), ""); if (useNoExtensionUri(uri)) { // convert URI from xxx.html to xxx/index.html uri = createNoExtensionUri(uri); } else { uri = createUri(uri); } // strip off leading / to enable generating non-root based sites if (uri.startsWith(FileUtil.URI_SEPARATOR_CHAR)) { uri = uri.substring(1, uri.length()); } return uri; }
@Test public void shouldThrowExceptionIfDestinationFolderNotWritable() throws Exception { String contentFolderName = "content"; String templateFolderName = "template"; File templateFolder = TestUtils.newFolder(folder.toFile(), templateFolderName); File contentFolder = TestUtils.newFolder(folder.toFile(), contentFolderName); File destinationFolder = mock(File.class); when(destinationFolder.exists()).thenReturn(true); JBakeConfiguration configuration = mock(JBakeConfiguration.class); when(configuration.getSourceFolder()).thenReturn(folder.toFile()); when(configuration.getTemplateFolder()).thenReturn(templateFolder); when(configuration.getTemplateFolderName()).thenReturn(templateFolderName); when(configuration.getContentFolder()).thenReturn(contentFolder); when(configuration.getContentFolderName()).thenReturn(contentFolderName); when(configuration.getDestinationFolder()).thenReturn(destinationFolder); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); try { inspector.inspect(); fail("should throw JBakeException"); } catch (JBakeException e) { assertThat(e.getMessage()).contains("Error: Destination folder is not writable:"); } }
/** * Determine if a given file is an asset file. * @param path to the file to validate. * @return true if the path provided points to a file in the asset folder. */ public boolean isAssetFile(File path) { boolean isAsset = false; try { if(FileUtil.directoryOnlyIfNotIgnored(path.getParentFile())) { if (FileUtil.isFileInDirectory(path, config.getAssetFolder())) { isAsset = true; } else if (FileUtil.isFileInDirectory(path, config.getContentFolder()) && FileUtil.getNotContentFileFilter().accept(path)) { isAsset = true; } } } catch (IOException ioe) { LOGGER.error("Unable to determine the path to asset file {}", path.getPath(), ioe); } return isAsset; }
private void ensureContentFolder() { File path = configuration.getContentFolder(); checkRequiredFolderExists(configuration.getContentFolderName(), path); }
asset.copyAssetsFromContent(config.getContentFolder());
@Test public void shouldReturnContentFolderFromConfiguration() throws Exception { File sourceFolder = TestUtils.getTestResourcesAsSourceFolder(); File expectedDestinationFolder = new File(sourceFolder, "content"); JBakeConfiguration config = util.loadConfig(sourceFolder); assertThat(config.getContentFolder()).isEqualTo(expectedDestinationFolder); }
/** * Starts watching the file system for changes to trigger a bake. * * @param config JBakeConfiguration settings */ public void start(JBakeConfiguration config) { try { FileSystemManager fsMan = VFS.getManager(); FileObject listenPath = fsMan.resolveFile(config.getContentFolder().toURI()); FileObject templateListenPath = fsMan.resolveFile(config.getTemplateFolder().toURI()); FileObject assetPath = fsMan.resolveFile(config.getAssetFolder().toURI()); logger.info("Watching for (content, template, asset) changes in [{}]", config.getSourceFolder().getPath()); DefaultFileMonitor monitor = new DefaultFileMonitor(new CustomFSChangeListener(config)); monitor.setRecursive(true); monitor.addFile(listenPath); monitor.addFile(templateListenPath); monitor.addFile(assetPath); monitor.start(); } catch (FileSystemException e) { logger.error("Problems watching filesystem changes", e); } } }
private String assetSubPath(File asset) throws IOException { // First, strip asset folder from file path String targetFolder = asset.getCanonicalPath().replace(config.getAssetFolder().getCanonicalPath() + File.separatorChar, ""); // And just to be sure, let's also remove the content folder, as some assets are copied from here. targetFolder = targetFolder.replace(config.getContentFolder().getCanonicalPath() + File.separatorChar, ""); return targetFolder; }
static public String getUriPathToContentRoot(JBakeConfiguration config, File sourceFile) { return getPathToRoot(config, config.getContentFolder(), sourceFile); }
public void crawl() { crawl(config.getContentFolder()); LOGGER.info("Content detected:"); for (String docType : DocumentTypes.getDocumentTypes()) { long count = db.getDocumentCount(docType); if (count > 0) { LOGGER.info("Parsed {} files of type: {}", count, docType); } } }
private String buildURI(final File sourceFile) { String uri = FileUtil.asPath(sourceFile).replace(FileUtil.asPath(config.getContentFolder()), ""); if (useNoExtensionUri(uri)) { // convert URI from xxx.html to xxx/index.html uri = createNoExtensionUri(uri); } else { uri = createUri(uri); } // strip off leading / to enable generating non-root based sites if (uri.startsWith(FileUtil.URI_SEPARATOR_CHAR)) { uri = uri.substring(1, uri.length()); } return uri; }
/** * Determine if a given file is an asset file. * @param path to the file to validate. * @return true if the path provided points to a file in the asset folder. */ public boolean isAssetFile(File path) { boolean isAsset = false; try { if(FileUtil.directoryOnlyIfNotIgnored(path.getParentFile())) { if (FileUtil.isFileInDirectory(path, config.getAssetFolder())) { isAsset = true; } else if (FileUtil.isFileInDirectory(path, config.getContentFolder()) && FileUtil.getNotContentFileFilter().accept(path)) { isAsset = true; } } } catch (IOException ioe) { LOGGER.error("Unable to determine the path to asset file {}", path.getPath(), ioe); } return isAsset; }
/** * Starts watching the file system for changes to trigger a bake. * * @param config JBakeConfiguration settings */ public void start(JBakeConfiguration config) { try { FileSystemManager fsMan = VFS.getManager(); FileObject listenPath = fsMan.resolveFile(config.getContentFolder().toURI()); FileObject templateListenPath = fsMan.resolveFile(config.getTemplateFolder().toURI()); FileObject assetPath = fsMan.resolveFile(config.getAssetFolder().toURI()); logger.info("Watching for (content, template, asset) changes in [{}]", config.getSourceFolder().getPath()); DefaultFileMonitor monitor = new DefaultFileMonitor(new CustomFSChangeListener(config)); monitor.setRecursive(true); monitor.addFile(listenPath); monitor.addFile(templateListenPath); monitor.addFile(assetPath); monitor.start(); } catch (FileSystemException e) { logger.error("Problems watching filesystem changes", e); } } }