public void execute(ConsoleReader consoleReader, ServerConnection connection, CommandArgs commandArgs)
throws DeploymentException {
ProgressObject po = null;
DistributeCommandArgs distributeCommandArgs = null;
try {
String[] args = commandArgs.getArgs();
if (args.length == 0) {
throw new DeploymentSyntaxException(
"Must specify a module or plan (or both) and optionally module IDs to replace");
}
DeploymentManager mgr = connection.getDeploymentManager();
Target[] allTargets = mgr.getTargets();
TargetModuleID[] allModules;
try {
allModules = mgr.getAvailableModules(null, allTargets);
} catch (TargetException e) {
throw new DeploymentException("Unable to load modules from server", e);
}
if (args.length >= 3 && args[0].equalsIgnoreCase("--targets")) // case of cluster redeployment
{
List modules = new ArrayList();
boolean multipleTargets;
File test = null;
File test1 = null;
File module = null;
File plan = null;
test = new File(args[2]); // check whether args[2] is a module or a plan
checkFirstArguement(test);
if (DeployUtils.isJarFile(test) || test.isDirectory()) {
if (module != null) {
throw new DeploymentSyntaxException("Module and plan cannot both be JAR files or directories!");
}
module = test;
} else {
if (plan != null) {
throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!");
}
plan = test;
}
if (args.length >= 4) {// than it can be plan,moduleId,TargetModuleId
test1 = new File(args[3]);
if (test1.exists() && test1.canRead()) // check if it is plan
{
if (DeployUtils.isJarFile(test1) || test1.isDirectory()) {
if (module != null) {
throw new DeploymentSyntaxException(
"Module and plan cannot both be JAR files or directories!");
}
module = test1;
} else {
if (plan != null) {
throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!");
}
plan = test1;
}
} else
modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, args[3], false));
}
if (module != null) {
module = module.getAbsoluteFile();
}
if (plan != null) {
plan = plan.getAbsoluteFile();
}
if (args.length >= 5) // Amy arguements beyond 4 should be ModuleId or Target ModuleId
{
for (int i = 4; i < args.length; i++) {
modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, args[i], false));
}
}
try {
distributeCommandArgs = new DistributeCommandArgsImpl(args);
} catch (CLParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List<String> targets = Arrays.asList(distributeCommandArgs.getTargets());
if (targets.size() > 0) {
Target[] tlist = identifyTargets(targets, mgr); // before starting undeployment and deployment verify the correctness of target argument
}
if (modules.size() == 0) {
String moduleId = guessModuleId(modules, connection, consoleReader, plan, module, allModules);