String presentation, String orm, String di, String extTheme, String senchaTouchTheme
) throws IOException {
/*
* Make sure we don't already have a webapp at this path
*/
Webapp existing = getWebapp(path, true);
if (existing != null) {
logService.log(Log.ERROR, "Webapp already exists",
"A webapp at " + path + CR +
"is already configured in your environment");
return null;
}
/*
* Make sure we've got a valid webapp folder path
*/
File webappFolder = new File(path);
if (!webappFolder.exists()) {
logService.log(Log.ERROR, "Path not found", path + " is not a valid folder");
return null;
}
/*
* Make sure we have a valid adaptrex webapp at this path
*/
File webappSrcFolder = new File(path + "/src/main/webapp");
if (!webappSrcFolder.exists()) {
logService.log(Log.ERROR, "Invalid webapp",
path + " is not a valid Adaptrex webapp." + CR +
"Adaptrex Tools requires your web contents at src/main/webapp.");
return null;
}
/*
* Check for an existing webapp config file
*/
Webapp webapp = webappService.loadWebapp(path);
if (webapp == null) {
webapp = new Webapp();
webapp.setFullPath(path);
/*
* If we're creating a new webapp, we need to know everything
* about the settings for this webapp
*/
List<String> missingConfigs = new ArrayList<String>();
if (basePackage == null) missingConfigs.add("base-package");
if (orm == null) missingConfigs.add("orm");
if (presentation == null) missingConfigs.add("presentation");
if (missingConfigs.size() > 0) {
String missingString = "";
for (String missingConfig : missingConfigs)
missingString += Tools.TAB + missingConfig + CR;
logService.log(Log.ERROR, "Missing Configuration Options",
"Your webapp is missing the following required configurations: " + CR +
missingString
);
return null;
}
}
/*
* Keep track of previously configured or missing settings
*/
List<String> previouslyConfigured = new ArrayList<String>();
/*
* If we're setting name, make sure it's not already configured
*/
boolean hasName = true;
if (webapp.getName() == null) {
if (name == null) hasName = false;
else webapp.setName(name);
} else if (name != null) {
previouslyConfigured.add(TAB + "-p=\"" + webapp.getFullPath() + "\" -n=\"" + name + "\"");
}
/*
* If we're setting adaptrex, make sure it's not already configured
*/
boolean hasAdaptrex = true;
if (webapp.getAdaptrex() == null) {
if (adaptrexFolder == null) hasAdaptrex = false;
else hasAdaptrex = webappService.setAdaptrexJS(webapp, adaptrexFolder);
} else if (adaptrexFolder != null) {
String opt = "-a" +
(adaptrexFolder.equals(JavaScriptFramework.DEFAULT) ? "" : "=" + adaptrexFolder);
previouslyConfigured.add(TAB + "-p=\"" + webapp.getFullPath() + "\" " + opt);
}
/*
* If we're setting extjs, make sure it's not already configured
*/
boolean hasExt = true;
if (webapp.getExt() == null) {
if (extFolder == null) hasExt = false;
else hasExt = webappService.setExtJS(webapp, extFolder);
} else if (extFolder != null) {
String opt = "-e" +
(extFolder.equals(JavaScriptFramework.DEFAULT) ? "" : "=" + extFolder);
previouslyConfigured.add(TAB + "-p=\"" + webapp.getFullPath() + "\" " + opt);
}
/*
* If we're setting adaptrexjs, make sure it's not already configured
*/
boolean hasSenchaTouch = true;
if (webapp.getSenchaTouch() == null) {
if (senchaTouchFolder == null) hasSenchaTouch = false;
else hasSenchaTouch = webappService.setSenchaTouch(webapp, senchaTouchFolder);
} else if (senchaTouchFolder != null) {
String opt = "-s" +
(senchaTouchFolder.equals(JavaScriptFramework.DEFAULT) ? "" : "=" + senchaTouchFolder);
previouslyConfigured.add(TAB + "-p=\"" + webapp.getFullPath() + "\" " + opt);
}
/*
* If we don't at a name, adaptrex or Ext/SenchaTouch, drop out
*/
if (!hasName) logService.log(Log.ERROR, "Missing Webapp Name",
"The webapp you are importing does not have a name already configured. In order to" + CR +
"import this webapp into your environment, you need to specify a name by including" + CR +
"the following option with your import command:" + CR +
TAB + "-sn=\"Webapp Name\""
);
if (!hasAdaptrex) logService.log(Log.ERROR, "Missing Adaptrex Folder",
"The webapp you are importing does not have an AdaptrexJS folder already configured." + CR +
"In order to import this webapp into your environment you need to specify an AdaptrexJS" + CR +
"version to use by including one of the following option with your import command:" + CR +
TAB + "-a=adaptrex-js-1.0.0" + CR +
TAB + "-a (setting this option without an explicit folder uses your only AdaptrexJS folder)"
);
if (!hasExt && !hasSenchaTouch) logService.log(Log.ERROR, "Missing ExtJS or Sencha Touch Folder",
"The webapp you are importing does not have an ExtJS or SenchaTouch folder already configured." + CR +
"In order to import this webapp into your environment you need to specify an ExtJS or Sencha Touch" + CR +
"version to use by including one of the following option with your import command:" + CR +
TAB + "-e=ext-js-4.1.1a" + CR +
TAB + "-e (setting this option without an explicit folder uses your only ExtJS folder)" + CR +
TAB + "-e=sencha-touch-2.1.0" + CR +
TAB + "-e (setting this option without an explicit folder uses your only Sencha Touch folder)"
);
if (!hasName || !hasAdaptrex || (!hasExt && !hasSenchaTouch)) return null;
/*
* If we have some previously configured settings, notify the user that we are not changing
* them and that they will need to manually run the configuration tools to change them
*/
if (previouslyConfigured.size() > 0) {
String cmds = StringUtils.join(previouslyConfigured, CR);
logService.log(Log.WARNING, "Webapp previously configured",
"The webapp at " + path + " has successfully" + CR +
"been added to your environment but the webapp itself has been previously" + CR +
"configured. The existing webapp configuration has been retained to ensure" + CR +
"compatibility. If you still wish to change the configuration of the existing " + CR +
"webapp, run one or more of the of the following commands:" + CR +
cmds
);
}
/*
* Save the new webapp and also add it to the environment
*/
webappService.saveWebapp(webapp);
addWebappToEnvironment(webapp);
saveEnvironment();
logService.log(Log.SUCCESS, "Webapp successfully added to environment");
/*
* Create bootstrap files
*/
if (webapp.getExt() != null)
compileService.createBootstrap(webapp, JavaScriptFramework.EXTJS);
if (webapp.getSenchaTouch() != null)
compileService.createBootstrap(webapp, JavaScriptFramework.SENCHA_TOUCH);
/*
* Add default themes
*/
if (extFolder != null) webapp.getExt().importTheme(webapp);
if (senchaTouchFolder != null) webapp.getSenchaTouch().importTheme(webapp);
return webapp;
}