Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 35 additions & 43 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,34 @@
</properties>

<dependencies>
<!-- Maven -->
<!-- Needed dependencies -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>${asmVersion}</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>${asmVersion}</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>2.0.6.1</version>
</dependency>
<dependency>
<groupId>org.vafer</groupId>
<artifactId>jdependency</artifactId>
<version>2.15</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.6.0</version>
</dependency>

<!-- Maven (provided) -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand Down Expand Up @@ -119,58 +146,17 @@
<version>3.15.2</version>
<scope>provided</scope>
</dependency>

<!-- Plexus -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.6.0</version>
</dependency>

<!-- DI -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>

<!-- Others -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>${asmVersion}</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>${asmVersion}</version>
</dependency>

<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>2.0.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.28.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.21.0</version>
</dependency>
<dependency>
<groupId>org.vafer</groupId>
<artifactId>jdependency</artifactId>
<version>2.15</version>
<scope>provided</scope>
</dependency>

<!-- Test -->
Expand Down Expand Up @@ -228,6 +214,12 @@
<version>3.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.21.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
51 changes: 34 additions & 17 deletions src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.io.OutputStreamWriter;
import java.io.PushbackInputStream;
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
Expand All @@ -56,9 +58,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;

import org.apache.commons.compress.archivers.zip.ExtraFieldUtils;
import org.apache.commons.compress.archivers.zip.X5455_ExtendedTimestamp;
import org.apache.commons.compress.archivers.zip.ZipExtraField;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.shade.filter.Filter;
import org.apache.maven.plugins.shade.relocation.Relocator;
Expand Down Expand Up @@ -95,23 +94,41 @@ public DefaultShader(final Logger logger) {

// workaround for MSHADE-420
private long getTime(ZipEntry entry) {
if (entry.getExtra() != null) {
try {
ZipExtraField[] fields =
ExtraFieldUtils.parse(entry.getExtra(), true, ExtraFieldUtils.UnparseableExtraField.SKIP);
for (ZipExtraField field : fields) {
if (X5455_ExtendedTimestamp.HEADER_ID.equals(field.getHeaderId())) {
// extended timestamp extra field: need to translate UTC to local time for Reproducible Builds
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(entry.getTime());
return entry.getTime() - (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET));
}
if (entry.getLastModifiedTime() == null) {
return -1;
}
long mtime = entry.getLastModifiedTime().toMillis();
if (hasX5455ExtendedTimestamp(entry)) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(mtime);
mtime = mtime - (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET));
}
return mtime;
}

/**
* Returns {@code true} if passed in {@link ZipEntry} has extra data that contains the extended timestamp (0x5455).
*
* @see <a href="https://commons.apache.org/proper/commons-compress/apidocs/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.html">X5455_ExtendedTimestamp</a>
*/
private static boolean hasX5455ExtendedTimestamp(ZipEntry zipEntry) {
if (zipEntry.getExtra() != null) {
ByteBuffer extraData = ByteBuffer.wrap(zipEntry.getExtra());
extraData.order(ByteOrder.LITTLE_ENDIAN);
while (extraData.hasRemaining()) {
int id = extraData.getShort() & 0xffff;
int length = extraData.getShort() & 0xffff;

if (id == 0x5455) {
// Extended TS is present
return true;
} else {
// skip to next
extraData.position(extraData.position() + length);
}
} catch (ZipException ze) {
// ignore
}
}
return entry.getTime();
return false;
}

public void shade(ShadeRequest shadeRequest) throws IOException, MojoExecutionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;

import org.apache.commons.io.IOUtils;
import org.apache.maven.plugins.shade.relocation.Relocator;
import org.codehaus.plexus.util.IOUtil;

/**
* Resources transformer that relocates classes in META-INF/services and appends entries in META-INF/services resources
Expand Down Expand Up @@ -97,7 +97,7 @@ public void modifyOutputStream(JarOutputStream jos) throws IOException {
jarEntry.setTime(time);
jos.putNextEntry(jarEntry);

IOUtils.writeLines(data, "\n", jos, StandardCharsets.UTF_8);
IOUtil.copy((String.join("\n", data) + "\n").getBytes(StandardCharsets.UTF_8), jos);
jos.flush();
data.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;

import org.apache.commons.io.IOUtils;
import org.apache.maven.plugins.shade.relocation.Relocator;
import org.codehaus.plexus.util.IOUtil;

/**
* Resource transformer that relocates classes in {@code META-INF/sisu/javax.inject.Named} and appends resources
Expand Down Expand Up @@ -78,7 +78,7 @@ public void modifyOutputStream(final JarOutputStream jos) throws IOException {
JarEntry jarEntry = new JarEntry(SISU_INDEX_PATH);
jarEntry.setTime(time);
jos.putNextEntry(jarEntry);
IOUtils.writeLines(indexEntries, "\n", jos, StandardCharsets.UTF_8);
IOUtil.copy((String.join("\n", indexEntries) + "\n").getBytes(StandardCharsets.UTF_8), jos);
jos.flush();
indexEntries.clear();
}
Expand Down