1 26 27 package net.sourceforge.groboutils.codecoverage.v2.logger; 28 29 import java.io.File ; 30 import java.util.Properties ; 31 32 import net.sourceforge.groboutils.codecoverage.v2.IChannelLogger; 33 import net.sourceforge.groboutils.codecoverage.v2.IChannelLoggerFactory; 34 35 36 48 public class MinDirChannelLoggerFactory implements IChannelLoggerFactory 49 { 50 public static final String DIRECTORY_PROPERTY = "dir"; 51 public static final String DEFAULT_DIRECTORY = "./.cover-logs"; 52 53 64 public IChannelLogger createChannelLogger( 65 String propertyPrefix, Properties props, short channelIndex ) 66 { 67 String directory = getDirectory( propertyPrefix, props ); 68 File dir = new File ( directory, Short.toString( channelIndex ) ); 69 if (dir.exists()) 70 { 71 if (!dir.isDirectory()) 72 { 73 System.err.println( 74 "MinDirLogger base directory is a file."); 75 dir = null; 76 } 77 } 78 else 79 { 80 dir.mkdirs(); 81 } 82 return new MinDirChannelLogger( dir ); 83 } 84 85 86 protected String getDirectory( String propertyPrefix, Properties props ) 87 { 88 String directory = props.getProperty( 89 propertyPrefix + DIRECTORY_PROPERTY ); 90 if (directory == null) 91 { 92 directory = DEFAULT_DIRECTORY; 93 } 94 return directory; 95 } 96 } 97 98 | Popular Tags |