src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractBundler.java
author herrick
Thu, 06 Jun 2019 19:10:12 -0400
branchJDK-8200758-branch
changeset 57390 1cb722a11ead
parent 57256 d7c27451f759
child 57392 46d4b0aa4542
permissions -rw-r--r--
8223333: Use try-with-resources where feasible Reviewed-by: asemenyuk, almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     1
/*
57106
ea870b9ce89a 8216492: Update copyright of all new jpackage fils to 2019
kcr
parents: 57096
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     4
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    10
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    15
 * accompanied this code).
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    16
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    20
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    23
 * questions.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    24
 */
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    25
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57030
diff changeset
    26
package jdk.jpackage.internal;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    27
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    28
import java.io.ByteArrayOutputStream;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    29
import java.io.File;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    30
import java.io.FileInputStream;
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
    31
import java.io.BufferedInputStream;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    32
import java.io.IOException;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    33
import java.io.InputStream;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    34
import java.nio.file.StandardCopyOption;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    35
import java.nio.file.Files;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    36
import java.text.MessageFormat;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    37
import java.util.Map;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    38
import java.util.ResourceBundle;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    39
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
    40
import jdk.jpackage.internal.resources.ResourceLocator;
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
    41
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    42
/**
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    43
 * AbstractBundler
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    44
 *
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    45
 * This is the base class all Bundlers extend from.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    46
 * It contains methods and parameters common to all Bundlers.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    47
 * The concrete implementations are in the platform specific Bundlers.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    48
 */
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    49
public abstract class AbstractBundler implements Bundler {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    50
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    51
    private static final ResourceBundle I18N = ResourceBundle.getBundle(
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
    52
            "jdk.jpackage.internal.resources.MainResources");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    53
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    54
    public static final BundlerParamInfo<File> IMAGES_ROOT =
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    55
            new StandardBundlerParam<>(
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    56
            "imagesRoot",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    57
            File.class,
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    58
            params -> new File(
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57106
diff changeset
    59
                StandardBundlerParam.TEMP_ROOT.fetchFrom(params), "images"),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    60
            (s, p) -> null);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    61
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
    62
    public InputStream getResourceAsStream(String name) {
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
    63
        return ResourceLocator.class.getResourceAsStream(name);
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
    64
    }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    65
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
    66
    protected void fetchResource(String publicName, String category,
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    67
            String defaultName, File result, boolean verbose, File publicRoot)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    68
            throws IOException {
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
    69
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    70
        try (InputStream is = streamResource(publicName, category,
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    71
                defaultName, verbose, publicRoot)) {
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    72
            if (is != null) {
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
    73
                Files.copy(is, result.toPath(),
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
    74
                        StandardCopyOption.REPLACE_EXISTING);
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    75
            } else {
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    76
                if (verbose) {
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    77
                    Log.verbose(MessageFormat.format(I18N.getString(
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    78
                            "message.no-default-resource"),
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    79
                            defaultName == null ? "" : defaultName,
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    80
                            category == null ? "" : "[" + category + "] ",
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    81
                            publicName));
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    82
                }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    83
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    84
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    85
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    86
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
    87
    protected void fetchResource(String publicName, String category,
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    88
            File defaultFile, File result, boolean verbose, File publicRoot)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    89
            throws IOException {
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
    90
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    91
        try (InputStream is = streamResource(publicName, category,
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    92
                null, verbose, publicRoot)) {
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    93
            if (is != null) {
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
    94
                Files.copy(is, result.toPath());
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    95
            } else {
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    96
                IOUtils.copyFile(defaultFile, result);
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    97
                if (verbose) {
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    98
                    Log.verbose(MessageFormat.format(I18N.getString(
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
    99
                            "message.using-custom-resource-from-file"),
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
   100
                            category == null ? "" : "[" + category + "] ",
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
   101
                            defaultFile.getAbsoluteFile()));
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57256
diff changeset
   102
                }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   103
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   104
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   105
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   106
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   107
    private InputStream streamResource(String publicName, String category,
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   108
            String defaultName, boolean verbose, File publicRoot)
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   109
            throws IOException {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   110
        boolean custom = false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   111
        InputStream is = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   112
        if (publicName != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   113
            if (publicRoot != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   114
                File publicResource = new File(publicRoot, publicName);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   115
                if (publicResource.exists() && publicResource.isFile()) {
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
   116
                    is = new BufferedInputStream(
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
   117
                            new FileInputStream(publicResource));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   118
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   119
            } else {
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
   120
                is = getResourceAsStream(publicName);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   121
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   122
            custom = (is != null);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   123
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   124
        if (is == null && defaultName != null) {
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
   125
            is = getResourceAsStream(defaultName);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   126
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   127
        if (verbose && is != null) {
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
   128
            String msg = null;
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
   129
            if (custom) {
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
   130
                msg = MessageFormat.format(I18N.getString(
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
   131
                        "message.using-custom-resource"),
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
   132
                        category == null ?
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
   133
                        "" : "[" + category + "] ", publicName);
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
   134
            } else {
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
   135
                msg = MessageFormat.format(I18N.getString(
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
   136
                        "message.using-default-resource"),
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
   137
                        defaultName == null ? "" : defaultName,
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
   138
                        category == null ? "" : "[" + category + "] ",
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57059
diff changeset
   139
                        publicName);
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56869
diff changeset
   140
            }
57020
a828547f7e50 8213394: Stop using Log.info() except for expected output.
herrick
parents: 57017
diff changeset
   141
            Log.verbose(msg);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   142
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   143
        return is;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   144
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   145
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   146
    protected String preprocessTextResource(String publicName, String category,
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   147
            String defaultName, Map<String, String> pairs,
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   148
            boolean verbose, File publicRoot) throws IOException {
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   149
        InputStream inp = streamResource(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   150
                publicName, category, defaultName, verbose, publicRoot);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   151
        if (inp == null) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   152
            throw new RuntimeException(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   153
                    "Jar corrupt? No " + defaultName + " resource!");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   154
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   155
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   156
        // read fully into memory
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   157
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   158
        byte[] buffer = new byte[1024];
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   159
        int length;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   160
        while ((length = inp.read(buffer)) != -1) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   161
            baos.write(buffer, 0, length);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   162
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   163
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   164
        // substitute
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   165
        String result = new String(baos.toByteArray());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   166
        for (Map.Entry<String, String> e : pairs.entrySet()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   167
            if (e.getValue() != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   168
                result = result.replace(e.getKey(), e.getValue());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   169
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   170
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   171
        return result;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   172
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   173
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   174
    @Override
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   175
    public String toString() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   176
        return getName();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   177
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   178
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   179
    @Override
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   180
    public void cleanup(Map<String, ? super Object> params) {
56989
0f19096663d1 8212625: Remove --echo-mode and related code
herrick
parents: 56982
diff changeset
   181
        try {
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   182
            IOUtils.deleteRecursive(
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57106
diff changeset
   183
                    StandardBundlerParam.TEMP_ROOT.fetchFrom(params));
56989
0f19096663d1 8212625: Remove --echo-mode and related code
herrick
parents: 56982
diff changeset
   184
        } catch (IOException e) {
0f19096663d1 8212625: Remove --echo-mode and related code
herrick
parents: 56982
diff changeset
   185
            Log.debug(e.getMessage());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   186
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   187
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   188
}