001package videolan.libdvdnav.ant.taskdefs; 002/*- 003 * ########################################################################## 004 * VideoLAN libdvdnav Java Bindings 005 * $Id: DVDTask.java 7215 2021-01-03 18:39:51Z ball $ 006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/videolan-libdvdnav/trunk/src/main/java/videolan/libdvdnav/ant/taskdefs/DVDTask.java $ 007 * %% 008 * Copyright (C) 2020, 2021 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 lombok.Getter; 029import lombok.NoArgsConstructor; 030import lombok.Setter; 031import lombok.ToString; 032import lombok.experimental.Accessors; 033import org.apache.tools.ant.BuildException; 034import org.apache.tools.ant.Task; 035import org.apache.tools.ant.util.ClasspathUtils; 036import videolan.libdvdnav.DVDNav; 037 038import static lombok.AccessLevel.PROTECTED; 039 040/** 041 * Abstract {@link.uri http://ant.apache.org/ Ant} {@link Task} base class 042 * to invoke {@link DVDNav}. 043 * 044 * {@ant.task} 045 * 046 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball} 047 * @version $Revision: 7215 $ 048 */ 049@NoArgsConstructor(access = PROTECTED) 050public abstract class DVDTask extends Task 051 implements AnnotatedAntTask, 052 ClasspathDelegateAntTask, 053 ConfigurableAntTask { 054 @Getter @Setter @Accessors(chain = true, fluent = true) 055 private ClasspathUtils.Delegate delegate = null; 056 @NotNull @Getter @Setter 057 private String file = null; 058 059 @Override 060 public void init() throws BuildException { 061 super.init(); 062 ClasspathDelegateAntTask.super.init(); 063 ConfigurableAntTask.super.init(); 064 } 065 066 @Override 067 public void execute() throws BuildException { 068 super.execute(); 069 AnnotatedAntTask.super.execute(); 070 } 071 072 /** 073 * {@link.uri http://ant.apache.org/ Ant} 074 * {@link org.apache.tools.ant.Task} to scan a {@link DVDNav DVD}. 075 * 076 * {@ant.task} 077 */ 078 @AntTask("dvd-scan") 079 @NoArgsConstructor @ToString 080 public static class Scan extends DVDTask { 081 @Override 082 public void execute() throws BuildException { 083 super.execute(); 084 085 String file = getFile(); 086 String language = System.getProperty("user.language"); 087 088 try (DVDNav dvd = new DVDNav(file)) { 089 dvd.setLanguage(language); 090 091 log(dvd.getTitle()); 092 log(dvd.getSerial()); 093 094 int count = 0; 095 DVDNav.Block block = null; 096 097 while ((block = dvd.getNextBlock()) != null) { 098 count += 1; 099 } 100 101 log("Blocks: " + count); 102 } catch (BuildException exception) { 103 throw exception; 104 } catch (Throwable throwable) { 105 throwable.printStackTrace(); 106 throw new BuildException(throwable); 107 } 108 } 109 } 110}