Clover coverage report - Alipes Project - 0.1
Coverage timestamp: Sat Sep 10 2005 21:25:58 BST
file stats: LOC: 123   Methods: 3
NCLOC: 75   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FileWildCardChangeConsoleAlerter.java 0% 0% 0% 0%
coverage
 1    /*
 2    * $Id: FileShowAllConsoleAlerter.java,v 1.3 2004/03/09 22:29:32
 3    * johndavidtaylor Exp $ Created on Mar 10, 2004 by John Taylor jdt@roe.ac.uk .
 4    */
 5    package org.abraracourcix.alipes.alerters;
 6    import java.io.File;
 7    import java.io.IOException;
 8   
 9    import org.abraracourcix.alipes.common.RegExpCreator;
 10    import org.abraracourcix.alipes.listeners.Listener;
 11    import org.abraracourcix.alipes.listeners.filter.EventFilterListener;
 12    import org.abraracourcix.alipes.listeners.logging.ConsoleListener;
 13    import org.abraracourcix.alipes.monitors.file.FileEvent;
 14    import org.abraracourcix.alipes.monitors.file.FileStateMonitor;
 15    import org.abraracourcix.alipes.monitors.file.FileStateMonitorFactory;
 16    import org.apache.commons.logging.Log;
 17    import org.apache.commons.logging.LogFactory;
 18    /**
 19    * Takes a filename wildcard pattern, a stale interval, and watches those files
 20    * to see if they're deleted/stale/created or change @TODO sort out the
 21    * difficulty of entering wildcards on the commandline!
 22    *
 23    * @author jdt
 24    */
 25    public final class FileWildCardChangeConsoleAlerter {
 26    /**
 27    * Hide public Constructor
 28    *
 29    */
 30  0 private FileWildCardChangeConsoleAlerter() {
 31    }
 32    /**
 33    * Log
 34    */
 35    private static Log log =
 36    LogFactory.getLog(FileWildCardChangeConsoleAlerter.class);
 37    /**
 38    * Set the wheels in motion
 39    *
 40    * @param args
 41    * rootfolder wildcard staletime(seconds)
 42    * @throws InterruptedException
 43    * if you hit ctrl-C
 44    * @throws IOException
 45    * if there's a prob finding the files
 46    */
 47  0 public static void main(final String[] args)
 48    throws InterruptedException, IOException {
 49  0 if (args.length != 3) {
 50  0 giveHelp();
 51  0 return;
 52    }
 53  0 final String dirName = args[0];
 54  0 final String wildCards = args[1];
 55  0 final String interval = args[2];
 56  0 log.info("dirName=" + dirName);
 57  0 log.info("wildCards=" + wildCards);
 58  0 log.info("interval=" + interval);
 59  0 final File root = new File(dirName);
 60  0 if (!(root.exists())) {
 61  0 throw new IOException("Directory " + dirName + " doesn't exist");
 62    }
 63  0 if (!root.isDirectory()) {
 64  0 throw new IOException(dirName + " isn't a directory");
 65    }
 66  0 int intervalSecs;
 67  0 try {
 68  0 intervalSecs = Integer.parseInt(interval);
 69    } catch (NumberFormatException nfe) {
 70  0 throw new NumberFormatException("3rd argument must be an integer number of seconds ");
 71    }
 72  0 System.out.println("Ctrl-C when you're bored");
 73  0 final String regExp = RegExpCreator.getRegExp(wildCards);
 74  0 final ConsoleListener listener = new ConsoleListener();
 75  0 final FileEvent[] interestingEvents =
 76    {
 77    FileEvent.CREATED,
 78    FileEvent.DELETED,
 79    FileEvent.GONE_STALE,
 80    FileEvent.UPDATED };
 81  0 final Listener filter =
 82    new EventFilterListener(
 83    listener,
 84    interestingEvents,
 85    EventFilterListener.FilterType.INCLUDED);
 86  0 final int pollFrequency = 10; //in seconds
 87  0 final FileStateMonitor mon =
 88    FileStateMonitorFactory.getFileStateMonitor(
 89    root,
 90    regExp,
 91    filter,
 92    pollFrequency);
 93  0 mon.setStaleInterval(intervalSecs);
 94  0 Thread.sleep(24 * 60 * 60 * 1000); //wait forever, well a day anyway
 95    }
 96    /**
 97    *
 98    */
 99  0 private static void giveHelp() {
 100  0 System.out.println(
 101    "Usage:\n java -jar your_uber_jar_here.jar dir files staleInt");
 102  0 System.out.println("where:\ndir is the root directory e.g. /tmp");
 103  0 System.out.println("files is a wildcard expression e.g. *.txt");
 104  0 System.out.println(
 105    "and staleInt is the time in seconds before a file is considered stale");
 106    }
 107    }
 108    /*
 109    * $Log: FileWildCardChangeConsoleAlerter.java,v $
 110    * Revision 1.1 2004/04/27 10:57:51 johndavidtaylor
 111    * changed package name
 112    *
 113    * Revision 1.1 2004/03/17 21:16:51 johndavidtaylor
 114    * Copied across from incubation in beanpeeler
 115    *
 116    * Revision 1.2 2004/03/11 15:46:34 johndavidtaylor
 117    * Applied coding standards
 118    *
 119    * Revision 1.1 2004/03/11 09:49:22 johndavidtaylor
 120    * Loads of updates
 121    *
 122    *
 123    */