gjp 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  #!/bin/bash
2
2
 
3
- # A crude integration test that builds commons-lang
3
+ # A crude integration test that builds commons-collections
4
4
 
5
5
  mkdir galaxy
6
6
  cd galaxy
data/lib/gjp.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "gjp/version"
2
2
  require "gjp/logger"
3
3
  require "gjp/template_manager"
4
+ require "gjp/git"
4
5
  require "gjp/project"
5
6
  require "gjp/pom"
6
7
  require "gjp/version_matcher"
@@ -12,7 +13,7 @@ require "gjp/source_getter"
12
13
  require "gjp/parent_pom_getter"
13
14
  require "gjp/maven_runner"
14
15
  require "gjp/package_spec_adapter"
15
- require "gjp/scaffolder"
16
+ require "gjp/spec_generator"
16
17
  require "gjp/archiver"
17
18
 
18
19
  require "gjp/cli"
@@ -38,23 +38,26 @@ module Gjp
38
38
  # Subcommands
39
39
  subcommand "init", "Inits a gjp project in the current directory" do
40
40
  def execute
41
- Gjp::Project.init(".")
42
- puts "Project inited."
43
- puts "Any file added to kit/ will be added to the kit package."
44
- puts "Any file added to src/<name> will be added to the corresponding package."
45
- puts "When you are ready to test a build, use \"gjp dry-run\"."
41
+ checking_exceptions do
42
+ Gjp::Project.init(".")
43
+ puts "Project inited."
44
+ puts "Any file added to kit/ will be added to the kit package."
45
+ puts "Any file added to src/<name> will be added to the corresponding package."
46
+ puts "When you are ready to test a build, use \"gjp dry-run\"."
47
+ end
46
48
  end
47
49
  end
48
50
 
49
51
  subcommand "dry-run", "Starts a dry-run build" do
50
52
  def execute
51
- if Gjp::Project.new(".").dry_run
52
- puts "Now dry-running, please start your build."
53
- puts "Any file added to kit/, presumably downloaded dependencies, will be added to the kit."
54
- puts "The src/ directory and all files in it will be brought back to the current state when finished."
55
- puts "Note that .gitignore files are honored!"
56
- puts "To run Maven from the kit, use \"gjp mvn\"."
57
- puts "To end this dry run, use \"gjp finish\"."
53
+ checking_exceptions do
54
+ if Gjp::Project.new(".").dry_run
55
+ puts "Now dry-running, please start your build."
56
+ puts "Any file added to kit/, presumably downloaded dependencies, will be added to the kit."
57
+ puts "The src/ directory and all files in it will be brought back to the current state when finished."
58
+ puts "To run Maven from the kit, use \"gjp mvn\"."
59
+ puts "To end this dry run, use \"gjp finish\"."
60
+ end
58
61
  end
59
62
  end
60
63
  end
@@ -68,55 +71,61 @@ module Gjp
68
71
  end
69
72
 
70
73
  def execute
71
- begin
74
+ checking_exceptions do
72
75
  project = Gjp::Project.new(".")
73
76
  result = Gjp::MavenRunner.new(project).mvn(@maven_options)
74
77
  puts "Real commandline was:"
75
78
  puts "#{result}"
76
- rescue Gjp::MavenNotFoundException
77
- puts "mvn executable not found in kit/ or any of its subdirectories"
78
79
  end
79
80
  end
80
81
  end
81
82
 
82
83
  subcommand "finish", "Ends the current dry-run" do
83
84
  def execute
84
- if Gjp::Project.new(".").finish
85
- puts "Dry-run finished."
86
- else
87
- puts "No dry-run is in progress."
85
+ checking_exceptions do
86
+ if Gjp::Project.new(".").finish
87
+ puts "Dry-run finished."
88
+ else
89
+ puts "No dry-run is in progress."
90
+ end
88
91
  end
89
92
  end
90
93
  end
91
94
 
92
- subcommand "generate-kit-spec", "Scaffolds or refreshes a spec file for the kit" do
95
+ subcommand "generate-kit-spec", "Creates or refreshes a spec file for the kit" do
93
96
  def execute
94
- project = Gjp::Project.new(".")
95
- result_path = Gjp::Scaffolder.new(project).generate_kit_spec
96
- puts "#{result_path} generated"
97
+ checking_exceptions do
98
+ project = Gjp::Project.new(".")
99
+ result_path = Gjp::SpecGenerator.new(project).generate_kit_spec
100
+ puts "#{result_path} generated"
101
+ end
97
102
  end
98
103
  end
99
104
 
100
105
  subcommand "generate-kit-archive", "Archives contents of kit in archives/" do
101
106
  def execute
102
- project = Gjp::Project.new(".")
103
- result_path = Gjp::Archiver.new(project).archive_kit
104
- puts "#{result_path} generated"
107
+ checking_exceptions do
108
+ project = Gjp::Project.new(".")
109
+ result_path = Gjp::Archiver.new(project).archive_kit
110
+ puts "#{result_path} generated"
111
+ end
105
112
  end
