Source Code Cross Referenced for ProjectUtil.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » common » util » project » 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 » ESB » cbesb 1.2 » com.bostechcorp.cbesb.common.util.project 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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$
023:         */
024:        package com.bostechcorp.cbesb.common.util.project;
025:
026:        import java.io.File;
027:        import java.util.Enumeration;
028:        import java.util.Properties;
029:
030:        import org.apache.tools.ant.DefaultLogger;
031:        import org.apache.tools.ant.Project;
032:        import org.apache.tools.ant.ProjectHelper;
033:        import org.eclipse.core.resources.IProject;
034:        import org.eclipse.core.resources.ResourcesPlugin;
035:        import org.eclipse.ui.IEditorPart;
036:        import org.eclipse.ui.PlatformUI;
037:        import org.eclipse.ui.part.FileEditorInput;
038:
039:        import com.bostechcorp.cbesb.common.util.ClassPathHacker;
040:        import com.bostechcorp.cbesb.common.util.EsbPathHelper;
041:        import com.bostechcorp.cbesb.common.util.FileUtil;
042:        import com.bostechcorp.cbesb.common.util.RuntimeClassLoader;
043:
044:        public class ProjectUtil {
045:            public static void buildProject(String projLocation)
046:                    throws Exception {
047:                //build java should first, then build map. because some map operation such as user operation will rely on UCM.jar
048:                build(projLocation + File.separator + "src" + File.separator
049:                        + "java" + File.separator + "build.xml");
050:                build(projLocation + File.separator + "build" + File.separator
051:                        + "build.xml");
052:
053:            }
054:
055:            public static void buildProjectClean(String projLocation)
056:                    throws Exception {
057:                build(projLocation + File.separator + "build" + File.separator
058:                        + "build.xml", "clean", new Properties());
059:                build(projLocation + File.separator + "src" + File.separator
060:                        + "java" + File.separator + "build.xml", "clean",
061:                        new Properties());
062:                String sa_path = projLocation + File.separator + "src"
063:                        + File.separator + "sa";
064:
065:                File sa_dir = new File(sa_path);
066:                if (sa_dir.exists() && sa_dir.isDirectory()) {
067:                    // this is a SA project; We need to do a lot of clean up
068:                    String sa_build_file_name = projLocation + File.separator
069:                            + "src" + File.separator + "sa" + File.separator
070:                            + "build.xml";
071:                    File sa_build_file = new File(sa_build_file_name);
072:                    if (sa_build_file.exists())
073:                        build(sa_build_file_name, "clean", new Properties());
074:
075:                    // We also need to check if the ESB directory is in the SA project by
076:                    // the installer component. If it does, we better remove it.
077:
078:                    String esbProj = ProjectRuntimeUtil
079:                            .getDependentESBProjNameByInfoFile(projLocation
080:                                    + File.separator + "projectinfo.xml");
081:                    String esb_dir_path = projLocation + File.separator
082:                            + esbProj;
083:                    //	   System.out.println("esb dir:" + esb_dir_path);
084:                    File esb_dir = new File(esb_dir_path);
085:                    if (esb_dir.exists() && esb_dir.isDirectory()) {
086:                        FileUtil.deleteFile(esb_dir);
087:                    }
088:                }
089:            }
090:
091:            private static void build(String buildFile) throws Exception {
092:                build(buildFile, null, new Properties());
093:            }
094:
095:            private static void build(String buildFile, String target,
096:                    Properties properties) throws Exception {
097:                Project ant = new Project();
098:                Enumeration keys = properties.keys();
099:                while (keys.hasMoreElements()) {
100:                    String key = (String) keys.nextElement();
101:                    String value = properties.getProperty(key);
102:
103:                    ant.setProperty(key, value);
104:                }
105:                DefaultLogger consoleLogger = new DefaultLogger();
106:                consoleLogger.setErrorPrintStream(System.err);
107:                consoleLogger.setOutputPrintStream(System.out);
108:                consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
109:                ant.addBuildListener(consoleLogger);
110:                try {
111:                    ant.fireBuildStarted();
112:                    ProjectHelper helper = ProjectHelper.getProjectHelper();
113:
114:                    ant.init();
115:                    helper.parse(ant, new File(buildFile));
116:
117:                    if (target != null)
118:                        ant.executeTarget(target);
119:                    else
120:                        ant.executeTarget(ant.getDefaultTarget());
121:
122:                    ant.fireBuildFinished(null);
123:                } catch (Exception e) {
124:                    ant.fireBuildFinished(e);
125:                    throw e;
126:                }
127:            }
128:
129:            public static void buildProjectDefGen(String projName)
130:                    throws Exception {
131:
132:                String projDef_Gen_File = EsbPathHelper.getCbesbHomeDir()
133:                        + File.separator + "bin" + File.separator
134:                        + "ProjDef_Gen.xml";
135:                Properties props = new Properties();
136:                props.put("cbesb_sa_project", projName);
137:                build(projDef_Gen_File, null, props);
138:
139:            }
140:
141:            public static void buildSa(String projLocation) throws Exception {
142:
143:                String sa_File = projLocation + File.separator + "src"
144:                        + File.separator + "sa" + File.separator + "build.xml";
145:                build(sa_File);
146:
147:            }
148:
149:            public static void buildDeploy(String projName) throws Exception {
150:
151:                String deploy_File = EsbPathHelper.getCbesbHomeDir()
152:                        + File.separator + "bin" + File.separator
153:                        + "deploy.xml";
154:                Properties props = new Properties();
155:                props.put("cbesb_sa_project", projName);
156:                build(deploy_File, null, props);
157:
158:            }
159:
160:            public static void prepareTestDBEnv(String projectName)
161:                    throws Exception {
162:                //MacroUtil.loadMacro();
163:                AddClassPathForDB(projectName);
164:            }
165:
166:            public static void prepareTestEnv(String projectName)
167:                    throws Exception {
168:                //MacroUtil.loadMacro();
169:                AddClassPath(projectName);
170:            }
171:
172:            public static void clearTestEnv(String projectName) {
173:                //MacroUtil.clearMacro();
174:                RuntimeClassLoader.clearSaPath(projectName);
175:            }
176:
177:            private static void AddClassPath(String projectName)
178:                    throws Exception {
179:
180:                String home = EsbPathHelper.getCbesbHomeDir();
181:                String pathSeparator = File.separator;
182:                String libpath = home + pathSeparator + "lib" + pathSeparator;
183:                String projectlocation = ProjectRuntimeUtil
184:                        .getProjectLocationByName(projectName);
185:                // the CCSL LIB is used very often; let us add it into CLASSPATH for running the tester
186:                ClassPathHacker.addFile(libpath
187:                        + "com.bostechcorp.cbesb.runtime.ccsl-lib.jar");
188:
189:                String libext = libpath + "ext";
190:
191:                File directory = new File(libext);
192:                if (directory.exists() && directory.isDirectory()) {
193:                    File[] entries = directory.listFiles();
194:
195:                    for (File entry : entries) {
196:                        if (entry.getName().endsWith("jar")
197:                                && entry.getName().startsWith("v")) {
198:                            ClassPathHacker.addFile(entry);
199:                        }
200:
201:                    }
202:                }
203:
204:                addLibToClassPath(projectlocation, projectName, projectName);
205:
206:                String esbProjName = ProjectRuntimeUtil
207:                        .getDependentESBProjNameByLoaction(projectlocation);
208:                if (esbProjName.equals(projectName))
209:                    return;
210:                String esbProjLocation = projectlocation.substring(0,
211:                        projectlocation.lastIndexOf(pathSeparator))
212:                        + pathSeparator + esbProjName;
213:                addLibToClassPath(esbProjLocation, esbProjName, projectName);
214:
215:            }
216:
217:            private static void addLibToClassPath(String projectLocation,
218:                    String currentProjName, String jbiProjName)
219:                    throws Exception {
220:                String pathSeparator = File.separator;
221:                String projectlib = projectLocation + pathSeparator + "lib"
222:                        + pathSeparator;
223:                RuntimeClassLoader.addToPath(jbiProjName, projectlib
224:                        + "CBESB_map_" + currentProjName + ".jar");
225:                RuntimeClassLoader.addToPath(jbiProjName, projectlib
226:                        + "CBESB_fsm_" + currentProjName + ".jar");
227:                RuntimeClassLoader.addToPath(jbiProjName, projectlib
228:                        + "CBESB_ucm_" + currentProjName + ".jar");
229:                addOptionalLibToClassPath(projectLocation, jbiProjName);
230:            }
231:
232:            private static void addOptionalLibToClassPath(
233:                    String projectLocation, String jbiProjName)
234:                    throws Exception {
235:                String path = projectLocation + "/lib/optional";
236:                File directory = new File(path);
237:                if (directory.exists() && directory.isDirectory()) {
238:                    File[] entries = directory.listFiles();
239:
240:                    for (File entry : entries) {
241:                        if (entry.getName().endsWith("jar")) {
242:                            RuntimeClassLoader.addToPath(jbiProjName, entry
243:                                    .getAbsolutePath());
244:                        }
245:
246:                    }
247:                }
248:
249:            }
250:
251:            private static void AddClassPathForDB(String projectName)
252:                    throws Exception {
253:
254:                String pathSeparator = File.separator;
255:                String projectlocation = ProjectRuntimeUtil
256:                        .getProjectLocationByName(projectName);
257:
258:                addOptionalLibToClassPath(projectlocation, projectName);
259:
260:                String esbProjName = ProjectRuntimeUtil
261:                        .getDependentESBProjNameByLoaction(projectlocation);
262:                if (esbProjName.equals(projectName))
263:                    return;
264:                String esbProjLocation = projectlocation.substring(0,
265:                        projectlocation.lastIndexOf(pathSeparator))
266:                        + pathSeparator + esbProjName;
267:                addOptionalLibToClassPath(esbProjLocation, projectName);
268:
269:            }
270:
271:            public static String getHL7ZipPathForUI(String projectName) {
272:
273:                File file = new File(projectName.concat("/projectinfo.xml"));
274:                //    	System.out.println("projectInfo:"+file.getAbsolutePath());
275:                String basePath = "";
276:                if (file.exists()) {
277:                    ProjectInfoDocument doc = ProjectInfoParser.load(file);
278:                    if (doc.getProject().getType().equals("ESB")) {
279:                        //	    		System.out.println("Workspace:"+ResourcesPlugin.getWorkspace().getRoot().getLocation().toString());
280:                        basePath = ResourcesPlugin.getWorkspace().getRoot()
281:                                .getLocation().toString()
282:                                + "/"
283:                                + doc.getProject().getName()
284:                                + "/src/formats/hl7";
285:                    } else {
286:                        String super ProjectName = doc.getProject()
287:                                .getAllSubProjects()[0].getName();
288:                        basePath = ResourcesPlugin.getWorkspace().getRoot()
289:                                .getLocation().toString()
290:                                + "/" + super ProjectName + "/src/formats/hl7";
291:                    }
292:                }
293:                return basePath;
294:
295:            }
296:
297:            public static String getZipPathForUI(String projectName,
298:                    String varname) {
299:
300:                File file = new File(projectName.concat("/projectinfo.xml"));
301:                //    	System.out.println("projectInfo:"+file.getAbsolutePath());
302:                String basePath = "";
303:                if (file.exists()) {
304:                    ProjectInfoDocument doc = ProjectInfoParser.load(file);
305:                    if (doc.getProject().getType().equals("ESB")) {
306:                        //	    		System.out.println("Workspace:"+ResourcesPlugin.getWorkspace().getRoot().getLocation().toString());
307:                        basePath = ResourcesPlugin.getWorkspace().getRoot()
308:                                .getLocation().toString()
309:                                + "/"
310:                                + doc.getProject().getName()
311:                                + "/src/formats/" + varname;
312:                    } else {
313:                        String super ProjectName = doc.getProject()
314:                                .getAllSubProjects()[0].getName();
315:                        basePath = ResourcesPlugin.getWorkspace().getRoot()
316:                                .getLocation().toString()
317:                                + "/"
318:                                + super ProjectName
319:                                + "/src/formats/"
320:                                + varname;
321:                    }
322:                }
323:                return basePath;
324:
325:            }
326:
327:            // get the root path of the zip files
328:
329:            public static String getX12ZipPathForUI(String projectName) {
330:                File file = new File(projectName.concat("/projectinfo.xml"));
331:                //    	System.out.println("projectInfo:"+file.getAbsolutePath());
332:                String basePath = "";
333:                if (file.exists()) {
334:                    ProjectInfoDocument doc = ProjectInfoParser.load(file);
335:                    if (doc.getProject().getType().equals("ESB")) {
336:                        //	    		System.out.println("Workspace:"+ResourcesPlugin.getWorkspace().getRoot().getLocation().toString());
337:                        basePath = ResourcesPlugin.getWorkspace().getRoot()
338:                                .getLocation().toString()
339:                                + "/"
340:                                + doc.getProject().getName()
341:                                + "/src/formats/x12";
342:                    } else {
343:                        String super ProjectName = doc.getProject()
344:                                .getAllSubProjects()[0].getName();
345:                        basePath = ResourcesPlugin.getWorkspace().getRoot()
346:                                .getLocation().toString()
347:                                + "/" + super ProjectName + "/src/formats/x12";
348:                    }
349:                }
350:                return basePath;
351:            }
352:
353:            public static String geX12ZipPathForServer(String projectName) {
354:                File file = new File(EsbPathHelper.getCbesbUiWorkSpace()
355:                        + File.separator
356:                        + projectName.concat("/projectinfo.xml"));
357:                //    	System.out.println("projectInfo:"+file.getAbsolutePath());
358:                String basePath = "";
359:                if (file.exists()) {
360:                    ProjectInfoDocument doc = ProjectInfoParser.load(file);
361:                    //	    	System.out.println("projectType:"+doc.getProject().getType());
362:
363:                    if (doc.getProject().getType().equals("ESB")) {
364:                        basePath = EsbPathHelper.getCbesbUiWorkSpace()
365:                                + File.separator + projectName + File.separator
366:                                + "src" + File.separator + "formats"
367:                                + File.separator + "x12";
368:                    } else {
369:
370:                        String super ProjectName = doc.getProject()
371:                                .getAllSubProjects()[0].getName();
372:                        basePath = EsbPathHelper.getCbesbUiWorkSpace()
373:                                + File.separator + super ProjectName
374:                                + File.separator + "src" + File.separator
375:                                + "formats" + File.separator + "x12";
376:                    }
377:                }
378:                return basePath;
379:            }
380:
381:            /**
382:             * This method only works in UI which relate a editor,such as flow editor and Map editor,etc.
383:             * But in the new wizard, it does not work.
384:             * @return
385:             */
386:            public static String getCurProjectName() {
387:
388:                return getCurProject().getName();
389:            }
390:
391:            /**
392:             * This method only works in UI which relate a editor,such as flow editor and Map editor,etc.
393:             * But in the new wizard, it does not work.
394:             * @return
395:             */
396:            public static IProject getCurProject() {
397:                FileEditorInput editorInput = (FileEditorInput) PlatformUI
398:                        .getWorkbench().getActiveWorkbenchWindow()
399:                        .getActivePage().getActiveEditor().getEditorInput();
400:                return editorInput.getFile().getProject();
401:
402:            }
403:
404:            public static String getProjectName(IEditorPart editor) {
405:
406:                FileEditorInput editorInput = (FileEditorInput) editor
407:                        .getEditorInput();
408:                return editorInput.getFile().getProject().getName();
409:            }
410:
411:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.