View Javadoc

1   /*
2   Karma core - Core of the Karma application
3   Copyright (C) 2004  Toolforge <www.toolforge.nl>
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Lesser General Public License for more details.
14  
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  }