private String getPathToRoot(File sourceFile) { return FileUtil.getUriPathToContentRoot(config, sourceFile); }
/** * 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; }
/** * platform independent file.getPath() * * @param file the file to transform, or {@code null} * @return The result of file.getPath() with all path Separators beeing a "/", or {@code null} * Needed to transform Windows path separators into slashes. */ public static String asPath(File file) { if (file == null) { return null; } return asPath(file.getPath()); }
@Override public boolean accept(File pathname) { //Accept if input is a non-hidden file with registered extension //or if a non-hidden and not-ignored directory return !pathname.isHidden() && (pathname.isFile() && Engines.getRecognizedExtensions().contains(fileExt(pathname))) || (directoryOnlyIfNotIgnored(pathname)); } };
private void initStructure(String type, JBakeConfiguration config) { Init init = new Init(config); try { File templateFolder = FileUtil.getRunningLocation(); File outputFolder; if (config.getSourceFolder() != null) { outputFolder = config.getSourceFolder(); } else { outputFolder = new File("."); } init.run(outputFolder, templateFolder, type); System.out.println("Base folder structure successfully created."); } catch (final Exception e) { final String msg = "Failed to initialise structure: " + e.getMessage(); throw new JBakeException(msg, e); } }
public static String fileExt(File src) { String name = src.getName(); return fileExt(name); }
@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)); }
static public String getUriPathToDestinationRoot(JBakeConfiguration config, File sourceFile) { return getPathToRoot(config, config.getDestinationFolder(), sourceFile); }
/** * 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()); }
@Override public boolean accept(File file) { return (!config.getAssetIgnoreHidden() || !file.isHidden()) && (file.isFile() || FileUtil.directoryOnlyIfNotIgnored(file)); } };
File[] contents = path.listFiles(FileUtil.getFileFilter()); if (contents != null) { Arrays.sort(contents);
map.put(Attributes.ROOTPATH, FileUtil.getUriPathToDestinationRoot(config, path)); map.put(Attributes.ROOTPATH, FileUtil.getUriPathToDestinationRoot(config, path)); render(new ModelRenderingConfig(path, "tagindex", model, findTemplateName("tagsindex"))); renderedCount++;
@Override public boolean accept(File pathname) { //Accept if input is a non-hidden file with NOT-registered extension //or if a non-hidden and not-ignored directory return !pathname.isHidden() && (pathname.isFile() //extension should not be from registered content extensions && !Engines.getRecognizedExtensions().contains(fileExt(pathname))) || (directoryOnlyIfNotIgnored(pathname)); } };
@Test public void testGetRunningLocation() throws Exception { File path = FileUtil.getRunningLocation(); assertEquals(new File("build/classes").getAbsolutePath(), path.getPath()); }
/** * Process the file by parsing the contents. * * @param file File input for parsing * @return The contents of the file */ public Map<String, Object> processFile(File file) { ParserEngine engine = Engines.get(FileUtil.fileExt(file)); if (engine==null) { LOGGER.error("Unable to find suitable markup engine for {}",file); return null; } return engine.parse(config, file); } }
static public String getUriPathToContentRoot(JBakeConfiguration config, File sourceFile) { return getPathToRoot(config, config.getContentFolder(), sourceFile); }
/** * 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()); }
@Override public boolean accept(File file) { return (!config.getAssetIgnoreHidden() || !file.isHidden()) && (file.isFile() || FileUtil.directoryOnlyIfNotIgnored(file)); } };
File[] contents = path.listFiles(FileUtil.getFileFilter()); if (contents != null) { Arrays.sort(contents);
map.put(Attributes.ROOTPATH, FileUtil.getUriPathToDestinationRoot(config, path)); map.put(Attributes.ROOTPATH, FileUtil.getUriPathToDestinationRoot(config, path)); render(new ModelRenderingConfig(path, "tagindex", model, findTemplateName("tagsindex"))); renderedCount++;