1 package net.sourceforge.cruisecontrol.labelincrementers; 2 3 import java.io.FileInputStream ; 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 import java.util.Properties ; 7 8 import net.sourceforge.cruisecontrol.LabelIncrementer; 9 10 import org.apache.log4j.Logger; 11 import org.jdom.Element; 12 13 public class PropertyFileLabelIncrementer implements LabelIncrementer { 14 private static final Logger LOG = Logger.getLogger(PropertyFileLabelIncrementer.class); 15 16 private String propertyFile; 17 18 private String propertyName; 19 20 private boolean preBuildIncrementer; 21 22 public String incrementLabel(String oldLabel, Element buildLog) { 23 return getLabel(); 24 } 25 26 public boolean isValidLabel(String label) { 27 return true; 28 } 29 30 public boolean isPreBuildIncrementer() { 31 return this.preBuildIncrementer; 32 } 33 34 public String getDefaultLabel() { 35 return getLabel(); 36 } 37 38 public void setPreBuildIncrementer(boolean preBuildIncrementer) { 39 this.preBuildIncrementer = preBuildIncrementer; 40 } 41 42 public void setPropertyFile(String propertyFile) { 43 this.propertyFile = propertyFile; 44 } 45 46 public void setPropertyName(String propertyName) { 47 this.propertyName = propertyName; 48 } 49 50 private String getLabel() { 51 InputStream is = null; 52 try { 53 is = new FileInputStream (propertyFile); 54 Properties p = new Properties (); 55 p.load(is); 56 57 String label = p.getProperty(propertyName); 58 LOG.info("Retrieved label " + label); 59 60 return label; 61 } catch (IOException ex) { 62 String msg = "Unable to retrieve label " + ex.getMessage(); 63 LOG.error(msg, ex); 64 throw new RuntimeException (msg); 65 } finally { 66 try { 67 if (is != null) { 68 is.close(); 69 } 70 } catch (Exception ex) { 71 } 72 } 73 } 74 75 } 76 | Popular Tags |