/** * 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 testIsFileInDirectory() throws Exception { File fixtureDir = new File(this.getClass().getResource("/fixture").getFile()); File jbakeFile = new File(fixtureDir.getCanonicalPath() + File.separatorChar + "jbake.properties"); assertTrue("jbake.properties expected to be in /fixture directory", FileUtil.isFileInDirectory(jbakeFile, fixtureDir)); File contentFile = new File(fixtureDir.getCanonicalPath() + File.separatorChar + "content" + File.separatorChar + "projects.html"); assertTrue("projects.html expected to be nested in the /fixture directory", FileUtil.isFileInDirectory(contentFile, fixtureDir)); File contentDir = contentFile.getParentFile(); assertFalse("jbake.properties file should not be in the /fixture/content directory", FileUtil.isFileInDirectory(jbakeFile, contentDir)); }
/** * 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; }