Permalink
Browse files

clean specific directories resolves #10

  • Loading branch information...
1 parent 7e17390 commit 186114ae64d1fbd230743419a8bcd2ce478199ea Joe Ferraro committed Aug 16, 2012
Showing with 90 additions and 5 deletions.
  1. +2 −1 Side Bar.sublime-menu
  2. +8 −0 commands/clean_directories.rb
  3. +18 −0 mavensmate.py
  4. +39 −2 support/lib/mavensmate.rb
  5. +23 −2 support/lib/metadata_helper.rb
View
@@ -5,7 +5,8 @@
"children":
[
{ "caption": "Compile Selected Files", "command": "delete_metadata", "args": {"files": []} },
- { "caption": "Delete Selected Files from Salesforce Server", "command": "delete_metadata", "args": {"files": []} }
+ { "caption": "Delete Selected Files from Salesforce Server", "command": "delete_metadata", "args": {"files": []} },
+ { "caption": "Refresh From Server", "command": "refresh_directory", "args": {"dirs": []} }
]
}
]
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby -W0
+require File.dirname(File.dirname(__FILE__)) + "/constants.rb"
+include Constants
+ENV["MM_CURRENT_PROJECT_DIRECTORY"] = ARGV[1]
+tmp_file = File.open(ARGV[0], "rb")
+dirs = tmp_file.read
+require LIB_ROOT + "/mavensmate.rb"
+MavensMate.clean_dirs({:dirs => dirs})
View
@@ -81,6 +81,24 @@ def mm_workspace():
workspace = sublime.active_window().active_view().settings().get('mm_workspace')
return workspace
+class RefreshDirectoryCommand(sublime_plugin.WindowCommand):
+ def run (self, dirs):
+ printer = PanelPrinter.get(self.window.id())
+ printer.show()
+ printer.write('\nRefreshing from server\n')
+ dir_string = ','.join(dirs)
+ printer.write(dir_string+'\n')
+ temp = tempfile.NamedTemporaryFile(delete=False, prefix="mm")
+ try:
+ temp.write(dir_string)
+ finally:
+ temp.close()
+ threads = []
+ thread = MetadataAPICall("clean_directories", "'"+temp.name+"' '"+mm_project_directory()+"'")
+ threads.append(thread)
+ thread.start()
+ handle_threads(threads, printer, handle_result, 0)
+
#displays edit project dialog
class EditProjectCommand(sublime_plugin.ApplicationCommand):
def run(command):
View
@@ -19,13 +19,13 @@ def self.new_project(params)
if (params[:pn] == "" || params[:un] == "" || params[:pw] == "")
return alert "Project Name, Salesforce Username, and Salesforce Password are all required fields!"
end
-
+ MetadataHelper.
project_folder = get_project_folder
project_name = params[:pn]
if File.directory?("#{project_folder}#{project_name}")
return alert "Hm, it looks like this project already exists in your project folder."
end
-
+
begin
un = params[:un]
pw = params[:pw]
@@ -305,6 +305,43 @@ def self.compile_project
puts res.to_json
end
end
+
+ def self.clean_dirs(options={})
+ begin
+ hash = { }
+ options[:dirs].split(",").each do |dir|
+ dir_base_name = dir.split("/").last
+ type = MetadataHelper.get_meta_type_by_dir(dir_base_name)[:xml_name]
+ hash[type] = ["*"]
+ end
+ threads = []
+ Thread.abort_on_exception = true
+ client = nil
+ pd = ENV['MM_CURRENT_PROJECT_DIRECTORY']
+ Dir.foreach("#{pd}/src") do |entry| #iterate the metadata folders
+ next if entry.include? "."
+ next if !options[:dirs].include?(entry) #skip the folder if it's not being refreshed
+ Dir.foreach("#{pd}/src/#{entry}") do |subentry| #iterate the files inside those folders
+ next if subentry == '.' || subentry == '..' || subentry == '.svn' || subentry == '.git'
+ FileUtils.rm_r "#{pd}/src/#{entry}/#{subentry}" #delete what's inside
+ end
+ end
+ tmp_dir = MavensMate::FileFactory.put_tmp_directory
+ MavensMate::FileFactory.put_package(tmp_dir, binding, false)
+ client = MavensMate::Client.new
+ threads << Thread.new {
+ thread_client = MavensMate::Client.new({ :sid => client.sid, :metadata_server_url => client.metadata_server_url })
+ project_zip = thread_client.retrieve({ :package => tmp_dir+"/package.xml" })
+ MavensMate::FileFactory.finish_clean(get_project_name, project_zip) #put the metadata in the project directory
+ }
+ threads.each { |aThread| aThread.join }
+ result = { :success => true }
+ puts result.to_json
+ rescue Exception => e
+ result = { :success => false, :message => +e.message + "\n" + e.backtrace.join("\n") }
+ puts result.to_json
+ end
+ end
#wipes local project and rewrites with server copies based on current project's package.xml, preserves svn/git
def self.clean_project(options={})
@@ -1,6 +1,6 @@
module MetadataHelper
- MM_API_VERSION = ENV['MM_API_VERSION'] || "24.0"
+ MM_API_VERSION = ENV['MM_API_VERSION'] || "25.0"
CORE_METADATA_TYPES = [ "ApexClass", "ApexComponent", "ApexPage", "ApexTrigger", "StaticResource" ]
META_DICTIONARY = eval(File.read("#{SUPPORT}/conf/metadata_dictionary"))
CHILD_META_DICTIONARY = eval(File.read("#{SUPPORT}/conf/metadata_children_dictionary"))
@@ -36,5 +36,26 @@ module MetadataHelper
".trigger" => "ApexTrigger",
".resource" => "StaticResource"
}
-
+
+ class << self
+ #returns the metadata definition by suffix (.cls, .trigger, .object, etc.)
+ def get_meta_type_by_suffix(suffix)
+ return META_DICTIONARY.detect {|f| f[:suffix] == suffix }
+ end
+
+ #returns the metadata definition by directory (classes, objects, etc.)
+ def get_meta_type_by_dir(dir)
+ return META_DICTIONARY.detect {|f| f[:directory_name] == dir }
+ end
+
+ #returns the metadata definition by name
+ def get_meta_type_by_name(name)
+ return META_DICTIONARY.detect {|f| f[:xml_name] == name }
+ end
+
+ #returns the metadata definition by name - child types (customfield, listview, etc.)
+ def get_child_meta_type_by_name(name)
+ return CHILD_META_DICTIONARY.detect {|f| f[:xml_name] == name }
+ end
+ end
end

0 comments on commit 186114a

Please sign in to comment.