106
113
  end
107
114
 
108
- subcommand "generate-package-spec", "Scaffolds or refreshes a spec file for a package" do
115
+ subcommand "generate-package-spec", "Creates or refreshes a spec file for a package" do
109
116
  option ["-f", "--filter"], "FILTER", "filter files to be installed by this spec", :default => "*.jar"
110
117
  parameter "NAME", "name of a package, that is, an src/ subdirectory name"
111
118
  parameter "POM", "a pom file path or URI"
112
119
  def execute
113
- project = Gjp::Project.new(".")
114
- result_path = Gjp::Scaffolder.new(project).generate_package_spec name, pom, filter
115
- if result_path != nil
116
- puts "#{result_path} generated"
117
- else
118
- "The file_list/#{name}_output file was not found. Ensure you have already run a" +
119
- "dry run and ensure you ended that phase with \"gjp finish\"."
120
+ checking_exceptions do
121
+ project = Gjp::Project.new(".")
122
+ result_path = Gjp::SpecGenerator.new(project).generate_package_spec name, pom, filter
123
+ if result_path != nil
124
+ puts "#{result_path} generated"
125
+ else
126
+ $stderr.puts "file_list/#{name}_output not found. Ensure you have already run a" +
127
+ "\"gjp dry run\" and \"gjp finish\"."
128
+ end
120
129
  end
121
130
  end
122
131
  end
@@ -124,47 +133,57 @@ module Gjp
124
133
  subcommand "generate-package-archive", "Archives contents of a package in archives/" do
125
134
  parameter "NAME", "name of a package, that is, an src/ subdirectory name"
126
135
  def execute
127
- project = Gjp::Project.new(".")
128
- result_path = Gjp::Archiver.new(project).archive_package name
129
- puts "#{result_path} generated"
136
+ checking_exceptions do
137
+ project = Gjp::Project.new(".")
138
+ result_path = Gjp::Archiver.new(project).archive_package name
139
+ puts "#{result_path} generated"
140
+ end
130
141
  end
131
142
  end
132
143
 
133
144
  subcommand "set-up-nonet-user", "Sets up a \"nonet\" user that cannot access the network" do
134
145
  def execute
135
- user = Gjp::LimitedNetworkUser.new("nonet")
136
- user.set_up
137
-
138
- "sudo #{user.get_path("useradd")} nonet\n" +
139
- "sudo #{user.get_path("iptables")} -A OUTPUT -m owner --uid-owner nonet -j DROP\n" +
140
- "User \"nonet\" set up, you can use \"sudo nonet\" to dry-run your build with no network access.\n" +
141
- "Note that the above iptables rule will be cleared at next reboot, you can use your distribution " +
142
- "tools to make it persistent or run \"gjp set-up-limited-nertwork-user\" again next time."
146
+ checking_exceptions do
147
+ user = Gjp::LimitedNetworkUser.new("nonet")
148
+ user.set_up
149
+
150
+ "sudo #{user.get_path("useradd")} nonet\n" +
151
+ "sudo #{user.get_path("iptables")} -A OUTPUT -m owner --uid-owner nonet -j DROP\n" +
152
+ "User \"nonet\" set up, you can use \"sudo nonet\" to dry-run your build with no network access.\n" +
153
+ "Note that the above iptables rule will be cleared at next reboot, you can use your distribution " +
154
+ "tools to make it persistent or run \"gjp set-up-limited-nertwork-user\" again next time."
155
+ end
143
156
  end
144
157
  end
145
158
 
146
159
  subcommand "tear-down-nonet-user", "Deletes a user previously created by gjp" do
147
160
  def execute
148
- user = Gjp::LimitedNetworkUser.new("nonet")
161
+ checking_exceptions do
162
+ user = Gjp::LimitedNetworkUser.new("nonet")
149
163
 
150
- user.tear_down
164
+ user.tear_down
151
165
 
152
- "sudo #{user.get_path("iptables")} -D OUTPUT -m owner --uid-owner nonet -j DROP\n" +
153
- "sudo #{user.get_path("userdel")} nonet\n"
166
+ "sudo #{user.get_path("iptables")} -D OUTPUT -m owner --uid-owner nonet -j DROP\n" +
167
+ "sudo #{user.get_path("userdel")} nonet\n"
168
+ end
154
169
  end
155
170
  end
156
171
 
157
172
  subcommand "get-pom", "Retrieves a pom corresponding to a filename" do
158
173
  parameter "NAME", "a jar file path, a project directory path or a non-existing filename in the `project-version` form"
159
174
  def execute
160
- puts Gjp::PomGetter.new.get_pom(name)
175
+ checking_exceptions do
176
+ puts Gjp::PomGetter.new.get_pom(name)
177
+ end
161
178
  end
162
179
  end
163
180
 
164
181
  subcommand "get-parent-pom", "Retrieves a pom that is the parent of an existing pom" do
165
182
  parameter "POM", "a pom file path or URI"
166
183
  def execute
