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 public class TimestampExposer
42 implements JarIdentificationExposer
43 {
44 public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
45 {
46 List entries = jarAnalyzer.getEntries();
47 SimpleDateFormat tsformat = new SimpleDateFormat( "yyyyMMdd", Locale.US );
48 Bag timestamps = new HashBag();
49 Iterator it = entries.iterator();
50 while ( it.hasNext() )
51 {
52 JarEntry entry = (JarEntry) it.next();
53 long time = entry.getTime();
54 String timestamp = tsformat.format( new Date( time ) );
55 timestamps.add( timestamp );
56 }
57
58 it = timestamps.iterator();
59 String ts = "";
60 int tsmax = 0;
61 while ( it.hasNext() )
62 {
63 String timestamp = (String) it.next();
64 int count = timestamps.getCount( timestamp );
65 if ( count > tsmax )
66 {
67 ts = timestamp;
68 tsmax = count;
69 }
70 }
71
72 if ( StringUtils.isNotEmpty( ts ) )
73 {
74 identification.addVersion( ts );
75 }
76 }
77 }