EMMA Coverage Report (generated Mon Mar 20 21:34:30 PST 2006)
[all classes][com.moesol.util]

COVERAGE SUMMARY FOR SOURCE FILE [BaseVersionProperties.java]

nameclass, %method, %block, %line, %
BaseVersionProperties.java100% (1/1)71%  (5/7)51%  (63/123)51%  (19/37)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BaseVersionProperties100% (1/1)71%  (5/7)51%  (63/123)51%  (19/37)
changedVersionProperties (String): boolean 0%   (0/1)0%   (0/28)0%   (0/7)
writeVersionProperties (String): void 0%   (0/1)0%   (0/22)0%   (0/7)
writeVersionProperties (Writer): void 100% (1/1)67%  (12/18)67%  (4/6)
checkForChanges (Properties): boolean 100% (1/1)83%  (19/23)71%  (5/7)
BaseVersionProperties (): void 100% (1/1)100% (8/8)100% (2/2)
changedProperty (Properties, String): boolean 100% (1/1)100% (21/21)100% (7/7)
getProperties (): Properties 100% (1/1)100% (3/3)100% (1/1)

1/*
2 * $Id: BaseVersionProperties.java,v 1.4 2006/02/15 08:10:55 hastings Exp $
3 *
4 * (c) Copyright, Moebius Solutions, Inc., 2004
5 *
6 *                       All Rights Reserved
7 *
8 * This material may be reproduced by or for the U. S. Government
9 * pursuant to the copyright license under the clause at
10 * DFARS 252.227-7014 (OCT 2001).
11 */
12package com.moesol.util;
13 
14import java.io.FileInputStream;
15import java.io.FileNotFoundException;
16import java.io.FileWriter;
17import java.io.IOException;
18import java.io.Writer;
19import java.util.Properties;
20 
21import com.moesol.generator.core.ApplyException;
22import com.moesol.generator.core.Template;
23 
24/**
25 * @author Hastings
26 */
27public class BaseVersionProperties {
28 
29        protected Properties m_properties = new Properties();
30 
31        public Properties getProperties() {
32                return m_properties;
33        }
34 
35        protected void writeVersionProperties(Writer wr) throws IOException {
36                Template t = new Template(
37                                "buildVersion=${buildVersion}\n" +
38                                "buildVersionCommas=${buildVersionCommas}\n" +
39                                "buildDate=${buildDate}\n");
40                try {
41                        t.apply(m_properties, wr);
42                } catch (ApplyException e) {
43                        throw new RuntimeException(e);
44                }
45        }
46 
47        protected void writeVersionProperties(String outputname) throws IOException {
48                if (!changedVersionProperties(outputname)) {
49                        return;
50                }
51                
52                FileWriter fr = new FileWriter(outputname);
53                try {
54                        writeVersionProperties(fr);
55                } finally {
56                        fr.close();
57                }
58        }
59        private boolean changedVersionProperties(String outputname) throws IOException {
60                try {
61                        FileInputStream fis = new FileInputStream(outputname);
62 
63                        try {
64                                Properties checker = new Properties();
65                                checker.load(fis);
66                                return checkForChanges(checker);
67                        } finally {
68                                fis.close();
69                        }
70                } catch (FileNotFoundException e) {
71                        return true;
72                }
73        }
74        /**
75         * @param checker
76         * @return true if buildVersion, buildVersionCommas, or buildDate
77     * are different than checker.
78         */
79        boolean checkForChanges(Properties checker) {
80                if (changedProperty(checker, "buildVersion")) {
81                        return true;
82                }
83                if (changedProperty(checker, "buildVersionCommas")) {
84                        return true;
85                }
86                if (changedProperty(checker, "buildDate")) {
87                        return true;
88                }
89                return false;
90        }
91 
92        private boolean changedProperty(Properties old, String prop) {
93                String old_value = old.getProperty(prop);
94                String new_value = m_properties.getProperty(prop);
95                if (old_value == null) {
96                        return true;
97                }
98                if (!old_value.equals(new_value)) {
99                        return true;
100                }
101                return false;
102        }
103        
104        
105 
106 
107}

[all classes][com.moesol.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov