update_xcode_plugins 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f023d4bc2dd0a3f9de58bff30ae2ffb2c88fee4
4
+ data.tar.gz: 303a5d87913f76c38f6027e03733c56183bc52d1
5
+ SHA512:
6
+ metadata.gz: f0ab4d2af6afe7f89b7d730ae57a99135996561189ea96d7af3304c37668737db6b8b6b88a63d39f798b58934bd88d187cb58964e2c69d0f085ecea4372fddfa
7
+ data.tar.gz: fef9eaa666d9dd60c8bb5b9b4104f4c158ab4a7913157cb13dbc2bd77f0954c0ccefd6bf3f5e133dec56c2220b37d37ff73e97c31d570ad17dbdbd9e3725c687
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ ### $ update\_xcode\_plugins
2
+
3
+ This tool adds the missing UUIDs into the installed Xcode plug-ins so that they can be loaded by newer versions of Xcode.
4
+
5
+ You can choose to run it once or install a **launch agent** that will trigger the tool every time any of your installed plugins are modified or Xcode/Xcode-beta gets updated.
6
+
7
+ #### Install
8
+
9
+ ```shell
10
+ $ gem install update_xcode_plugins
11
+ ```
12
+
13
+ (if using system ruby: `sudo gem install update_xcode_plugins`)
14
+
15
+ #### Usage
16
+
17
+ In Terminal:
18
+
19
+ ```shell
20
+ $ update_xcode_plugins
21
+ ```
22
+
23
+ ![](http://i.imgur.com/XQZHSND.png)
24
+
25
+ ##### Other options
26
+
27
+ For a dry run,
28
+
29
+ ```shell
30
+ $ update_xcode_plugins --dry-run
31
+ ```
32
+
33
+ ![](http://i.imgur.com/SPdbt2V.png)
34
+
35
+ To install the launch agent,
36
+
37
+ ```shell
38
+ $ update_xcode_plugins --install-launch-agent
39
+ ```
40
+
41
+ or to uninstall the launch agent,
42
+
43
+ ```shell
44
+ $ update_xcode_plugins --uninstall-launch-agent
45
+ ```
46
+
47
+ #### Contact
48
+
49
+ [@inket](https://github.com/inket) / [@inket](https://twitter.com/inket) on Twitter / [mahdi.jp](https://mahdi.jp)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/update_xcode_plugins'
4
+
5
+ if CLI.uninstall_launch_agent?
6
+ LaunchAgent.uninstall
7
+ elsif CLI.install_launch_agent?
8
+ LaunchAgent.install(__FILE__)
9
+ else
10
+ PluginsUpdater.update_plugins
11
+ end
data/lib/bundle.rb ADDED
@@ -0,0 +1,37 @@
1
+ require_relative 'cli'
2
+
3
+ class Bundle
4
+ attr_accessor :path
5
+
6
+ def initialize(path)
7
+ self.path = path.strip
8
+ end
9
+
10
+ def valid?
11
+ false
12
+ end
13
+
14
+ def info_path
15
+ "#{path}/Contents/Info.plist"
16
+ end
17
+
18
+ def version
19
+ defaults_read('CFBundleShortVersionString')
20
+ end
21
+
22
+ def defaults_read(key)
23
+ plist_path = "#{path}/Contents/Info"
24
+ `defaults read "#{plist_path}" #{key}`.strip
25
+ end
26
+
27
+ def defaults_write(*args)
28
+ plist_path = "#{path}/Contents/Info"
29
+ command = "defaults write \"#{plist_path}\" #{args.join(' ')}"
30
+
31
+ if CLI.dry_run?
32
+ puts command
33
+ else
34
+ `#{command}`.strip
35
+ end
36
+ end
37
+ end
data/lib/cli.rb ADDED
@@ -0,0 +1,13 @@
1
+ class CLI
2
+ def self.dry_run?
3
+ ARGV.include?('-d') || ARGV.include?('--dry-run')
4
+ end
5
+
6
+ def self.install_launch_agent?
7
+ ARGV.include?('--install-launch-agent')
8
+ end
9
+
10
+ def self.uninstall_launch_agent?
11
+ ARGV.include?('--uninstall-launch-agent')
12
+ end
13
+ end
@@ -0,0 +1,80 @@
1
+ class LaunchAgent
2
+ attr_accessor :bin_path
3
+
4
+ def self.install(bin_path)
5
+ LaunchAgent.new(bin_path).install
6
+ puts 'Done.'
7
+ end
8
+
9
+ def self.uninstall
10
+ LaunchAgent.new.uninstall
11
+ puts 'Done.'
12
+ end
13
+
14
+ def initialize(bin_path = nil)
15
+ self.bin_path = bin_path
16
+ end
17
+
18
+ def install
19
+ File.open(launch_agent_path, 'w') do |file|
20
+ file.write(xml)
21
+ end
22
+
23
+ `launchctl load "#{launch_agent_path}"`
24
+ end
25
+
26
+ def uninstall
27
+ `launchctl unload "#{launch_agent_path}"`
28
+
29
+ File.delete(launch_agent_path) if File.exist?(launch_agent_path)
30
+ end
31
+
32
+ def identifier
33
+ 'jp.mahdi.update_xcode_plugins'
34
+ end
35
+
36
+ def launch_agent_path
37
+ "#{Dir.home}/Library/LaunchAgents/#{identifier}.plist"
38
+ end
39
+
40
+ def watch_paths
41
+ [
42
+ '/Applications/Xcode.app',
43
+ '/Applications/Xcode-beta.app',
44
+ '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/'
45
+ ]
46
+ end
47
+
48
+ def watch_paths_xml
49
+ watch_paths.map do |path|
50
+ "<string>#{path}</string>"
51
+ end.join("\n")
52
+ end
53
+
54
+ def xml
55
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
56
+ <!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
57
+ <plist version=\"1.0\">
58
+ <dict>
59
+ <key>Label</key>
60
+ <string>#{identifier}</string>
61
+ <key>ProgramArguments</key>
62
+ <array>
63
+ <string>/usr/bin/env</string>
64
+ <string>ruby</string>
65
+ <string>#{bin_path}</string>
66
+ </array>
67
+ <key>RunAtLoad</key>
68
+ <false/>
69
+ <key>StandardErrorPath</key>
70
+ <string>/tmp/#{identifier}.err</string>
71
+ <key>StandardOutPath</key>
72
+ <string>/tmp/#{identifier}.out</string>
73
+ <key>WatchPaths</key>
74
+ <array>
75
+ #{watch_paths_xml}
76
+ </array>
77
+ </dict>
78
+ </plist>"
79
+ end
80
+ end
@@ -0,0 +1,47 @@
1
+ require_relative 'xcode'
2
+ require_relative 'xcode_plugin'
3
+
4
+ class PluginsUpdater
5
+ def self.update_plugins
6
+ xcodes = Xcode.find_xcodes
7
+
8
+ if xcodes.empty?
9
+ puts "Didn't find any Xcode installed on your system."
10
+ return
11
+ else
12
+ puts 'Found:'
13
+ puts xcodes
14
+ end
15
+
16
+ puts separator
17
+
18
+ plugins = XcodePlugin.find_plugins
19
+
20
+ if plugins.empty?
21
+ puts "Didn't find any Xcode Plug-in installed on your system."
22
+ return
23
+ else
24
+ puts 'Plugins:'
25
+ puts plugins
26
+ end
27
+
28
+ puts separator
29
+ puts 'Updating...'
30
+
31
+ uuids = xcodes.collect(&:uuid)
32
+ uuids.each do |uuid|
33
+ plugins.each do |plugin|
34
+ if plugin.add_uuid(uuid) && !CLI.dry_run?
35
+ puts "Added #{uuid} to #{plugin}"
36
+ end
37
+ end
38
+ end
39
+
40
+ puts separator
41
+ puts 'Done.'
42
+ end
43
+
44
+ def self.separator
45
+ '-----------------------------------------------'
46
+ end
47
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'plugins_updater'
2
+ require_relative 'launch_agent'
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ class UpdateXcodePlugins
2
+ VERSION = '0.1'
3
+ end
data/lib/xcode.rb ADDED
@@ -0,0 +1,30 @@
1
+ require_relative 'bundle'
2
+
3
+ class Xcode < Bundle
4
+ def self.find_xcodes
5
+ output = `mdfind kMDItemCFBundleIdentifier = "com.apple.dt.Xcode"`
6
+ output.lines.collect do |xcode_path|
7
+ Xcode.from_bundle(xcode_path)
8
+ end.compact.keep_if(&:valid?)
9
+ end
10
+
11
+ def self.from_bundle(path)
12
+ xcode = new(path)
13
+ xcode.valid? ? xcode : nil
14
+ end
15
+
16
+ def valid?
17
+ is_app = path.end_with?('.app')
18
+ has_info = File.exist?(info_path)
19
+
20
+ is_app && has_info
21
+ end
22
+
23
+ def uuid
24
+ defaults_read('DVTPlugInCompatibilityUUID')
25
+ end
26
+
27
+ def to_s
28
+ "Xcode (#{version}) [#{uuid}]: #{path}"
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ require_relative 'bundle'
2
+
3
+ class XcodePlugin < Bundle
4
+ def self.find_plugins
5
+ plugins_path = "#{Dir.home}/Library/Application Support/Developer/Shared/Xcode/Plug-ins/"
6
+
7
+ unless Dir.exist?(plugins_path)
8
+ puts "Couldn't find Plug-ins directory."
9
+ return []
10
+ end
11
+
12
+ Dir.entries(plugins_path).collect do |plugin_path|
13
+ XcodePlugin.from_bundle("#{plugins_path}#{plugin_path}")
14
+ end.compact.keep_if(&:valid?)
15
+ end
16
+
17
+ def self.from_bundle(path)
18
+ plugin = new(path)
19
+ plugin.valid? ? plugin : nil
20
+ end
21
+
22
+ def valid?
23
+ not_hidden = !path.split('/').last.start_with?('.')
24
+ is_plugin = path.end_with?('.xcplugin')
25
+ has_info = File.exist?(info_path)
26
+
27
+ not_hidden && is_plugin && has_info
28
+ end
29
+
30
+ def has_uuid?(uuid)
31
+ defaults_read('DVTPlugInCompatibilityUUIDs').include?(uuid)
32
+ end
33
+
34
+ def add_uuid(uuid)
35
+ return false if has_uuid?(uuid)
36
+
37
+ defaults_write('DVTPlugInCompatibilityUUIDs', '-array-add', uuid)
38
+ true
39
+ end
40
+
41
+ def to_s
42
+ "#{path.split('/').last.sub(/\.xcplugin$/, '')} (#{version})"
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: update_xcode_plugins
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Mahdi Bchetnia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This tool adds the missing UUIDs into the installed Xcode plug-ins so
14
+ that they can be loaded by newer versions of Xcode.
15
+ email:
16
+ - injekter@gmail.com
17
+ executables:
18
+ - update_xcode_plugins
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE
23
+ - README.md
24
+ - bin/update_xcode_plugins
25
+ - lib/bundle.rb
26
+ - lib/cli.rb
27
+ - lib/launch_agent.rb
28
+ - lib/plugins_updater.rb
29
+ - lib/update_xcode_plugins.rb
30
+ - lib/version.rb
31
+ - lib/xcode.rb
32
+ - lib/xcode_plugin.rb
33
+ homepage: http://github.com/inket/update_xcode_plugins
34
+ licenses:
35
+ - MIT
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.3.6
51
+ requirements: []
52
+ rubyforge_project: update_xcode_plugins
53
+ rubygems_version: 2.4.8
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Updates Xcode plug-ins to match the installed Xcode versions.
57
+ test_files: []