| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
package com.atlassian.core.util; |
| 10 |
|
|
| 11 |
|
import com.opensymphony.module.propertyset.PropertySet; |
| 12 |
|
import org.apache.log4j.Category; |
| 13 |
|
import org.apache.log4j.Logger; |
| 14 |
|
|
| 15 |
|
import java.util.Collection; |
| 16 |
|
import java.util.Iterator; |
| 17 |
|
import java.util.Properties; |
| 18 |
|
import java.io.*; |
| 19 |
|
|
|
|
|
| 72.9% |
Uncovered Elements: 29 (107) |
Complexity: 32 |
Complexity Density: 0.56 |
|
| 20 |
|
public class PropertyUtils |
| 21 |
|
{ |
| 22 |
|
private static final Logger log = Logger.getLogger(PropertyUtils.class); |
| 23 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 24 |
0
|
public static Properties getProperties(String resource, Class callingClass)... |
| 25 |
|
{ |
| 26 |
0
|
return getPropertiesFromStream(ClassLoaderUtils.getResourceAsStream(resource, callingClass)); |
| 27 |
|
} |
| 28 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 29 |
0
|
public static Properties getPropertiesFromFile(File file)... |
| 30 |
|
{ |
| 31 |
0
|
try |
| 32 |
|
{ |
| 33 |
0
|
return getPropertiesFromStream(new FileInputStream(file)); |
| 34 |
|
} |
| 35 |
|
catch (FileNotFoundException e) |
| 36 |
|
{ |
| 37 |
0
|
log.error("Error loading properties from file: " + file.getPath() + ". File does not exist.", e); |
| 38 |
0
|
return null; |
| 39 |
|
} |
| 40 |
|
} |
| 41 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 42 |
0
|
public static Properties getPropertiesFromStream(InputStream is)... |
| 43 |
|
{ |
| 44 |
0
|
if (is == null) |
| 45 |
0
|
return null; |
| 46 |
|
|
| 47 |
0
|
Properties props = new Properties(); |
| 48 |
0
|
try |
| 49 |
|
{ |
| 50 |
0
|
props.load(is); |
| 51 |
|
} |
| 52 |
|
catch (IOException e) |
| 53 |
|
{ |
| 54 |
0
|
log.error("Error loading properties from stream.", e); |
| 55 |
|
} |
| 56 |
|
finally |
| 57 |
|
{ |
| 58 |
0
|
FileUtils.shutdownStream(is); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
0
|
return props; |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
@param |
| 69 |
|
@param |
| 70 |
|
@return |
| 71 |
|
|
|
|
|
| 87.5% |
Uncovered Elements: 11 (88) |
Complexity: 26 |
Complexity Density: 0.59 |
|
| 72 |
20
|
public static boolean identical(PropertySet pThis, PropertySet pThat)... |
| 73 |
|
{ |
| 74 |
|
|
| 75 |
20
|
if (pThis == null && pThat == null) |
| 76 |
1
|
return true; |
| 77 |
|
|
| 78 |
|
|
| 79 |
19
|
if (pThis == null || pThat == null) |
| 80 |
2
|
return false; |
| 81 |
|
|
| 82 |
17
|
Collection thisKeys = pThis.getKeys(); |
| 83 |
17
|
Collection thatKeys = pThat.getKeys(); |
| 84 |
|
|
| 85 |
17
|
if (!thisKeys.containsAll(thatKeys) || !thatKeys.containsAll(thisKeys)) |
| 86 |
1
|
return false; |
| 87 |
|
|
| 88 |
16
|
Iterator thisKeysIterator = thisKeys.iterator(); |
| 89 |
16
|
String key; |
| 90 |
16
|
int keyType; |
| 91 |
36
|
while (thisKeysIterator.hasNext()) |
| 92 |
|
{ |
| 93 |
28
|
key = (String) thisKeysIterator.next(); |
| 94 |
28
|
keyType = pThis.getType(key); |
| 95 |
28
|
if (PropertySet.BOOLEAN == keyType) |
| 96 |
|
{ |
| 97 |
4
|
if (pThis.getBoolean(key) != pThat.getBoolean(key)) |
| 98 |
1
|
return false; |
| 99 |
|
} |
| 100 |
24
|
else if (PropertySet.DATA == keyType) |
| 101 |
|
{ |
| 102 |
0
|
throw new IllegalArgumentException("DATA Comparision has not been implemented in PropertyUtil"); |
| 103 |
|
} |
| 104 |
24
|
else if (PropertySet.DATE == keyType) |
| 105 |
|
{ |
| 106 |
4
|
if (!pThis.getDate(key).equals(pThat.getDate(key))) |
| 107 |
1
|
return false; |
| 108 |
|
} |
| 109 |
20
|
else if (PropertySet.DOUBLE == keyType) |
| 110 |
|
{ |
| 111 |
4
|
if (pThis.getDouble(key) != pThat.getDouble(key)) |
| 112 |
1
|
return false; |
| 113 |
|
} |
| 114 |
16
|
else if (PropertySet.INT == keyType) |
| 115 |
|
{ |
| 116 |
4
|
if (pThis.getInt(key) != pThat.getInt(key)) |
| 117 |
1
|
return false; |
| 118 |
|
} |
| 119 |
12
|
else if (PropertySet.OBJECT == keyType) |
| 120 |
|
{ |
| 121 |
0
|
throw new IllegalArgumentException("OBJECT Comparision has not been implemented in PropertyUtil"); |
| 122 |
|
} |
| 123 |
12
|
else if (PropertySet.PROPERTIES == keyType) |
| 124 |
|
{ |
| 125 |
0
|
throw new IllegalArgumentException("PROPERTIES Comparision has not been implemented in PropertyUtil"); |
| 126 |
|
} |
| 127 |
12
|
else if (PropertySet.LONG == keyType) |
| 128 |
|
{ |
| 129 |
4
|
if (pThis.getLong(key) != pThat.getLong(key)) |
| 130 |
1
|
return false; |
| 131 |
|
} |
| 132 |
8
|
else if (PropertySet.STRING == keyType) |
| 133 |
|
{ |
| 134 |
4
|
if (!pThis.getString(key).equals(pThat.getString(key))) |
| 135 |
1
|
return false; |
| 136 |
|
} |
| 137 |
4
|
else if (PropertySet.TEXT == keyType) |
| 138 |
|
{ |
| 139 |
4
|
if (!pThis.getText(key).equals(pThat.getText(key))) |
| 140 |
2
|
return false; |
| 141 |
|
} |
| 142 |
0
|
else if (PropertySet.XML == keyType) |
| 143 |
|
{ |
| 144 |
0
|
throw new IllegalArgumentException("XML Comparision has not been implemented in PropertyUtil"); |
| 145 |
|
} |
| 146 |
|
} |
| 147 |
|
|
| 148 |
8
|
return true; |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
} |