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 java.io.IOException;
22 import java.io.Reader;
23 import java.util.Collection;
24
25 import org.apache.rat.api.Document;
26 import org.apache.rat.document.DocumentAnalyser;
27 import org.apache.rat.license.ILicense;
28 import org.apache.rat.utils.DefaultLog;
29
30 import static java.lang.String.format;
31
32
33
34
35 class DocumentHeaderAnalyser implements DocumentAnalyser {
36
37
38 private final Collection<ILicense> licenses;
39
40 private final IHeaderMatcher generatedMatcher;
41
42
43
44
45
46 DocumentHeaderAnalyser(final IHeaderMatcher generatedMatcher, final Collection<ILicense> licenses) {
47 super();
48 this.generatedMatcher = generatedMatcher;
49 this.licenses = licenses;
50 }
51
52 @Override
53 public void analyse(final Document document) {
54 if (!document.isIgnored()) {
55 try (Reader reader = document.reader()) {
56 DefaultLog.getInstance().debug(format("Processing: %s", document));
57 HeaderCheckWorker worker = new HeaderCheckWorker(generatedMatcher, reader, licenses, document);
58 worker.read();
59 } catch (IOException e) {
60 DefaultLog.getInstance().warn(String.format("Cannot read header of %s", document));
61 document.getMetaData().setDocumentType(Document.Type.UNKNOWN);
62 } catch (RatHeaderAnalysisException e) {
63 DefaultLog.getInstance().warn(String.format("Cannot process header of %s", document));
64 document.getMetaData().setDocumentType(Document.Type.UNKNOWN);
65 }
66 }
67 }
68 }