| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.student.common.util; |
| 17 |
|
|
| 18 |
|
import java.io.IOException; |
| 19 |
|
import java.io.InputStream; |
| 20 |
|
import java.util.jar.Attributes; |
| 21 |
|
import java.util.jar.Manifest; |
| 22 |
|
|
| 23 |
|
import javax.servlet.ServletContext; |
| 24 |
|
|
| 25 |
|
import static org.apache.commons.io.IOUtils.*; |
| 26 |
|
import static org.apache.commons.lang.StringUtils.*; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
|
|
|
| 68.7% |
Uncovered Elements: 26 (83) |
Complexity: 19 |
Complexity Density: 0.37 |
|
| 31 |
|
public class ManifestInspector { |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
public static final String MANIFEST_LOCATION = "/META-INF/MANIFEST.MF"; |
| 37 |
|
public static final String BUNDLE_NAME = "Bundle-Name"; |
| 38 |
|
public static final String BUNDLE_VERSION = "Bundle-Version"; |
| 39 |
|
public static final String BUNDLE_TIMESTAMP = "Bundle-Timestamp"; |
| 40 |
|
public static final String BUNDLE_BUILD_NUMBER = "Bundle-BuildNumber"; |
| 41 |
|
public static final String NO_BUILD_INFORMATION_AVAILABLE = "No build information available"; |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 46 |
0
|
protected Manifest getManifest(ServletContext servletContext) throws IOException {... |
| 47 |
0
|
InputStream in = null; |
| 48 |
0
|
try { |
| 49 |
0
|
in = servletContext.getResourceAsStream(MANIFEST_LOCATION); |
| 50 |
0
|
if (in == null) { |
| 51 |
0
|
return null; |
| 52 |
|
} else { |
| 53 |
0
|
return new Manifest(in); |
| 54 |
|
} |
| 55 |
|
} catch (IOException e) { |
| 56 |
0
|
throw e; |
| 57 |
|
} finally { |
| 58 |
0
|
closeQuietly(in); |
| 59 |
|
} |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
|
| 65 |
4
|
protected BuildInformation getBuildInformation(Manifest manifest) {... |
| 66 |
|
|
| 67 |
4
|
if (manifest == null) { |
| 68 |
1
|
return null; |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
|
| 72 |
3
|
Attributes attributes = manifest.getMainAttributes(); |
| 73 |
|
|
| 74 |
|
|
| 75 |
3
|
String name = attributes.getValue(BUNDLE_NAME); |
| 76 |
3
|
String version = attributes.getValue(BUNDLE_VERSION); |
| 77 |
3
|
String buildNumber = attributes.getValue(BUNDLE_BUILD_NUMBER); |
| 78 |
3
|
String timestamp = attributes.getValue(BUNDLE_TIMESTAMP); |
| 79 |
|
|
| 80 |
|
|
| 81 |
3
|
BuildInformation bi = new BuildInformation(); |
| 82 |
3
|
bi.setName(name); |
| 83 |
3
|
bi.setVersion(version); |
| 84 |
3
|
bi.setBuildNumber(buildNumber); |
| 85 |
3
|
bi.setTimestamp(timestamp); |
| 86 |
3
|
return bi; |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 92 |
0
|
public String getBuildInformationString(ServletContext context) throws IOException {... |
| 93 |
|
|
| 94 |
0
|
Manifest manifest = getManifest(context); |
| 95 |
|
|
| 96 |
|
|
| 97 |
0
|
BuildInformation buildInformation = getBuildInformation(manifest); |
| 98 |
|
|
| 99 |
|
|
| 100 |
0
|
return toString(buildInformation); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
|
|
|
| 61.9% |
Uncovered Elements: 8 (21) |
Complexity: 6 |
Complexity Density: 0.55 |
|
| 106 |
6
|
protected boolean isNullOrEmpty(BuildInformation bi) {... |
| 107 |
6
|
if (bi == null) { |
| 108 |
0
|
return true; |
| 109 |
|
} |
| 110 |
6
|
if (!isEmpty(bi.getName())) { |
| 111 |
4
|
return false; |
| 112 |
|
} |
| 113 |
2
|
if (!isEmpty(bi.getVersion())) { |
| 114 |
0
|
return false; |
| 115 |
|
} |
| 116 |
2
|
if (!isEmpty(bi.getBuildNumber())) { |
| 117 |
0
|
return false; |
| 118 |
|
} |
| 119 |
2
|
if (!isEmpty(bi.getTimestamp())) { |
| 120 |
0
|
return false; |
| 121 |
|
} |
| 122 |
2
|
return true; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
|
|
|
| 89.7% |
Uncovered Elements: 3 (29) |
Complexity: 7 |
Complexity Density: 0.41 |
|
| 128 |
3
|
public String toString(BuildInformation bi) {... |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
3
|
if (isNullOrEmpty(bi)) { |
| 136 |
1
|
return NO_BUILD_INFORMATION_AVAILABLE; |
| 137 |
|
} |
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
2
|
if (!isEmpty(bi.getBuildNumber())) { |
| 143 |
1
|
bi.setBuildNumber("#" + bi.getBuildNumber()); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
2
|
StringBuffer sb = new StringBuffer(); |
| 150 |
2
|
if (!isEmpty(bi.getName())) { |
| 151 |
2
|
sb.append(bi.getName()); |
| 152 |
2
|
sb.append(" :: "); |
| 153 |
|
} |
| 154 |
2
|
if (!isEmpty(bi.getVersion())) { |
| 155 |
2
|
sb.append(bi.getVersion()); |
| 156 |
2
|
sb.append(" :: "); |
| 157 |
|
} |
| 158 |
2
|
if (!isEmpty(bi.getBuildNumber())) { |
| 159 |
1
|
sb.append(bi.getBuildNumber()); |
| 160 |
1
|
sb.append(" :: "); |
| 161 |
|
} |
| 162 |
2
|
if (!isEmpty(bi.getTimestamp())) { |
| 163 |
2
|
sb.append(bi.getTimestamp()); |
| 164 |
|
} |
| 165 |
2
|
return sb.toString(); |
| 166 |
|
} |
| 167 |
|
} |