Skip to content
This repository
Browse code

deploy to server functionality

  • Loading branch information...
commit 419c98e162fde0e615175f742d68b3fcb96ac0d2 1 parent f75c721
Joe Ferraro authored
7 commands/deploy_to_server.rb
... ... @@ -0,0 +1,7 @@
  1 +#!/usr/bin/env ruby -W0
  2 +require File.dirname(File.dirname(__FILE__)) + "/constants.rb"
  3 +include Constants
  4 +require SUPPORT + "/environment.rb"
  5 +require CONTROLLERS_ROOT + "/deploy_controller.rb"
  6 +ENV["MM_CURRENT_PROJECT_DIRECTORY"] = ARGV[0]
  7 +dispatch :controller => "deploy", :action => "index"
9 mavensmate.py
@@ -88,6 +88,13 @@ def run(command):
88 88 temp_file_name = generate_ui("new_project", mm_workspace())
89 89 launch_mavens_mate_window(temp_file_name)
90 90
  91 +#displays deploy dialog
  92 +class DeployToServerCommand(sublime_plugin.ApplicationCommand):
  93 + def run(command):
  94 + start_local_server()
  95 + temp_file_name = generate_ui("deploy_to_server", mm_project_directory())
  96 + launch_mavens_mate_window(temp_file_name)
  97 +
91 98 #displays new project dialog
92 99 class CheckoutProjectCommand(sublime_plugin.ApplicationCommand):
93 100 def run(command):
@@ -282,7 +289,7 @@ def run(self):
282 289 msg_string = msg_string.replace(":null", "None")
283 290 msg_string = msg_string.replace("namespace\"None", "namespace\":None")
284 291 msg_string = msg_string.replace("\\n", "\\\n")
285   - #print "result is: " + msg_string
  292 + print "result is: " + msg_string
286 293 res = None
287 294 try:
288 295 res = ast.literal_eval(msg_string)
68 support/app/controllers/deploy_controller.rb
... ... @@ -1,9 +1,9 @@
1 1 # encoding: utf-8
2   -require ENV['TM_BUNDLE_SUPPORT'] + '/lib/mavensmate.rb'
3   -require ENV['TM_BUNDLE_SUPPORT'] + '/lib/factory.rb'
4   -require ENV['TM_BUNDLE_SUPPORT'] + '/lib/metadata_helper.rb'
5   -require ENV['TM_BUNDLE_SUPPORT'] + '/lib/object.rb'
6   -require ENV['TM_BUNDLE_SUPPORT'] + '/lib/util.rb'
  2 +require SUPPORT + '/lib/mavensmate.rb'
  3 +require SUPPORT + '/lib/factory.rb'
  4 +require SUPPORT + '/lib/metadata_helper.rb'
  5 +require SUPPORT + '/lib/object.rb'
  6 +require SUPPORT + '/lib/util.rb'
7 7 class DeployController < ApplicationController
8 8
9 9 include MetadataHelper
@@ -11,16 +11,16 @@ class DeployController < ApplicationController
11 11 layout "base", :only => [:index, :index_new, :show_compile_result]
12 12
13 13 def index
14   - if File.not.exist? "#{ENV['TM_PROJECT_DIRECTORY']}/config/.org_metadata"
15   - MavensMate.build_index
16   - else
17   - confirmed = TextMate::UI.request_confirmation(
18   - :title => "MavensMate",
19   - :prompt => "Would you like to refresh the local index of your Salesforce.com org's metadata?",
20   - :button1 => "Refresh",
21   - :button2 => "No")
22   - end
23   -
  14 + # if File.not.exist? "#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/config/.org_metadata"
  15 + # MavensMate.build_index
  16 + # else
  17 + # confirmed = TextMate::UI.request_confirmation(
  18 + # :title => "MavensMate",
  19 + # :prompt => "Would you like to refresh the local index of your Salesforce.com org's metadata?",
  20 + # :button1 => "Refresh",
  21 + # :button2 => "No")
  22 + # end
  23 + #MavensMate.build_index
24 24 connections = []
25 25 begin
26 26 pconfig = MavensMate.get_project_config
@@ -38,20 +38,20 @@ def index
38 38 end
39 39
40 40 changesets = []
41   - if File.directory?("#{ENV['TM_PROJECT_DIRECTORY']}/changesets")
42   - Dir.foreach("#{ENV['TM_PROJECT_DIRECTORY']}/changesets") do |c|
43   - next if c == "." or c == ".."
44   - changesets.push(c)
45   - end
46   - end
  41 + # if File.directory?("#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/changesets")
  42 + # Dir.foreach("#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/changesets") do |c|
  43 + # next if c == "." or c == ".."
  44 + # changesets.push(c)
  45 + # end
  46 + # end
