1 package org.apache.rat.mp;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.rat.api.Document;
23 import org.apache.rat.api.MetaData;
24 import org.apache.rat.api.RatException;
25 import org.apache.rat.document.impl.DocumentImplUtils;
26 import org.apache.rat.report.IReportable;
27 import org.apache.rat.report.RatReport;
28
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.io.InputStream;
33 import java.io.InputStreamReader;
34 import java.io.Reader;
35
36
37
38
39
40 class FilesReportable implements IReportable
41 {
42 private final File basedir;
43
44 private final String[] files;
45
46 FilesReportable( File basedir, String[] files )
47 throws IOException
48 {
49 final File currentDir = new File( System.getProperty( "user.dir" ) ).getCanonicalFile();
50 final File f = basedir.getCanonicalFile();
51 if ( currentDir.equals( f ) )
52 {
53 this.basedir = null;
54 }
55 else
56 {
57 this.basedir = basedir;
58 }
59 this.files = files;
60 }
61
62 public void run( RatReport report ) throws RatException
63 {
64 FileDocument document = new FileDocument();
65 for (String file : files) {
66 document.setFile(new File(basedir, file));
67 document.getMetaData().clear();
68 report.report(document);
69 }
70 }
71
72 private class FileDocument implements Document
73 {
74 private File file;
75 private final MetaData metaData = new MetaData();
76
77 void setFile( File file )
78 {
79 this.file = file;
80 }
81
82 public boolean isComposite() {
83 return DocumentImplUtils.isZip(file);
84 }
85
86 public Reader reader() throws IOException
87 {
88 final InputStream in = new FileInputStream( file );
89 return new InputStreamReader( in );
90 }
91
92 public String getName()
93 {
94 return DocumentImplUtils.toName( file );
95 }
96
97 public MetaData getMetaData() {
98 return metaData;
99 }
100
101 public InputStream inputStream() throws IOException {
102 return new FileInputStream(file);
103 }
104
105 @Override
106 public String toString() {
107 return "File:" + file.getAbsolutePath();
108 }
109 }
110 }