1 | |
package org.apache.maven.shared.jar.identification.exposers; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.shared.jar.JarAnalyzer; |
23 | |
import org.apache.maven.shared.jar.identification.JarIdentification; |
24 | |
import org.apache.maven.shared.jar.identification.JarIdentificationExposer; |
25 | |
import org.codehaus.plexus.logging.AbstractLogEnabled; |
26 | |
import org.codehaus.plexus.util.IOUtil; |
27 | |
import org.codehaus.plexus.util.StringUtils; |
28 | |
|
29 | |
import java.io.BufferedReader; |
30 | |
import java.io.IOException; |
31 | |
import java.io.InputStream; |
32 | |
import java.io.InputStreamReader; |
33 | |
import java.util.ArrayList; |
34 | |
import java.util.Iterator; |
35 | |
import java.util.List; |
36 | |
import java.util.jar.JarEntry; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class TextFileExposer |
46 | |
extends AbstractLogEnabled |
47 | |
implements JarIdentificationExposer |
48 | |
{ |
49 | |
public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer ) |
50 | |
{ |
51 | 0 | List textFiles = findTextFileVersions( jarAnalyzer ); |
52 | 0 | if ( !textFiles.isEmpty() ) |
53 | |
{ |
54 | 0 | Iterator ithits = textFiles.iterator(); |
55 | 0 | while ( ithits.hasNext() ) |
56 | |
{ |
57 | 0 | String ver = (String) ithits.next(); |
58 | 0 | identification.addVersion( ver ); |
59 | 0 | } |
60 | |
} |
61 | 0 | } |
62 | |
|
63 | |
private List findTextFileVersions( JarAnalyzer jarAnalyzer ) |
64 | |
{ |
65 | 0 | List textVersions = new ArrayList(); |
66 | 0 | List hits = jarAnalyzer.getVersionEntries(); |
67 | |
|
68 | 0 | Iterator it = hits.iterator(); |
69 | 0 | while ( it.hasNext() ) |
70 | |
{ |
71 | 0 | JarEntry entry = (JarEntry) it.next(); |
72 | |
|
73 | |
|
74 | 0 | if ( !entry.getName().endsWith( ".class" ) ) |
75 | |
{ |
76 | 0 | getLogger().debug( "Version Hit: " + entry.getName() ); |
77 | 0 | InputStream is = null; |
78 | |
try |
79 | |
{ |
80 | 0 | is = jarAnalyzer.getEntryInputStream( entry ); |
81 | 0 | BufferedReader br = new BufferedReader( new InputStreamReader( is ) ); |
82 | |
|
83 | 0 | String line = br.readLine(); |
84 | |
|
85 | |
|
86 | |
|
87 | 0 | getLogger().debug( line ); |
88 | 0 | if ( StringUtils.isNotEmpty( line ) ) |
89 | |
{ |
90 | 0 | textVersions.add( line ); |
91 | |
} |
92 | |
} |
93 | 0 | catch ( IOException e ) |
94 | |
{ |
95 | 0 | getLogger().warn( "Unable to read line from " + entry.getName(), e ); |
96 | |
} |
97 | |
finally |
98 | |
{ |
99 | 0 | IOUtil.close( is ); |
100 | 0 | } |
101 | |
} |
102 | 0 | } |
103 | 0 | return textVersions; |
104 | |
} |
105 | |
} |