private void copy(File sourceFolder, File targetFolder, final FileFilter filter) { final File[] assets = sourceFolder.listFiles(filter); if (assets != null) { Arrays.sort(assets); for (File asset : assets) { final File target = new File(targetFolder, asset.getName()); if (asset.isFile()) { copyFile(asset, target); } else if (asset.isDirectory()) { copy(asset, target, filter); } } } }
/** * Copy all files from assets folder to destination folder * read from configuration */ public void copy() { copy(config.getAssetFolder()); }
asset.copy(); asset.copyAssetsFromContent(config.getContentFolder());
/** * Copy all files from supplied path. * * @param path The starting path */ public void copy(File path) { FileFilter filter = new FileFilter() { @Override public boolean accept(File file) { return (!config.getAssetIgnoreHidden() || !file.isHidden()) && (file.isFile() || FileUtil.directoryOnlyIfNotIgnored(file)); } }; copy(path, config.getDestinationFolder(), filter); }
asset.copy(); asset.copyAssetsFromContent(config.getContentFolder());
private void copy(File sourceFolder, File targetFolder, final FileFilter filter) { final File[] assets = sourceFolder.listFiles(filter); if (assets != null) { Arrays.sort(assets); for (File asset : assets) { final File target = new File(targetFolder, asset.getName()); if (asset.isFile()) { copyFile(asset, target); } else if (asset.isDirectory()) { copy(asset, target, filter); } } } }
/** * Responsible for copying any asset files that exist within the content directory. * * @param path of the content directory */ public void copyAssetsFromContent(File path) { copy(path, config.getDestinationFolder(), FileUtil.getNotContentFileFilter()); }
@Test public void testCopy() throws Exception { Asset asset = new Asset(config); asset.copy(); File cssFile = new File(folder.toString() + File.separatorChar + "css" + File.separatorChar + "bootstrap.min.css"); Assertions.assertTrue(cssFile.exists(), () -> "File " + cssFile.getAbsolutePath() + " does not exist"); File imgFile = new File(folder.toString() + File.separatorChar + "img" + File.separatorChar + "glyphicons-halflings.png"); Assertions.assertTrue(imgFile.exists(), () -> "File " + imgFile.getAbsolutePath() + " does not exist"); File jsFile = new File(folder.toString() + File.separatorChar + "js" + File.separatorChar + "bootstrap.min.js"); Assertions.assertTrue(jsFile.exists(), () -> "File " + jsFile.getAbsolutePath() + " does not exist"); Assertions.assertTrue(asset.getErrors().isEmpty(), "Errors during asset copying"); }
@Test public void testJBakeIgnoredFolder() { URL assetsUrl = this.getClass().getResource("/fixture/assets"); File assets = new File(assetsUrl.getFile()); Asset asset = new Asset(config); asset.copy(assets); File cssFile = new File(folder.toString() + File.separatorChar + "css" + File.separatorChar + "bootstrap.min.css"); Assertions.assertTrue(cssFile.exists(), () -> "File " + cssFile.getAbsolutePath() + " does not exist"); File imgFile = new File(folder.toString() + File.separatorChar + "img" + File.separatorChar + "glyphicons-halflings.png"); Assertions.assertTrue(imgFile.exists(), () -> "File " + imgFile.getAbsolutePath() + " does not exist"); File jsFile = new File(folder.toString() + File.separatorChar + "js" + File.separatorChar + "bootstrap.min.js"); Assertions.assertTrue(jsFile.exists(), () -> "File " + jsFile.getAbsolutePath() + " does not exist"); File ignorableFolder = new File(folder.toString() + File.separatorChar + "ignorablefolder"); Assertions.assertFalse(ignorableFolder.exists(), () -> "Folder " + ignorableFolder.getAbsolutePath() + " must not exist"); Assertions.assertTrue(asset.getErrors().isEmpty(), "Errors during asset copying"); }
@Test public void testCopyIgnore() throws Exception { File assetFolder = new File(folder.toFile(), "ignoredAssets"); assetFolder.mkdirs(); FileUtils.copyDirectory(new File(this.getClass().getResource("/fixture/ignorables").getFile()), assetFolder); config.setAssetFolder(assetFolder); config.setAssetIgnoreHidden(true); TestUtils.hideAssets(assetFolder); Asset asset = new Asset(config); asset.copy(assetFolder); File testFile = new File(folder.toFile(), "test.txt"); Assertions.assertTrue(testFile.exists(), () -> "File " + testFile.getAbsolutePath() + " does not exist"); File testIgnoreFile = new File(folder.toFile(), ".test.txt"); Assertions.assertFalse(testIgnoreFile.exists(), () -> "File " + testIgnoreFile.getAbsolutePath() + " does exist"); Assertions.assertTrue(asset.getErrors().isEmpty(), "Errors during asset copying"); }
@Test public void testCopyCustomFolder() throws Exception { config.setAssetFolder(new File(config.getSourceFolder(), "/media")); Asset asset = new Asset(config); asset.copy(); File favFile = new File(folder.toString() + File.separatorChar + "favicon.ico"); Assertions.assertTrue(favFile.exists(), () -> "File " + favFile.getAbsolutePath() + " does not exist"); Assertions.assertTrue(asset.getErrors().isEmpty(), "Errors during asset copying"); }
/** * Primary intention is to extend test cases to increase coverage. * * @throws Exception */ @Test public void testUnlistable() throws Exception { config.setAssetFolder(new File(config.getSourceFolder(), "non-exsitent")); Asset asset = new Asset(config); asset.copy(); }
/** * Primary intention is to extend test cases to increase coverage. * * @throws Exception */ @Test public void testWriteProtected() throws Exception { File assets = new File(config.getSourceFolder(), "assets"); File css = new File(folder.toFile(),"css"); css.mkdir(); final File cssFile = new File(css, "bootstrap.min.css"); FileUtils.touch(cssFile); cssFile.setReadOnly(); config.setAssetFolder(assets); config.setDestinationFolder(folder.toFile()); Asset asset = new Asset(config); asset.copy(); cssFile.setWritable(true); Assertions.assertFalse(asset.getErrors().isEmpty(), "At least one error during copy expected"); }
@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(); } }
/** * Copy all files from assets folder to destination folder * read from configuration */ public void copy() { copy(config.getAssetFolder()); }
/** * Copy all files from supplied path. * * @param path The starting path */ public void copy(File path) { FileFilter filter = new FileFilter() { @Override public boolean accept(File file) { return (!config.getAssetIgnoreHidden() || !file.isHidden()) && (file.isFile() || FileUtil.directoryOnlyIfNotIgnored(file)); } }; copy(path, config.getDestinationFolder(), filter); }
/** * Responsible for copying any asset files that exist within the content directory. * * @param path of the content directory */ public void copyAssetsFromContent(File path) { copy(path, config.getDestinationFolder(), FileUtil.getNotContentFileFilter()); }