1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.analyzer;
19
20 import com.github.packageurl.MalformedPackageURLException;
21 import com.github.packageurl.PackageURL;
22 import com.github.packageurl.PackageURLBuilder;
23 import com.google.common.base.Strings;
24 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
25 import java.io.File;
26 import java.io.FileFilter;
27 import java.io.FileInputStream;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.InputStreamReader;
32 import java.io.Reader;
33 import java.io.UnsupportedEncodingException;
34 import java.nio.charset.StandardCharsets;
35 import java.nio.file.Paths;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.Enumeration;
39 import java.util.HashMap;
40 import java.util.HashSet;
41 import java.util.List;
42 import java.util.Map;
43 import java.util.Map.Entry;
44 import java.util.Properties;
45 import java.util.Set;
46 import java.util.StringTokenizer;
47 import java.util.concurrent.atomic.AtomicInteger;
48 import java.util.jar.Attributes;
49 import java.util.jar.JarEntry;
50 import java.util.jar.JarFile;
51 import java.util.jar.Manifest;
52 import java.util.regex.Pattern;
53 import java.util.zip.ZipEntry;
54
55 import org.apache.commons.io.FilenameUtils;
56 import org.apache.commons.lang3.StringUtils;
57 import org.apache.commons.io.IOUtils;
58 import org.jsoup.Jsoup;
59 import org.owasp.dependencycheck.Engine;
60 import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
61 import org.owasp.dependencycheck.data.nvd.ecosystem.Ecosystem;
62 import org.owasp.dependencycheck.dependency.Confidence;
63 import org.owasp.dependencycheck.dependency.Dependency;
64 import org.owasp.dependencycheck.dependency.EvidenceType;
65 import org.owasp.dependencycheck.dependency.naming.GenericIdentifier;
66 import org.owasp.dependencycheck.dependency.naming.Identifier;
67 import org.owasp.dependencycheck.dependency.naming.PurlIdentifier;
68 import org.owasp.dependencycheck.exception.InitializationException;
69 import org.owasp.dependencycheck.utils.FileFilterBuilder;
70 import org.owasp.dependencycheck.utils.FileUtils;
71 import org.owasp.dependencycheck.utils.Settings;
72 import org.owasp.dependencycheck.xml.pom.Developer;
73 import org.owasp.dependencycheck.xml.pom.License;
74 import org.owasp.dependencycheck.xml.pom.Model;
75 import org.owasp.dependencycheck.xml.pom.PomUtils;
76 import org.slf4j.Logger;
77 import org.slf4j.LoggerFactory;
78
79
80
81
82
83
84
85 public class JarAnalyzer extends AbstractFileTypeAnalyzer {
86
87
88
89
90
91
92 public static final String DEPENDENCY_ECOSYSTEM = Ecosystem.JAVA;
93
94
95
96 private static final Logger LOGGER = LoggerFactory.getLogger(JarAnalyzer.class);
97
98
99
100
101 private static final AtomicInteger DIR_COUNT = new AtomicInteger(0);
102
103
104
105 private static final String NEWLINE = System.getProperty("line.separator");
106
107
108
109
110 private static final Set<String> IGNORE_VALUES = newHashSet(
111 "Sun Java System Application Server");
112
113
114
115 private static final Set<String> IGNORE_KEYS = newHashSet(
116 "built-by",
117 "created-by",
118 "builtby",
119 "built-with",
120 "builtwith",
121 "createdby",
122 "build-jdk",
123 "buildjdk",
124 "ant-version",
125 "antversion",
126 "dynamicimportpackage",
127 "dynamicimport-package",
128 "dynamic-importpackage",
129 "dynamic-import-package",
130 "import-package",
131 "ignore-package",
132 "export-package",
133 "importpackage",
134 "import-template",
135 "importtemplate",
136 "java-vendor",
137 "export-template",
138 "exporttemplate",
139 "ignorepackage",
140 "exportpackage",
141 "sealed",
142 "manifest-version",
143 "archiver-version",
144 "manifestversion",
145 "archiverversion",
146 "classpath",
147 "class-path",
148 "tool",
149 "bundle-manifestversion",
150 "bundlemanifestversion",
151 "bundle-vendor",
152 "include-resource",
153 "embed-dependency",
154 "embedded-artifacts",
155 "ipojo-components",
156 "ipojo-extension",
157 "plugin-dependencies",
158 "today",
159 "tstamp",
160 "dstamp",
161 "eclipse-sourcereferences",
162 "kotlin-version",
163 "require-capability");
164
165
166
167
168 @SuppressWarnings("deprecation")
169 private static final String IMPLEMENTATION_VENDOR_ID = Attributes.Name.IMPLEMENTATION_VENDOR_ID
170 .toString();
171
172
173
174 private static final String BUNDLE_VERSION = "Bundle-Version";
175
176
177
178 private static final String BUNDLE_DESCRIPTION = "Bundle-Description";
179
180
181
182 private static final String BUNDLE_NAME = "Bundle-Name";
183
184
185
186 private static final Pattern HTML_DETECTION_PATTERN = Pattern.compile("\\<[a-z]+.*/?\\>", Pattern.CASE_INSENSITIVE);
187
188
189
190 private static final String ANALYZER_NAME = "Jar Analyzer";
191
192
193
194 private static final AnalysisPhase ANALYSIS_PHASE = AnalysisPhase.INFORMATION_COLLECTION;
195
196
197
198 private static final List<String> EXCLUDE_JARS = Arrays.asList("-doc.jar", "-src.jar", "-javadoc.jar", "-sources.jar");
199
200
201
202 private static final String[] EXTENSIONS = {"jar", "war", "aar"};
203
204
205
206 private static final FileFilter FILTER = FileFilterBuilder.newInstance().addExtensions(EXTENSIONS).build();
207
208
209
210
211 private static final byte[] ZIP_FIRST_BYTES = new byte[]{0x50, 0x4B, 0x03, 0x04};
212
213
214
215
216 private static final byte[] ZIP_EMPTY_FIRST_BYTES = new byte[]{0x50, 0x4B, 0x05, 0x06};
217
218
219
220
221 private static final byte[] ZIP_SPANNED_FIRST_BYTES = new byte[]{0x50, 0x4B, 0x07, 0x08};
222
223
224
225
226
227 private File tempFileLocation = null;
228
229
230
231
232
233 private static final String VALID_NAME = "^[A-Za-z0-9_\\-.]+$";
234
235
236
237
238
239
240
241 @Override
242 protected FileFilter getFileFilter() {
243 return FILTER;
244 }
245
246
247
248
249
250
251 @Override
252 public String getName() {
253 return ANALYZER_NAME;
254 }
255
256
257
258
259
260
261 @Override
262 public AnalysisPhase getAnalysisPhase() {
263 return ANALYSIS_PHASE;
264 }
265
266 @Override
267 public boolean accept(File pathname) {
268 final boolean accepted = super.accept(pathname);
269 return accepted && !isExcludedJar(pathname);
270 }
271
272
273
274
275
276
277
278
279
280 private boolean isExcludedJar(File path) {
281 final String fileName = path.getName().toLowerCase();
282 return EXCLUDE_JARS.stream().anyMatch(fileName::endsWith);
283 }
284
285
286
287
288
289
290
291
292 @Override
293 protected String getAnalyzerEnabledSettingKey() {
294 return Settings.KEYS.ANALYZER_JAR_ENABLED;
295 }
296
297
298
299
300
301
302
303
304
305
306 @Override
307 public void analyzeDependency(Dependency dependency, Engine engine) throws AnalysisException {
308 final List<ClassNameInformation> classNames = collectClassNames(dependency);
309 final String fileName = dependency.getFileName().toLowerCase();
310 if ((classNames.isEmpty()
311 && (fileName.endsWith("-sources.jar")
312 || fileName.endsWith("-javadoc.jar")
313 || fileName.endsWith("-src.jar")
314 || fileName.endsWith("-doc.jar")
315 || isMacOSMetaDataFile(dependency, engine)))
316 || !isZipFile(dependency)) {
317 engine.removeDependency(dependency);
318 return;
319 }
320 Exception exception = null;
321 boolean hasManifest = false;
322 try {
323 hasManifest = parseManifest(dependency, classNames);
324 } catch (IOException ex) {
325 LOGGER.debug("Invalid Manifest", ex);
326 exception = ex;
327 }
328 boolean hasPOM = false;
329 try {
330 hasPOM = analyzePOM(dependency, classNames, engine);
331 } catch (AnalysisException ex) {
332 LOGGER.debug("Error parsing pom.xml", ex);
333 exception = ex;
334 }
335 final boolean addPackagesAsEvidence = !(hasManifest && hasPOM);
336 analyzePackageNames(classNames, dependency, addPackagesAsEvidence);
337 dependency.setEcosystem(DEPENDENCY_ECOSYSTEM);
338
339 if (exception != null) {
340 throw new AnalysisException(String.format("An error occurred extracting evidence from "
341 + "%s, analysis may be incomplete; please see the log for more details.",
342 dependency.getDisplayFileName()), exception);
343 }
344 }
345
346
347
348
349
350
351
352
353
354
355
356
357 @SuppressFBWarnings(justification = "If actual file path is not null the path will have elements and getFileName will not be called on a null",
358 value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"})
359 private boolean isMacOSMetaDataFile(final Dependency dependency, final Engine engine) {
360 if (dependency.getActualFilePath() != null) {
361 final String fileName = Paths.get(dependency.getActualFilePath()).getFileName().toString();
362 return fileName.startsWith("._") && hasDependencyWithFilename(engine.getDependencies(), fileName.substring(2));
363 }
364 return false;
365 }
366
367
368
369
370
371
372
373
374
375
376
377 @SuppressFBWarnings(justification = "If actual file path is not null the path will have elements and getFileName will not be called on a null",
378 value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"})
379 private boolean hasDependencyWithFilename(final Dependency[] dependencies, final String fileName) {
380 for (final Dependency dependency : dependencies) {
381 if (dependency.getActualFilePath() != null
382 && Paths.get(dependency.getActualFilePath()).getFileName().toString().equalsIgnoreCase(fileName)) {
383 return true;
384 }
385 }
386 return false;
387 }
388
389
390
391
392
393
394
395
396
397
398
399 @SuppressFBWarnings(justification = "try with resources will clean up the output stream", value = {"OBL_UNSATISFIED_OBLIGATION"})
400 private boolean isZipFile(final Dependency dependency) {
401 final byte[] buffer = new byte[4];
402 try (FileInputStream fileInputStream = new FileInputStream(dependency.getActualFilePath())) {
403 if (fileInputStream.read(buffer) > 0
404 && (Arrays.equals(buffer, ZIP_FIRST_BYTES)
405 || Arrays.equals(buffer, ZIP_EMPTY_FIRST_BYTES)
406 || Arrays.equals(buffer, ZIP_SPANNED_FIRST_BYTES))) {
407 return true;
408 }
409 } catch (Exception e) {
410 LOGGER.warn("Unable to check if '{}' is a zip file", dependency.getActualFilePath());
411 LOGGER.trace("", e);
412 }
413 return false;
414 }
415
416
417
418
419
420
421
422
423
424
425
426
427
428 protected boolean analyzePOM(Dependency dependency, List<ClassNameInformation> classes, Engine engine) throws AnalysisException {
429
430
431 boolean evidenceAdded = false;
432 try (JarFile jar = new JarFile(dependency.getActualFilePath(), false)) {
433
434 final String repoPomName = FilenameUtils.removeExtension(dependency.getActualFilePath()) + ".pom";
435 final File repoPom = new File(repoPomName);
436 if (repoPom.isFile()) {
437 final Model pom = PomUtils.readPom(repoPom);
438 evidenceAdded |= setPomEvidence(dependency, pom, classes, true);
439 }
440
441 final List<String> pomEntries = retrievePomListing(jar);
442
443 for (String path : pomEntries) {
444 LOGGER.debug("Reading pom entry: {}", path);
445 try {
446
447 final Properties pomProperties = retrievePomProperties(path, jar);
448 final File pomFile = extractPom(path, jar);
449 final Model pom = PomUtils.readPom(pomFile);
450 pom.setGAVFromPomDotProperties(pomProperties);
451 pom.processProperties(pomProperties);
452
453 final String artifactId = new File(path).getParentFile().getName();
454 if (dependency.getActualFile().getName().startsWith(artifactId)) {
455 evidenceAdded |= setPomEvidence(dependency, pom, classes, true);
456 } else {
457 final String displayPath = String.format("%s%s%s",
458 dependency.getFilePath(),
459 File.separator,
460 path);
461 final String displayName = String.format("%s%s%s",
462 dependency.getFileName(),
463 File.separator,
464 path);
465 final Dependency newDependency = new Dependency();
466 newDependency.setActualFilePath(pomFile.getAbsolutePath());
467 newDependency.setFileName(displayName);
468 newDependency.setFilePath(displayPath);
469 newDependency.setEcosystem(DEPENDENCY_ECOSYSTEM);
470 String groupId = pom.getGroupId();
471 String version = pom.getVersion();
472 if (groupId == null) {
473 groupId = pom.getParentGroupId();
474 }
475 if (version == null) {
476 version = pom.getParentVersion();
477 }
478 if (groupId == null) {
479 newDependency.setName(pom.getArtifactId());
480 newDependency.setPackagePath(String.format("%s:%s", pom.getArtifactId(), version));
481 } else {
482 newDependency.setName(String.format("%s:%s", groupId, pom.getArtifactId()));
483 newDependency.setPackagePath(String.format("%s:%s:%s", groupId, pom.getArtifactId(), version));
484 }
485 newDependency.setDisplayFileName(String.format("%s (shaded: %s)",
486 dependency.getDisplayFileName(), newDependency.getPackagePath()));
487 newDependency.setVersion(version);
488 setPomEvidence(newDependency, pom, null, true);
489 if (dependency.getProjectReferences().size() > 0) {
490 newDependency.addAllProjectReferences(dependency.getProjectReferences());
491 }
492 engine.addDependency(newDependency);
493 }
494 } catch (AnalysisException ex) {
495 LOGGER.warn("An error occurred while analyzing '{}'.", dependency.getActualFilePath());
496 LOGGER.trace("", ex);
497 }
498 }
499 } catch (IOException ex) {
500 LOGGER.warn("Unable to read JarFile '{}'.", dependency.getActualFilePath());
501 LOGGER.trace("", ex);
502 }
503 return evidenceAdded;
504 }
505
506
507
508
509
510
511
512
513
514 private Properties retrievePomProperties(String path, final JarFile jar) {
515 final Properties pomProperties = new Properties();
516 final String propPath = path.substring(0, path.length() - 7) + "pom.properties";
517 final ZipEntry propEntry = jar.getEntry(propPath);
518 if (propEntry != null) {
519 try (Reader reader = new InputStreamReader(jar.getInputStream(propEntry), StandardCharsets.UTF_8)) {
520 pomProperties.load(reader);
521 LOGGER.debug("Read pom.properties: {}", propPath);
522 } catch (UnsupportedEncodingException ex) {
523 LOGGER.trace("UTF-8 is not supported", ex);
524 } catch (IOException ex) {
525 LOGGER.trace("Unable to read the POM properties", ex);
526 }
527 }
528 return pomProperties;
529 }
530
531
532
533
534
535
536
537
538
539 private List<String> retrievePomListing(final JarFile jar) throws IOException {
540 final List<String> pomEntries = new ArrayList<>();
541 final Enumeration<JarEntry> entries = jar.entries();
542 while (entries.hasMoreElements()) {
543 final JarEntry entry = entries.nextElement();
544 final String entryName = new File(entry.getName()).getName().toLowerCase();
545 if (!entry.isDirectory() && "pom.xml".equals(entryName)
546 && entry.getName().toUpperCase().startsWith("META-INF")) {
547 pomEntries.add(entry.getName());
548 }
549 }
550 return pomEntries;
551 }
552
553
554
555
556
557
558
559
560
561
562 private File extractPom(String path, JarFile jar) throws AnalysisException {
563 final File tmpDir = getNextTempDirectory();
564 final File file = new File(tmpDir, "pom.xml");
565 final ZipEntry entry = jar.getEntry(path);
566 if (entry == null) {
567 throw new AnalysisException(String.format("Pom (%s) does not exist in %s", path, jar.getName()));
568 }
569 try (InputStream input = jar.getInputStream(entry);
570 FileOutputStream fos = new FileOutputStream(file)) {
571 IOUtils.copy(input, fos);
572 } catch (IOException ex) {
573 LOGGER.warn("An error occurred reading '{}' from '{}'.", path, jar.getName());
574 LOGGER.error("", ex);
575 }
576 return file;
577 }
578
579
580
581
582
583
584
585
586
587
588
589
590 public static boolean setPomEvidence(Dependency dependency, Model pom,
591 List<ClassNameInformation> classes, boolean isMainPom) {
592 if (pom == null) {
593 return false;
594 }
595 boolean foundSomething = false;
596 boolean addAsIdentifier = true;
597 String groupid = intepolationFailCheck(pom.getGroupId());
598 String parentGroupId = intepolationFailCheck(pom.getParentGroupId());
599 String artifactid = intepolationFailCheck(pom.getArtifactId());
600 String parentArtifactId = intepolationFailCheck(pom.getParentArtifactId());
601 String version = intepolationFailCheck(pom.getVersion());
602 String parentVersion = intepolationFailCheck(pom.getParentVersion());
603
604 if (("org.sonatype.oss".equals(parentGroupId) && "oss-parent".equals(parentArtifactId))
605 || ("org.springframework.boot".equals(parentGroupId) && "spring-boot-starter-parent".equals(parentArtifactId))) {
606 parentGroupId = null;
607 parentArtifactId = null;
608 parentVersion = null;
609 }
610
611 if ((groupid == null || groupid.isEmpty()) && parentGroupId != null && !parentGroupId.isEmpty()) {
612 groupid = parentGroupId;
613 }
614
615 final String originalGroupID = groupid;
616
617 if ((artifactid == null || artifactid.isEmpty()) && parentArtifactId != null && !parentArtifactId.isEmpty()) {
618 artifactid = parentArtifactId;
619 }
620
621 final String originalArtifactID = artifactid;
622 if (artifactid != null && (artifactid.startsWith("org.") || artifactid.startsWith("com."))) {
623 artifactid = artifactid.substring(4);
624 }
625
626 if ((version == null || version.isEmpty()) && parentVersion != null && !parentVersion.isEmpty()) {
627 version = parentVersion;
628 }
629
630 if (isMainPom && dependency.getName() == null && originalArtifactID != null && !originalArtifactID.isEmpty()) {
631 if (originalGroupID != null && !originalGroupID.isEmpty()) {
632 dependency.setName(String.format("%s:%s", originalGroupID, originalArtifactID));
633 } else {
634 dependency.setName(originalArtifactID);
635 }
636 }
637 if (isMainPom && dependency.getVersion() == null && version != null && !version.isEmpty()) {
638 dependency.setVersion(version);
639 }
640
641 if (groupid != null && !groupid.isEmpty()) {
642 foundSomething = true;
643 dependency.addEvidence(EvidenceType.VENDOR, "pom", "groupid", groupid, Confidence.HIGHEST);
644
645
646
647 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "groupid", groupid, Confidence.HIGHEST);
648 addMatchingValues(classes, groupid, dependency, EvidenceType.VENDOR);
649 addMatchingValues(classes, groupid, dependency, EvidenceType.PRODUCT);
650 if (parentGroupId != null && !parentGroupId.isEmpty() && !parentGroupId.equals(groupid)) {
651 dependency.addEvidence(EvidenceType.VENDOR, "pom", "parent-groupid", parentGroupId, Confidence.MEDIUM);
652
653
654 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "parent-groupid", parentGroupId, Confidence.MEDIUM);
655 addMatchingValues(classes, parentGroupId, dependency, EvidenceType.VENDOR);
656 addMatchingValues(classes, parentGroupId, dependency, EvidenceType.PRODUCT);
657 }
658 } else {
659 addAsIdentifier = false;
660 }
661
662 if (artifactid != null && !artifactid.isEmpty()) {
663 foundSomething = true;
664 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "artifactid", artifactid, Confidence.HIGHEST);
665 dependency.addEvidence(EvidenceType.VENDOR, "pom", "artifactid", artifactid, Confidence.LOW);
666 addMatchingValues(classes, artifactid, dependency, EvidenceType.VENDOR);
667 addMatchingValues(classes, artifactid, dependency, EvidenceType.PRODUCT);
668 if (parentArtifactId != null && !parentArtifactId.isEmpty() && !parentArtifactId.equals(artifactid)) {
669 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "parent-artifactid", parentArtifactId, Confidence.MEDIUM);
670 dependency.addEvidence(EvidenceType.VENDOR, "pom", "parent-artifactid", parentArtifactId, Confidence.LOW);
671 addMatchingValues(classes, parentArtifactId, dependency, EvidenceType.VENDOR);
672 addMatchingValues(classes, parentArtifactId, dependency, EvidenceType.PRODUCT);
673 }
674 } else {
675 addAsIdentifier = false;
676 }
677
678 if (version != null && !version.isEmpty()) {
679 foundSomething = true;
680 dependency.addEvidence(EvidenceType.VERSION, "pom", "version", version, Confidence.HIGHEST);
681 if (parentVersion != null && !parentVersion.isEmpty() && !parentVersion.equals(version)) {
682 dependency.addEvidence(EvidenceType.VERSION, "pom", "parent-version", version, Confidence.LOW);
683 }
684 } else {
685 addAsIdentifier = false;
686 }
687
688 if (addAsIdentifier && isMainPom) {
689 Identifier id = null;
690 try {
691 if (originalArtifactID != null && originalArtifactID.matches(VALID_NAME)
692 && originalGroupID != null && originalGroupID.matches(VALID_NAME)) {
693 final PackageURL purl = PackageURLBuilder.aPackageURL().withType("maven").withNamespace(originalGroupID)
694 .withName(originalArtifactID).withVersion(version).build();
695 id = new PurlIdentifier(purl, Confidence.HIGH);
696 } else {
697 LOGGER.debug("Invalid maven identifier identified: " + originalGroupID + ":" + originalArtifactID);
698 }
699 } catch (MalformedPackageURLException ex) {
700 final String gav = String.format("%s:%s:%s", originalGroupID, originalArtifactID, version);
701 LOGGER.debug("Error building package url for " + gav + "; using generic identifier instead.", ex);
702 id = new GenericIdentifier("maven:" + gav, Confidence.HIGH);
703 }
704 if (id != null) {
705 dependency.addSoftwareIdentifier(id);
706 }
707 }
708
709
710 final String org = pom.getOrganization();
711 if (org != null && !org.isEmpty()) {
712 dependency.addEvidence(EvidenceType.VENDOR, "pom", "organization name", org, Confidence.HIGH);
713 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "organization name", org, Confidence.LOW);
714 addMatchingValues(classes, org, dependency, EvidenceType.VENDOR);
715 addMatchingValues(classes, org, dependency, EvidenceType.PRODUCT);
716 }
717
718 String orgUrl = pom.getOrganizationUrl();
719 if (orgUrl != null && !orgUrl.isEmpty()) {
720 if (orgUrl.startsWith("https://github.com/") || orgUrl.startsWith("https://gitlab.com/")) {
721 orgUrl = orgUrl.substring(19);
722 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "url", orgUrl, Confidence.HIGH);
723 } else {
724 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "organization url", orgUrl, Confidence.LOW);
725 }
726 dependency.addEvidence(EvidenceType.VENDOR, "pom", "organization url", orgUrl, Confidence.MEDIUM);
727 }
728
729 final String pomName = pom.getName();
730 if (pomName != null && !pomName.isEmpty() && !"${project.groupId}:${project.artifactId}".equals(pomName)) {
731 foundSomething = true;
732 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "name", pomName, Confidence.HIGH);
733 dependency.addEvidence(EvidenceType.VENDOR, "pom", "name", pomName, Confidence.HIGH);
734 addMatchingValues(classes, pomName, dependency, EvidenceType.VENDOR);
735 addMatchingValues(classes, pomName, dependency, EvidenceType.PRODUCT);
736 }
737
738
739 final String description = pom.getDescription();
740 if (description != null && !description.isEmpty()
741 && !description.startsWith("POM was created by")
742 && !description.startsWith("Sonatype helps open source projects")
743 && !description.endsWith("project for Spring Boot")) {
744 foundSomething = true;
745 final String trimmedDescription = addDescription(dependency, description, "pom", "description");
746 addMatchingValues(classes, trimmedDescription, dependency, EvidenceType.VENDOR);
747 addMatchingValues(classes, trimmedDescription, dependency, EvidenceType.PRODUCT);
748 }
749
750 String projectURL = pom.getProjectURL();
751 if (projectURL != null && !projectURL.trim().isEmpty()) {
752 if (projectURL.startsWith("https://github.com/") || projectURL.startsWith("https://gitlab.com/")) {
753 projectURL = projectURL.substring(19);
754 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "url", projectURL, Confidence.HIGH);
755 } else {
756 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "url", projectURL, Confidence.MEDIUM);
757 }
758 dependency.addEvidence(EvidenceType.VENDOR, "pom", "url", projectURL, Confidence.HIGHEST);
759
760 }
761
762 if (pom.getDevelopers() != null && !pom.getDevelopers().isEmpty()) {
763 for (Developer dev : pom.getDevelopers()) {
764 if (!Strings.isNullOrEmpty(dev.getId())) {
765 dependency.addEvidence(EvidenceType.VENDOR, "pom", "developer id", dev.getId(), Confidence.MEDIUM);
766 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "developer id", dev.getId(), Confidence.LOW);
767 }
768 if (!Strings.isNullOrEmpty(dev.getName())) {
769 dependency.addEvidence(EvidenceType.VENDOR, "pom", "developer name", dev.getName(), Confidence.MEDIUM);
770 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "developer name", dev.getName(), Confidence.LOW);
771 }
772 if (!Strings.isNullOrEmpty(dev.getEmail())) {
773 dependency.addEvidence(EvidenceType.VENDOR, "pom", "developer email", dev.getEmail(), Confidence.LOW);
774 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "developer email", dev.getEmail(), Confidence.LOW);
775 }
776 if (!Strings.isNullOrEmpty(dev.getOrganizationUrl())) {
777 dependency.addEvidence(EvidenceType.VENDOR, "pom", "developer org URL", dev.getOrganizationUrl(), Confidence.MEDIUM);
778 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "developer org URL", dev.getOrganizationUrl(), Confidence.LOW);
779 }
780 final String devOrg = dev.getOrganization();
781 if (!Strings.isNullOrEmpty(devOrg)) {
782 dependency.addEvidence(EvidenceType.VENDOR, "pom", "developer org", devOrg, Confidence.MEDIUM);
783 dependency.addEvidence(EvidenceType.PRODUCT, "pom", "developer org", devOrg, Confidence.LOW);
784 addMatchingValues(classes, devOrg, dependency, EvidenceType.VENDOR);
785 addMatchingValues(classes, devOrg, dependency, EvidenceType.PRODUCT);
786 }
787 }
788 }
789
790 extractLicense(pom, dependency);
791 return foundSomething;
792 }
793
794
795
796
797
798
799
800
801
802
803
804
805 protected void analyzePackageNames(List<ClassNameInformation> classNames,
806 Dependency dependency, boolean addPackagesAsEvidence) {
807 final Map<String, Integer> vendorIdentifiers = new HashMap<>();
808 final Map<String, Integer> productIdentifiers = new HashMap<>();
809 analyzeFullyQualifiedClassNames(classNames, vendorIdentifiers, productIdentifiers);
810
811 final int classCount = classNames.size();
812
813 vendorIdentifiers.forEach((key, value) -> {
814 final float ratio = value / (float) classCount;
815 if (ratio > 0.5) {
816
817 dependency.addVendorWeighting(key);
818 if (addPackagesAsEvidence && key.length() > 1) {
819 dependency.addEvidence(EvidenceType.VENDOR, "jar", "package name", key, Confidence.LOW);
820 }
821 }
822 });
823 productIdentifiers.forEach((key, value) -> {
824 final float ratio = value / (float) classCount;
825 if (ratio > 0.5) {
826
827 dependency.addProductWeighting(key);
828 if (addPackagesAsEvidence && key.length() > 1) {
829 dependency.addEvidence(EvidenceType.PRODUCT, "jar", "package name", key, Confidence.LOW);
830 }
831 }
832 });
833 }
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852 protected boolean parseManifest(Dependency dependency, List<ClassNameInformation> classInformation)
853 throws IOException {
854 boolean foundSomething = false;
855 try (JarFile jar = new JarFile(dependency.getActualFilePath(), false)) {
856 final Manifest manifest = jar.getManifest();
857 if (manifest == null) {
858 if (!dependency.getFileName().toLowerCase().endsWith("-sources.jar")
859 && !dependency.getFileName().toLowerCase().endsWith("-javadoc.jar")
860 && !dependency.getFileName().toLowerCase().endsWith("-src.jar")
861 && !dependency.getFileName().toLowerCase().endsWith("-doc.jar")) {
862 LOGGER.debug("Jar file '{}' does not contain a manifest.", dependency.getFileName());
863 }
864 return false;
865 }
866 String source = "Manifest";
867 String specificationVersion = null;
868 boolean hasImplementationVersion = false;
869 Attributes atts = manifest.getMainAttributes();
870 for (Entry<Object, Object> entry : atts.entrySet()) {
871 String key = entry.getKey().toString();
872 String value = atts.getValue(key);
873 if (HTML_DETECTION_PATTERN.matcher(value).find()) {
874 value = Jsoup.parse(value).text();
875 }
876 if (value.startsWith("git@github.com:") || value.startsWith("git@gitlab.com:")) {
877 value = value.substring(15);
878 }
879 if (IGNORE_VALUES.contains(value)) {
880 continue;
881 } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_TITLE.toString())) {
882 foundSomething = true;
883 dependency.addEvidence(EvidenceType.PRODUCT, source, key, value, Confidence.HIGH);
884 addMatchingValues(classInformation, value, dependency, EvidenceType.PRODUCT);
885 } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_VERSION.toString())) {
886 hasImplementationVersion = true;
887 foundSomething = true;
888 dependency.addEvidence(EvidenceType.VERSION, source, key, value, Confidence.HIGH);
889 } else if ("specification-version".equalsIgnoreCase(key)) {
890 specificationVersion = value;
891 } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_VENDOR.toString())) {
892 foundSomething = true;
893 dependency.addEvidence(EvidenceType.VENDOR, source, key, value, Confidence.HIGH);
894 addMatchingValues(classInformation, value, dependency, EvidenceType.VENDOR);
895 } else if (key.equalsIgnoreCase(IMPLEMENTATION_VENDOR_ID)) {
896 foundSomething = true;
897 dependency.addEvidence(EvidenceType.VENDOR, source, key, value, Confidence.MEDIUM);
898 addMatchingValues(classInformation, value, dependency, EvidenceType.VENDOR);
899 } else if (key.equalsIgnoreCase(BUNDLE_DESCRIPTION)) {
900 if (!value.startsWith("Sonatype helps open source projects")) {
901 foundSomething = true;
902 addDescription(dependency, value, "manifest", key);
903 addMatchingValues(classInformation, value, dependency, EvidenceType.PRODUCT);
904 }
905 } else if (key.equalsIgnoreCase(BUNDLE_NAME)) {
906 foundSomething = true;
907 dependency.addEvidence(EvidenceType.PRODUCT, source, key, value, Confidence.MEDIUM);
908 addMatchingValues(classInformation, value, dependency, EvidenceType.PRODUCT);
909
910
911 } else if (key.equalsIgnoreCase(BUNDLE_VERSION)) {
912 foundSomething = true;
913 dependency.addEvidence(EvidenceType.VERSION, source, key, value, Confidence.HIGH);
914 } else if (key.equalsIgnoreCase(Attributes.Name.MAIN_CLASS.toString())) {
915
916 continue;
917
918 } else if ("implementation-url".equalsIgnoreCase(key)
919 && value != null
920 && value.startsWith("https://projects.spring.io/spring-boot/#/spring-boot-starter-parent/parent/")) {
921 continue;
922 } else {
923 key = key.toLowerCase();
924 if (!IGNORE_KEYS.contains(key)
925 && !key.endsWith("jdk")
926 && !key.contains("lastmodified")
927 && !key.endsWith("package")
928 && !key.endsWith("classpath")
929 && !key.endsWith("class-path")
930 && !key.endsWith("-scm")
931 && !key.startsWith("scm-")
932 && !value.trim().startsWith("scm:")
933 && !isImportPackage(key, value)
934 && !isPackage(key, value)) {
935 foundSomething = true;
936 if (key.contains("version")) {
937 if (!key.contains("specification")) {
938 dependency.addEvidence(EvidenceType.VERSION, source, key, value, Confidence.MEDIUM);
939 }
940 } else if ("build-id".equals(key)) {
941 int pos = value.indexOf('(');
942 if (pos > 0) {
943 value = value.substring(0, pos - 1);
944 }
945 pos = value.indexOf('[');
946 if (pos > 0) {
947 value = value.substring(0, pos - 1);
948 }
949 dependency.addEvidence(EvidenceType.VERSION, source, key, value, Confidence.MEDIUM);
950 } else if (key.contains("title")) {
951 dependency.addEvidence(EvidenceType.PRODUCT, source, key, value, Confidence.MEDIUM);
952 addMatchingValues(classInformation, value, dependency, EvidenceType.PRODUCT);
953 } else if (key.contains("vendor")) {
954 if (key.contains("specification")) {
955 dependency.addEvidence(EvidenceType.VENDOR, source, key, value, Confidence.LOW);
956 } else {
957 dependency.addEvidence(EvidenceType.VENDOR, source, key, value, Confidence.MEDIUM);
958 addMatchingValues(classInformation, value, dependency, EvidenceType.VENDOR);
959 }
960 } else if (key.contains("name")) {
961 dependency.addEvidence(EvidenceType.PRODUCT, source, key, value, Confidence.MEDIUM);
962 dependency.addEvidence(EvidenceType.VENDOR, source, key, value, Confidence.MEDIUM);
963 addMatchingValues(classInformation, value, dependency, EvidenceType.VENDOR);
964 addMatchingValues(classInformation, value, dependency, EvidenceType.PRODUCT);
965 } else if (key.contains("license")) {
966 addLicense(dependency, value);
967 } else if (key.contains("description")) {
968 if (!value.startsWith("Sonatype helps open source projects")) {
969 final String trimmedDescription = addDescription(dependency, value, "manifest", key);
970 addMatchingValues(classInformation, trimmedDescription, dependency, EvidenceType.VENDOR);
971 addMatchingValues(classInformation, trimmedDescription, dependency, EvidenceType.PRODUCT);
972 }
973 } else {
974 dependency.addEvidence(EvidenceType.PRODUCT, source, key, value, Confidence.LOW);
975 dependency.addEvidence(EvidenceType.VENDOR, source, key, value, Confidence.LOW);
976 addMatchingValues(classInformation, value, dependency, EvidenceType.VERSION);
977 addMatchingValues(classInformation, value, dependency, EvidenceType.PRODUCT);
978 if (value.matches(".*\\d.*")) {
979 final StringTokenizer tokenizer = new StringTokenizer(value, " ");
980 while (tokenizer.hasMoreElements()) {
981 final String s = tokenizer.nextToken();
982 if (s.matches("^[0-9.]+$")) {
983 dependency.addEvidence(EvidenceType.VERSION, source, key, s, Confidence.LOW);
984 }
985 }
986 }
987 }
988 }
989 }
990 }
991 for (Map.Entry<String, Attributes> item : manifest.getEntries().entrySet()) {
992 final String name = item.getKey();
993 source = "manifest: " + name;
994 atts = item.getValue();
995 for (Entry<Object, Object> entry : atts.entrySet()) {
996 final String key = entry.getKey().toString();
997 final String value = atts.getValue(key);
998 if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_TITLE.toString())) {
999 foundSomething = true;
1000 dependency.addEvidence(EvidenceType.PRODUCT, source, key, value, Confidence.MEDIUM);
1001 addMatchingValues(classInformation, value, dependency, EvidenceType.PRODUCT);
1002 } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_VERSION.toString())) {
1003 foundSomething = true;
1004 dependency.addEvidence(EvidenceType.VERSION, source, key, value, Confidence.MEDIUM);
1005 } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_VENDOR.toString())) {
1006 foundSomething = true;
1007 dependency.addEvidence(EvidenceType.VENDOR, source, key, value, Confidence.MEDIUM);
1008 addMatchingValues(classInformation, value, dependency, EvidenceType.VENDOR);
1009 } else if (key.equalsIgnoreCase(Attributes.Name.SPECIFICATION_TITLE.toString())) {
1010 foundSomething = true;
1011 dependency.addEvidence(EvidenceType.PRODUCT, source, key, value, Confidence.MEDIUM);
1012 addMatchingValues(classInformation, value, dependency, EvidenceType.PRODUCT);
1013 }
1014 }
1015 }
1016 if (specificationVersion != null && !hasImplementationVersion) {
1017 foundSomething = true;
1018 dependency.addEvidence(EvidenceType.VERSION, source, "specification-version", specificationVersion, Confidence.HIGH);
1019 }
1020 }
1021 return foundSomething;
1022 }
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039 public static String addDescription(Dependency dependency, String description, String source, String key) {
1040 if (dependency.getDescription() == null) {
1041 dependency.setDescription(description);
1042 }
1043 String desc;
1044 if (HTML_DETECTION_PATTERN.matcher(description).find()) {
1045 desc = Jsoup.parse(description).text();
1046 } else {
1047 desc = description;
1048 }
1049 dependency.setDescription(desc);
1050 if (desc.length() > 100) {
1051 desc = desc.replaceAll("\\s\\s+", " ");
1052 final int posSuchAs = desc.toLowerCase().indexOf("such as ", 100);
1053 final int posLike = desc.toLowerCase().indexOf("like ", 100);
1054 final int posWillUse = desc.toLowerCase().indexOf("will use ", 100);
1055 final int posUses = desc.toLowerCase().indexOf(" uses ", 100);
1056
1057 int pos = -1;
1058 pos = Math.max(pos, posSuchAs);
1059 if (pos >= 0 && posLike >= 0) {
1060 pos = Math.min(pos, posLike);
1061 } else {
1062 pos = Math.max(pos, posLike);
1063 }
1064 if (pos >= 0 && posWillUse >= 0) {
1065 pos = Math.min(pos, posWillUse);
1066 } else {
1067 pos = Math.max(pos, posWillUse);
1068 }
1069 if (pos >= 0 && posUses >= 0) {
1070 pos = Math.min(pos, posUses);
1071 } else {
1072 pos = Math.max(pos, posUses);
1073 }
1074 if (pos > 0) {
1075 desc = desc.substring(0, pos) + "...";
1076 }
1077
1078
1079
1080
1081
1082
1083
1084 }
1085 return desc;
1086 }
1087
1088
1089
1090
1091
1092
1093
1094 private void addLicense(Dependency d, String license) {
1095 if (d.getLicense() == null) {
1096 d.setLicense(license);
1097 } else if (!d.getLicense().contains(license)) {
1098 d.setLicense(d.getLicense() + NEWLINE + license);
1099 }
1100 }
1101
1102
1103
1104
1105
1106
1107
1108
1109 @Override
1110 public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
1111 try {
1112 final File baseDir = getSettings().getTempDirectory();
1113 tempFileLocation = File.createTempFile("check", "tmp", baseDir);
1114 if (!tempFileLocation.delete()) {
1115 final String msg = String.format("Unable to delete temporary file '%s'.", tempFileLocation.getAbsolutePath());
1116 setEnabled(false);
1117 throw new InitializationException(msg);
1118 }
1119 if (!tempFileLocation.mkdirs()) {
1120 final String msg = String.format("Unable to create directory '%s'.", tempFileLocation.getAbsolutePath());
1121 setEnabled(false);
1122 throw new InitializationException(msg);
1123 }
1124 } catch (IOException ex) {
1125 setEnabled(false);
1126 throw new InitializationException("Unable to create a temporary file", ex);
1127 }
1128 }
1129
1130
1131
1132
1133 @Override
1134 public void closeAnalyzer() {
1135 if (tempFileLocation != null && tempFileLocation.exists()) {
1136 LOGGER.debug("Attempting to delete temporary files from `{}`", tempFileLocation.toString());
1137 final boolean success = FileUtils.delete(tempFileLocation);
1138 if (!success && tempFileLocation.exists()) {
1139 final String[] l = tempFileLocation.list();
1140 if (l != null && l.length > 0) {
1141 LOGGER.warn("Failed to delete the JAR Analyzder's temporary files from `{}`, "
1142 + "see the log for more details", tempFileLocation.getAbsolutePath());
1143 }
1144 }
1145 }
1146 }
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157 private boolean isImportPackage(String key, String value) {
1158 final Pattern packageRx = Pattern.compile("^(\\s*[a-zA-Z0-9_#\\$\\*\\.]+\\s*[,;])+(\\s*[a-zA-Z0-9_#\\$\\*\\.]+\\s*)?$");
1159 final boolean matches = packageRx.matcher(value).matches();
1160 return matches && (key.contains("import") || key.contains("include") || value.length() > 10);
1161 }
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171 protected List<ClassNameInformation> collectClassNames(Dependency dependency) {
1172 final List<ClassNameInformation> classNames = new ArrayList<>();
1173 try (JarFile jar = new JarFile(dependency.getActualFilePath(), false)) {
1174 final Enumeration<JarEntry> entries = jar.entries();
1175 while (entries.hasMoreElements()) {
1176 final JarEntry entry = entries.nextElement();
1177 final String name = entry.getName().toLowerCase();
1178
1179 if (name.endsWith(".class") && !name.matches("^javax?\\..*$")) {
1180 final ClassNameInformation className = new ClassNameInformation(name.substring(0, name.length() - 6));
1181 classNames.add(className);
1182 }
1183 }
1184 } catch (IOException ex) {
1185 LOGGER.warn("Unable to open jar file '{}'.", dependency.getFileName());
1186 LOGGER.debug("", ex);
1187 }
1188 return classNames;
1189 }
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203 private void analyzeFullyQualifiedClassNames(List<ClassNameInformation> classNames,
1204 Map<String, Integer> vendor, Map<String, Integer> product) {
1205 for (ClassNameInformation entry : classNames) {
1206 final List<String> list = entry.getPackageStructure();
1207 addEntry(vendor, list.get(0));
1208
1209 if (list.size() == 2) {
1210 addEntry(product, list.get(1));
1211 } else if (list.size() == 3) {
1212 addEntry(vendor, list.get(1));
1213 addEntry(product, list.get(1));
1214 addEntry(product, list.get(2));
1215 } else if (list.size() >= 4) {
1216 addEntry(vendor, list.get(1));
1217 addEntry(vendor, list.get(2));
1218 addEntry(product, list.get(1));
1219 addEntry(product, list.get(2));
1220 addEntry(product, list.get(3));
1221 }
1222 }
1223 }
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233 private void addEntry(Map<String, Integer> collection, String key) {
1234 if (collection.containsKey(key)) {
1235 collection.put(key, collection.get(key) + 1);
1236 } else {
1237 collection.put(key, 1);
1238 }
1239 }
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252 protected static void addMatchingValues(List<ClassNameInformation> classes, String value, Dependency dep, EvidenceType type) {
1253 if (value == null || value.isEmpty() || classes == null || classes.isEmpty()) {
1254 return;
1255 }
1256 final HashSet<String> tested = new HashSet<>();
1257
1258 for (ClassNameInformation cni : classes) {
1259
1260 for (String key : cni.getPackageStructure()) {
1261
1262 if (!tested.contains(key)) {
1263 tested.add(key);
1264 final int pos = StringUtils.indexOfIgnoreCase(value, key);
1265 if ((pos == 0 && (key.length() == value.length() || (key.length() < value.length()
1266 && !Character.isLetterOrDigit(value.charAt(key.length())))))
1267 || (pos > 0 && !Character.isLetterOrDigit(value.charAt(pos - 1))
1268 && (pos + key.length() == value.length() || (key.length() < value.length()
1269 && !Character.isLetterOrDigit(value.charAt(pos + key.length())))))) {
1270 dep.addEvidence(type, "jar", "package name", key, Confidence.HIGHEST);
1271 }
1272 }
1273 }
1274 }
1275 }
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285 private boolean isPackage(String key, String value) {
1286
1287 return !key.matches(".*(version|title|vendor|name|license|description).*")
1288 && value.matches("^[a-zA-Z_][a-zA-Z0-9_\\$]*\\.([a-zA-Z_][a-zA-Z0-9_\\$]*\\.)*([a-zA-Z_][a-zA-Z0-9_\\$]*)$");
1289
1290 }
1291
1292
1293
1294
1295
1296
1297
1298 private static String intepolationFailCheck(String value) {
1299 if (value != null && value.contains("${")) {
1300 return null;
1301 }
1302 return value;
1303 }
1304
1305
1306
1307
1308
1309
1310
1311
1312 public static void extractLicense(Model pom, Dependency dependency) {
1313
1314 if (pom.getLicenses() != null) {
1315 StringBuilder license = null;
1316 for (License lic : pom.getLicenses()) {
1317 String tmp = null;
1318 if (lic.getName() != null) {
1319 tmp = lic.getName();
1320 }
1321 if (lic.getUrl() != null) {
1322 if (tmp == null) {
1323 tmp = lic.getUrl();
1324 } else {
1325 tmp += ": " + lic.getUrl();
1326 }
1327 }
1328 if (tmp == null) {
1329 continue;
1330 }
1331 if (HTML_DETECTION_PATTERN.matcher(tmp).find()) {
1332 tmp = Jsoup.parse(tmp).text();
1333 }
1334 if (license == null) {
1335 license = new StringBuilder(tmp);
1336 } else {
1337 license.append("\n").append(tmp);
1338 }
1339 }
1340 if (license != null) {
1341 dependency.setLicense(license.toString());
1342
1343 }
1344 }
1345 }
1346
1347
1348
1349
1350 protected static class ClassNameInformation {
1351
1352
1353
1354
1355 private String name;
1356
1357
1358
1359
1360 private final ArrayList<String> packageStructure = new ArrayList<>();
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384 ClassNameInformation(String className) {
1385 name = className;
1386 if (name.contains("/")) {
1387 final String[] tmp = StringUtils.split(className.toLowerCase(), '/');
1388 int start = 0;
1389 int end = 3;
1390 if ("com".equals(tmp[0]) || "org".equals(tmp[0])) {
1391 start = 1;
1392 end = 4;
1393 }
1394 if (tmp.length <= end) {
1395 end = tmp.length - 1;
1396 }
1397 packageStructure.addAll(Arrays.asList(tmp).subList(start, end + 1));
1398 } else {
1399 packageStructure.add(name);
1400 }
1401 }
1402
1403
1404
1405
1406
1407
1408 public String getName() {
1409 return name;
1410 }
1411
1412
1413
1414
1415
1416
1417 public void setName(String name) {
1418 this.name = name;
1419 }
1420
1421
1422
1423
1424
1425
1426 public ArrayList<String> getPackageStructure() {
1427 return packageStructure;
1428 }
1429 }
1430
1431
1432
1433
1434
1435
1436
1437 private File getNextTempDirectory() throws AnalysisException {
1438 final int dirCount = DIR_COUNT.incrementAndGet();
1439 final File directory = new File(tempFileLocation, String.valueOf(dirCount));
1440
1441 if (directory.exists()) {
1442 return getNextTempDirectory();
1443 }
1444 if (!directory.mkdirs()) {
1445 final String msg = String.format("Unable to create temp directory '%s'.", directory.getAbsolutePath());
1446 throw new AnalysisException(msg);
1447 }
1448 return directory;
1449 }
1450 }