47 47
48   - MavensMate.build_index if confirmed
49   - meta_array = eval(File.read("#{ENV['TM_PROJECT_DIRECTORY']}/config/.org_metadata")) #=> comprehensive list of server metadata
50   - render "_deploy", :locals => { :meta_array => meta_array, :child_metadata_definition => CHILD_META_DICTIONARY, :connections => connections, :changesets => changesets }
  48 + #MavensMate.build_index if confirmed
  49 + #meta_array = eval(File.read("#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/config/.org_metadata")) #=> comprehensive list of server metadata
  50 + render "_deploy", :locals => { :child_metadata_definition => CHILD_META_DICTIONARY, :connections => connections, :changesets => changesets }
51 51 end
52 52
53 53 def index_new
54   - # if File.not.exist? "#{ENV['TM_PROJECT_DIRECTORY']}/config/.org_metadata"
  54 + # if File.not.exist? "#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/config/.org_metadata"
55 55 # MavensMate.build_index
56 56 # else
57 57 # confirmed = TextMate::UI.request_confirmation(
@@ -80,15 +80,15 @@ def index_new
80 80 end
81 81
82 82 changesets = []
83   - if File.directory?("#{ENV['TM_PROJECT_DIRECTORY']}/changesets")
84   - Dir.foreach("#{ENV['TM_PROJECT_DIRECTORY']}/changesets") do |c|
  83 + if File.directory?("#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/changesets")
  84 + Dir.foreach("#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/changesets") do |c|
85 85 next if c == "." or c == ".."
86 86 changesets.push(c)
87 87 end
88 88 end
89 89
90 90 MavensMate.build_index if confirmed
91   - meta_array = eval(File.read("#{ENV['TM_PROJECT_DIRECTORY']}/config/.org_metadata")) #=> comprehensive list of server metadata
  91 + meta_array = eval(File.read("#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/config/.org_metadata")) #=> comprehensive list of server metadata
92 92 render "_deploy_compare", :locals => { :meta_array => meta_array, :child_metadata_definition => CHILD_META_DICTIONARY, :connections => connections, :changesets => changesets }
93 93 end
94 94
@@ -113,16 +113,16 @@ def deploy_metadata
113 113 is_check_only = params[:check_only]
114 114 result = MavensMate.deploy_to_server(params)
115 115 result = MavensMate::Util.parse_deploy_response(result)
116   - `osascript '#{ENV['TM_BUNDLE_SUPPORT']}/osx/growl.scpt' 'Deploy complete'`
  116 + `osascript '#{SUPPORT}/osx/growl.scpt' 'Deploy complete'`
117 117
118 118 require 'erb'
119   - template = ERB.new File.new("#{ENV['TM_BUNDLE_SUPPORT']}/app/views/deploy/_async_deploy_result.html.erb").read, nil, "-"
  119 + template = ERB.new File.new("#{SUPPORT}/app/views/deploy/_async_deploy_result.html.erb").read, nil, "-"
120 120 erb = template.result(binding)
121   - src = File.new("#{ENV['TM_PROJECT_DIRECTORY']}/config/.async_deploy_result.html", "w")
  121 + src = File.new("#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/config/.async_deploy_result.html", "w")
122 122 src.puts(erb)
123 123 src.close
124 124 MavensMate.close_deploy_window
125   - `open "#{ENV['TM_PROJECT_DIRECTORY']}/config/.async_deploy_result.html"`
  125 + `open "#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/config/.async_deploy_result.html"`
126 126 rescue Exception => e
127 127 TextMate::UI.alert(:warning, "MavensMate", e.message + "\n" + e.backtrace.join("\n"))
128 128 end
@@ -135,7 +135,7 @@ def deploy_metadata
135 135 result = MavensMate.deploy_to_server(params)
136 136 result = MavensMate::Util.parse_deploy_response(result)
137 137 render "_deploy_result", :locals => { :result => result, :is_check_only => params[:check_only] }
138   - `osascript '#{ENV['TM_BUNDLE_SUPPORT']}/osx/growl.scpt' 'Deploy complete'`
  138 + `osascript '#{SUPPORT}/osx/growl.scpt' 'Deploy complete'`
139 139 rescue Exception => e
140 140 TextMate::UI.alert(:warning, "MavensMate", e.message + "\n" + e.backtrace.join("\n"))
141 141 end
@@ -151,7 +151,7 @@ def show_compile_result
151 151 file_name = message[:file_name]
152 152 fns = message[:file_name].split("/")
153 153 file_name = fns[fns.length - 1]
154   - full_path = "#{ENV['TM_PROJECT_DIRECTORY']}/src/#{message[:file_name]}"
  154 + full_path = "#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/src/#{message[:file_name]}"