167
- puts Gjp::ParentPomGetter.new.get_parent_pom(pom)
184
+ checking_exceptions do
185
+ puts Gjp::ParentPomGetter.new.get_parent_pom(pom)
186
+ end
168
187
  end
169
188
  end
170
189
 
@@ -172,8 +191,10 @@ module Gjp
172
191
  parameter "POM", "a pom file path or URI"
173
192
 
174
193
  def execute
175
- puts Gjp::SourceAddressGetter.new.get_source_address(pom)
176
- end
194
+ checking_exceptions do
195
+ puts Gjp::SourceAddressGetter.new.get_source_address(pom)
196
+ end
197
+ end
177
198
  end
178
199
 
179
200
  subcommand "get-source", "Retrieves a project's source code directory" do
@@ -182,8 +203,29 @@ module Gjp
182
203
  parameter "[DIRECTORY]", "directory in which to save the source code", :default => "."
183
204
 
184
205
  def execute
185
- puts Gjp::SourceGetter.new.get_source(address, pom, directory)
206
+ checking_exceptions do
207
+ puts Gjp::SourceGetter.new.get_source(address, pom, directory)
208
+ end
186
209
  end
187
210
  end
211
+
212
+ # handles most fatal exceptions
213
+ def checking_exceptions
214
+ begin
215
+ yield
216
+ rescue Errno::EACCES => e
217
+ $stderr.puts e
218
+ rescue Errno::ENOENT => e
219
+ $stderr.puts e
220
+ rescue Errno::EEXIST => e
221
+ $stderr.puts e
222
+ rescue NotGjpDirectoryException
223
+ $stderr.puts "This is not a gjp project directory, see gjp init"
224
+ rescue GitAlreadyInitedException
225
+ $stderr.puts "This directory is already a gjp project"
226
+ rescue Gjp::MavenNotFoundException
227
+ $stderr.puts "mvn executable not found in kit/ or any of its subdirectories"
228
+ end
229
+ end
188
230
  end
189
231
  end
@@ -0,0 +1,68 @@
1
+ # encoding: UTF-8
2
+
3
+ module Gjp
4
+ # encapsulates git, all methods refer to the current directory
5
+ class Git
6
+ include Logger
7
+
8
+ # inits a repo
9
+ def self.init
10
+ if Dir.exists?(".git") == false
11
+ `git init`
12
+ else
13
+ raise GitAlreadyInitedException
14
+ end
15
+ end
16
+
17
+ # returns a list of filenames that changed in the repo
18
+ # since the specified tag
19
+ def changed_files_since(tag)
20
+ `git diff-tree --no-commit-id --name-only -r gjp_#{tag} HEAD`.split("\n")
21
+ end
22
+
23
+ # adds all files in the current directory and removes
24
+ # all files not in the current directory.
25
+ # if tag is given, commit is also tagged
26
+ def commit_whole_directory(message, tag = nil)
27
+ log.debug "committing with message: #{message}"
28
+
29
+ `git rm -r --cached --ignore-unmatch .`
30
+ `git add .`
31
+ `git commit -m "#{message}"`
32
+
33
+ if tag != nil
34
+ `git tag gjp_#{tag}`
35
+ end
36
+ end
37
+
38
+ # returns the highest suffix found in tags with the given prefix
39
+ def get_tag_maximum_suffix(prefix)
40
+ `git tag`.split.map do |tag|
41
+ if tag =~ /^gjp_#{prefix}_([0-9]+)$/
42
+ $1.to_i
43
+ else
44
+ 0
45
+ end
46
+ end.max or 0
47
+ end
48
+
49
+ # reverts path contents as per specified tag
50
+ def revert_whole_directory(path, tag)
51
+ `git rm -rf --ignore-unmatch #{path}`
52
+ `git checkout -f gjp_#{tag} -- #{path}`
53
+
54
+ `git clean -f -d #{path}`
55
+ end
56
+
57
+ # 3-way merges the git file at path with the one in new_path
58
+ # assuming they have a common ancestor at the specified tag
59
+ def merge_with_tag(path, new_path, tag)
60
+ `git show gjp_#{tag}:#{path} > #{path}.old_version`
61
+ `git merge-file --ours #{path} #{path}.old_version #{new_path}`
62
+ File.delete "#{path}.old_version"
63
+ end
64
+ end
65
+
66
+ class GitAlreadyInitedException < Exception
67
+ end
68
+ end
@@ -10,6 +10,7 @@ module Gjp
10
10
  attr_reader :summary
11
11
  attr_reader :url
12
12
  attr_reader :project_name
13
+ attr_reader :project_version
13
14
  attr_reader :group_id
14
15
  attr_reader :artifact_id
15
16
  attr_reader :version
@@ -28,6 +29,7 @@ module Gjp
28
29
  @summary = cleanup_description(pom.description, 60)
29
30
  @url = pom.url
30
31
  @project_name = project.name
32
+ @project_version = project.version
31
33
  @group_id = pom.group_id
32
34
  @artifact_id = pom.artifact_id
33
35
  @version = pom.version
@@ -19,45 +19,45 @@ module Gjp
19
19
  end
