/* * [CompactWebsite.java] * * Summary: Feeds the entire website to the Compactor to squish HTML down to smallest size. * * 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: * 2.8 2009-04-04 no longer correct missing entities. Just issue warning messages. */ package com.mindprod.htmlmacros; import com.mindprod.commandline.CommandLine; import com.mindprod.common18.Misc; import com.mindprod.compactor.Compactor; import com.mindprod.filter.AllButSVNDirectoriesFilter; import com.mindprod.filter.ExtensionListFilter; import com.mindprod.htmlmacros.macro.Global; import java.io.File; import java.util.List; import static com.mindprod.htmlmacros.macro.Global.configuration; import static java.lang.System.*; /** * Feeds the entire website to the Compactor to squish HTML down to smallest size. * * @author Roedy Green, Canadian Mind Products * @version 2.8 2009-04-04 no longer correct missing entities. Just issue warning messages. * @since 2009 */ public final class CompactWebsite { /** * where files are we are to compact */ private static File webrootDir; /** * 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() { final List htmlDirs = configuration.getDirsContainingHTMLMacros(); final List includeDirs = configuration.getDirsContainingIncludes(); String[] args = new String[ htmlDirs.size() + includeDirs.size() + 1 ]; args[ 0 ] = "-q"; int i = 1; for ( String aDir : htmlDirs ) { args[ i++ ] = webrootDir + "\\" + aDir; } // add include dirs for ( String aDir : includeDirs ) { args[ i++ ] = webrootDir + "\\" + aDir; } filesToProcess = new CommandLine( args, new AllButSVNDirectoriesFilter(), new ExtensionListFilter( "html" ) ); } /** * Expands macros written in Java in HTML files files. * * @param args names of files to process, no wildcards. */ public static void main( String[] args ) { // anything on command line gets all files redone. // nothing, default gets recently changed files only. Global.installConfiguration( args ); webrootDir = new File( Global.configuration.getLocalWebrootWithSlashes() ); out.println( "Compacting the entire website." ); gatherFiles(); out.println( filesToProcess.size() + " files gathered for CompactWebsite" ); for ( File fileToProcess : filesToProcess ) { assert fileToProcess != null; assert fileToProcess.exists() : "file to process missing"; try { // works on masters, leaves macros in place. Compactor.compactFile( true /* quiet */, fileToProcess ); } catch ( Exception e ) { err.println(); e.printStackTrace( err ); err.println( "Compactor failed in file " + fileToProcess ); err.println(); } } out.println( "done" ); // don't remove the System.exit( 0 ). It bypasses a Sun bug. // It works OK in JET. Misc.trackLastThread(); System.exit( 0 ); } } // end CompactWebsite