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.io.File;
018:
019: import org.apache.tools.ant.BuildException;
020: import org.apache.tools.ant.Project;
021: import org.apache.tools.ant.types.Path;
022:
023: import com.metaboss.sdlctools.applications.anttasks.builder.MetaBossBuilderTask;
024: import com.metaboss.sdlctools.applications.anttasks.builder.ToolInvocationDefinition;
025: import com.metaboss.util.ObjectUtils;
026: import com.sun.xml.rpc.tools.ant.Wscompile;
027:
028: /** This definition is responsible for invocation of the Java compiler */
029: public class WSCompileInvocationDefinition extends
030: ToolInvocationDefinition {
031: // This class provides definition of the source definition
032: private Boolean mIsServer = null;
033: private boolean mIsOverwriteExisting = false;
034: private File mConfigFile = null;
035: private File mModelFile = null;
036:
037: /** Public constructor for the invocation */
038: public WSCompileInvocationDefinition(
039: MetaBossBuilderTask pOwnerTask, String pInvocationName) {
040: super (pOwnerTask, pInvocationName);
041: }
042:
043: /** Setter for the isServer flag */
044: public void setIsServer(boolean pIsServer) {
045: mIsServer = new Boolean(pIsServer);
046: }
047:
048: /** Getter for the isServer flag */
049: public boolean isServer() {
050: if (mIsServer == null)
051: throw new BuildException(
052: "Missing IsServer, which is mandatory for ant task invocation.");
053: return mIsServer.booleanValue();
054: }
055:
056: /** Setter for the isOverwriteExisting flag */
057: public void setIsOverwriteExisting(boolean pIsOverwriteExisting) {
058: mIsOverwriteExisting = pIsOverwriteExisting;
059: }
060:
061: /** Getter for the isOverwriteExisting flag */
062: public boolean isOverwriteExisting() {
063: return mIsOverwriteExisting;
064: }
065:
066: /** Setter for the file location */
067: public void setConfigFileLocation(String pFilePath) {
068: mConfigFile = new File(pFilePath).getAbsoluteFile();
069: }
070:
071: /** Gets the path of the config file to work on */
072: public File getConfigFile() {
073: return mConfigFile;
074: }
075:
076: /** Gets the path of the model file to work on or generate */
077: public File getModelFile() {
078: return mModelFile;
079: }
080:
081: /** Setter for the file location */
082: public void setModelFileLocation(String pFilePath) {
083: mModelFile = new File(pFilePath).getAbsoluteFile();
084: }
085:
086: /** Overridden to compare details of the invocation */
087: public boolean equals(Object pOther) {
088: if (this == pOther)
089: return true;
090: if (pOther instanceof WSCompileInvocationDefinition) {
091: WSCompileInvocationDefinition lOther = (WSCompileInvocationDefinition) pOther;
092: getOwnerTask().getLogger().verbose(
093: "Comparing two " + getClass().getName()
094: + " instances...");
095:
096: // Compare names
097: if (!ObjectUtils.equals(getToolInvocationName(), lOther
098: .getToolInvocationName())) {
099: getOwnerTask()
100: .getLogger()
101: .verbose(
102: "Name mismatch ('"
103: + getToolInvocationName()
104: + "' vs '"
105: + lOther
106: .getToolInvocationName()
107: + "')");
108: return false;
109: }
110: // Compare server flag
111: if (!ObjectUtils.equals(mIsServer, lOther.mIsServer)) {
112: getOwnerTask().getLogger().verbose(
113: "Server flag mismatch ('" + isServer()
114: + "' vs '" + lOther.isServer() + "')");
115: return false;
116: }
117: // Compare model files
118: if (!ObjectUtils.equals(getModelFile(), lOther
119: .getModelFile())) {
120: getOwnerTask().getLogger().verbose(
121: "Model file mismatch ('"
122: + getModelFile().getAbsolutePath()
123: + "' vs '"
124: + lOther.getModelFile()
125: .getAbsolutePath() + "')");
126: return false;
127: }
128: // Compare config files
129: if (!ObjectUtils.equals(getConfigFile(), lOther
130: .getConfigFile())) {
131: getOwnerTask().getLogger().verbose(
132: "Config file mismatch ('"
133: + getConfigFile().getAbsolutePath()
134: + "' vs '"
135: + lOther.getConfigFile()
136: .getAbsolutePath() + "')");
137: return false;
138: }
139: getOwnerTask().getLogger().verbose(
140: "The instances are equal");
141: return true; // Everything appears to be in order
142: }
143: return false;
144: }
145:
146: /** This method will have to invoke the generator */
147: public void invoke() throws BuildException {
148: MetaBossBuilderTask lOwnerTask = getOwnerTask();
149: Project lThisProject = lOwnerTask.getProject();
150: // Now create and execute the web services compiler task
151: Wscompile lWscompileTask = (Wscompile) lThisProject
152: .createTask("Wscompile");
153: if (lWscompileTask == null)
154: throw new BuildException(
155: "Unable to instantiate Wscompile task");
156: lWscompileTask.setTaskName(lOwnerTask.getTaskName());
157: lWscompileTask.setSourceBase(lOwnerTask.getGenDir());
158: lWscompileTask.setBase(lOwnerTask.getClassDir());
159: lWscompileTask.setKeep(true);
160: // Collect features and set them
161: StringBuffer lFeatures = new StringBuffer("searchschema,wsi");
162: if (!isOverwriteExisting())
163: lFeatures.append(",donotoverride");
164: lWscompileTask.setFeatures(lFeatures.toString());
165: lWscompileTask.setServer(isServer());
166: lWscompileTask.setConfig(getConfigFile());
167: lWscompileTask.setModel(getModelFile());
168: // Add specialised JAXRPC classpath
169: Path lClasspath = lWscompileTask.createClasspath();
170: lClasspath.addExisting(lOwnerTask
171: .getPath("JAXRPCWebServicesCompileClasspath"));
172: if (!isFailOnError()) {
173: try {
174: lWscompileTask.execute();
175: } catch (BuildException e) {
176: // Ignore the failure
177: getOwnerTask().getLogger().info(
178: "Ignoring the failure: " + e.toString());
179: }
180: } else
181: lWscompileTask.execute();
182: }
183: }
|