1616import java .util .Map .Entry ;
1717
1818import utilities .JSON ;
19+ import utilities .JSON .Object ;
1920import utilities .OS ;
21+ import utilities .OS .FileInfo ;
2022
2123Path DIRECTORY ;
22- Optional <Path > FILES_LIST_FILE ;
2324
2425/**
2526 * Considered JVM properties are:
3031 * <li>{@code gitReposChanged} (required for {@code mainEclipse}) -- The comma
3132 * separated list of URLs of Git repositories that changed since the
3233 * baseline.</li>
33- * <li>{@code filesList} (optional) -- path to a file listing all files and
34- * their size in the directory.<br>
35- * Can be generated using the UNIX command
36- * {@code find . -exec stat --format "%n %s" {} \; }</li>
3734 * </ul>
3835 * The generated data files (mainly JSON) are written at locations within the
3936 * specified directory where the website pages expect them.
4037 */
4138void main (String [] args ) throws IOException {
4239 DIRECTORY = Path .of (OS .readProperty ("dropDirectory" )).toRealPath ();
43- FILES_LIST_FILE = Optional .ofNullable (System .getProperty ("filesList" )).map (Path ::of );
4440 IO .println ("INFO: Generating drop data file for" );
4541 IO .println ("\t " + DIRECTORY );
46- FILES_LIST_FILE .ifPresent (list -> {
47- IO .println ("INFO: Reading files from:" );
48- IO .println ("\t " + list );
49- });
5042
5143 switch (args [0 ]) {
5244 case "mainEclipse" -> mainEclipsePageData ();
@@ -57,12 +49,15 @@ void main(String[] args) throws IOException {
5749}
5850
5951final Pattern COMMA = Pattern .compile ("," );
52+ final String FILENAME = "name" ;
53+ final String FILE_SIZE = "size" ;
54+ final String FILE_HASH_TYPE = "sha512" ;
6055
6156void mainEclipsePageData () throws IOException {
6257 String gitBaselineTag = OS .readProperty ("gitBaselineTag" ).trim ();
6358 List <String > gitReposChanged = List .of (OS .readProperty ("gitReposChanged" ).trim ().split ("," ));
6459
65- Map <Path , Long > files = OS .listFileTree (DIRECTORY , FILES_LIST_FILE , null , 1 );
60+ Map <Path , FileInfo > files = OS .listFileTree (DIRECTORY , 1 );
6661 Map <String , String > properties = OS .loadProperties (DIRECTORY .resolve ("buildproperties.properties" ));
6762 String buildId = properties .get ("BUILD_ID" );
6863 ZonedDateTime buildDate = buildTimestamp (buildId );
@@ -116,13 +111,15 @@ void mainEclipsePageData() throws IOException {
116111
117112 buildProperties .add ("swtBinaries" , collectFileEntries (files , filename -> filename .startsWith ("swt-" )));
118113
114+ writeChecksumsSummaryFile (buildProperties , buildId , "eclipse" );
115+
119116 Path file = DIRECTORY .resolve ("buildproperties.json" );
120117 IO .println ("Write Eclipse drop main data to: " + file );
121118 JSON .write (buildProperties , file );
122119}
123120
124121void mainEquinoxPageData () throws IOException {
125- Map <Path , Long > files = OS .listFileTree (DIRECTORY , FILES_LIST_FILE , null , 1 );
122+ Map <Path , FileInfo > files = OS .listFileTree (DIRECTORY , 1 );
126123 Map <String , String > properties = OS .loadProperties (DIRECTORY .resolve ("buildproperties.properties" ));
127124 String buildId = properties .get ("BUILD_ID" );
128125 ZonedDateTime buildDate = buildTimestamp (buildId );
@@ -153,20 +150,21 @@ void mainEquinoxPageData() throws IOException {
153150 buildProperties .add ("starterKits" , collectFileEntries (files ,
154151 filename -> filename .startsWith ("EclipseRT-OSGi-StarterKit-" ) && !OS .isMacTarGZ (filename )));
155152
153+ writeChecksumsSummaryFile (buildProperties , buildId , "equinox" );
154+
156155 Path file = DIRECTORY .resolve ("buildproperties.json" );
157156 IO .println ("Write Equinox drop main data to: " + file );
158157 JSON .write (buildProperties , file );
159158}
160159
161160void buildLogsPageData () throws IOException {
162- Path buildLogsDirectory = Path .of ("buildlogs" );
163- Path comparatorLogsDirectory = Path .of ("buildlogs/comparatorlogs" );
164- Map <Path , Long > files = OS .listFileTree (DIRECTORY , FILES_LIST_FILE , buildLogsDirectory , 3 );
161+ Path comparatorLogsDirectory = Path .of ("comparatorlogs" );
162+ Map <Path , FileInfo > files = OS .listFileTree (DIRECTORY .resolve ("buildlogs" ), 2 );
165163
166164 JSON .Object logFiles = JSON .Object .create ();
167- JSON .Array buildLogs = colleFilesInDirectory ( buildLogsDirectory , filename -> filename .startsWith ("s" ), files );
165+ JSON .Array buildLogs = collectFileEntries ( files , filename -> filename .startsWith ("s" ));
168166 logFiles .add ("build" , buildLogs );
169- JSON .Array comparatorLogs = colleFilesInDirectory ( comparatorLogsDirectory , _ -> true , files );
167+ JSON .Array comparatorLogs = collectFilesInDirectory ( files , comparatorLogsDirectory , _ -> true );
170168 logFiles .add ("comparator" , comparatorLogs );
171169
172170 Path file = DIRECTORY .resolve ("buildlogs/logs.json" );
@@ -185,12 +183,12 @@ String previousReleaseAPILabel(Map<String, String> buildProps) {
185183 return major + "." + (minor - 1 );
186184}
187185
188- JSON .Array collectFileEntries (Map <Path , Long > buildFiles , Predicate <String > filenameFilter ) {
189- return colleFilesInDirectory ( null , filenameFilter , buildFiles );
186+ JSON .Array collectFileEntries (Map <Path , FileInfo > buildFiles , Predicate <String > filenameFilter ) {
187+ return collectFilesInDirectory ( buildFiles , null , filenameFilter );
190188}
191189
192- JSON .Array colleFilesInDirectory ( Path inDirectory , Predicate < String > filenameFilter , Map < Path , Long > buildFiles ) {
193- Function <Entry <Path , Long >, String > getFilename = f -> f .getKey ().getFileName ().toString ();
190+ JSON .Array collectFilesInDirectory ( Map < Path , FileInfo > buildFiles , Path inDirectory , Predicate < String > filenameFilter ) {
191+ Function <Entry <Path , FileInfo >, String > getFilename = f -> f .getKey ().getFileName ().toString ();
194192 int expectedNameCount = inDirectory != null ? inDirectory .getNameCount () + 1 : 1 ;
195193 return buildFiles .entrySet ().stream ().filter (f -> {
196194 Path file = f .getKey ();
@@ -218,7 +216,7 @@ JSON.Array colleFilesInDirectory(Path inDirectory, Predicate<String> filenameFil
218216 return 100 ;
219217})).thenComparing (Comparator .naturalOrder ());
220218
221- JSON .Object createFileEntry (String filename , Map <Path , Long > buildFiles , String platform ) {
219+ JSON .Object createFileEntry (String filename , Map <Path , FileInfo > buildFiles , String platform ) {
222220 Path filePath = Path .of (filename );
223221 JSON .Object file = createFileDescription (filePath , buildFiles .get (filePath ));
224222 if (platform != null ) {
@@ -227,10 +225,28 @@ JSON.Object createFileEntry(String filename, Map<Path, Long> buildFiles, String
227225 return file ;
228226}
229227
230- JSON .Object createFileDescription (Path file , Long fileSize ) {
228+ void writeChecksumsSummaryFile (JSON .Object buildProperties , String buildId , String client ) throws IOException {
229+ Path checksumSummary = DIRECTORY .resolve (client + "-" + buildId + "-checksums" );
230+ List <String > lines = buildProperties .members ().values ().stream () //
231+ .filter (JSON .Array .class ::isInstance ).map (JSON .Array .class ::cast ) //
232+ .map (JSON .Array ::elements ).flatMap (List ::stream ) //
233+ .filter (JSON .Object .class ::isInstance ).map (JSON .Object .class ::cast ) //
234+ .map (Object ::members ).filter (o -> o .containsKey (FILENAME ) && o .containsKey (FILE_HASH_TYPE ))
235+ .sorted (Comparator .comparing ((Map <String , JSON .Value > o ) -> getStringValue (o , FILENAME )))
236+ .map (o -> getStringValue (o , FILE_HASH_TYPE ) + " *" + getStringValue (o , FILENAME )).toList ();
237+ IO .println ("Write checksum summary file to: " + checksumSummary );
238+ Files .write (checksumSummary , lines );
239+ }
240+
241+ String getStringValue (Map <String , JSON .Value > o , String key ) {
242+ return ((JSON .String ) o .get (key )).characters ();
243+ }
244+
245+ JSON .Object createFileDescription (Path file , FileInfo fileInfo ) {
231246 JSON .Object fileEntry = JSON .Object .create ();
232- fileEntry .add ("name" , JSON .String .create (file .toString ().replace (File .separatorChar , '/' )));
233- fileEntry .add ("size" , JSON .String .create (OS .fileSizeAsString (fileSize )));
247+ fileEntry .add (FILENAME , JSON .String .create (file .toString ().replace (File .separatorChar , '/' )));
248+ fileEntry .add (FILE_SIZE , JSON .String .create (OS .fileSizeAsString (fileInfo .size ())));
249+ fileEntry .add (FILE_HASH_TYPE , JSON .String .create (fileInfo .hashSHA512 ()));
234250 return fileEntry ;
235251}
236252
0 commit comments