001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: Mdl2JJTask.java 6318 2007-03-26 06:13:03Z lzheng $
023: */
024: package com.bostechcorp.cbesb.tools.ant;
025:
026: import java.io.File;
027: import java.util.ArrayList;
028: import java.util.LinkedList;
029: import java.util.List;
030:
031: import org.apache.tools.ant.BuildException;
032: import org.apache.tools.ant.Task;
033: import org.apache.tools.ant.taskdefs.Java;
034: import org.apache.tools.ant.types.Path;
035: import org.apache.tools.ant.types.Reference;
036:
037: import com.bostechcorp.cbesb.common.mdl.fsmparser.Mdl2Fsm;
038:
039: /**
040: * @author elu
041: *
042: */
043: public class Mdl2JJTask extends Task {
044: static public String DEFAULT_FSM_PACKAGE_NAME = "com.bostechcorp.cbesb.fsmparser";
045:
046: private boolean failOnError = true;
047: private String taggedMdl;
048: private String destDir;
049: private String projName;
050: private boolean useZip = true;
051: private boolean fork = true;
052: private Path classpath = null;
053:
054: private List<File> mdlFiles;
055: private LinkedList argslist;
056:
057: /**
058: * @return the destDir
059: */
060: public String getDestDir() {
061: return destDir;
062: }
063:
064: /**
065: * @param destDir the destDir to set
066: */
067: public void setDestDir(String destDir) {
068: this .destDir = destDir;
069: }
070:
071: /**
072: * @return the taggedMdl
073: */
074: public String getTaggedMdl() {
075: return taggedMdl;
076: }
077:
078: /**
079: * @param taggedMdl the taggedMdl to set
080: */
081: public void setTaggedMdl(String taggedMdl) {
082: this .taggedMdl = taggedMdl;
083: }
084:
085: /**
086: * @return the projName
087: */
088: public String getProjName() {
089: return projName;
090: }
091:
092: /**
093: * @param projName the projName to set
094: */
095: public void setProjName(String projName) {
096: this .projName = projName;
097: }
098:
099: public boolean isUseZip() {
100: return useZip;
101: }
102:
103: public void setUseZip(boolean useZip) {
104: this .useZip = useZip;
105: }
106:
107: /**
108: *
109: */
110: public Mdl2JJTask() {
111: mdlFiles = new ArrayList<File>();
112: }
113:
114: /**
115: * execute the task
116: *
117: * @throws BuildException
118: */
119: public void execute() {
120: try {
121: // System.out.println("TaggedMdl:"+taggedMdl);
122: TaggedFileList tfl = new TaggedFileList(taggedMdl);
123:
124: mdlFiles = tfl.load();
125: // String zipFile=null;
126: for (File f : mdlFiles) {
127: System.out.println(f.getAbsolutePath());
128: boolean useDefaultMdlResolver = true;
129: if (isUseZip()) {
130: if (f.getAbsolutePath().indexOf(
131: File.separatorChar + "src"
132: + File.separatorChar +
133:
134: "formats" + File.separatorChar
135: + "x12") > -1) {
136: // System.out.println("x12");
137: // System.out.println("projectName:"+projName);
138: // String path=f.getPath();
139: // int pos=path.indexOf(File.separator+"x12"+File.separator);
140: // String varName=path.substring(pos+5,path.indexOf(File.separator, pos+5));
141: //
142: // zipFile=ProjectUtil.geX12ZipPathForServer(projName)+File.separatorChar+varName+".zip";
143: // System.out.println(zipFile);
144:
145: useDefaultMdlResolver = false;
146: } else if (f.getAbsolutePath().indexOf(
147: File.separatorChar + "src"
148: + File.separatorChar + "formats"
149: + File.separatorChar + "hl7") > -1) {
150: // System.out.println("x12");
151: // System.out.println("projectName:"+projName);
152: // String path=f.getPath();
153: // int pos=path.indexOf(File.separator+"hl7"+File.separator);
154: // String varName=path.substring(pos+5,path.indexOf(File.separator, pos+5));
155: //
156: // zipFile=ProjectUtil.get.geX12ZipPathForServer(projName)+File.separatorChar+varName+".zip";
157: // System.out.println(zipFile);
158: useDefaultMdlResolver = false;
159:
160: }
161: }
162: Mdl2Fsm.mdl2JJ(f, DEFAULT_FSM_PACKAGE_NAME
163: + tfl.extraJavaPackageName(projName, f),
164: destDir, useDefaultMdlResolver);
165:
166: }
167: } catch (Exception ex) {
168: ex.printStackTrace();
169: }
170: }
171:
172: private void executeInForkedVM(String[] args) {
173: try {
174: // Create an instance of the compiler, redirecting output to
175: // the project log
176: Java java = (Java) (getProject().createTask("java"));
177: // getProject().log("using classpath: " + classpath,
178: // Project.MSG_DEBUG);
179: System.err.println("using classpath: " + classpath);
180: java.setClasspath(classpath);
181: java
182: .setClassname("com.bostechcorp.cbesb.tools.ant.mdl.Mdl2Fsm1");
183: for (int i = 0; i < args.length; i++) {
184: java.createArg().setValue(args[i]);
185: }
186: java.setFailonerror(failOnError);
187: //we are forking here to be sure that if AdminClient calls
188: //System.exit() it doesn't halt the build
189: java.setFork(true);
190: java.setTaskName("Mdl2JJ");
191: java.execute();
192: } catch (BuildException e) {
193: //rethrow these
194: throw e;
195: } catch (Exception e) {
196: throw new BuildException("Exception in " + getTaskName(), e);
197: }
198: }
199:
200: /**
201: * add one arg
202: *
203: * @param argument
204: */
205: protected void addArg(String argument) {
206: argslist.add(argument);
207: }
208:
209: /**
210: * add one arg
211: *
212: * @param argument
213: */
214: protected void addArg(String argument, boolean test) {
215: if (test) {
216: argslist.add(argument);
217: }
218: }
219:
220: /**
221: * add an arg pair
222: *
223: * @param argument
224: * @param param
225: */
226: protected void addArgs(String argument, String param) {
227: addArg(argument);
228: addArg(param);
229: }
230:
231: /**
232: * add an arg pair if the test is true
233: *
234: * @param argument first arg
235: * @param param param to accompany
236: * @param test test to trigger argument add
237: */
238: protected void addArgs(String argument, String param, boolean test) {
239: if (test) {
240: addArg(argument);
241: addArg(param);
242: }
243: }
244:
245: /**
246: * Set the optional classpath
247: *
248: * @param classpath the classpath to use when loading class
249: */
250: public void setClasspath(Path classpath) {
251: createClasspath().append(classpath);
252: }
253:
254: /**
255: * Set the optional classpath
256: *
257: * @return a path instance to be configured by the Ant core.
258: */
259: public Path createClasspath() {
260: if (classpath == null) {
261: classpath = new Path(getProject());
262: }
263: return classpath.createPath();
264: }
265:
266: /**
267: * Set the reference to an optional classpath
268: *
269: * @param r the id of the Ant path instance to act as the classpath
270: */
271: public void setClasspathRef(Reference r) {
272: createClasspath().setRefid(r);
273: }
274:
275: /**
276: * @return the failOnError
277: */
278: public boolean isFailOnError() {
279: return failOnError;
280: }
281:
282: /**
283: * @param failOnError the failOnError to set
284: */
285: public void setFailOnError(boolean failOnError) {
286: this .failOnError = failOnError;
287: }
288:
289: /**
290: * @return the fork
291: */
292: public boolean isFork() {
293: return fork;
294: }
295:
296: /**
297: * @param fork the fork to set
298: */
299: public void setFork(boolean fork) {
300: this.fork = fork;
301: }
302:
303: }
|