KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > nbbuild > L10nTask


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.nbbuild;
21
22 import java.io.BufferedReader JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.FileReader JavaDoc;
25 import java.io.FileWriter JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.util.Enumeration JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Hashtable JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.StringTokenizer JavaDoc;
32 import java.util.Vector JavaDoc;
33 import org.apache.tools.ant.BuildException;
34 import org.apache.tools.ant.DirectoryScanner;
35 import org.apache.tools.ant.Project;
36 import org.apache.tools.ant.taskdefs.Delete;
37 import org.apache.tools.ant.taskdefs.GZip;
38 import org.apache.tools.ant.taskdefs.MatchingTask;
39 import org.apache.tools.ant.taskdefs.Tar;
40 import org.apache.tools.ant.types.FileSet;
41 import org.netbeans.nbbuild.utils.cvsutils.CvsEntries;
42
43 /**
44  * This task was created to create L10N kits.
45  * The xml to call this task might look like:
46  * <l10nTask topdirs="${f4jroot} ${nbroot}" modules="${all_modules}" localizableFile="${localizableF}" generatedFile="${genFile}" changedFile="${changedFile}" buildDir="${l10n-build}" distDir="${l10n-dist}" buildNumber="${buildnumber}"/>
47  *
48  *
49  * Each resulting kit will be a tar file containing one directory
50  * for each repository examined.
51  * Each repository_directory will contain one tar-file
52  * for each module with changed localizable files.
53  * The structure of the tar file is as follows:
54  * repository_dir/
55  * module_tar/
56  * generatedFile
57  * contentFile
58  * localizableFile1.html
59  * localizableFile2.gif...
60  *
61  * 1. All localizable files (as defined in "localizableFile")
62  * "localizableFile" is a list of file patterns difining all localizable source files.
63  * "localizableFile" itself is not included in the kit.
64  * 2. A content file (as named in "contentFile")
65  * This is a list of the names of all localizable files which need to be (re)localized.
66  * 3. A generated file (as named in "generatedFile")
67  * This is a list of the names of all localizable files with the most recent
68  * CVS revision number.
69  *
70  * The generated file need not be committed to cvs until the files come back
71  * localized. (This is a change from the procedure followed in late 2001).
72  *
73  * As of version 1.1.2, converted Gzip methods to use ant 1.4.1, and added ability to
74  * 1) embed exclude patterns in the l10n.list file
75  * (must use keyword "exclude " followed by the pattern.)
76  * 2) add ability to embed reading of additional files
77  * (must use the keyword "read " followed by the path to the file)
78  * The special case "read global" will read the file set by the property globalFile
79  * 3) add the ability to embed properties in the patterns. i
80  * The special case "l10n-module" property will be set from within L10nTask
81  *
82  * @author Erica Grevemeyer
83  * @version 1.1, Feb 4 11:21:09 PST 2002
84  * @version 1.1.2 Aug 29 15:23:51 PDT 2002
85  */

