001package silicondust.ant.taskdefs; 002/*- 003 * ########################################################################## 004 * TV H/W, EPGs, and Recording 005 * $Id: HDHRDiscoverTask.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/HDHRDiscoverTask.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.swing.table.ArrayListTableModel; 024import ball.util.ant.taskdefs.AnnotatedAntTask; 025import ball.util.ant.taskdefs.AntTask; 026import ball.util.ant.taskdefs.ClasspathDelegateAntTask; 027import ball.util.ant.taskdefs.ConfigurableAntTask; 028import java.util.Map; 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.HDHRTuner; 038 039/** 040 * {@link.uri http://ant.apache.org/ Ant} {@link Task} to discover HDHomeRun 041 * tuners on the network. 042 * 043 * {@ant.task} 044 * 045 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball} 046 * @version $Revision: 5999 $ 047 */ 048@AntTask("hdhr-discover") 049@NoArgsConstructor @ToString 050public class HDHRDiscoverTask extends Task implements AnnotatedAntTask, 051 ClasspathDelegateAntTask, 052 ConfigurableAntTask { 053 @Getter @Setter @Accessors(chain = true, fluent = true) 054 private ClasspathUtils.Delegate delegate = null; 055 056 @Override 057 public void init() throws BuildException { 058 super.init(); 059 ClasspathDelegateAntTask.super.init(); 060 ConfigurableAntTask.super.init(); 061 } 062 063 @Override 064 public void execute() throws BuildException { 065 super.execute(); 066 AnnotatedAntTask.super.execute(); 067 068 try { 069 Map<Integer,HDHRTuner> map = HDHRTuner.discover(); 070 071 if (! map.values().isEmpty()) { 072 log(); 073 log(new TableModelImpl(map.values())); 074 } 075 } catch (BuildException exception) { 076 throw exception; 077 } catch (Throwable throwable) { 078 throw new BuildException(throwable); 079 } 080 } 081 082 private class TableModelImpl extends ArrayListTableModel<HDHRTuner> { 083 private static final long serialVersionUID = -8623509340568397843L; 084 085 public TableModelImpl(Iterable<HDHRTuner> iterable) { 086 super(iterable, "URI", "ID", "Model", "Count"); 087 } 088 089 @Override 090 protected Object getValueAt(HDHRTuner row, int x) { 091 Object object = null; 092 093 switch (x) { 094 case 0: 095 default: 096 object = row.getURI(); 097 break; 098 099 case 1: 100 object = Integer.toString(row.getID(), 16); 101 break; 102 103 case 2: 104 object = row.getModel(); 105 break; 106 107 case 3: 108 object = row.getCount(); 109 break; 110 } 111 112 return object; 113 } 114 } 115}