001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.sdlctools.applications.anttasks.builder.tools;
016:
017: import java.util.ArrayList;
018: import java.util.Arrays;
019: import java.util.Iterator;
020: import java.util.List;
021:
022: import org.apache.tools.ant.BuildException;
023: import org.apache.tools.ant.Project;
024: import org.apache.tools.ant.taskdefs.Java;
025: import org.apache.tools.ant.types.Commandline;
026: import org.apache.tools.ant.types.Path;
027:
028: import com.metaboss.sdlctools.applications.anttasks.builder.MetaBossBuilderTask;
029: import com.metaboss.sdlctools.applications.anttasks.builder.ToolInvocationDefinition;
030: import com.metaboss.util.AntUtils;
031: import com.metaboss.util.ObjectUtils;
032:
033: /** This definition is responsible for invocation of the Java VM ant task */
034: public class JavaVMInvocationDefinition extends
035: ToolInvocationDefinition {
036: private boolean mDiscrete = false; // If equals true - will always run
037: private String mClassName = null; // The clas name to execute
038: private String mClasspathReference = null; // Actual classpath to use
039: private Path mClasspathPath = null; // Actual classpath to use
040: private String mClasspathName = null; // Logical classpath to use
041: private boolean mFork = false; // Fork or Not
042: private boolean mFailOnError = true; // Fail or Not
043: private List mArguments = new ArrayList(); // Array of command line arguments
044:
045: /** Public constructor for the invocation */
046: public JavaVMInvocationDefinition(MetaBossBuilderTask pOwnerTask,
047: String pToolInvocationName) {
048: super (pOwnerTask, pToolInvocationName);
049: }
050:
051: /** Sets the Java class to run */
052: public void setClassName(String pClassName) {
053: mClassName = pClassName;
054: }
055:
056: /** Sets the path to add to the VM */
057: public void setClasspathPath(Path pClasspathPath) {
058: mClasspathPath = pClasspathPath;
059: }
060:
061: /** Sets the name of the predefined Java class path. This classpath is
062: * predefined internally in the in the resources stored stored in MetaBossAntIntegration.jar file */
063: public void setClasspathName(String pClasspathName) {
064: mClasspathName = pClasspathName;
065: }
066:
067: /** Sets the reference to the predefined Java class path. This classpath is
068: * predefined in the project */
069: public void setClasspathReference(String pClasspathReference) {
070: mClasspathReference = pClasspathReference;
071: }
072:
073: /** Sets the Java class path */
074: public void addArgument(String pArgument) {
075: mArguments.add(pArgument);
076: }
077:
078: /** Sets fork flag. */
079: public void setFork(boolean pFork) {
080: mFork = pFork;
081: }
082:
083: /** Sets fail on error flag (default true). */
084: public void setFailOnError(boolean pFailOnError) {
085: mFailOnError = pFailOnError;
086: }
087:
088: /** Sets discrete flag. It means that this invocation will run even if there are the same ones */
089: public void setDiscrete(boolean pDiscrete) {
090: mDiscrete = pDiscrete;
091: }
092:
093: /** Overridden to compare details of the invocation */
094: public boolean equals(Object pOther) {
095: if (mDiscrete == true)
096: return false; // Never equals
097: if (this == pOther)
098: return true;
099: if ((pOther instanceof JavaVMInvocationDefinition) == false)
100: return false;
101: JavaVMInvocationDefinition lOther = (JavaVMInvocationDefinition) pOther;
102: if (lOther.mDiscrete == true)
103: return false; // Never equals
104: // Compare attributes one by one
105: if (!ObjectUtils.equals(mClassName, lOther.mClassName))
106: return false;
107: if (!ObjectUtils.equals(mClasspathName, lOther.mClasspathName))
108: return false;
109: if (!ObjectUtils.equals(mClasspathReference,
110: lOther.mClasspathReference))
111: return false;
112: if (!AntUtils.equals(mClasspathPath, lOther.mClasspathPath))
113: return false;
114: if (!Arrays.equals(mArguments.toArray(), lOther.mArguments
115: .toArray()))
116: return false;
117: if (mFork != lOther.mFork)
118: return false;
119: if (mFailOnError != lOther.mFailOnError)
120: return false;
121: return true; // Everything appears to be in order
122: }
123:
124: /** This method will have to invoke the generator */
125: public void invoke() throws BuildException {
126: MetaBossBuilderTask lOwnerTask = getOwnerTask();
127: Project lThisProject = getOwnerTask().getProject();
128: // Now create and execute the java compiler task
129: Java lJavaTask = (Java) lThisProject.createTask("java");
130: lJavaTask.setTaskName(lOwnerTask.getTaskName());
131: lJavaTask.setClassname(mClassName);
132: // Work on classpath
133: Path lClasspath = lJavaTask.createClasspath();
134: if (mClasspathName != null)
135: lClasspath.addExisting(lOwnerTask.getPath(mClasspathName));
136: if (mClasspathPath != null)
137: lClasspath.addExisting(mClasspathPath);
138: if (mClasspathReference != null) {
139: Object lReferencedPath = lThisProject
140: .getReference(mClasspathReference);
141: if ((lReferencedPath == null)
142: || ((lReferencedPath instanceof Path) == false))
143: throw new BuildException("The path with id '"
144: + mClasspathReference
145: + "' is not found in the project");
146: lClasspath.addExisting((Path) lReferencedPath);
147: }
148: // Work on arguments
149: for (Iterator lArgumentsIterator = mArguments.iterator(); lArgumentsIterator
150: .hasNext();) {
151: String lArgument = (String) lArgumentsIterator.next();
152: Commandline.Argument lTaskArgument = lJavaTask.createArg();
153: lTaskArgument.setValue(lArgument);
154: }
155: lJavaTask.setFailonerror(mFailOnError);
156: lJavaTask.setFork(mFork);
157: lJavaTask.execute();
158: }
159: }
|