private void checkAssetFolder() { File path = configuration.getAssetFolder(); if (!path.exists()) { LOGGER.warn("No asset folder '{}' was found!", path.getAbsolutePath()); } }
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; }
/** * Copy all files from assets folder to destination folder * read from configuration */ public void copy() { copy(config.getAssetFolder()); }
/** * 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; }
@Test public void shouldReturnAssetFolderFromConfiguration() throws Exception { File sourceFolder = TestUtils.getTestResourcesAsSourceFolder(); File expectedDestinationFolder = new File(sourceFolder, "assets"); JBakeConfiguration config = util.loadConfig(sourceFolder); assertThat(config.getAssetFolder()).isEqualTo(expectedDestinationFolder); }
@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(); }
/** * 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); } } }
@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!"); }
@Test public void shouldReturnDefaultConfigurationWithDefaultFolders() throws Exception { File sourceFolder = folder.getRoot(); File destinationFolder = folder.newFolder("output"); File templateFolder = new File(folder.getRoot(), "templates"); File assetFolder = new File(folder.getRoot(), "assets"); JBakeConfiguration configuration = new JBakeConfigurationFactory().createDefaultJbakeConfiguration(sourceFolder, destinationFolder, true); assertThat(configuration.getSourceFolder()).isEqualTo(sourceFolder); assertThat(configuration.getDestinationFolder()).isEqualTo(destinationFolder); assertThat(configuration.getTemplateFolder()).isEqualTo(templateFolder); assertThat(configuration.getAssetFolder()).isEqualTo(assetFolder); assertThat(configuration.getClearCache()).isEqualTo(true); }
private void checkAssetFolder() { File path = configuration.getAssetFolder(); if (!path.exists()) { LOGGER.warn("No asset folder '{}' was found!", path.getAbsolutePath()); } }
/** * Copy all files from assets folder to destination folder * read from configuration */ public void copy() { copy(config.getAssetFolder()); }
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; }
/** * 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); } } }