155 155 full_path.gsub!(/unpackaged\//, '')
156 156 TextMate.go_to(:file => full_path, :line => message[:line_number], :column => message[:column_number])
157 157 rescue
231 support/app/views/deploy/_deploy.html.erb
@@ -100,15 +100,9 @@
100 100 <label for="cname" style="font-weight:bold;">Changeset Name</label>
101 101 <input class="xlarge" size="100" type="text" id="cname">
102 102 </div> -->
103   - <div class="clearfix">
104   - <label>
105   - <input type="checkbox" id="set_and_forget" style="margin:0px;width:32px;"/>
106   - <div>Set and Forget</div>
107   - </label>
108   - </div>
109   - <div id="deploy_info" style="display:none;" class="alert-message block-message info">
  103 +<!-- <div id="deploy_info" style="display:none;" class="alert-message block-message info">
110 104 <p><strong>This deployment will run in async mode.</strong></p>
111   - </div>
  105 + </div> -->
112 106
113 107 </fieldset>
114 108 </form>
@@ -127,15 +121,16 @@
127 121
128 122 <div id="metadata">
129 123
130   - <form class="form-stacked" style="padding-left:15px;margin-bottom:5px;">
  124 + <form class="form-stacked" style="padding-left:5px;margin-bottom:2px;">
131 125 <fieldset>
132   - <div class="clearfix">
  126 +<!-- <div class="clearfix">
133 127 <label for="ptype">Package Type</label>
134 128 <select id="ptype">
135 129 <option>Custom</option>
136 130 <option>Changeset</option>
137 131 </select>
138   - </div>
  132 + </div> -->
  133 + <a href="javascript:void(0)" class="btn success" onclick="refresh_index()">Refresh Metadata From Server</a>
139 134 <div class="clearfix" id="changesetwrapper" style="display:none">
140 135 <label for="cset">Changeset</label>
141 136 <select id="cset">
@@ -162,7 +157,7 @@
162 157 <div id="project_wrapper">
163 158
164 159 <div id="filter">
165   - <input type="text" id="txtFilter" style="width:200px" />
  160 + <input type="text" id="txtFilter" style="width:165px" />
166 161 <a href="#" id="btnClearFilter" onclick="clearFilter();" class="btn small error" style="visibility:invisible;opacity:0;font-weight:bold;position:relative;top:1px;right:30px;padding:4px 7px 4px;">X</a>
167 162 <a href="#" id="btnSelectAll" class="btn small" style="font-weight:normal;padding:4px 7px 4px;">all</a>
168 163 <a href="#" id="btnDeselectAll" class="btn small" style="font-weight:normal;padding:4px 7px 4px;">none</a>
@@ -171,39 +166,7 @@
171 166 <div id="treewrapper">
172 167 <div id="tree">
173 168 <ul>
174   - <% meta_array.each do |hash| %>
175   - <%
176   - next if !hash[:children]
177   - next if hash[:children].size == 0
178   - class_name = (hash[:children] && hash[:children].size > 0) ? "folder" : ""
179   - %>
180   - <li data="level: 1, hasChildTypes: <%=hash[:hasChildTypes]%>, inFolder: <%=hash[:inFolder]%>" id="<%= hash[:key] %>" class="folder level1"><%= hash[:title] %>
181   - <% if hash[:children] %>
182   - <ul>
183   - <% hash[:children].each do |child| %>
184   - <% child_class_name = (child[:children] && child[:children].size > 0) ? "folder" : "" %>
185   - <li data="level: 2" id="<%= child[:key] %>" class="<%= child_class_name %> level2"><%= child[:title] %>
186   - <% if child[:children] && child[:children].size > 0 %>
187   - <ul>
188   - <% child[:children].each do |gchild| %>
189   - <li data="level: 3" class="level3"><%= gchild[:title] %>
190   - <% if gchild[:children] && gchild[:children].size > 0 %>
191   - <ul>
192   - <% gchild[:children].each do |ggchild| %>
193   - <li data="level: 4" class="level4"><%= ggchild[:title] %></li>
194   - <% end %>
195   - </ul>
196   - <% end %>
197   - </li>
198   - <% end %>
199   - </ul>
200   - <% end %>
201   - </li>
202   - <% end %>
203   - </ul>
204   - <% end %>
205   - </li>
206   - <% end %>
  169 +
207 170 </ul>
208 171 </div>
209 172 <div id="info"></div>
@@ -232,12 +195,14 @@
232 195 <div class="loading_indicator"></div>
233 196 </div>
234 197 <div class="deploy_wait_description">
235   - Deploying to <span id="where"></span>.<br/><br/>
236   - Do not close or minimize this window.
  198 + Indexing metadata...
237 199 </div>
238 200
239 201
240 202 <script type="text/javascript">
  203 + var mm_cpd = '<%= ENV["MM_CURRENT_PROJECT_DIRECTORY"] %>';
  204 + var has_indexed_metadata = <%= File.exist? "#{ENV["MM_CURRENT_PROJECT_DIRECTORY"]}/config/.org_metadata" %>;
  205 +
241 206 document.title = "Deploy To Server";
242 207
243 208 var child_def = {}
@@ -270,15 +235,7 @@
270 235 return "";
271 236 }
272 237 }
273   -
274   - $("#set_and_forget").click(function() {
275   - if (this.checked) {
276   - $("#deploy_info").show();
277   - } else {
278   - $("#deploy_info").hide();
279   - }
280   - });
281   -
  238 +
