gjp 0.23.0 → 0.24.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -101,7 +101,7 @@ Note that, if the build was unsusccesful, the following command can be used to c
101
101
 
102
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-package-script commons-collections
104
+ gjp generate-package-script
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
 
@@ -123,14 +123,14 @@ You can inspect the generated "galaxy-kit.spec" file, but in general you should
123
123
 
124
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:
125
125
 
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
128
- less output/commons-collections/commons-collections.spec
126
+ gjp generate-package-archive
127
+ gjp generate-package-spec
128
+ less ../commons-collections.spec
129
129
 
130
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
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
- Packages are ready to be submitted to an OBS project. As OBS integration is not yet implemented, refer to OBS documentation to do that.
133
+ OBS users: note that the output/ directory created by gjp can be submitted or used as OBS project. Feel free to replace it with a symlink pointing at your home OBS project, or use symlinks from your OBS project to its contents.
134
134
 
135
135
  #### Ant packages
136
136
 
@@ -179,7 +179,7 @@ You are advised to use [Maven Central](http://search.maven.org/) to search for s
179
179
 
180
180
  ### Troubleshooting
181
181
 
182
- `gjp` internally uses `git` to keep track of files, any gjp project is actually also a `git` repo. Feel free to navigate it, you can commit, push and pull freely as long as the `gjp` tags are preserved. You can also delete commits and tags, effectively rewiding gjp history (just make sure to delete all tags pointing to a certain commit when you discard it).
182
+ `gjp` internally uses `git` to keep track of files, any gjp project is actually also a `git` repo. Feel free to navigate it, you can commit, push and pull freely as long as the `gjp` tags are preserved. You can also delete commits and tags, effectively rewinding gjp history (just make sure to delete all tags pointing to a certain commit when you discard it).
183
183
 
184
184
  ## Motivation
185
185
 
@@ -23,15 +23,14 @@ cd ..
23
23
  gjp dry-run
24
24
  cd src/commons-collections/commons-collections-3.2.1-src/
25
25
  gjp mvn package -DskipTests
26
- cd ../../..
27
26
  gjp finish
28
27
 
29
28
  gjp generate-kit-archive
30
29
  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
-
30
+ gjp generate-package-script
31
+ gjp generate-package-archive
32
+ gjp generate-package-spec
33
+ cd ../../..
35
34
 
36
35
  cd src
37
36
  mkdir commons-fileupload
@@ -43,14 +42,14 @@ rm commons-fileupload-1.3-src.zip
43
42
  gjp dry-run
44
43
  cd commons-fileupload-1.3-src/
45
44
  gjp mvn package -DskipTests
46
- cd ../../..
47
45
  gjp finish
48
46
 
49
47
  gjp generate-kit-archive -i
50
48
  gjp generate-kit-spec
51
-
52
- gjp generate-package-archive commons-fileupload
53
- gjp generate-package-spec commons-fileupload src/commons-fileupload/commons-fileupload-1.3-src/pom.xml
49
+ gjp generate-package-script
50
+ gjp generate-package-archive
51
+ gjp generate-package-spec
52
+ cd ../../..
54
53
 
55
54
 
56
55
  echo "**************** All Done ****************"
@@ -134,12 +134,13 @@ module Gjp
134
134
  end
135
135
 
136
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"
137
+ parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", :default => "."
138
138
  def execute
139
139
  checking_exceptions do
140
140
  project = Gjp::Project.new(".")
141
+ package_name = project.get_package_name(directory)
141
142
  history_file = File.join(Dir.home, ".bash_history")
142
- result_path, conflict_count = Gjp::ScriptGenerator.new(project, history_file).generate_build_script(name)
143
+ result_path, conflict_count = Gjp::ScriptGenerator.new(project, history_file).generate_build_script(package_name)
143
144
  puts "#{format_path(result_path, project)} generated"
144
145
  if conflict_count > 0
145
146
  puts "Warning: #{conflict_count} unresolved conflicts"
@@ -150,12 +151,13 @@ module Gjp
150
151
 
151
152
  subcommand "generate-package-spec", "Create or refresh a spec file for a package" do
152
153
  option ["-f", "--filter"], "FILTER", "filter files to be installed by this spec", :default => "*.jar"
153
- parameter "NAME", "name of a package, that is, an src/ subdirectory name"
154
- parameter "POM", "a pom file path or URI"
154
+ parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", :default => "."
155
+ parameter "[POM]", "a pom file path", :default => "pom.xml"
155
156
  def execute
156
157
  checking_exceptions do
157
158
  project = Gjp::Project.new(".")
158
- result_path, conflict_count = Gjp::SpecGenerator.new(project).generate_package_spec name, pom, filter
159
+ package_name = project.get_package_name(directory)
160
+ result_path, conflict_count = Gjp::SpecGenerator.new(project).generate_package_spec package_name, pom, filter
159
161
  puts "#{format_path(result_path, project)} generated"
160
162
  if conflict_count > 0
161
163
  puts "Warning: #{conflict_count} unresolved conflicts"
@@ -165,11 +167,12 @@ module Gjp
165
167
  end
166
168
 
167
169
  subcommand "generate-package-archive", "Create or refresh a package tarball" do
168
- parameter "NAME", "name of a package, that is, an src/ subdirectory name"
170
+ parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", :default => "."
169
171
  def execute
170
172
  checking_exceptions do
171
173
  project = Gjp::Project.new(".")
172
- result_path = Gjp::Archiver.new(project).archive_package name
174
+ package_name = project.get_package_name(directory)
175
+ result_path = Gjp::Archiver.new(project).archive_package package_name
173
176
  puts "#{format_path(result_path, project)} generated"
174
177
  end
175
178
  end
@@ -271,12 +274,14 @@ module Gjp
271
274
  $stderr.puts e
272
275
  rescue Errno::EEXIST => e
273
276
  $stderr.puts e
274
- rescue NotGjpDirectoryException
275
- $stderr.puts "This is not a gjp project directory, see gjp init"
276
- rescue GitAlreadyInitedException
277
+ rescue NoProjectDirectoryError => e
278
+ $stderr.puts "#{e.directory} not a gjp project directory, see gjp init"
279
+ rescue NoPackageDirectoryException => e
280
+ $stderr.puts "#{e.directory} is not a gjp package directory, see README"
281
+ rescue GitAlreadyInitedError => e
277
282
  $stderr.puts "This directory is already a gjp project"
278
- rescue Gjp::ExecutableNotFoundException
279
- $stderr.puts "Executable not found in kit/ or any of its subdirectories"
283
+ rescue ExecutableNotFoundError => e
284
+ $stderr.puts "Executable #{e.executable} not found in kit/ or any of its subdirectories"
280
285
  end
281
286
  end
282
287
  end
@@ -18,7 +18,7 @@ module Gjp
18
18
  if Dir.exists?(".git") == false
19
19
  `git init`
20
20
  else
21
- raise GitAlreadyInitedException
21
+ raise GitAlreadyInitedError
22
22
  end
23
23
  end
24
24
  end
@@ -80,10 +80,18 @@ module Gjp
80
80
  # reverts path contents as per specified tag
81
81
  def revert_whole_directory(path, tag)
82
82
  Dir.chdir(@directory) do
83
- `git rm -rf --ignore-unmatch #{path}`
83
+ # reverts added and modified files, both in index and working tree
84
84
  `git checkout -f gjp_#{tag} -- #{path}`
85
85
 
86
- `git clean -f -d #{path}`
86
+ # compute the list of deleted files
87
+ files_in_tag = `git ls-tree --name-only -r gjp_#{tag} -- #{path}`.split("\n")
88
+ files_in_head = `git ls-tree --name-only -r HEAD -- #{path}`.split("\n")
89
+ files_added_after_head = `git ls-files -o -- #{path}`.split("\n")
90
+ files_to_delete = files_in_head - files_in_tag + files_added_after_head
91
+
92
+ files_to_delete.each do |file|
93
+ File.delete(file)
94
+ end
87
95
  end
88
96
  end
89
97
 
@@ -115,6 +123,6 @@ module Gjp
115
123
  end
116
124
  end
117
125
 
118
- class GitAlreadyInitedException < Exception
126
+ class GitAlreadyInitedError < StandardError
119
127
  end
120
128
  end
@@ -50,7 +50,7 @@ module Gjp
50
50
 
51
51
  "#{mvn_path} -Dmaven.repo.local=#{repo_path} -s#{config_path}"
52
52
  else
53
- raise ExecutableNotFoundException
53
+ raise ExecutableNotFoundError.new("mvn")
54
54
  end
55
55
  end
56
56
 
@@ -69,11 +69,16 @@ module Gjp
69
69
 
70
70
  "#{ant_path}"
71
71
  else
72
- raise ExecutableNotFoundException
72
+ raise ExecutableNotFoundError.new("ant")
73
73
  end
74
74
  end
75
75
  end
76
76
 
77
- class ExecutableNotFoundException < Exception
77
+ class ExecutableNotFoundError < Exception
78
+ attr_reader :executable
79
+
80
+ def initialize(executable)
81
+ @executable = executable
82
+ end
78
83
  end
79
84
  end
@@ -30,7 +30,7 @@ module Gjp
30
30
  result = File.expand_path("..", result)
31
31
  end
32
32
 
33
- raise NotGjpDirectoryException if result == "/"
33
+ raise NoProjectDirectoryError.new(starting_dir) if result == "/"
34
34
 
35
35
  result
36
36
  end
@@ -42,6 +42,23 @@ module Gjp
42
42
  File.directory?(File.join(dir, ".git"))
43
43
  end
44
44
 
45
+ # returns the package name corresponding to the specified dir, if any
46
+ # raises NoPackageDirectoryError if dir is not a (sub)directory of a package
47
+ def get_package_name(dir)
48
+ begin
49
+ dir_path = Pathname.new(File.expand_path(dir)).relative_path_from(Pathname.new(@full_path))
50
+ components = dir_path.to_s.split(File::SEPARATOR)
51
+
52
+ if components.count >= 2 and components.first == "src" and Dir.exist?(File.join(@full_path, components[0], components[1]))
53
+ components[1]
54
+ else
55
+ raise NoPackageDirectoryError
56
+ end
57
+ rescue ArgumentError, NoProjectDirectoryError
58
+ raise NoPackageDirectoryError.new(dir)
59
+ end
60
+ end
61
+
45
62
  # inits a new project directory structure
46
63
  def self.init(dir)
47
64
  Dir.chdir(dir) do
@@ -57,6 +74,7 @@ module Gjp
57
74
  template_manager.copy "output", "."
58
75
  template_manager.copy "kit", "."
59
76
  template_manager.copy "src", "."
77
+ template_manager.copy "gitignore", ".gitignore"
60
78
 
61
79
  project.take_snapshot "Template files added", :init
62
80
  end
@@ -210,6 +228,18 @@ module Gjp
210
228
  end
211
229
  end
212
230
 
213
- class NotGjpDirectoryException < Exception
231
+ class NoProjectDirectoryError < StandardError
232
+ attr_reader :directory
233
+
234
+ def initialize(directory)
235
+ @directory = directory
236
+ end
237
+ end
238
+ class NoPackageDirectoryError < StandardError
239
+ attr_reader :directory
240
+
241
+ def initialize(directory)
242
+ @directory = directory
243
+ end
214
244
  end
215
245
  end
@@ -11,34 +11,50 @@ module Gjp
11
11
 
12
12
  def generate_kit_spec
13
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")
14
+ spec_name = "#{@project.name}-kit.spec"
15
+ spec_path = File.join("kit", spec_name)
16
+ output_dir = File.join("output", "#{@project.name}-kit")
17
+ FileUtils.mkdir_p(output_dir)
17
18
 
18
19
  adapter = Gjp::KitSpecAdapter.new(@project)
19
-
20
20
  conflict_count = generate_merging("kit.spec", adapter.get_binding, spec_path, :generate_kit_spec)
21
+
22
+ symlink_to_output(spec_path, output_dir)
23
+
21
24
  [spec_path, conflict_count]
22
25
  end
23
26
  end
24
27
 
25
- def generate_package_spec(name, pom, filter)
28
+ def generate_package_spec(name, pom_path, filter)
29
+ pom = Gjp::Pom.new(pom_path)
26
30
  @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")
30
-
31
- adapter = Gjp::PackageSpecAdapter.new(@project, name, Gjp::Pom.new(pom), filter)
31
+ spec_name = "#{name}.spec"
32
+ spec_path = File.join("src", name, spec_name)
33
+ output_dir = File.join("output", name)
34
+ FileUtils.mkdir_p(output_dir)
32
35
 
36
+ adapter = Gjp::PackageSpecAdapter.new(@project, name, pom, filter)
33
37
  conflict_count = generate_merging("package.spec", adapter.get_binding, spec_path, "generate_#{name}_spec")
38
+
39
+ symlink_to_output(spec_path, output_dir)
40
+
34
41
  [spec_path, conflict_count]
35
42
  end
36
43
  end
37
44
 
45
+ private
46
+
38
47
  # generates a spec file from a template and 3-way merges it
39
48
  def generate_merging(template, binding, path, tag_prefix)
40
49
  new_content = TemplateManager.new.generate(template, binding)
41
50
  @project.merge_new_content(new_content, path, "Spec generated", tag_prefix)
42
51
  end
52
+
53
+ # links a spec file in a subdirectory of output/
54
+ def symlink_to_output(spec_path, destination_dir)
55
+ spec_name = Pathname.new(spec_path).basename.to_s
56
+ destination_spec_path = File.join(destination_dir, spec_name)
57
+ FileUtils.symlink(File.expand_path(spec_path), destination_spec_path, :force => true)
58
+ end
43
59
  end
44
60
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Gjp
4
- VERSION = "0.23.0"
4
+ VERSION = "0.24.0"
5
5
  end
@@ -1,2 +1,2 @@
1
1
  *.gjp_user_edited
2
- *.tar.xz
2
+ output/
@@ -19,7 +19,7 @@ describe Gjp::Git do
19
19
  it "complains if a double initialization is attempted" do
20
20
  expect {
21
21
  @git.init
22
- }.to raise_error(Gjp::GitAlreadyInitedException)
22
+ }.to raise_error(Gjp::GitAlreadyInitedError)
23
23
  end
