Skip to content

Commit

Permalink
Merge pull request #545 from basil/commons-comprses
Browse files Browse the repository at this point in the history
Remove usages of Commons Compress
  • Loading branch information
Dohbedoh authored May 27, 2024
2 parents 5fc6afc + b283ae3 commit 261d6f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
17 changes: 8 additions & 9 deletions src/main/java/com/cloudbees/jenkins/support/SupportPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import jenkins.metrics.impl.JenkinsMetricProviderImpl;
import jenkins.model.GlobalConfiguration;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.io.output.CountingOutputStream;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
Expand Down Expand Up @@ -378,8 +378,7 @@ public static void writeBundle(
try {
try (BulkChange change = new BulkChange(ContentFilter.bulkChangeTarget());
CountingOutputStream countingOs = new CountingOutputStream(outputStream);
ZipArchiveOutputStream binaryOut =
new ZipArchiveOutputStream(new BufferedOutputStream(countingOs, 16384))) {
ZipOutputStream binaryOut = new ZipOutputStream(new BufferedOutputStream(countingOs, 16384))) {
ContentFilter filter = getDefaultContentFilter(true);

// Generate the content of the manifest.md going through all the components which will be included. It
Expand Down Expand Up @@ -410,9 +409,9 @@ public static void writeBundle(
final String name = getNameFiltered(filter, content.getName(), content.getFilterableParameters());

try {
final ZipArchiveEntry entry = new ZipArchiveEntry(name);
final ZipEntry entry = new ZipEntry(name);
entry.setTime(content.getTime());
binaryOut.putArchiveEntry(entry);
binaryOut.putNextEntry(entry);
entryCreated = true;
binaryOut.flush();
OutputStream out = content.shouldBeFiltered() ? filteredOut : unfilteredOut;
Expand All @@ -434,7 +433,7 @@ public static void writeBundle(
textOut.reset();
selector.reset();
if (entryCreated) {
binaryOut.closeArchiveEntry();
binaryOut.closeEntry();
entryCreated = false;
}
LOGGER.log(
Expand All @@ -453,15 +452,15 @@ public static void writeBundle(
String errorContent = errors.toString();
if (StringUtils.isNotBlank(errorContent)) {
try {
binaryOut.putArchiveEntry(new ZipArchiveEntry("manifest/errors.txt"));
binaryOut.putNextEntry(new ZipEntry("manifest/errors.txt"));
entryCreated = true;
textOut.write(errorContent.getBytes(StandardCharsets.UTF_8));
textOut.flush();
} catch (IOException e) {
logger.log(Level.WARNING, "Could not write manifest/errors.txt to zip archive", e);
} finally {
if (entryCreated) {
binaryOut.closeArchiveEntry();
binaryOut.closeEntry();
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/com/cloudbees/jenkins/support/CheckFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import jenkins.model.Jenkins;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -157,12 +157,12 @@ private void assertComponent(List<Class<? extends Component>> componentClasses,
.collect(Collectors.toList());
SupportPlugin.writeBundle(zipOutputStream, componentsRequested);

// ZipArchiveInputStream zip = new ZipArchiveInputStream(new FileInputStream(fileZip));
// ZipInputStream zip = new ZipInputStream(new FileInputStream(fileZip));
try (ZipFile zip = new ZipFile(fileZip)) {
Enumeration<ZipArchiveEntry> zipFileEntries = zip.getEntries();
Enumeration<? extends ZipEntry> zipFileEntries = zip.entries();

while (zipFileEntries.hasMoreElements()) {
ZipArchiveEntry entry = zipFileEntries.nextElement();
ZipEntry entry = zipFileEntries.nextElement();
if (entry.isDirectory()) {
break;
}
Expand All @@ -181,7 +181,7 @@ private void assertComponent(List<Class<? extends Component>> componentClasses,
}
}

private String getContentFromEntry(ZipFile zip, ZipArchiveEntry entry) throws IOException {
private String getContentFromEntry(ZipFile zip, ZipEntry entry) throws IOException {
if (entry.getSize() == 0) {
return "";
}
Expand Down

0 comments on commit 261d6f7

Please sign in to comment.