282 239 $("#save_changeset").click(function() {
283 240 if (this.checked) {
284 241 $("#changeset_name_wrapper").show();
@@ -286,32 +243,7 @@
286 243 $("#changeset_name_wrapper").hide();
287 244 }
288 245 });
289   -
290   -
291   - function deploy() {
292   - deploy_mode = deployMode();
293   - if (deploy_mode == "async") {
294   - $("#where").html($("#un").val());
295   - $(".deploy_loading").fadeIn();
296   - $(".deploy_wait_description").fadeIn();
297   - }
298   -
299   - $("#result").html(
300   - dispatch({
301   - controller: "deploy",
302   - action: "deploy_metadata",
303   - un: $("#un").val(),
304   - pw: $("#pw").val(),
305   - server_url: $("#server_url").val(),
306   - check_only: isValidateOnly(),
307   - mode: deploy_mode,
308   - tree: get_tree(),
309   - package_type: $("#ptype").val(),
310   - changeset: $("#cset").val()
311   - })
312   - );
313   - }
314   -
  246 +
315 247 function resizeWindowAfterResult() {
316 248 window.resizeTo(800, window.innerHeight);
317 249 window.moveTo(
@@ -321,6 +253,7 @@
321 253 }
322 254
323 255 $(function() {
  256 +
324 257 //if dom elements is removed, we need to resize the window
325 258 $( "body" ).bind(
326 259 "DOMNodeInserted",
@@ -369,21 +302,15 @@
369 302
370 303 $('.tabs').tabs();
371 304
372   - $("#project_wrapper").height($(window).height() - 175)
  305 + $("#project_wrapper").height($(window).height() - 225)
373 306
374 307 var resizeHeight = $("#form").height();
375   - resizeAndCenterWindowByHeight(resizeHeight + 150);
  308 + resizeAndCenterWindowByHeight(resizeHeight + 250);
376 309
377 310 $(window).resize(function() {
378   - $("#project_wrapper").height($(window).height() - 175)
  311 + $("#project_wrapper").height($(window).height() - 225)
379 312 });
380 313
381   - //instantiate and populate metadata tree
382   - $("#tree").dynatree({
383   - persist: false,
384   - checkbox: true,
385   - selectMode: 3
386   - });
387 314
388 315 $.expr[':'].Contains = function(a, i, m) {
389 316 return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
@@ -419,49 +346,27 @@
419 346 // fire the above change event after every letter
420 347 $(this).change();
421 348 });
422   -
423   - $("#tree").dynatree("getRoot").visit(function(node) {
424   - node.expand(false);
425   - });
426 349
427   - var rootNode = $("#tree").dynatree("getRoot");
428   -
429   - function filter_tree(searchTerm) {
430   - var regex = new RegExp(searchTerm,"i");
431   - rootNode.visit(function(node) { 
       
432   - if (node.isVisible() && node.data.title) { 
           
433   - // Filter currently visible non-root nodes. 
           
434   - nodeTitle = node.data.title;
435   -
436   - if ( nodeTitle.match(regex) ) {
437   - // Make sure we and all our parents are visible 
               
438   - node.visitParents(function(node) { 
                   
439   - $(node.li).show(); 
                   
440   - return (node.parent != null); 
               
441   - }, true);
442   -             // Terminate the traversal of this branch since the node matches
443   - return 'skip';
444   - } else {
445   - $(node.li).hide();
446   - }
447   -
448   -
449   - // if (nodeTitle.indexOf(searchTerm) >= 0 || nodeTitleLower.indexOf(searchTerm) >= 0) { 
               
450   - // // Make sure we and all our parents are visible 
               
451   - // node.visitParents(function(node) { 
                   
452   - // $(node.li).show(); 
                   
453   - // return (node.parent != null); 
               
454   - // }, true);
455   - //             // Terminate the traversal of this branch since the node matches
456   - // return 'skip'; 
           
457   - // } else { 
               
458   - // // Hide the node. 
               
459   - // $(node.li).hide(); 
           
460   - // }
461   - }
462   - });
463   - }
  350 + index_org(!has_indexed_metadata);
464 351 });
  352 +
  353 + function filter_tree(searchTerm) {
  354 + var regex = new RegExp(searchTerm,"i");
  355 + rootNode.visit(function(node) {
  356 + if (node.isVisible() && node.data.title) {
  357 + nodeTitle = node.data.title;
  358 + if ( nodeTitle.match(regex) ) {
  359 + node.visitParents(function(node) {
  360 + $(node.li).show();
  361 + return (node.parent != null);
  362 + }, true);
  363 + return 'skip';
  364 + } else {
  365 + $(node.li).hide();
  366 + }
  367 + }
  368 + });
  369 + }
465 370
466 371 function expandAll() {
467 372 $("#tree").dynatree("getRoot").visit(function(node){
@@ -508,5 +413,65 @@
508 413 }
509 414 });
510 415 return false;
511   - });
  416 + });
  417 +
  418 + function showBlanket() { $('.deploy_loading').fadeIn(); }
  419 +
  420 + function hideBlanket() { $('.deploy_loading').hide(); }
  421 +
  422 + var rootNode;
  423 +
  424 + function index_org(refresh) {
  425 + console.log('indexing org')
  426 + console.log(refresh)
  427 + $.ajax({
  428 + type: "GET",
  429 + url: "http://127.0.0.1:7777/metadata/index",
  430 + data: {
  431 + mm_current_project_directory: mm_cpd,
  432 + do_refresh: refresh
  433 + },
  434 + beforeSend: function() { showBlanket(); },
  435 + complete: function(data){
  436 + console.log(data)
  437 + $("#tree").dynatree("destroy")
  438 + $("#tree ul").html(data.responseText);
  439 + $("#tree").dynatree({
  440 + persist: false,
  441 + checkbox: true,
  442 + selectMode: 3
  443 + });
  444 + $("#tree").dynatree("getRoot").visit(function(node) {
  445 + node.expand(false);
  446 + });
  447 + rootNode = $("#tree").dynatree("getRoot");
  448 + hideBlanket();
  449 + }
  450 + });
  451 + }
  452 +
  453 + function refresh_index() {
  454 + index_org(true);
  455 + }
  456 +
  457 + function deploy() {
  458 + $.ajax({
  459 + type: "POST",
  460 + url: "http://127.0.0.1:7777/deploy",
  461 + data: {
  462 + un: $("#un").val(),
  463 + pw: $("#pw").val(),
  464 + server_url: $("#server_url").val(),
  465 + check_only: isValidateOnly(),
  466 + tree: get_tree(),
  467 + mm_current_project_directory: mm_cpd
  468 + },
  469 + beforeSend: function() { showBlanket(); },
  470 + complete: function(data){
  471 + console.log(data)
  472 + $("#result").html(data.responseText);
  473 + hideBlanket();
  474 + }
  475 + });
  476 + }
