View Javadoc
1 /*** 2 * ReportTask.java 3 * 4 * Project: Dependency Tool 5 * 6 * WHEN WHO WHAT 7 * 06.06.2003 pko initial public release 8 * 9 * Copyright 2003 ELCA Informatique SA 10 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland 11 * www.elca.ch 12 * 13 * This library is free software; you can redistribute it and/or 14 * modify it under the terms of the GNU Lesser General Public License 15 * as published by the Free Software Foundation; either version 2.1 of 16 * the License, or (at your option) any later version. 17 * 18 * This library is distributed in the hope that it will be useful, but 19 * WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 * Lesser General Public License for more details. 22 * 23 * You should have received a copy of the GNU Lesser General Public 24 * License along with this library; if not, write to the Free Software 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 26 * USA 27 */ 28 29 package ch.elca.dependency.ant; 30 31 import org.apache.tools.ant.BuildException; 32 import org.apache.tools.ant.Task; 33 import org.apache.tools.ant.taskdefs.Java; 34 import org.apache.tools.ant.types.Path; 35 import org.apache.tools.ant.types.Reference; 36 37 import ch.elca.dependency.DPT_CONST; 38 39 /*** 40 * Ant Task to run Dependency Tool reports out of a ant's build.xml 41 * 42 * @author Pawel Kowalski 43 * @version 1.0-beta 44 */ 45 public class ReportTask extends Task { 46 47 /*** 48 * Error message: <code>ROOT_UNSPECIFIED</code>. 49 */ 50 private static final String ROOT_UNSPECIFIED = "root attribute required"; 51 52 /*** 53 * Error message: <code>REPORT_CONFIG_UNSPECIFIED</code>. 54 */ 55 private static final String REPORT_CONFIG_UNSPECIFIED = "report config unspecified"; 56 57 /*** 58 * Classpath used for executing this Task. 59 */ 60 private Path m_classpath = null; 61 62 /*** 63 * Path to the Root of the project to be analyzed. 64 */ 65 private String m_projectRoot = null; 66 67 /*** 68 * Path to the Report config file. 69 */ 70 private String m_report = null; 71 72 /*** 73 * Filterstring to be applied before analysis of a project. 74 */ 75 private String m_filter = null; 76 77 /*** 78 * Layer filename. 79 */ 80 private String m_perspective = null; 81 82 /*** 83 * Supports classpath attribute 84 * 85 * @param classpath a <code>Path</code> value 86 */ 87 public void setClasspath(Path classpath) { 88 m_classpath = classpath; 89 } 90 91 /*** 92 * Supports classpathref attribute 93 * 94 * @param reference a <code>Reference</code> value 95 */ 96 public void setClasspathRef(Reference reference) { 97 createClasspath().setRefid(reference); 98 } 99 100 /*** 101 * Support nested classpath elements 102 * 103 * @return a <code>Path</code> value 104 */ 105 public Path createClasspath() { 106 if (m_classpath == null) { 107 m_classpath = new Path(this.getProject()); 108 } 109 return m_classpath.createPath(); 110 } 111 112 /*** 113 * Set (to be analyzed-) project root 114 * 115 * @param projectRoot a <code>String</code> value 116 */ 117 public void setRoot(String projectRoot) { 118 m_projectRoot = projectRoot; 119 } 120 121 /*** 122 * Set report config file 123 * 124 * @param report a <code>String</code> value 125 */ 126 public void setReport(String report) { 127 m_report = report; 128 } 129 130 /*** 131 * Set analyze filter 132 * 133 * @param filter a <code>String</code> value 134 */ 135 public void setFilter(String filter) { 136 m_filter = filter; 137 } 138 139 /*** 140 * Set Layer description file. 141 * 142 * @param perspective a <code>String</code> value 143 */ 144 public void setPerspective(String perspective) { 145 m_perspective = perspective; 146 } 147 148 /*** 149 * Execute this AntTask 150 * 151 * @exception BuildException if an error occurs 152 */ 153 public void execute() throws BuildException { 154 155 checkParameters(); 156 157 158 Java javaTask = (Java)getProject().createTask("java"); 159 javaTask.setTaskName(getTaskName()); 160 javaTask.setClassname(DPT_CONST.MAIN_CLASS_FQ_NAME); 161 javaTask.setClasspath(m_classpath); 162 163 // project root 164 // 165 javaTask.createArg().setValue(DPT_CONST.CMDLINE_SEPARATOR + DPT_CONST.ROOT); 166 javaTask.createArg().setValue(m_projectRoot); 167 168 // report config, either user specified or none 169 // 170 javaTask.createArg().setValue(DPT_CONST.CMDLINE_SEPARATOR + DPT_CONST.REPORT); 171 javaTask.createArg().setValue(m_report); 172 173 // filter, either user specified or none 174 // 175 if (!(m_filter == null || "".equals(m_filter))) { 176 javaTask.createArg().setValue(DPT_CONST.CMDLINE_SEPARATOR + DPT_CONST.FILTER); 177 javaTask.createArg().setValue(m_filter); 178 } 179 180 // layer, either user specified or none 181 // 182 if (!(m_perspective == null || "".equals(m_perspective))) { 183 javaTask.createArg().setValue(DPT_CONST.CMDLINE_SEPARATOR + DPT_CONST.PERSPECTIVE); 184 javaTask.createArg().setValue(m_perspective); 185 } 186 187 // execute java task 188 // 189 javaTask.setFork(true); 190 if (javaTask.executeJava() != 0) { 191 throw new BuildException("generating report failed"); 192 } 193 } 194 195 /*** 196 * Check whether required parameters were specified. 197 * 198 * @exception BuildException if an error occurs 199 */ 200 private void checkParameters() throws BuildException { 201 if (m_projectRoot == null || "".equals(m_projectRoot)) { 202 throw new BuildException(ROOT_UNSPECIFIED); 203 } 204 if (m_report == null || "".equals(m_report)) { 205 throw new BuildException(REPORT_CONFIG_UNSPECIFIED); 206 } 207 } 208 }

This page was automatically generated by Maven