24
24
  end
25
25
 
@@ -37,7 +37,7 @@ describe Gjp::KitRunner do
37
37
  end
38
38
  end
39
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)
40
+ expect { @kit_runner.get_maven_commandline(".") }.to raise_error(Gjp::ExecutableNotFoundError)
41
41
  end
42
42
  end
43
43
 
@@ -51,7 +51,7 @@ describe Gjp::KitRunner do
51
51
  end
52
52
  it "doesn't run Maven if it is not available" do
53
53
  @project.from_directory do
54
- expect { @kit_runner.mvn([]) }.to raise_error(Gjp::ExecutableNotFoundException)
54
+ expect { @kit_runner.mvn([]) }.to raise_error(Gjp::ExecutableNotFoundError)
55
55
  end
56
56
  end
57
57
  end
@@ -67,7 +67,7 @@ describe Gjp::KitRunner do
67
67
  end
68
68
  end
69
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)
70
+ expect { @kit_runner.get_ant_commandline(".") }.to raise_error(Gjp::ExecutableNotFoundError)
71
71
  end
72
72
  end
73
73
 
@@ -81,7 +81,7 @@ describe Gjp::KitRunner do
81
81
  end
82
82
  it "doesn't run Ant if it is not available" do
83
83
  @project.from_directory do
