1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved. 2 * 3 * This program and the accompanying materials are made available under 4 * the terms of the Common Public License v1.0 which accompanies this distribution, 5 * and is available at http://www.eclipse.org/legal/cpl-v10.html 6 * 7 * $Id: FileTask.java,v 1.2.2.1 2004/07/08 10:52:10 vlad_r Exp $ 8 */ 9 package com.vladium.emma.ant; 10 11 import java.io.File; 12 import java.util.ArrayList; 13 import java.util.Iterator; 14 import java.util.List; 15 16 import org.apache.tools.ant.DirectoryScanner; 17 import org.apache.tools.ant.types.FileSet; 18 19 import com.vladium.emma.ant.XFileSet; 20 21 // ---------------------------------------------------------------------------- 22 /** 23 * @author Vlad Roubtsov, (C) 2003 24 */ 25 public 26 abstract class FileTask extends NestedTask 27 { 28 // public: ................................................................ 29 30 31 // public static final class FileElement 32 // { 33 // public FileElement (final List /* File */ files) 34 // { 35 // m_files = files; 36 // } 37 // 38 // public void setFile (final File file) 39 // { 40 // if (file != null) m_files.add (file); 41 // } 42 // 43 // 44 // private final List /* File */ m_files; 45 // 46 // } // end of nested class 47 48 49 // infileset|fileset element: 50 addInfileset(final XFileSet set)51 public final void addInfileset (final XFileSet set) 52 { 53 if (set != null) m_dataFileSets.add (set); 54 } 55 addFileset(final XFileSet set)56 public final void addFileset (final XFileSet set) 57 { 58 if (set != null) m_dataFileSets.add (set); 59 } 60 61 62 // // infile|file element: 63 // 64 // public final FileElement createInfile () 65 // { 66 // return new FileElement (m_dataFiles); 67 // } 68 // 69 // public final FileElement createFile () 70 // { 71 // return new FileElement (m_dataFiles); 72 // } 73 74 // protected: ............................................................. 75 76 FileTask(final SuppressableTask parent)77 protected FileTask (final SuppressableTask parent) 78 { 79 super (parent); 80 81 m_dataFileSets = new ArrayList (); 82 // m_dataFiles = new ArrayList (); 83 } 84 85 getDataPath(final boolean removeNonexistent)86 protected final String [] getDataPath (final boolean removeNonexistent) 87 { 88 final List /* String */ _files = new ArrayList (); 89 90 // merge filesets: 91 for (Iterator i = m_dataFileSets.iterator (); i.hasNext (); ) 92 { 93 final FileSet set = (FileSet) i.next (); 94 final DirectoryScanner ds = set.getDirectoryScanner (project); 95 final File dsBaseDir = ds.getBasedir (); 96 97 final String [] dsfiles = ds.getIncludedFiles (); 98 for (int f = 0; f < dsfiles.length; ++ f) 99 { 100 _files.add (new File (dsBaseDir, dsfiles [f]).getAbsolutePath ()); 101 } 102 } 103 104 // // merge files: 105 // for (Iterator i = m_dataFiles.iterator (); i.hasNext (); ) 106 // { 107 // final File file = (File) i.next (); 108 // if (! removeNonexistent || file.exists ()) 109 // { 110 // _files.add (file.getAbsolutePath ()); 111 // } 112 // } 113 114 if (_files.size () == 0) 115 return EMPTY_STRING_ARRAY; 116 else 117 { 118 final String [] files = new String [_files.size ()]; 119 _files.toArray (files); 120 121 return files; 122 } 123 } 124 125 // package: ............................................................... 126 127 // private: ............................................................... 128 129 130 private final List /* FileSet */ m_dataFileSets; // never null 131 // private final List /* File */ m_dataFiles; // never null 132 133 private static final String [] EMPTY_STRING_ARRAY = new String [0]; 134 135 } // end of class 136 // ----------------------------------------------------------------------------