1212*/
1313package org .pentaho .di .ui .i18n ;
1414
15- import java .io .BufferedReader ;
16- import java .io .IOException ;
17- import java .io .InputStreamReader ;
18- import java .util .ArrayList ;
19- import java .util .Collections ;
20- import java .util .Hashtable ;
21- import java .util .List ;
22- import java .util .Locale ;
23- import java .util .Map ;
24-
25- import org .apache .commons .vfs .FileObject ;
26- import org .pentaho .di .core .Const ;
27- import org .pentaho .di .core .exception .KettleXMLException ;
28- import org .pentaho .di .core .fileinput .FileInputList ;
29- import org .pentaho .di .core .logging .LogWriter ;
30- import org .pentaho .di .core .variables .Variables ;
31- import org .pentaho .di .core .vfs .KettleVFS ;
32- import org .pentaho .di .core .xml .XMLHandler ;
33- import org .pentaho .di .i18n .BaseMessages ;
34- import org .pentaho .di .i18n .LanguageChoice ;
35- import org .pentaho .di .ui .spoon .Spoon ;
36- import org .pentaho .di .ui .spoon .job .JobGraph ;
37- import org .w3c .dom .Document ;
38- import org .w3c .dom .Node ;
39- import org .w3c .dom .NodeList ;
15+ import java .io .BufferedReader ;
16+ import java .io .IOException ;
17+ import java .io .InputStreamReader ;
18+ import java .util .ArrayList ;
19+ import java .util .Collections ;
20+ import java .util .Hashtable ;
21+ import java .util .List ;
22+ import java .util .Locale ;
23+ import java .util .Map ;
24+
25+ import org .apache .commons .vfs .FileObject ;
26+ import org .pentaho .di .core .Const ;
27+ import org .pentaho .di .core .exception .KettleXMLException ;
28+ import org .pentaho .di .core .fileinput .FileInputList ;
29+ import org .pentaho .di .core .logging .LogWriter ;
30+ import org .pentaho .di .core .variables .Variables ;
31+ import org .pentaho .di .core .vfs .KettleVFS ;
32+ import org .pentaho .di .core .xml .XMLHandler ;
33+ import org .pentaho .di .i18n .BaseMessages ;
34+ import org .pentaho .di .i18n .LanguageChoice ;
35+ import org .pentaho .di .ui .spoon .Spoon ;
36+ import org .pentaho .di .ui .spoon .job .JobGraph ;
37+ import org .w3c .dom .Document ;
38+ import org .w3c .dom .Node ;
39+ import org .w3c .dom .NodeList ;
4040
4141/**
4242 * This class takes care of crawling through the source code
@@ -50,7 +50,7 @@ public class MessagesSourceCrawler {
5050 /**
5151 * The source directories to crawl through
5252 */
53- private String [] sourceDirectories ;
53+ private List < String > sourceDirectories ;
5454
5555 /**
5656 * The directories to search for XUL files in
@@ -66,31 +66,35 @@ public class MessagesSourceCrawler {
6666 /**
6767 * The file names to avoid (base names)
6868 */
69- private String [] filesToAvoid ;
69+ private List <String > filesToAvoid ;
70+
71+ private String singleMessagesFile ;
7072
7173
7274 /**
73- * @param sourceDirectories The source directories to crawl through
75+ * @param sourceDirectories The source directories to crawl through
76+ * @param singleMessagesFile the messages file if there is only one, otherwise: null
7477 */
75- public MessagesSourceCrawler (String [] sourceDirectories ) {
78+ public MessagesSourceCrawler (List < String > sourceDirectories , String singleMessagesFile ) {
7679 super ();
77- this .sourceDirectories = sourceDirectories ;
80+ this .sourceDirectories = sourceDirectories ;
81+ this .singleMessagesFile = singleMessagesFile ;
7882 this .occurrences = new ArrayList <KeyOccurrence >();
79- this .filesToAvoid = new String [] {} ;
83+ this .filesToAvoid = new ArrayList < String >() ;
8084 this .xulDirectories = new String [] {};
8185 }
8286
8387 /**
8488 * @return The source directories to crawl through
8589 */
86- public String [] getSourceDirectories () {
90+ public List < String > getSourceDirectories () {
8791 return sourceDirectories ;
8892 }
8993
9094 /**
9195 * @param sourceDirectories The source directories to crawl through
9296 */
93- public void setSourceDirectories (String [] sourceDirectories ) {
97+ public void setSourceDirectories (List < String > sourceDirectories ) {
9498 this .sourceDirectories = sourceDirectories ;
9599 }
96100
@@ -110,16 +114,16 @@ public void setOccurrences(List<KeyOccurrence> occurrences) {
110114 }
111115
112116 /**
113- * @return the filesToAvoid
117+ * @return the files to avoid
114118 */
115- public String [] getFilesToAvoid () {
119+ public List < String > getFilesToAvoid () {
116120 return filesToAvoid ;
117121 }
118122
119123 /**
120- * @param filesToAvoid the filesToAvoid to set
124+ * @param filesToAvoid the files to avoid
121125 */
122- public void setFilesToAvoid (String [] filesToAvoid ) {
126+ public void setFilesToAvoid (List < String > filesToAvoid ) {
123127 this .filesToAvoid = filesToAvoid ;
124128 }
125129
@@ -140,17 +144,19 @@ public void addKeyOccurrence(KeyOccurrence occ) {
140144 }
141145 }
142146
143- public void crawl () throws IOException {
144- String [] masks = new String [sourceDirectories .length ];
145- String [] req = new String [sourceDirectories .length ];
146- boolean [] subdirs = new boolean [sourceDirectories .length ];
147+ public void crawl () throws IOException {
148+ String [] dirs = new String [sourceDirectories .size ()];
149+ String [] masks = new String [sourceDirectories .size ()];
150+ String [] req = new String [sourceDirectories .size ()];
151+ boolean [] subdirs = new boolean [sourceDirectories .size ()];
147152
148- for (int i =0 ;i <masks .length ;i ++) {
153+ for (int i =0 ;i <masks .length ;i ++) {
154+ dirs [i ] = sourceDirectories .get (i );
149155 masks [i ] = ".*\\ .java$" ;
150156 req [i ] = "N" ;
151157 subdirs [i ] = true ;
152158 }
153- FileInputList fileInputList = FileInputList .createFileList (new Variables (), sourceDirectories , masks , req , subdirs );
159+ FileInputList fileInputList = FileInputList .createFileList (new Variables (), dirs , masks , req , subdirs );
154160
155161 /**
156162 * We don't want the Messages.java files, there is nothing in there for us.
@@ -251,7 +257,7 @@ public void lookForOccurrencesInFile(FileObject fileObject) throws IOException {
251257 //
252258 // "import org.pentaho.di.trans.steps.sortedmerge.Messages;"
253259 //
254- if (line .matches ("^[ \t ]*import [a-z\\ ._ ]*\\ .Messages;[ \t ]*$" )) {
260+ if (line .matches ("^[ \t ]*import [a-z\\ ._0-9 ]*\\ .Messages;[ \t ]*$" )) {
255261 int beginIndex = line .indexOf ("org.pentaho." );
256262 int endIndex = line .indexOf (".Messages;" );
257263 messagesPackage = line .substring (beginIndex , endIndex ); // if there is any specified, we take this one.
@@ -382,15 +388,28 @@ public List<KeyOccurrence> getOccurrencesForPackage(String messagesPackage) {
382388 return list ;
383389 }
384390
385- public static void main (String [] args ) throws IOException {
386- MessagesSourceCrawler crawler = new MessagesSourceCrawler (new String [] { "src" , "src-ui" , } );
387- crawler .setFilesToAvoid (
388- new String [] {
389- "MessagesSourceCrawler.java" , "KeyOccurence.java" , "TransLator.java" ,
390- "MenuHelper.java" , "Messages.java" , "XulMessages.java" ,
391- "AnnotatedStepsConfigManager.java" , "AnnotatedJobConfigManager.java" ,
392- "JobEntryValidatorUtils.java" , "Const.java" , "XulHelper.java" ,
393- });
391+ public static void main (String [] args ) throws IOException {
392+ List <String > directories = new ArrayList <String >();
393+ directories .add ("src-core" );
394+ directories .add ("src" );
395+ directories .add ("src-ui" );
396+
397+ List <String > filesToAvoid = new ArrayList <String >();
398+ filesToAvoid .add ("MessagesSourceCrawler.java" );
399+ filesToAvoid .add ("KeyOccurence.java" );
400+ filesToAvoid .add ("TransLator.java" );
401+ filesToAvoid .add ("MenuHelper.java" );
402+ filesToAvoid .add ("Messages.java" );
403+ filesToAvoid .add ("XulMessages.java" );
404+ filesToAvoid .add ("AnnotatedStepsConfigManager.java" );
405+ filesToAvoid .add ("AnnotatedJobConfigManager.java" );
406+ filesToAvoid .add ("JobEntryValidatorUtils.java" );
407+ filesToAvoid .add ("Const.java" );
408+ filesToAvoid .add ("XulHelper.java" );
409+
410+
411+ MessagesSourceCrawler crawler = new MessagesSourceCrawler ( directories , null );
412+ crawler .setFilesToAvoid (filesToAvoid );
394413 crawler .crawl ();
395414 int mis =0 ;
396415 LanguageChoice .getInstance ().setDefaultLocale (Locale .US );
@@ -434,6 +453,20 @@ public KeyOccurrence getKeyOccurrence(String key, String selectedMessagesPackage
434453 }
435454 }
436455 return null ;
456+ }
457+
458+ /**
459+ * @return the singleMessagesFile
460+ */
461+ public String getSingleMessagesFile () {
462+ return singleMessagesFile ;
463+ }
464+
465+ /**
466+ * @param singleMessagesFile the singleMessagesFile to set
467+ */
468+ public void setSingleMessagesFile (String singleMessagesFile ) {
469+ this .singleMessagesFile = singleMessagesFile ;
437470 }
438471
439472}
0 commit comments