Skip to content

Commit

Permalink
[MJAR-275] - Update maven-archiver to 3.6.0
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Solórzano <jorsol@gmail.com>
  • Loading branch information
jorsol committed Jun 27, 2022
1 parent b6fe3eb commit e8c7c8c
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 5 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Expand Up @@ -76,7 +76,7 @@

<properties>
<mavenFileManagementVersion>3.0.0</mavenFileManagementVersion>
<mavenArchiverVersion>3.5.2</mavenArchiverVersion>
<mavenArchiverVersion>3.6.0</mavenArchiverVersion>
<mavenVersion>3.1.0</mavenVersion>
<!-- TODO remove with Maven APi upgrade -->
<!-- the same version as in Maven 3.1.0 -->
Expand Down Expand Up @@ -150,6 +150,11 @@
<version>3.4.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
21 changes: 21 additions & 0 deletions src/it/MJAR-275-reproducible-module-info/invoker.properties
@@ -0,0 +1,21 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# NOTE: Requires Java 10+ to compile the module declaration for Java 9+,
# this is due that compiling the module declaration generates a
# module descriptor with the JDK version on it, making it unreproducible.
invoker.java.version = 10+
77 changes: 77 additions & 0 deletions src/it/MJAR-275-reproducible-module-info/pom.xml
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>mjar-275-reproducible-multi-release-modular-jar</artifactId>
<name>mjar-275-reproducible-multi-release-modular-jar</name>
<description>Verifies that the modular descriptor is reproducible (timestamp is set)</description>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.outputTimestamp>2022-06-26T13:25:58Z</project.build.outputTimestamp>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<archive>
<manifest>
<mainClass>myproject.HelloWorld</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>8</release>
</configuration>
<executions>
<execution>
<id>java9</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>9</release>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
</compileSourceRoots>
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@@ -0,0 +1,37 @@
package myproject;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/**
* The classic Hello World App.
*/
public class HelloWorld
{

/**
* Main method.
*
* @param args Not used
*/
public static void main( String[] args )
{
System.out.println( "Hi!" );
}
}
@@ -0,0 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

module myproject {
exports myproject;
}
97 changes: 97 additions & 0 deletions src/it/MJAR-275-reproducible-module-info/verify.groovy
@@ -0,0 +1,97 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import java.io.*;
import java.lang.module.*;
import java.nio.file.attribute.FileTime;
import java.time.Instant;
import java.util.*;
import java.util.jar.*;

boolean result = true;
JarFile jar;

try
{
File target = new File( basedir, "target" );
if ( !target.exists() || !target.isDirectory() )
{
System.err.println( "target file is missing or not a directory." );
return false;
}

File artifact = new File( target, "mjar-275-reproducible-multi-release-modular-jar-1.0-SNAPSHOT.jar" );
if ( !artifact.exists() || !artifact.isFile() )
{
System.err.println( "Could not find generated JAR: " + artifact );
return false;
}

jar = new JarFile( artifact );

Attributes manifest = jar.getManifest().getMainAttributes();

if ( !"myproject.HelloWorld".equals( manifest.get( Attributes.Name.MAIN_CLASS ) ) )
{
System.err.println( "Manifest main class attribute not equals myproject.HelloWorld" );
return false;
}

InputStream moduleDescriptorInputStream = jar.getInputStream( jar.getEntry( "META-INF/versions/9/module-info.class" ) );
ModuleDescriptor moduleDescriptor = ModuleDescriptor.read( moduleDescriptorInputStream );

if ( !"myproject.HelloWorld".equals( moduleDescriptor.mainClass().orElse( null ) ) )
{
System.err.println( "Module descriptor main class not equals myproject.HelloWorld" );
return false;
}

// Normalize to UTC
long millis = Instant.parse( "2022-06-26T13:25:58Z" ).toEpochMilli();
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis( millis );
millis = millis - ( cal.get( Calendar.ZONE_OFFSET ) + cal.get( Calendar.DST_OFFSET ) );

FileTime timestamp = FileTime.fromMillis( millis );
Enumeration<JarEntry> entries = jar.entries();
while ( entries.hasMoreElements() )
{
JarEntry entry = entries.nextElement();
FileTime lastModifiedTime = entry.getLastModifiedTime();
if ( !timestamp.equals( lastModifiedTime ) )
{
System.err.println( "The last modified time is not expected for the entry: " + entry );
result = false;
}
}
}
catch( Throwable e )
{
e.printStackTrace();
result = false;
}
finally
{
if ( jar != null )
{
jar.close();
}
}

return result;
Expand Up @@ -141,9 +141,10 @@ public abstract class AbstractJarMojo
private boolean skipIfEmpty;

/**
* Timestamp for reproducible output archive entries, either formatted as ISO 8601
* <code>yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like
* <a href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>).
* Timestamp for reproducible output archive entries, either formatted as ISO 8601 extended offset date-time
* (e.g. in UTC such as '2011-12-03T10:15:30Z' or with an offset '2019-10-05T20:37:42+06:00'),
* or as an int representing seconds since the epoch
* (like <a href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>).
*
* @since 3.2.0
*/
Expand Down Expand Up @@ -257,7 +258,7 @@ public File createArchive()
archiver.setOutputFile( jarFile );

// configure for Reproducible Builds based on outputTimestamp value
archiver.configureReproducible( outputTimestamp );
archiver.configureReproducibleBuild( outputTimestamp );

archive.setForced( forceCreation );

Expand Down

0 comments on commit e8c7c8c

Please sign in to comment.