1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.jar.identification.exposers;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.text.SimpleDateFormat;
25 import java.util.Date;
26 import java.util.List;
27 import java.util.Locale;
28 import java.util.jar.JarEntry;
29
30 import org.apache.commons.collections4.Bag;
31 import org.apache.commons.collections4.bag.HashBag;
32 import org.apache.maven.shared.jar.JarAnalyzer;
33 import org.apache.maven.shared.jar.identification.JarIdentification;
34 import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
35
36
37
38
39 @Singleton
40 @Named("timestamp")
41 public class TimestampExposer implements JarIdentificationExposer {
42 @Override
43 public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
44 List<JarEntry> entries = jarAnalyzer.getEntries();
45 SimpleDateFormat tsformat = new SimpleDateFormat("yyyyMMdd", Locale.US);
46 Bag<String> timestamps = new HashBag<>();
47 for (JarEntry entry : entries) {
48 long time = entry.getTime();
49 String timestamp = tsformat.format(new Date(time));
50 timestamps.add(timestamp);
51 }
52
53 String ts = "";
54 int tsmax = 0;
55 for (String timestamp : timestamps) {
56 int count = timestamps.getCount(timestamp);
57 if (count > tsmax) {
58 ts = timestamp;
59 tsmax = count;
60 }
61 }
62
63 if (ts != null && !ts.isEmpty()) {
64 identification.addVersion(ts);
65 }
66 }
67 }