Source Code Cross Referenced for CommandRedeploy.java in  » EJB-Server-geronimo » deploy-tool » org » apache » geronimo » deployment » cli » 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 » EJB Server geronimo » deploy tool » org.apache.geronimo.deployment.cli 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.deployment.cli;
017:
018:        import java.io.File;
019:        import java.io.IOException;
020:        import java.util.ArrayList;
021:        import java.util.List;
022:
023:        import javax.enterprise.deploy.spi.DeploymentManager;
024:        import javax.enterprise.deploy.spi.Target;
025:        import javax.enterprise.deploy.spi.TargetModuleID;
026:        import javax.enterprise.deploy.spi.exceptions.TargetException;
027:        import javax.enterprise.deploy.spi.status.ProgressObject;
028:
029:        import org.apache.geronimo.cli.deployer.CommandArgs;
030:        import org.apache.geronimo.common.DeploymentException;
031:        import org.apache.geronimo.kernel.repository.Artifact;
032:        import jline.ConsoleReader;
033:
034:        /**
035:         * The CLI deployer logic to redeploy.
036:         *
037:         * @version $Rev: 602966 $ $Date: 2007-12-10 08:42:55 -0800 (Mon, 10 Dec 2007) $
038:         */
039:        public class CommandRedeploy extends AbstractCommand {
040:
041:            public void execute(ConsoleReader consoleReader,
042:                    ServerConnection connection, CommandArgs commandArgs)
043:                    throws DeploymentException {
044:                ProgressObject po = null;
045:                try {
046:                    String[] args = commandArgs.getArgs();
047:
048:                    if (args.length == 0) {
049:                        throw new DeploymentSyntaxException(
050:                                "Must specify a module or plan (or both) and optionally module IDs to replace");
051:                    }
052:
053:                    DeploymentManager mgr = connection.getDeploymentManager();
054:                    Target[] allTargets = mgr.getTargets();
055:                    TargetModuleID[] allModules;
056:                    try {
057:                        allModules = mgr.getAvailableModules(null, allTargets);
058:                    } catch (TargetException e) {
059:                        throw new DeploymentException(
060:                                "Unable to load modules from server", e);
061:                    }
062:
063:                    List modules = new ArrayList();
064:                    File module = null;
065:                    File plan = null;
066:                    File test = new File(args[0]); // Guess whether the first argument is a module or a plan
067:                    if (!test.exists()) {
068:                        throw new DeploymentSyntaxException(
069:                                "Module or plan file does not exist: "
070:                                        + test.getAbsolutePath());
071:                    }
072:                    if (!test.canRead()) {
073:                        throw new DeploymentException("Cannot read file "
074:                                + test.getAbsolutePath());
075:                    }
076:                    if (DeployUtils.isJarFile(test) || test.isDirectory()) {
077:                        module = test;
078:                    } else {
079:                        plan = test;
080:                    }
081:                    if (args.length > 1) { // Guess whether the second argument is a module, plan, ModuleID, or TargetModuleID
082:                        test = new File(args[1]);
083:                        if (test.exists() && test.canRead()
084:                                && !args[1].equals(args[0])) {
085:                            if (DeployUtils.isJarFile(test)
086:                                    || test.isDirectory()) {
087:                                if (module != null) {
088:                                    throw new DeploymentSyntaxException(
089:                                            "Module and plan cannot both be JAR files or directories!");
090:                                }
091:                                module = test;
092:                            } else {
093:                                if (plan != null) {
094:                                    throw new DeploymentSyntaxException(
095:                                            "Module or plan must be a JAR file or directory!");
096:                                }
097:                                plan = test;
098:                            }
099:                        } else {
100:                            modules.addAll(DeployUtils.identifyTargetModuleIDs(
101:                                    allModules, args[1], false));
102:                        }
103:                    }
104:                    for (int i = 2; i < args.length; i++) { // Any arguments beyond 2 must be a ModuleID or TargetModuleID
105:                        modules.addAll(DeployUtils.identifyTargetModuleIDs(
106:                                allModules, args[i], false));
107:                    }
108:                    // If we don't have any moduleIDs, try to guess one.
109:                    if (modules.size() == 0 && connection.isGeronimo()) {
110:                        emit(
111:                                consoleReader,
112:                                "No ModuleID or TargetModuleID provided.  Attempting to guess based on the content of the "
113:                                        + (plan == null ? "archive" : "plan")
114:                                        + ".");
115:                        String moduleId = null;
116:                        try {
117:                            if (plan != null) {
118:                                moduleId = DeployUtils
119:                                        .extractModuleIdFromPlan(plan);
120:                                if (moduleId == null) { // plan just doesn't have a config ID
121:                                    String fileName = module == null ? plan
122:                                            .getName() : module.getName();
123:                                    int pos = fileName.lastIndexOf('.');
124:                                    String artifactId = pos > -1 ? module
125:                                            .getName().substring(0, pos)
126:                                            : module.getName();
127:                                    moduleId = Artifact.DEFAULT_GROUP_ID + "/"
128:                                            + artifactId + "//";
129:                                    emit(
130:                                            consoleReader,
131:                                            "Unable to locate Geronimo deployment plan in archive.  Calculating default ModuleID from archive name.");
132:                                }
133:                            } else if (module != null) {
134:                                moduleId = DeployUtils
135:                                        .extractModuleIdFromArchive(module);
136:                                if (moduleId == null) {
137:                                    int pos = module.getName().lastIndexOf('.');
138:                                    String artifactId = pos > -1 ? module
139:                                            .getName().substring(0, pos)
140:                                            : module.getName();
141:                                    moduleId = Artifact.DEFAULT_GROUP_ID + "/"
142:                                            + artifactId + "//";
143:                                    emit(
144:                                            consoleReader,
145:                                            "Unable to locate Geronimo deployment plan in archive.  Calculating default ModuleID from archive name.");
146:                                }
147:                            }
148:                        } catch (IOException e) {
149:                            throw new DeploymentException(
150:                                    "Unable to read input files: "
151:                                            + e.getMessage(), e);
152:                        }
153:                        if (moduleId != null) {
154:                            emit(consoleReader, "Attempting to use ModuleID '"
155:                                    + moduleId + "'");
156:                            modules.addAll(DeployUtils.identifyTargetModuleIDs(
157:                                    allModules, moduleId, true));
158:                        } else {
159:                            emit(consoleReader,
160:                                    "Unable to calculate a ModuleID from supplied module and/or plan.");
161:                        }
162:                    }
163:                    if (modules.size() == 0) { // Either not deploying to Geronimo or unable to identify modules
164:                        throw new DeploymentSyntaxException(
165:                                "No ModuleID or TargetModuleID available.  Nothing to do.  Maybe you should add a ModuleID or TargetModuleID to the command line?");
166:                    }
167:                    if (module != null) {
168:                        module = module.getAbsoluteFile();
169:                    }
170:                    if (plan != null) {
171:                        plan = plan.getAbsoluteFile();
172:                    }
173:                    // Now that we've sorted out all the arguments, do the work
174:                    TargetModuleID[] ids = (TargetModuleID[]) modules
175:                            .toArray(new TargetModuleID[modules.size()]);
176:                    boolean multiple = isMultipleTargets(ids);
177:                    po = mgr.redeploy(ids, module, plan);
178:                    waitForProgress(consoleReader, po);
179:                    TargetModuleID[] done = po.getResultTargetModuleIDs();
180:                    for (int i = 0; i < done.length; i++) {
181:                        TargetModuleID id = done[i];
182:                        emit(consoleReader, "Redeployed "
183:                                + id.getModuleID()
184:                                + (multiple ? " on " + id.getTarget().getName()
185:                                        : "")
186:                                + (id.getWebURL() == null ? "" : " @ "
187:                                        + id.getWebURL()));
188:                        if (id.getChildTargetModuleID() != null) {
189:                            for (int j = 0; j < id.getChildTargetModuleID().length; j++) {
190:                                TargetModuleID child = id
191:                                        .getChildTargetModuleID()[j];
192:                                emit(consoleReader, "  `-> "
193:                                        + child.getModuleID()
194:                                        + (child.getWebURL() == null ? ""
195:                                                : " @ " + child.getWebURL()));
196:                            }
197:                        }
198:                    }
199:                } catch (IOException e) {
200:                    throw new DeploymentException("Could not write to console",
201:                            e);
202:                }
203:                if (po.getDeploymentStatus().isFailed()) {
204:                    throw new DeploymentException("Operation failed: "
205:                            + po.getDeploymentStatus().getMessage());
206:                }
207:            }
208:
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.