|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import java.nio.file.attribute.FileTime; |
| 21 | +import java.time.Instant; |
| 22 | +import java.util.jar.*; |
| 23 | + |
| 24 | +def target = new File( basedir, 'target' ) |
| 25 | +assert target.isDirectory() |
| 26 | + |
| 27 | +def apidocs = new File( target, 'apidocs' ) |
| 28 | +assert apidocs.isDirectory() |
| 29 | + |
| 30 | +def options = new File( apidocs, 'options' ) |
| 31 | +assert options.isFile() |
| 32 | +assert options.text.contains( "'Copyright © 2020. All rights reserved.'" ) |
| 33 | + |
| 34 | +def artifact = new File( target, 'bar-0.1.0-SNAPSHOT-javadoc.jar' ) |
| 35 | +assert artifact.isFile() |
| 36 | + |
| 37 | +// notimestamp in html files |
| 38 | +apidocs.eachFileRecurse |
| 39 | +{ |
| 40 | + if ( it.name.endsWith( '.html' ) ) |
| 41 | + { |
| 42 | + assert it.text =~ /<!-- Generated by javadoc (\(\d+\) )?-->/ |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +// Normalize to UTC |
| 47 | +long normalizeUTC( String timestamp ) |
| 48 | +{ |
| 49 | + long millis = Instant.parse( timestamp ).toEpochMilli() |
| 50 | + Calendar cal = Calendar.getInstance() |
| 51 | + cal.setTimeInMillis( millis ) |
| 52 | + return millis - ( cal.get( Calendar.ZONE_OFFSET ) + cal.get( Calendar.DST_OFFSET ) ) |
| 53 | +} |
| 54 | + |
| 55 | +JarFile jar = new JarFile( artifact ) |
| 56 | + |
| 57 | +// All entries should have the same timestamp |
| 58 | +FileTime expectedTimestamp = FileTime.fromMillis( normalizeUTC( "2020-02-29T23:59:58Z" ) ) |
| 59 | +def testTimestamp = |
| 60 | +{ |
| 61 | + JarEntry entry -> assert expectedTimestamp.equals( entry.getLastModifiedTime() ) |
| 62 | +} |
| 63 | + |
| 64 | +jar.stream().forEach( testTimestamp ) |
| 65 | +jar.close() |
0 commit comments