001package ball.util.ant.taskdefs;
002/*-
003 * ##########################################################################
004 * Utilities
005 * $Id: AnnotatedAntTask.html 5431 2020-02-12 19:03:17Z ball $
006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/hcf-dev/blog/2019-07-08-fivethirtyeight-best-scrabble-string/src/main/resources/javadoc/src-html/ball/util/ant/taskdefs/AnnotatedAntTask.html $
007 * %%
008 * Copyright (C) 2008 - 2020 Allen D. Ball
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the "License");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 *
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an "AS IS" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * ##########################################################################
022 */
023import org.apache.tools.ant.BuildException;
024import org.apache.tools.ant.Task;
025
026/**
027 * Interface indicating {@link Task} is annotated with {@link AntTask} and
028 * related annotations.
029 *
030 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
031 * @version $Revision: 5431 $
032 */
033public interface AnnotatedAntTask extends AntTaskLogMethods {
034
035    /**
036     * Method to get {@link AntTask#value()}.
037     *
038     * @return  {@link AntTask#value()} if {@link.this} {@link Task} is
039     *          annotated; {@code null} otherwise.
040     */
041    default String getAntTaskName() {
042        AntTask annotation = getClass().getAnnotation(AntTask.class);
043
044        return (annotation != null) ? annotation.value() : null;
045    }
046
047    /**
048     * Default implementation for {@link Task} subclasses.  Check attributes
049     * annotated with {@link AntTaskAttributeConstraint}.
050     * See {@link AnnotatedAntTaskConfigurationChecker}.
051     *
052     * @throws  BuildException  If a
053     *                          {@link AntTaskAttributeConstraint.Checker}
054     *                          fails.
055     */
056    default void execute() throws BuildException {
057        new AnnotatedAntTaskConfigurationChecker((Task) this).checkErrors();
058    }
059}