KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > build > MissingBeanInfoDetector


1 /**
2  * Sep 05, 2006
3  *
4  * Copyright 2004 uitags
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package net.sf.uitags.build;
19
20 import java.io.File JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import net.sf.uitags.build.TldUtils.Tag;
25
26 import org.apache.maven.plugin.AbstractMojo;
27 import org.apache.maven.plugin.MojoFailureException;
28 import org.w3c.dom.Document JavaDoc;
29
30 /**
31  * @goal detectMissingBeanInfo
32  * @description Detects missing bean info classes.
33  * @author hgani
34  * @version $Id$
35  */

36 public final class MissingBeanInfoDetector extends AbstractMojo {
37   //////////////////////////////////////
38
////////// Maven parameters //////////
39
//////////////////////////////////////
40

41   /**
42    * The name of the TLD file containing the tags that require bean info.
43    * @parameter
44    * @required
45    */

46   private String JavaDoc tldFile;
47   /**
48    * The directory containing the tag bean info source files.
49    * @parameter
50    * @required
51    */

52   private String JavaDoc sourceDir;
53
54
55   ////////////////////////////
56
////////// Fields //////////
57
////////////////////////////
58

59   // keyed on tag names
60
private Map JavaDoc tags;
61
62
63   ////////////////////////////////////////////
64
////////// Initialization Methods //////////
65
////////////////////////////////////////////
66

67   /**
68    * Processes Maven parameters and save the results to instance variables.
69    */

70   private void init() {
71     Document JavaDoc tldDocument = TldUtils.getDocument(this.tldFile);
72     this.tags = TldUtils.extractTags(tldDocument);
73   }
74
75
76   ////////////////////////////////////
77
////////// Action Methods //////////
78
////////////////////////////////////
79

80   public void execute() throws MojoFailureException {
81     init();
82
83     boolean beanInfoMissing = false;
84     for (Iterator JavaDoc iter = this.tags.entrySet().iterator(); iter.hasNext(); ) {
85       Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iter.next();
86       if (!assertBeanInfoExists((Tag) entry.getValue())) {
87         beanInfoMissing = true;
88       }
89     }
90
91     if (beanInfoMissing) {
92       throw new MojoFailureException(
93           "At least one bean info class is missing");
94     }
95   }
96
97   private boolean assertBeanInfoExists(Tag tag) {
98     String JavaDoc tagHandler = tag.getHandlerPath();
99
100     File JavaDoc handlerFile = new File JavaDoc(
101         this.sourceDir + tagHandler + "BeanInfo.java");
102     if (!handlerFile.exists()) {
103       getLog().error("Missing bean info for: " +
104           tag.getFullyQualifiedHandlerName());
105       return false;
106     }
107     return true;
108   }
109
110   ////////////////////////////////////
111
////////// Static Methods //////////
112
////////////////////////////////////
113

114   public static void main(String JavaDoc args[]) throws MojoFailureException {
115     if (args.length != 2) {
116       printUsage();
117     }
118
119     MissingBeanInfoDetector generator = new MissingBeanInfoDetector();
120     generator.tldFile = args[0];
121     generator.sourceDir = args[1];
122     generator.execute();
123   }
124
125   private static void printUsage() {
126     System.err.println("Usage: PROGRAM TLD_FILE JAVA_SRC_DIR");
127     System.exit(1);
128   }
129 }
130
Popular Tags