20
20
 
21
21
  def group_id
22
- @doc.xpath("project/groupId/text()").to_s
22
+ @doc.xpath("project/groupId").text
23
23
  end
24
24
 
25
25
  def artifact_id
26
- @doc.xpath("project/artifactId/text()").to_s
26
+ @doc.xpath("project/artifactId").text
27
27
  end
28
28
 
29
29
  def version
30
- @doc.xpath("project/version/text()").to_s
30
+ @doc.xpath("project/version").text
31
31
  end
32
32
 
33
33
  def description
34
- @doc.xpath("project/description/text()").to_s
34
+ @doc.xpath("project/description").text
35
35
  end
36
36
 
37
37
  def url
38
- @doc.xpath("project/url/text()").to_s
38
+ @doc.xpath("project/url").text
39
39
  end
40
40
 
41
41
  def license_name
42
- @doc.xpath("project/licenses/license/name/text()").to_s
42
+ @doc.xpath("project/licenses/license/name").text
43
43
  end
44
44
 
45
45
  def runtime_dependency_ids
46
46
  result = @doc.xpath("project/dependencies/dependency[not(optional='true') and not(scope='provided') and not(scope='test') and not(scope='system')]").map do |element|
47
- [element.xpath("groupId/text()").to_s, element.xpath("artifactId/text()").to_s, element.xpath("version/text()").to_s]
47
+ [element.xpath("groupId").text, element.xpath("artifactId").text, element.xpath("version").text]
48
48
  end
49
49
  end
50
50
 
51
51
  def parent_group_id
52
- @doc.xpath("project/parent/groupId/text()").to_s
52
+ @doc.xpath("project/parent/groupId").text
53
53
  end
54
54
 
55
55
  def parent_artifact_id
56
- @doc.xpath("project/parent/artifactId/text()").to_s
56
+ @doc.xpath("project/parent/artifactId").text
57
57
  end
58
58
 
59
59
  def parent_version
60
- @doc.xpath("project/parent/version/text()").to_s
60
+ @doc.xpath("project/parent/version").text
61
61
  end
62
62
  end
63
63
  end
@@ -7,13 +7,11 @@ module Gjp
7
7
  class Project
8
8
  include Logger
9
9
 
10
- # list of possible statuses
11
- @@statuses = [:dry_running]
12
-
13
10
  attr_accessor :full_path
14
11
 
15
12
  def initialize(path)
16
13
  @full_path = Gjp::Project.find_project_dir(File.expand_path(path))
14
+ @git = Gjp::Git.new
17
15
  end
18
16
 
19
17
  # finds the project directory up in the tree, like git does
@@ -23,7 +21,7 @@ module Gjp
23
21
  result = File.expand_path("..", result)
24
22
  end
25
23
 
26
- raise ArgumentError, "This is not a gjp project directory" if result == "/"
24
+ raise NotGjpDirectoryException if result == "/"
27
25
 
28
26
  result
29
27
  end
@@ -38,9 +36,7 @@ module Gjp
38
36
  # inits a new project directory structure
39
37
  def self.init(dir)
40
38
  Dir.chdir(dir) do
41
- if Dir.exists?(".git") == false
42
- `git init`
43
- end
39
+ Gjp::Git.init
44
40
 
45
41
  Dir.mkdir "src"
46
42
  Dir.mkdir "kit"
@@ -64,33 +60,34 @@ module Gjp
64
60
  # when finished
65
61
  def dry_run
66
62
  from_directory do
67
- status = get_status
68
- if status == :dry_running
63
+ if is_dry_running
69
64
  return false
70
65
  end
71
66
 
72
- set_status :dry_running
73
67
  take_snapshot "Dry-run started", :dry_run_started
74
68
  end
75
69
 
76
70
  true
77
71
  end
78
72
 
73
+ # returns true iff we are currently dry-running
74
+ def is_dry_running
75
+ latest_tag_count(:dry_run_started) > latest_tag_count(:dry_run_finished)
76
+ end
77
+
79
78
  # ends any phase that was previously started,
80
79
  # generating file lists
81
80
  def finish
82
81
  from_directory do
83
- status = get_status
84
- if status == :dry_running
82
+ if is_dry_running
85
83
  take_snapshot "Changes during dry-run"
86
84
 
87
85
  update_output_file_lists
88
86
  take_snapshot "File list updates"
89
87
 
90
- revert "src", :dry_run_started
88
+ @git.revert_whole_directory("src", latest_tag(:dry_run_started))
91
89
  take_snapshot "Sources reverted as before dry-run"
92
90
 
93
- set_status nil
94
91
  take_snapshot "Dry run finished", :dry_run_finished
95
92
 
96
93
  return true
@@ -114,12 +111,12 @@ module Gjp
114
111
  end
115
112
 
