Source Code Cross Referenced for WsGenTask.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » ant » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999-2005 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: WsGenTask.java 7508 2005-10-14 12:44:23Z sauthieg $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.ant;
025:
026:        import java.io.File;
027:
028:        import org.apache.tools.ant.AntClassLoader;
029:        import org.apache.tools.ant.BuildException;
030:        import org.apache.tools.ant.DirectoryScanner;
031:        import org.apache.tools.ant.Project;
032:        import org.apache.tools.ant.taskdefs.Java;
033:        import org.apache.tools.ant.taskdefs.MatchingTask;
034:        import org.apache.tools.ant.types.Path;
035:
036:        /**
037:         * Launch WsGen from Ant.
038:         *
039:         * @author Guillaume Sauthier
040:         */
041:        public class WsGenTask extends MatchingTask {
042:
043:            /** Bootstrap class name. */
044:            private static final String BOOTSTRAP_CLASS = "org.objectweb.jonas.server.Bootstrap";
045:
046:            /** WsGen class name (JOnAS 3.3). */
047:            private static final String WSGEN_CLASS = "org.objectweb.jonas_ws.wsgen.WsGen";
048:
049:            /** destination directory */
050:            private File destination = null;
051:
052:            /** source directory */
053:            private File source = null;
054:
055:            /** validation of XML files ? */
056:            private boolean validation = true;
057:
058:            /** name of javac command */
059:            private String javac = null;
060:
061:            /** list of javac options */
062:            private String javacOpts = null;
063:
064:            /** will WsGen keep already generated files ? */
065:            private boolean keepGenerated = false;
066:
067:            /** Will WsGen create configuration files ? */
068:            private boolean noConfig = false;
069:
070:            /** verbose mode */
071:            private boolean verbose = false;
072:
073:            /** debug mode */
074:            private boolean debug = false;
075:
076:            /** JVM debug mode */
077:            private boolean jvmDebug = false;
078:
079:            /** $JONAS_ROOT */
080:            private File jonasRoot = null;
081:
082:            /** $JONAS_BASE */
083:            private File jonasBase = null;
084:
085:            /**
086:             * Set the output Directory
087:             * @param d output dir
088:             */
089:            public void setDestdir(File d) {
090:                destination = d;
091:            }
092:
093:            /**
094:             * Set where source jar files are located
095:             * @param s sources dir
096:             */
097:            public void setSrcdir(File s) {
098:                source = s;
099:            }
100:
101:            /**
102:             * Set XML Validation on/off
103:             * @param v on/off
104:             */
105:            public void setValidation(boolean v) {
106:                validation = v;
107:            }
108:
109:            /**
110:             * Set the javac command line
111:             * @param j javac to use
112:             */
113:            public void setJavac(String j) {
114:                javac = j;
115:            }
116:
117:            /**
118:             * Set Java Compiler Options
119:             * @param opts Options
120:             */
121:            public void setJavacopts(String opts) {
122:                javacOpts = opts;
123:            }
124:
125:            /**
126:             * Set keep Generated mode to on/off
127:             * @param k on/off
128:             */
129:            public void setKeepgen(boolean k) {
130:                keepGenerated = k;
131:            }
132:
133:            /**
134:             * Set noConfig mode to on/off
135:             * @param c on/off
136:             */
137:            public void setNoconfig(boolean c) {
138:                noConfig = c;
139:            }
140:
141:            /**
142:             * Set WSDL2Java verbose mode to on/off
143:             * @param v on/off
144:             */
145:            public void setVerbose(boolean v) {
146:                verbose = v;
147:            }
148:
149:            /**
150:             * Set WSDL2Java debug mode to on/off
151:             * @param b on/off
152:             */
153:            public void setDebug(boolean b) {
154:                debug = b;
155:            }
156:
157:            /**
158:             * Set debug mode on/off. Used only by developpers that wants to Debug GenIC
159:             * @param d boolean
160:             */
161:            public void setJvmdebug(boolean d) {
162:                jvmDebug = d;
163:            }
164:
165:            /**
166:             * Set the JONAS_ROOT to use
167:             * @param jr JONAS_ROOT
168:             */
169:            public void setJonasroot(File jr) {
170:                jonasRoot = jr;
171:            }
172:
173:            /**
174:             * Set the JONAS_BASE to use
175:             * @param jb JONAS_BASE
176:             */
177:            public void setJonasbase(File jb) {
178:                jonasBase = jb;
179:            }
180:
181:            /**
182:             * Execute the WsGen Ant Task.
183:             * @throws BuildException if wsgen cannot finish
184:             */
185:            public void execute() throws BuildException {
186:
187:                // init the wsgen task
188:                initWsGenTask();
189:
190:                // execute
191:                DirectoryScanner ds = getDirectoryScanner(source);
192:                ds.scan();
193:                String[] files = ds.getIncludedFiles();
194:
195:                for (int i = 0; i < files.length; i++) {
196:
197:                    Java wsgen = createWsGen(source + File.separator + files[i]);
198:
199:                    // calling WsGen task
200:                    log("Calling  WsGen task for '" + source + File.separator
201:                            + files[i] + "'.", Project.MSG_VERBOSE);
202:
203:                    if (wsgen.executeJava() != 0) {
204:                        throw new BuildException("WsGen reported an error.");
205:                    }
206:                }
207:
208:            }
209:
210:            /**
211:             * Create and configure the WsGen Java task.
212:             * @param filename input file name to be processed by WsGen
213:             * @return the configured Java Ant Task
214:             * @throws BuildException if the Java Task cannot be created
215:             */
216:            private Java createWsGen(String filename) throws BuildException {
217:
218:                Java wsgenTask = null; // WsGen task
219:
220:                wsgenTask = (Java) getProject().createTask("java");
221:                wsgenTask.setTaskName("wsgen");
222:                wsgenTask.setFork(true);
223:
224:                // jonas root
225:                wsgenTask.createJvmarg()
226:                        .setValue("-Dinstall.root=" + jonasRoot);
227:
228:                // jonas base
229:                wsgenTask.createJvmarg().setValue("-Djonas.base=" + jonasBase);
230:
231:                // Endorsed directory
232:                File endorsedDir = new File(new File(jonasRoot, "lib"),
233:                        "endorsed");
234:                wsgenTask.createJvmarg().setValue(
235:                        "-Djava.endorsed.dirs=" + endorsedDir);
236:
237:                // java policy file
238:                String jonasConfigDir = jonasRoot + File.separator + "conf";
239:                File javaPolicyFile = new File(jonasConfigDir, "java.policy");
240:                if (javaPolicyFile.exists()) {
241:                    wsgenTask.createJvmarg().setValue(
242:                            "-Djava.security.policy="
243:                                    + javaPolicyFile.toString());
244:                }
245:
246:                // JVM Debug
247:                if (jvmDebug) {
248:                    this 
249:                            .log(
250:                                    "Launching in debug mode on port 12345, waiting for connection ...",
251:                                    Project.MSG_INFO);
252:                    wsgenTask
253:                            .createJvmarg()
254:                            .setLine(
255:                                    "-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=12345,suspend=y");
256:                }
257:
258:                // The bootstrap class must launch the GenIC class
259:                wsgenTask.createArg().setValue(WSGEN_CLASS);
260:
261:                wsgenTask.createArg().setValue("-d");
262:                wsgenTask.createArg().setFile(destination);
263:
264:                // add ow_jonas_bootstrap.jar
265:                String bootJar = jonasRoot + File.separator + "lib"
266:                        + File.separator + "common" + File.separator
267:                        + "ow_jonas_bootstrap.jar";
268:                Path classpath = new Path(getProject(), bootJar);
269:
270:                log("Using classpath: " + classpath.toString(),
271:                        Project.MSG_VERBOSE);
272:                wsgenTask.setClasspath(classpath);
273:
274:                if (!checkBootstrapClassName(classpath)) {
275:                    log("Cannot find bootstrap class in classpath.",
276:                            Project.MSG_ERR);
277:                    throw new BuildException(
278:                            "Bootstrap class not found, please check the classpath.");
279:                } else {
280:                    wsgenTask.setClassname(BOOTSTRAP_CLASS);
281:                }
282:
283:                // keepgenerated
284:                if (keepGenerated) {
285:                    wsgenTask.createArg().setValue("-keepgenerated");
286:                }
287:
288:                // noconfig
289:                if (noConfig) {
290:                    wsgenTask.createArg().setValue("-noconfig");
291:                }
292:
293:                // novalidation
294:                if (!validation) {
295:                    wsgenTask.createArg().setValue("-novalidation");
296:                }
297:
298:                // javac
299:                if (javac != null) {
300:                    wsgenTask.createArg().setValue("-javac");
301:                    wsgenTask.createArg().setLine(javac);
302:                }
303:
304:                // javacopts
305:                if (javacOpts != null && !javacOpts.equals("")) {
306:                    wsgenTask.createArg().setValue("-javacopts");
307:                    wsgenTask.createArg().setLine(javacOpts);
308:                }
309:
310:                // verbose
311:                if (verbose) {
312:                    wsgenTask.createArg().setValue("-verbose");
313:                }
314:
315:                // debug
316:                if (debug) {
317:                    wsgenTask.createArg().setValue("-debug");
318:                }
319:
320:                // input file to process by GenIC
321:                wsgenTask.createArg().setValue(filename);
322:
323:                return wsgenTask;
324:
325:            }
326:
327:            /**
328:             * Initialize build properties
329:             * @throws BuildException if required properties are not set
330:             */
331:            private void initWsGenTask() throws BuildException {
332:                // try to define jonasRoot if not set
333:                if (jonasRoot == null) {
334:                    // get ant property
335:                    String jr = getProject().getProperty("jonas.root");
336:                    jonasRoot = new File(jr);
337:
338:                    if (jr == null) {
339:                        throw new BuildException(
340:                                "attribute jonasroot is necessary.");
341:                    }
342:                }
343:
344:                // use jonasRoot as jonasBase if not set
345:                if (jonasBase == null) {
346:                    String jb = getProject().getProperty("jonas.base");
347:                    if (jb == null) {
348:                        jonasBase = jonasRoot;
349:                    } else {
350:                        jonasBase = new File(jb);
351:                    }
352:
353:                }
354:
355:                // default destination : project directory
356:                if (destination == null) {
357:                    destination = getProject().getBaseDir();
358:                }
359:
360:                // javac javacOpts
361:                // by default WsGen already handle them
362:
363:            }
364:
365:            /**
366:             * Check the bootstrap class name to use in the given classpath.
367:             *
368:             * @param classpath classpath where the boostrap class must be searched.
369:             * @return true if the bootstrap is available in the classpath
370:             */
371:            private boolean checkBootstrapClassName(Path classpath) {
372:                log("Looking for bootstrap class in classpath: "
373:                        + classpath.toString(), Project.MSG_VERBOSE);
374:                AntClassLoader cl = new AntClassLoader(classpath.getProject(),
375:                        classpath);
376:                try {
377:                    cl.loadClass(BOOTSTRAP_CLASS);
378:                    log("Found Bootstrap class '" + BOOTSTRAP_CLASS
379:                            + "' in classpath.", Project.MSG_VERBOSE);
380:                } catch (ClassNotFoundException cnf1) {
381:                    log("Bootstrap class '" + BOOTSTRAP_CLASS
382:                            + "' not found in classpath.", Project.MSG_VERBOSE);
383:                    return false;
384:                }
385:                return true;
386:            }
387:
388:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.