1. /*
  2. * Copyright 2000-2002,2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant;
  18. import org.apache.tools.ant.util.StringUtils;
  19. /**
  20. * Extends DefaultLogger to strip out empty targets.
  21. *
  22. */
  23. public class NoBannerLogger extends DefaultLogger {
  24. /**
  25. * Name of the current target, if it should
  26. * be displayed on the next message. This is
  27. * set when a target starts building, and reset
  28. * to <code>null</code> after the first message for
  29. * the target is logged.
  30. */
  31. protected String targetName;
  32. /** Sole constructor. */
  33. public NoBannerLogger() {
  34. }
  35. /**
  36. * Notes the name of the target so it can be logged
  37. * if it generates any messages.
  38. *
  39. * @param event A BuildEvent containing target information.
  40. * Must not be <code>null</code>.
  41. */
  42. public void targetStarted(BuildEvent event) {
  43. targetName = event.getTarget().getName();
  44. }
  45. /**
  46. * Resets the current target name to <code>null</code>.
  47. *
  48. * @param event Ignored in this implementation.
  49. */
  50. public void targetFinished(BuildEvent event) {
  51. targetName = null;
  52. }
  53. /**
  54. * Logs a message for a target if it is of an appropriate
  55. * priority, also logging the name of the target if this
  56. * is the first message which needs to be logged for the
  57. * target.
  58. *
  59. * @param event A BuildEvent containing message information.
  60. * Must not be <code>null</code>.
  61. */
  62. public void messageLogged(BuildEvent event) {
  63. if (event.getPriority() > msgOutputLevel
  64. || null == event.getMessage()
  65. || "".equals(event.getMessage().trim())) {
  66. return;
  67. }
  68. if (null != targetName) {
  69. out.println(StringUtils.LINE_SEP + targetName + ":");
  70. targetName = null;
  71. }
  72. super.messageLogged(event);
  73. }
  74. }