src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixSourcesBuilder.java
branchJDK-8200758-branch
changeset 58762 0fe62353385b
parent 58696 61c44899b4eb
child 58887 920f6770d71c
equal deleted inserted replaced
58761:88e2753a2334 58762:0fe62353385b
    26 package jdk.jpackage.internal;
    26 package jdk.jpackage.internal;
    27 
    27 
    28 import java.io.IOException;
    28 import java.io.IOException;
    29 import java.nio.charset.StandardCharsets;
    29 import java.nio.charset.StandardCharsets;
    30 import java.nio.file.Path;
    30 import java.nio.file.Path;
       
    31 import java.text.MessageFormat;
    31 import java.util.*;
    32 import java.util.*;
    32 import java.util.function.*;
    33 import java.util.function.*;
    33 import java.util.stream.Collectors;
    34 import java.util.stream.Collectors;
    34 import java.util.stream.Stream;
    35 import java.util.stream.Stream;
    35 import javax.xml.stream.XMLStreamException;
    36 import javax.xml.stream.XMLStreamException;
    73         do {
    74         do {
    74             ApplicationLayout layout = appImageSupplier.get();
    75             ApplicationLayout layout = appImageSupplier.get();
    75             // Don't want AppImageFile.FILENAME in installed application.
    76             // Don't want AppImageFile.FILENAME in installed application.
    76             // Register it with app image at a role without a match in installed
    77             // Register it with app image at a role without a match in installed
    77             // app layout to exclude it from layout transformation.
    78             // app layout to exclude it from layout transformation.
    78             layout.pathGroup().setPath(new Object(), Path.of(AppImageFile.FILENAME));
    79             layout.pathGroup().setPath(new Object(),
       
    80                     AppImageFile.getPathInAppImage(Path.of("")));
    79 
    81 
    80             // Want absolute paths to source files in generated WiX sources.
    82             // Want absolute paths to source files in generated WiX sources.
    81             // This is to handle scenario if sources would be processed from
    83             // This is to handle scenario if sources would be processed from
    82             // differnt current directory.
    84             // differnt current directory.
    83             appImage = layout.resolveAt(appImageRoot.toAbsolutePath().normalize());
    85             appImage = layout.resolveAt(appImageRoot.toAbsolutePath().normalize());
   134         });
   136         });
   135     }
   137     }
   136 
   138 
   137     void logWixFeatures() {
   139     void logWixFeatures() {
   138         if (wixVersion.compareTo("3.6") >= 0) {
   140         if (wixVersion.compareTo("3.6") >= 0) {
   139             Log.verbose(I18N.getString("message.use-wix36-features"));
   141             Log.verbose(MessageFormat.format(I18N.getString(
       
   142                     "message.use-wix36-features"), wixVersion));
   140         }
   143         }
   141     }
   144     }
   142 
   145 
   143     private void normalizeFileAssociation(FileAssociation fa) {
   146     private void normalizeFileAssociation(FileAssociation fa) {
   144         fa.launcherPath = addExeSuffixToPath(
   147         fa.launcherPath = addExeSuffixToPath(
   145                 installedAppImage.launchersDirectory().resolve(fa.launcherPath));
   148                 installedAppImage.launchersDirectory().resolve(fa.launcherPath));
   146 
   149 
   147         if (fa.iconPath != null && !fa.iconPath.toFile().exists()) {
   150         if (fa.iconPath != null && !fa.iconPath.toFile().exists()) {
   148             fa.iconPath = null;
   151             fa.iconPath = null;
       
   152         }
       
   153 
       
   154         if (fa.iconPath != null) {
       
   155             fa.iconPath = fa.iconPath.toAbsolutePath();
   149         }
   156         }
   150 
   157 
   151         // Filter out empty extensions.
   158         // Filter out empty extensions.
   152         fa.extensions = fa.extensions.stream().filter(Predicate.not(
   159         fa.extensions = fa.extensions.stream().filter(Predicate.not(
   153                 String::isEmpty)).collect(Collectors.toList());
   160                 String::isEmpty)).collect(Collectors.toList());
   275 
   282 
   276         boolean isFile() {
   283         boolean isFile() {
   277             return cfg.isFile;
   284             return cfg.isFile;
   278         }
   285         }
   279 
   286 
       
   287         static void startElement(XMLStreamWriter xml, String componentId,
       
   288                 String componentGuid) throws XMLStreamException, IOException {
       
   289             xml.writeStartElement("Component");
       
   290             xml.writeAttribute("Win64", "yes");
       
   291             xml.writeAttribute("Id", componentId);
       
   292             xml.writeAttribute("Guid", componentGuid);
       
   293         }
       
   294 
   280         private static final class Config {
   295         private static final class Config {
   281             Config withRegistryKeyPath() {
   296             Config withRegistryKeyPath() {
   282                 withRegistryKeyPath = true;
   297                 withRegistryKeyPath = true;
   283                 return this;
   298                 return this;
   284             }
   299             }
   327 
   342 
   328         xml.writeStartElement("DirectoryRef");
   343         xml.writeStartElement("DirectoryRef");
   329         xml.writeAttribute("Id", Id.Folder.of(directoryRefPath));
   344         xml.writeAttribute("Id", Id.Folder.of(directoryRefPath));
   330 
   345 
   331         final String componentId = "c" + role.idOf(path);
   346         final String componentId = "c" + role.idOf(path);
   332         xml.writeStartElement("Component");
   347         Component.startElement(xml, componentId, String.format("{%s}",
   333         xml.writeAttribute("Id", componentId);
   348                 role.guidOf(path)));
   334         xml.writeAttribute("Guid", String.format("{%s}", role.guidOf(path)));
       
   335 
   349 
   336         boolean isRegistryKeyPath = !systemWide || role.isRegistryKeyPath();
   350         boolean isRegistryKeyPath = !systemWide || role.isRegistryKeyPath();
   337         if (isRegistryKeyPath) {
   351         if (isRegistryKeyPath) {
   338             addRegistryKeyPath(xml, directoryRefPath);
   352             addRegistryKeyPath(xml, directoryRefPath);
   339             if ((role.isFile() || (role == Component.CreateFolder
   353             if ((role.isFile() || (role == Component.CreateFolder
   714         xml.writeEndElement(); // <RegistrySearch>
   728         xml.writeEndElement(); // <RegistrySearch>
   715         xml.writeEndElement(); // <Property>
   729         xml.writeEndElement(); // <Property>
   716 
   730 
   717         xml.writeStartElement("DirectoryRef");
   731         xml.writeStartElement("DirectoryRef");
   718         xml.writeAttribute("Id", INSTALLDIR.toString());
   732         xml.writeAttribute("Id", INSTALLDIR.toString());
   719         xml.writeStartElement("Component");
   733         Component.startElement(xml, componentId, "*");
   720         xml.writeAttribute("Id", componentId);
       
   721         xml.writeAttribute("Guid", "*");
       
   722 
   734 
   723         addRegistryKeyPath(xml, INSTALLDIR, () -> propertyId, () -> {
   735         addRegistryKeyPath(xml, INSTALLDIR, () -> propertyId, () -> {
   724             // The following code converts a path to value to be saved in registry.
   736             // The following code converts a path to value to be saved in registry.
   725             // E.g.:
   737             // E.g.:
   726             //  INSTALLDIR -> [INSTALLDIR]
   738             //  INSTALLDIR -> [INSTALLDIR]