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 import org.codehaus.plexus.util.StringUtils;
36
37
38
39
40 @Singleton
41 @Named("timestamp")
42 public class TimestampExposer implements JarIdentificationExposer {
43 @Override
44 public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
45 List<JarEntry> entries = jarAnalyzer.getEntries();
46 SimpleDateFormat tsformat = new SimpleDateFormat("yyyyMMdd", Locale.US);
47 Bag<String> timestamps = new HashBag<>();
48 for (JarEntry entry : entries) {
49 long time = entry.getTime();
50 String timestamp = tsformat.format(new Date(time));
51 timestamps.add(timestamp);
52 }
53
54 String ts = "";
55 int tsmax = 0;
56 for (String timestamp : timestamps) {
57 int count = timestamps.getCount(timestamp);
58 if (count > tsmax) {
59 ts = timestamp;
60 tsmax = count;
61 }
62 }
63
64 if (StringUtils.isNotEmpty(ts)) {
65 identification.addVersion(ts);
66 }
67 }
68 }