def __init__(self, basepath, options): self.basepath = os.path.abspath(basepath) self.options = options if not hasattr(self.options, 'no_symlinks'): self.options.no_symlinks = True java_home, exec_suffix = java_utils.JavaHomeAndSuffix() self.java_command = os.path.join(java_home, 'bin', 'java' + exec_suffix) self.javac_command = os.path.join(java_home, 'bin', 'javac' + exec_suffix) self._ValidateXmlFiles() self.app_engine_web_xml = self._ReadAppEngineWebXml() self.app_engine_web_xml.app_root = self.basepath if self.options.app_id: self.app_engine_web_xml.app_id = self.options.app_id if self.options.version: self.app_engine_web_xml.version_id = self.options.version quickstart = xml_parser_utils.BooleanValue( self.app_engine_web_xml.beta_settings.get('java_quickstart', 'false')) if quickstart: web_xml_str, _ = java_quickstart.quickstart_generator( self.basepath) webdefault_xml_str = java_quickstart.get_webdefault_xml() web_xml_str = java_quickstart.remove_mappings( web_xml_str, webdefault_xml_str) self.web_xml = web_xml_parser.WebXmlParser().ProcessXml( web_xml_str) else: self.web_xml = self._ReadWebXml()
def TranslateXmlToYaml(app_engine_web_xml_str, backends_xml_str, web_xml_str, static_files, api_version): """Does xml-string to yaml-string translation, given each separate file text. Processes each xml string into an object representing the xml, and passes these to the translator. Args: app_engine_web_xml_str: text from app_engine_web.xml backends_xml_str: text from backends.xml web_xml_str: text from web.xml static_files: List of static files api_version: current api version Returns: The full text of the app.yaml generated from the xml files. Raises: AppEngineConfigException: raised in processing stage for illegal XML. """ aewx_parser = aewxp.AppEngineWebXmlParser() backends_parser = backends_xml_parser.BackendsXmlParser() web_parser = web_xml_parser.WebXmlParser() app_engine_web_xml = aewx_parser.ProcessXml(app_engine_web_xml_str) backends_xml = backends_parser.ProcessXml(backends_xml_str) web_xml = web_parser.ProcessXml(web_xml_str) translator = AppYamlTranslator(app_engine_web_xml, backends_xml, web_xml, static_files, api_version) return translator.GetYaml()
def TranslateXmlToYamlForDevAppServer(app_engine_web_xml_str, web_xml_str, has_jsps, war_root): """Does xml-string to yaml-string translation, given each separate file text. Processes each xml string into an object representing the xml, and passes these to the translator. This variant is used in the Dev App Server context, where files are served directly from the input war directory, unlike the appcfg case where they are copied or linked into a parallel hierarchy. This means that there is no __static__ directory containing exactly the files that are supposed to be served statically. Args: app_engine_web_xml_str: text from app_engine_web.xml web_xml_str: text from web.xml has_jsps: true if the app has any *.jsp files war_root: the path to the root directory of the war hierarchy Returns: The full text of the app.yaml generated from the xml files. Raises: AppEngineConfigException: raised in processing stage for illegal XML. """ aewx_parser = aewxp.AppEngineWebXmlParser() web_parser = web_xml_parser.WebXmlParser() app_engine_web_xml = aewx_parser.ProcessXml(app_engine_web_xml_str) web_xml = web_parser.ProcessXml(web_xml_str, has_jsps) translator = AppYamlTranslatorForDevAppServer(app_engine_web_xml, web_xml, war_root) return translator.GetYaml()
def _parse_java_configuration(self, app_engine_web_xml_path): """Parse appengine-web.xml and web.xml. Args: app_engine_web_xml_path: A string containing the full path of the .../WEB-INF/appengine-web.xml file. The corresponding .../WEB-INF/web.xml file must also be present. Returns: A tuple where the first element is the parsed appinfo.AppInfoExternal object and the second element is a list of the paths of the files that were used to produce it, namely the input appengine-web.xml file and the corresponding web.xml file. """ with open(app_engine_web_xml_path) as f: app_engine_web_xml_str = f.read() app_engine_web_xml = (app_engine_web_xml_parser.AppEngineWebXmlParser( ).ProcessXml(app_engine_web_xml_str)) quickstart = xml_parser_utils.BooleanValue( app_engine_web_xml.beta_settings.get('java_quickstart', 'false')) web_inf_dir = os.path.dirname(app_engine_web_xml_path) if quickstart: app_dir = os.path.dirname(web_inf_dir) web_xml_str, web_xml_path = java_quickstart.quickstart_generator( app_dir) webdefault_xml_str = java_quickstart.get_webdefault_xml() web_xml_str = java_quickstart.remove_mappings( web_xml_str, webdefault_xml_str) else: web_xml_path = os.path.join(web_inf_dir, 'web.xml') with open(web_xml_path) as f: web_xml_str = f.read() has_jsps = False for _, _, filenames in os.walk(self.application_root): if any(f.endswith('.jsp') for f in filenames): has_jsps = True break web_xml = web_xml_parser.WebXmlParser().ProcessXml( web_xml_str, has_jsps) app_yaml_str = yaml_translator.TranslateXmlToYamlForDevAppServer( app_engine_web_xml, web_xml, self.application_root) config = appinfo.LoadSingleAppInfo(app_yaml_str) return config, [app_engine_web_xml_path, web_xml_path]
def __init__(self, basepath, options): self.basepath = os.path.abspath(basepath) self.options = options if not hasattr(self.options, 'no_symlinks'): self.options.no_symlinks = True java_home, exec_suffix = java_utils.JavaHomeAndSuffix() self.java_command = os.path.join(java_home, 'bin', 'java' + exec_suffix) self.javac_command = os.path.join(java_home, 'bin', 'javac' + exec_suffix) self._ValidateXmlFiles() self.app_engine_web_xml = self._ReadAppEngineWebXml() if self.app_engine_web_xml.env in ['flex', 'flexible']: raise ConfigurationError( 'Flex environment is not supported with this tool.' ' Please use the Cloud SDK to perform a deployment.') self.app_engine_web_xml.app_root = self.basepath if self.options.app_id: self.app_engine_web_xml.app_id = self.options.app_id if self.options.version: self.app_engine_web_xml.version_id = self.options.version quickstart = xml_parser_utils.BooleanValue( self.app_engine_web_xml.beta_settings.get('java_quickstart', 'false')) if quickstart: web_xml_str, _ = java_quickstart.quickstart_generator( self.basepath) webdefault_xml_str = java_quickstart.get_webdefault_xml() web_xml_str = java_quickstart.remove_mappings( web_xml_str, webdefault_xml_str) self.web_xml = web_xml_parser.WebXmlParser().ProcessXml( web_xml_str) else: self.web_xml = self._ReadWebXml()
def TranslateXmlToYaml(app_engine_web_xml_str, web_xml_str, has_jsps): """Does xml-string to yaml-string translation, given each separate file text. Processes each xml string into an object representing the xml, and passes these to the translator. Args: app_engine_web_xml_str: text from app_engine_web.xml web_xml_str: text from web.xml has_jsps: true if the app has any *.jsp files Returns: The full text of the app.yaml generated from the xml files. Raises: AppEngineConfigException: raised in processing stage for illegal XML. """ aewx_parser = aewxp.AppEngineWebXmlParser() web_parser = web_xml_parser.WebXmlParser() app_engine_web_xml = aewx_parser.ProcessXml(app_engine_web_xml_str) web_xml = web_parser.ProcessXml(web_xml_str, has_jsps) translator = AppYamlTranslator(app_engine_web_xml, web_xml, [], '1.0') return translator.GetYaml()