116
113
  new_tracked_files = (
117
- `git diff-tree --no-commit-id --name-only -r #{latest_tag(:dry_run_started)} HEAD`.split("\n")
118
- .select { |file| file.start_with?(directory) }
119
- .map { |file|file[directory.length + 1, file.length] }
120
- .concat(tracked_files)
121
- .uniq
122
- .sort
114
+ @git.changed_files_since(latest_tag(:dry_run_started))
115
+ .select { |file| file.start_with?(directory) }
116
+ .map { |file|file[directory.length + 1, file.length] }
117
+ .concat(tracked_files)
118
+ .uniq
119
+ .sort
123
120
  )
124
121
 
125
122
  log.debug("writing file list for #{directory}: #{new_tracked_files.to_s}")
@@ -133,80 +130,27 @@ module Gjp
133
130
  end
134
131
  end
135
132
 
136
- # adds the project's whole contents to git
137
- # if tag is given, commit is tagged
138
- def take_snapshot(message, tag = nil)
139
- log.debug "committing with message: #{message}"
140
-
141
- `git rm -r --cached --ignore-unmatch .`
142
- `git add .`
143
- `git commit -m "#{message}"`
144
-
145
- if tag != nil
146
- `git tag gjp_#{tag}_#{latest_tag_count(tag) + 1}`
133
+ # takes a revertable snapshot of this project
134
+ def take_snapshot(message, prefix = nil)
135
+ tag = if prefix
136
+ "#{prefix}_#{latest_tag_count(prefix) + 1}"
137
+ else
138
+ nil
147
139
  end
140
+
141
+ @git.commit_whole_directory(message, tag)
148
142
  end
149
143
 
150
144
  # returns the last tag of its type corresponding to a
151
145
  # gjp snapshot
152
146
  def latest_tag(tag_type)
153
- "gjp_#{tag_type}_#{latest_tag_count(tag_type)}"
147
+ "#{tag_type}_#{latest_tag_count(tag_type)}"
154
148
  end
155
149
 
156
150
  # returns the last tag count of its type corresponding
157
151
  # to a gjp snapshot
158
152
  def latest_tag_count(tag_type)
159
- `git tag`.split.map do |tag|
160
- if tag =~ /^gjp_#{tag_type}_([0-9]+)$/
161
- $1.to_i
162
- else
163
- 0
164
- end
165
- end.max or 0
166
- end
167
-
168
- # reverts path contents as per latest tag
169
- def revert(path, tag)
170
- `git rm -rf --ignore-unmatch #{path}`
171
- `git checkout -f #{latest_tag(tag)} -- #{path}`
172
-
173
- `git clean -f -d #{path}`
174
- end
175
-
176
- # returns a symbol with the current status
177
- # flag
178
- def get_status
179
- from_directory do
180
- @@statuses.each do |status|
181
- if File.exists?(status_file_name(status))
182
- return status
183
- end
184
- end
185
- end
186
-
187
- nil
188
- end
189
-
190
- # sets a project status flag. if status = nil,
191
- # clears all status flags
192
- def set_status(status)
193
- from_directory do
194
- @@statuses.each do |a_status|
195
- file_name = status_file_name(a_status)
196
- if File.exists?(file_name)
197
- File.delete(file_name)
198
- end
199
-
200
- if a_status == status
201
- FileUtils.touch(file_name)
202
- end
203
- end
204
- end
205
- end
206
-
207
- # returns a file name that represents a status
208
- def status_file_name(status)
209
- ".#{status.to_s}"
153
+ @git.get_tag_maximum_suffix(tag_type)
210
154
  end
211
155
 
212
156
  # runs a block from the project directory or a subdirectory
@@ -223,11 +167,14 @@ module Gjp
223
167
  end
224
168
 
225
169
  def version
226
- `git rev-parse --short #{latest_tag(:dry_run_finished)}`.strip
170
+ latest_tag_count(:dry_run_finished)
227
171
  end
228
172
 
229
173
  def get_binding
230
174
  binding
231
175
  end
232
176
  end
177
+
178
+ class NotGjpDirectoryException < Exception
179
+ end
233
180
  end
@@ -2,11 +2,12 @@
2
2
 
3
3
  module Gjp
4
4
  # creates and updates spec files
5
- class Scaffolder
5
+ class SpecGenerator
6
6
  include Logger
7
7
 
8
8
  def initialize(project)
9
9
  @project = project
10
+ @git = Gjp::Git.new
10
11
  end
11
12
 
12
13
  def generate_kit_spec
@@ -25,36 +26,32 @@ module Gjp
25
26
 
26
27
  adapter = Gjp::PackageSpecAdapter.new(@project, name, Gjp::Pom.new(pom), filter)
27
28
 
28
- generate_merging "package.spec", adapter.get_binding, spec_path, "scaffold_#{name}_spec"
29
+ generate_merging "package.spec", adapter.get_binding, spec_path, "generate_#{name}_spec"
29
30
 
30
31
  spec_path
31
32
  end
32
33
 
33
34
  # generates a file in result_path from template together with binding.
34
35
  # if a file already exists at that position, 3-way merge it with the
35
- # version with the latest tag specified. Takes a snapshot in the end
36
- # for future merges
37
- def generate_merging(template, binding, result_path, tag)
36
+ # common ancestor. Takes a snapshot in the end for future merges
37
+ def generate_merging(template, binding, result_path, tag_prefix)
38
38
  @project.from_directory do
