KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Dec 07, 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.BufferedReader JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.InputStreamReader JavaDoc;
23
24 import org.apache.maven.plugin.AbstractMojo;
25
26 /**
27  * Generates JSDoc (to be included in the website).
28  *
29  * @goal generateJsdoc
30  * @description Generates JSDoc (to be included in the website).
31  * @author jonni
32  * @version $Id$
33  */

34 public final class JsdocGenerator extends AbstractMojo {
35   //////////////////////////////////////
36
////////// Maven parameters //////////
37
//////////////////////////////////////
38

39   /**
40    * The directory containing the JavaScript source files.
41    * @parameter
42    * @required
43    */

44   private String JavaDoc sourceDir;
45   /**
46    * The directory to contained generated HTML documents.
47    * @parameter
48    * @required
49    */

50   private String JavaDoc outputDir;
51
52
53   ////////////////////////////////////
54
////////// Action Methods //////////
55
////////////////////////////////////
56

57   public void execute() {
58     try {
59       String JavaDoc jsdocScript = readJsdocScriptFromUserInput();
60
61       if (userWantsToRunJsdoc(jsdocScript)) {
62         String JavaDoc command =
63             "perl " +
64             jsdocScript +
65             " -r " + this.sourceDir +
66             " -d " + this.outputDir;
67         getLog().info("Running " + command);
68
69         Runtime.getRuntime().exec(command);
70       }
71       else {
72         getLog().info("JSDoc does not run.");
73       }
74     }
75     catch (Exception JavaDoc e) {
76       // Don't fail on any error.
77
getLog().error(e);
78     }
79   }
80
81   private String JavaDoc readJsdocScriptFromUserInput() throws IOException JavaDoc {
82     getLog().info("JSDoc script to execute [JSDoc won't run if not supplied]: ");
83     BufferedReader JavaDoc input = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(System.in));
84
85     return input.readLine();
86   }
87
88   private boolean userWantsToRunJsdoc(String JavaDoc jsdocScript) {
89     return (jsdocScript.trim().length() > 0);
90   }
91
92
93   ////////////////////////////////////
94
////////// Static Methods //////////
95
////////////////////////////////////
96

97   public static void main(String JavaDoc args[]) {
98     if (args.length != 2) {
99       printUsage();
100     }
101
102     JsdocGenerator generator = new JsdocGenerator();
103     generator.sourceDir = args[0];
104     generator.outputDir = args[1];
105     generator.execute();
106   }
107
108   private static void printUsage() {
109     System.err.println("Usage: PROGRAM JS_SRC_DIR JSDOC_OUTPUT_DIR");
110     System.exit(1);
111   }
112 }
113
Popular Tags