512 477 </script>
33 support/app/views/deploy/_metadata_tree.html.erb
... ... @@ -0,0 +1,33 @@
  1 +<% meta_array.each do |hash| %>
  2 + <%
  3 + next if !hash[:children]
  4 + next if hash[:children].size == 0
  5 + class_name = (hash[:children] && hash[:children].size > 0) ? "folder" : ""
  6 + %>
  7 + <li data="level: 1, hasChildTypes: <%=hash[:hasChildTypes]%>, inFolder: <%=hash[:inFolder]%>" id="<%= hash[:key] %>" class="folder level1"><%= hash[:title] %>
  8 + <% if hash[:children] %>
  9 + <ul>
  10 + <% hash[:children].each do |child| %>
  11 + <% child_class_name = (child[:children] && child[:children].size > 0) ? "folder" : "" %>
  12 + <li data="level: 2" id="<%= child[:key] %>" class="<%= child_class_name %> level2"><%= child[:title] %>
  13 + <% if child[:children] && child[:children].size > 0 %>
  14 + <ul>
  15 + <% child[:children].each do |gchild| %>
  16 + <li data="level: 3" class="level3"><%= gchild[:title] %>
  17 + <% if gchild[:children] && gchild[:children].size > 0 %>
  18 + <ul>
  19 + <% gchild[:children].each do |ggchild| %>
  20 + <li data="level: 4" class="level4"><%= ggchild[:title] %></li>
  21 + <% end %>
  22 + </ul>
  23 + <% end %>
  24 + </li>
  25 + <% end %>
  26 + </ul>
  27 + <% end %>
  28 + </li>
  29 + <% end %>
  30 + </ul>
  31 + <% end %>
  32 + </li>
  33 +<% end %>
40 support/lib/client.rb
@@ -32,32 +32,34 @@ class Client
32 32 attr_accessor :user_id
33 33 # metadata api endpoint url
34 34 attr_accessor :metadata_server_url
35   -
36   - is_retry = false
37   -
  35 +