39
- TemplateManager.new.generate template, binding, "#{result_path}.new_scaffold"
39
+ TemplateManager.new.generate template, binding, "#{result_path}.new_version"
40
40
 
41
- already_scaffolded = @project.latest_tag(tag) != ""
41
+ already_generated = @project.latest_tag(tag_prefix) != ""
42
42
  already_existing = File.exist? result_path
43
43
 
44
- if already_scaffolded and already_existing
44
+ if already_generated and already_existing
45
45
  # 3-way merge
46
- `git show #{@project.latest_tag(tag)}:#{result_path} > #{result_path}.old_scaffold`
47
- `git merge-file --ours #{result_path} #{result_path}.old_scaffold #{result_path}.new_scaffold`
48
- File.delete "#{result_path}.new_scaffold"
49
- File.delete "#{result_path}.old_scaffold"
46
+ @git.merge_with_tag("#{result_path}", "#{result_path}.new_version", @project.latest_tag(tag_prefix))
47
+ File.delete "#{result_path}.new_version"
50
48
  else
51
49
  # just replace
52
- File.rename "#{result_path}.new_scaffold", result_path
50
+ File.rename "#{result_path}.new_version", result_path
53
51
  end
54
52
 
55
- @project.take_snapshot "Kit spec scaffolded", tag
53
+ @project.take_snapshot("Spec generated", tag_prefix)
56
54
  end
57
55
  end
58
-
59
56
  end
60
57
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Gjp
4
- VERSION = "0.18.0"
4
+ VERSION = "0.19.0"
5
5
  end
@@ -44,12 +44,10 @@ be installed on end users' systems.
44
44
 
45
45
  %install
46
46
  install -d -m 0755 %{buildroot}%{_datadir}/gjp/%{name}/
47
- mv README.SUSE ../
48
47
  cp -a * %{buildroot}%{_datadir}/gjp/%{name}/
49
48
 
50
49
  %files
51
50
  %defattr(-,root,root)
52
- %doc ../README.SUSE
53
51
  %{_datadir}/gjp/
54
52
 
55
53
  %changelog
@@ -1,9 +1,8 @@
1
- Any files you put here will be copied as is in the "kit" package.
1
+ This directory contains all binary files needed to build a gjp project's
2
+ packages.
2
3
 
3
- You should add all dependencies and build tools here, so that they are
4
- available at build time.
5
-
6
- gjp will recognise Maven, Ant and other popular build tool binaries in here.
4
+ These files should only be used during build and should not be installed
5
+ on users' systems.
7
6
 
8
7
  Some generally useful configuration files are also placed here (eg.
9
- m2/settings.xml for Maven builds.
8
+ m2/settings.xml for Maven builds).
@@ -26,7 +26,7 @@ Source0: %{name}.tar.xz
26
26
  BuildRoot: %{_tmppath}/%{name}-%{version}-build
27
27
  BuildRequires: xz
28
28
  BuildRequires: java-devel
29
- BuildRequires: <%= project_name %>-kit
29
+ BuildRequires: <%= project_name %>-kit == <%= project_version %>
30
30
  BuildArch: noarch
31
31
  Provides: mvn(<%= group_id %>:<%= artifact_id %>) == <%= version %>
32
32
  <% runtime_dependency_ids.each do |dependency_id| %>
@@ -1,13 +1,6 @@
1
1
  For each package you want to create, you should create a subdirectory here
2
- named after the package Maven name "orgId:artifactId:version", eg.
3
-
4
- ./commons-collections:commons-collections:3.2/
2
+ named after the package name itself.
5
3
 
6
4
  In that directory, place all the source files "verbatim" (as checked out from
7
- the original source repository).
8
-
9
- You can create any other directory for your convenience here. In case of git-
10
- tracked projects, for example, you can clone the whole repository and copy the
11
- version you want to build in orgId_artifactId_version.
12
-
13
- Please note that .gitignore files are honored!
5
+ the original source repository, ideally in a different subdirectory)
6
+ plus any additional files you might need for the build.
@@ -31,7 +31,7 @@ describe Gjp::Project do
31
31
 
32
32
  expect {
33
33
  Gjp::Project.find_project_dir(File.expand_path("..", @project_path)).should raise_error
34
- }.to raise_error(ArgumentError)
34
+ }.to raise_error(Gjp::NotGjpDirectoryException)
35
35
  end
36
36
  end
37
37
 
@@ -51,21 +51,14 @@ describe Gjp::Project do
51
51
  end
52
52
  end
53
53
 
54
- describe "#set_status" do
55
- it "stores a project's status flag" do
54
+ describe "#is_dry_running" do
55
+ it "checks if a project is dry running" do
56
56
  @project.from_directory do