86 public class L10nTask extends MatchingTask {
87     private String JavaDoc[] modules;
88     private String JavaDoc[] topdirs;
89     private String JavaDoc localizableFile, generatedFile, changedFile,globalFile;
90     private String JavaDoc allFile = "l10n.list.all";
91     private String JavaDoc excludePattern = "";
92     private String JavaDoc includePattern = "";
93     // Sets the set of exclude patterns.
94
// Patterns may be separated by a comma or a space.
95
// The first instance which necessitated this addition was
96
// "**/ja/**"
97
private String JavaDoc buildDir;
98     private String JavaDoc distDir;
99     private Vector JavaDoc error = new Vector JavaDoc();
100     private Hashtable JavaDoc<String JavaDoc, CvsEntries> cvsEntriesCache=new Hashtable JavaDoc<String JavaDoc, CvsEntries>();
101     private Hashtable JavaDoc<String JavaDoc, String JavaDoc> changed = new Hashtable JavaDoc<String JavaDoc, String JavaDoc>();
102     private Hashtable JavaDoc<String JavaDoc, String JavaDoc> generatedFileHash = new Hashtable JavaDoc<String JavaDoc, String JavaDoc>();
103     private Hashtable JavaDoc<String JavaDoc, String JavaDoc> fullPropHash = null ;
104
105     private Project p;
106     private boolean readGlobalFile=false; //have we already read globalFile?
107
private StringBuffer JavaDoc[] globalsbholder= new StringBuffer JavaDoc[2];
108     static boolean DEBUG = false;
109     boolean cont=false;
110     private String JavaDoc buildNumber;
111     String JavaDoc[] localizableFiles;
112
113     public void execute() throws BuildException {
114         // 1. Check that settable variables have been set.
115
// If they have not been, abandon ship!
116

117         if (modules == null ) {
118             throw new BuildException("Required variable not set. Set 'modules' in the calling .xml file");
119         }
120         if (topdirs == null ) {
121             throw new BuildException("Required variable not set. Set 'topdirs' in the calling .xml file");
122         }
123         if (distDir == null ) {
124             throw new BuildException("Required variable not set. Set 'distDir' in the calling .xml file");
125         }
126
127         if (buildDir == null ) {
128             throw new BuildException("Required variable not set. Set 'buildDir' in the calling .xml file");
129         }
130         if (localizableFile == null ) {
131             throw new BuildException("Required variable not set. Set 'localizableFile' in the calling .xml file");
132         }
133         if (generatedFile == null ) {
134             throw new BuildException("Required variable not set. Set 'generatedFile' in the calling .xml file");
135         }
136         if (changedFile == null ) {
137             throw new BuildException("Required variable not set. Set 'changedFile' in the calling .xml file");
138         }
139         if (buildNumber == null ) {
140             throw new BuildException("Required variable not set. Set 'buildNumber' in the calling .xml file");
141         }
142
143         //if the dir doesn't exist, make it.
144
// if the dir still doesn't exist, fail.
145
File JavaDoc dd = new File JavaDoc(distDir);
146         if ( ! dd.exists() ) {
147             dd.mkdirs();
148         }
149
150         System.out.print("topdirs:\t");
151         for (int j=0; j<topdirs.length; j++) {
152             System.out.print(topdirs[j]+"\t");
153         }
154
155         System.out.print("\nmodules:\t");
156         for (int i=0; i<modules.length; i++) {
157             System.out.print(modules[i]+"\t");
158         }
159
160         System.out.println("\ndistDir:\t"+distDir);
161         System.out.println("buildDir:\t"+buildDir);
162         System.out.println("localizableFile:\t"+localizableFile);
163         System.out.println("generatedFile:\t"+generatedFile);
164         System.out.println("changedFile:\t"+changedFile);
165         System.out.println("globalFile:\t"+globalFile);
166         System.out.println("buildNumber:\t"+buildNumber);
167
168
169         CvsEntries ce;
170
171         p=this.getProject();
172
173         for (int i=0; i<topdirs.length; i++) {
174             // if (DEBUG) System.out.println("STARTING TOPDIR "+topdirs[i]);
175
for(int j=0; j<modules.length; j++) {
176                 if (modules[j] != null && ! modules[j].equals("")) {
177                     @SuppressWarnings JavaDoc("unchecked")
178                     Hashtable JavaDoc<String JavaDoc,String JavaDoc> props = p.getProperties();
179                     fullPropHash = props;
180
181                     // System.out.println("IN FOR MODULES "+modules[j]);
182
// System.out.println("\tSTARTING MODULE "+modules[j]);
183

184                     File JavaDoc f = new File JavaDoc(topdirs[i]+File.separator+modules[j]+File.separator+localizableFile);
185                     // System.out.println("Localizable file is: "+f.getAbsolutePath());
186

187                     if ( f.exists() ) {
188                         System.out.println("\t\tFILE exists"+topdirs[i]+File.separator+modules[j]+File.separator+localizableFile);
189                         File JavaDoc topDir = new File JavaDoc(topdirs[i]);
190                         File JavaDoc modDir = new File JavaDoc(topdirs[i]+File.separator+modules[j]);
191
192                         // moved getGeneratedFiles from here to only getGeneratedFiles
193
// if there are localizableFiles.
194

195                         localizableFiles = getLocalizableFiles(topDir, modules[j]);
196                         if (localizableFiles == null ) {
197                             if (DEBUG) {
198                                 System.out.println("\t\tNo Localizable Files for this module."+topDir+File.separator+modules[j]);
199                             }
200                         } else {
201
202                             //don't look for the generated Files if there are no localizableFiles
203
generatedFileHash = getGeneratedFiles(topDir, modules[j]);
204                             //if ( generatedFileHash == null ) { System. out.println("\t\tGENFILEHASH is null"); }
205

206                                         /* DO PRE PROCESSING
207                                                 int lastSlashIndex;
208                                                 String parentDirFullPath;
209                                                 String cacheDirFullPath;
210                                          */

211
212                             for (int k=0; k<localizableFiles.length; k++) {
213
214                                 // DO SOME PRE-PROCESSING HERE. CACHE DIR REACTION (don't check for existance of same dir over & over again).
215

216
217                                 int lastSlashIndex = localizableFiles[k].lastIndexOf(File.separator);
218                                 String JavaDoc parentDirFullPath = localizableFiles[k].substring(0, lastSlashIndex);
219
220                                 // Check that the CVS/ dir exists.
221
// If it does not, assume we are dealing with a generated dir
222
// which does not need to be examined by me.
223
if ( ! new File JavaDoc(parentDirFullPath+"/CVS").exists() ) {
224                                     //System.out.println("CVSDIR doesn't exist ["+parentDirFullPath+"/CVS ]");
225
// skip to the end of this loop
226
//HEY! there must be a cleaner way!!
227
System.out.println("This dir is a generated dir with no CVS dir "+parentDirFullPath);
228
229                                 } else {
230
231                                     // PRINT TO "allfiles" list.
232
boolean success = printToAllFile(topdirs[i], modules[j], localizableFiles);
233                                     if (! success) {
234                                         System.out.println("ERROR: Print to All File in "+topdirs[i]+", "+modules[j]+"failed.");
235
236                                     }
237
238                                     ce = cvsEntriesCache.get(parentDirFullPath);
239
240                                     if ( ce == null ) {
241                                         ce = new CvsEntries(parentDirFullPath); //passing parentDirFullPath
242
cvsEntriesCache.put(parentDirFullPath, ce);
243                                     }
244
245                                     if ( generatedFileHash == null ) {
246                                         generatedFileHash=new Hashtable JavaDoc<String JavaDoc, String JavaDoc>();
247                                     }
248
249
250                                     String JavaDoc localizableFileOnly = localizableFiles[k].substring(localizableFiles[k].lastIndexOf(File.separator)+1);
251                                     if (localizableFileOnly == null) { System.out.println("NULL LOCALIZABLE FILE"); }
252
253                                     String JavaDoc ceRev = ce.getRevnoByFileName(localizableFileOnly);
254
255                                     if ( ceRev == null ) {
256                                         // If this file is NOT in ce (doesn't exist in CVS/Entries)
257
// there is something wrong with the build working directory.
258
// We will collect these file names & report at the end.
259

260                                         //Maybe we don't want to add them. THe build generates lots of files which aren't in CVS.
261
// error.add(localizableFiles[k]);
262

263                                     } else {
264                                         // System.out.println("CEREV: "+ceRev);
265
// compare revnos
266

267                                         String JavaDoc genRev = generatedFileHash.get(localizableFiles[k]);
268                                         // if (DEBUG) System.out.println("GENREV "+genRev + "\tFN: "+localizableFiles[k]);
269

270                                         if ( genRev == null || ! ceRev.equals(genRev)) {
271                                             //Update changed fileHash
272
changed.put(localizableFiles[k], ceRev);
273
274
275                                             //Update generatedFileHash
276
generatedFileHash.put(localizableFiles[k], ceRev);
277
278
279                                             //if (DEBUG) System.out.println("I got this far, but there was nothing CHANGED: "+localizableFiles[k]);
280
}
281                                     }
282                                 }
283
284                             } //for localizable files
285

286                             // IN HERE PRINT TO GENERATED FILE.
287
boolean success = printToFile(topdirs[i], modules[j]);
288
289
290                             if (! success) {
291                                 System.out.println("ERROR: Print to File in "+topdirs[i]+", "+modules[j]+"failed.");
292                             }
293
294                             // toDir should be build/topDir
295
// baseDir should be fullpathtoTopDir
296
// if (DEBUG) System.out.println("BUILDDIR "+buildDir);
297
File JavaDoc tDir = new File JavaDoc(buildDir+File.separator+topdirs[i]);
298                             int lio = topdirs[i].lastIndexOf(File.separator);
299                             String JavaDoc shortTopdir = topdirs[i].substring(lio+1);
300
301
302                             // make a tar no matter what.
303
// At a minimum it will have
304
// file module.l10n.list.all.
305
// THEN delete files.
306

307                             mkTars(topdirs[i]+File.separator, buildDir+File.separator+shortTopdir+File.separator+modules[j]+".tar", topdirs[i]+File.separator+modules[j]+File.separator+modules[j]+"."+changedFile, modules[j]);
308                             // if (! changed.isEmpty() ) {
309
Delete delete = (Delete)p.createTask("delete");
310                             FileSet fs = new FileSet();
311                             fs.setDir(new File JavaDoc(topdirs[i]+File.separator+modules[j]));
312                             String JavaDoc includes = modules[j]+"."+generatedFile+","+ modules[j]+"."+changedFile+","+ modules[j]+"."+allFile;
313                             fs.setIncludes(includes);
314                             delete.addFileset(fs);
315
316                             delete.setVerbose(true);
317                             delete.execute();
318                             //}
319

320
321                             // Clean up before moving on.
322

323                             // if (DEBUG) System.out.println("CLEARING "+topdirs[i] + " " + modules[j]);
324
generatedFileHash.clear();
325                             changed.clear();
326                             error.clear();
327
328                         } // if File: topDirs[i]/modules[j]/localizableFile exists
329
} // if localizableFiles is not null
330
} // if module isn't null
331
} //for module
332
} //for topdirs
333

334         // Tar everything
335
if (DEBUG) System.out.println("ABOUT TO MAKE THE BIG TAR: "+distDir+"/l10n-"+buildNumber+".tar.gz");
336
337         // Check to make sure that the build dir exists,
338
// & that there are little tars to tar... or we get a "basedir dne"
339
// exception.
340

341         File JavaDoc bd = new File JavaDoc(buildDir);
342         if (bd.exists()) {
343             File JavaDoc tarFile = new File JavaDoc(buildDir+"/l10n-"+buildNumber+".tar");
344
345             Tar tar = (Tar)p.createTask("tar");
346             tar.setBasedir(bd);
347             tar.setDestFile(tarFile);
348             Tar.TarLongFileMode mode = new Tar.TarLongFileMode();
349             mode.setValue(Tar.TarLongFileMode.GNU);
350             tar.setLongfile(mode);
351             ////// automatically includes all in the basedir
352
tar.execute();
353
354             if ( tarFile.exists() ) {
355                 GZip gzip = (GZip)p.createTask("gzip");
356                 gzip.setSrc(new File JavaDoc(buildDir+"/l10n-"+buildNumber+".tar"));
357                 gzip.setZipfile(new File JavaDoc(distDir+"/l10n-"+buildNumber+".tar.gz"));
358                 gzip.execute();
359             } else {
360                 System.out.println("NO tar file, can't gzip"+buildDir+"/l10n-"+buildNumber+".tar");
361             }
362         } else {
363             System.out.println("No files in builddir. No kit to build");
364         }
365
366
367
368
369     } // execute()
370

371     public void mkTars(String JavaDoc srcDir, String JavaDoc fullTarfilePath, String JavaDoc fullIncludesFilePath, String JavaDoc module) {
372         //String td = srcDir.substring(srcDir.lastIndexOf(File.separator)+1);
373
if (DEBUG) {
374             // System.out.println("SRCDIR = "+srcDir);
375
//System.out.println("FULL TARFILE PATH = "+fullTarfilePath);
376
}
377
378         File JavaDoc incBaseDir = new File JavaDoc(srcDir);
379         Tar tar = (Tar)p.createTask("tar");
380         tar.setBasedir(new File JavaDoc(srcDir));
381         tar.setDestFile(new File JavaDoc(fullTarfilePath));
382
383         File JavaDoc incFile = new File JavaDoc(fullIncludesFilePath);
384
385         if (incFile.exists() ) {
386             tar.setIncludes(module+File.separator+module+"."+allFile);
387             tar.setIncludes(module+File.separator+module+"."+generatedFile);
388             tar.setIncludes(module+File.separator+module+"."+changedFile);
389             tar.setIncludesfile(incFile);
390             Tar.TarLongFileMode mode = new Tar.TarLongFileMode();
391             mode.setValue(Tar.TarLongFileMode.GNU);
392             tar.setLongfile(mode);
393             tar.execute();
394         }
395
396     }
397
398     public boolean printToAllFile(String JavaDoc fullTopDir, String JavaDoc module, String JavaDoc[] localizableFiles) {
399         try {
400             int lastSlashIndex = fullTopDir.lastIndexOf(File.separator);
401             String JavaDoc topDir= fullTopDir.substring(lastSlashIndex+1);
402
403             File JavaDoc f = new File JavaDoc(buildDir+ File.separator +topDir );
404             f.mkdirs();
405
406             FileWriter JavaDoc allWrite = new FileWriter JavaDoc(fullTopDir+File.separator+module+File.separator+module+"."+allFile);
407
408             if ( localizableFiles != null ) {
409                 for (int i=0; i<localizableFiles.length; i++) {
410                     int lio = localizableFiles[i].lastIndexOf(fullTopDir);
411                     if (lio >= 0) {
412                         String JavaDoc moduleFileName= localizableFiles[i].substring(lio+fullTopDir.length()+1);
413                         allWrite.write(moduleFileName+"\n");
414                     } else {
415                         System.out.println("Error: NO TOPDIR HERE: "+ localizableFiles[i]+ " FTD: "+fullTopDir+" LIO "+lio);
416                     }
417
418                 }
419             }
420             allWrite.close();
421
422         } catch (IOException JavaDoc ioe) {
423             System.out.println("IOException"+ioe);
424             return false;
425         }
426         return true;
427
428     }
429     public boolean printToFile(String JavaDoc fullTopDir, String JavaDoc module) {
430
431         // if (DEBUG) System.out.println("IN printToFile FULLTOPDIR"+fullTopDir+ " MODULE" + module);
432

433         try {
434
435             int lastSlashIndex = fullTopDir.lastIndexOf(File.separator);
436             String JavaDoc topDir= fullTopDir.substring(lastSlashIndex+1);
437
438                 /* No need to mkdirs now - printToAllFile is making them.
439                         File f = new File(buildDir+ File.separator +topDir );
440                         f.mkdirs();
441                  */

442
443             FileWriter JavaDoc genWrite = new FileWriter JavaDoc(fullTopDir+File.separator+module+File.separator+module+"."+generatedFile);
444             FileWriter JavaDoc changedWrite = new FileWriter JavaDoc(fullTopDir+File.separator+module+File.separator+module+"."+changedFile);
445
446
447             if ( generatedFileHash == null ) {
448                 generatedFileHash = new Hashtable JavaDoc<String JavaDoc, String JavaDoc>();
449             } else {
450
451                 for (Enumeration JavaDoc<String JavaDoc> g = generatedFileHash.keys() ; g.hasMoreElements() ;) {
452                     String JavaDoc genFileKey = g.nextElement();
453                     int lioTopDir = genFileKey.lastIndexOf(topDir);
454                     String JavaDoc moduleFileName = genFileKey.substring(lioTopDir+topDir.length()+1) ;
455
456                     genWrite.write(moduleFileName+"\t"+generatedFileHash.get(genFileKey)+"\n");
457                 }
458
459                 // To make sure the changeFile & generatedFile appear in the tar,
460
// make them the first lines in the file.
461
for (Enumeration JavaDoc<String JavaDoc> c = changed.keys() ; c.hasMoreElements() ;) {
462                     String JavaDoc changedFileKey = c.nextElement();
463
464                     int lio = changedFileKey.lastIndexOf(topDir+File.separator+module);
465                     String JavaDoc moduleFileName;
466                     if (lio >= 0) {
467
468                         moduleFileName=changedFileKey.substring(changedFileKey.lastIndexOf(topDir+File.separator+module)+topDir.length()+1);
469                         changedWrite.write(moduleFileName+"\n");
470                     } else {
471                         // If we get here, the cache is probobly not really being cleared.
472

473                         //The cache is not being cleared
474
// OR we have wild-card characters
475
System.out.println("WARNING: L10n.list file error. Each item in your list should reference the current module. If this is a global l10n file used over several modules use the property ${l10n-module} as a place-holder. This error occurred in "+module+".");
476                         // Contact program administrator.\r\t"+ changedFileKey+ "\r\tTD "+topDir+File.separator+module +" LIO "+lio);
477
}
478
479                     //changedWrite.write(changedFileKey+"\n");
480
//Changed should have a list of fullpath in order to do copy
481
}
482             }
483
484             if (! error.isEmpty() ) {
485                 FileWriter JavaDoc errorWrite = new FileWriter JavaDoc(buildDir+File.separator+"l10n-errors.txt", true);
486                 for (Enumeration JavaDoc e = error.elements(); e.hasMoreElements();) {
487                     String JavaDoc ee = (String JavaDoc)e.nextElement();
488                     errorWrite.write(ee+"\n");
489                     System.out.println("Error: "+ee);
490                 }
491                 errorWrite.close();
492             }
493
494
495             genWrite.close();
496             changedWrite.close();
497
498
499         } catch (IOException JavaDoc ioe) {
500             System.out.println("IOException printToFile()"+ioe);
501             return false;
502         }
503         return true;
504     }
505
506     /** You can use this function independently of "execute()", but
507      * you have to set these attributes: localizableFile,
508      * globalFile (if "read global" is used in any l10n.list
509      * files), excludePattern (if desired), includePattern (if
510      * desired)
511      */

512     public String JavaDoc[] getLocalizableFiles(File JavaDoc topRoot, String JavaDoc module) {
513         String JavaDoc[] lfs = null;
514         StringBuffer JavaDoc[] sbholder=new StringBuffer JavaDoc[2];
515         StringBuffer JavaDoc sbi= new StringBuffer JavaDoc();
516         StringBuffer JavaDoc sbe = new StringBuffer JavaDoc();
517         String JavaDoc includeS="";
518         String JavaDoc excludeS="";
519         // if (DEBUG) System.out.println("\t\tIN getLocalizableFiles(File "+topRoot.getName()+", " + module+")");
520

521         if( fullPropHash == null) {
522             p = getProject() ;
523             @SuppressWarnings JavaDoc("unchecked")
524             Hashtable JavaDoc<String JavaDoc,String JavaDoc> props = p.getProperties();
525             fullPropHash = props;
526         }
527         fullPropHash.put("l10n-module", module);
528
529         try {
530             File JavaDoc includes = new File JavaDoc(topRoot.getCanonicalPath() + File.separator + module + File.separator + localizableFile);
531             if ( ! includes.exists() || includes.length() <= 0 ) {
532                 //if (DEBUG) System.out.println("FILE IS too short to mess with "+ module);
533
return lfs;
534             }
535
536             try {
537                 sbholder = processListFile(includes,module);
538             } catch (java.io.IOException JavaDoc ioe) {
539                 System.out.println("Error processing file. "+ioe);
540             }
541
542             if (sbholder != null) {
543                 sbi = sbholder[0];
544                 sbe = sbholder[1];
545
546                 sbe.append(" "+excludePattern);
547                 sbi.append(" "+includePattern);
548
549                 if (DEBUG) {
550                     System.out.println("INC "+sbi.toString());
551                     System.out.println("EXC "+sbe.toString());
552                 }
553             }
554
555             this.fileset = new FileSet();
556
557             // this.setIncludesfile(includes);
558
if ( sbi !=null) {
559                 this.setIncludes(sbi.toString());
560                 //changed to accomodate excludes in file
561
}
562
563             if (sbe != null ) {
564                 this.setExcludes(sbe.toString());
565                 // Sets the set of exclude patterns.
566
// Patterns may be separated by a comma or a space.
567
}
568
569             DirectoryScanner ds = this.getDirectoryScanner(topRoot);
570
571             ds.scan();
572             lfs = ds.getIncludedFiles();
573
574             for (int k=0; k<lfs.length; k++) {
575                 // if (DEBUG) System.out.println("\t\t\tLFS "+lfs[k]);
576
lfs[k] = topRoot+File.separator+lfs[k].trim();
577                 //lfs[k] = topRoot+File.separator+lfs[k];
578
}
579
580             // if (DEBUG) System.out.println("THERE ARE "+lfs.length + " FILES in INCL FILES");
581
} catch(java.io.IOException JavaDoc e) {
582             System.out.println(e.getMessage());
583         }
584         return lfs;
585     }
586
587     public Hashtable JavaDoc<String JavaDoc, String JavaDoc> getGeneratedFiles(File JavaDoc topDir, String JavaDoc mod) {
588         // NOTE: This method will return 'null' 100% of the time if there
589
// are no l10n.list.generated files.
590
// At this writing, this functionality is not used.
591
// EG 1/03
592

593         Hashtable JavaDoc<String JavaDoc, String JavaDoc> h=new Hashtable JavaDoc<String JavaDoc, String JavaDoc>();
594         // Read generated File
595
try {
596
597             String JavaDoc topDirFullPath = topDir.getCanonicalPath();
598             // if (DEBUG) System.out.println("\t\ttopDirFullPath: "+topDirFullPath);
599

600             BufferedReader JavaDoc inBuff = new BufferedReader JavaDoc(new FileReader JavaDoc(new File JavaDoc(topDir+File.separator+mod,generatedFile)));
601             boolean eof = false;
602             while (! eof) {
603                 String JavaDoc line = inBuff.readLine();
604                 if (line==null) {
605                     eof = true;
606                 } else {
607                     //System.out.println("LL "+ line);
608

609                     int tabIndex = line.indexOf("\t");
610                     if (tabIndex > 0) {
611                         String JavaDoc filename = line.substring(0,tabIndex);
612                         String JavaDoc revision = line.substring(tabIndex+1);
613                         h.put(topDirFullPath+File.separator+filename, revision);
614                     } else {
615                         System.out.println("There's no tab in this line"+"["+line+"]");
616
617                     }
618
619                 }
620
621             } //while
622
} catch(java.io.FileNotFoundException JavaDoc e) {
623             // Warning: Generated File: "+generatedFile+" in "+
624
// topDir+File.separator+mod+" not found.
625
// Adding all files to changed list."
626
return(null);
627         } catch(java.io.IOException JavaDoc e) {
628             System.out.println("IOException "+ e);
629         }
630
631         return h;
632     }
633
634     // Accessor Methods
635

636     public void setTopdirs(String JavaDoc s) {
637         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(s);
638         String JavaDoc[] tops = new String JavaDoc[st.countTokens()];
639         int i=0;
640         while (st.hasMoreTokens()) {
641             tops[i++]=st.nextToken();
642         }
643
644         if (false) {
645             for (int j=0; j<tops.length; j++) {
646                 System.out.println("TOPS "+tops[j]);
647             }
648         }
649
650         this.topdirs = tops;
651
652     }
653     public void setModules(String JavaDoc s) {
654         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(s,",");
655         HashSet JavaDoc<String JavaDoc> modSet = new HashSet JavaDoc<String JavaDoc>(); //This will guarantee that there will be no duplications
656
String JavaDoc fullMod = null;
657
658         while (st.hasMoreTokens()) {
659             fullMod=st.nextToken().trim();;
660
661             // if (DEBUG) System.out.println("ITEM IN MODLIST: "+fullMod);
662

663             int index = fullMod.indexOf(File.separator);
664             if (index >= 0) {
665                 //Check that the mod doesn't have a slash
666
// (if it does, keep only what is to the left of the slash)
667
fullMod=fullMod.substring(0,index);
668
669                 // if (DEBUG) System.out.println("CHANGED FULLMOD & it's NOW "+fullMod);
670
}
671             modSet.add( fullMod );
672         }
673         this.modules = new String JavaDoc[ modSet.size() ];
674         Iterator JavaDoc<String JavaDoc> it = modSet.iterator();
675
676         int i=0;
677         while( it.hasNext() )
678             this.modules[i++] = it.next();
679
680     }
681
682     public StringBuffer JavaDoc[] processListFile(File JavaDoc inc,String JavaDoc module) throws IOException JavaDoc {
683         System.out.println("Reading list file: "+inc.toString());
684         StringBuffer JavaDoc[] sbholder=new StringBuffer JavaDoc[2];
685         StringBuffer JavaDoc sbi = new StringBuffer JavaDoc();
686         StringBuffer JavaDoc sbe = new StringBuffer JavaDoc();
687
688
689         if(inc.exists() && inc.length() >0) {
690             //Read Includes File.
691
BufferedReader JavaDoc br = new BufferedReader JavaDoc(new FileReader JavaDoc(inc));
692             String JavaDoc line;
693             while((line=br.readLine()) != null && line.indexOf("#") <0) {
694                 boolean skipit=false;
695                 // For each line check if there are any properties which
696
// should be interpreted first.
697
while (line.indexOf("${") >= 0 && skipit == false) {
698
699                     String JavaDoc propertyName;
700                     String JavaDoc value="";
701                     String JavaDoc res="";
702                     String JavaDoc pre="";
703
704                     propertyName=line.substring(line.indexOf("${")+2,line.indexOf("}"));
705
706                     if (fullPropHash.containsKey(propertyName)) {
707
708                         value=fullPropHash.get(propertyName);
709                         res = line.substring(line.indexOf("}")+1);
710                         pre= line.substring(0,line.indexOf("{")-1);
711                         line=pre+value+res;
712                         // System.out.println("LINE is now "+line);
713
} else {
714                         System.out.println("Uninterpretable property in l10n file:"+inc.toString()+". "+propertyName+" Interpreting the entire line literally.");
715                         skipit=true;
716                     }
717                 }
718
719                 if (line.indexOf("exclude") >= 0) {
720                     sbe.append(" "+line.substring("exclude".length()+1));
721                 } else if (line.indexOf("read global") >= 0) {
722
723                     if (globalFile != null && ! globalFile.equals("")) {
724                         if (readGlobalFile==true) {
725                             System.out.println("Already read it");
726                             //We did it once, don't do it again.
727
// just copy in the values.
728
sbi.append(" "+globalsbholder[0]);
729                             sbe.append(" "+globalsbholder[1]);
730                         } else {
731                             globalsbholder[0]= new StringBuffer JavaDoc();
732                             globalsbholder[1]= new StringBuffer JavaDoc();
733                             StringBuffer JavaDoc[] globalarray = processListFile(new File JavaDoc(globalFile),module);
734                             if (globalarray[0] != null) {
735                                 sbi.append(" "+globalarray[0]);
736                                 globalsbholder[0].append(" "+globalarray[0]);
737                                 //put it where we can get it back.
738
}
739                             if (globalarray[1] != null) {
740                                 sbe.append(" "+globalarray[1]);
741                                 globalsbholder[1].append(" "+globalarray[1]);
742                                 //put it where we can get it back.
743
}
744                         }
745                         readGlobalFile = true ;
746                     }
747                 } else if( line.trim().startsWith( "read")) {
748                     String JavaDoc l = line.trim() ;
749                     l = l.substring( 4) ;
750                     l = l.trim() ;
751                     StringBuffer JavaDoc[] sbarr = processListFile( new File JavaDoc( l),
752                             module) ;
753                     sbi.append( " " + sbarr[ 0]) ;
754                     sbe.append( " " + sbarr[ 1]) ;
755                 } else {
756                     sbi.append(" "+line);
757                 }
758                 // System.out.println("GLOBAL"+line.indexOf("read global")+" EXCLUDES "+line.indexOf("exclude")+ "FILE"+inc.toString());
759
} //while
760
br.close();
761         }
762         sbholder[0]=sbi;
763         sbholder[1]=sbe;
764         return sbholder;
765     }
766
767     public void setDistDir(String JavaDoc s) {
768         // if (DEBUG) System.out.println("DIST DIR SHOULD BE: "+s);
769
this.distDir=s;
770     }
771     public void setBuildDir(String JavaDoc s) {
772         this.buildDir=s;
773     }
774     public void setDebug(boolean s) {
775         this.DEBUG=s;
776     }
777     public void setLocalizableFile(String JavaDoc s) {
778         this.localizableFile=s;
779     }
780     public void setExcludePattern(String JavaDoc s) {
781         this.excludePattern=s;
782     }
783     public void setIncludePattern(String JavaDoc s) {
784         this.includePattern=s;
785     }
786
787     public void setBuildNumber(String JavaDoc s) {
788         this.buildNumber=s;
789     }
790     public void setGeneratedFile(String JavaDoc s) {
791         this.generatedFile=s;
792     }
793     public void setChangedFile(String JavaDoc s) {
794         this.changedFile=s;
795     }
796     public void setGlobalFile(String JavaDoc s) {
797         this.globalFile=s;
798     }
799 }
800
Popular Tags