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 java.io.File;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.InputStreamReader;
27 import java.io.Reader;
28
29 import org.apache.rat.api.Document;
30 import org.apache.rat.api.MetaData;
31 import org.apache.rat.api.RatException;
32 import org.apache.rat.document.impl.DocumentImplUtils;
33 import org.apache.rat.report.IReportable;
34 import org.apache.rat.report.RatReport;
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 ( int i = 0; i < files.length; i++ )
66 {
67 document.setFile( new File( basedir, files[i] ) );
68 document.getMetaData().clear();
69 report.report( document );
70 }
71 }
72
73 private class FileDocument implements Document
74 {
75 private File file;
76 private final MetaData metaData = new MetaData();
77
78 void setFile( File file )
79 {
80 this.file = file;
81 }
82
83 public boolean isComposite() {
84 return DocumentImplUtils.isZip(file);
85 }
86
87 public Reader reader() throws IOException
88 {
89 final InputStream in = new FileInputStream( file );
90 return new InputStreamReader( in );
91 }
92
93 public String getName()
94 {
95 return DocumentImplUtils.toName( file );
96 }
97
98 public MetaData getMetaData() {
99 return metaData;
100 }
101
102 public InputStream inputStream() throws IOException {
103 return new FileInputStream(file);
104 }
105
106 public String toString() {
107 return "File:" + file.getAbsolutePath();
108 }
109 }
110 }