Source Code Cross Referenced for ProjectAddModuleWizard.java in  » Web-Framework » roma-webwizard » org » romaframework » wizard » command » project » impl » 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 » Web Framework » roma webwizard » org.romaframework.wizard.command.project.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.romaframework.wizard.command.project.impl;
018:
019:        import java.io.File;
020:        import java.io.IOException;
021:        import java.net.MalformedURLException;
022:        import java.net.URL;
023:        import java.util.HashSet;
024:        import java.util.Map;
025:        import java.util.Set;
026:
027:        import org.apache.tools.ant.DefaultLogger;
028:        import org.apache.tools.ant.Project;
029:        import org.apache.tools.ant.ProjectHelper;
030:        import org.romaframework.core.io.virtualfile.VirtualFile;
031:        import org.romaframework.core.io.virtualfile.VirtualFileFactory;
032:        import org.romaframework.wizard.MainWizard;
033:        import org.romaframework.wizard.ProjectManager;
034:        import org.romaframework.wizard.WizardConstants;
035:        import org.romaframework.wizard.command.project.OptionalProjectBaseWizardCommand;
036:        import org.romaframework.wizard.helper.FileManagementHelper;
037:        import org.romaframework.wizard.properties.ModuleProperties;
038:        import org.romaframework.wizard.properties.ProjectProperties;
039:
040:        /**
041:         * This wizard add a module to the current project. Modules are in ROMA_HOME/modules. See help to know syntax.
042:         * 
043:         * @author Luca Garulli (luca.garulli@assetdata.it)
044:         */
045:        public class ProjectAddModuleWizard extends
046:                OptionalProjectBaseWizardCommand {
047:
048:            public static final String NAME = "add";
049:
050:            public String getName() {
051:                return NAME;
052:            }
053:
054:            @Override
055:            public String getParameters() {
056:                return super .getParameters() + " <module-name>";
057:            }
058:
059:            public void execute(String[] iParameters) {
060:                if (iParameters.length < 2)
061:                    syntaxError();
062:
063:                iParameters = parseOptionalParameters(iParameters);
064:
065:                // READ ARGUMENTS
066:                String moduleName = iParameters[1];
067:
068:                String sourcePath = MainWizard.getRomaHome() + "modules/"
069:                        + moduleName;
070:
071:                sourcePath = FileManagementHelper.getVirtualPath(sourcePath);
072:                if (sourcePath == null) {
073:                    getIO().getError().println(
074:                            "Error: module '" + moduleName
075:                                    + "' not found in directory "
076:                                    + MainWizard.getRomaHome() + "modules");
077:                    return;
078:                }
079:
080:                ModuleProperties moduleProperties;
081:                try {
082:                    moduleProperties = new ModuleProperties(sourcePath);
083:
084:                    if (moduleProperties.existsFile()) {
085:                        getIO()
086:                                .getOutput()
087:                                .println(
088:                                        "Installing module: '"
089:                                                + moduleName
090:                                                + "' version: "
091:                                                + moduleProperties
092:                                                        .getProperty(ModuleProperties.VERSION_VAR)
093:                                                + "\n");
094:
095:                        addDependentModules(moduleProperties);
096:                    }
097:                } catch (IOException e1) {
098:                    getIO().getError().println(
099:                            "Error: Cannot load module's properties file "
100:                                    + ModuleProperties.MODULE_FILE_NAME
101:                                    + " in: " + sourcePath);
102:                    return;
103:                }
104:
105:                String projectPath = ProjectManager.getInstance()
106:                        .getProjectPath(projectName);
107:
108:                ProjectProperties projProp = ProjectManager.getInstance()
109:                        .getProjectInfo(projectName);
110:
111:                if (projProp == null)
112:                    return;
113:
114:                if (!moduleName.startsWith(WizardConstants.PROJECT_TYPE_PREFIX)) {
115:                    // COPY SCAFFOLDING ONLY IN NO-PROJECT MODULES
116:                    VirtualFile scaffoldingFile = FileManagementHelper
117:                            .getVirtualFile(sourcePath + "/scaffolding");
118:                    // EXECUTE THE COPY OF SCAFFOLDING IF ANY
119:                    FileManagementHelper.executeCopy(getIO(), scaffoldingFile,
120:                            projectPath, true);
121:                }
122:
123:                VirtualFile sourceLibPath = FileManagementHelper
124:                        .getVirtualFile(sourcePath + "/lib/");
125:
126:                String runTimeLibPath = projProp
127:                        .getProperty(ProjectProperties.RUNTIME_LIBS_VAR);
128:
129:                // EXECUTE THE COPY OF LIBS IF ANY (CHECK FOR PROJECT'S PROPERTY
130:                // COMPILE-TIME)
131:                FileManagementHelper.executeCopy(getIO(), sourceLibPath,
132:                        projectPath + "/" + runTimeLibPath, true);
133:
134:                String scriptPath = sourcePath + "/wizard/wizard.xml";
135:                VirtualFile antFile = null;
136:                try {
137:                    antFile = VirtualFileFactory.getFile(new URL(scriptPath));
138:                } catch (MalformedURLException e) {
139:                    getIO().getError().println(
140:                            "Cannot execute script: " + scriptPath);
141:                }
142:
143:                ProjectProperties prjProperties = ProjectManager.getInstance()
144:                        .getProjectInfo(projectName);
145:
146:                if (antFile != null && antFile.exists()) {
147:                    executeAntScript(antFile, prjProperties);
148:                }
149:
150:                if (moduleProperties.existsFile()) {
151:                    prjProperties.addInstalledModule(moduleName,
152:                            moduleProperties
153:                                    .getProperty(ModuleProperties.VERSION_VAR));
154:                }
155:            }
156:
157:            private void executeAntScript(VirtualFile antFile,
158:                    ProjectProperties prjProperties) {
159:                File buildFile = new File(antFile.getAbsolutePath());
160:                Project p = new Project();
161:
162:                // BIND ALL PROJECT VARIABLES
163:                p.setUserProperty("project.name", projectName);
164:
165:                copyProjectProperty(p, prjProperties, "project.src",
166:                        ProjectProperties.SRC_VAR);
167:                copyProjectProperty(p, prjProperties, "project.package",
168:                        ProjectProperties.PACKAGE_VAR);
169:                copyProjectProperty(p, prjProperties, "project.package-path",
170:                        ProjectProperties.PACKAGE_PATH_VAR);
171:                copyProjectProperty(p, prjProperties, "project.run-time-lib",
172:                        ProjectProperties.RUNTIME_LIBS_VAR);
173:                copyProjectProperty(p, prjProperties,
174:                        "project.compile-time-lib",
175:                        ProjectProperties.COMPTIME_LIBS_VAR);
176:                copyProjectProperty(p, prjProperties, "project.ioc-path",
177:                        ProjectProperties.IOC_PATH_VAR);
178:                copyProjectProperty(p, prjProperties, "project.ioc-file",
179:                        ProjectProperties.IOC_FILE_VAR);
180:
181:                p.setUserProperty("ant.file", buildFile.getAbsolutePath());
182:
183:                DefaultLogger consoleLogger = new DefaultLogger();
184:                consoleLogger.setErrorPrintStream(getIO().getError());
185:                consoleLogger.setOutputPrintStream(getIO().getOutput());
186:                consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
187:                p.addBuildListener(consoleLogger);
188:
189:                p.init();
190:                ProjectHelper helper = ProjectHelper.getProjectHelper();
191:                p.addReference("ant.projectHelper", helper);
192:                helper.parse(p, buildFile);
193:                p.executeTarget(p.getDefaultTarget());
194:            }
195:
196:            private void copyProjectProperty(Project p,
197:                    ProjectProperties prjProperties, String iName, String iValue) {
198:                String value = prjProperties.getProperty(iValue);
199:                if (value != null)
200:                    p.setUserProperty(iName, value);
201:            }
202:
203:            private void addDependentModules(ModuleProperties moduleProperties) {
204:                Map<String, String> moduleDependencies = moduleProperties
205:                        .getDependencies();
206:                if (moduleDependencies.size() == 0)
207:                    return;
208:
209:                getIO().getOutput()
210:                        .println(
211:                                "Found dependent modules: "
212:                                        + moduleDependencies + "\n");
213:
214:                for (Map.Entry<String, String> depModule : moduleDependencies
215:                        .entrySet()) {
216:                    ProjectProperties projProp = ProjectManager.getInstance()
217:                            .getProjectInfo(projectName);
218:                    if (projProp != null
219:                            && projProp
220:                                    .getProperty(ProjectProperties.MODULE_PREFIX_VAR
221:                                            + depModule.getKey()) != null
222:                            && projProp.getProperty(
223:                                    ProjectProperties.MODULE_PREFIX_VAR
224:                                            + depModule.getKey()).equals(
225:                                    depModule.getValue()))
226:                        continue; // module already added
227:
228:                    // TODO: deep module version test
229:
230:                    // ADD DEPENDENT MODULE
231:                    new ProjectAddModuleWizard().execute(new String[] {
232:                            ProjectAddModuleWizard.NAME, depModule.getKey(),
233:                            moduleDependencies.get(depModule.getValue()) });
234:                }
235:            }
236:
237:            @Override
238:            public void help() {
239:                super .help();
240:
241:                StringBuffer buffer = new StringBuffer();
242:                buffer
243:                        .append("        <module-name>  is the module name. See below to know what modules you have installed");
244:                buffer.append("\n");
245:                buffer
246:                        .append("\nPlease specify the module to add to your project between the following discovered in the $ROMA_HOME/modules directory:\n");
247:
248:                // PRINT AVAILABLE MODULE LIST
249:                File modulesDir = new File(MainWizard.getRomaHome() + "modules");
250:                File[] modulesFiles = modulesDir.listFiles();
251:                Set<String> modules = new HashSet<String>();
252:                String moduleName;
253:                for (File moduleDir : modulesFiles) {
254:                    moduleName = moduleDir.getName();
255:                    if (moduleName.equals(WizardConstants.CORE_MODULE_NAME))
256:                        continue;
257:
258:                    if (moduleDir.isDirectory())
259:                        // ADD DIRECTORY MODULE
260:                        modules.add(moduleName);
261:                    else if (moduleDir.getName().endsWith(
262:                            WizardConstants.MODULE_PACKAGE_EXT))
263:                        // ADD ZIP MODULE
264:                        modules.add(moduleName.substring(0, moduleName.length()
265:                                - WizardConstants.MODULE_PACKAGE_EXT.length()));
266:                }
267:
268:                for (String module : modules) {
269:                    buffer.append("\n- " + module);
270:                }
271:
272:                buffer.append("\n");
273:                buffer.append("\nExample:");
274:                buffer.append("\n");
275:                buffer.append("\nroma " + getName() + " web-jetty");
276:
277:                getIO().getError().println(buffer);
278:            }
279:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.