git_compound 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +8 -0
  5. data/Compoundfile +4 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +21 -0
  8. data/README.md +291 -0
  9. data/Rakefile +13 -0
  10. data/bin/console +7 -0
  11. data/bin/setup +5 -0
  12. data/exe/gitcompound +5 -0
  13. data/git_compound.gemspec +33 -0
  14. data/lib/git_compound/builder.rb +93 -0
  15. data/lib/git_compound/command/options.rb +55 -0
  16. data/lib/git_compound/command.rb +113 -0
  17. data/lib/git_compound/component/destination.rb +45 -0
  18. data/lib/git_compound/component/source.rb +53 -0
  19. data/lib/git_compound/component/version/branch.rb +30 -0
  20. data/lib/git_compound/component/version/gem_version.rb +45 -0
  21. data/lib/git_compound/component/version/sha.rb +33 -0
  22. data/lib/git_compound/component/version/tag.rb +30 -0
  23. data/lib/git_compound/component/version/version_strategy.rb +45 -0
  24. data/lib/git_compound/component.rb +78 -0
  25. data/lib/git_compound/dsl/component_dsl.rb +60 -0
  26. data/lib/git_compound/dsl/manifest_dsl.rb +27 -0
  27. data/lib/git_compound/exceptions.rb +16 -0
  28. data/lib/git_compound/lock.rb +64 -0
  29. data/lib/git_compound/logger/colors.rb +123 -0
  30. data/lib/git_compound/logger/core_ext/string.rb +5 -0
  31. data/lib/git_compound/logger.rb +43 -0
  32. data/lib/git_compound/manifest.rb +39 -0
  33. data/lib/git_compound/node.rb +17 -0
  34. data/lib/git_compound/repository/git_command.rb +33 -0
  35. data/lib/git_compound/repository/git_repository.rb +79 -0
  36. data/lib/git_compound/repository/git_version.rb +43 -0
  37. data/lib/git_compound/repository/remote_file/git_archive_strategy.rb +30 -0
  38. data/lib/git_compound/repository/remote_file/github_strategy.rb +54 -0
  39. data/lib/git_compound/repository/remote_file/remote_file_strategy.rb +27 -0
  40. data/lib/git_compound/repository/remote_file.rb +34 -0
  41. data/lib/git_compound/repository/repository_local.rb +81 -0
  42. data/lib/git_compound/repository/repository_remote.rb +12 -0
  43. data/lib/git_compound/repository.rb +19 -0
  44. data/lib/git_compound/task/task.rb +28 -0
  45. data/lib/git_compound/task/task_all.rb +27 -0
  46. data/lib/git_compound/task/task_each.rb +18 -0
  47. data/lib/git_compound/task/task_single.rb +21 -0
  48. data/lib/git_compound/task.rb +22 -0
  49. data/lib/git_compound/version.rb +5 -0
  50. data/lib/git_compound/worker/circular_dependency_checker.rb +31 -0
  51. data/lib/git_compound/worker/component_builder.rb +30 -0
  52. data/lib/git_compound/worker/component_replacer.rb +25 -0
  53. data/lib/git_compound/worker/component_update_dispatcher.rb +64 -0
  54. data/lib/git_compound/worker/component_updater.rb +24 -0
  55. data/lib/git_compound/worker/components_collector.rb +20 -0
  56. data/lib/git_compound/worker/conflicting_dependency_checker.rb +31 -0
  57. data/lib/git_compound/worker/local_changes_guard.rb +47 -0
  58. data/lib/git_compound/worker/name_constraint_checker.rb +20 -0
  59. data/lib/git_compound/worker/pretty_print.rb +18 -0
  60. data/lib/git_compound/worker/task_runner.rb +12 -0
  61. data/lib/git_compound/worker/worker.rb +20 -0
  62. data/lib/git_compound.rb +112 -0
  63. metadata +193 -0