57
- @project.set_status :dry_running
58
- File.exists?(".dry_running").should be_true
59
- end
60
- end
61
- end
62
-
63
- describe "#get_status" do
64
- it "gets a project's status flag" do
65
- @project.from_directory do
66
- @project.get_status.should be_nil
67
- @project.set_status :dry_running
68
- @project.get_status.should eq :dry_running
57
+ @project.is_dry_running.should be_false
58
+ @project.dry_run
59
+ @project.is_dry_running.should be_true
60
+ @project.finish
61
+ @project.is_dry_running.should be_false
69
62
  end
70
63
  end
71
64
  end
@@ -78,7 +71,7 @@ describe Gjp::Project do
78
71
  @project.take_snapshot "test", :revertable
79
72
 
80
73
  `git rev-list --all`.split("\n").length.should eq 2
81
- @project.latest_tag(:revertable).should eq "gjp_revertable_1"
74
+ @project.latest_tag(:revertable).should eq "revertable_1"
82
75
  end
83
76
  end
84
77
  end
@@ -100,14 +93,14 @@ describe Gjp::Project do
100
93
  end
101
94
 
102
95
  @project.finish.should be_true
103
- @project.get_status.should be_nil
96
+ @project.is_dry_running.should be_false
104
97
 
105
98
  @project.from_directory do
106
- `git rev-list --all`.split("\n").length.should eq 6
99
+ `git rev-list --all`.split("\n").length.should eq 5
107
100
  File.read("src/abc/test").should eq "A\n"
108
101
  File.readlines(File.join("file_lists", "abc_output")).should include("test2\n")
109
102
 
110
- `git diff-tree --no-commit-id --name-only -r HEAD~2`.split("\n").should_not include("src/abc/test2")
103
+ `git diff-tree --no-commit-id --name-only -r HEAD~`.split("\n").should_not include("src/abc/test2")
111
104
  File.exists?("src/abc/test2").should be_false
112
105
  end
113
106
  end
@@ -124,7 +117,7 @@ describe Gjp::Project do
124
117
  @project.dry_run.should be_true
125
118
 
126
119
  @project.from_directory do
127
- @project.get_status.should eq :dry_running
120
+ @project.is_dry_running.should be_true
128
121
  `git rev-list --all`.split("\n").length.should eq 2
129
122
  `git diff-tree --no-commit-id --name-only -r HEAD`.split("\n").should include("src/test")
130
123
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Gjp::Scaffolder do
5
+ describe Gjp::SpecGenerator do
6
6
  before(:each) do
7
7
  @project_path = File.join("spec", "data", "test-project")
8
8
  Dir.mkdir(@project_path)
@@ -15,8 +15,9 @@ describe Gjp::Scaffolder do
15
15
  test_file = File.join("kit", "test")
16
16
  File.open(test_file, "w") { |io| io.puts "kit content test file" }
17
17
  end
18
+ @project.finish
18
19
 
19
- @scaffolder = Gjp::Scaffolder.new(@project)
20
+ @spec_generator = Gjp::SpecGenerator.new(@project)
20
21
  end
21
22
 
22
23
  after(:each) do
@@ -24,21 +25,18 @@ describe Gjp::Scaffolder do
24
25
  end
25
26
 
26
27
  describe "#generate_kit_spec" do
27
- it "scaffolds the first version" do
28
- @project.dry_run
29
- @project.finish
30
-
31
- @scaffolder.generate_kit_spec.should be_true
28
+ it "generates the first version" do
29
+ @spec_generator.generate_kit_spec.should be_true
32
30
 
33
31
  @project.from_directory do
34
32
  spec_lines = File.readlines(File.join("specs", "test-project-kit.spec"))
35
33
  spec_lines.should include("Name: test-project-kit\n")
36
- spec_lines.should include("Version: #{`git rev-parse --short #{@project.latest_tag(:dry_run_finished)}`}")
34
+ spec_lines.should include("Version: 1\n")
37
35
  spec_lines.should include("Source0: %{name}.tar.xz\n")
38
36
  end
39
37
  end
40
- it "scaffolds a second version" do
41
- @scaffolder.generate_kit_spec.should be_true
38
+ it "generates a second version" do
39
+ @spec_generator.generate_kit_spec.should be_true
42
40
  @project.dry_run
43
41
  Dir.chdir(@project_path) do
44
42
  test_file = File.join("kit", "test")
@@ -50,18 +48,18 @@ describe Gjp::Scaffolder do
50
48
  end
51
49
  @project.finish
52
50
 
53
- @scaffolder.generate_kit_spec.should be_true
51
+ @spec_generator.generate_kit_spec.should be_true
54
52
 
55
53
  @project.from_directory do
56
54
  spec_lines = File.readlines(File.join("specs", "test-project-kit.spec"))
57
55
  spec_lines.should include("Name: test-project-kit\n")
58
- spec_lines.should include("Version: #{`git rev-parse --short #{@project.latest_tag(:dry_run_finished)}`}")
56
+ spec_lines.should include("Version: 2\n")
59
57
  spec_lines.should include("Source0: %{name}.tar.xz\n")
60
58
  spec_lines.should include("nonconflicting line\n")
61
59
  end
62
60
  end
