Package com.adaptrex.tools.webapp

Examples of com.adaptrex.tools.webapp.Webapp


  @Override
  public Webapp loadWebapp(String fullPath) throws IOException {
    Environment env = environmentService.getEnvironment();

    Webapp webapp = new Webapp();
    webapp.setFullPath(fullPath);
   
    /*
     * Create collections to hold our settings, frameworks and webapps for later processing
     */
    Ini ini = new Ini();
    File appSettings = new File(fullPath + "/src/main/webapp/adaptrex/app.config");
    if (!appSettings.exists()) return null;
    ini.load(new FileReader(appSettings));
   
    /*
     * Get our app name
     */
    Ini.Section settingsSection = ini.get(SETTINGS);
    webapp.setName(settingsSection.get("name"));
    webapp.setBasePackage(settingsSection.get(BASE_PACKAGE));
    webapp.setGlobalFolder(settingsSection.get(GLOBAL_FOLDER));
    webapp.setGlobalNamespace(settingsSection.get(GLOBAL_NAMESPACE));
   
   
    /*
     * Get information about our webapp's frameworks
     */
    Ini.Section frameworkSection = ini.get(FRAMEWORKS);
    if (frameworkSection.containsKey(ADAPTREXJS))
      webapp.setAdaptrex(env.getAdaptrexFrameworks().get(frameworkSection.get(ADAPTREXJS)));
    if (frameworkSection.containsKey(EXTJS))
      webapp.setExt(env.getExtFrameworks().get(frameworkSection.get(EXTJS)));
    if (frameworkSection.containsKey(SENCHA_TOUCH))
      webapp.setSenchaTouch(env.getSenchaTouchFrameworks().get(frameworkSection.get(SENCHA_TOUCH)));
    if (frameworkSection.containsKey(ORM))
      webapp.setOrm(frameworkSection.get(ORM));
    if (frameworkSection.containsKey(PRESENTATION))
      webapp.setPresentation(frameworkSection.get(PRESENTATION));
    if (frameworkSection.containsKey(DI))
      webapp.setDi(frameworkSection.get(DI));
     
   
    /*
     * Get our list of pages
     */
    Map<String,String> pagesSection = ini.get(PAGES);
    Map<String,Page> pages = webapp.getPages();
    if (pagesSection != null) {
      for (String key : pagesSection.keySet()) {
        String[] valueParts = pagesSection.get(key).split(",");
        String path = key.replace(".", "/");
        String name = valueParts[0];
View Full Code Here


  private void generatePage() throws ParseException, IOException, TemplateException {
    setGeneratePageOptions();
    cl = commandService.parseCommands(PAGE_USAGE);
    commandService.requireOptions(PAGE_USAGE, "P", "N", "f");
   
    Webapp webapp = commandService.getWebapp();
   
    String pagePath    = cl.getOptionValue("P");
    String namespace  = cl.getOptionValue("N");
    String framework  = cl.getOptionValue("f");
   
View Full Code Here

    return page;
  }

  @Override
  public boolean setName(Webapp webapp, String name) {
    Webapp existing = environmentService.getWebapp(name, true);
    if (existing != null) {
      logService.log(Log.ERROR, "A webapp named \"" + name + "\" already exists");
      return false;
    }
   
View Full Code Here

   
    /*
     * Load Webapps and confirm that the webapp actually exists on the machine
     */
    for (String webappPath : webappPaths) {
      Webapp webapp = webappService.loadWebapp(webappPath);
      if (webapp != null) addWebappToEnvironment(webapp);
        else logService.log(Log.WARNING, "Couldn't find webapp @ " + webappPath);
    }
   
    return true;
View Full Code Here

  /*
   * Get a webapp (optionally suppress warnings)
   */
  @Override
  public Webapp getWebapp(String path, boolean suppressWarning) {
    Webapp webapp = env.getWebapps().get(path.replace("\\/", "."));
   
    if (!suppressWarning && webapp == null)
      logService.log(Log.ERROR, "Could not find webapp at \"" + path + "\"");
    return webapp;
  }
View Full Code Here

      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;
  }
View Full Code Here

    Ini.Section weblibSection = ini.get(Environment.WEBAPPS);
    if (weblibSection == null) weblibSection = ini.add(Environment.WEBAPPS);
    weblibSection.clear();
    Map<String,Webapp> webapps = e.getWebapps();
    for (String key : webapps.keySet()) {
      Webapp webapp = webapps.get(key);
      String webappPath = webapp.getFullPath();
      if (webappPath.endsWith("/")) webappPath = webappPath.substring(0, webappPath.length()-1);
      weblibSection.put(webapp.getName().replace(" ", ".").toLowerCase(), webappPath);
    }
   
    ini.store(configFile);
  }
View Full Code Here

  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);
      }
