package com.adaptrex.tools.command;
import static com.adaptrex.tools.Tools.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.cli.ParseException;
import com.adaptrex.tools.environment.Environment;
import com.adaptrex.tools.environment.IEnvironmentService;
import com.adaptrex.tools.framework.javascript.AdaptrexJS;
import com.adaptrex.tools.framework.javascript.ExtJS;
import com.adaptrex.tools.framework.javascript.JavaScriptFramework;
import com.adaptrex.tools.framework.javascript.SenchaTouch;
import com.adaptrex.tools.log.ILogService;
import com.adaptrex.tools.webapp.IWebappService;
import com.adaptrex.tools.webapp.Page;
import com.adaptrex.tools.webapp.Webapp;
import com.google.inject.Inject;
public class Show extends Command {
@Inject
public Show(ICommandService commandService, ILogService logService,
IEnvironmentService environmentService, IWebappService webappService) throws ParseException,
IOException {
super(commandService, logService, environmentService, webappService);
}
// private static final String ENV_USAGE = "adaptrex show environment";
private static final String WEBAPP_USAGE = "adaptrex show webapp [-p <path>]";
public void run() throws ParseException, IOException {
String target = commandService.getTarget();
if (target.equals("environment"))
printEnvironment();
else if (target.equals("webapp"))
printWebapp();
}
private void printWebapp() throws ParseException {
commandService.addWebappOptions();
cl = commandService.parseCommands(WEBAPP_USAGE);
Webapp webapp = commandService.getWebapp();
if (webapp == null)
return;
System.out.println("Webapp Configuration" + CR + HR + CR +
"Webapp Name : " + webapp.getName() + CR +
"Webapp Path : " + webapp.getFullPath() + CR +
"Common Namespace : " + webapp.getGlobalNamespace() + CR +
"Common JS Folder : " + webapp.getGlobalFolder() + CR +
HR);
AdaptrexJS adaptrex = webapp.getAdaptrex();
ExtJS ext = webapp.getExt();
SenchaTouch st = webapp.getSenchaTouch();
String orm = webapp.getOrm();
String presentation = webapp.getPresentation();
String di = webapp.getDi();
System.out.println(CR + "Frameworks" + CR + HR + CR +
"AdaptrexJS : " +
(adaptrex == null ? "-" : adaptrex.getVersion() +
" (" + adaptrex.getFolderName() + ")") + CR +
"ExtJS : "
+ (ext == null ? "-" : ext.getVersion() + " (" + ext.getFolderName() + ")") + CR +
"Sencha Touch : " +
(st == null ? "-" : st.getVersion() + " (" + st.getFolderName() + ")") + CR +
"ORM : " + (orm == null ? "-" : orm) + CR +
"Presentation : " + (presentation == null ? "-" : presentation) + CR +
"DI : " + (di == null ? "-" : di) + CR +
HR);
List<Page> touchPages = new ArrayList<Page>();
List<Page> extPages = new ArrayList<Page>();
for (String pageName : webapp.getPages().keySet()) {
Page page = webapp.getPages().get(pageName);
if (page.getFrameworkType().equals(JavaScriptFramework.SENCHA_TOUCH)) {
touchPages.add(page);
} else {
extPages.add(page);
}
}
System.out.println(CR + "ExtJS Pages" + CR + HR);
if (extPages.size() > 0) {
for (Page page : extPages)
System.out.println(page.getNamespace() + " (" + page.getPath() + ")");
} else {
System.out.println("No ExtJS Pages Configured");
}
System.out.println(HR);
System.out.println(CR + "Sencha Touch Pages" + CR + HR);
if (touchPages.size() > 0) {
for (Page page : touchPages)
System.out.println(page.getNamespace() + " (" + page.getPath() + ")");
} else {
System.out.println("No Sencha Touch Pages Configured");
}
System.out.println(HR);
}
private void printEnvironment() {
Environment env = environmentService.getEnvironment();
System.out.println("Adaptrex Environment" + CR + HR + CR + "Webroot Path : "
+ env.getWebrootPath() + CR + "Sencha Cmd Path : " + env.getCmdPath() + CR + HR + CR);
System.out.println("Available Frameworks" + CR + HR);
Map<String, AdaptrexJS> adaptrexFrameworks = env.getAdaptrexFrameworks();
for (String key : adaptrexFrameworks.keySet()) {
AdaptrexJS adaptrex = adaptrexFrameworks.get(key);
System.out.println("Adaptrex : " + adaptrex.getVersion() + " (" + adaptrex.getFolderName()
+ ")");
}
Map<String, ExtJS> extFrameworks = env.getExtFrameworks();
for (String key : extFrameworks.keySet()) {
ExtJS ext = extFrameworks.get(key);
System.out.println("ExtJS : " + ext.getVersion() + " (" + ext.getFolderName() + ")");
}
Map<String, SenchaTouch> senchaTouchFrameworks = env.getSenchaTouchFrameworks();
for (String key : senchaTouchFrameworks.keySet()) {
SenchaTouch st = senchaTouchFrameworks.get(key);
System.out.println("Sencha Touch : " + st.getVersion() + " (" + st.getFolderName() + ")");
}
System.out.println(HR);
System.out.println(CR + "Configured Webapps" + CR + HR);
Map<String, Webapp> webapps = env.getWebapps();
if (webapps.size() > 0) {
for (String key : webapps.keySet()) {
Webapp webapp = webapps.get(key);
System.out.println(webapp.getName() + " (" + webapp.getFullPath() + ")");
}
} else {
System.out.println("No Webapps Configured");
}
System.out.println(HR);
}
}