1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.*; 23 import java.util.*; 24 25 import org.apache.tools.ant.* ; 26 import org.apache.tools.ant.taskdefs.* ; 27 import org.apache.tools.ant.types.FileSet; 28 import org.apache.tools.ant.types.Path; 29 30 39 public class LocJHIndexer extends MatchingTask { 40 41 protected File basedir = null ; 42 protected String dbdir = null ; 43 protected String locales = null ; 44 protected String jhall = null ; 45 46 49 public void setJhall( String jhall) { 50 this.jhall = jhall; 51 } 52 53 54 protected String getJhall() { 55 String ret = null ; 56 String prop = null ; 57 58 if( jhall != null) { 60 ret = jhall ; 61 } 62 else { 63 64 prop = getProject().getProperty("locjhindexer.jhall"); 66 if( prop != null) { 67 ret = prop ; 68 } 69 } 70 71 return( ret) ; 72 } 73 74 75 public void setBasedir( File dir) { 76 basedir = dir ; 77 } 78 79 82 public void setDbdir( String dir) { 83 dbdir = dir ; 84 } 85 86 87 public void setLocales( String s) { 88 locales = s ; 89 } 90 91 92 protected String getLocales() { 93 if( locales != null) { 94 return( locales) ; 95 } 96 return(getProject().getProperty("locjhindexer.locales")); 97 } 98 99 public void execute() throws BuildException { 100 String locs = getLocales() ; 101 String helpset_locs = null ; 102 StringTokenizer tokenizer = null ; 103 String loc = null ; 104 105 if( getJhall() == null) 106 throw new BuildException( "Must specify the jhall attribute") ; 107 if( dbdir == null || dbdir.trim().equals( "")) 108 throw new BuildException( "Must specify the dbdir attribute") ; 109 if( basedir == null) 110 throw new BuildException( "Must specify the basedir attribute") ; 111 if( locs == null || locs.trim().equals( "")) 112 throw new BuildException( "Must specify the locales attribute") ; 113 114 getProject().addTaskDefinition("jhindexer", JHIndexer.class); 116 117 tokenizer = new StringTokenizer( locs, ", ") ; 119 while( tokenizer.hasMoreTokens()) { 120 loc = tokenizer.nextToken() ; 121 122 if( hasHelpset( loc)) { 124 125 if( helpset_locs == null) { 127 helpset_locs = new String ( loc) ; 128 } 129 else { 130 helpset_locs += "," + loc ; 131 } 132 } 133 } 134 135 if( helpset_locs != null) { 137 tokenizer = new StringTokenizer( helpset_locs, ", ") ; 138 while( tokenizer.hasMoreTokens()) { 139 loc = tokenizer.nextToken() ; 140 141 RunForLocale( loc) ; 143 } 144 } 145 } 146 147 148 protected boolean hasHelpset( String loc) { 149 boolean ret = false ; 150 LocHelpsetFilter filter = new LocHelpsetFilter( loc) ; 151 File files[] ; 152 153 files = basedir.listFiles( filter) ; 154 if( files != null && files.length > 0) { 155 ret = true ; 156 } 157 158 return( ret) ; 159 } 160 161 protected void RunForLocale( String locale) throws BuildException { 163 JHIndexer jhindexer ; 164 165 jhindexer = (JHIndexer) getProject().createTask("jhindexer"); 166 jhindexer.init() ; 167 168 jhindexer.setIncludes( locale + "/**/*.htm*") ; 169 jhindexer.setExcludes( locale + "/" + dbdir + "/" + "," + 170 locale + "/credits.htm*") ; 171 jhindexer.setBasedir( new File( basedir + "/")) ; 172 jhindexer.setDb( new File( basedir + "/" + locale + "/" + dbdir)) ; 173 jhindexer.setLocale( locale) ; 174 setJHLib( jhindexer) ; 175 176 jhindexer.execute() ; 177 } 178 179 protected void setJHLib( JHIndexer jhindexer) { 180 String jhlib, dir, regexp ; 181 int idx, i ; 182 FileSet fs ; 183 File file ; 184 LinkedList<String > dirs, regexps ; 185 StringTokenizer st ; 186 Path path ; 187 188 dirs = new LinkedList<String >() ; 190 regexps = new LinkedList<String >() ; 191 jhlib = getJhall() ; 192 st = new StringTokenizer( jhlib, " \n,") ; 193 while( st.hasMoreTokens()) { 194 regexp = st.nextToken() ; 195 196 idx = regexp.lastIndexOf( "/") ; 199 dir = regexp.substring( 0, idx) ; 200 file = new File( dir) ; 201 if( file.exists()) { 202 dirs.add( dir) ; 203 regexps.add( regexp.substring( idx+1)) ; 204 } 205 } 206 207 if( dirs.size() > 0) { 208 path = jhindexer.createClasspath() ; 209 for( i = 0; i < dirs.size(); i++) { 210 dir = dirs.get( i) ; 211 regexp = regexps.get( i) ; 212 fs = new FileSet() ; 213 fs.setDir( new File( dir)) ; 214 fs.setIncludes( regexp) ; 215 path.addFileset( fs) ; 216 } 217 } 218 else { 219 throw new BuildException( "jhall not found.") ; 220 } 221 } 222 223 protected class LocHelpsetFilter implements FilenameFilter { 224 protected String locale = null ; 225 226 public LocHelpsetFilter( String loc) { 227 locale = loc ; 228 } 229 230 public boolean accept(File dir, 231 String name) { 232 return( name.endsWith( "_" + locale + ".hs")) ; 233 } 234 } 235 236 } 237 238 | Popular Tags |