Closed hacki11 closed 5 years ago
Hmm... It's always been a little unclear to me whether model/
belonged in the zip file, or if it would just be implicitly created because it's a prerequisite for model/fileA.xyz
. The ZipMisc
model ignores parent directories entirely - it creates them if needed when extracting, and doesn't worry about them when encoding.
The nice thing about ZipMisc, as it is, is that it tries to modify the zip file as little as possible - it just copies entries over wholesale. To make the "names" work, we'll have to first read the whole file upfront to populate names.
It looks to me like model/
is being implicitly added to the zip file when we add model/fileA.xyz
, which is what causes explicitly adding model/
to fail. Seems that ZipMisc
's previous input has always been either this:
model/fileA.xyz
model/fileB.xyz
or
model/
model/fileA.xyz
model/fileB.xyz
and now, for whatever reason, for the first time it's seeing
model/fileA.xyz
model/fileB.xyz
model/
I could be wrong in my diagnosis, but if I'm correct, it seems to me that the easiest fix might be this:
} else if (!toOmit.test(entry.getName())) {
// if it isn't being modified, just copy the file stream straight-up
try {
ZipEntry newEntry = new ZipEntry(entry);
newEntry.setCompressedSize(-1);
zipOutput.putNextEntry(newEntry);
copy(zipInput, zipOutput);
} catch (java.util.zip.ZipException e) {
if (e.getMessage().startsWith("duplicate entry")) {
// no worries, sometimes input zips have strange orders, see https://github.com/diffplug/goomph/issues/84
} else {
throw e;
}
}
further investigation had shown that the order is not the problem. there are indeed duplicate entries within the zip file (ZipOutputStream provided by gradle does support this).
One can set the behavior at jar { duplicatesStrategy = DuplicatesStrategy.INCLUDE/WARN/EXCLUDE }
.
My duplicates arise due the following setting:
if (project.convention.findPlugin(JavaPluginConvention)) {
// Change the output directory for the main and test source sets back to the old path
sourceSets.main.output.classesDir = new File(buildDir, "classes/main")
sourceSets.main.output.resourcesDir = new File(buildDir, "classes/main")
sourceSets.test.output.classesDir = new File(buildDir, "classes/test")
sourceSets.test.output.resourcesDir = new File(buildDir, "classes/test")
}
I did this because IntelliJ does not support the different folders for languages (java, groovy, etc.) like gradle needs. Because i want to use the platform testrunner instead of gradle i need this setting.
Though not directly an issue with ZipMisc here, but for me it would be nice to have. It is your decision what to do - with your go i will provide a pr of course.
Sounds like your zip file is gonna have duplicate entries for every file? What's the platform testrunner? The eclipse built-in one? Making this work seems less productive than making it so that you don't need your zips to have duplicate entries.
Closing due to inactivity. Feel free to reopen.
I have a module where ZipMisc has a problem saying a path would be duplicate.
there are some resources within my module like:
model/fileA.xyz model/fileB.xyz
During the BndManifestPlugin
ZipMisc.modify(jarTask.getArchivePath(), toModify, Predicates.alwaysFalse());
it wants to add the files in the following order:model/fileA.xyz model/fileB.xyz model/
The last entry is the problem here.
My fix would be to check if the entry already exists in ZipMisc: