|
| 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.io.*; |
| 21 | +import java.lang.module.*; |
| 22 | +import java.nio.file.attribute.FileTime; |
| 23 | +import java.time.Instant; |
| 24 | +import java.util.*; |
| 25 | +import java.util.jar.*; |
| 26 | + |
| 27 | +File target = new File( basedir, "target" ) |
| 28 | + |
| 29 | +assert target.exists() |
| 30 | +assert target.isDirectory() |
| 31 | + |
| 32 | +File artifact = new File( target, "mjar-275-reproducible-multi-release-modular-jar-1.0-SNAPSHOT.jar" ); |
| 33 | + |
| 34 | +assert artifact.exists() |
| 35 | +assert artifact.isFile() |
| 36 | + |
| 37 | +JarFile jar = new JarFile( artifact ); |
| 38 | + |
| 39 | +Attributes manifest = jar.getManifest().getMainAttributes(); |
| 40 | + |
| 41 | +assert "myproject.HelloWorld".equals( manifest.get( Attributes.Name.MAIN_CLASS ) ) |
| 42 | + |
| 43 | +InputStream moduleDescriptorInputStream = jar.getInputStream( jar.getEntry( "META-INF/versions/9/module-info.class" ) ); |
| 44 | +ModuleDescriptor moduleDescriptor = ModuleDescriptor.read( moduleDescriptorInputStream ); |
| 45 | + |
| 46 | +assert "myproject.HelloWorld".equals( moduleDescriptor.mainClass().orElse( null ) ) |
| 47 | + |
| 48 | +// Normalize to UTC |
| 49 | +long normalizeUTC( String timestamp ) |
| 50 | +{ |
| 51 | + long millis = Instant.parse( timestamp ).toEpochMilli(); |
| 52 | + Calendar cal = Calendar.getInstance(); |
| 53 | + cal.setTimeInMillis( millis ); |
| 54 | + return millis - ( cal.get( Calendar.ZONE_OFFSET ) + cal.get( Calendar.DST_OFFSET ) ); |
| 55 | +} |
| 56 | + |
| 57 | +// All entries should have the same timestamp |
| 58 | +FileTime expectedTimestamp = FileTime.fromMillis( normalizeUTC( "2022-06-26T13:25:58Z" ) ); |
| 59 | +Enumeration<JarEntry> entries = jar.entries(); |
| 60 | +while ( entries.hasMoreElements() ) |
| 61 | +{ |
| 62 | + assert expectedTimestamp.equals( entries.nextElement().getLastModifiedTime() ) |
| 63 | +} |
| 64 | + |
| 65 | +jar.close(); |
0 commit comments