001package silicondust.ant.taskdefs;
002/*-
003 * ##########################################################################
004 * TV H/W, EPGs, and Recording
005 * $Id: HDHRRecordingTask.java 5999 2020-05-18 16:41:28Z ball $
006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/silicondust/trunk/src/main/java/silicondust/ant/taskdefs/HDHRRecordingTask.java $
007 * %%
008 * Copyright (C) 2013 - 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 ball.util.ant.taskdefs.AnnotatedAntTask;
024import ball.util.ant.taskdefs.AntTask;
025import ball.util.ant.taskdefs.ClasspathDelegateAntTask;
026import ball.util.ant.taskdefs.ConfigurableAntTask;
027import ball.util.ant.taskdefs.NotNull;
028import java.io.File;
029import lombok.Getter;
030import lombok.NoArgsConstructor;
031import lombok.Setter;
032import lombok.ToString;
033import lombok.experimental.Accessors;
034import org.apache.tools.ant.BuildException;
035import org.apache.tools.ant.Task;
036import org.apache.tools.ant.util.ClasspathUtils;
037import silicondust.HDHRRecording;
038
039import static lombok.AccessLevel.PROTECTED;
040
041/**
042 * {@link.uri http://ant.apache.org/ Ant} {@link Task}
043 * to display metadata about an {@link HDHRRecording}.
044 *
045 * {@ant.task}
046 *
047 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
048 * @version $Revision: 5999 $
049 */
050@NoArgsConstructor(access = PROTECTED)
051public abstract class HDHRRecordingTask extends Task
052                                        implements AnnotatedAntTask,
053                                                   ClasspathDelegateAntTask,
054                                                   ConfigurableAntTask {
055    @Getter @Setter @Accessors(chain = true, fluent = true)
056    private ClasspathUtils.Delegate delegate = null;
057
058    @Override
059    public void init() throws BuildException {
060        super.init();
061        ClasspathDelegateAntTask.super.init();
062        ConfigurableAntTask.super.init();
063    }
064
065    @Override
066    public void execute() throws BuildException {
067        super.execute();
068        AnnotatedAntTask.super.execute();
069    }
070
071    @AntTask("hdhr-recording-metadata")
072    @NoArgsConstructor @ToString
073    public static class Metadata extends HDHRRecordingTask {
074        @NotNull @Getter @Setter
075        private File file = null;
076
077        @Override
078        public void execute() throws BuildException {
079            super.execute();
080
081            try {
082                HDHRRecording recording = new HDHRRecording(getFile());
083
084                log(String.valueOf(recording));
085                log("offset=" + recording.getOffset());
086            } catch (BuildException exception) {
087                throw exception;
088            } catch (Throwable throwable) {
089                throw new BuildException(throwable);
090            }
091        }
092    }
093}