38 36 def initialize(creds={})
39 37 HTTPI.log = false
40 38 Savon.configure do |config|
41 39 config.log = false
42 40 end
43 41
44   - begin
45   - if ENV["MM_CURRENT_PROJECT_DIRECTORY"] != ''
46   - yml = YAML::load(File.open(ENV['MM_CURRENT_PROJECT_DIRECTORY'] + "/config/.session"))
47   - self.user_id = yml['user_id']
48   - self.sid = yml['sid']
49   - self.metadata_server_url = yml['metadata_server_url']
50   - self.endpoint = yml['endpoint']
51   - self.pclient = get_partner_client
52   - end
  42 + if ! creds[:override_session]
  43 + begin
  44 + if ENV["MM_CURRENT_PROJECT_DIRECTORY"] != ''
  45 + yml = YAML::load(File.open(ENV['MM_CURRENT_PROJECT_DIRECTORY'] + "/config/.session"))
  46 + self.user_id = yml['user_id']
  47 + self.sid = yml['sid']
  48 + self.metadata_server_url = yml['metadata_server_url']
  49 + self.endpoint = yml['endpoint']
  50 + self.pclient = get_partner_client
  51 + end
53 52
54   - response = self.pclient.request :get_user_info do
55   - soap.header = get_soap_header
  53 + response = self.pclient.request :get_user_info do
  54 + soap.header = get_soap_header
  55 + end
  56 +
  57 + return
  58 + rescue Exception => e
  59 + #exception here means most likely that cached auth creds are no longer valid
  60 + #we're ok with this, the script will attempt another login
  61 + #raise Exception.new(e.message)
56 62 end
57   - #raise Exception.new(response.to_hash.inspect)
58   - return
59   - rescue Exception => e
60   - #raise Exception.new(e.message)
61 63 end
62 64
63 65 if creds[:sid].nil? && creds[:metadata_server_url].nil?
@@ -76,7 +78,7 @@ def initialize(creds={})
76 78 end
77 79
78 80 begin
79   - if ENV["MM_CURRENT_PROJECT_DIRECTORY"] != ''
  81 + if ENV["MM_CURRENT_PROJECT_DIRECTORY"] != '' and ! creds[:override_session]
80 82 src = File.new(ENV["MM_CURRENT_PROJECT_DIRECTORY"]+"/config/.session", "w")
81 83 src.puts("user_id: " + self.user_id)
82 84 src.puts("sid: " + self.sid)
70 support/lib/local_server.rb
@@ -23,6 +23,8 @@ def start_test
23 23 server.mount('/vc', VersionControlServlet)
24 24 server.mount('/auth', AuthenticationServlet)
25 25 server.mount('/test', ApexUnitTestServlet)
  26 + server.mount('/metadata/index', MetadataIndexServlet)
  27 + server.mount('/deploy', DeployServlet)
26 28 server.start
27 29 end
28 30
@@ -44,6 +46,8 @@ def start
44 46 server.mount('/vc', VersionControlServlet)
45 47 server.mount('/auth', AuthenticationServlet)
46 48 server.mount('/test', ApexUnitTestServlet)
  49 + server.mount('/metadata/index', MetadataIndexServlet)
  50 + server.mount('/deploy', DeployServlet)
47 51 server.start
48 52 end
49 53 Process.detach(pid)
@@ -71,11 +75,73 @@ def do_POST(req, resp)
71 75 html = ac.render_to_string "unit_test/_test_result", :locals => { :result => result }
72 76 resp.body = html
73 77 rescue Exception => e
74   - puts e.message + "\n\n" + e.backtrace.join("\n")
75   - resp.body = "TEST RESULT: " + test_result.inspect + "\n\n" + "Request: " + req.inspect + "\n\n" + e.message + "\n\n" + e.backtrace.join("\n")
  78 + #puts e.message + "\n\n" + e.backtrace.join("\n")
  79 + #resp.body = "TEST RESULT: " + test_result.inspect + "\n\n" + "Request: " + req.inspect + "\n\n" + e.message + "\n\n" + e.backtrace.join("\n")
  80 + result = {
  81 + :success => false,
  82 + :message => e.message
  83 + }
  84 + resp.body = result.to_json
