1 /*
   2  * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.oracle.tools.packager;
  27 
  28 import java.io.ByteArrayOutputStream;
  29 import java.io.IOException;
  30 import java.io.PrintStream;
  31 
  32 /**
  33  * @deprecated use {@link ToolProvider} to locate the {@code "javapackager"} tool instead.
  34  */
  35 @Deprecated(since="10", forRemoval=true)
  36 public class Log {
  37     public static class Logger {
  38         private boolean verbose = false;
  39 
  40         public Logger(boolean v) {
  41             verbose = v;
  42         }
  43 
  44         public void info(String msg) {
  45             System.out.println(msg);
  46         }
  47 
  48         public void verbose(Throwable t) {
  49             if (Log.debug || verbose) {
  50                 t.printStackTrace(System.out);
  51             }
  52         }
  53 
  54         public void verbose(String msg) {
  55             if (Log.debug || verbose) {
  56                 System.out.println(msg);
  57             }
  58         }
  59 
  60         public void debug(String msg) {
  61             if (Log.debug) {
  62                 System.out.println(msg);
  63             }
  64         }
  65     }
  66 
  67     private static Logger delegate = null;
  68     private static boolean debug =
  69             "true".equals(System.getenv("JAVAFX_ANT_DEBUG"));
  70 
  71     public static void setLogger(Logger l) {
  72         delegate = l;
  73         if (l == null) {
  74             delegate = new Logger(false);
  75         }
  76     }
  77 
  78 
  79     public static void info(String msg) {
  80         if (delegate != null) {
  81            delegate.info(msg);
  82         }
  83     }
  84 
  85     public static void verbose(String msg) {
  86         if (delegate != null) {
  87            delegate.verbose(msg);
  88         }
  89     }
  90 
  91     public static void verbose(Throwable t) {
  92         if (delegate != null) {
  93            delegate.verbose(t);
  94         }
  95     }
  96 
  97     public static void debug(String msg) {
  98         if (delegate != null) {
  99            delegate.debug(msg);
 100         }
 101     }
 102 
 103     public static void debug(RuntimeException re) {
 104         debug((Throwable) re);
 105     }
 106 
 107     public static void debug(Throwable t) {
 108         try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
 109             try (PrintStream ps = new PrintStream(baos)) {
 110                 t.printStackTrace(ps);
 111             }
 112             debug(baos.toString());
 113         } catch (IOException e) {
 114             e.printStackTrace();
 115         }
 116     }
 117 
 118     public static boolean isDebug() {
 119         return debug;
 120     }
 121 
 122     public static void setDebug(boolean debug) {
 123         Log.debug = debug;
 124     }
 125 }