| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.owasp.dependencycheck.analyzer; |
| 20 | |
|
| 21 | |
import java.io.File; |
| 22 | |
import java.util.Enumeration; |
| 23 | |
import java.util.logging.Level; |
| 24 | |
import java.util.logging.Logger; |
| 25 | |
import javax.xml.bind.JAXBException; |
| 26 | |
import javax.xml.parsers.ParserConfigurationException; |
| 27 | |
import org.owasp.dependencycheck.Engine; |
| 28 | |
import org.owasp.dependencycheck.dependency.Dependency; |
| 29 | |
import org.owasp.dependencycheck.dependency.Evidence; |
| 30 | |
import org.owasp.dependencycheck.dependency.EvidenceCollection; |
| 31 | |
import java.io.IOException; |
| 32 | |
import java.io.InputStreamReader; |
| 33 | |
import java.io.Reader; |
| 34 | |
import java.util.ArrayList; |
| 35 | |
import java.util.HashMap; |
| 36 | |
import java.util.List; |
| 37 | |
import java.util.Map; |
| 38 | |
import java.util.Map.Entry; |
| 39 | |
import java.util.Properties; |
| 40 | |
import java.util.Set; |
| 41 | |
import java.util.StringTokenizer; |
| 42 | |
import java.util.jar.Attributes; |
| 43 | |
import java.util.jar.JarEntry; |
| 44 | |
import java.util.jar.JarFile; |
| 45 | |
import java.util.jar.Manifest; |
| 46 | |
import java.util.regex.Pattern; |
| 47 | |
import java.util.zip.ZipEntry; |
| 48 | |
import javax.xml.bind.JAXBContext; |
| 49 | |
import javax.xml.bind.JAXBElement; |
| 50 | |
import javax.xml.bind.Unmarshaller; |
| 51 | |
import javax.xml.parsers.SAXParser; |
| 52 | |
import javax.xml.parsers.SAXParserFactory; |
| 53 | |
import javax.xml.transform.sax.SAXSource; |
| 54 | |
import org.jsoup.Jsoup; |
| 55 | |
import org.owasp.dependencycheck.jaxb.pom.MavenNamespaceFilter; |
| 56 | |
import org.owasp.dependencycheck.jaxb.pom.generated.License; |
| 57 | |
import org.owasp.dependencycheck.jaxb.pom.generated.Model; |
| 58 | |
import org.owasp.dependencycheck.jaxb.pom.generated.Organization; |
| 59 | |
import org.owasp.dependencycheck.utils.NonClosingStream; |
| 60 | |
import org.xml.sax.InputSource; |
| 61 | |
import org.xml.sax.SAXException; |
| 62 | |
import org.xml.sax.XMLFilter; |
| 63 | |
import org.xml.sax.XMLReader; |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
public class JarAnalyzer extends AbstractAnalyzer implements Analyzer { |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | 1 | private static final String NEWLINE = System.getProperty("line.separator"); |
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | 1 | private static final Set<String> IGNORE_VALUES = newHashSet( |
| 84 | |
"Sun Java System Application Server"); |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | 1 | private static final Set<String> IGNORE_KEYS = newHashSet( |
| 89 | |
"built-by", |
| 90 | |
"created-by", |
| 91 | |
"builtby", |
| 92 | |
"createdby", |
| 93 | |
"build-jdk", |
| 94 | |
"buildjdk", |
| 95 | |
"ant-version", |
| 96 | |
"antversion", |
| 97 | |
"import-package", |
| 98 | |
"export-package", |
| 99 | |
"importpackage", |
| 100 | |
"exportpackage", |
| 101 | |
"sealed", |
| 102 | |
"manifest-version", |
| 103 | |
"archiver-version", |
| 104 | |
"manifestversion", |
| 105 | |
"archiverversion", |
| 106 | |
"classpath", |
| 107 | |
"class-path", |
| 108 | |
"tool", |
| 109 | |
"bundle-manifestversion", |
| 110 | |
"bundlemanifestversion", |
| 111 | |
"include-resource"); |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
private static final String BUNDLE_VERSION = "Bundle-Version"; |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
private static final String BUNDLE_DESCRIPTION = "Bundle-Description"; |
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
private static final String BUNDLE_NAME = "Bundle-Name"; |
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
private static final String BUNDLE_VENDOR = "Bundle-Vendor"; |
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | 1 | private static final Pattern HTML_DETECTION_PATTERN = Pattern.compile("\\<[a-z]+.*/?\\>", Pattern.CASE_INSENSITIVE); |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
private Unmarshaller pomUnmarshaller; |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | 13 | public JarAnalyzer() { |
| 142 | |
try { |
| 143 | 13 | final JAXBContext jaxbContext = JAXBContext.newInstance("org.owasp.dependencycheck.jaxb.pom.generated"); |
| 144 | 13 | pomUnmarshaller = jaxbContext.createUnmarshaller(); |
| 145 | 0 | } catch (JAXBException ex) { |
| 146 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.SEVERE, "Unable to load parser. See the log for more details."); |
| 147 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINE, null, ex); |
| 148 | 13 | } |
| 149 | 13 | } |
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
private static final String ANALYZER_NAME = "Jar Analyzer"; |
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | 1 | private static final AnalysisPhase ANALYSIS_PHASE = AnalysisPhase.INFORMATION_COLLECTION; |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | 1 | private static final Set<String> EXTENSIONS = newHashSet("jar", "war"); |
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
public Set<String> getSupportedExtensions() { |
| 170 | 137 | return EXTENSIONS; |
| 171 | |
} |
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
public String getName() { |
| 179 | 1 | return ANALYZER_NAME; |
| 180 | |
} |
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
public boolean supportsExtension(String extension) { |
| 190 | 133 | return EXTENSIONS.contains(extension); |
| 191 | |
} |
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
public AnalysisPhase getAnalysisPhase() { |
| 199 | 3 | return ANALYSIS_PHASE; |
| 200 | |
} |
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
@Override |
| 213 | |
public void analyze(Dependency dependency, Engine engine) throws AnalysisException { |
| 214 | |
try { |
| 215 | 16 | final ArrayList<ClassNameInformation> classNames = collectClassNames(dependency); |
| 216 | 16 | final String fileName = dependency.getFileName().toLowerCase(); |
| 217 | 16 | if (classNames.isEmpty() |
| 218 | |
&& (fileName.endsWith("-sources.jar") |
| 219 | |
|| fileName.endsWith("-javadoc.jar") |
| 220 | |
|| fileName.endsWith("-src.jar") |
| 221 | |
|| fileName.endsWith("-doc.jar"))) { |
| 222 | 0 | engine.getDependencies().remove(dependency); |
| 223 | |
} |
| 224 | 16 | final boolean hasManifest = parseManifest(dependency, classNames); |
| 225 | 16 | final boolean hasPOM = analyzePOM(dependency, classNames); |
| 226 | 16 | final boolean addPackagesAsEvidence = !(hasManifest && hasPOM); |
| 227 | 16 | analyzePackageNames(classNames, dependency, addPackagesAsEvidence); |
| 228 | 0 | } catch (IOException ex) { |
| 229 | 0 | throw new AnalysisException("Exception occurred reading the JAR file.", ex); |
| 230 | 16 | } |
| 231 | 16 | } |
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
protected boolean analyzePOM(Dependency dependency, ArrayList<ClassNameInformation> classes) throws AnalysisException { |
| 245 | 16 | boolean foundSomething = false; |
| 246 | |
final JarFile jar; |
| 247 | |
try { |
| 248 | 16 | jar = new JarFile(dependency.getActualFilePath()); |
| 249 | 0 | } catch (IOException ex) { |
| 250 | 0 | final String msg = String.format("Unable to read JarFile '%s'.", dependency.getActualFilePath()); |
| 251 | 0 | final AnalysisException ax = new AnalysisException(msg, ex); |
| 252 | 0 | dependency.getAnalysisExceptions().add(ax); |
| 253 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.WARNING, msg); |
| 254 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINE, null, ex); |
| 255 | 0 | return false; |
| 256 | 16 | } |
| 257 | |
List<String> pomEntries; |
| 258 | |
try { |
| 259 | 16 | pomEntries = retrievePomListing(jar); |
| 260 | 0 | } catch (IOException ex) { |
| 261 | 0 | final String msg = String.format("Unable to read Jar file entries in '%s'.", dependency.getActualFilePath()); |
| 262 | 0 | final AnalysisException ax = new AnalysisException(msg, ex); |
| 263 | 0 | dependency.getAnalysisExceptions().add(ax); |
| 264 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.WARNING, msg); |
| 265 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.INFO, msg, ex); |
| 266 | 0 | return false; |
| 267 | 16 | } |
| 268 | 16 | if (pomEntries.isEmpty()) { |
| 269 | 9 | return false; |
| 270 | |
} |
| 271 | 7 | if (pomEntries.size() > 1) { |
| 272 | 0 | pomEntries = filterPomEntries(pomEntries, classes); |
| 273 | |
} |
| 274 | 7 | for (String path : pomEntries) { |
| 275 | 7 | Properties pomProperties = null; |
| 276 | |
try { |
| 277 | 7 | pomProperties = retrievePomProperties(path, jar); |
| 278 | 0 | } catch (IOException ex) { |
| 279 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINEST, "ignore this, failed reading a non-existent pom.properties", ex); |
| 280 | 7 | } |
| 281 | 7 | Model pom = null; |
| 282 | |
try { |
| 283 | 7 | pom = retrievePom(path, jar); |
| 284 | 0 | } catch (JAXBException ex) { |
| 285 | 0 | final String msg = String.format("Unable to parse POM '%s' in '%s'", |
| 286 | |
path, dependency.getFilePath()); |
| 287 | 0 | final AnalysisException ax = new AnalysisException(msg, ex); |
| 288 | 0 | dependency.getAnalysisExceptions().add(ax); |
| 289 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINE, msg, ax); |
| 290 | 0 | } catch (IOException ex) { |
| 291 | 0 | final String msg = String.format("Unable to retrieve POM '%s' in '%s'", |
| 292 | |
path, dependency.getFilePath()); |
| 293 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINE, msg, ex); |
| 294 | 7 | } |
| 295 | 7 | foundSomething = setPomEvidence(dependency, pom, pomProperties, classes) || foundSomething; |
| 296 | 7 | } |
| 297 | 7 | return foundSomething; |
| 298 | |
} |
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "OS_OPEN_STREAM", |
| 311 | |
justification = "The reader is closed by closing the zipEntry") |
| 312 | |
private Properties retrievePomProperties(String path, final JarFile jar) throws IOException { |
| 313 | 7 | Properties pomProperties = null; |
| 314 | 7 | final String propPath = path.substring(0, path.length() - 7) + "pom.properies"; |
| 315 | 7 | final ZipEntry propEntry = jar.getEntry(propPath); |
| 316 | 7 | if (propEntry != null) { |
| 317 | 0 | final Reader reader = new InputStreamReader(jar.getInputStream(propEntry), "UTF-8"); |
| 318 | 0 | pomProperties = new Properties(); |
| 319 | 0 | pomProperties.load(reader); |
| 320 | |
} |
| 321 | 7 | return pomProperties; |
| 322 | |
} |
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
private List<String> retrievePomListing(final JarFile jar) throws IOException { |
| 333 | 16 | final List<String> pomEntries = new ArrayList<String>(); |
| 334 | 16 | final Enumeration<JarEntry> entries = jar.entries(); |
| 335 | 6838 | while (entries.hasMoreElements()) { |
| 336 | 6822 | final JarEntry entry = entries.nextElement(); |
| 337 | 6822 | final String entryName = (new File(entry.getName())).getName().toLowerCase(); |
| 338 | 6822 | if (!entry.isDirectory() && "pom.xml".equals(entryName)) { |
| 339 | 7 | pomEntries.add(entry.getName()); |
| 340 | |
} |
| 341 | 6822 | } |
| 342 | 16 | return pomEntries; |
| 343 | |
} |
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
private Model retrievePom(String path, JarFile jar) throws JAXBException, IOException { |
| 356 | 7 | final ZipEntry entry = jar.getEntry(path); |
| 357 | 7 | if (entry != null) { |
| 358 | 7 | Model m = null; |
| 359 | |
try { |
| 360 | 7 | final XMLFilter filter = new MavenNamespaceFilter(); |
| 361 | 7 | final SAXParserFactory spf = SAXParserFactory.newInstance(); |
| 362 | 7 | final SAXParser sp = spf.newSAXParser(); |
| 363 | 7 | final XMLReader xr = sp.getXMLReader(); |
| 364 | 7 | filter.setParent(xr); |
| 365 | 7 | final NonClosingStream stream = new NonClosingStream(jar.getInputStream(entry)); |
| 366 | 7 | final InputStreamReader reader = new InputStreamReader(stream, "UTF-8"); |
| 367 | 7 | final InputSource xml = new InputSource(reader); |
| 368 | 7 | final SAXSource source = new SAXSource(filter, xml); |
| 369 | 7 | final JAXBElement<Model> el = pomUnmarshaller.unmarshal(source, Model.class); |
| 370 | 7 | m = el.getValue(); |
| 371 | 0 | } catch (ParserConfigurationException ex) { |
| 372 | 0 | final String msg = String.format("Unable to parse pom '%s' in jar '%s'", path, jar.getName()); |
| 373 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINE, msg, ex); |
| 374 | 0 | } catch (SAXException ex) { |
| 375 | 0 | final String msg = String.format("Unable to parse pom '%s' in jar '%s'", path, jar.getName()); |
| 376 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINE, msg, ex); |
| 377 | 7 | } |
| 378 | 7 | return m; |
| 379 | |
} |
| 380 | 0 | return null; |
| 381 | |
} |
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
private boolean setPomEvidence(Dependency dependency, Model pom, Properties pomProperties, ArrayList<ClassNameInformation> classes) { |
| 395 | 7 | boolean foundSomething = false; |
| 396 | 7 | if (pom == null) { |
| 397 | 0 | return foundSomething; |
| 398 | |
} |
| 399 | 7 | String groupid = interpolateString(pom.getGroupId(), pomProperties); |
| 400 | 7 | if (groupid != null && !groupid.isEmpty()) { |
| 401 | 4 | if (groupid.startsWith("org.") || groupid.startsWith("com.")) { |
| 402 | 3 | groupid = groupid.substring(4); |
| 403 | |
} |
| 404 | 4 | foundSomething = true; |
| 405 | 4 | dependency.getVendorEvidence().addEvidence("pom", "groupid", groupid, Evidence.Confidence.HIGH); |
| 406 | 4 | dependency.getProductEvidence().addEvidence("pom", "groupid", groupid, Evidence.Confidence.LOW); |
| 407 | 4 | addMatchingValues(classes, groupid, dependency.getVendorEvidence()); |
| 408 | 4 | addMatchingValues(classes, groupid, dependency.getProductEvidence()); |
| 409 | |
} |
| 410 | 7 | String artifactid = interpolateString(pom.getArtifactId(), pomProperties); |
| 411 | 7 | if (artifactid != null && !artifactid.isEmpty()) { |
| 412 | 7 | if (artifactid.startsWith("org.") || artifactid.startsWith("com.")) { |
| 413 | 0 | artifactid = artifactid.substring(4); |
| 414 | |
} |
| 415 | 7 | foundSomething = true; |
| 416 | 7 | dependency.getProductEvidence().addEvidence("pom", "artifactid", artifactid, Evidence.Confidence.HIGH); |
| 417 | 7 | dependency.getVendorEvidence().addEvidence("pom", "artifactid", artifactid, Evidence.Confidence.LOW); |
| 418 | 7 | addMatchingValues(classes, artifactid, dependency.getVendorEvidence()); |
| 419 | 7 | addMatchingValues(classes, artifactid, dependency.getProductEvidence()); |
| 420 | |
} |
| 421 | |
|
| 422 | 7 | final String version = interpolateString(pom.getVersion(), pomProperties); |
| 423 | 7 | if (version != null && !version.isEmpty()) { |
| 424 | 2 | foundSomething = true; |
| 425 | 2 | dependency.getVersionEvidence().addEvidence("pom", "version", version, Evidence.Confidence.HIGHEST); |
| 426 | |
} |
| 427 | |
|
| 428 | 7 | final Organization org = pom.getOrganization(); |
| 429 | 7 | if (org != null && org.getName() != null) { |
| 430 | 0 | foundSomething = true; |
| 431 | 0 | final String orgName = interpolateString(org.getName(), pomProperties); |
| 432 | 0 | if (orgName != null && !orgName.isEmpty()) { |
| 433 | 0 | dependency.getVendorEvidence().addEvidence("pom", "organization name", orgName, Evidence.Confidence.HIGH); |
| 434 | 0 | addMatchingValues(classes, orgName, dependency.getVendorEvidence()); |
| 435 | |
} |
| 436 | |
} |
| 437 | |
|
| 438 | 7 | final String pomName = interpolateString(pom.getName(), pomProperties); |
| 439 | 7 | if (pomName != null && !pomName.isEmpty()) { |
| 440 | 7 | foundSomething = true; |
| 441 | 7 | dependency.getProductEvidence().addEvidence("pom", "name", pomName, Evidence.Confidence.HIGH); |
| 442 | 7 | dependency.getVendorEvidence().addEvidence("pom", "name", pomName, Evidence.Confidence.HIGH); |
| 443 | 7 | addMatchingValues(classes, pomName, dependency.getVendorEvidence()); |
| 444 | 7 | addMatchingValues(classes, pomName, dependency.getProductEvidence()); |
| 445 | |
} |
| 446 | |
|
| 447 | |
|
| 448 | 7 | if (pom.getDescription() != null) { |
| 449 | 3 | foundSomething = true; |
| 450 | 3 | final String description = interpolateString(pom.getDescription(), pomProperties); |
| 451 | 3 | if (description != null && !description.isEmpty()) { |
| 452 | 3 | addDescription(dependency, description, "pom", "description"); |
| 453 | 3 | addMatchingValues(classes, description, dependency.getVendorEvidence()); |
| 454 | 3 | addMatchingValues(classes, description, dependency.getProductEvidence()); |
| 455 | |
} |
| 456 | |
} |
| 457 | |
|
| 458 | |
|
| 459 | 7 | if (pom.getLicenses() != null) { |
| 460 | 1 | String license = null; |
| 461 | 1 | for (License lic : pom.getLicenses().getLicense()) { |
| 462 | 1 | String tmp = null; |
| 463 | 1 | if (lic.getName() != null) { |
| 464 | 1 | tmp = interpolateString(lic.getName(), pomProperties); |
| 465 | |
} |
| 466 | 1 | if (lic.getUrl() != null) { |
| 467 | 1 | if (tmp == null) { |
| 468 | 0 | tmp = interpolateString(lic.getUrl(), pomProperties); |
| 469 | |
} else { |
| 470 | 1 | tmp += ": " + interpolateString(lic.getUrl(), pomProperties); |
| 471 | |
} |
| 472 | |
} |
| 473 | 1 | if (tmp == null) { |
| 474 | 0 | continue; |
| 475 | |
} |
| 476 | 1 | if (HTML_DETECTION_PATTERN.matcher(tmp).find()) { |
| 477 | 0 | tmp = Jsoup.parse(tmp).text(); |
| 478 | |
} |
| 479 | 1 | if (license == null) { |
| 480 | 1 | license = tmp; |
| 481 | |
} else { |
| 482 | 0 | license += "\n" + tmp; |
| 483 | |
} |
| 484 | 1 | } |
| 485 | 1 | if (license != null) { |
| 486 | 1 | dependency.setLicense(license); |
| 487 | |
} |
| 488 | |
} |
| 489 | 7 | return foundSomething; |
| 490 | |
} |
| 491 | |
|
| 492 | |
|
| 493 | |
|
| 494 | |
|
| 495 | |
|
| 496 | |
|
| 497 | |
|
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
|
| 502 | |
|
| 503 | |
protected void analyzePackageNames(ArrayList<ClassNameInformation> classNames, |
| 504 | |
Dependency dependency, boolean addPackagesAsEvidence) { |
| 505 | 16 | final HashMap<String, Integer> vendorIdentifiers = new HashMap<String, Integer>(); |
| 506 | 16 | final HashMap<String, Integer> productIdentifiers = new HashMap<String, Integer>(); |
| 507 | 16 | analyzeFullyQualifiedClassNames(classNames, vendorIdentifiers, productIdentifiers); |
| 508 | |
|
| 509 | 16 | final int classCount = classNames.size(); |
| 510 | 16 | final EvidenceCollection vendor = dependency.getVendorEvidence(); |
| 511 | 16 | final EvidenceCollection product = dependency.getProductEvidence(); |
| 512 | |
|
| 513 | 16 | for (Map.Entry<String, Integer> entry : vendorIdentifiers.entrySet()) { |
| 514 | 160 | final float ratio = entry.getValue() / (float) classCount; |
| 515 | 160 | if (ratio > 0.5) { |
| 516 | |
|
| 517 | 32 | vendor.addWeighting(entry.getKey()); |
| 518 | 32 | if (addPackagesAsEvidence && entry.getKey().length() > 1) { |
| 519 | 18 | vendor.addEvidence("jar", "package", entry.getKey(), Evidence.Confidence.LOW); |
| 520 | |
} |
| 521 | |
} |
| 522 | 160 | } |
| 523 | 16 | for (Map.Entry<String, Integer> entry : productIdentifiers.entrySet()) { |
| 524 | 3476 | final float ratio = entry.getValue() / (float) classCount; |
| 525 | 3476 | if (ratio > 0.5) { |
| 526 | 19 | product.addWeighting(entry.getKey()); |
| 527 | 19 | if (addPackagesAsEvidence && entry.getKey().length() > 1) { |
| 528 | 9 | product.addEvidence("jar", "package", entry.getKey(), Evidence.Confidence.LOW); |
| 529 | |
} |
| 530 | |
} |
| 531 | 3476 | } |
| 532 | 16 | } |
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
|
| 538 | |
|
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | |
|
| 545 | |
|
| 546 | |
|
| 547 | |
|
| 548 | |
protected boolean parseManifest(Dependency dependency, ArrayList<ClassNameInformation> classInformation) throws IOException { |
| 549 | 16 | boolean foundSomething = false; |
| 550 | 16 | JarFile jar = null; |
| 551 | |
try { |
| 552 | 16 | jar = new JarFile(dependency.getActualFilePath()); |
| 553 | |
|
| 554 | 16 | final Manifest manifest = jar.getManifest(); |
| 555 | 16 | if (manifest == null) { |
| 556 | |
|
| 557 | 0 | if (!dependency.getFileName().toLowerCase().endsWith("-sources.jar") |
| 558 | |
&& !dependency.getFileName().toLowerCase().endsWith("-javadoc.jar") |
| 559 | |
&& !dependency.getFileName().toLowerCase().endsWith("-src.jar") |
| 560 | |
&& !dependency.getFileName().toLowerCase().endsWith("-doc.jar")) { |
| 561 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.INFO, |
| 562 | |
String.format("Jar file '%s' does not contain a manifest.", |
| 563 | |
dependency.getFileName())); |
| 564 | |
} |
| 565 | 0 | return false; |
| 566 | |
} |
| 567 | 16 | final Attributes atts = manifest.getMainAttributes(); |
| 568 | |
|
| 569 | 16 | final EvidenceCollection vendorEvidence = dependency.getVendorEvidence(); |
| 570 | 16 | final EvidenceCollection productEvidence = dependency.getProductEvidence(); |
| 571 | 16 | final EvidenceCollection versionEvidence = dependency.getVersionEvidence(); |
| 572 | |
|
| 573 | 16 | final String source = "Manifest"; |
| 574 | |
|
| 575 | 16 | for (Entry<Object, Object> entry : atts.entrySet()) { |
| 576 | 236 | String key = entry.getKey().toString(); |
| 577 | 236 | String value = atts.getValue(key); |
| 578 | 236 | if (HTML_DETECTION_PATTERN.matcher(value).find()) { |
| 579 | 0 | value = Jsoup.parse(value).text(); |
| 580 | |
} |
| 581 | 236 | if (IGNORE_VALUES.contains(value)) { |
| 582 | 0 | continue; |
| 583 | 236 | } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_TITLE.toString())) { |
| 584 | 7 | foundSomething = true; |
| 585 | 7 | productEvidence.addEvidence(source, key, value, Evidence.Confidence.HIGH); |
| 586 | 7 | addMatchingValues(classInformation, value, productEvidence); |
| 587 | 229 | } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_VERSION.toString())) { |
| 588 | 10 | foundSomething = true; |
| 589 | 10 | versionEvidence.addEvidence(source, key, value, Evidence.Confidence.HIGH); |
| 590 | 219 | } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_VENDOR.toString())) { |
| 591 | 6 | foundSomething = true; |
| 592 | 6 | vendorEvidence.addEvidence(source, key, value, Evidence.Confidence.HIGH); |
| 593 | 6 | addMatchingValues(classInformation, value, vendorEvidence); |
| 594 | 213 | } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_VENDOR_ID.toString())) { |
| 595 | 3 | foundSomething = true; |
| 596 | 3 | vendorEvidence.addEvidence(source, key, value, Evidence.Confidence.MEDIUM); |
| 597 | 3 | addMatchingValues(classInformation, value, vendorEvidence); |
| 598 | 210 | } else if (key.equalsIgnoreCase(BUNDLE_DESCRIPTION)) { |
| 599 | 7 | foundSomething = true; |
| 600 | 7 | addDescription(dependency, value, "manifest", key); |
| 601 | |
|
| 602 | 7 | addMatchingValues(classInformation, value, productEvidence); |
| 603 | 203 | } else if (key.equalsIgnoreCase(BUNDLE_NAME)) { |
| 604 | 10 | foundSomething = true; |
| 605 | 10 | productEvidence.addEvidence(source, key, value, Evidence.Confidence.MEDIUM); |
| 606 | 10 | addMatchingValues(classInformation, value, productEvidence); |
| 607 | 193 | } else if (key.equalsIgnoreCase(BUNDLE_VENDOR)) { |
| 608 | 8 | foundSomething = true; |
| 609 | 8 | vendorEvidence.addEvidence(source, key, value, Evidence.Confidence.HIGH); |
| 610 | 8 | addMatchingValues(classInformation, value, vendorEvidence); |
| 611 | 185 | } else if (key.equalsIgnoreCase(BUNDLE_VERSION)) { |
| 612 | 10 | foundSomething = true; |
| 613 | 10 | versionEvidence.addEvidence(source, key, value, Evidence.Confidence.HIGH); |
| 614 | 175 | } else if (key.equalsIgnoreCase(Attributes.Name.MAIN_CLASS.toString())) { |
| 615 | 5 | continue; |
| 616 | |
|
| 617 | |
|
| 618 | |
|
| 619 | |
|
| 620 | |
|
| 621 | |
|
| 622 | |
|
| 623 | |
|
| 624 | |
} else { |
| 625 | 170 | key = key.toLowerCase(); |
| 626 | |
|
| 627 | 170 | if (!IGNORE_KEYS.contains(key) |
| 628 | |
&& !key.endsWith("jdk") |
| 629 | |
&& !key.contains("lastmodified") |
| 630 | |
&& !key.endsWith("package") |
| 631 | |
&& !key.endsWith("classpath") |
| 632 | |
&& !key.endsWith("class-path") |
| 633 | |
&& !key.endsWith("-scm") |
| 634 | |
&& !key.startsWith("scm-") |
| 635 | |
&& !isImportPackage(key, value) |
| 636 | |
&& !isPackage(key, value)) { |
| 637 | |
|
| 638 | 51 | foundSomething = true; |
| 639 | 51 | if (key.contains("version")) { |
| 640 | 8 | if (key.contains("specification")) { |
| 641 | 6 | versionEvidence.addEvidence(source, key, value, Evidence.Confidence.LOW); |
| 642 | |
} else { |
| 643 | 2 | versionEvidence.addEvidence(source, key, value, Evidence.Confidence.MEDIUM); |
| 644 | |
} |
| 645 | |
|
| 646 | 43 | } else if (key.contains("title")) { |
| 647 | 6 | productEvidence.addEvidence(source, key, value, Evidence.Confidence.MEDIUM); |
| 648 | 6 | addMatchingValues(classInformation, value, productEvidence); |
| 649 | 37 | } else if (key.contains("vendor")) { |
| 650 | 3 | if (key.contains("specification")) { |
| 651 | 3 | vendorEvidence.addEvidence(source, key, value, Evidence.Confidence.LOW); |
| 652 | |
} else { |
| 653 | 0 | vendorEvidence.addEvidence(source, key, value, Evidence.Confidence.MEDIUM); |
| 654 | 0 | addMatchingValues(classInformation, value, vendorEvidence); |
| 655 | |
} |
| 656 | 34 | } else if (key.contains("name")) { |
| 657 | 11 | productEvidence.addEvidence(source, key, value, Evidence.Confidence.MEDIUM); |
| 658 | 11 | vendorEvidence.addEvidence(source, key, value, Evidence.Confidence.MEDIUM); |
| 659 | 11 | addMatchingValues(classInformation, value, vendorEvidence); |
| 660 | 11 | addMatchingValues(classInformation, value, productEvidence); |
| 661 | 23 | } else if (key.contains("license")) { |
| 662 | 6 | addLicense(dependency, value); |
| 663 | |
} else { |
| 664 | 17 | if (key.contains("description")) { |
| 665 | 0 | addDescription(dependency, value, "manifest", key); |
| 666 | |
} else { |
| 667 | 17 | productEvidence.addEvidence(source, key, value, Evidence.Confidence.LOW); |
| 668 | 17 | vendorEvidence.addEvidence(source, key, value, Evidence.Confidence.LOW); |
| 669 | 17 | addMatchingValues(classInformation, value, vendorEvidence); |
| 670 | 17 | addMatchingValues(classInformation, value, productEvidence); |
| 671 | 17 | if (value.matches(".*\\d.*")) { |
| 672 | 6 | final StringTokenizer tokenizer = new StringTokenizer(value, " "); |
| 673 | 30 | while (tokenizer.hasMoreElements()) { |
| 674 | 24 | final String s = tokenizer.nextToken(); |
| 675 | 24 | if (s.matches("^[0-9.]+$")) { |
| 676 | 0 | versionEvidence.addEvidence(source, key, s, Evidence.Confidence.LOW); |
| 677 | |
} |
| 678 | 24 | } |
| 679 | |
} |
| 680 | |
} |
| 681 | |
} |
| 682 | |
} |
| 683 | |
} |
| 684 | 231 | } |
| 685 | |
} finally { |
| 686 | 16 | if (jar != null) { |
| 687 | 16 | jar.close(); |
| 688 | |
} |
| 689 | |
} |
| 690 | 16 | return foundSomething; |
| 691 | |
} |
| 692 | |
|
| 693 | |
|
| 694 | |
|
| 695 | |
|
| 696 | |
|
| 697 | |
|
| 698 | |
|
| 699 | |
|
| 700 | |
|
| 701 | |
private void addDescription(Dependency dependency, String description, String source, String key) { |
| 702 | 10 | if (dependency.getDescription() == null) { |
| 703 | 9 | dependency.setDescription(description); |
| 704 | |
} |
| 705 | |
String desc; |
| 706 | 10 | if (HTML_DETECTION_PATTERN.matcher(description).find()) { |
| 707 | 0 | desc = Jsoup.parse(description).text(); |
| 708 | |
} else { |
| 709 | 10 | desc = description; |
| 710 | |
} |
| 711 | 10 | dependency.setDescription(desc); |
| 712 | 10 | if (desc.length() > 100) { |
| 713 | 2 | final int posSuchAs = desc.toLowerCase().indexOf("such as ", 100); |
| 714 | 2 | final int posLike = desc.toLowerCase().indexOf("like ", 100); |
| 715 | 2 | int pos = -1; |
| 716 | 2 | if (posLike > 0 && posSuchAs > 0) { |
| 717 | 0 | pos = posLike > posSuchAs ? posLike : posSuchAs; |
| 718 | 2 | } else if (posLike > 0) { |
| 719 | 2 | pos = posLike; |
| 720 | 0 | } else if (posSuchAs > 0) { |
| 721 | 0 | pos = posSuchAs; |
| 722 | |
} |
| 723 | 2 | String descToUse = desc; |
| 724 | 2 | if (pos > 0) { |
| 725 | 2 | final StringBuilder sb = new StringBuilder(pos + 3); |
| 726 | 2 | sb.append(desc.substring(0, pos)); |
| 727 | 2 | sb.append("..."); |
| 728 | 2 | descToUse = sb.toString(); |
| 729 | |
} |
| 730 | 2 | dependency.getProductEvidence().addEvidence(source, key, descToUse, Evidence.Confidence.LOW); |
| 731 | 2 | dependency.getVendorEvidence().addEvidence(source, key, descToUse, Evidence.Confidence.LOW); |
| 732 | 2 | } else { |
| 733 | 8 | dependency.getProductEvidence().addEvidence(source, key, desc, Evidence.Confidence.MEDIUM); |
| 734 | 8 | dependency.getVendorEvidence().addEvidence(source, key, desc, Evidence.Confidence.MEDIUM); |
| 735 | |
} |
| 736 | 10 | } |
| 737 | |
|
| 738 | |
|
| 739 | |
|
| 740 | |
|
| 741 | |
|
| 742 | |
|
| 743 | |
|
| 744 | |
private void addLicense(Dependency d, String license) { |
| 745 | 6 | if (d.getLicense() == null) { |
| 746 | 6 | d.setLicense(license); |
| 747 | 0 | } else if (!d.getLicense().contains(license)) { |
| 748 | 0 | d.setLicense(d.getLicense() + NEWLINE + license); |
| 749 | |
} |
| 750 | 6 | } |
| 751 | |
|
| 752 | |
|
| 753 | |
|
| 754 | |
|
| 755 | |
public void initialize() { |
| 756 | |
|
| 757 | 1 | } |
| 758 | |
|
| 759 | |
|
| 760 | |
|
| 761 | |
|
| 762 | |
public void close() { |
| 763 | |
|
| 764 | 1 | } |
| 765 | |
|
| 766 | |
|
| 767 | |
|
| 768 | |
|
| 769 | |
|
| 770 | |
|
| 771 | |
|
| 772 | |
|
| 773 | |
|
| 774 | |
|
| 775 | |
|
| 776 | |
|
| 777 | |
|
| 778 | |
|
| 779 | |
|
| 780 | |
|
| 781 | |
|
| 782 | |
|
| 783 | |
|
| 784 | |
|
| 785 | |
|
| 786 | |
|
| 787 | |
|
| 788 | |
|
| 789 | |
|
| 790 | |
|
| 791 | |
|
| 792 | |
protected String interpolateString(String text, Properties properties) { |
| 793 | 40 | Properties props = properties; |
| 794 | 40 | if (text == null) { |
| 795 | 8 | return text; |
| 796 | |
} |
| 797 | 32 | if (props == null) { |
| 798 | 25 | props = new Properties(); |
| 799 | |
} |
| 800 | |
|
| 801 | 32 | final int pos = text.indexOf("${"); |
| 802 | 32 | if (pos < 0) { |
| 803 | 29 | return text; |
| 804 | |
} |
| 805 | 3 | final int end = text.indexOf("}"); |
| 806 | 3 | if (end < pos) { |
| 807 | 0 | return text; |
| 808 | |
} |
| 809 | |
|
| 810 | 3 | final String propName = text.substring(pos + 2, end); |
| 811 | 3 | String propValue = interpolateString(props.getProperty(propName), props); |
| 812 | 3 | if (propValue == null) { |
| 813 | 0 | propValue = ""; |
| 814 | |
} |
| 815 | 3 | final StringBuilder sb = new StringBuilder(propValue.length() + text.length()); |
| 816 | 3 | sb.append(text.subSequence(0, pos)); |
| 817 | 3 | sb.append(propValue); |
| 818 | 3 | sb.append(text.substring(end + 1)); |
| 819 | 3 | return interpolateString(sb.toString(), props); |
| 820 | |
} |
| 821 | |
|
| 822 | |
|
| 823 | |
|
| 824 | |
|
| 825 | |
|
| 826 | |
|
| 827 | |
|
| 828 | |
|
| 829 | |
|
| 830 | |
|
| 831 | |
private boolean isImportPackage(String key, String value) { |
| 832 | 53 | final Pattern packageRx = Pattern.compile("^((([a-zA-Z_#\\$0-9]\\.)+)\\s*\\;\\s*)+$"); |
| 833 | 53 | if (packageRx.matcher(value).matches()) { |
| 834 | 0 | return (key.contains("import") || key.contains("include")); |
| 835 | |
} |
| 836 | 53 | return false; |
| 837 | |
} |
| 838 | |
|
| 839 | |
|
| 840 | |
|
| 841 | |
|
| 842 | |
|
| 843 | |
|
| 844 | |
|
| 845 | |
|
| 846 | |
|
| 847 | |
private ArrayList<ClassNameInformation> collectClassNames(Dependency dependency) { |
| 848 | 16 | final ArrayList<ClassNameInformation> classNames = new ArrayList<ClassNameInformation>(); |
| 849 | 16 | JarFile jar = null; |
| 850 | |
try { |
| 851 | 16 | jar = new JarFile(dependency.getActualFilePath()); |
| 852 | 16 | final Enumeration entries = jar.entries(); |
| 853 | 6838 | while (entries.hasMoreElements()) { |
| 854 | 6822 | final JarEntry entry = (JarEntry) entries.nextElement(); |
| 855 | 6822 | final String name = entry.getName().toLowerCase(); |
| 856 | |
|
| 857 | 6822 | if (name.endsWith(".class") && !name.matches("^javax?\\..*$")) { |
| 858 | 5781 | final ClassNameInformation className = new ClassNameInformation(name.substring(0, name.length() - 6)); |
| 859 | 5781 | classNames.add(className); |
| 860 | |
} |
| 861 | 6822 | } |
| 862 | 0 | } catch (IOException ex) { |
| 863 | 0 | final String msg = String.format("Unable to open jar file '%s'.", dependency.getFileName()); |
| 864 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.WARNING, msg); |
| 865 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINE, null, ex); |
| 866 | |
} finally { |
| 867 | 16 | if (jar != null) { |
| 868 | |
try { |
| 869 | 16 | jar.close(); |
| 870 | 0 | } catch (IOException ex) { |
| 871 | 0 | Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINEST, null, ex); |
| 872 | 16 | } |
| 873 | |
} |
| 874 | |
} |
| 875 | 16 | return classNames; |
| 876 | |
} |
| 877 | |
|
| 878 | |
|
| 879 | |
|
| 880 | |
|
| 881 | |
|
| 882 | |
|
| 883 | |
|
| 884 | |
|
| 885 | |
|
| 886 | |
|
| 887 | |
|
| 888 | |
|
| 889 | |
|
| 890 | |
private void analyzeFullyQualifiedClassNames(ArrayList<ClassNameInformation> classNames, |
| 891 | |
HashMap<String, Integer> vendor, HashMap<String, Integer> product) { |
| 892 | 16 | for (ClassNameInformation entry : classNames) { |
| 893 | 5781 | final ArrayList<String> list = entry.getPackageStructure(); |
| 894 | 5781 | addEntry(vendor, list.get(0)); |
| 895 | |
|
| 896 | 5781 | if (list.size() == 2) { |
| 897 | 0 | addEntry(product, list.get(1)); |
| 898 | |
} |
| 899 | 5781 | if (list.size() == 3) { |
| 900 | 1989 | addEntry(vendor, list.get(1)); |
| 901 | 1989 | addEntry(product, list.get(1)); |
| 902 | 1989 | addEntry(product, list.get(2)); |
| 903 | |
} |
| 904 | 5781 | if (list.size() >= 4) { |
| 905 | 3792 | addEntry(vendor, list.get(1)); |
| 906 | 3792 | addEntry(vendor, list.get(2)); |
| 907 | 3792 | addEntry(product, list.get(1)); |
| 908 | 3792 | addEntry(product, list.get(2)); |
| 909 | 3792 | addEntry(product, list.get(3)); |
| 910 | |
} |
| 911 | 5781 | } |
| 912 | 16 | } |
| 913 | |
|
| 914 | |
|
| 915 | |
|
| 916 | |
|
| 917 | |
|
| 918 | |
|
| 919 | |
|
| 920 | |
|
| 921 | |
|
| 922 | |
private void addEntry(HashMap<String, Integer> collection, String key) { |
| 923 | 30708 | if (collection.containsKey(key)) { |
| 924 | 27072 | collection.put(key, collection.get(key) + 1); |
| 925 | |
} else { |
| 926 | 3636 | collection.put(key, 1); |
| 927 | |
} |
| 928 | 30708 | } |
| 929 | |
|
| 930 | |
|
| 931 | |
|
| 932 | |
|
| 933 | |
|
| 934 | |
|
| 935 | |
|
| 936 | |
|
| 937 | |
|
| 938 | |
|
| 939 | |
|
| 940 | |
private void addMatchingValues(ArrayList<ClassNameInformation> classes, String value, EvidenceCollection evidence) { |
| 941 | 145 | if (value == null || value.isEmpty()) { |
| 942 | 0 | return; |
| 943 | |
} |
| 944 | 145 | final String text = value.toLowerCase(); |
| 945 | 145 | for (ClassNameInformation cni : classes) { |
| 946 | 59610 | for (String key : cni.getPackageStructure()) { |
| 947 | 217618 | if (text.contains(key)) { |
| 948 | 66967 | evidence.addEvidence("jar", "package name", key, Evidence.Confidence.HIGHEST); |
| 949 | |
} |
| 950 | |
} |
| 951 | |
} |
| 952 | 145 | } |
| 953 | |
|
| 954 | |
|
| 955 | |
|
| 956 | |
|
| 957 | |
|
| 958 | |
|
| 959 | |
|
| 960 | |
|
| 961 | |
|
| 962 | |
|
| 963 | |
|
| 964 | |
|
| 965 | |
|
| 966 | |
|
| 967 | |
|
| 968 | |
|
| 969 | |
|
| 970 | |
|
| 971 | |
|
| 972 | |
private List<String> filterPomEntries(List<String> pomEntries, ArrayList<ClassNameInformation> classes) { |
| 973 | 0 | return pomEntries; |
| 974 | |
|
| 975 | |
|
| 976 | |
|
| 977 | |
|
| 978 | |
|
| 979 | |
|
| 980 | |
|
| 981 | |
|
| 982 | |
|
| 983 | |
|
| 984 | |
|
| 985 | |
|
| 986 | |
|
| 987 | |
|
| 988 | |
|
| 989 | |
|
| 990 | |
|
| 991 | |
|
| 992 | |
|
| 993 | |
|
| 994 | |
|
| 995 | |
|
| 996 | |
|
| 997 | |
|
| 998 | |
|
| 999 | |
|
| 1000 | |
|
| 1001 | |
|
| 1002 | |
|
| 1003 | |
|
| 1004 | |
|
| 1005 | |
|
| 1006 | |
|
| 1007 | |
|
| 1008 | |
|
| 1009 | |
|
| 1010 | |
|
| 1011 | |
|
| 1012 | |
|
| 1013 | |
|
| 1014 | |
|
| 1015 | |
|
| 1016 | |
|
| 1017 | |
|
| 1018 | |
|
| 1019 | |
|
| 1020 | |
|
| 1021 | |
|
| 1022 | |
|
| 1023 | |
|
| 1024 | |
|
| 1025 | |
} |
| 1026 | |
|
| 1027 | |
|
| 1028 | |
|
| 1029 | |
|
| 1030 | |
|
| 1031 | |
|
| 1032 | |
|
| 1033 | |
|
| 1034 | |
|
| 1035 | |
private boolean isPackage(String key, String value) { |
| 1036 | |
|
| 1037 | 53 | return !key.matches(".*(version|title|vendor|name|license|description).*") |
| 1038 | |
&& value.matches("^([a-zA-Z_][a-zA-Z0-9_\\$]*(\\.[a-zA-Z_][a-zA-Z0-9_\\$]*)*)?$"); |
| 1039 | |
} |
| 1040 | |
|
| 1041 | |
|
| 1042 | |
|
| 1043 | |
|
| 1044 | |
protected static class ClassNameInformation { |
| 1045 | |
|
| 1046 | |
|
| 1047 | |
|
| 1048 | |
|
| 1049 | |
|
| 1050 | |
|
| 1051 | |
|
| 1052 | |
|
| 1053 | |
|
| 1054 | |
|
| 1055 | |
|
| 1056 | |
|
| 1057 | |
|
| 1058 | |
|
| 1059 | |
|
| 1060 | |
|
| 1061 | |
|
| 1062 | |
|
| 1063 | |
|
| 1064 | 5781 | ClassNameInformation(String className) { |
| 1065 | 5781 | name = className; |
| 1066 | 5781 | if (name.contains("/")) { |
| 1067 | 5781 | final String[] tmp = className.toLowerCase().split("/"); |
| 1068 | 5781 | int start = 0; |
| 1069 | 5781 | int end = 3; |
| 1070 | 5781 | if ("com".equals(tmp[0]) || "org".equals(tmp[0])) { |
| 1071 | 5354 | start = 1; |
| 1072 | 5354 | end = 4; |
| 1073 | |
} |
| 1074 | 5781 | if (tmp.length <= end) { |
| 1075 | 1989 | end = tmp.length - 1; |
| 1076 | |
} |
| 1077 | 26916 | for (int i = start; i <= end; i++) { |
| 1078 | 21135 | packageStructure.add(tmp[i]); |
| 1079 | |
} |
| 1080 | 5781 | } else { |
| 1081 | 0 | packageStructure.add(name); |
| 1082 | |
} |
| 1083 | 5781 | } |
| 1084 | |
|
| 1085 | |
|
| 1086 | |
|
| 1087 | |
private String name; |
| 1088 | |
|
| 1089 | |
|
| 1090 | |
|
| 1091 | |
|
| 1092 | |
|
| 1093 | |
|
| 1094 | |
public String getName() { |
| 1095 | 0 | return name; |
| 1096 | |
} |
| 1097 | |
|
| 1098 | |
|
| 1099 | |
|
| 1100 | |
|
| 1101 | |
|
| 1102 | |
|
| 1103 | |
public void setName(String name) { |
| 1104 | 0 | this.name = name; |
| 1105 | 0 | } |
| 1106 | |
|
| 1107 | |
|
| 1108 | |
|
| 1109 | |
|
| 1110 | 5781 | private ArrayList<String> packageStructure = new ArrayList<String>(); |
| 1111 | |
|
| 1112 | |
|
| 1113 | |
|
| 1114 | |
|
| 1115 | |
|
| 1116 | |
|
| 1117 | |
public ArrayList<String> getPackageStructure() { |
| 1118 | 65391 | return packageStructure; |
| 1119 | |
} |
| 1120 | |
} |
| 1121 | |
} |