76 85 end
77 86 end
78 87 end
  88 +
  89 + #indexes server metadata to the .org_metadata file in the project config folder
  90 + class MetadataIndexServlet < WEBrick::HTTPServlet::AbstractServlet
  91 + def do_GET(req, resp)
  92 + begin
  93 + resp['Content-Type'] = 'html'
  94 + ENV["MM_CURRENT_PROJECT_DIRECTORY"] = req.query["mm_current_project_directory"]
  95 + do_refresh = req.query["do_refresh"]
  96 + metadata_array = nil
  97 + if do_refresh == "true" or do_refresh == true
  98 + metadata_array = MavensMate.build_index
  99 + else
  100 + metadata_array = eval(File.read("#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/config/.org_metadata")) #=> comprehensive list of server metadata
  101 + end
  102 + ac = ApplicationController.new
  103 + html = ac.render_to_string "deploy/_metadata_tree", :locals => { :meta_array => metadata_array }
  104 + resp.body = html
  105 + rescue Exception => e
  106 + resp['Content-Type'] = 'json'
  107 + result = {
  108 + :success => false,
  109 + :message => e.message + "\n\n" + e.backtrace.join("\n")
  110 + }
  111 + resp.body = result.to_json
  112 + end
  113 + end
  114 + end
  115 +
  116 + class DeployServlet < WEBrick::HTTPServlet::AbstractServlet
  117 + def do_POST(req, resp)
  118 + begin
  119 + resp['Content-Type'] = 'html'
  120 + ENV["MM_CURRENT_PROJECT_DIRECTORY"] = req.query["mm_current_project_directory"]
  121 + params = {}
  122 + params[:un] = req.query["un"]
  123 + params[:pw] = req.query["pw"]
  124 + params[:server_url] = req.query["server_url"]
  125 + params[:package] = eval(req.query["tree"])
  126 + params[:check_only] = req.query["check_only"]
  127 + params[:package_type] = "Custom"
  128 + deploy_result = MavensMate.deploy_to_server(params)
  129 + html = nil
  130 + begin
  131 + result = MavensMate::Util.parse_deploy_response(deploy_result)
  132 + ac = ApplicationController.new
  133 + html = ac.render_to_string "deploy/_deploy_result", :locals => { :result => result, :is_check_only => params[:check_only] }
  134 + rescue
  135 + html = '<div id="error_message" class="alert-message error"><p><strong>Deployment Failed!</strong></p><p>'+deploy_result[:message]+'</p></div> '
  136 + end
  137 + resp.body = html
  138 + rescue Exception => e
  139 + result = '<div id="error_message" class="alert-message error"><p><strong>Deployment Failed!</strong></p><p>'+e.message+'</p></div> '
  140 + resp.body = result
  141 + end
  142 + end
  143 + end
  144 +
79 145
80 146 class ProjectServlet < WEBrick::HTTPServlet::AbstractServlet
81 147 def do_POST(req, resp)
123 support/lib/mavensmate.rb
@@ -384,57 +384,30 @@ def self.new_changeset(options={})
384 384
385 385 #deploys project metadata to a salesforce.com server
386 386 def self.deploy_to_server(params)
387   - validate [:internet, :mm_project]
388   -
389 387 begin
390   - if params[:mode] == "async"
391   - endpoint = MavensMate::Util.get_sfdc_endpoint(params[:server_url])
392   - tmp_dir = MavensMate::FileFactory.put_tmp_directory
393   - client = MavensMate::Client.new
394   - if params[:package_type] == "Custom"
395   - hash = params[:package]
396   - deploy = true
397   - MavensMate::FileFactory.put_package(tmp_dir, binding, false)
398   - zip_file = client.retrieve({ :package => "#{tmp_dir}/package.xml" })
399   - else
400   - zip_file = client.retrieve({ :package => "#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/changesets/#{params[:changeset]}/unpackaged/package.xml" })
401   - end
402   - client = MavensMate::Client.new({ :username => params[:un], :password => params[:pw], :endpoint => endpoint })
403   - result = client.deploy({
404   - :zip_file => zip_file,
405   - :deploy_options => "<checkOnly>#{params[:check_only]}</checkOnly><rollbackOnError>true</rollbackOnError>"
406   - })
407   - MavensMate::FileFactory.remove_directory(tmp_dir) unless params[:package_type] != "Custom"
408   - return result
  388 + endpoint = MavensMate::Util.get_sfdc_endpoint(params[:server_url])
  389 + tmp_dir = MavensMate::FileFactory.put_tmp_directory
  390 + client = MavensMate::Client.new
  391 + if params[:package_type] == "Custom"
  392 + hash = params[:package]
  393 + deploy = true
  394 + MavensMate::FileFactory.put_package(tmp_dir, binding, false)
  395 + zip_file = client.retrieve({ :package => "#{tmp_dir}/package.xml" })
409 396 else
410   - puts '<div id="mm_logger">'
411   - TextMate.call_with_progress( :title => "MavensMate", :message => "Deploying to the server") do
412   - endpoint = MavensMate::Util.get_sfdc_endpoint(params[:server_url])
413   - tmp_dir = MavensMate::FileFactory.put_tmp_directory
414   - client = MavensMate::Client.new
415   - if params[:package_type] == "Custom"
416   - hash = params[:package]
417   - deploy = true
418   - MavensMate::FileFactory.put_package(tmp_dir, binding, false)
419   - zip_file = client.retrieve({ :package => "#{tmp_dir}/package.xml" })
420   - else
421   - zip_file = client.retrieve({ :package => "#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/changesets/#{params[:changeset]}/unpackaged/package.xml" })
422   - end
423   - client = MavensMate::Client.new({ :username => params[:un], :password => params[:pw], :endpoint => endpoint })
424   - result = client.deploy({
425   - :zip_file => zip_file,
426   - :deploy_options => "<checkOnly>#{params[:check_only]}</checkOnly><rollbackOnError>true</rollbackOnError>"
427   - })
428   - MavensMate::FileFactory.remove_directory(tmp_dir) unless params[:package_type] != "Custom"
429   - puts "</div>"
430   - return result
431   - end
432   - end
  397 + zip_file = client.retrieve({ :package => "#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/changesets/#{params[:changeset]}/unpackaged/package.xml" })
  398 + end
  399 + client = MavensMate::Client.new({ :username => params[:un], :password => params[:pw], :endpoint => endpoint, :override_session => true })
  400 + result = client.deploy({
  401 + :zip_file => zip_file,
  402 + :deploy_options => "<checkOnly>#{params[:check_only]}</checkOnly><rollbackOnError>true</rollbackOnError>"
  403 + })
  404 + MavensMate::FileFactory.remove_directory(tmp_dir) unless params[:package_type] != "Custom"
  405 + return result
