throw new DeploymentException("Invalid login for Maven repository '"+repo+"'");
}
Map categories = new HashMap();
List available = new ArrayList();
for (int i = 0; i < data.getPlugins().length; i++) {
PluginMetadata metadata = data.getPlugins()[i];
List list = (List) categories.get(metadata.getCategory());
if(list == null) {
list = new ArrayList();
categories.put(metadata.getCategory(), list);
}
list.add(metadata);
}
for (Iterator it = categories.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
String category = (String) entry.getKey();
List items = (List) entry.getValue();
out.println();
out.print(DeployUtils.reformat(category, 4, 72));
for (int i = 0; i < items.size(); i++) {
PluginMetadata metadata = (PluginMetadata) items.get(i);
String prefix = " ";
if(!metadata.isInstalled() && metadata.isEligible()) {
available.add(metadata);
prefix = Integer.toString(available.size());
if(available.size() < 10) {
prefix += " ";
}
prefix += ": ";
}
out.print(DeployUtils.reformat(prefix+metadata.getName()+" ("+metadata.getVersion()+")", 8, 72));
out.flush();
}
}
if(available.size() == 0) {
out.println();
out.println("No plugins from this site are eligible for installation.");
return;
}
out.println();
out.print("Install Service [enter number or 'q' to quit]: ");
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String answer = in.readLine();
if(answer.equalsIgnoreCase("q")) {
return;
}
int selection = Integer.parseInt(answer);
PluginMetadata target = ((PluginMetadata) available.get(selection - 1));
long start = System.currentTimeMillis();
Object key = mgr.startInstall(PluginList.createInstallList(data, target.getModuleId()), null, null);
DownloadResults results = CommandInstallCAR.showProgress(mgr, key);
int time = (int)(System.currentTimeMillis() - start) / 1000;
out.println();
if(!results.isFailed()) {
out.print(DeployUtils.reformat("**** Installation Complete!", 4, 72));
for (int i = 0; i < results.getDependenciesPresent().length; i++) {
Artifact uri = results.getDependenciesPresent()[i];
out.print(DeployUtils.reformat("Used existing: "+uri, 4, 72));
}
for (int i = 0; i < results.getDependenciesInstalled().length; i++) {
Artifact uri = results.getDependenciesInstalled()[i];
out.print(DeployUtils.reformat("Installed new: "+uri, 4, 72));
}
out.println();
out.print(DeployUtils.reformat("Downloaded "+(results.getTotalDownloadBytes()/1024)+" kB in "+time+"s ("+results.getTotalDownloadBytes()/(1024*time)+" kB/s)", 4, 72));
}
if(results.isFinished() && !results.isFailed()) {
out.print(DeployUtils.reformat("Now starting "+target.getModuleId()+"...", 4, 72));
out.flush();
new CommandStart().execute(out, connection, new String[]{target.getModuleId().toString()});
}
} catch (IOException e) {
throw new DeploymentException("Unable to install configuration", e);
} catch(NumberFormatException e) {
throw new DeploymentException("Invalid response");