84
- expect { @kit_runner.ant([]) }.to raise_error(Gjp::ExecutableNotFoundException)
84
+ expect { @kit_runner.ant([]) }.to raise_error(Gjp::ExecutableNotFoundError)
85
85
  end
86
86
  end
87
87
  end
@@ -31,7 +31,54 @@ 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(Gjp::NotGjpDirectoryException)
34
+ }.to raise_error(Gjp::NoProjectDirectoryError)
35
+ end
36
+ end
37
+
38
+ describe ".get_package_name" do
39
+ it "raises an error with a directory outside a gjp project" do
40
+ expect {
41
+ @project.get_package_name("/")
42
+ }.to raise_error(Gjp::NoPackageDirectoryError)
43
+ end
44
+
45
+ it "raises an error with a gjp project directory" do
46
+ expect {
47
+ @project.get_package_name(@project_path)
48
+ }.to raise_error(Gjp::NoPackageDirectoryError)
49
+ end
50
+
51
+ it "raises an error with a gjp kit directory" do
52
+ expect {
53
+ @project.get_package_name(File.join(@project_path, "kit"))
54
+ }.to raise_error(Gjp::NoPackageDirectoryError)
55
+ end
56
+
57
+ it "raises an error with a gjp src directory" do
58
+ expect {
59
+ @project.get_package_name(File.join(@project_path, "src"))
60
+ }.to raise_error(Gjp::NoPackageDirectoryError)
61
+ end
62
+
63
+ it "raises an error with a nonexisting package directory" do
64
+ expect {
65
+ @project.get_package_name(File.join(@project_path, "src", "test_package"))
66
+ }.to raise_error(Gjp::NoPackageDirectoryError)
67
+ end
68
+
69
+ it "returns the package on an existing package directory" do
70
+ FileUtils.mkdir_p(File.join(@project_path, "src", "test_package"))
71
+ @project.get_package_name(File.join(@project_path, "src", "test_package")).should eq "test_package"
72
+ end
73
+
74
+ it "returns the package on an existing package subdirectory" do
75
+ FileUtils.mkdir_p(File.join(@project_path, "src", "test_package", "subdir1"))
76
+ @project.get_package_name(File.join(@project_path, "src", "test_package", "subdir1")).should eq "test_package"
77
+ end
78
+
79
+ it "returns the package on an existing package subsubdirectory" do
80
+ FileUtils.mkdir_p(File.join(@project_path, "src", "test_package", "subdir1", "subdir2"))
81
+ @project.get_package_name(File.join(@project_path, "src", "test_package", "subdir1", "subdir2")).should eq "test_package"
35
82
  end
36
83
  end
37
84
 
@@ -114,7 +114,7 @@ describe Gjp::SpecGenerator do
114
114
  end
115
115
 
116
116
  FileUtils.copy(File.join("spec", "data", "nailgun", "pom.xml"), @project_path)
117
- @spec_generator.generate_package_spec "test", "pom.xml", "*.jar"
117
+ @spec_generator.generate_package_spec "test", File.join(@project_path, "pom.xml"), "*.jar"
118
118
 
119
119
  @project.from_directory do
120
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.23.0
4
+ version: 0.24.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-11-25 00:00:00.000000000 Z
12
+ date: 2013-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -177,11 +177,11 @@ files:
177
177
  - lib/gjp/template_manager.rb
178
178
  - lib/gjp/version.rb
179
179
  - lib/gjp/version_matcher.rb
180
+ - lib/template/gitignore
180
181
  - lib/template/kit.spec
181
182
  - lib/template/kit/CONTENTS
182
183
  - lib/template/kit/jars/CONTENTS
183
184
  - lib/template/kit/m2/settings.xml
184
- - lib/template/output/.gitignore
185
185
  - lib/template/output/CONTENTS
186
186
  - lib/template/package.spec
187
187
  - lib/template/src/CONTENTS