EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.prototype.framework.utils]

COVERAGE SUMMARY FOR SOURCE FILE [RunProperties.java]

nameclass, %method, %block, %line, %
RunProperties.java0%   (0/1)0%   (0/11)0%   (0/168)0%   (0/43)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RunProperties0%   (0/1)0%   (0/11)0%   (0/168)0%   (0/43)
<static initializer> 0%   (0/1)0%   (0/3)0%   (0/2)
RunProperties (CommandLine, Options): void 0%   (0/1)0%   (0/48)0%   (0/14)
getLongOpt (String): String 0%   (0/1)0%   (0/15)0%   (0/4)
getOptionObject (String): Object 0%   (0/1)0%   (0/5)0%   (0/1)
getOptionObject (char): Object 0%   (0/1)0%   (0/11)0%   (0/2)
getOptionValue (String): String 0%   (0/1)0%   (0/27)0%   (0/6)
getOptionValue (char): String 0%   (0/1)0%   (0/11)0%   (0/2)
getPropertyFromFile (String): String 0%   (0/1)0%   (0/10)0%   (0/3)
hasOption (String): boolean 0%   (0/1)0%   (0/13)0%   (0/2)
hasOption (char): boolean 0%   (0/1)0%   (0/11)0%   (0/2)
hasPropertyInFile (String): boolean 0%   (0/1)0%   (0/14)0%   (0/5)

1package de.uka.ipd.sdq.prototype.framework.utils;
2 
3import java.io.FileInputStream;
4import java.io.FileNotFoundException;
5import java.io.IOException;
6import java.util.Properties;
7 
8import org.apache.commons.cli.CommandLine;
9import org.apache.commons.cli.Options;
10import org.apache.log4j.Logger;
11 
12public class RunProperties
13{
14        private static final long serialVersionUID = -5663835008494398378L;
15        
16        private CommandLine cmdLine;
17        private Options options;
18        private Properties propertyFile = null;
19        
20        private static Logger logger = org.apache.log4j.Logger.getRootLogger();
21        
22        public RunProperties(CommandLine cmdLine, Options options)
23        {
24                super();
25                this.cmdLine = cmdLine;
26                this.options = options;
27                
28                if(cmdLine.hasOption("f"))
29                {
30                        propertyFile = new Properties();
31                        try {
32                                propertyFile.load(new FileInputStream(cmdLine.getOptionValue("f")));
33                        } catch (FileNotFoundException e) {
34                                logger.error("Property file could not be found.",e);
35                                propertyFile = null;
36                        } catch (IOException e) {
37                                logger.debug("Error reading property file.",e);
38                                propertyFile = null;
39                        }
40                }
41        }
42        
43        private String getPropertyFromFile(String key)
44        {
45                if(propertyFile != null)
46                {
47                        return propertyFile.getProperty(key);
48                }
49                return null;
50        }
51        
52        private boolean hasPropertyInFile(String key)
53        {
54                if(propertyFile != null)
55                {
56                        if(propertyFile.getProperty(key) == null)
57                        {
58                                return false;
59                        }
60                        else
61                        {
62                                return true;
63                        }
64                }
65                return false;
66        }
67        
68        private String getLongOpt(String opt)
69        {
70                String longOpt = opt;
71                
72                if(options.hasOption(opt))
73                {
74                        longOpt = options.getOption(opt).getLongOpt();
75                }
76                
77                return longOpt;
78        }
79        
80        public String getOptionValue(char opt)
81        {
82                String sOpt = ""+opt;
83                return getOptionValue(sOpt);
84        }
85        
86        public String getOptionValue(String opt)
87        { 
88                if(cmdLine.hasOption(opt))
89                {
90                        return cmdLine.getOptionValue(opt);
91                }
92                else // look in file
93                {
94                        String longOpt = getLongOpt(opt);
95                        
96                        if(hasPropertyInFile(longOpt))
97                        {
98                                return getPropertyFromFile(longOpt);
99                        }
100                        else
101                        {
102                                return cmdLine.getOptionValue(opt);
103                        }
104                }
105        }
106 
107        public boolean hasOption(char opt)
108        {
109                String sOpt = ""+opt;
110                return hasOption(sOpt);
111        }
112 
113        public boolean hasOption(String opt)
114        {
115                if(hasPropertyInFile(getLongOpt(opt))) return true;
116                return cmdLine.hasOption(opt);
117        }
118 
119        public Object getOptionObject(char opt)
120        {
121                String sOpt = ""+opt;
122                return getOptionObject(sOpt);
123        }
124 
125        public Object getOptionObject(String opt)
126        {
127                return cmdLine.getOptionObject(opt);
128        }
129}

[all classes][de.uka.ipd.sdq.prototype.framework.utils]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov