Skip to content

Commit

Permalink
[MASSEMBLY-986] Minimal default Manifest should be used by jar archiver
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Apr 23, 2023
1 parent 434f110 commit 485bd94
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 24 deletions.
9 changes: 8 additions & 1 deletion src/it/projects/reproducible/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
* under the License.
*/

//import java.util.zip.*
import java.util.jar.*;
import org.apache.commons.compress.archivers.zip.*

File deployDir = new File( basedir, 'target/repo/org/apache/maven/its/reproducible/1.0' )

assert deployDir.exists()

// Minimal Manifest was created
JarFile jarFile = new JarFile( new File( deployDir, "reproducible-1.0-src.jar" ) )
Manifest mf = jarFile.getManifest()
Attributes attrs = mf.getMainAttributes()
assert attrs.size() == 1
assert attrs.containsKey(Attributes.Name.MANIFEST_VERSION)

ZipFile zip = new ZipFile( new File( deployDir, "reproducible-1.0-src.zip" ) )
StringBuilder sb = new StringBuilder()
StringBuilder sb2 = new StringBuilder()
Expand Down
2 changes: 1 addition & 1 deletion src/it/projects/reproducible/zip-content-755.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ executable: 100755

resulting sha1:
97d0ea3b4a87cd3ea78edd1c3c25914d69ea97f3 reproducible-1.0-src.zip.sha1
a0c4cf1ed244e60221e12367f50ff676066b8e65 reproducible-1.0-src.jar.sha1
d3aec46dedbfc5dcb31f7055f130860aeb8fcf66 reproducible-1.0-src.jar.sha1
bf93dd529253157352b87097d9d23eba8c9ca61a reproducible-1.0-src.tar.sha1
2 changes: 1 addition & 1 deletion src/it/projects/reproducible/zip-content-775.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ executable: 100775

resulting sha1:
50116502c6107740c2a35ef296b5abda08c5dec7 reproducible-1.0-src.zip.sha1
cc7e3a984179f63d6b37bc86c61e9cc461c62288 reproducible-1.0-src.jar.sha1
3bb81a423ca18a01dd76e0f872c66a1a7528f064 reproducible-1.0-src.jar.sha1
3efc10ec9c3099ba061e58d5b2a935ba643da237 reproducible-1.0-src.tar.sha1
2 changes: 1 addition & 1 deletion src/it/projects/reproducible/zip-content-win.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ executable: 100644

resulting sha1:
cb1dc226d702733bfa405b7090b74ab7e77bf39e reproducible-1.0-src.zip.sha1
3b31d88a36985f526fb3fe6ba5987387e4887f23 reproducible-1.0-src.jar.sha1
a916d0299f54a790ede766709ce54daebef5e818 reproducible-1.0-src.jar.sha1
b85f960069d6a444f928a87761b63fde60ea687d reproducible-1.0-src.tar.sha1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.List;
import java.util.Map;