63
- it "scaffolds a conflicting version" do
64
- @scaffolder.generate_kit_spec.should be_true
61
+ it "generates a conflicting version" do
62
+ @spec_generator.generate_kit_spec.should be_true
65
63
  @project.dry_run
66
64
  Dir.chdir(@project_path) do
67
65
  test_file = File.join("kit", "test")
@@ -76,21 +74,22 @@ describe Gjp::Scaffolder do
76
74
  io.write(spec_contents)
77
75
  end
78
76
  end
77
+ @project.finish
79
78
 
80
- @scaffolder.generate_kit_spec.should be_true
79
+ @spec_generator.generate_kit_spec.should be_true
81
80
 
82
81
  @project.from_directory do
83
82
  spec_lines = File.readlines(File.join("specs", "test-project-kit.spec"))
84
83
  spec_lines.should include("Name: test-project-kit\n")
85
84
  spec_lines.should include("Source0: %{name}.tar.xz\n")
86
85
  spec_lines.should include("CONFLICTING!\n")
87
- spec_lines.should_not include("Version: #{`git rev-parse --short #{@project.latest_tag(:dry_run_finished)}`}")
86
+ spec_lines.should_not include("Version: 2\n")
88
87
  end
89
88
  end
90
89
  end
91
90
 
92
91
  describe "#generate_package_spec" do
93
- it "scaffolds the first version" do
92
+ it "generates the first version" do
94
93
 
95
94
  @project.from_directory do
96
95
  FileUtils.mkdir_p File.join("src", "test", "out")
@@ -110,7 +109,7 @@ describe Gjp::Scaffolder do
110
109
  @project.finish
111
110
  end
112
111
 
113
- @scaffolder.generate_package_spec "test", File.join("spec", "data", "nailgun", "pom.xml"), "*.jar"
112
+ @spec_generator.generate_package_spec "test", File.join("spec", "data", "nailgun", "pom.xml"), "*.jar"
114
113
 
115
114
  @project.from_directory do
116
115
  spec_lines = File.readlines(File.join("specs", "test.spec"))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gjp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -155,10 +155,11 @@ files:
155
155
  - Rakefile
156
156
  - bin/gjp
157
157
  - gjp.gemspec
158
- - integration-tests/commons-io.sh
158
+ - integration-tests/commons-collections.sh
159
159
  - lib/gjp.rb
160
160
  - lib/gjp/archiver.rb
161
161
  - lib/gjp/cli.rb
162
+ - lib/gjp/git.rb
162
163
  - lib/gjp/limited_network_user.rb
163
164
  - lib/gjp/logger.rb
164
165
  - lib/gjp/maven_runner.rb
@@ -168,9 +169,9 @@ files:
168
169
  - lib/gjp/pom.rb
169
170
  - lib/gjp/pom_getter.rb
170
171
  - lib/gjp/project.rb
171
- - lib/gjp/scaffolder.rb
172
172
  - lib/gjp/source_address_getter.rb
173
173
  - lib/gjp/source_getter.rb
174
+ - lib/gjp/spec_generator.rb
174
175
  - lib/gjp/template_manager.rb
175
176
  - lib/gjp/version.rb
176
177
  - lib/gjp/version_matcher.rb
@@ -178,7 +179,6 @@ files:
178
179
  - lib/template/file_lists/CONTENTS
179
180
  - lib/template/kit.spec
180
181
  - lib/template/kit/CONTENTS
181
- - lib/template/kit/README.SUSE
182
182
  - lib/template/kit/m2/settings.xml
183
183
  - lib/template/package.spec
184
184
  - lib/template/specs/CONTENTS
@@ -207,9 +207,9 @@ files:
207
207
  - spec/lib/pom_getter_spec.rb
208
208
  - spec/lib/pom_spec.rb
209
209
  - spec/lib/project_spec.rb
210
- - spec/lib/scaffolder_spec.rb
211
210
  - spec/lib/source_address_getter_spec.rb
212
211
  - spec/lib/source_getter_spec.rb
212
+ - spec/lib/spec_generator_spec.rb
213
213
  - spec/lib/template_manager_spec.rb
214
214
  - spec/lib/version_matcher_spec.rb
215
215
  - spec/spec_helper.rb
@@ -263,9 +263,9 @@ test_files:
263
263
  - spec/lib/pom_getter_spec.rb
264
264
  - spec/lib/pom_spec.rb
265
265
  - spec/lib/project_spec.rb
266
- - spec/lib/scaffolder_spec.rb
267
266
  - spec/lib/source_address_getter_spec.rb
268
267
  - spec/lib/source_getter_spec.rb
268
+ - spec/lib/spec_generator_spec.rb
269
269
  - spec/lib/template_manager_spec.rb
270
270
  - spec/lib/version_matcher_spec.rb
271
271
  - spec/spec_helper.rb
@@ -1,4 +0,0 @@
1
- Contents of this package are automatically packaged by the gjp program in order
2
- to build other Java packages from source. They are not needed after rpm files
3
- are created, so this package should only be used by the Build Service and
4
- should never be installed on end users' systems.