@@ -0,0 +1,64 @@
1
+ module GitCompound
2
+ module Worker
3
+ # Worker that decides whether component
4
+ # should be built, updated or replaced
5
+ #
6
+ class ComponentUpdateDispatcher < Worker
7
+ def initialize(lock)
8
+ @lock = lock
9
+ @print = PrettyPrint.new
10
+ @build = ComponentBuilder.new(lock)
11
+ @update = ComponentUpdater.new(lock)
12
+ @replace = ComponentReplacer.new(lock)
13
+ end
14
+
15
+ def visit_component(component)
16
+ @component = component
17
+ @component_exists = component.destination_exists?
18
+ @repository = component.destination_repository if
19
+ @component_exists
20
+
21
+ case
22
+ when component_needs_building? then strategy = @build
23
+ when component_needs_updating? then strategy = @update
24
+ when component_needs_replacing? then strategy = @replace
25
+ else
26
+ Logger.inline 'Unchanged: '
27
+ @print.visit_component(component)
28
+ @lock.lock_component(component)
29
+ return
30
+ end
31
+
32
+ strategy.visit_component(component)
33
+ end
34
+
35
+ private
36
+
37
+ # Component needs building if it's destination directory
38
+ # does not exist
39
+ #
40
+ def component_needs_building?
41
+ !@component_exists
42
+ end
43
+
44
+ # Component needs updating if it exists, remote origin matches
45
+ # new component origin and HEAD sha has changed
46
+ #
47
+ def component_needs_updating?
48
+ return false unless @component_exists
49
+
50
+ @repository.origin_remote =~ /#{@component.origin}$/ &&
51
+ @repository.head_sha != @component.sha
52
+ end
53
+
54
+ # Component needs replacing if it exists but repository
55
+ # remote origin does not match new component origin
56
+ #
57
+ def component_needs_replacing?
58
+ return false unless @component_exists
59
+
60
+ !(@repository.origin_remote =~ /#{@component.origin}$/)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,24 @@
1
+ module GitCompound
2
+ module Worker
3
+ # Worker that updates component
4
+ #
5
+ class ComponentUpdater < Worker
6
+ def initialize(lock)
7
+ @lock = lock
8
+ @print = PrettyPrint.new
9
+ end
10
+
11
+ def visit_component(component)
12
+ raise "Component `#{component.name}` is not built !" unless
13
+ component.destination_exists?
14
+
15
+ Logger.inline 'Updating: '
16
+ @print.visit_component(component)
17
+
18
+ component.update
19
+
20
+ @lock.lock_component(component)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module GitCompound
2
+ module Worker
3
+ # Worker thas collects are encountered components
4
+ #
5
+ class ComponentsCollector < Worker
6
+ attr_reader :components
7
+
8
+ def initialize(collection)
9
+ raise GitCompoundError, 'Collection should be a Hash' unless
10
+ collection.is_a? Hash
11
+
12
+ @components = collection
13
+ end
14
+
15
+ def visit_component(component)
16
+ @components.store(component.name, component)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ module GitCompound
2
+ module Worker
3
+ # Worker that detects conflicting dependencies
4
+ #
5
+ class ConflictingDependencyChecker < Worker
6
+ # TODO: this should collect all components first
7
+ # using ComponentsCollector worker
8
+ #
9
+ def initialize
10
+ @components = []
11
+ end
12
+
13
+ def visit_component(component)
14
+ if conflict_exists?(component)
15
+ raise ConflictingDependencyError,
16
+ "Conflicting dependency detected in component `#{component.name}`!"
17
+ end
18
+ @components << component
19
+ end
20
+
21
+ private
22
+
23
+ def conflict_exists?(component)
24
+ @components.any? do |other|
25
+ component.destination_path == other.destination_path &&
26
+ !(component == other && component.version == other.version)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,47 @@
1
+ module GitCompound
2
+ module Worker
3
+ # Worker that defends local changes in
4
+ # component repositories
5
+ #
6
+ class LocalChangesGuard < Worker
7
+ def initialize(lock)
8
+ @lock = lock
9
+ end
10
+
11
+ def visit_component(component)
12
+ @component = component
13
+ @repository = component.destination_repository
14
+
15
+ check_uncommited_changes!
16
+ check_untracked_files!
17
+ end
18
+
19
+ private
20
+
21
+ def check_uncommited_changes!
22
+ return unless @repository.uncommited_changes?
23
+
24
+ raise LocalChangesError,
25
+ "Component `#{@component.name}` contains uncommited changes !"
26
+ end
27
+
28
+ def check_untracked_files!
29
+ return unless @repository.untracked_files?(subcomponents_dirs)
30
+
31
+ raise LocalChangesError,
32
+ "Component `#{@component.name}` contains untracked files !"
33
+ end
34
+
35
+ def subcomponents_dirs
36
+ locked_dirs = @lock.components.map { |locked| "#{locked.destination_path}".chop }
37
+ component_subdirs = locked_dirs.select do |locked_dir|
38
+ locked_dir.start_with?(@component.destination_path)
39
+ end
40
+
41
+ component_subdirs.collect do |subdir|
42
+ subdir.sub(/^#{@component.destination_path}/, '').split(File::SEPARATOR).first
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,20 @@
1
+ module GitCompound
2
+ module Worker
3
+ # Worker that detects if component name and its manifest name matches
4
+ # This is important because it is additional verification of consistency
5
+ # of manifests
6
+ #
7
+ class NameConstraintChecker < Worker
8
+ def visit_component(component)
9
+ return unless component.manifest.exists?
10
+
11
+ component_name = component.name
12
+ manifest_name = component.manifest.name
13
+
14
+ return if component_name == manifest_name
15
+ raise NameConstraintError, "Name of component `#{component_name}` " \
16
+ "does not match name in its manifest (`#{manifest_name}`) !"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module GitCompound
2
+ module Worker
3
+ # Worker that prints dependency tree
4
+ #
5
+ class PrettyPrint < Worker
6
+ def visit_component(component)
7
+ print_component(component)
8
+ end
9
+
10
+ private
11
+
12
+ def print_component(component)
13
+ Logger.inline ' ' * component.ancestors.count
14
+ Logger.info "`#{component.name}` component, #{component.version}"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module GitCompound
2
+ module Worker
3
+ # Worker that executes manifest tasks
4
+ # This happens when visitor visits manifests in reverse order
5
+ #
6
+ class TaskRunner < Worker
7
+ def visit_task(task)
8
+ task.execute
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module GitCompound
2
+ module Worker
3
+ # Abstract worker
4
+ #
5
+ class Worker
6
+ def visit_component(_component)
7
+ end
8
+
9
+ def visit_manifest(_manifest)
10
+ end
11
+
12
+ def visit_task(_task)
13
+ end
14
+
15
+ # Maybe ?
16
+ # def result
17
+ # end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,112 @@
1
+ require 'git_compound/exceptions'
2
+ require 'git_compound/version'
3
+
4
+ # Git Compound module
5
+ #
6
+ module GitCompound
7
+ autoload :Builder, 'git_compound/builder'
8
+ autoload :Command, 'git_compound/command'
9
+ autoload :Component, 'git_compound/component'
10
+ autoload :Lock, 'git_compound/lock'
11
+ autoload :Logger, 'git_compound/logger'
12
+ autoload :Manifest, 'git_compound/manifest'
13
+ autoload :Node, 'git_compound/node'
14
+ autoload :Repository, 'git_compound/repository'
15
+ autoload :Task, 'git_compound/task'
16
+
17
+ # GitCompound Domain Specific Language
18
+ #
19
+ module DSL
20
+ autoload :ComponentDSL, 'git_compound/dsl/component_dsl'
21
+ autoload :ManifestDSL, 'git_compound/dsl/manifest_dsl'
22
+ end
23
+
24
+ # GitCompound component class
25
+ #
26
+ class Component
27
+ autoload :Source, 'git_compound/component/source'
28
+ autoload :Destination, 'git_compound/component/destination'
29
+
30
+ # Possible component versions
31
+ #
32
+ module Version
33
+ autoload :Branch, 'git_compound/component/version/branch'
34
+ autoload :GemVersion, 'git_compound/component/version/gem_version'
35
+ autoload :SHA, 'git_compound/component/version/sha'
36
+ autoload :Tag, 'git_compound/component/version/tag'
37
+ autoload :VersionStrategy, 'git_compound/component/version/version_strategy'
38
+ end
39
+ end
40
+
41
+ # GitCompound Command
42
+ #
43
+ module Command
44
+ autoload :Options, 'git_compound/command/options'
45
+ end
46
+
47
+ # GitCompound Logger
48
+ #
49
+ module Logger
50
+ autoload :Colors, 'git_compound/logger/colors'
51
+ require 'git_compound/logger/core_ext/string'
52
+ end
53
+
54
+ # Task module
55
+ #
56
+ module Task
57
+ autoload :Task, 'git_compound/task/task'
58
+ autoload :TaskAll, 'git_compound/task/task_all'
59
+ autoload :TaskEach, 'git_compound/task/task_each'
60
+ autoload :TaskSingle, 'git_compound/task/task_single'
61
+ end
62
+
63
+ # Repository
64
+ #
65
+ module Repository
66
+ autoload :GitCommand, 'git_compound/repository/git_command'
67
+ autoload :GitRepository, 'git_compound/repository/git_repository'
68
+ autoload :GitVersion, 'git_compound/repository/git_version'
69
+ autoload :RemoteFile, 'git_compound/repository/remote_file'
70
+ autoload :RepositoryLocal, 'git_compound/repository/repository_local'
71
+ autoload :RepositoryRemote, 'git_compound/repository/repository_remote'
72
+
73
+ # Remote file strategy
74
+ #
75
+ class RemoteFile
76
+ autoload :GitArchiveStrategy,
77
+ 'git_compound/repository/remote_file/git_archive_strategy'
78
+ autoload :GithubStrategy,
79
+ 'git_compound/repository/remote_file/github_strategy'
80
+ autoload :RemoteFileStrategy,
81
+ 'git_compound/repository/remote_file/remote_file_strategy'
82
+ end
83
+ end
84
+
85
+ # Workers
86
+ #
87
+ module Worker
88
+ autoload :CircularDependencyChecker,
89
+ 'git_compound/worker/circular_dependency_checker'
90
+ autoload :ComponentBuilder,
91
+ 'git_compound/worker/component_builder'
92
+ autoload :ComponentUpdateDispatcher,
93
+ 'git_compound/worker/component_update_dispatcher'
94
+ autoload :ComponentUpdater,
95
+ 'git_compound/worker/component_updater'
96
+ autoload :ComponentReplacer,
97
+ 'git_compound/worker/component_replacer'
98
+ autoload :ComponentsCollector,
99
+ 'git_compound/worker/components_collector'
100
+ autoload :ConflictingDependencyChecker,
101
+ 'git_compound/worker/conflicting_dependency_checker'
102
+ autoload :LocalChangesGuard,
103
+ 'git_compound/worker/local_changes_guard'
104
+ autoload :NameConstraintChecker,
105
+ 'git_compound/worker/name_constraint_checker'
106
+ autoload :PrettyPrint, 'git_compound/worker/pretty_print'
107
+ autoload :TaskRunner, 'git_compound/worker/task_runner'
108
+ autoload :Worker, 'git_compound/worker/worker'
109
+ end
110
+
111
+ extend Command
112
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_compound
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ platform: ruby
6
+ authors:
7
+ - Grzegorz Bizon
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.31.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.31.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.10.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.10.0
97
+ description:
98
+ email:
99
+ - grzegorz.bizon@ntsn.pl
100
+ executables:
101
+ - gitcompound
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - Compoundfile
109
+ - Gemfile
110
+ - LICENSE
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - exe/gitcompound
116
+ - git_compound.gemspec
117
+ - lib/git_compound.rb
118
+ - lib/git_compound/builder.rb
119
+ - lib/git_compound/command.rb
120
+ - lib/git_compound/command/options.rb
121
+ - lib/git_compound/component.rb
122
+ - lib/git_compound/component/destination.rb
123
+ - lib/git_compound/component/source.rb
124
+ - lib/git_compound/component/version/branch.rb
125
+ - lib/git_compound/component/version/gem_version.rb
126
+ - lib/git_compound/component/version/sha.rb
127
+ - lib/git_compound/component/version/tag.rb
128
+ - lib/git_compound/component/version/version_strategy.rb
129
+ - lib/git_compound/dsl/component_dsl.rb
130
+ - lib/git_compound/dsl/manifest_dsl.rb
131
+ - lib/git_compound/exceptions.rb
132
+ - lib/git_compound/lock.rb
133
+ - lib/git_compound/logger.rb
134
+ - lib/git_compound/logger/colors.rb
135
+ - lib/git_compound/logger/core_ext/string.rb
136
+ - lib/git_compound/manifest.rb
137
+ - lib/git_compound/node.rb
138
+ - lib/git_compound/repository.rb
139
+ - lib/git_compound/repository/git_command.rb
140
+ - lib/git_compound/repository/git_repository.rb
141
+ - lib/git_compound/repository/git_version.rb
142
+ - lib/git_compound/repository/remote_file.rb
143
+ - lib/git_compound/repository/remote_file/git_archive_strategy.rb
144
+ - lib/git_compound/repository/remote_file/github_strategy.rb
145
+ - lib/git_compound/repository/remote_file/remote_file_strategy.rb
146
+ - lib/git_compound/repository/repository_local.rb
147
+ - lib/git_compound/repository/repository_remote.rb
148
+ - lib/git_compound/task.rb
149
+ - lib/git_compound/task/task.rb
150
+ - lib/git_compound/task/task_all.rb
151
+ - lib/git_compound/task/task_each.rb
152
+ - lib/git_compound/task/task_single.rb
153
+ - lib/git_compound/version.rb
154
+ - lib/git_compound/worker/circular_dependency_checker.rb
155
+ - lib/git_compound/worker/component_builder.rb
156
+ - lib/git_compound/worker/component_replacer.rb
157
+ - lib/git_compound/worker/component_update_dispatcher.rb
158
+ - lib/git_compound/worker/component_updater.rb
159
+ - lib/git_compound/worker/components_collector.rb
160
+ - lib/git_compound/worker/conflicting_dependency_checker.rb
161
+ - lib/git_compound/worker/local_changes_guard.rb
162
+ - lib/git_compound/worker/name_constraint_checker.rb
163
+ - lib/git_compound/worker/pretty_print.rb
164
+ - lib/git_compound/worker/task_runner.rb
165
+ - lib/git_compound/worker/worker.rb
166
+ homepage: https://github.com/grzesiek/git_compound
167
+ licenses:
168
+ - MIT
169
+ metadata: {}
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '2.2'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements:
185
+ - git scm version > 2
186
+ - gnu tar
187
+ rubyforge_project:
188
+ rubygems_version: 2.4.5
189
+ signing_key:
190
+ specification_version: 4
191
+ summary: Compose you project using git repositories and ruby tasks
192
+ test_files: []
193
+ has_rdoc: