1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.core.cmd.impl;
20
21 import nl.toolforge.karma.core.cmd.CommandDescriptor;
22 import nl.toolforge.karma.core.cmd.CommandException;
23 import nl.toolforge.karma.core.cmd.CommandResponse;
24 import nl.toolforge.karma.core.manifest.ManifestException;
25 import org.apache.tools.ant.BuildException;
26 import org.apache.tools.ant.Project;
27
28 import java.io.File;
29
30 /***
31 * Generates Javadoc API documentation for the given module.
32 *
33 * @author W.H. Schraal
34 * @author D.A. Smedes
35 * @version $Id: DocModule.java,v 1.9 2004/11/02 23:57:06 asmedes Exp $
36 */
37 public class DocModule extends AbstractBuildCommand {
38
39 private static final String JAVADOC_OUTPUT_DIR = "module.javadoc.outputdir";
40 private static final String MODULE_NAME = "module.name";
41 private static final String MODULE_STATE = "module.state";
42 private static final String MODULE_SRC = "module.src";
43
44 protected CommandResponse response = new CommandResponse();
45
46 public DocModule(CommandDescriptor descriptor) {
47 super(descriptor);
48 }
49
50 /***
51 * @throws CommandException When the module doesn't have a <code>src/java</code> or when no source files are
52 * available.
53 */
54 public void execute() throws CommandException {
55
56 super.execute();
57
58 File srcDir = getBuildEnvironment().getModuleSourceDirectory();
59
60 if (!srcDir.exists()) {
61 throw new CommandException(CommandException.NO_SRC_DIR, new Object[]{module, "src/java"});
62 }
63
64 Project project = getAntProject("doc-module.xml");
65
66 project.setProperty(JAVADOC_OUTPUT_DIR, getBuildEnvironment().getModuleJavadocDirectory().getPath());
67 project.setProperty(MODULE_NAME, module.getName());
68 project.setProperty(MODULE_STATE, getCurrentManifest().getState(module).toString());
69 project.setProperty(MODULE_SRC, srcDir.getPath());
70
71 try {
72 project.executeTarget("run");
73 } catch (BuildException b) {
74 throw new CommandException(b, CommandException.BUILD_FAILED, new Object[]{module});
75 }
76 }
77
78 public CommandResponse getCommandResponse() {
79 return response;
80 }
81
82 protected File getSourceDirectory() throws ManifestException {
83 return new File(getCurrentModule().getBaseDir(), "src/java");
84 }
85 }