/* * [ReplaceWebsite.java] * * Summary: Feeds the entire Mindprod website to Replacer to refresh all macro expansions. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.8 2009-02-06 include go package in ZIP bundle. * boilerplate refresher macros e.g. dog Allows arbitrary expander macro * code. * Futures: Error messages give offset/line number, nearby text check for generated by macro not just * generated to * remove old text. Can embed a " in a parm by encoding it as " * 1.9 2010-01-23 new configuration design with interface and multiple dynamic configurations */ package com.mindprod.htmlmacros; import com.mindprod.commandline.CommandLine; import com.mindprod.common18.EIO; import com.mindprod.common18.Misc; import com.mindprod.filter.AllButFootDirectoriesFilter; import com.mindprod.filter.ExtensionListFilter; import com.mindprod.htmlmacros.macro.Global; import com.mindprod.htmlmacros.support.Embellishment; import com.mindprod.htmlmacros.support.Fireup; import com.mindprod.htmlmacros.support.Shutdown; import com.mindprod.stores.Stock; import java.io.File; import java.util.List; import static com.mindprod.htmlmacros.macro.Global.configuration; import static java.lang.System.*; /** * Feeds the entire Mindprod website to Replacer to refresh all macro expansions. * * @author Roedy Green, Canadian Mind Products * @version 1.9 2010-01-23 new configuration design with interface and multiple dynamic configurations * @since 2009 */ public final class ReplaceWebsite extends Replacer { /** * where we build list of files to process, contains fully qualified file names. */ private static CommandLine filesToProcess; /** * Get fully qualified name of all the files to process. */ private static void gatherFiles() { // just HTML dirs, not the include dirs. Not the KJV dirs. final List htmlDirs = configuration.getDirsContainingHTMLMacros(); final String[] args = new String[ htmlDirs.size() + 1 ]; // fake in a quiet to suppress list of all dirs to proces args[ 0 ] = "-q"; // fake a command line with all dirs spelled out individually. int i = 1; final String localWebrootDir = configuration.getLocalWebrootWithBackslashes(); for ( String aDir : htmlDirs ) { args[ i++ ] = localWebrootDir + "\\" + aDir; } filesToProcess = new CommandLine( args, new AllButFootDirectoriesFilter(), new ExtensionListFilter( ExtensionListFilter.COMMON_HTML_EXTENSIONS ) ); } /** * Expands macros written in Java in HTML files files. * * @param args not used. Configuration and list of files is hard coded. */ public static void main( final String[] args ) { Global.installConfiguration( args ); out.println( "Expanding macros on entire " + Global.configuration.getLocalWebrootWithBackslashes() + " website" ); gatherFiles(); out.println( filesToProcess.size() + " files gathered for website site macro expansion." ); final boolean quiet = filesToProcess.isQuiet(); final boolean verbose = filesToProcess.isVerbose(); Fireup.fireup(); Stock.DeadwoodCheckSafe(); /* we are processing all files, so a deadwood check makes sense */ // marker file to request graceful stop final File stop = new File( configuration.getLocalWebrootWithSlashes() + "/busy/stop.dat" ); for ( File fileToProcess : filesToProcess ) { assert fileToProcess.exists() : "file to process missing"; try { final boolean alwaysRegenerate = Global.configuration.alwaysRegenerate( fileToProcess ); final boolean containsRandomQuotation = Embellishment.QUOTATION.isFileEmbellishedWithThisLetter( fileToProcess ); if ( expandMacrosInFile( fileToProcess, quiet, verbose, alwaysRegenerate || containsRandomQuotation ) ) { break; } } catch ( Exception e ) { err.println(); e.printStackTrace( err ); err.println( " in file " + EIO.getCanOrAbsPath( fileToProcess ) ); err.println(); // we don't exit. We keep on processing files. } } // end for each file loop Shutdown.shutdown(); Misc.trackLastThread(); out.println( "ReplaceWebsite done" ); System.exit( 0 ); } // end main } // end ReplaceMindProd