in tomee-patch-plugin/src/main/java/org/apache/tomee/patch/plugin/PatchMojo.java [337:373]
private void updateSourceJar() throws IOException {
final List<Artifact> attachedArtifacts = this.project.getAttachedArtifacts();
final List<File> sourceJars = attachedArtifacts.stream()
.filter(Artifact::hasClassifier)
.filter(artifact -> "sources".equals(artifact.getClassifier()))
.filter(artifact -> "java-source".equals(artifact.getType()))
.map(Artifact::getFile)
.collect(Collectors.toList());
Files.mkdir(patchSourceJarsDirectory);
for (final File sourceJar : sourceJars) {
final File extractedZip = new File(patchClasspathDirectory, sourceJar.getName() + ".extracted");
Files.mkdir(extractedZip);
Zips.unzip(sourceJar, extractedZip);
copySource(patchSourceDirectory, extractedZip);
getLog().info("Patching " + sourceJar.getName());
final File patchedSourceJar = new File(patchClasspathDirectory, sourceJar.getName() + ".patched");
try (final ZipOutputStream zipOutputStream = new ZipOutputStream(IO.write(patchedSourceJar))) {
final List<File> files = Dir.from(extractedZip).files().collect(Collectors.toList());
final int beginIndex = extractedZip.getAbsolutePath().length() + 1;
for (File file : files) {
final String relativeFileName = file.getAbsolutePath().substring(beginIndex);
zipOutputStream.putNextEntry(new ZipEntry(relativeFileName));
zipOutputStream.write(IO.readBytes(file));
}
}
IO.copy(patchedSourceJar, sourceJar);
}
}