1/* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved. 2 * 3 * This program and the accompanying materials are made available under 4 * the terms of the Common Public License v1.0 which accompanies this distribution, 5 * and is available at http://www.eclipse.org/legal/cpl-v10.html 6 * 7 * $Id: SuppressableTask.java,v 1.1.1.1.2.2 2004/07/16 23:32:04 vlad_r Exp $ 8 */ 9package com.vladium.emma.ant; 10 11import java.io.File; 12 13import com.vladium.emma.IAppConstants; 14import com.vladium.util.IProperties; 15 16import org.apache.tools.ant.BuildException; 17import org.apache.tools.ant.Location; 18import org.apache.tools.ant.Task; 19 20// ---------------------------------------------------------------------------- 21/** 22 * @author Vlad Roubtsov, (C) 2003 23 */ 24public 25abstract class SuppressableTask extends Task 26{ 27 // public: ................................................................ 28 29 30 public void init () throws BuildException 31 { 32 super.init (); 33 34 m_verbosityCfg = new VerbosityCfg (); 35 m_genericCfg = new GenericCfg (this); 36 } 37 38 /** 39 * Set the optional 'enabled' attribute [defaults to 'true']. 40 */ 41 public final void setEnabled (final boolean enabled) 42 { 43 m_enabled = enabled; 44 } 45 46 public final boolean isEnabled () 47 { 48 return m_enabled; 49 } 50 51 // verbosity attribute: 52 53 public void setVerbosity (final VerbosityCfg.VerbosityAttribute verbosity) 54 { 55 m_verbosityCfg.setVerbosity (verbosity); 56 } 57 58 // verbosity class filter attribute: 59 60 public void setVerbosityfilter (final String filter) 61 { 62 m_verbosityCfg.setVerbosityfilter (filter); 63 } 64 65 // .properties file attribute: 66 67 public final void setProperties (final File file) 68 { 69 m_genericCfg.setProperties (file); 70 } 71 72 // generic property element: 73 74 public final PropertyElement createProperty () 75 { 76 return m_genericCfg.createProperty (); 77 } 78 79 80 public static BuildException newBuildException (final String msg, final Location location) 81 { 82 final String prefixedMsg = ((msg == null) || (msg.length () == 0)) 83 ? msg 84 : IAppConstants.APP_THROWABLE_BUILD_ID + " " + msg; 85 86 return new BuildException (prefixedMsg, location); 87 } 88 89 public static BuildException newBuildException (final String msg, final Throwable cause, final Location location) 90 { 91 final String prefixedMsg = ((msg == null) || (msg.length () == 0)) 92 ? msg 93 : IAppConstants.APP_THROWABLE_BUILD_ID + " " + msg; 94 95 return new BuildException (prefixedMsg, cause, location); 96 } 97 98 // protected: ............................................................. 99 100 101 protected SuppressableTask () 102 { 103 m_enabled = true; // by default, all tasks are enabled 104 } 105 106 protected IProperties getTaskSettings () 107 { 108 // (1) by default, generic settings are always more specific than any file settings 109 110 // (2) verbosity settings use dedicated attributes and hence are more specific 111 // than anything generic 112 113 final IProperties fileSettings = m_genericCfg.getFileSettings (); 114 final IProperties genericSettings = m_genericCfg.getGenericSettings (); 115 final IProperties verbositySettings = m_verbosityCfg.getSettings (); 116 117 return IProperties.Factory.combine (verbositySettings, 118 IProperties.Factory.combine (genericSettings, 119 fileSettings)); 120 } 121 122 // package: ............................................................... 123 124 // private: ............................................................... 125 126 127 private /*final*/ VerbosityCfg m_verbosityCfg; 128 private /*final*/ GenericCfg m_genericCfg; 129 private boolean m_enabled; 130 131} // end of class 132// ----------------------------------------------------------------------------