|
27 | 27 |
|
28 | 28 | import static jdk.jpackage.internal.util.PathUtils.normalizedAbsolutePathString; |
29 | 29 |
|
| 30 | +import java.io.ByteArrayInputStream; |
30 | 31 | import java.io.IOException; |
31 | | -import java.io.PrintWriter; |
32 | 32 | import java.io.UncheckedIOException; |
33 | 33 | import java.net.URI; |
34 | 34 | import java.net.URISyntaxException; |
|
44 | 44 | import java.util.stream.Stream; |
45 | 45 | import javax.xml.stream.XMLStreamException; |
46 | 46 | import javax.xml.stream.XMLStreamWriter; |
| 47 | +import javax.xml.transform.TransformerException; |
| 48 | +import javax.xml.transform.TransformerFactory; |
| 49 | +import javax.xml.transform.stream.StreamResult; |
| 50 | +import javax.xml.transform.stream.StreamSource; |
47 | 51 | import jdk.internal.util.Architecture; |
48 | 52 | import jdk.internal.util.OSVersion; |
49 | 53 | import jdk.jpackage.internal.PackagingPipeline.PackageTaskID; |
|
53 | 57 | import jdk.jpackage.internal.model.MacPkgPackage; |
54 | 58 | import jdk.jpackage.internal.model.Package; |
55 | 59 | import jdk.jpackage.internal.model.PackagerException; |
| 60 | +import jdk.jpackage.internal.resources.ResourceLocator; |
56 | 61 | import jdk.jpackage.internal.util.XmlUtils; |
57 | 62 |
|
58 | 63 | record MacPkgPackager(MacPkgPackage pkg, BuildEnv env, Optional<Services> services, Path outputDir) { |
@@ -457,29 +462,13 @@ private void prepareConfigFiles() throws IOException { |
457 | 462 | } |
458 | 463 |
|
459 | 464 | private void patchCPLFile(Path cpl) throws IOException { |
460 | | - String cplData = Files.readString(cpl); |
461 | | - String[] lines = cplData.split("\n"); |
462 | | - try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(cpl))) { |
463 | | - int skip = 0; |
464 | | - // Used to skip Java.runtime bundle, since |
465 | | - // pkgbuild with --root will find two bundles app and Java runtime. |
466 | | - // We cannot generate component proprty list when using |
467 | | - // --component argument. |
468 | | - for (int i = 0; i < lines.length; i++) { |
469 | | - if (lines[i].trim().equals("<key>BundleIsRelocatable</key>")) { |
470 | | - out.println(lines[i]); |
471 | | - out.println("<false/>"); |
472 | | - i++; |
473 | | - } else if (lines[i].trim().equals("<key>ChildBundles</key>")) { |
474 | | - ++skip; |
475 | | - } else if ((skip > 0) && lines[i].trim().equals("</array>")) { |
476 | | - --skip; |
477 | | - } else { |
478 | | - if (skip == 0) { |
479 | | - out.println(lines[i]); |
480 | | - } |
481 | | - } |
482 | | - } |
| 465 | + try (final var xsltResource = ResourceLocator.class.getResourceAsStream("adjust-component-plist.xsl")) { |
| 466 | + final var srcXml = new StreamSource(new ByteArrayInputStream(Files.readAllBytes(cpl))); |
| 467 | + final var dstXml = new StreamResult(cpl.toFile()); |
| 468 | + final var xslt = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltResource)); |
| 469 | + xslt.transform(srcXml, dstXml); |
| 470 | + } catch (TransformerException ex) { |
| 471 | + throw new RuntimeException(ex); |
483 | 472 | } |
484 | 473 | } |
485 | 474 |
|
|
0 commit comments