Skip to content

Commit 8909d76

Browse files
committed
Remove the zip exploding code from the JRubyJarCopyAction
Making this as a separate commit so it's easier to figure out later. But either way, this ensures that jar files go into the shadowed jrubyjar unmolested. Fixes #307
1 parent f69840d commit 8909d76

File tree

1 file changed

+16
-88
lines changed

1 file changed

+16
-88
lines changed

jar-plugin/src/main/groovy/com/github/jrubygradle/jar/internal/JRubyJarCopyAction.groovy

Lines changed: 16 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import org.gradle.api.internal.file.DefaultFileTreeElement
3232
import org.gradle.api.internal.file.copy.CopyAction
3333
import org.gradle.api.internal.file.copy.CopyActionProcessingStream
3434
import org.gradle.api.internal.file.copy.FileCopyDetailsInternal
35-
import org.gradle.api.specs.Spec
3635
import org.gradle.api.tasks.WorkResult
3736
import org.gradle.api.tasks.bundling.Zip
3837
import org.gradle.api.tasks.util.PatternSet
@@ -238,81 +237,26 @@ class JRubyJarCopyAction implements CopyAction {
238237

239238
@Override
240239
void visitFile(FileCopyDetails fileDetails) {
241-
if (!isArchive(fileDetails)) {
242-
try {
243-
boolean isClass = isClass(fileDetails)
244-
if (!remapper.hasRelocators() || !isClass) {
245-
if (!isTransformable(fileDetails)) {
246-
String mappedPath = remapper.map(fileDetails.relativePath.pathString)
247-
ZipEntry archiveEntry = new ZipEntry(mappedPath)
248-
archiveEntry.setTime(getArchiveTimeFor(fileDetails.lastModified))
249-
archiveEntry.unixMode = (UnixStat.FILE_FLAG | fileDetails.mode)
250-
zipOutStr.putNextEntry(archiveEntry)
251-
fileDetails.copyTo(zipOutStr)
252-
zipOutStr.closeEntry()
253-
} else {
254-
transform(fileDetails)
255-
}
256-
} else if (isClass && !isUnused(fileDetails.path)) {
257-
remapClass(fileDetails)
258-
}
259-
recordVisit(fileDetails.relativePath)
260-
} catch (Exception e) {
261-
throw new GradleException(String.format("Could not add %s to ZIP '%s'.", fileDetails, zipFile), e)
262-
}
263-
} else {
264-
processArchive(fileDetails)
265-
}
266-
}
267-
268-
private void processArchive(FileCopyDetails fileDetails) {
269-
ZipFile archive = new ZipFile(fileDetails.file)
270240
try {
271-
List<ArchiveFileTreeElement> archiveElements = archive.entries.collect {
272-
new ArchiveFileTreeElement(new RelativeArchivePath(it))
273-
}
274-
Spec<FileTreeElement> patternSpec = patternSet.asSpec
275-
List<ArchiveFileTreeElement> filteredArchiveElements = archiveElements.findAll { ArchiveFileTreeElement archiveElement ->
276-
patternSpec.isSatisfiedBy(archiveElement.asFileTreeElement())
277-
}
278-
filteredArchiveElements.each { ArchiveFileTreeElement archiveElement ->
279-
if (archiveElement.relativePath.file) {
280-
visitArchiveFile(archiveElement, archive)
281-
}
282-
}
283-
} finally {
284-
archive.close()
285-
}
286-
}
287-
288-
private void visitArchiveDirectory(RelativeArchivePath archiveDir) {
289-
if (recordVisit(archiveDir)) {
290-
zipOutStr.putNextEntry(archiveDir.entry)
291-
zipOutStr.closeEntry()
292-
}
293-
}
294-
295-
private void visitArchiveFile(ArchiveFileTreeElement archiveFile, ZipFile archive) {
296-
RelativeArchivePath archiveFilePath = archiveFile.relativePath
297-
if (archiveFile.classFile || !isTransformable(archiveFile)) {
298-
if (recordVisit(archiveFilePath) && !isUnused(archiveFilePath.entry.name)) {
299-
if (!remapper.hasRelocators() || !archiveFile.classFile) {
300-
copyArchiveEntry(archiveFilePath, archive)
241+
boolean isClass = isClass(fileDetails)
242+
if (!remapper.hasRelocators() || !isClass) {
243+
if (!isTransformable(fileDetails)) {
244+
String mappedPath = remapper.map(fileDetails.relativePath.pathString)
245+
ZipEntry archiveEntry = new ZipEntry(mappedPath)
246+
archiveEntry.setTime(getArchiveTimeFor(fileDetails.lastModified))
247+
archiveEntry.unixMode = (UnixStat.FILE_FLAG | fileDetails.mode)
248+
zipOutStr.putNextEntry(archiveEntry)
249+
fileDetails.copyTo(zipOutStr)
250+
zipOutStr.closeEntry()
301251
} else {
302-
remapClass(archiveFilePath, archive)
252+
transform(fileDetails)
303253
}
254+
} else if (isClass && !isUnused(fileDetails.path)) {
255+
remapClass(fileDetails)
304256
}
305-
} else {
306-
transform(archiveFile, archive)
307-
}
308-
}
309-
310-
private void addParentDirectories(RelativeArchivePath file) {
311-
if (file) {
312-
addParentDirectories(file.parent)
313-
if (!file.file) {
314-
visitArchiveDirectory(file)
315-
}
257+
recordVisit(fileDetails.relativePath)
258+
} catch (Exception e) {
259+
throw new GradleException(String.format("Could not add %s to ZIP '%s'.", fileDetails, zipFile), e)
316260
}
317261
}
318262

@@ -384,22 +328,6 @@ class JRubyJarCopyAction implements CopyAction {
384328
}
385329
}
386330

387-
private void copyArchiveEntry(RelativeArchivePath archiveFile, ZipFile archive) {
388-
String mappedPath = remapper.map(archiveFile.entry.name)
389-
ZipEntry entry = new ZipEntry(mappedPath)
390-
entry.setTime(getArchiveTimeFor(archiveFile.entry.time))
391-
RelativeArchivePath mappedFile = new RelativeArchivePath(entry)
392-
addParentDirectories(mappedFile)
393-
zipOutStr.putNextEntry(mappedFile.entry)
394-
InputStream is = archive.getInputStream(archiveFile.entry)
395-
try {
396-
IOUtils.copyLarge(is, zipOutStr)
397-
} finally {
398-
is.close()
399-
}
400-
zipOutStr.closeEntry()
401-
}
402-
403331
@Override
404332
protected void visitDir(FileCopyDetails dirDetails) {
405333
try {

0 commit comments

Comments
 (0)