def execute(self): if 'username' not in self.params or self.params['username'] == None or self.params['username'] == '': raise MMException('Please enter a Salesforce.com username') if 'password' not in self.params or self.params['password'] == None or self.params['password'] == '': raise MMException('Please enter a Salesforce.com password') if 'org_type' not in self.params or self.params['org_type'] == None or self.params['org_type'] == '': raise MMException('Please select an org type') if 'org_type' in self.params and self.params['org_type'] == "custom" and "org_url" not in self.params: raise MMException('To use a custom org type, please include a org_url parameter') if 'org_type' in self.params and self.params['org_type'] == "custom" and "org_url" in self.params and self.params["org_url"] == "": raise MMException('Please specify the org url') client = MavensMateClient(credentials={ "username" : self.params['username'], "password" : self.params['password'], "org_type" : self.params['org_type'], "org_url" : self.params.get('org_url', None) }) response = { "sid" : client.sid, "user_id" : client.user_id, "metadata_server_url" : client.metadata_server_url, "server_url" : client.server_url, "metadata" : client.get_org_metadata(subscription=self.params.get('subscription', None)), "success" : True } return util.generate_response(response)
def execute(self): if 'username' not in self.params or self.params['username'] == None or self.params['username'] == '': raise MMException('Please enter a Salesforce.com username') if 'password' not in self.params or self.params['password'] == None or self.params['password'] == '': raise MMException('Please enter a Salesforce.com password') if 'org_type' not in self.params or self.params['org_type'] == None or self.params['org_type'] == '': raise MMException('Please select an org type') if 'org_type' in self.params and self.params['org_type'] == "custom" and "org_url" not in self.params: raise MMException('To use a custom org type, please include a org_url parameter') if 'org_type' in self.params and self.params['org_type'] == "custom" and "org_url" in self.params and self.params["org_url"] == "": raise MMException('Please specify the org url') config.logger.debug('=================>') config.logger.debug(self.params) client = MavensMateClient(credentials={ "username" : self.params['username'], "password" : self.params['password'], "org_type" : self.params['org_type'], "org_url" : self.params.get('org_url', None) }) response = { "sid" : client.sid, "user_id" : client.user_id, "metadata_server_url" : client.metadata_server_url, "server_url" : client.server_url, "metadata" : client.get_org_metadata(subscription=self.params.get('subscription', None)), "org_metadata_types" : util.metadata_types(), "success" : True } return util.generate_response(response)
def execute(self): if 'script_name' in self.params: #running an apex script self.params["body"] = util.get_file_as_string( os.path.join(config.project.location, "apex-scripts", self.params["script_name"])) if 'debug_categories' not in self.params and not os.path.isfile( os.path.join(config.project.location, "config", ".apex_script")): self.params["debug_categories"] = [{ "category": "Apex_code", "level": "DEBUG" }] elif os.path.isfile( os.path.join(config.project.location, "config", ".apex_script")): log_settings = util.parse_json_from_file( os.path.join(config.project.location, "config", ".apex_script")) categories = [] levels = log_settings["levels"] for category in levels.keys(): categories.append({ "category": category, "level": levels[category] }) self.params["debug_categories"] = categories elif 'debug_categories' not in self.params: self.params["debug_categories"] = [{ "category": "Apex_code", "level": "DEBUG" }] return_log = self.params.get("return_log", True) execute_result = config.sfdc_client.execute_apex(self.params) result = { 'column': execute_result['column'], 'compileProblem': execute_result['compileProblem'], 'compiled': execute_result['compiled'], 'exceptionMessage': execute_result['exceptionMessage'], 'exceptionStackTrace': execute_result['exceptionStackTrace'], 'line': execute_result['line'], 'success': execute_result['success'], } if 'log' in execute_result and return_log: result['log'] = execute_result['log'] if result['success']: log_apex = config.connection.get_plugin_client_setting( 'mm_log_anonymous_apex', False) if log_apex: location = config.project.log_anonymous_apex( self.params['body'], execute_result['log'], self.params.get("script_name", None)) result["log_location"] = location return util.generate_response(result)
def execute(self): if 'script_name' in self.params: #running an apex script self.params["body"] = util.get_file_as_string(os.path.join(config.project.location,"apex-scripts",self.params["script_name"])) if 'debug_categories' not in self.params and not os.path.isfile(os.path.join(config.project.location,"config",".apex_script")): self.params["debug_categories"] = [ { "category" : "Apex_code", "level" : "DEBUG" } ] elif os.path.isfile(os.path.join(config.project.location,"config",".apex_script")): log_settings = util.parse_json_from_file(os.path.join(config.project.location,"config",".apex_script")) categories = [] levels = log_settings["levels"] for category in levels.keys(): categories.append({ "category" : category, "level" : levels[category] }) self.params["debug_categories"] = categories elif 'debug_categories' not in self.params: self.params["debug_categories"] = [ { "category" : "Apex_code", "level" : "DEBUG" } ] return_log = self.params.get("return_log", True) execute_result = config.sfdc_client.execute_apex(self.params) result = { 'column' : execute_result['column'], 'compileProblem' : execute_result['compileProblem'], 'compiled' : execute_result['compiled'], 'exceptionMessage' : execute_result['exceptionMessage'], 'exceptionStackTrace' : execute_result['exceptionStackTrace'], 'line' : execute_result['line'], 'success' : execute_result['success'], } if 'log' in execute_result and return_log: result['log'] = execute_result['log'] if result['success']: log_apex = config.connection.get_plugin_client_setting('mm_log_anonymous_apex', False) if log_apex: location = config.project.log_anonymous_apex(self.params['body'], execute_result['log'], self.params.get("script_name", None)) result["log_location"] = location return util.generate_response(result)
def execute(self): project = config.project files = self.params.get('files', None) use_tooling_api = config.connection.get_plugin_client_setting('mm_compile_with_tooling_api', False) check_for_conflicts = config.connection.get_plugin_client_setting('mm_compile_check_conflicts', False) compiling_apex_metadata = True for f in files: if f.split('.')[-1] not in util.TOOLING_API_EXTENSIONS: #cannot use tooling api compiling_apex_metadata = False break #when compiling apex metadata, check to see if it is newer on the server if check_for_conflicts and compiling_apex_metadata: if 'action' not in self.params or self.params['action'] != 'overwrite': has_conflict, msg = config.project.conflict_manager.check_for_conflicts(files) if has_conflict: return msg #use tooling api here, if possible if use_tooling_api == True and compiling_apex_metadata and int(float(util.SFDC_API_VERSION)) >= 27: if 'metadata_container' not in project.settings or project.settings['metadata_container'] == None: container_id = project.sfdc_client.get_metadata_container_id() new_settings = project.settings new_settings['metadata_container'] = container_id project.put_settings_file(new_settings) else: container_id = project.settings['metadata_container'] file_ext = files[0].split('.')[-1] try: result = project.sfdc_client.compile_with_tooling_api(files, container_id) except MetadataContainerException as e: project.sfdc_client.delete_mavensmate_metadatacontainers_for_this_user() response = project.sfdc_client.new_metadatacontainer_for_this_user() project.update_setting("metadata_container",response["id"]) return CompileSelectedMetadataCommand(params=self.params,args=self.args).execute() if 'Id' in result and 'State' in result: if result['State'] == 'Completed': project.conflict_manager.refresh_local_store(files=files) return util.generate_response(result) #the user has either chosen not to use the tooling api, or it's non apex metadata else: try: for f in files: if '-meta.xml' in f: corresponding_file = f.split('-meta.xml')[0] if corresponding_file not in files: files.append(corresponding_file) for f in files: if '-meta.xml' in f: continue file_ext = f.split('.')[-1] metadata_type = util.get_meta_type_by_suffix(file_ext) if metadata_type == None: if sys.platform == "win32": dir_parts = f.split("\\") else: dir_parts = f.split("/") if 'documents' in dir_parts: metadata_type = util.get_meta_type_by_name("Document") if metadata_type != None and 'metaFile' in metadata_type and metadata_type['metaFile'] == True: corresponding_file = f + '-meta.xml' if corresponding_file not in files: files.append(corresponding_file) metadata_package_dict = util.get_metadata_hash(files) #debug(metadata_package_dict) tmp = util.put_tmp_directory_on_disk() os.makedirs(os.path.join(tmp,"unpackaged")) #copy files from project directory to tmp for full_file_path in files: if 'package.xml' in full_file_path: continue if config.is_windows: destination = os.path.join(tmp,'unpackaged',full_file_path.split('\src\\')[1]) else: destination = os.path.join(tmp,'unpackaged',full_file_path.split('/src/')[1]) destination_directory = os.path.dirname(destination) if not os.path.exists(destination_directory): os.makedirs(destination_directory) shutil.copy2(full_file_path, destination_directory) package_xml = util.get_package_xml_contents(metadata_package_dict) util.put_package_xml_in_directory(os.path.join(tmp,"unpackaged"), package_xml) zip_file = util.zip_directory(tmp, tmp) deploy_params = { "zip_file" : zip_file, "rollback_on_error" : True, "ret_xml" : True } deploy_result = project.sfdc_client.deploy(deploy_params) d = xmltodict.parse(deploy_result,postprocessor=util.xmltodict_postprocessor) result = d["soapenv:Envelope"]["soapenv:Body"]['checkDeployStatusResponse']['result'] shutil.rmtree(tmp) # Get new properties for the files we just compiled if result['success'] == True: project.conflict_manager.refresh_local_store(files=files) return json.dumps(result) except Exception, e: try: shutil.rmtree(tmp) except: pass return util.generate_error_response(e.message)
def execute(self): project = config.project files = self.params.get('files', None) use_tooling_api = config.connection.get_plugin_client_setting('mm_compile_with_tooling_api', False) check_for_conflicts = config.connection.get_plugin_client_setting('mm_compile_check_conflicts', False) compiling_apex_metadata = True for f in files: if f.split('.')[-1] not in util.TOOLING_API_EXTENSIONS: #cannot use tooling api compiling_apex_metadata = False break #when compiling apex metadata, check to see if it is newer on the server if check_for_conflicts and compiling_apex_metadata: if 'action' not in self.params or self.params['action'] != 'overwrite': has_conflict, msg = config.project.conflict_manager.check_for_conflicts(files) if has_conflict: return msg #use tooling api here, if possible if use_tooling_api == True and compiling_apex_metadata and int(float(util.SFDC_API_VERSION)) >= 27: if 'metadata_container' not in project.settings or project.settings['metadata_container'] == None: container_id = project.sfdc_client.get_metadata_container_id() new_settings = project.settings new_settings['metadata_container'] = container_id project.put_settings_file(new_settings) else: container_id = project.settings['metadata_container'] file_ext = files[0].split('.')[-1] try: result = project.sfdc_client.compile_with_tooling_api(files, container_id) except MetadataContainerException as e: project.sfdc_client.delete_mavensmate_metadatacontainers_for_this_user() response = project.sfdc_client.new_metadatacontainer_for_this_user() project.update_setting("metadata_container",response["id"]) #return CompileSelectedMetadataCommand(params=self.params,args=self.args).execute() #ensure only a single retry result = project.sfdc_client.compile_with_tooling_api(files, response["id"]) if 'Id' in result and 'State' in result: if result['State'] == 'Completed': project.conflict_manager.refresh_local_store(files=files) return util.generate_response(result) #the user has either chosen not to use the tooling api, or it's non apex metadata else: try: for f in files: if '-meta.xml' in f: corresponding_file = f.split('-meta.xml')[0] if corresponding_file not in files: files.append(corresponding_file) for f in files: if '-meta.xml' in f: continue file_ext = f.split('.')[-1] metadata_type = util.get_meta_type_by_suffix(file_ext) if metadata_type == None: if sys.platform == "win32": dir_parts = f.split("\\") else: dir_parts = f.split("/") if 'documents' in dir_parts: metadata_type = util.get_meta_type_by_name("Document") if metadata_type != None and 'metaFile' in metadata_type and metadata_type['metaFile'] == True: corresponding_file = f + '-meta.xml' if corresponding_file not in files: files.append(corresponding_file) metadata_package_dict = util.get_metadata_hash(files) #debug(metadata_package_dict) tmp = util.put_tmp_directory_on_disk() os.makedirs(os.path.join(tmp,"unpackaged")) #copy files from project directory to tmp for full_file_path in files: if 'package.xml' in full_file_path: continue if config.is_windows: destination = os.path.join(tmp,'unpackaged',full_file_path.split('\src\\')[1]) else: destination = os.path.join(tmp,'unpackaged',full_file_path.split('/src/')[1]) destination_directory = os.path.dirname(destination) if not os.path.exists(destination_directory): os.makedirs(destination_directory) shutil.copy2(full_file_path, destination_directory) package_xml = util.get_package_xml_contents(metadata_package_dict) util.put_package_xml_in_directory(os.path.join(tmp,"unpackaged"), package_xml) zip_file = util.zip_directory(tmp, tmp) deploy_params = { "zip_file" : zip_file, "rollback_on_error" : True, "ret_xml" : True } deploy_result = project.sfdc_client.deploy(deploy_params) d = xmltodict.parse(deploy_result,postprocessor=util.xmltodict_postprocessor) result = d["soapenv:Envelope"]["soapenv:Body"]['checkDeployStatusResponse']['result'] shutil.rmtree(tmp) # Get new properties for the files we just compiled if result['success'] == True: project.conflict_manager.refresh_local_store(files=files) return json.dumps(result) except Exception, e: try: shutil.rmtree(tmp) except: pass return util.generate_error_response(e.message)