View Full Code Here

    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);
View Full Code Here

  private void configureWebapp() throws ParseException, IOException {
    setConfigureWebappOptions();
    cl = commandService.parseCommands(WEBAPP_USAGE);
    commandService.requireOneOption(WEBAPP_USAGE, "n", "a", "e", "s", "t", "T");
   
    Webapp webapp = commandService.getWebapp();
    if (webapp == null) return;
   
    boolean doSave = false;
    boolean bootstrapExt = false;
    boolean bootstrapSenchaTouch = false;
   
    /*
     * Set Name
     */
    if (cl.hasOption("n")) {
      String sn = cl.getOptionValue("n");
      if (webappService.setName(webapp, sn)) doSave = true;
    }
   
    /*
     * Set Adaptrex
     */
    if (cl.hasOption("a")) {
      String adaptrex = cl.getOptionValue("a");
      if (adaptrex == null) adaptrex = JavaScriptFramework.DEFAULT;
      if (webappService.setAdaptrexJS(webapp, adaptrex)) {
        doSave = true;
        bootstrapExt = true;
        bootstrapSenchaTouch = true;
      }
    }
   
    /*
     * Set Ext
     */
    if (cl.hasOption("e")) {
      String ext = cl.getOptionValue("e");
      if (ext == null) ext = JavaScriptFramework.DEFAULT;
      if (webappService.setExtJS(webapp, ext)) {
        doSave = true;
        bootstrapExt = true;
      }
    }
   
    /*
     * Set Sencha Touch
     */
    if (cl.hasOption("s")) {
      String sencha = cl.getOptionValue("s");
      if (sencha == null) sencha = JavaScriptFramework.DEFAULT;
      if (webappService.setSenchaTouch(webapp, sencha)) {
        doSave = true;
        bootstrapSenchaTouch = true;
      }
    }   
   
    if (doSave) {
      webappService.saveWebapp(webapp);
      commandService.printLog();
    }
   
    if (bootstrapExt) {
      compileService.createBootstrap(webapp, JavaScriptFramework.EXTJS);
      commandService.printLog();
    }
   
    if (bootstrapSenchaTouch) {
      compileService.createBootstrap(webapp, JavaScriptFramework.SENCHA_TOUCH);
      commandService.printLog();
    }

    /*
     * Add themes
     */
    if (cl.hasOption("t")) {
      try {
        boolean success = webapp.getExt().importTheme(webapp, cl.getOptionValue("t"));
        if (success) {
          commandService.log(Log.SUCCESS, "Theme Successfully Imported", null);
        } else {
          commandService.log(Log.ERROR, "Unspecified Error Importing Theme", null);
        }
      } catch (Exception e) {
        commandService.log(Log.ERROR, "Error Importing Theme", e.getMessage());
      }
      commandService.printLog();
    }
    if (cl.hasOption("T")) {
      try {
        boolean success = webapp.getSenchaTouch().importTheme(webapp, cl.getOptionValue("T"));
        if (success) {
          commandService.log(Log.SUCCESS, "Theme Successfully Imported", null);
        } else {
          commandService.log(Log.ERROR, "Unspecified Error Importing Theme", null);
        }
View Full Code Here

TOP

Related Classes of com.adaptrex.tools.webapp.Webapp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.