private void checkRequiredFolderExists(String folderName, File path) { if (!FileUtil.isExistingFolder(path)) { throw new JBakeException("Error: Required folder cannot be found! Expected to find [" + folderName + "] at: " + path.getAbsolutePath()); } }
private void ensureDestination() { File destination = configuration.getDestinationFolder(); if (!destination.exists()) { destination.mkdirs(); } if (!destination.canWrite()) { throw new JBakeException("Error: Destination folder is not writable: " + destination.getAbsolutePath()); } }
private void ensureSource() throws JBakeException { File source = configuration.getSourceFolder(); if (!FileUtil.isExistingFolder(source)) { throw new JBakeException("Error: Source folder must exist: " + source.getAbsolutePath()); } if (!configuration.getSourceFolder().canRead()) { throw new JBakeException("Error: Source folder is not readable: " + source.getAbsolutePath()); } }
public void bake(final JBakeConfiguration config) { final Oven oven = new Oven(config); oven.bake(); final List<Throwable> errors = oven.getErrors(); if (!errors.isEmpty()) { final StringBuilder msg = new StringBuilder(); // TODO: decide, if we want the all errors here msg.append( MessageFormat.format("JBake failed with {0} errors:\n", errors.size())); int errNr = 1; for (final Throwable error : errors) { msg.append(MessageFormat.format("{0}. {1}\n", errNr, error.getMessage())); ++errNr; } throw new JBakeException(msg.toString(), errors.get(0)); } } }
private LaunchOptions parseArguments(String[] args) { LaunchOptions res = new LaunchOptions(); CmdLineParser parser = new CmdLineParser(res); try { parser.parseArgument(args); } catch (final CmdLineException e) { printUsage(res); throw new JBakeException("Invalid commandline arguments: " + e.getMessage(), e); } return res; }
private CompositeConfiguration load(File source) throws ConfigurationException { if (!source.exists()) { throw new JBakeException("The given source folder '" + source.getAbsolutePath() + "' does not exist."); } if (!source.isDirectory()) { throw new JBakeException("The given source folder is not a directory."); } CompositeConfiguration config = new CompositeConfiguration(); config.setListDelimiter(','); File customConfigFile = new File(source, LEGACY_CONFIG_FILE); if (customConfigFile.exists()) { displayLegacyConfigFileWarningIfRequired(); config.addConfiguration(new PropertiesConfiguration(customConfigFile)); } customConfigFile = new File(source, CONFIG_FILE); if (customConfigFile.exists()) { config.addConfiguration(new PropertiesConfiguration(customConfigFile)); } config.addConfiguration(new PropertiesConfiguration(DEFAULT_CONFIG_FILE)); config.addConfiguration(new SystemConfiguration()); return config; }
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); } }
/** * Get a document by sourceUri and update it from the given map. * @param incomingDocMap The document's db columns. * @return The saved document. * @throws IllegalArgumentException if sourceUri or docType are null, or if the document doesn't exist. */ public ODocument mergeDocument(Map<String, ? extends Object> incomingDocMap) { String sourceUri = (String) incomingDocMap.get(DocumentAttributes.SOURCE_URI.toString()); if (null == sourceUri) throw new IllegalArgumentException("Document sourceUri is null."); String docType = (String) incomingDocMap.get(Crawler.Attributes.TYPE); if (null == docType) throw new IllegalArgumentException("Document docType is null."); // Get a document by sourceUri String sql = "SELECT * FROM " + docType + " WHERE sourceuri=?"; activateOnCurrentThread(); List<ODocument> results = db.command(new OSQLSynchQuery<ODocument>(sql)).execute(sourceUri); if (results.size() == 0) throw new JBakeException("No document with sourceUri '"+sourceUri+"'."); // Update it from the given map. ODocument incomingDoc = new ODocument(docType); incomingDoc.fromMap(incomingDocMap); ODocument merged = results.get(0).merge(incomingDoc, true, false); return merged; }
protected void run(String[] args) { SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); LaunchOptions res = parseArguments(args); final JBakeConfiguration config; try { if (res.isRunServer()) { config = getJBakeConfigurationFactory().createJettyJbakeConfiguration(res.getSource(), res.getDestination(), res.isClearCache()); } else { config = getJBakeConfigurationFactory().createDefaultJbakeConfiguration(res.getSource(), res.getDestination(), res.isClearCache()); } } catch (final ConfigurationException e) { throw new JBakeException("Configuration error: " + e.getMessage(), e); } run(res, config); }
private void ensureDestination() { File destination = configuration.getDestinationFolder(); if (!destination.exists()) { destination.mkdirs(); } if (!destination.canWrite()) { throw new JBakeException("Error: Destination folder is not writable: " + destination.getAbsolutePath()); } }
private void checkRequiredFolderExists(String folderName, File path) { if (!FileUtil.isExistingFolder(path)) { throw new JBakeException("Error: Required folder cannot be found! Expected to find [" + folderName + "] at: " + path.getAbsolutePath()); } }
private void ensureSource() throws JBakeException { File source = configuration.getSourceFolder(); if (!FileUtil.isExistingFolder(source)) { throw new JBakeException("Error: Source folder must exist: " + source.getAbsolutePath()); } if (!configuration.getSourceFolder().canRead()) { throw new JBakeException("Error: Source folder is not readable: " + source.getAbsolutePath()); } }
public void bake(final JBakeConfiguration config) { final Oven oven = new Oven(config); oven.bake(); final List<Throwable> errors = oven.getErrors(); if (!errors.isEmpty()) { final StringBuilder msg = new StringBuilder(); // TODO: decide, if we want the all errors here msg.append( MessageFormat.format("JBake failed with {0} errors:\n", errors.size())); int errNr = 1; for (final Throwable error : errors) { msg.append(MessageFormat.format("{0}. {1}\n", errNr, error.getMessage())); ++errNr; } throw new JBakeException(msg.toString(), errors.get(0)); } } }
private LaunchOptions parseArguments(String[] args) { LaunchOptions res = new LaunchOptions(); CmdLineParser parser = new CmdLineParser(res); try { parser.parseArgument(args); } catch (final CmdLineException e) { printUsage(res); throw new JBakeException("Invalid commandline arguments: " + e.getMessage(), e); } return res; }
private CompositeConfiguration load(File source) throws ConfigurationException { if (!source.exists()) { throw new JBakeException("The given source folder '" + source.getAbsolutePath() + "' does not exist."); } if (!source.isDirectory()) { throw new JBakeException("The given source folder is not a directory."); } CompositeConfiguration config = new CompositeConfiguration(); config.setListDelimiter(','); File customConfigFile = new File(source, LEGACY_CONFIG_FILE); if (customConfigFile.exists()) { displayLegacyConfigFileWarningIfRequired(); config.addConfiguration(new PropertiesConfiguration(customConfigFile)); } customConfigFile = new File(source, CONFIG_FILE); if (customConfigFile.exists()) { config.addConfiguration(new PropertiesConfiguration(customConfigFile)); } config.addConfiguration(new PropertiesConfiguration(DEFAULT_CONFIG_FILE)); config.addConfiguration(new SystemConfiguration()); return config; }
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); } }
/** * Get a document by sourceUri and update it from the given map. * @param incomingDocMap The document's db columns. * @return The saved document. * @throws IllegalArgumentException if sourceUri or docType are null, or if the document doesn't exist. */ public ODocument mergeDocument(Map<String, ? extends Object> incomingDocMap) { String sourceUri = (String) incomingDocMap.get(DocumentAttributes.SOURCE_URI.toString()); if (null == sourceUri) throw new IllegalArgumentException("Document sourceUri is null."); String docType = (String) incomingDocMap.get(Crawler.Attributes.TYPE); if (null == docType) throw new IllegalArgumentException("Document docType is null."); // Get a document by sourceUri String sql = "SELECT * FROM " + docType + " WHERE sourceuri=?"; activateOnCurrentThread(); List<ODocument> results = db.command(new OSQLSynchQuery<ODocument>(sql)).execute(sourceUri); if (results.size() == 0) throw new JBakeException("No document with sourceUri '"+sourceUri+"'."); // Update it from the given map. ODocument incomingDoc = new ODocument(docType); incomingDoc.fromMap(incomingDocMap); ODocument merged = results.get(0).merge(incomingDoc, true, false); return merged; }
protected void run(String[] args) { SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); LaunchOptions res = parseArguments(args); final JBakeConfiguration config; try { if (res.isRunServer()) { config = getJBakeConfigurationFactory().createJettyJbakeConfiguration(res.getSource(), res.getDestination(), res.isClearCache()); } else { config = getJBakeConfigurationFactory().createDefaultJbakeConfiguration(res.getSource(), res.getDestination(), res.isClearCache()); } } catch (final ConfigurationException e) { throw new JBakeException("Configuration error: " + e.getMessage(), e); } run(res, config); }