gjp 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -109,26 +109,26 @@ Of course this script can also be manually modified, and it must be in more diff
109
109
 
110
110
  #### Generating archives and spec files
111
111
 
112
- The following command will generate the kit spec:
112
+ The following command will generate the kit archive in `output/galaxy-kit/`:
113
113
 
114
- gjp generate-kit-spec
115
- less output/galaxy-kit/galaxy-kit.spec
114
+ gjp generate-kit-archive
116
115
 
117
- Nothing fancy here, the spec simply copies `kit/` contents in a special directory to be available for later compilation of packages.
118
- You can also edit the spec file manually if you want. When you later regenerate it, `gjp` will automatically try to reconcile changes with a [three-way merge](http://en.wikipedia.org/wiki/Three-way_merge#Three-way_merge).
116
+ Note that, in later runs, you can also use the `--incremental` option to create an additional "diff" tar.xz file instead of rebuilding it from scratch.
119
117
 
120
- You can also generate the corresponding .tar.xz file in `output/galaxy-kit/` with:
118
+ The following command will generate the kit spec:
121
119
 
122
- gjp generate-kit-archive
120
+ gjp generate-kit-spec
123
121
 
122
+ You can inspect the generated "galaxy-kit.spec" file, but in general you should not need to edit it.
124
123
 
125
124
  You can then generate the project spec and archive files provided you have a pom file (more formats will be supported in future). In this case:
126
125
 
127
- gjp generate-package-spec commons-collections src/commons-collections/commons-collections-3.2.1-src/pom.xml
128
126
  gjp generate-package-archive commons-collections
127
+ gjp generate-package-spec commons-collections src/commons-collections/commons-collections-3.2.1-src/pom.xml
129
128
  less output/commons-collections/commons-collections.spec
130
129
 
131
130
  commons-collection BuldRequires galaxy-kit, its archive contains only source files and it will install any produced .jar file in `/usr/lib/java`.
131
+ You can also edit the specs file manually if you want. When you later regenerate it, `gjp` will automatically try to reconcile changes with a [three-way merge](http://en.wikipedia.org/wiki/Three-way_merge#Three-way_merge).
132
132
 
133
133
  Packages are ready to be submitted to an OBS project. As OBS integration is not yet implemented, refer to OBS documentation to do that.
134
134
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  # A crude integration test that builds commons-collections
4
4
 
5
+ rm -Rf galaxy
5
6
  mkdir galaxy
6
7
  cd galaxy
7
8
  gjp init
@@ -21,20 +22,37 @@ cd ..
21
22
 
22
23
  gjp dry-run
23
24
  cd src/commons-collections/commons-collections-3.2.1-src/
24
- gjp mvn package
25
+ gjp mvn package -DskipTests
26
+ cd ../../..
25
27
  gjp finish
26
28
 
29
+ gjp generate-kit-archive
30
+ gjp generate-kit-spec
31
+
32
+ gjp generate-package-archive commons-collections
33
+ gjp generate-package-spec commons-collections src/commons-collections/commons-collections-3.2.1-src/pom.xml
34
+
35
+
36
+ cd src
37
+ mkdir commons-fileupload
38
+ cd commons-fileupload
39
+ wget http://mirror.nohup.it/apache//commons/fileupload/source/commons-fileupload-1.3-src.zip
40
+ unzip commons-fileupload-1.3-src.zip
41
+ rm commons-fileupload-1.3-src.zip
42
+
43
+ gjp dry-run
44
+ cd commons-fileupload-1.3-src/
45
+ gjp mvn package -DskipTests
27
46
  cd ../../..
28
- cat >src/commons-collections/build.sh << "EOF"
29
- #!/bin/sh
30
- cd src/commons-collections/commons-collections-3.2.1-src/
31
- ../../../kit/apache-maven-3.1.0/bin/mvn -Dmaven.repo.local=`readlink -e ../../../kit/m2` -s`readlink -e ../../../kit/m2/settings.xml` package
32
- EOF
47
+ gjp finish
33
48
 
49
+ gjp generate-kit-archive -i
34
50
  gjp generate-kit-spec
35
- gjp generate-kit-archive
36
51
 
37
- gjp generate-package-spec commons-collections src/commons-collections/commons-collections-3.2.1-src/pom.xml
38
- gjp generate-package-archive commons-collections
52
+ gjp generate-package-archive commons-fileupload
53
+ gjp generate-package-spec commons-fileupload src/commons-fileupload/commons-fileupload-1.3-src/pom.xml
54
+
55
+
56
+ echo "**************** All Done ****************"
39
57
 
40
- echo "All Done"
58
+ ls -lah output/*
data/lib/gjp.rb CHANGED
@@ -12,7 +12,8 @@ require "gjp/pom_getter"
12
12
  require "gjp/source_address_getter"
13
13
  require "gjp/source_getter"
14
14
  require "gjp/parent_pom_getter"
15
- require "gjp/maven_runner"
15
+ require "gjp/kit_runner"
16
+ require "gjp/kit_spec_adapter"
16
17
  require "gjp/package_spec_adapter"
17
18
  require "gjp/spec_generator"
18
19
  require "gjp/archiver"
@@ -10,14 +10,25 @@ module Gjp
10
10
  end
11
11
 
12
12
  # generates an archive for the kit package
13
- def archive_kit
13
+ def archive_kit(incremental)
14
14
  destination_dir = File.join(@project.full_path, "output", "#{@project.name}-kit")
15
15
  FileUtils.mkdir_p(destination_dir)
16
- destination_file = File.join(destination_dir, "#{@project.name}-kit.tar.xz")
16
+ destination_file_prefix = "#{@project.name}-kit"
17
+ destination_file_suffix = ".tar.xz"
17
18
 
18
- archive("kit", destination_file)
19
+ @project.take_snapshot "Kit archival started"
20
+
21
+ destination_file = if incremental
22
+ log.debug "doing incremental archive"
23
+ archive_incremental("kit", destination_dir, destination_file_prefix, destination_file_suffix, :archive_kit)
24
+ else
25
+ remove_stale_incremental(destination_dir, destination_file_prefix, destination_file_suffix)
26
+ archive_single("kit", File.join(destination_dir, destination_file_prefix + destination_file_suffix))
27
+ end
28
+
29
+ @project.take_snapshot "Kit archive generated", :archive_kit
19
30
 
20
- Pathname.new(destination_file).relative_path_from Pathname.new(@project.full_path)
31
+ destination_file
21
32
  end
22
33
 
23
34
  # generates an archive for a project's package based on its file list
@@ -26,16 +37,56 @@ module Gjp
26
37
  FileUtils.mkdir_p(destination_dir)
27
38
  destination_file = File.join(destination_dir, "#{name}.tar.xz")
28
39
 
29
- archive(File.join("src", name), destination_file)
30
-
31
- Pathname.new(destination_file).relative_path_from Pathname.new(@project.full_path)
40
+ archive_single(File.join("src", name), destination_file)
32
41
  end
33
42
 
34
- # archives a folder's contents to the destination file
35
- def archive(folder, destination_file)
36
- @project.from_directory folder do
43
+ # archives a directory's contents to the destination file
44
+ def archive_single(source_directory, destination_file)
45
+ log.debug "creating #{destination_file}"
46
+ @project.from_directory source_directory do
37
47
  `tar -cJf #{destination_file} *`
38
48
  end
49
+
50
+ destination_file
51
+ end
52
+
53
+ # archives a directory's changed contents since last time archive_incremental was called
54
+ # uses snapshots with tag_prefix to keep track of calls to this method
55
+ # destination files will be destination_file_prefix_NNNN_destination_file_suffix
56
+ def archive_incremental(source_directory, destination_dir, destination_file_prefix, destination_file_suffix, tag_prefix)
57
+ @project.from_directory do
58
+ latest_tag_count = @project.latest_tag_count(tag_prefix)
59
+
60
+ if latest_tag_count == 0
61
+ archive_single(source_directory, File.join(destination_dir, destination_file_prefix + destination_file_suffix))
62
+ else
63
+ destination_file = File.join(destination_dir, "#{destination_file_prefix}_#{"%04d" % (latest_tag_count)}#{destination_file_suffix}")
64
+ tag = @project.latest_tag(tag_prefix)
65
+ log.debug "creating #{destination_file} with files newer than #{tag}"
66
+
67
+ log.debug "files that changed since then: #{@project.git.changed_files_since(tag)}"
68
+ list = @project.git.changed_files_since(tag).select do |file|
69
+ File.expand_path(file) =~ /^#{File.expand_path(source_directory)}\//
70
+ end.map do |file|
71
+ Pathname.new(file).relative_path_from Pathname.new(source_directory)
72
+ end
73
+ @project.from_directory source_directory do
74
+ `tar -cJf #{destination_file} #{list.join(" ")}`
75
+ end
76
+
77
+ destination_file
78
+ end
79
+ end
80
+ end
81
+
82
+ # removes any stale incremental files
83
+ def remove_stale_incremental(destination_dir, destination_file_prefix, destination_file_suffix)
84
+ Dir.entries(destination_dir)
85
+ .select { |f| f =~ /^#{destination_file_prefix}_([0-9]+)#{destination_file_suffix}$/}
86
+ .each do |f|
87
+ log.debug "removing stale incremental archive #{f}"
88
+ File.delete(File.join(destination_dir, f))
89
+ end
39
90
  end
40
91
  end
41
92
  end
@@ -7,7 +7,7 @@ module Gjp
7
7
 
8
8
  def initialize(project, history_path)
9
9
  @project = project
10
- @maven_runner = Gjp::MavenRunner.new(project)
10
+ @kit_runner = Gjp::KitRunner.new(project)
11
11
  @history_path = history_path
12
12
  end
13
13
 
@@ -29,7 +29,7 @@ module Gjp
29
29
  ] +
30
30
  relevant_lines.map do |line|
31
31
  if line =~ /gjp +mvn/
32
- line.gsub(/gjp +mvn/, "#{@maven_runner.get_maven_commandline("$PROJECT_PREFIX")}")
32
+ line.gsub(/gjp +mvn/, "#{@kit_runner.get_maven_commandline("$PROJECT_PREFIX")}")
33
33
  else
34
34
  line
35
35
  end
@@ -65,13 +65,29 @@ module Gjp
65
65
 
66
66
  # override parsing in order to pipe everything to mvn
67
67
  def parse(args)
68
- @maven_options = args
68
+ @options = args
69
69
  end
70
70
 
71
71
  def execute
72
72
  checking_exceptions do
73
73
  project = Gjp::Project.new(".")
74
- Gjp::MavenRunner.new(project).mvn(@maven_options)
74
+ Gjp::KitRunner.new(project).mvn(@options)
75
+ end
76
+ end
77
+ end
78
+
79
+ subcommand "ant", "Locates and runs Ant from any directory in kit/" do
80
+ parameter "[ANT OPTIONS] ...", "ant options", :attribute_name => "dummy"
81
+
82
+ # override parsing in order to pipe everything to mvn
83
+ def parse(args)
84
+ @options = args
85
+ end
86
+
87
+ def execute
88
+ checking_exceptions do
89
+ project = Gjp::Project.new(".")
90
+ Gjp::KitRunner.new(project).ant(@options)
75
91
  end
76
92
  end
77
93
  end
@@ -93,6 +109,14 @@ module Gjp
93
109
  end
94
110
  end
95
111
 
112
+ subcommand "purge-jars", "Locates jars in src/ and moves them to kit/" do
113
+ def execute
114
+ Gjp::Project.new(".").purge_jars.each do |original, final|
115
+ puts "Replaced #{original} with symlink pointing to to #{final}"
116
+ end
117
+ end
118
+ end
119
+
96
120
  subcommand "generate-build-script", "Create or refresh a build.sh file" do
97
121
  parameter "NAME", "name of a package, that is, an src/ subdirectory name"
98
122
  def execute
@@ -100,7 +124,7 @@ module Gjp
100
124
  project = Gjp::Project.new(".")
101
125
  history_file = File.join(Dir.home, ".bash_history")
102
126
  result_path, conflict_count = Gjp::BuildScriptGenerator.new(project, history_file).generate_build_script(name)
103
- puts "#{result_path} generated"
127
+ puts "#{format_path(result_path, project)} generated"
104
128
  if conflict_count > 0
105
129
  puts "Warning: #{conflict_count} unresolved conflicts"
106
130
  end
@@ -113,7 +137,7 @@ module Gjp
113
137
  checking_exceptions do
114
138
  project = Gjp::Project.new(".")
115
139
  result_path, conflict_count = Gjp::SpecGenerator.new(project).generate_kit_spec
116
- puts "#{result_path} generated"
140
+ puts "#{format_path(result_path, project)} generated"
117
141
  if conflict_count > 0
118
142
  puts "Warning: #{conflict_count} unresolved conflicts"
119
143
  end
@@ -122,11 +146,12 @@ module Gjp
122
146
  end
123
147
 
124
148
  subcommand "generate-kit-archive", "Create or refresh the kit tarball" do
149
+ option ["-i", "--incremental"], :flag, "create an archive with only the difference from the previous one"
125
150
  def execute
126
151
  checking_exceptions do
127
152
  project = Gjp::Project.new(".")
128
- result_path = Gjp::Archiver.new(project).archive_kit
129
- puts "#{result_path} generated"
153
+ result_path = Gjp::Archiver.new(project).archive_kit(incremental?)
154
+ puts "#{format_path(result_path, project)} generated"
130
155
  end
131
156
  end
132
157
  end
@@ -139,7 +164,7 @@ module Gjp
139
164
  checking_exceptions do
140
165
  project = Gjp::Project.new(".")
141
166
  result_path, conflict_count = Gjp::SpecGenerator.new(project).generate_package_spec name, pom, filter
142
- puts "#{result_path} generated"
167
+ puts "#{format_path(result_path, project)} generated"
143
168
  if conflict_count > 0
144
169
  puts "Warning: #{conflict_count} unresolved conflicts"
145
170
  end
@@ -153,7 +178,7 @@ module Gjp
153
178
  checking_exceptions do
154
179
  project = Gjp::Project.new(".")
155
180
  result_path = Gjp::Archiver.new(project).archive_package name
156
- puts "#{result_path} generated"
181
+ puts "#{format_path(result_path, project)} generated"
157
182
  end
158
183
  end
159
184
  end
@@ -226,6 +251,16 @@ module Gjp
226
251
  end
227
252
  end
228
253
 
254
+ # generates a version of path relative to the current directory
255
+ def format_path(path, project)
256
+ full_path = if Pathname.new(path).relative?
257
+ File.join(project.full_path, path)
258
+ else
259
+ path
260
+ end
261
+ Pathname.new(full_path).relative_path_from(Pathname.new(Dir.pwd))
262
+ end
263
+
229
264
  # handles most fatal exceptions
230
265
  def checking_exceptions
231
266
  begin
@@ -240,8 +275,8 @@ module Gjp
240
275
  $stderr.puts "This is not a gjp project directory, see gjp init"
241
276
  rescue GitAlreadyInitedException
242
277
  $stderr.puts "This directory is already a gjp project"
243
- rescue Gjp::MavenNotFoundException
244
- $stderr.puts "mvn executable not found in kit/ or any of its subdirectories"
278
+ rescue Gjp::ExecutableNotFoundException
279
+ $stderr.puts "Executable not found in kit/ or any of its subdirectories"
245
280
  end
246
281
  end
247
282
  end
@@ -80,7 +80,9 @@ module Gjp
80
80
  # returns the conflict count
81
81
  def merge_with_tag(path, new_path, tag)
82
82
  Dir.chdir(@directory) do
83
+ log.debug "calling git show gjp_#{tag}:#{path} > #{path}.old_version, output follows"
83
84
  `git show gjp_#{tag}:#{path} > #{path}.old_version`
85
+ log.debug "calling git merge-file #{path} #{path}.old_version #{new_path}, output follows"
84
86
  `git merge-file #{path} #{path}.old_version #{new_path} -L "newly generated" -L "previously generated" -L "user edited"`
85
87
  conflict_count = $?.exitstatus
86
88
  File.delete "#{path}.old_version"
@@ -0,0 +1,79 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'find'
4
+ require 'pathname'
5
+
6
+ module Gjp
7
+ # runs programs from a gjp kit with gjp-specific options
8
+ class KitRunner
9
+ include Logger
10
+
11
+ def initialize(project)
12
+ @project = project
13
+ end
14
+
15
+ # finds an executable in a bin/ subdirectory of kit
16
+ def find_executable(name)
17
+ @project.from_directory do
18
+ Find.find("kit") do |path|
19
+ if path =~ /bin\/#{name}$/
20
+ log.debug("found #{name} executable: #{path}")
21
+ return path
22
+ end
23
+ end
24
+ end
25
+
26
+ log.debug("#{name} executable not found")
27
+ nil
28
+ end
29
+
30
+ # runs an external executable
31
+ def run_executable(full_commandline)
32
+ log.debug "running #{full_commandline}"
33
+ Process.wait(Process.spawn(full_commandline))
34
+ end
35
+
36
+ # runs mvn in a subprocess
37
+ def mvn(options)
38
+ run_executable "#{get_maven_commandline(@project.full_path)} #{options.join(' ')}"
39
+ end
40
+
41
+ # returns a command line for running Maven from the specified
42
+ # prefix
43
+ def get_maven_commandline(prefix)
44
+ executable = find_executable("mvn")
45
+
46
+ if executable != nil
47
+ mvn_path = File.join(prefix, executable)
48
+ repo_path = File.join(prefix, "kit", "m2")
49
+ config_path = File.join(prefix, "kit", "m2", "settings.xml")
50
+
51
+ "#{mvn_path} -Dmaven.repo.local=#{repo_path} -s#{config_path}"
52
+ else
53
+ raise ExecutableNotFoundException
54
+ end
55
+ end
56
+
57
+ # runs mvn in a subprocess
58
+ def ant(options)
59
+ run_executable "#{get_ant_commandline(@project.full_path)} #{options.join(' ')}"
60
+ end
61
+
62
+ # returns a command line for running Ant from the specified
63
+ # prefix
64
+ def get_ant_commandline(prefix)
65
+ executable = find_executable("ant")
66
+
67
+ if executable != nil
68
+ ant_path = File.join(prefix, executable)
69
+
70
+ "#{ant_path}"
71
+ else
72
+ raise ExecutableNotFoundException
73
+ end
74
+ end
75
+ end
76
+
77
+ class ExecutableNotFoundException < Exception
78
+ end
79
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+
3
+ module Gjp
4
+ # encapsulates details of a kit needed by the spec file
5
+ # retrieving them from other objects
6
+ class KitSpecAdapter
7
+ attr_reader :name
8
+ attr_reader :version
9
+ attr_reader :archives
10
+
11
+ def initialize(project)
12
+ @name = project.name
13
+ @version = project.version
14
+
15
+ @archives =
16
+ project.from_directory do
17
+ ["#{name}-kit.tar.xz"] +
18
+ Dir.entries("output/#{name}-kit")
19
+ .select { |f| f =~ /_[0-9]+.tar.xz$/ }
20
+ .sort
21
+ end
22
+ end
23
+
24
+ def get_binding
25
+ binding
26
+ end
27
+ end
28
+ end
29
+
@@ -8,12 +8,21 @@ module Gjp
8
8
  include Logger
9
9
 
10
10
  attr_accessor :full_path
11
+ attr_accessor :git
11
12
 
12
13
  def initialize(path)
13
14
  @full_path = Gjp::Project.find_project_dir(File.expand_path(path))
14
15
  @git = Gjp::Git.new(@full_path)
15
16
  end
16
17
 
18
+ def name
19
+ File.basename(@full_path)
20
+ end
21
+
22
+ def version
23
+ latest_tag_count(:dry_run_finished)
24
+ end
25
+
17
26
  # finds the project directory up in the tree, like git does
18
27
  def self.find_project_dir(starting_dir)
19
28
  result = starting_dir
@@ -145,19 +154,24 @@ module Gjp
145
154
  # returns the number of conflicts
146
155
  def merge_new_content(new_content, path, snapshot_message, tag_prefix)
147
156
  from_directory do
157
+ log.debug "merging new content to #{path} with prefix #{tag_prefix}"
148
158
  already_existing = File.exist? path
149
159
  previous_tag = latest_tag(tag_prefix)
150
160
 
151
161
  if already_existing
162
+ log.debug "moving #{path} to #{path}.gjp_user_edited"
152
163
  File.rename path, "#{path}.gjp_user_edited"
153
164
  end
154
165
 
155
166
  File.open(path, "w") { |io| io.write(new_content) }
167
+ log.debug "taking snapshot with new content: #{snapshot_message}"
156
168
  take_snapshot(snapshot_message, tag_prefix)
157
169
 
158
170
  if already_existing
159
171
  if previous_tag == ""
160
172
  previous_tag = latest_tag(tag_prefix)
173
+ log.debug "there was no tag with prefix #{tag_prefix} before snapshot"
174
+ log.debug "defaulting to #{previous_tag} after snapshot"
161
175
  end
162
176
 
163
177
  # 3-way merge
@@ -204,18 +218,26 @@ module Gjp
204
218
  end
205
219
 
206
220
 
207
- # helpers for ERB
208
-
209
- def name
210
- File.basename(@full_path)
211
- end
212
-
213
- def version
214
- latest_tag_count(:dry_run_finished)
215
- end
221
+ # moves any .jar from src/ to kit/ and links it back
222
+ def purge_jars
223
+ from_directory do
224
+ result = []
225
+ Find.find("src") do |file|
226
+ if file =~ /.jar$/ and not File.symlink?(file)
227
+ new_location = File.join("kit", "jars", Pathname.new(file).split[1])
228
+ FileUtils.mv(file, new_location)
229
+
230
+ link_target = Pathname.new(new_location)
231
+ .relative_path_from(Pathname.new(file).split.first)
232
+ .to_s
233
+
234
+ File.symlink(link_target, file)
235
+ result << [file, new_location]
236
+ end
237
+ end
216
238
 
217
- def get_binding
218
- binding
239
+ result
240
+ end
219
241
  end
220
242
  end
221
243
 
@@ -10,22 +10,29 @@ module Gjp
10
10
  end
11
11
 
12
12
  def generate_kit_spec
13
- destination_dir = File.join(@project.full_path, "output", "#{@project.name}-kit")
14
- FileUtils.mkdir_p(destination_dir)
15
- spec_path = File.join(destination_dir, "#{@project.name}-kit.spec")
16
- conflict_count = generate_merging("kit.spec", @project.get_binding, spec_path, :generate_kit_spec)
17
- [spec_path, conflict_count]
13
+ @project.from_directory do
14
+ destination_dir = File.join("output", "#{@project.name}-kit")
15
+ FileUtils.mkdir_p(destination_dir)
16
+ spec_path = File.join(destination_dir, "#{@project.name}-kit.spec")
17
+
18
+ adapter = Gjp::KitSpecAdapter.new(@project)
19
+
20
+ conflict_count = generate_merging("kit.spec", adapter.get_binding, spec_path, :generate_kit_spec)
21
+ [spec_path, conflict_count]
22
+ end
18
23
  end
19
24
 
20
25
  def generate_package_spec(name, pom, filter)
21
- destination_dir = File.join(@project.full_path, "output", name)
22
- FileUtils.mkdir_p(destination_dir)
23
- spec_path = File.join(destination_dir, "#{name}.spec")
26
+ @project.from_directory do
27
+ destination_dir = File.join("output", name)
28
+ FileUtils.mkdir_p(destination_dir)
29
+ spec_path = File.join(destination_dir, "#{name}.spec")
24
30
 
25
- adapter = Gjp::PackageSpecAdapter.new(@project, name, Gjp::Pom.new(pom), filter)
31
+ adapter = Gjp::PackageSpecAdapter.new(@project, name, Gjp::Pom.new(pom), filter)
26
32
 
27
- conflict_count = generate_merging("package.spec", adapter.get_binding, spec_path, "generate_#{name}_spec")
28
- [spec_path, conflict_count]
33
+ conflict_count = generate_merging("package.spec", adapter.get_binding, spec_path, "generate_#{name}_spec")
34
+ [spec_path, conflict_count]
35
+ end
29
36
  end
30
37
 
31
38
  # generates a spec file from a template and 3-way merges it
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Gjp
4
- VERSION = "0.21.0"
4
+ VERSION = "0.22.0"
5
5
  end
@@ -22,7 +22,9 @@ License: Apache-2.0
22
22
  Summary: Build-time dependencies for gjp project <%= name %>
23
23
  Url: https://github.com/SilvioMoioli/gjp
24
24
  Group: Development/Libraries/Java
25
- Source0: %{name}.tar.xz
25
+ <% archives.each_with_index do |archive, i| %>
26
+ Source<%= i %>: <%= archive %>
27
+ <% end %>
26
28
  BuildRoot: %{_tmppath}/%{name}-%{version}-build
27
29
  BuildArch: noarch
28
30
  BuildRequires: xz
@@ -38,7 +40,13 @@ not be used except for rebuilding those packages and it should never
38
40
  be installed on end users' systems.
39
41
 
40
42
  %prep
41
- %setup -q -c
43
+ <% (0..(archives.length-1)).each do |i| %>
44
+ <% if i > 0 %>
45
+ %setup -q -c -T -D -b <%= i %>
46
+ <% else %>
47
+ %setup -q -c -T -b <%= i %>
48
+ <% end %>
49
+ <% end %>
42
50
 
43
51
  %build
44
52
  # nothing to do, gjp kits are precompiled by design
@@ -0,0 +1 @@
1
+ This directory contains jars moved here from source archives.
@@ -29,6 +29,7 @@ BuildRequires: java-devel
29
29
  BuildRequires: <%= project_name %>-kit >= <%= project_version %>
30
30
  BuildArch: noarch
31
31
  Provides: mvn(<%= group_id %>:<%= artifact_id %>) == <%= version %>
32
+ Requires: java
32
33
  <% runtime_dependency_ids.each do |dependency_id| %>
33
34
  Requires: mvn(<%= dependency_id[0] %>:<%= dependency_id[1] %>) <% if dependency_id[3] != nil %>==<%= dependency_id[3] %><% end %>
34
35
  <% end %>
@@ -17,28 +17,75 @@ describe Gjp::Archiver do
17
17
 
18
18
  let(:archiver) { Gjp::Archiver.new(@project) }
19
19
 
20
- describe "#archive" do
20
+ describe "#archive_single" do
21
21
  it "archives a list of files" do
22
22
  @project.from_directory do
23
23
  File.open("test", "w") { |io| io.puts "test content" }
24
24
 
25
- archiver.archive ".", "test.tar.xz"
25
+ archiver.archive_single(".", "test.tar.xz")
26
26
  `tar -Jtf test.tar.xz`.split.should include("test")
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
+ describe "#archive_incremental" do
32
+ it "archives an increment of a directory" do
33
+ @project.from_directory do
34
+ File.open("test", "w") { |io| io.puts "test content 1" }
35
+ File.open("test2", "w") { |io| io.puts "test content 1" }
36
+ archiver.archive_incremental(".", ".", "test", ".tar.xz", :archive_kit)
37
+ `tar -Jtf test.tar.xz`.split.should include("test")
38
+
39
+ @project.take_snapshot("test archive snapshot 1", :archive_kit)
40
+
41
+ File.open("test", "w") { |io| io.puts "test content 2" }
42
+ File.open("test3", "w") { |io| io.puts "test content 2" }
43
+
44
+ @project.take_snapshot("test archive snapshot 2")
45
+
46
+ archiver.archive_incremental(".", ".", "test", ".tar.xz", :archive_kit)
47
+ files = `tar -Jtf test_0001.tar.xz`.split
48
+
49
+ files.should include("test")
50
+ files.should include("test3")
51
+ files.should_not include("test2")
52
+ end
53
+ end
54
+ end
55
+
31
56
  describe "#archive_kit" do
32
- it "archives a kit package files" do
57
+ it "archives a kit package files, not incrementally" do
58
+ @project.from_directory do
59
+ File.open(File.join("kit","kit_test"), "w") { |io| io.puts "test content" }
60
+ end
61
+ @project.finish(false)
62
+
63
+ archiver.archive_kit(false)
64
+ @project.from_directory do
65
+ `tar -Jtf output/test-project-kit/test-project-kit.tar.xz`.split.should include("kit_test")
66
+ end
67
+ end
68
+ it "archives a kit package files incrementally" do
33
69
  @project.from_directory do
34
70
  File.open(File.join("kit","kit_test"), "w") { |io| io.puts "test content" }
35
71
  end
36
72
  @project.finish(false)
37
73
 
38
- archiver.archive_kit
74
+ archiver.archive_kit(true)
39
75
  @project.from_directory do
40
76
  `tar -Jtf output/test-project-kit/test-project-kit.tar.xz`.split.should include("kit_test")
41
77
  end
78
+
79
+ @project.from_directory do
80
+ File.open(File.join("kit","kit_test2"), "w") { |io| io.puts "test content" }
81
+ end
82
+
83
+ archiver.archive_kit(true)
84
+ @project.from_directory do
85
+ files = `tar -Jtf output/test-project-kit/test-project-kit_0001.tar.xz`.split
86
+ files.should include("kit_test2")
87
+ files.should_not include("kit_test")
88
+ end
42
89
  end
43
90
  end
44
91
 
@@ -0,0 +1,98 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Gjp::KitRunner do
6
+
7
+ before(:each) do
8
+ @project_path = File.join("spec", "data", "test-project")
9
+ Dir.mkdir(@project_path)
10
+
11
+ Gjp::Project.init(@project_path)
12
+ @project = Gjp::Project.new(@project_path)
13
+ @kit_runner = Gjp::KitRunner.new(@project)
14
+ end
15
+
16
+ after(:each) do
17
+ FileUtils.rm_rf(@project_path)
18
+ end
19
+
20
+ describe "#find_executable" do
21
+ it "finds an executable in kit" do
22
+ mock_executable("mvn")
23
+ @kit_runner.find_executable("mvn").should eq @executable
24
+ end
25
+ it "doesn't find a Maven executable in kit" do
26
+ @kit_runner.find_executable("mvn").should be_nil
27
+ end
28
+ end
29
+
30
+ describe "#get_maven_commandline" do
31
+ it "returns commandline options for running maven" do
32
+ mock_executable("mvn")
33
+
34
+ @project.from_directory do
35
+ commandline = @kit_runner.get_maven_commandline(".")
36
+ commandline.should eq "./#{@executable} -Dmaven.repo.local=./kit/m2 -s./kit/m2/settings.xml"
37
+ end
38
+ end
39
+ it "doesn't return commandline options if Maven is not available" do
40
+ expect { @kit_runner.get_maven_commandline(".") }.to raise_error(Gjp::ExecutableNotFoundException)
41
+ end
42
+ end
43
+
44
+ describe "#mvn" do
45
+ it "runs maven" do
46
+ mock_executable("mvn")
47
+ @project.from_directory do
48
+ @kit_runner.mvn(["extra-option"])
49
+ File.read("test_out").strip.should match /extra-option$/
50
+ end
51
+ end
52
+ it "doesn't run Maven if it is not available" do
53
+ @project.from_directory do
54
+ expect { @kit_runner.mvn([]) }.to raise_error(Gjp::ExecutableNotFoundException)
55
+ end
56
+ end
57
+ end
58
+
59
+
60
+ describe "#get_ant_commandline" do
61
+ it "returns commandline options for running Ant" do
62
+ mock_executable("ant")
63
+
64
+ @project.from_directory do
65
+ commandline = @kit_runner.get_ant_commandline(".")
66
+ commandline.should eq "./#{@executable}"
67
+ end
68
+ end
69
+ it "doesn't return commandline options if Ant is not available" do
70
+ expect { @kit_runner.get_ant_commandline(".") }.to raise_error(Gjp::ExecutableNotFoundException)
71
+ end
72
+ end
73
+
74
+ describe "#ant" do
75
+ it "runs Ant" do
76
+ mock_executable("ant")
77
+ @project.from_directory do
78
+ @kit_runner.ant(["extra-option"])
79
+ File.read("test_out").strip.should match /extra-option$/
80
+ end
81
+ end
82
+ it "doesn't run Ant if it is not available" do
83
+ @project.from_directory do
84
+ expect { @kit_runner.ant([]) }.to raise_error(Gjp::ExecutableNotFoundException)
85
+ end
86
+ end
87
+ end
88
+
89
+ def mock_executable(executable)
90
+ Dir.chdir(@project_path) do
91
+ @bin_dir = File.join("kit", executable, "bin")
92
+ FileUtils.mkdir_p(@bin_dir)
93
+ @executable = File.join(@bin_dir, executable)
94
+ File.open(@executable, "w") { |io| io.puts "echo $0 $*>test_out" }
95
+ File.chmod(0777, @executable)
96
+ end
97
+ end
98
+ end
@@ -158,6 +158,23 @@ describe Gjp::Project do
158
158
  `git diff-tree --no-commit-id --name-only -r HEAD`.split("\n").should include("src/test")
159
159
  `git cat-file tag gjp_dry_run_started_1 | tail -1`.should include("src")
160
160
  end
161
+ end
162
+ end
163
+
164
+ describe "#purge_jars" do
165
+ it "moves jars in kit/jars" do
166
+ @project.from_directory do
167
+ `echo "jarring" > src/test.jar`
168
+ end
169
+ @project.finish(false).should be_false
170
+
171
+ @project.purge_jars
172
+
173
+ @project.from_directory do
174
+ File.symlink?(File.join("src", "test.jar")).should be_true
175
+ File.readlink(File.join("src", "test.jar")).should eq "../kit/jars/test.jar"
176
+ File.readlines(File.join("kit", "jars", "test.jar")).should include("jarring\n")
177
+ end
161
178
  end
162
179
  end
163
180
  end
@@ -32,7 +32,7 @@ describe Gjp::SpecGenerator do
32
32
  spec_lines = File.readlines(File.join("output", "test-project-kit", "test-project-kit.spec"))
33
33
  spec_lines.should include("Name: test-project-kit\n")
34
34
  spec_lines.should include("Version: 1\n")
35
- spec_lines.should include("Source0: %{name}.tar.xz\n")
35
+ spec_lines.should include("Source0: test-project-kit.tar.xz\n")
36
36
  end
37
37
  end
38
38
  it "generates a second version" do
@@ -54,7 +54,7 @@ describe Gjp::SpecGenerator do
54
54
  spec_lines = File.readlines(File.join("output", "test-project-kit", "test-project-kit.spec"))
55
55
  spec_lines.should include("Name: test-project-kit\n")
56
56
  spec_lines.should include("Version: 2\n")
57
- spec_lines.should include("Source0: %{name}.tar.xz\n")
57
+ spec_lines.should include("Source0: test-project-kit.tar.xz\n")
58
58
  spec_lines.should include("nonconflicting line\n")
59
59
  end
60
60
  end
@@ -81,7 +81,7 @@ describe Gjp::SpecGenerator do
81
81
  @project.from_directory do
82
82
  spec_lines = File.readlines(File.join("output", "test-project-kit", "test-project-kit.spec"))
83
83
  spec_lines.should include("Name: test-project-kit\n")
84
- spec_lines.should include("Source0: %{name}.tar.xz\n")
84
+ spec_lines.should include("Source0: test-project-kit.tar.xz\n")
85
85
  spec_lines.should include("<<<<<<< newly generated\n")
86
86
  spec_lines.should include("Version: 2\n")
87
87
  spec_lines.should include("=======\n")
@@ -109,10 +109,12 @@ describe Gjp::SpecGenerator do
109
109
  `touch src/test/out/test#{i}.jar`
110
110
  end
111
111
 
112
+
112
113
  @project.finish(false)
113
114
  end
114
115
 
115
- @spec_generator.generate_package_spec "test", File.join("spec", "data", "nailgun", "pom.xml"), "*.jar"
116
+ FileUtils.copy(File.join("spec", "data", "nailgun", "pom.xml"), @project_path)
117
+ @spec_generator.generate_package_spec "test", "pom.xml", "*.jar"
116
118
 
117
119
  @project.from_directory do
118
120
  spec_lines = File.readlines(File.join("output", "test", "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.21.0
4
+ version: 0.22.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-09 00:00:00.000000000 Z
12
+ date: 2013-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -155,15 +155,16 @@ files:
155
155
  - Rakefile
156
156
  - bin/gjp
157
157
  - gjp.gemspec
158
- - integration-tests/commons-collections.sh
158
+ - integration-tests/commons.sh
159
159
  - lib/gjp.rb
160
160
  - lib/gjp/archiver.rb
161
161
  - lib/gjp/build_script_generator.rb
162
162
  - lib/gjp/cli.rb
163
163
  - lib/gjp/git.rb
164
+ - lib/gjp/kit_runner.rb
165
+ - lib/gjp/kit_spec_adapter.rb
164
166
  - lib/gjp/limited_network_user.rb
165
167
  - lib/gjp/logger.rb
166
- - lib/gjp/maven_runner.rb
167
168
  - lib/gjp/maven_website.rb
168
169
  - lib/gjp/package_spec_adapter.rb
169
170
  - lib/gjp/parent_pom_getter.rb
@@ -178,6 +179,7 @@ files:
178
179
  - lib/gjp/version_matcher.rb
179
180
  - lib/template/kit.spec
180
181
  - lib/template/kit/CONTENTS
182
+ - lib/template/kit/jars/CONTENTS
181
183
  - lib/template/kit/m2/settings.xml
182
184
  - lib/template/output/.gitignore
183
185
  - lib/template/output/CONTENTS
@@ -201,8 +203,8 @@ files:
201
203
  - spec/data/tomcat/pom.xml
202
204
  - spec/lib/archiver_spec.rb
203
205
  - spec/lib/build_script_generator_spec.rb
206
+ - spec/lib/kit_runner_spec.rb
204
207
  - spec/lib/limited_network_user_spec_interactive.rb
205
- - spec/lib/maven_runner_spec.rb
206
208
  - spec/lib/maven_website_spec.rb
207
209
  - spec/lib/parent_pom_getter_spec.rb
208
210
  - spec/lib/pom_getter_spec.rb
@@ -258,8 +260,8 @@ test_files:
258
260
  - spec/data/tomcat/pom.xml
259
261
  - spec/lib/archiver_spec.rb
260
262
  - spec/lib/build_script_generator_spec.rb
263
+ - spec/lib/kit_runner_spec.rb
261
264
  - spec/lib/limited_network_user_spec_interactive.rb
262
- - spec/lib/maven_runner_spec.rb
263
265
  - spec/lib/maven_website_spec.rb
264
266
  - spec/lib/parent_pom_getter_spec.rb
265
267
  - spec/lib/pom_getter_spec.rb
@@ -1,57 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'find'
4
- require 'pathname'
5
-
6
- module Gjp
7
- # runs Maven from a gjp kit with gjp-specific options
8
- class MavenRunner
9
- include Logger
10
-
11
- def initialize(project)
12
- @project = project
13
- end
14
-
15
- # finds mvn in kit
16
- def find_maven_executable
17
- @project.from_directory do
18
- Find.find("kit") do |path|
19
- if path =~ /bin\/mvn$/
20
- log.debug("found Maven executable: #{path}")
21
- return path
22
- end
23
- end
24
- end
25
-
26
- log.debug("Maven executable not found")
27
- nil
28
- end
29
-
30
- # returns a command line for running Maven from the specified
31
- # prefix
32
- def get_maven_commandline(prefix)
33
- maven_executable = find_maven_executable
34
-
35
- if maven_executable != nil
36
- mvn_path = File.join(prefix, maven_executable)
37
- repo_path = File.join(prefix, "kit", "m2")
38
- config_path = File.join(prefix, "kit", "m2", "settings.xml")
39
-
40
- "#{mvn_path} -Dmaven.repo.local=#{repo_path} -s#{config_path}"
41
- else
42
- raise MavenNotFoundException
43
- end
44
- end
45
-
46
- # runs mvn in a subprocess
47
- def mvn(options)
48
- full_commandline = "#{get_maven_commandline(@project.full_path)} #{options.join(' ')}"
49
- log.debug full_commandline
50
-
51
- Process.wait(Process.spawn(full_commandline))
52
- end
53
- end
54
-
55
- class MavenNotFoundException < Exception
56
- end
57
- end
@@ -1,68 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Gjp::MavenRunner do
6
-
7
- before(:each) do
8
- @project_path = File.join("spec", "data", "test-project")
9
- Dir.mkdir(@project_path)
10
-
11
- Gjp::Project.init(@project_path)
12
- @project = Gjp::Project.new(@project_path)
13
- @maven_runner = Gjp::MavenRunner.new(@project)
14
- end
15
-
16
- after(:each) do
17
- FileUtils.rm_rf(@project_path)
18
- end
19
-
20
- describe "#find_maven_executable" do
21
- it "finds a Maven executable in kit" do
22
- mock_maven_executable
23
- @maven_runner.find_maven_executable.should eq @maven_executable
24
- end
25
- it "doesn't find a Maven executable in kit" do
26
- @maven_runner.find_maven_executable.should be_nil
27
- end
28
- end
29
-
30
- describe "#get_maven_commandline" do
31
- it "returns commandline options for running maven" do
32
- mock_maven_executable
33
-
34
- @project.from_directory do
35
- commandline = @maven_runner.get_maven_commandline(".")
36
- commandline.should eq "./#{@maven_executable} -Dmaven.repo.local=./kit/m2 -s./kit/m2/settings.xml"
37
- end
38
- end
39
- it "doesn't return commandline options if Maven is not available" do
40
- expect { @maven_runner.get_maven_commandline(".") }.to raise_error(Gjp::MavenNotFoundException)
41
- end
42
- end
43
-
44
- describe "#mvn" do
45
- it "runs maven" do
46
- mock_maven_executable
47
- @project.from_directory do
48
- @maven_runner.mvn(["extra-option"])
49
- File.read("test_out").strip.should match /extra-option$/
50
- end
51
- end
52
- it "doesn't run Maven if it is not available" do
53
- @project.from_directory do
54
- expect { @maven_runner.mvn([]) }.to raise_error(Gjp::MavenNotFoundException)
55
- end
56
- end
57
- end
58
-
59
- def mock_maven_executable
60
- Dir.chdir(@project_path) do
61
- @bin_dir = File.join("kit", "mvn", "bin")
62
- FileUtils.mkdir_p(@bin_dir)
63
- @maven_executable = File.join(@bin_dir, "mvn")
64
- File.open(@maven_executable, "w") { |io| io.puts "echo $0 $*>test_out" }
65
- File.chmod(0777, @maven_executable)
66
- end
67
- end
68
- end