001package videolan.libdvdnav.ant.taskdefs;
002
003import ball.util.ant.taskdefs.AnnotatedAntTask;
004import ball.util.ant.taskdefs.AntTask;
005import ball.util.ant.taskdefs.ClasspathDelegateAntTask;
006import ball.util.ant.taskdefs.ConfigurableAntTask;
007import ball.util.ant.taskdefs.NotNull;
008import lombok.Getter;
009import lombok.NoArgsConstructor;
010import lombok.Setter;
011import lombok.ToString;
012import lombok.experimental.Accessors;
013import org.apache.tools.ant.BuildException;
014import org.apache.tools.ant.Task;
015import org.apache.tools.ant.util.ClasspathUtils;
016import videolan.libdvdnav.DVDNav;
017
018import static lombok.AccessLevel.PROTECTED;
019
020/**
021 * Abstract {@link.uri http://ant.apache.org/ Ant} {@link Task} base class
022 * to invoke {@link DVDNav}.
023 *
024 * {@ant.task}
025 *
026 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
027 * @version $Revision: 5794 $
028 */
029@NoArgsConstructor(access = PROTECTED)
030public abstract class DVDTask extends Task
031                              implements AnnotatedAntTask,
032                                         ClasspathDelegateAntTask,
033                                         ConfigurableAntTask {
034    @Getter @Setter @Accessors(chain = true, fluent = true)
035    private ClasspathUtils.Delegate delegate = null;
036    @NotNull @Getter @Setter
037    private String file = null;
038
039    @Override
040    public void init() throws BuildException {
041        super.init();
042        ClasspathDelegateAntTask.super.init();
043        ConfigurableAntTask.super.init();
044    }
045
046    @Override
047    public void execute() throws BuildException {
048        super.execute();
049        AnnotatedAntTask.super.execute();
050    }
051
052    /**
053     * {@link.uri http://ant.apache.org/ Ant}
054     * {@link org.apache.tools.ant.Task} to scan a {@link DVDNav DVD}.
055     *
056     * {@ant.task}
057     */
058    @AntTask("dvd-scan")
059    @NoArgsConstructor @ToString
060    public static class Scan extends DVDTask {
061        @Override
062        public void execute() throws BuildException {
063            super.execute();
064
065            String file = getFile();
066            String language = System.getProperty("user.language");
067
068            try (DVDNav dvd = new DVDNav(file)) {
069                dvd.setLanguage(language);
070
071                log(dvd.getTitle());
072                log(dvd.getSerial());
073
074                int count = 0;
075                DVDNav.Block block = null;
076
077                while ((block = dvd.getNextBlock()) != null) {
078                    count += 1;
079                }
080
081                log("Blocks: " + count);
082            } catch (BuildException exception) {
083                throw exception;
084            } catch (Throwable throwable) {
085                throwable.printStackTrace();
086                throw new BuildException(throwable);
087            }
088        }
089    }
090}