gjp 0.22.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -38,7 +38,7 @@ The basic process is:
38
38
  * a `gjp` project is created;
39
39
  * package sources are added in `src/<package name>`;
40
40
  * any other file that is needed for the build, except the JDK, is added in binary form (jars, the Maven executable, plugins, etc.) in `kit/`. In `gjp` a **kit** is a set of binary files that satisfies all build dependencies in a `gjp` project;
41
- * a build is attempted and during the build, `gjp` keeps track of file changes. When it finishes, `gjp` restores `src/` in its original state, making it a "repeatable dry-run build". `gjp` will retain any files that were automatically downloaded by Maven or other similar tools in `kit/`, along with other binary build dependencies, and create a list of files produced by the build for later spec generation;
41
+ * a build is attempted and during the build, `gjp` keeps track of file changes. When it finishes, `gjp` restores `src/` in its original state, making it a "repeatable dry-run build". `gjp` will retain any files that were automatically downloaded by Maven or other similar tools in `kit/`, along with other binary build dependencies, and note any produced file for later spec generation;
42
42
  * `gjp` produces spec files for two packages: one for the project itself and one for the kit needed to build it;
43
43
  * kit and project packages can be submitted to [OBS](http://en.opensuse.org/openSUSE:Build_Service). Project package will rebuild cleanly because it needs no Internet access - all files were already downloaded during the dry-run phase above and are included in the kit.
44
44
 
@@ -91,7 +91,7 @@ Success! Now we have to tell gjp to return in normal mode:
91
91
 
92
92
  gjp finish
93
93
 
94
- At this point `gjp` restored `src/` as it was before the build and listed outputs in `output/commons-collections/produced_file_list`. It will be used later to compile the `%install` and `%files` sections of the project spec.
94
+ At this point `gjp` restored `src/` as it was before the build while taking note of any produced file, so that later it will be able to output `%install` and `%files` sections of the project spec file automatically.
95
95
 
96
96
  Note that, if the build was unsusccesful, the following command can be used to cancel it and return to pre-dry running state:
97
97
 
@@ -99,9 +99,9 @@ Note that, if the build was unsusccesful, the following command can be used to c
99
99
 
100
100
  #### Generating a build script
101
101
 
102
- `gjp` expects that all commands needed to build a package are put in a `build.sh` script in `src/<package name>`. If you are a Bash user you are lucky - `gjp` can do this for you by looking at your command history! Just type:
102
+ `gjp` expects that all commands needed to build a package are in a `build.sh` script in `src/<package name>`. If you are a Bash user you are lucky - `gjp` can create one for you by looking at your command history! Just type:
103
103
 
104
- gjp generate-build-script commons-collections
104
+ gjp generate-package-script commons-collections
105
105
 
106
106
  Note that `gjp` will substitute the `gjp mvn` calls with equivalent lines that are actually runnable on a build host without `gjp` itself.
107
107
 
@@ -132,6 +132,14 @@ You can also edit the specs file manually if you want. When you later regenerate
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
 
135
+ #### Ant packages
136
+
137
+ Building Ant packages is not really different from Maven ones, as `gjp ant` will operate exactly like `gjp mvn`.
138
+
139
+ Sometimes you will have jar files distributed along with the source archive that will end up in `src/`: you don't want that, just run `gjp purge-jars` to have them moved to the kit. The command will generate a symlink back to the original, so builds will not fail.
140
+
141
+ Once built, you are advised to grab an "informational" pom.xml (via `gjp get-pom` or Maven Central) in order to generate its spec.
142
+
135
143
  #### Optional: running networkless dry-run builds
136
144
 
137
145
  `gjp` has a subcommand to setup a `nonet` user without Internet access, courtesy of `iptables`. You can simply retry the build using that user to see if it works. Note that the following commands will alter group permissions to allow both your current user and `nonet` to work on the same files.
@@ -15,9 +15,9 @@ unzip commons-collections-3.2.1-src.zip
15
15
  rm commons-collections-3.2.1-src.zip
16
16
 
17
17
  cd ../../kit
18
- wget http://apache.fastbull.org/maven/maven-3/3.1.0/binaries/apache-maven-3.1.0-bin.zip
19
- unzip apache-maven-3.1.0-bin.zip
20
- rm apache-maven-3.1.0-bin.zip
18
+ wget http://apache.fastbull.org/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.zip
19
+ unzip apache-maven-*.zip
20
+ rm apache-maven-*.zip
21
21
  cd ..
22
22
 
23
23
  gjp dry-run
@@ -55,4 +55,4 @@ gjp generate-package-spec commons-fileupload src/commons-fileupload/commons-file
55
55
 
56
56
  echo "**************** All Done ****************"
57
57
 
58
- ls -lah output/*
58
+ ls -lah output/*
data/lib/gjp.rb CHANGED
@@ -2,7 +2,7 @@ require "gjp/version"
2
2
  require "gjp/logger"
3
3
  require "gjp/template_manager"
4
4
  require "gjp/git"
5
- require "gjp/build_script_generator"
5
+ require "gjp/script_generator"
6
6
  require "gjp/project"
7
7
  require "gjp/pom"
8
8
  require "gjp/version_matcher"
data/lib/gjp/cli.rb CHANGED
@@ -109,21 +109,11 @@ module Gjp
109
109
  end
110
110
  end
111
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
-
120
- subcommand "generate-build-script", "Create or refresh a build.sh file" do
121
- parameter "NAME", "name of a package, that is, an src/ subdirectory name"
112
+ subcommand "generate-kit-spec", "Create or refresh a spec file for the kit" do
122
113
  def execute
123
114
  checking_exceptions do
124
115
  project = Gjp::Project.new(".")
125
- history_file = File.join(Dir.home, ".bash_history")
126
- result_path, conflict_count = Gjp::BuildScriptGenerator.new(project, history_file).generate_build_script(name)
116
+ result_path, conflict_count = Gjp::SpecGenerator.new(project).generate_kit_spec
127
117
  puts "#{format_path(result_path, project)} generated"
128
118
  if conflict_count > 0
129
119
  puts "Warning: #{conflict_count} unresolved conflicts"
@@ -132,26 +122,28 @@ module Gjp
132
122
  end
133
123
  end
134
124
 
135
- subcommand "generate-kit-spec", "Create or refresh a spec file for the kit" do
125
+ subcommand "generate-kit-archive", "Create or refresh the kit tarball" do
126
+ option ["-i", "--incremental"], :flag, "create an archive with only the difference from the previous one"
136
127
  def execute
137
128
  checking_exceptions do
138
129
  project = Gjp::Project.new(".")
139
- result_path, conflict_count = Gjp::SpecGenerator.new(project).generate_kit_spec
130
+ result_path = Gjp::Archiver.new(project).archive_kit(incremental?)
140
131
  puts "#{format_path(result_path, project)} generated"
141
- if conflict_count > 0
142
- puts "Warning: #{conflict_count} unresolved conflicts"
143
- end
144
132
  end
145
133
  end
146
134
  end
147
135
 
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"
136
+ subcommand "generate-package-script", "Create or refresh a build.sh file for a package" do
137
+ parameter "NAME", "name of a package, that is, an src/ subdirectory name"
150
138
  def execute
151
139
  checking_exceptions do
152
140
  project = Gjp::Project.new(".")
153
- result_path = Gjp::Archiver.new(project).archive_kit(incremental?)
141
+ history_file = File.join(Dir.home, ".bash_history")
142
+ result_path, conflict_count = Gjp::ScriptGenerator.new(project, history_file).generate_build_script(name)
154
143
  puts "#{format_path(result_path, project)} generated"
144
+ if conflict_count > 0
145
+ puts "Warning: #{conflict_count} unresolved conflicts"
146
+ end
155
147
  end
156
148
  end
157
149
  end
@@ -183,6 +175,14 @@ module Gjp
183
175
  end
184
176
  end
185
177
 
178
+ subcommand "purge-jars", "Locates jars in src/ and moves them to kit/" do
179
+ def execute
180
+ Gjp::Project.new(".").purge_jars.each do |original, final|
181
+ puts "Replaced #{original} with symlink pointing to to #{final}"
182
+ end
183
+ end
184
+ end
185
+
186
186
  subcommand "set-up-nonet-user", "Sets up a \"nonet\" user that cannot access the network" do
187
187
  def execute
188
188
  checking_exceptions do
data/lib/gjp/git.rb CHANGED
@@ -26,8 +26,20 @@ module Gjp
26
26
  # returns a list of filenames that changed in the repo
27
27
  # since the specified tag
28
28
  def changed_files_since(tag)
29
+ changed_files_between(tag, nil, ".")
30
+ end
31
+
32
+ # returns a list of filenames that changed in the repo
33
+ # between specified tags, in a certain directory
34
+ def changed_files_between(start_tag, end_tag, directory)
29
35
  Dir.chdir(@directory) do
30
- `git diff-tree --no-commit-id --name-only -r gjp_#{tag} HEAD`.split("\n")
36
+ prefixed_start_tag = "gjp_#{start_tag}"
37
+ prefixed_end_tag = if end_tag
38
+ "gjp_#{end_tag}"
39
+ else
40
+ "HEAD"
41
+ end
42
+ `git diff-tree --no-commit-id --name-only -r #{prefixed_start_tag} #{prefixed_end_tag} -- #{directory}`.split("\n")
31
43
  end
32
44
  end
33
45
 
@@ -36,15 +36,8 @@ module Gjp
36
36
  @runtime_dependency_ids = pom.runtime_dependency_ids
37
37
  @description = cleanup_description(pom.description, 1500)
38
38
 
39
- produced_file_list = File.join(project.full_path, "output", @name, "produced_file_list")
40
- @outputs = if File.exist?(produced_file_list)
41
- File.open(produced_file_list).readlines.map do |line|
42
- line.strip
43
- end.select do |line|
44
- File.fnmatch? filter, File.basename(line.strip)
45
- end
46
- else
47
- []
39
+ @outputs = project.get_produced_files(package_name).select do |file|
40
+ File.fnmatch? filter, File.basename(file)
48
41
  end
49
42
  end
50
43
 
data/lib/gjp/project.rb CHANGED
@@ -90,13 +90,9 @@ module Gjp
90
90
  @git.revert_whole_directory(".", latest_tag(:dry_run_started))
91
91
  @git.delete_tag(latest_tag(:dry_run_started))
92
92
  else
93
- take_snapshot "Changes during dry-run"
94
-
95
- update_produced_file_lists
96
- take_snapshot "File list updates"
93
+ take_snapshot "Changes during dry-run", :dry_run_changed
97
94
 
98
95
  @git.revert_whole_directory("src", latest_tag(:dry_run_started))
99
- take_snapshot "Sources reverted as before dry-run"
100
96
 
101
97
  take_snapshot "Dry run finished", :dry_run_finished
102
98
  end
@@ -105,38 +101,6 @@ module Gjp
105
101
  false
106
102
  end
107
103
 
108
- # updates files that contain lists of the output files produced by
109
- # the build of each package
110
- def update_produced_file_lists
111
- each_package_directory do |name, path|
112
- FileUtils.mkdir_p(File.join("output", name))
113
-
114
- list_file = File.join("output", name, "produced_file_list")
115
- tracked_files = if File.exists?(list_file)
116
- File.readlines(list_file).map { |line| line.strip }
117
- else
118
- []
119
- end
120
-
121
- files = (
122
- @git.changed_files_since(latest_tag(:dry_run_started))
123
- .select { |file| file.start_with?(path) }
124
- .map { |file|file[path.length + 1, file.length] }
125
- .concat(tracked_files)
126
- .uniq
127
- .sort
128
- )
129
-
130
- log.debug("writing file list for #{path}: #{files.to_s}")
131
-
132
- File.open(list_file, "w+") do |file_list|
133
- files.each do |file|
134
- file_list.puts file
135
- end
136
- end
137
- end
138
- end
139
-
140
104
  # takes a revertable snapshot of this project
141
105
  def take_snapshot(message, tag_prefix = nil, tag_message = nil)
142
106
  tag = if tag_prefix
@@ -200,23 +164,28 @@ module Gjp
200
164
  end
201
165
  end
202
166
 
203
- # runs a block for each package directory in src/
204
- def each_package_directory
205
- from_directory do
206
- Dir.foreach("src") do |entry|
207
- if File.directory?(File.join(Dir.getwd, "src", entry)) and entry != "." and entry != ".."
208
- directory = File.join("src", entry)
209
- yield entry, directory
210
- end
211
- end
212
- end
213
- end
214
-
215
167
  # returns the latest dry run start directory
216
168
  def latest_dry_run_directory
217
169
  @git.get_message(latest_tag(:dry_run_started))
218
170
  end
219
171
 
172
+ # returns a list of files produced during dry-runs in a certain package
173
+ def get_produced_files(package)
174
+ dry_run_count = latest_tag_count(:dry_run_changed)
175
+ log.debug "Getting produced files from #{dry_run_count} dry runs"
176
+ if dry_run_count >= 1
177
+ package_dir = File.join("src", package)
178
+ (1..dry_run_count).map do |i|
179
+ @git.changed_files_between("dry_run_started_#{i}", "dry_run_changed_#{i}", package_dir)
180
+ end
181
+ .flatten
182
+ .uniq
183
+ .sort
184
+ .map { |file| Pathname.new(file).relative_path_from(Pathname.new(package_dir)).to_s }
185
+ else
186
+ []
187
+ end
188
+ end
220
189
 
221
190
  # moves any .jar from src/ to kit/ and links it back
222
191
  def purge_jars
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Gjp
4
4
  # generates build scripts from bash_history
5
- class BuildScriptGenerator
5
+ class ScriptGenerator
6
6
  include Logger
7
7
 
8
8
  def initialize(project, history_path)
data/lib/gjp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Gjp
4
- VERSION = "0.22.0"
4
+ VERSION = "0.23.0"
5
5
  end
@@ -0,0 +1,83 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Gjp::Git do
6
+ before(:each) do
7
+ @git_path = File.expand_path(File.join("spec", "data", "test-repo"))
8
+ Dir.mkdir(@git_path)
9
+
10
+ @git = Gjp::Git.new(@git_path)
11
+ @git.init
12
+ end
13
+
14
+ after(:each) do
15
+ FileUtils.rm_rf(@git_path)
16
+ end
17
+
18
+ describe "#init" do
19
+ it "complains if a double initialization is attempted" do
20
+ expect {
21
+ @git.init
22
+ }.to raise_error(Gjp::GitAlreadyInitedException)
23
+ end
24
+ end
25
+
26
+ describe "#changed_files_since" do
27
+ it "lists files changed since a gjp tag" do
28
+ Dir.chdir(@git_path) do
29
+ File.open("file1", "w") do |file|
30
+ file.write "test"
31
+ end
32
+
33
+ @git.commit_whole_directory("test", "test")
34
+
35
+ File.open("file2", "w") do |file|
36
+ file.write "test"
37
+ end
38
+
39
+ @git.commit_whole_directory("test end")
40
+
41
+ files = @git.changed_files_since("test")
42
+
43
+ files.should_not include("file1")
44
+ files.should include("file2")
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "#changed_files_between" do
50
+ it "lists files changed between gjp tags" do
51
+ Dir.chdir(@git_path) do
52
+ File.open("file1", "w") do |file|
53
+ file.write "test"
54
+ end
55
+
56
+ @git.commit_whole_directory("test", "test_start")
57
+
58
+ File.open("file2", "w") do |file|
59
+ file.write "test"
60
+ end
61
+ Dir.mkdir("subdir")
62
+ File.open(File.join("subdir","file3"), "w") do |file|
63
+ file.write "test"
64
+ end
65
+
66
+ @git.commit_whole_directory("test", "test_end")
67
+
68
+ File.open("file4", "w") do |file|
69
+ file.write "test"
70
+ end
71
+
72
+ @git.commit_whole_directory("test")
73
+
74
+ files = @git.changed_files_between("test_start", "test_end", "subdir")
75
+
76
+ files.should_not include("file1")
77
+ files.should_not include("file2")
78
+ files.should include("subdir/file3")
79
+ files.should_not include("file4")
80
+ end
81
+ end
82
+ end
83
+ end
@@ -97,11 +97,10 @@ describe Gjp::Project do
97
97
  @project.is_dry_running.should be_false
98
98
 
99
99
  @project.from_directory do
100
- `git rev-list --all`.split("\n").length.should eq 5
100
+ `git rev-list --all`.split("\n").length.should eq 4
101
101
  File.read("src/abc/test").should eq "A\n"
102
- File.readlines(File.join("output", "abc", "produced_file_list")).should include("test2\n")
103
102
 
104
- `git diff-tree --no-commit-id --name-only -r HEAD~`.split("\n").should_not include("src/abc/test2")
103
+ `git diff-tree --no-commit-id --name-only -r HEAD~`.split("\n").should include("src/abc/test2")
105
104
  File.exists?("src/abc/test2").should be_false
106
105
  end
107
106
  end
@@ -134,8 +133,6 @@ describe Gjp::Project do
134
133
 
135
134
  File.read("kit/test").should eq "A\n"
136
135
  File.exists?("kit/test2").should be_false
137
-
138
- File.exists?(File.join("output", "abc", "produced_file_list")).should be_false
139
136
  end
140
137
  end
141
138
  end
@@ -161,6 +158,35 @@ describe Gjp::Project do
161
158
  end
162
159
  end
163
160
 
161
+ describe "#get_produced_files" do
162
+ it "gets a list of produced files" do
163
+ @project.from_directory do
164
+ Dir.mkdir("src/abc")
165
+ `echo A > src/abc/added_outside_dry_run`
166
+ end
167
+
168
+ @project.dry_run.should be_true
169
+ @project.from_directory do
170
+ `echo A > src/abc/added_in_first_dry_run`
171
+ `echo A > src/added_outside_directory`
172
+ end
173
+ @project.finish(false).should be_true
174
+
175
+ @project.dry_run.should be_true
176
+ @project.from_directory do
177
+ `echo A > src/abc/added_in_second_dry_run`
178
+ end
179
+ @project.finish(false).should be_true
180
+
181
+ list = @project.get_produced_files("abc")
182
+ list.should include("added_in_first_dry_run")
183
+ list.should include("added_in_second_dry_run")
184
+
185
+ list.should_not include("added_outside_dry_run")
186
+ list.should_not include("added_outside_directory")
187
+ end
188
+ end
189
+
164
190
  describe "#purge_jars" do
165
191
  it "moves jars in kit/jars" do
166
192
  @project.from_directory do
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Gjp::BuildScriptGenerator do
5
+ describe Gjp::ScriptGenerator do
6
6
  before(:each) do
7
7
  @project_path = File.join("spec", "data", "test-project")
8
8
  Dir.mkdir(@project_path)
@@ -22,7 +22,7 @@ describe Gjp::BuildScriptGenerator do
22
22
 
23
23
  FileUtils.mkdir_p(File.join("src", "test-package"))
24
24
 
25
- @generator = Gjp::BuildScriptGenerator.new(@project, "history")
25
+ @generator = Gjp::ScriptGenerator.new(@project, "history")
26
26
  end
27
27
 
28
28
  mock_maven_executable
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.22.0
4
+ version: 0.23.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-11 00:00:00.000000000 Z
12
+ date: 2013-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -158,7 +158,6 @@ files:
158
158
  - integration-tests/commons.sh
159
159
  - lib/gjp.rb
160
160
  - lib/gjp/archiver.rb
161
- - lib/gjp/build_script_generator.rb
162
161
  - lib/gjp/cli.rb
163
162
  - lib/gjp/git.rb
164
163
  - lib/gjp/kit_runner.rb
@@ -171,6 +170,7 @@ files:
171
170
  - lib/gjp/pom.rb
172
171
  - lib/gjp/pom_getter.rb
173
172
  - lib/gjp/project.rb
173
+ - lib/gjp/script_generator.rb
174
174
  - lib/gjp/source_address_getter.rb
175
175
  - lib/gjp/source_getter.rb
176
176
  - lib/gjp/spec_generator.rb
@@ -202,7 +202,7 @@ files:
202
202
  - spec/data/struts-apps/pom.xml
203
203
  - spec/data/tomcat/pom.xml
204
204
  - spec/lib/archiver_spec.rb
205
- - spec/lib/build_script_generator_spec.rb
205
+ - spec/lib/git_spec.rb
206
206
  - spec/lib/kit_runner_spec.rb
207
207
  - spec/lib/limited_network_user_spec_interactive.rb
208
208
  - spec/lib/maven_website_spec.rb
@@ -210,6 +210,7 @@ files:
210
210
  - spec/lib/pom_getter_spec.rb
211
211
  - spec/lib/pom_spec.rb
212
212
  - spec/lib/project_spec.rb
213
+ - spec/lib/script_generator_spec.rb
213
214
  - spec/lib/source_address_getter_spec.rb
214
215
  - spec/lib/source_getter_spec.rb
215
216
  - spec/lib/spec_generator_spec.rb
@@ -259,7 +260,7 @@ test_files:
259
260
  - spec/data/struts-apps/pom.xml
260
261
  - spec/data/tomcat/pom.xml
261
262
  - spec/lib/archiver_spec.rb
262
- - spec/lib/build_script_generator_spec.rb
263
+ - spec/lib/git_spec.rb
263
264
  - spec/lib/kit_runner_spec.rb
264
265
  - spec/lib/limited_network_user_spec_interactive.rb
265
266
  - spec/lib/maven_website_spec.rb
@@ -267,6 +268,7 @@ test_files:
267
268
  - spec/lib/pom_getter_spec.rb
268
269
  - spec/lib/pom_spec.rb
269
270
  - spec/lib/project_spec.rb
271
+ - spec/lib/script_generator_spec.rb
270
272
  - spec/lib/source_address_getter_spec.rb
271
273
  - spec/lib/source_getter_spec.rb
272
274
  - spec/lib/spec_generator_spec.rb