1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.analysis;
20
21 import static java.lang.String.format;
22
23 import java.io.IOException;
24 import java.io.Reader;
25 import java.util.Collection;
26
27 import org.apache.rat.api.Document;
28 import org.apache.rat.document.IDocumentAnalyser;
29 import org.apache.rat.license.ILicense;
30 import org.apache.rat.utils.Log;
31
32
33
34
35 class DocumentHeaderAnalyser implements IDocumentAnalyser {
36
37
38 private final Collection<ILicense> licenses;
39
40 private final Log log;
41
42
43
44
45
46
47
48 public DocumentHeaderAnalyser(final Log log, final Collection<ILicense> licenses) {
49 super();
50 this.licenses = licenses;
51 this.log = log;
52 }
53
54 @Override
55 public void analyse(Document document) {
56 try (Reader reader = document.reader()) {
57 log.debug(format("Processing: %s", document));
58 HeaderCheckWorker worker = new HeaderCheckWorker(reader, licenses, document);
59 worker.read();
60 } catch (IOException e) {
61 log.warn(String.format("Cannot read header of %s", document));
62 document.getMetaData().setDocumentType(Document.Type.UNKNOWN);
63 } catch (RatHeaderAnalysisException e) {
64 log.warn(String.format("Cannot process header of %s", document));
65 document.getMetaData().setDocumentType(Document.Type.UNKNOWN);
66 }
67 }
68
69 }