001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*- 002 * 003 * Copyright © 2017 MicroBean. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 014 * implied. See the License for the specific language governing 015 * permissions and limitations under the License. 016 */ 017package org.microbean.helm.maven; 018 019import java.io.Serializable; 020 021import java.util.EventObject; 022import java.util.Objects; 023 024import org.apache.maven.plugin.logging.Log; 025 026/** 027 * An {@link EventObject} describing a meaningful event in the life of 028 * a <a href="https://docs.helm.sh/glossary/#release">Helm 029 * release</a>. 030 * 031 * @author <a href="https://about.me/lairdnelson" 032 * target="_parent">Laird Nelson</a> 033 * 034 * @see EventObject 035 */ 036public abstract class AbstractReleaseEvent extends EventObject { 037 038 039 /* 040 * Static fields. 041 */ 042 043 044 /** 045 * The version of this class for {@linkplain Serializable 046 * serialization} purposes. 047 */ 048 private static final long serialVersionUID = 1L; 049 050 051 /* 052 * Constructors. 053 */ 054 055 056 /** 057 * Creates a new {@link AbstractReleaseEvent}. 058 * 059 * @param source the {@link AbstractReleaseMojo} responsible for 060 * firing the event; must not be {@code null} 061 * 062 * @exception IllegalArgumentException if {@code source} is {@code 063 * null}; thrown by the {@link EventObject#EventObject(Object)} 064 * constructor 065 */ 066 protected AbstractReleaseEvent(final AbstractReleaseMojo source) { 067 super(source); 068 } 069 070 071 /* 072 * Instance methods. 073 */ 074 075 076 /** 077 * Returns the {@link Log} that may be used to log information. 078 * 079 * <p>This method may return {@code null}.</p> 080 * 081 * @return the {@link Log} that may be used to log information, or 082 * {@code null} 083 */ 084 public final Log getLog() { 085 final AbstractReleaseMojo source = this.getSource(); 086 final Log log; 087 if (source == null) { 088 log = null; 089 } else { 090 log = source.getLog(); 091 } 092 return log; 093 } 094 095 /** 096 * Overrides the {@link EventObject#getSource()} method to cast its 097 * return type to an {@link AbstractReleaseMojo}. 098 * 099 * <p>This method never returns {@code null}.</p> 100 * 101 * <p>Overrides of this method must not return {@code null}.</p> 102 * 103 * @return the {@link AbstractReleaseMojo} implementation that fired 104 * this event; never {@code null} 105 */ 106 @Override 107 public AbstractReleaseMojo getSource() { 108 return (AbstractReleaseMojo)super.getSource(); 109 } 110 111}