You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

NoBannerLogger.java 3.1 kB

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