433 406 rescue Exception => e
434   - #alert e.message + "\n" + e.backtrace.join("\n")
435   - puts "</div>"
436 407 MavensMate::FileFactory.remove_directory(tmp_dir)
437   - alert e.message
  408 + #result = { :success => false, :message => e.message + "\n" + e.backtrace.join("\n") }
  409 + result = { :success => false, :message => e.message }
  410 + return result
438 411 end
439 412 end
440 413
@@ -630,41 +603,37 @@ def self.get_project_config
630 603
631 604 #builds server index and stores in .org_metadata
632 605 def self.build_index
633   - mhash = eval(File.read("#{ENV['TM_BUNDLE_SUPPORT']}/conf/metadata_dictionary"))
  606 + mhash = eval(File.read("#{SUPPORT}/conf/metadata_dictionary"))
634 607 mhash.sort! { |a,b| a[:xml_name].downcase <=> b[:xml_name].downcase }
635 608 project_array = []
636 609 progress = 0
637   - threads = []
638   - TextMate.call_with_progress(:title =>'MavensMate',
639   - :summary => 'Building server metadata index',
640   - :details => 'This could take a while, but it\'ll all be worth it!',
641   - :indeterminate => true ) do |dialog|
642   - client = MavensMate::Client.new
643   - mhash.each do |metadata|
644   - threads << Thread.new {
645   - thread_client = MavensMate::Client.new({ :sid => client.sid, :metadata_server_url => client.metadata_server_url })
646   - #progress = progress + 100/mhash.length
647   - #dialog.parameters = {'summary' => 'Retrieving '+metadata[:xml_name],'progressValue' => progress }
648   - begin
649   - project_array.push({
650   - :title => metadata[:xml_name],
651   - :key => metadata[:xml_name],
652   - :isLazy => false,
653   - :isFolder => true,
654   - :selected => false,
655   - :children => thread_client.list(metadata[:xml_name], false, "array"),
656   - :inFolder => metadata[:in_folder],
657   - :hasChildTypes => metadata[:child_xml_names] ? true : false
658   - })
659   - rescue Exception => e
660   - puts e.message + "\n" + e.backtrace.join("\n")
661   - end
662   - }
663   - end
664   - threads.each { |aThread| aThread.join }
665   - end
  610 + threads = []
  611 + client = MavensMate::Client.new
  612 + mhash.each do |metadata|
  613 + threads << Thread.new {
  614 + thread_client = MavensMate::Client.new({ :sid => client.sid, :metadata_server_url => client.metadata_server_url })
  615 + #progress = progress + 100/mhash.length
  616 + #dialog.parameters = {'summary' => 'Retrieving '+metadata[:xml_name],'progressValue' => progress }
  617 + begin
  618 + project_array.push({
  619 + :title => metadata[:xml_name],
  620 + :key => metadata[:xml_name],
  621 + :isLazy => false,
  622 + :isFolder => true,
  623 + :selected => false,
  624 + :children => thread_client.list(metadata[:xml_name], false, "array"),
  625 + :inFolder => metadata[:in_folder],
  626 + :hasChildTypes => metadata[:child_xml_names] ? true : false
  627 + })
  628 + rescue Exception => e
  629 + puts e.message + "\n" + e.backtrace.join("\n")
  630 + end
  631 + }
  632 + end
  633 + threads.each { |aThread| aThread.join }
666 634 project_array.sort! { |a,b| a[:title].downcase <=> b[:title].downcase }
667 635 File.open("#{ENV['MM_CURRENT_PROJECT_DIRECTORY']}/config/.org_metadata", 'w') {|f| f.write(project_array.inspect) }
  636 + return project_array
668 637 end
669 638
670 639 #selects all metadata in tree
2  support/lib/util.rb
@@ -2,7 +2,7 @@ module MavensMate
2 2 module Util
3 3 class << self
4 4
5   - #include MetadataHelper
  5 + include MetadataHelper
6 6
7 7 def get_random_string(len=8)
8 8 o = [('a'..'z'),('A'..'Z')].map{|i| i.to_a}.flatten;

0 comments on commit 419c98e

Please sign in to comment.
Something went wrong with that request. Please try again.