28
28
import java .io .IOException ;
29
29
import java .net .URL ;
30
30
import java .net .URLClassLoader ;
31
+ import java .text .DateFormat ;
32
+ import java .text .ParseException ;
33
+ import java .text .SimpleDateFormat ;
31
34
import java .util .ArrayList ;
32
35
import java .util .List ;
33
36
import java .util .jar .JarEntry ;
@@ -46,6 +49,7 @@ public class ServiceDescriptorGenerator
46
49
extends AbstractMojo
47
50
{
48
51
private static final String LS = System .lineSeparator ();
52
+ private static final DateFormat OUTPUT_DATE_FORMAT = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ssXXX" );
49
53
50
54
@ Parameter (defaultValue = "io.trino.spi.Plugin" )
51
55
private String pluginClassName ;
@@ -59,6 +63,9 @@ public class ServiceDescriptorGenerator
59
63
@ Parameter (defaultValue = "${project.build.outputDirectory}" )
60
64
private File classesDirectory ;
61
65
66
+ @ Parameter (defaultValue = "${project.build.outputTimestamp}" )
67
+ private String outputTimestamp ;
68
+
62
69
@ Parameter (defaultValue = "${project}" )
63
70
private MavenProject project ;
64
71
@@ -96,7 +103,18 @@ public void execute()
96
103
97
104
try (FileOutputStream out = new FileOutputStream (servicesJar );
98
105
JarOutputStream jar = new JarOutputStream (out )) {
99
- jar .putNextEntry (new JarEntry ("META-INF/services/" + pluginClassName ));
106
+
107
+ JarEntry jarEntry = new JarEntry ("META-INF/services/" + pluginClassName );
108
+ if (outputTimestamp != null && !outputTimestamp .isBlank ()) {
109
+ try {
110
+ jarEntry .setTime (OUTPUT_DATE_FORMAT .parse (outputTimestamp ).getTime ());
111
+ }
112
+ catch (ParseException e ) {
113
+ throw new RuntimeException ("Could not parse outputTimestamp: " + outputTimestamp , e );
114
+ }
115
+ }
116
+
117
+ jar .putNextEntry (jarEntry );
100
118
jar .write (servicesFileData );
101
119
jar .closeEntry ();
102
120
}
0 commit comments