author | herrick |
Fri, 16 Aug 2019 06:55:31 -0400 | |
branch | JDK-8200758-branch |
changeset 57776 | 783db59cd8d3 |
parent 57106 | ea870b9ce89a |
child 57909 | c7de06ed4b54 |
permissions | -rw-r--r-- |
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:
57039
diff
changeset
|
2 |
* Copyright (c) 2011, 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 | 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.IOException; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
30 |
import java.io.PrintStream; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
31 |
import java.io.PrintWriter; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
32 |
|
56994
b4aca2dbe2b5
8212537: Create method and class description comments for main functionality
herrick
parents:
56989
diff
changeset
|
33 |
/** |
b4aca2dbe2b5
8212537: Create method and class description comments for main functionality
herrick
parents:
56989
diff
changeset
|
34 |
* Log |
b4aca2dbe2b5
8212537: Create method and class description comments for main functionality
herrick
parents:
56989
diff
changeset
|
35 |
* |
b4aca2dbe2b5
8212537: Create method and class description comments for main functionality
herrick
parents:
56989
diff
changeset
|
36 |
* General purpose logging mechanism. |
b4aca2dbe2b5
8212537: Create method and class description comments for main functionality
herrick
parents:
56989
diff
changeset
|
37 |
*/ |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
38 |
public class Log { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
39 |
public static class Logger { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
40 |
private boolean verbose = false; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
41 |
private PrintWriter out = null; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
42 |
private PrintWriter err = null; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
43 |
|
57776 | 44 |
// verbose defaults to true unless environment variable JPACKAGE_DEBUG |
45 |
// is set to true. |
|
46 |
// Then it is only set to true by using --verbose jpackage option |
|
47 |
||
48 |
public Logger() { |
|
49 |
verbose = ("true".equals(System.getenv("JPACKAGE_DEBUG"))); |
|
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
50 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
51 |
|
57776 | 52 |
public void setVerbose() { |
53 |
verbose = true; |
|
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
54 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
55 |
|
56987 | 56 |
public boolean isVerbose() { |
57 |
return verbose; |
|
58 |
} |
|
59 |
||
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
60 |
public void setPrintWriter(PrintWriter out, PrintWriter err) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
61 |
this.out = out; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
62 |
this.err = err; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
63 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
64 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
65 |
public void flush() { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
66 |
if (out != null) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
67 |
out.flush(); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
68 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
69 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
70 |
if (err != null) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
71 |
err.flush(); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
72 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
73 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
74 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
75 |
public void info(String msg) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
76 |
if (out != null) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
77 |
out.println(msg); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
78 |
} else { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
79 |
System.out.println(msg); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
80 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
81 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
82 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
83 |
public void error(String msg) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
84 |
if (err != null) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
85 |
err.println(msg); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
86 |
} else { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
87 |
System.err.println(msg); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
88 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
89 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
90 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
91 |
public void verbose(Throwable t) { |
57776 | 92 |
if (out != null && verbose) { |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
93 |
t.printStackTrace(out); |
57776 | 94 |
} else if (verbose) { |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
95 |
t.printStackTrace(System.out); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
96 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
97 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
98 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
99 |
public void verbose(String msg) { |
57776 | 100 |
if (out != null && verbose) { |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
101 |
out.println(msg); |
57776 | 102 |
} else if (verbose) { |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
103 |
System.out.println(msg); |
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 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
108 |
private static Logger delegate = null; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
109 |
|
57776 | 110 |
public static void setLogger(Logger logger) { |
111 |
delegate = (logger != null) ? logger : new Logger(); |
|
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
112 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
113 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
114 |
public static void flush() { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
115 |
if (delegate != null) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
116 |
delegate.flush(); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
117 |
} |
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 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
120 |
public static void info(String msg) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
121 |
if (delegate != null) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
122 |
delegate.info(msg); |
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 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
125 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
126 |
public static void error(String msg) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
127 |
if (delegate != null) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
128 |
delegate.error(msg); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
129 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
130 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
131 |
|
57776 | 132 |
public static void setVerbose() { |
56987 | 133 |
if (delegate != null) { |
57776 | 134 |
delegate.setVerbose(); |
56987 | 135 |
} |
136 |
} |
|
137 |
||
138 |
public static boolean isVerbose() { |
|
57776 | 139 |
return (delegate != null) ? delegate.isVerbose() : false; |
56987 | 140 |
} |
141 |
||
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
142 |
public static void verbose(String msg) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
143 |
if (delegate != null) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
144 |
delegate.verbose(msg); |
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 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
147 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
148 |
public static void verbose(Throwable t) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
149 |
if (delegate != null) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
150 |
delegate.verbose(t); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
151 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
152 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
153 |
} |