| Line | Hits | Note | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * $Id: GnuplotTask.java 1011 2008-06-16 17:57:36Z amandel $ | ||
| 3 | * | ||
| 4 | * Copyright 2006, The jCoderZ.org Project. All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions are | ||
| 8 | * met: | ||
| 9 | * | ||
| 10 | * * Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * * Redistributions in binary form must reproduce the above | ||
| 13 | * copyright notice, this list of conditions and the following | ||
| 14 | * disclaimer in the documentation and/or other materials | ||
| 15 | * provided with the distribution. | ||
| 16 | * * Neither the name of the jCoderZ.org Project nor the names of | ||
| 17 | * its contributors may be used to endorse or promote products | ||
| 18 | * derived from this software without specific prior written | ||
| 19 | * permission. | ||
| 20 | * | ||
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND | ||
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS | ||
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
| 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
| 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
| 31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 32 | */ | ||
| 33 | package org.jcoderz.commons.taskdefs; | ||
| 34 | |||
| 35 | import java.io.File; | ||
| 36 | import java.io.IOException; | ||
| 37 | import java.util.Locale; | ||
| 38 | |||
| 39 | import org.apache.tools.ant.BuildException; | ||
| 40 | import org.apache.tools.ant.Project; | ||
| 41 | import org.apache.tools.ant.Task; | ||
| 42 | import org.apache.tools.ant.taskdefs.Execute; | ||
| 43 | import org.apache.tools.ant.taskdefs.LogStreamHandler; | ||
| 44 | import org.apache.tools.ant.types.Commandline; | ||
| 45 | |||
| 46 | /** | ||
| 47 | * Ant task for the 'gnuplot' command. | ||
| 48 | * | ||
| 49 | * @author Michael Griffel | ||
| 50 | */ | ||
| 51 | 0 | public class GnuplotTask | |
| 52 | extends Task | ||
| 53 | { | ||
| 54 | /** The input files. */ | ||
| 55 | private File[] mInFiles; | ||
| 56 | /** terminate ant build on error. */ | ||
| 57 | private boolean mFailOnError; | ||
| 58 | 0 | private final Commandline mCommand = new Commandline(); | |
| 59 | |||
| 60 | /** | ||
| 61 | * Sets the gnuplot input file to be processed. | ||
| 62 | * @param f the gnuplot input file (log message info). | ||
| 63 | */ | ||
| 64 | public void setIn (File f) | ||
| 65 | { | ||
| 66 | 0 | mInFiles = new File[] {f}; | |
| 67 | |||
| 68 | 0 | } | |
| 69 | |||
| 70 | /** | ||
| 71 | * Set whether we should fail on an error. | ||
| 72 | * @param b Whether we should fail on an error. | ||
| 73 | */ | ||
| 74 | public void setFailonerror (boolean b) | ||
| 75 | { | ||
| 76 | 0 | mFailOnError = b; | |
| 77 | 0 | } | |
| 78 | |||
| 79 | /** | ||
| 80 | * Execute this task. | ||
| 81 | * | ||
| 82 | * @throws BuildException An building exception occurred. | ||
| 83 | */ | ||
| 84 | public void execute () | ||
| 85 | throws BuildException | ||
| 86 | { | ||
| 87 | try | ||
| 88 | { | ||
| 89 | 0 | checkAttributes(); | |
| 90 | |||
| 91 | 0 | (1) | mCommand.setExecutable("gnuplot"); |
| 92 | |||
| 93 | 0 | for (int i = 0; i < mInFiles.length; i++) | |
| 94 | { | ||
| 95 | 0 | mCommand.createArgument().setValue(mInFiles[i].getAbsolutePath()); | |
| 96 | } | ||
| 97 | |||
| 98 | 0 | final Execute exe = new Execute(new LogStreamHandler( | |
| 99 | this, Project.MSG_VERBOSE, Project.MSG_WARN), null); | ||
| 100 | 0 | exe.setCommandline(mCommand.getCommandline()); | |
| 101 | 0 | log(mCommand.describeCommand(), Project.MSG_VERBOSE); | |
| 102 | try | ||
| 103 | { | ||
| 104 | 0 | exe.execute(); | |
| 105 | } | ||
| 106 | 0 | catch (IOException e) | |
| 107 | { | ||
| 108 | 0 | throw new BuildException(e, getLocation()); | |
| 109 | 0 | } | |
| 110 | } | ||
| 111 | 0 | catch (BuildException e) | |
| 112 | { | ||
| 113 | 0 | if (mFailOnError) | |
| 114 | { | ||
| 115 | 0 | throw e; | |
| 116 | } | ||
| 117 | 0 | log(e.getMessage(), Project.MSG_ERR); | |
| 118 | 0 | } | |
| 119 | 0 | } | |
| 120 | |||
| 121 | /** | ||
| 122 | * Checks the attributes provided by this class. | ||
| 123 | * @throws BuildException | ||
| 124 | */ | ||
| 125 | private void checkAttributes () | ||
| 126 | throws BuildException | ||
| 127 | { | ||
| 128 | 0 | checkAttributeInFile(); | |
| 129 | 0 | } | |
| 130 | |||
| 131 | private void checkAttributeInFile () | ||
| 132 | { | ||
| 133 | 0 | if (mInFiles == null) | |
| 134 | { | ||
| 135 | 0 | throw new BuildException( | |
| 136 | "Missing mandatory attribute 'in'.", getLocation()); | ||
| 137 | } | ||
| 138 | |||
| 139 | 0 | for (int i = 0; i < mInFiles.length; i++) | |
| 140 | { | ||
| 141 | 0 | if (!mInFiles[i].exists()) | |
| 142 | { | ||
| 143 | 0 | throw new BuildException( | |
| 144 | "Input file '" + mInFiles[i] + "' not found.", | ||
| 145 | getLocation()); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | 0 | } | |
| 149 | |||
| 150 | /** | ||
| 151 | * Set the input files. | ||
| 152 | * | ||
| 153 | * @param inFiles the input files. | ||
| 154 | */ | ||
| 155 | public void setInFiles (File[] inFiles) | ||
| 156 | { | ||
| 157 | 0 | (2) | mInFiles = inFiles; |
| 158 | 0 | } | |
| 159 | |||
| 160 | } |
|
|
(3) | Got an exception - java.lang.RuntimeException: Unable to get class information for @throws tag 'BuildException'. | |||
|
|
(4) | GnuplotTask.mInFiles not initialized in constructor | |||
|
|
(1) | 91 | : | 0 | Copied and pasted code. 232 equal tokens (70 lines) found in 2 locations. See also: org.jcoderz.commons.taskdefs.DotTask:116 |
|
|
(2) | 157 | : | 0 | org.jcoderz.commons.taskdefs.GnuplotTask.setInFiles(File[]) may expose internal representation by storing an externally mutable object into GnuplotTask.mInFiles |