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.commons.collections.Bag; |
23 | |
import org.apache.commons.collections.bag.HashBag; |
24 | |
import org.apache.maven.shared.jar.JarAnalyzer; |
25 | |
import org.apache.maven.shared.jar.identification.JarIdentification; |
26 | |
import org.apache.maven.shared.jar.identification.JarIdentificationExposer; |
27 | |
import org.codehaus.plexus.util.StringUtils; |
28 | |
|
29 | |
import java.text.SimpleDateFormat; |
30 | |
import java.util.Date; |
31 | |
import java.util.Iterator; |
32 | |
import java.util.List; |
33 | |
import java.util.Locale; |
34 | |
import java.util.jar.JarEntry; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class TimestampExposer |
42 | |
implements JarIdentificationExposer |
43 | |
{ |
44 | |
public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer ) |
45 | |
{ |
46 | 0 | List entries = jarAnalyzer.getEntries(); |
47 | 0 | SimpleDateFormat tsformat = new SimpleDateFormat( "yyyyMMdd", Locale.US ); |
48 | 0 | Bag timestamps = new HashBag(); |
49 | 0 | Iterator it = entries.iterator(); |
50 | 0 | while ( it.hasNext() ) |
51 | |
{ |
52 | 0 | JarEntry entry = (JarEntry) it.next(); |
53 | 0 | long time = entry.getTime(); |
54 | 0 | String timestamp = tsformat.format( new Date( time ) ); |
55 | 0 | timestamps.add( timestamp ); |
56 | 0 | } |
57 | |
|
58 | 0 | it = timestamps.iterator(); |
59 | 0 | String ts = ""; |
60 | 0 | int tsmax = 0; |
61 | 0 | while ( it.hasNext() ) |
62 | |
{ |
63 | 0 | String timestamp = (String) it.next(); |
64 | 0 | int count = timestamps.getCount( timestamp ); |
65 | 0 | if ( count > tsmax ) |
66 | |
{ |
67 | 0 | ts = timestamp; |
68 | 0 | tsmax = count; |
69 | |
} |
70 | 0 | } |
71 | |
|
72 | 0 | if ( StringUtils.isNotEmpty( ts ) ) |
73 | |
{ |
74 | 0 | identification.addVersion( ts ); |
75 | |
} |
76 | 0 | } |
77 | |
} |