import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException;
import org.apache.maven.plugins.assembly.archive.archiver.AssemblyProxyArchiver;
Expand Down Expand Up @@ -293,10 +294,7 @@ protected Archiver createArchiver(
final List<FileSelector> extraSelectors = new ArrayList<>();
final List<ArchiveFinalizer> extraFinalizers = new ArrayList<>();
if (archiver instanceof JarArchiver) {
if (mergeManifestMode != null) {
((JarArchiver) archiver)
.setFilesetmanifest(JarArchiver.FilesetManifestConfig.valueOf(mergeManifestMode));
}
configureJarArchiver((JarArchiver) archiver, mergeManifestMode, configSource.getJarArchiveConfiguration());

extraSelectors.add(new JarSecurityFileSelector());

Expand Down Expand Up @@ -351,6 +349,23 @@ protected Archiver createArchiver(
return archiver;
}

private void configureJarArchiver(
JarArchiver archiver, String mergeManifestMode, MavenArchiveConfiguration configuration) {

if (mergeManifestMode != null) {
archiver.setFilesetmanifest(JarArchiver.FilesetManifestConfig.valueOf(mergeManifestMode));
}

archiver.setMinimalDefaultManifest(true);

if (configuration != null) {
archiver.setCompress(configuration.isCompress());
archiver.setForced(configuration.isForced());
archiver.setIndex(configuration.isIndex());
archiver.setRecompressAddedZips(configuration.isRecompressAddedZips());
}
}

private void configureContainerDescriptorHandler(
final ContainerDescriptorHandler handler,
final Xpp3Dom config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Collections;
import java.util.List;

import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.model.Model;
import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException;
Expand Down Expand Up @@ -179,7 +180,7 @@ public void testCreateArchiver_ShouldConfigureArchiver() throws Exception {
when(configSource.getOverrideGid()).thenReturn(0);
when(configSource.getOverrideGroupName()).thenReturn("root");

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createArchiver("dummy", false, "finalName", configSource, null, false, null, null);

Expand All @@ -204,7 +205,7 @@ public void testCreateArchiver_ShouldCreateTarArchiverWithNoCompression() throws
when(configSource.getOverrideGid()).thenReturn(0);
when(configSource.getOverrideGroupName()).thenReturn("root");

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createArchiver("tar", false, "finalName", configSource, null, false, null, null);

Expand Down Expand Up @@ -240,16 +241,17 @@ public void testCreateArchiver_ShouldCreateWarArchiverWithIgnoreWebxmlSetToFalse
when(configSource.getProject()).thenReturn(new MavenProject(new Model()));
when(configSource.getWorkingDirectory()).thenReturn(new File("."));
when(configSource.isIgnorePermissions()).thenReturn(true);
when(configSource.getJarArchiveConfiguration()).thenReturn(new MavenArchiveConfiguration());

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createArchiver("war", false, null, configSource, null, false, null, null);

assertFalse(twArchiver.ignoreWebxml);

// result of easymock migration, should be assert of expected result instead of verifying methodcalls
verify(configSource).getArchiverConfig();
verify(configSource).getJarArchiveConfiguration();
verify(configSource, times(2)).getJarArchiveConfiguration();
verify(configSource).getMavenSession();
verify(configSource, times(2)).getOverrideGid();
verify(configSource, times(2)).getOverrideGroupName();
Expand Down Expand Up @@ -278,7 +280,7 @@ public void testCreateArchiver_ShouldCreateZipArchiver() throws Exception {
when(configSource.getWorkingDirectory()).thenReturn(new File("."));
when(configSource.isIgnorePermissions()).thenReturn(true);

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createArchiver("zip", false, null, configSource, null, false, null, null);

Expand All @@ -302,7 +304,7 @@ public void testCreateWarArchiver_ShouldDisableIgnoreWebxmlOption() throws Excep

when(archiverManager.getArchiver("war")).thenReturn(twArchiver);

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createWarArchiver();

Expand All @@ -318,7 +320,7 @@ public void testCreateTarArchiver_ShouldNotInitializeCompression() throws Except

when(archiverManager.getArchiver("tar")).thenReturn(archiver);

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createTarArchiver("tar", TarLongFileMode.fail);

Expand All @@ -335,7 +337,7 @@ public void testCreateTarArchiver_TarGzFormat_ShouldInitializeGZipCompression()

when(archiverManager.getArchiver("tar")).thenReturn(archiver);

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createTarArchiver("tar.gz", TarLongFileMode.fail);

Expand All @@ -352,7 +354,7 @@ public void testCreateTarArchiver_TgzFormat_ShouldInitializeGZipCompression() th

when(archiverManager.getArchiver("tar")).thenReturn(archiver);

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createTarArchiver("tgz", TarLongFileMode.fail);

Expand All @@ -369,7 +371,7 @@ public void testCreateTarArchiver_TarBz2Format_ShouldInitializeBZipCompression()

when(archiverManager.getArchiver("tar")).thenReturn(archiver);

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createTarArchiver("tar.bz2", TarLongFileMode.fail);

Expand All @@ -386,7 +388,7 @@ public void testCreateTarArchiver_Tbz2Format_ShouldInitializeBZipCompression() t

when(archiverManager.getArchiver("tar")).thenReturn(archiver);

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createTarArchiver("tbz2", TarLongFileMode.fail);

Expand All @@ -403,7 +405,7 @@ public void testCreateTarArchiver_TarXzFormat_ShouldInitializeXzCompression() th

when(archiverManager.getArchiver("tar")).thenReturn(archiver);

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createTarArchiver("tar.xz", TarLongFileMode.fail);

Expand All @@ -420,7 +422,7 @@ public void testCreateTarArchiver_TXzFormat_ShouldInitializeXzCompression() thro

when(archiverManager.getArchiver("tar")).thenReturn(archiver);

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createTarArchiver("txz", TarLongFileMode.fail);

Expand All @@ -437,7 +439,7 @@ public void testCreateTarArchiver_TarZstFormat_ShouldInitializeZstCompression()

when(archiverManager.getArchiver("tar")).thenReturn(archiver);

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createTarArchiver("tar.zst", TarLongFileMode.fail);

Expand All @@ -454,7 +456,7 @@ public void testCreateTarArchiver_TZstFormat_ShouldInitializeZstCompression() th

when(archiverManager.getArchiver("tar")).thenReturn(archiver);

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

subject.createTarArchiver("tzst", TarLongFileMode.fail);

Expand All @@ -471,7 +473,7 @@ public void testCreateTarArchiver_InvalidFormat_ShouldFailWithInvalidCompression

when(archiverManager.getArchiver("tar")).thenReturn(ttArchiver);

final DefaultAssemblyArchiver subject = createSubject(new ArrayList<AssemblyArchiverPhase>());
final DefaultAssemblyArchiver subject = createSubject(new ArrayList<>());

try {
subject.createTarArchiver("tar.Z", null);
Expand Down

0 comments on commit 485bd94

Please sign in to comment.