diff --git a/docs/manual/OptionalTasks/jdepend.html b/docs/manual/OptionalTasks/jdepend.html index 61d3893eb..54fcdf79c 100644 --- a/docs/manual/OptionalTasks/jdepend.html +++ b/docs/manual/OptionalTasks/jdepend.html @@ -71,6 +71,12 @@ href="#nested">nested elements.
If the operation is running for more than this value, the jdepend + * will be canceled. (works only when in 'fork' mode).
+ * @param value the maximum time (in milliseconds) allowed before + * declaring the test as 'timed-out' + * @see #setFork(boolean) + */ + public void setTimeout(Long value) { + timeout = value; + } - public Integer getTimeout() { - return _timeout; - } - */ + /** + * @return the timeout value + */ + public Long getTimeout() { + return timeout; + } /** * The output file name. @@ -350,6 +376,43 @@ public class JDependTask extends Task { */ private static final int ERRORS = 1; + /** + * Search for the given resource and add the directory or archive + * that contains it to the classpath. + * + *Doesn't work for archives in JDK 1.1 as the URL returned by + * getResource doesn't contain the name of the archive.
+ * + * @param resource resource that one wants to lookup + * @since Ant 1.6 + */ + private void addClasspathEntry(String resource) { + /* + * pre Ant 1.6 this method used to call getClass().getResource + * while Ant 1.6 will call ClassLoader.getResource(). + * + * The difference is that Class.getResource expects a leading + * slash for "absolute" resources and will strip it before + * delegating to ClassLoader.getResource - so we now have to + * emulate Class's behavior. + */ + if (resource.startsWith("/")) { + resource = resource.substring(1); + } else { + resource = "org/apache/tools/ant/taskdefs/optional/jdepend/" + + resource; + } + + File f = LoaderUtils.getResourceSource(getClass().getClassLoader(), + resource); + if (f != null) { + log("Found " + f.getAbsolutePath(), Project.MSG_DEBUG); + runtimeClasses.createPath().setLocation(f); + } else { + log("Couldn\'t find " + resource, Project.MSG_DEBUG); + } + } + /** * execute the task * @@ -380,7 +443,7 @@ public class JDependTask extends Task { // execute the test and get the return code int exitValue = JDependTask.ERRORS; - //boolean wasKilled = false; + boolean wasKilled = false; if (!getFork()) { exitValue = executeInVM(commandline); } else { @@ -388,21 +451,22 @@ public class JDependTask extends Task { exitValue = executeAsForked(commandline, watchdog); // null watchdog means no timeout, you'd better not check with null if (watchdog != null) { - //info will be used in later version do nothing for now - //wasKilled = watchdog.killedProcess(); + wasKilled = watchdog.killedProcess(); } } // if there is an error/failure and that it should halt, stop // everything otherwise just log a statement - boolean errorOccurred = exitValue == JDependTask.ERRORS; + boolean errorOccurred = exitValue == JDependTask.ERRORS || wasKilled; if (errorOccurred) { + String errorMessage = "JDepend FAILED" + + (wasKilled ? " - Timed out" : ""); + if (getHaltonerror()) { - throw new BuildException("JDepend failed", - getLocation()); + throw new BuildException(errorMessage, getLocation()); } else { - log("JDepend FAILED", Project.MSG_ERR); + log(errorMessage, Project.MSG_ERR); } } } @@ -540,6 +604,9 @@ public class JDependTask extends Task { // JL: comment extracted from JUnitTask (and slightly modified) public int executeAsForked(CommandlineJava commandline, ExecuteWatchdog watchdog) throws BuildException { + runtimeClasses = new Path(getProject()); + addClasspathEntry("/jdepend/textui/JDepend.class"); + // if not set, auto-create the ClassPath from the project createClasspath(); @@ -550,6 +617,24 @@ public class JDependTask extends Task { createJvmarg(commandline).setValue(getClasspath().toString()); } + if (includeRuntime) { + Vector v = Execute.getProcEnvironment(); + Enumeration e = v.elements(); + while (e.hasMoreElements()) { + String s = (String) e.nextElement(); + if (s.startsWith("CLASSPATH=")) { + commandline.createClasspath(getProject()).createPath() + .append(new Path(getProject(), + s.substring("CLASSPATH=".length() + ))); + } + } + log("Implicitly adding " + runtimeClasses + " to CLASSPATH", + Project.MSG_VERBOSE); + commandline.createClasspath(getProject()).createPath() + .append(runtimeClasses); + } + if (getOutputFile() != null) { // having a space between the file and its path causes commandline // to add quotes around the argument thus making JDepend not taking @@ -620,13 +705,9 @@ public class JDependTask extends Task { * @throws BuildException in case of error */ protected ExecuteWatchdog createWatchdog() throws BuildException { - - return null; - /* - if (getTimeout() == null) { - return null; - } - return new ExecuteWatchdog(getTimeout().intValue()); - */ + if (getTimeout() == null) { + return null; + } + return new ExecuteWatchdog(getTimeout().longValue()); } } diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java new file mode 100644 index 000000000..b745474b9 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java @@ -0,0 +1,155 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "Ant" and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + *