gjp 0.11.2 → 0.13.1
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/.gitignore +1 -0
- data/LICENSE +1 -1
- data/README.md +1 -0
- data/lib/gjp/archiver.rb +49 -0
- data/lib/gjp/cli.rb +41 -2
- data/lib/gjp/maven_runner.rb +15 -5
- data/lib/gjp/project.rb +52 -37
- data/lib/gjp/scaffolder.rb +42 -0
- data/lib/gjp/template_manager.rb +25 -0
- data/lib/gjp/version.rb +1 -1
- data/lib/gjp.rb +3 -0
- data/lib/template/archives/CONTENTS +3 -0
- data/lib/template/kit.spec +51 -0
- data/lib/template/specs/CONTENTS +3 -0
- data/spec/lib/archiver_spec.rb +60 -0
- data/spec/lib/maven_runner_spec.rb +31 -14
- data/spec/lib/project_spec.rb +2 -2
- data/spec/lib/scaffolder_spec.rb +94 -0
- data/spec/lib/template_manager_spec.rb +53 -0
- metadata +14 -2
data/.gitignore
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -24,6 +24,7 @@ Currently available tools:
|
|
24
24
|
* `gjp finish` marks the end of a phase;
|
25
25
|
* `gjp dry-run` starts a new dry-run phase, where you attempt to build your package. Any change to src/ will be reverted after you call `gjp finish`;
|
26
26
|
* `gjp mvn` locates and runs Maven from any directory in kit/, using options to force repository in kit/m2 and settings in kit/m2/settings.xml;
|
27
|
+
* `gjp scaffold-kit-spec` creates or refreshes a spec file for the kit package;
|
27
28
|
* `gjp set-up-nonet-user` sets up a user named `nonet` without Internet access using `iptables`, needs superuser privileges. You can then use it for networkless dry-runs;
|
28
29
|
* `gjp tear-down-nonet-user` removes a user previously created by gjp;
|
29
30
|
* `gjp scaffold-jar-table DIRECTORY` looks for jars in the project's DIRECTORY and classifies them as build-time dependencies (b), run-time dependencies (r) or products (p);
|
data/lib/gjp/archiver.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Gjp
|
4
|
+
# generates file archives that accompany spec files
|
5
|
+
class Archiver
|
6
|
+
include Logger
|
7
|
+
|
8
|
+
def initialize(project)
|
9
|
+
@project = project
|
10
|
+
end
|
11
|
+
|
12
|
+
# generates an archive for the project's kit package based on
|
13
|
+
# its file list
|
14
|
+
def archive_kit
|
15
|
+
list_file = File.join(@project.full_path, "file_lists/kit")
|
16
|
+
if not File.exist? list_file
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
destination_file = File.join(@project.full_path, "archives/#{@project.name}-kit.tar.xz")
|
20
|
+
|
21
|
+
@project.from_directory "kit" do
|
22
|
+
archive list_file, destination_file
|
23
|
+
end
|
24
|
+
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
# generates an archive for a project's source package based on
|
29
|
+
# its file list
|
30
|
+
def archive_src(name)
|
31
|
+
list_file = File.join(@project.full_path, "file_lists/#{name}_input")
|
32
|
+
if not File.exist? list_file
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
destination_file = File.join(@project.full_path, "archives/#{@project.name}-#{name}.tar.xz")
|
36
|
+
|
37
|
+
@project.from_directory File.join("src", name) do
|
38
|
+
archive list_file, destination_file
|
39
|
+
end
|
40
|
+
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
# compresses files specified in the list file to the destination file
|
45
|
+
def archive(list_file, destination_file)
|
46
|
+
`tar --files-from=#{list_file} -cJf #{destination_file}`
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/gjp/cli.rb
CHANGED
@@ -82,8 +82,12 @@ module Gjp
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def execute
|
85
|
-
|
86
|
-
|
85
|
+
begin
|
86
|
+
project = Gjp::Project.new(".")
|
87
|
+
Gjp::MavenRunner.new(project).mvn(@maven_options)
|
88
|
+
rescue Gjp::MavenNotFoundException
|
89
|
+
puts "mvn executable not found in kit/ or any of its subdirectories, gather it"
|
90
|
+
end
|
87
91
|
end
|
88
92
|
end
|
89
93
|
|
@@ -105,6 +109,41 @@ module Gjp
|
|
105
109
|
end
|
106
110
|
end
|
107
111
|
|
112
|
+
subcommand "scaffold-kit-spec", "Scaffolds or refreshes a spec file for the kit package" do
|
113
|
+
def execute
|
114
|
+
project = Gjp::Project.new(".")
|
115
|
+
success = Gjp::Scaffolder.new(project).scaffold_kit_spec
|
116
|
+
if not success
|
117
|
+
puts "You must be gathering before scaffolding."
|
118
|
+
puts "Use \"gjp gather\" to start a new gathering."
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
subcommand "generate-kit-archive", "Archives contents of the kit package in a tarball" do
|
124
|
+
def execute
|
125
|
+
project = Gjp::Project.new(".")
|
126
|
+
success = Gjp::Archiver.new(project).archive_kit
|
127
|
+
if not success
|
128
|
+
"The file_list/kit file was not found. Ensure you already added content to kit/ " +
|
129
|
+
"during a gathering and/or dry-running phase, and ensure you ended that phase " +
|
130
|
+
"with \"gjp finish\"."
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
subcommand "generate-src-archive", "Archives contents of one src package in a tarball" do
|
136
|
+
parameter "NAME", "name of a package in src/"
|
137
|
+
def execute
|
138
|
+
project = Gjp::Project.new(".")
|
139
|
+
success = Gjp::Archiver.new(project).archive_src name
|
140
|
+
if not success
|
141
|
+
"The file_list/#{name}_input file was not found. Ensure you already added content to " +
|
142
|
+
"src/#{name} during a gathering phase, and ensure you ended that phase with \"gjp finish\"."
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
108
147
|
subcommand "set-up-nonet-user", "Sets up a \"nonet\" user that cannot access the network" do
|
109
148
|
def execute
|
110
149
|
user = Gjp::LimitedNetworkUser.new("nonet")
|
data/lib/gjp/maven_runner.rb
CHANGED
@@ -23,6 +23,7 @@ module Gjp
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
log.debug("Maven executable not found")
|
26
27
|
nil
|
27
28
|
end
|
28
29
|
|
@@ -31,11 +32,13 @@ module Gjp
|
|
31
32
|
prefix = path_from running_full_path, kit_full_path
|
32
33
|
maven_executable = find_maven_executable
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
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")
|
37
39
|
|
38
|
-
|
40
|
+
"#{mvn_path} -Dmaven.repo.local=`readlink -e #{repo_path}` -s`readlink -e #{config_path}`"
|
41
|
+
end
|
39
42
|
end
|
40
43
|
|
41
44
|
# returns a path from origin to destination, provided they are both absolute
|
@@ -47,7 +50,14 @@ module Gjp
|
|
47
50
|
def mvn(options)
|
48
51
|
kit_full_path = File.join(@project.full_path, "kit")
|
49
52
|
running_full_path = File.expand_path(".")
|
50
|
-
|
53
|
+
maven_commandline = get_maven_commandline(kit_full_path, running_full_path)
|
54
|
+
if maven_commandline == nil
|
55
|
+
raise MavenNotFoundException
|
56
|
+
end
|
57
|
+
Process.wait(Process.spawn("#{maven_commandline} #{options.join(' ')}"))
|
51
58
|
end
|
52
59
|
end
|
60
|
+
|
61
|
+
class MavenNotFoundException < Exception
|
62
|
+
end
|
53
63
|
end
|
data/lib/gjp/project.rb
CHANGED
@@ -42,9 +42,12 @@ module Gjp
|
|
42
42
|
`git init`
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
template_manager = Gjp::TemplateManager.new
|
46
|
+
template_manager.copy "archives", "."
|
47
|
+
template_manager.copy "file_lists", "."
|
48
|
+
template_manager.copy "kit", "."
|
49
|
+
template_manager.copy "specs", "."
|
50
|
+
template_manager.copy "src", "."
|
48
51
|
|
49
52
|
`git add .`
|
50
53
|
`git commit -m "Project initialized"`
|
@@ -54,11 +57,6 @@ module Gjp
|
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
57
|
-
# copies a file/dir from the template directory to the destination directory
|
58
|
-
def self.copy_from_template(template_file, destination_dir)
|
59
|
-
FileUtils.cp_r(File.join(File.dirname(__FILE__), "..", "template", template_file), destination_dir)
|
60
|
-
end
|
61
|
-
|
62
60
|
# starts a gathering phase, all files added to the project
|
63
61
|
# will be added to packages (including kit)
|
64
62
|
def gather
|
@@ -71,7 +69,7 @@ module Gjp
|
|
71
69
|
end
|
72
70
|
|
73
71
|
set_status :gathering
|
74
|
-
take_snapshot "Gathering started", :
|
72
|
+
take_snapshot "Gathering started", :gathering_started
|
75
73
|
end
|
76
74
|
|
77
75
|
true
|
@@ -90,7 +88,7 @@ module Gjp
|
|
90
88
|
end
|
91
89
|
|
92
90
|
set_status :dry_running
|
93
|
-
take_snapshot "Dry-run started", :
|
91
|
+
take_snapshot "Dry-run started", :dry_run_started
|
94
92
|
end
|
95
93
|
|
96
94
|
true
|
@@ -104,41 +102,45 @@ module Gjp
|
|
104
102
|
if status == :gathering
|
105
103
|
take_snapshot "Changes during gathering"
|
106
104
|
|
107
|
-
update_changed_file_list
|
108
|
-
update_changed_src_file_list
|
105
|
+
update_changed_file_list "kit", "kit", :gathering_started
|
106
|
+
update_changed_src_file_list :input, :gathering_started
|
109
107
|
take_snapshot "File list updates"
|
110
108
|
|
111
109
|
set_status nil
|
112
|
-
take_snapshot "Gathering finished", :
|
110
|
+
take_snapshot "Gathering finished", :gathering_finished
|
113
111
|
|
114
112
|
:gathering
|
115
113
|
elsif status == :dry_running
|
116
114
|
take_snapshot "Changes during dry-run"
|
117
115
|
|
118
|
-
update_changed_file_list
|
119
|
-
update_changed_src_file_list
|
116
|
+
update_changed_file_list "kit", "kit", :dry_run_started
|
117
|
+
update_changed_src_file_list :output, :dry_run_started
|
120
118
|
take_snapshot "File list updates"
|
121
119
|
|
122
|
-
revert
|
120
|
+
revert "src", :dry_run_started
|
123
121
|
take_snapshot "Sources reverted as before dry-run"
|
124
122
|
|
125
123
|
set_status nil
|
126
|
-
take_snapshot "Dry run finished", :
|
124
|
+
take_snapshot "Dry run finished", :dry_run_finished
|
127
125
|
|
128
126
|
:dry_running
|
129
127
|
end
|
130
128
|
end
|
131
129
|
end
|
132
130
|
|
133
|
-
|
131
|
+
# updates one of the files that tracks changes in src/ directories form a certain tag
|
132
|
+
# list_name is the name of the list of files to update, there will be one for each
|
133
|
+
# package in src/
|
134
|
+
def update_changed_src_file_list(list_name, tag)
|
134
135
|
Dir.foreach("src") do |entry|
|
135
136
|
if File.directory?(File.join(Dir.getwd, "src", entry)) and entry =~ /([^:\/]+:[^:]+:[^:]+)$/
|
136
|
-
update_changed_file_list(File.join("src", entry), "#{$1}_#{list_name.to_s}")
|
137
|
+
update_changed_file_list(File.join("src", entry), "#{$1}_#{list_name.to_s}", tag)
|
137
138
|
end
|
138
139
|
end
|
139
140
|
end
|
140
141
|
|
141
|
-
|
142
|
+
# updates file_name with the file names changed in directory since tag
|
143
|
+
def update_changed_file_list(directory, file_name, tag)
|
142
144
|
list_file = File.join("file_lists", file_name)
|
143
145
|
tracked_files = if File.exists?(list_file)
|
144
146
|
File.readlines(list_file)
|
@@ -147,7 +149,7 @@ module Gjp
|
|
147
149
|
end
|
148
150
|
|
149
151
|
new_tracked_files = (
|
150
|
-
`git diff-tree --no-commit-id --name-only -r HEAD`.split("\n")
|
152
|
+
`git diff-tree --no-commit-id --name-only -r #{latest_tag(tag)} HEAD`.split("\n")
|
151
153
|
.select { |file| file.start_with?(directory) }
|
152
154
|
.map { |file|file[directory.length + 1, file.length] }
|
153
155
|
.concat(tracked_files)
|
@@ -157,7 +159,6 @@ module Gjp
|
|
157
159
|
|
158
160
|
log.debug("writing file list for #{directory}: #{new_tracked_files.to_s}")
|
159
161
|
|
160
|
-
|
161
162
|
File.open(list_file, "w+") do |file_list|
|
162
163
|
new_tracked_files.each do |file|
|
163
164
|
file_list.puts file
|
@@ -167,34 +168,34 @@ module Gjp
|
|
167
168
|
|
168
169
|
# adds the project's whole contents to git
|
169
170
|
# if tag is given, commit is tagged
|
170
|
-
def take_snapshot(message,
|
171
|
+
def take_snapshot(message, tag = nil)
|
171
172
|
log.debug "committing with message: #{message}"
|
172
173
|
|
173
174
|
`git rm -r --cached .`
|
174
175
|
`git add .`
|
175
176
|
`git commit -m "#{message}"`
|
176
177
|
|
177
|
-
if
|
178
|
-
latest_count = if
|
178
|
+
if tag != nil
|
179
|
+
latest_count = if latest_tag(tag) =~ /^gjp_.*_([0-9]+)$/
|
179
180
|
$1
|
180
181
|
else
|
181
182
|
0
|
182
183
|
end
|
183
|
-
`git tag
|
184
|
+
`git tag gjp_#{tag}_#{latest_count.to_i + 1}`
|
184
185
|
end
|
185
186
|
end
|
186
187
|
|
187
|
-
# returns the last
|
188
|
-
def
|
189
|
-
`git describe --abbrev=0 --tags --match=
|
188
|
+
# returns the last tag given in a gjp snapshot
|
189
|
+
def latest_tag(tag)
|
190
|
+
`git describe --abbrev=0 --tags --match=gjp_#{tag}_*`.strip
|
190
191
|
end
|
191
192
|
|
192
|
-
# reverts
|
193
|
-
def revert(
|
194
|
-
`git rm -rf --ignore-unmatch #{
|
195
|
-
`git checkout -f #{
|
193
|
+
# reverts path contents as per latest tag
|
194
|
+
def revert(path, tag)
|
195
|
+
`git rm -rf --ignore-unmatch #{path}`
|
196
|
+
`git checkout -f #{latest_tag(tag)} -- #{path}`
|
196
197
|
|
197
|
-
`git clean -f -d #{
|
198
|
+
`git clean -f -d #{path}`
|
198
199
|
end
|
199
200
|
|
200
201
|
# returns a symbol with the current status
|
@@ -233,11 +234,25 @@ module Gjp
|
|
233
234
|
".#{status.to_s}"
|
234
235
|
end
|
235
236
|
|
236
|
-
# runs a block from the project directory
|
237
|
-
def from_directory
|
238
|
-
Dir.chdir(@full_path) do
|
237
|
+
# runs a block from the project directory or a subdirectory
|
238
|
+
def from_directory(subdirectory = "")
|
239
|
+
Dir.chdir(File.join(@full_path, subdirectory)) do
|
239
240
|
yield
|
240
241
|
end
|
241
242
|
end
|
243
|
+
|
244
|
+
# helpers for ERB
|
245
|
+
|
246
|
+
def name
|
247
|
+
File.basename(@full_path)
|
248
|
+
end
|
249
|
+
|
250
|
+
def version
|
251
|
+
`git rev-parse --short #{latest_tag(:dry_run_finished)}`.strip
|
252
|
+
end
|
253
|
+
|
254
|
+
def get_binding
|
255
|
+
binding
|
256
|
+
end
|
242
257
|
end
|
243
258
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Gjp
|
4
|
+
# creates and updates spec files
|
5
|
+
class Scaffolder
|
6
|
+
include Logger
|
7
|
+
|
8
|
+
def initialize(project)
|
9
|
+
@project = project
|
10
|
+
end
|
11
|
+
|
12
|
+
def scaffold_kit_spec
|
13
|
+
if @project.get_status != :gathering
|
14
|
+
return false
|
15
|
+
end
|
16
|
+
|
17
|
+
@project.from_directory do
|
18
|
+
spec_path = File.join("specs", "#{@project.name}-kit.spec")
|
19
|
+
|
20
|
+
TemplateManager.new.generate "kit.spec", @project.get_binding, "#{spec_path}.new_scaffold"
|
21
|
+
|
22
|
+
already_scaffolded = @project.latest_tag(:scaffold_kit_spec) != ""
|
23
|
+
already_existing = File.exist? spec_path
|
24
|
+
|
25
|
+
if already_scaffolded and already_existing
|
26
|
+
# 3-way merge
|
27
|
+
`git show #{@project.latest_tag(:scaffold_kit_spec)}:#{spec_path} > #{spec_path}.old_scaffold`
|
28
|
+
`git merge-file --ours #{spec_path} #{spec_path}.old_scaffold #{spec_path}.new_scaffold`
|
29
|
+
File.delete "#{spec_path}.new_scaffold"
|
30
|
+
File.delete "#{spec_path}.old_scaffold"
|
31
|
+
else
|
32
|
+
# just replace
|
33
|
+
File.rename "#{spec_path}.new_scaffold", spec_path
|
34
|
+
end
|
35
|
+
|
36
|
+
@project.take_snapshot "Kit spec scaffolded", :scaffold_kit_spec
|
37
|
+
|
38
|
+
true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "erb"
|
4
|
+
|
5
|
+
module Gjp
|
6
|
+
# operates on files in template/
|
7
|
+
class TemplateManager
|
8
|
+
include Logger
|
9
|
+
|
10
|
+
attr_reader :template_path
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@template_path = File.join(File.dirname(__FILE__), "..", "template")
|
14
|
+
end
|
15
|
+
|
16
|
+
def copy(template_name, destination_dir)
|
17
|
+
FileUtils.cp_r(File.join(template_path, template_name), destination_dir)
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate(template_name, object_binding, destination_path)
|
21
|
+
erb = ERB.new File.read(File.join(template_path, template_name))
|
22
|
+
File.open(destination_path, "w") { |io| io.write erb.result(object_binding) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/gjp/version.rb
CHANGED
data/lib/gjp.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "gjp/version"
|
2
2
|
require "gjp/logger"
|
3
|
+
require "gjp/template_manager"
|
3
4
|
require "gjp/project"
|
4
5
|
require "gjp/pom"
|
5
6
|
require "gjp/version_matcher"
|
@@ -11,5 +12,7 @@ require "gjp/source_address_getter"
|
|
11
12
|
require "gjp/source_getter"
|
12
13
|
require "gjp/parent_pom_getter"
|
13
14
|
require "gjp/maven_runner"
|
15
|
+
require "gjp/scaffolder"
|
16
|
+
require "gjp/archiver"
|
14
17
|
|
15
18
|
require "gjp/cli"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# spec file for gjp kit for project "<%= name %>"
|
3
|
+
#
|
4
|
+
# Copyright (c) <%= Time.now.year %> <%= Etc.getlogin %>
|
5
|
+
#
|
6
|
+
# All modifications and additions to the file contributed by third parties
|
7
|
+
# remain the property of their copyright owners, unless otherwise agreed
|
8
|
+
# upon. The license for this file, and modifications and additions to the
|
9
|
+
# file, is the same license as for the pristine package itself (unless the
|
10
|
+
# license for the pristine package is not an Open Source License, in which
|
11
|
+
# case the license is the MIT License). An "Open Source License" is a
|
12
|
+
# license that conforms to the Open Source Definition (Version 1.9)
|
13
|
+
# published by the Open Source Initiative.
|
14
|
+
|
15
|
+
# Please submit bugfixes or comments via http://bugs.opensuse.org/
|
16
|
+
#
|
17
|
+
|
18
|
+
Name: <%= name %>-kit
|
19
|
+
Version: <%= version %>
|
20
|
+
Release: 1
|
21
|
+
License: Apache-2.0
|
22
|
+
Summary: Build-time dependencies for %{name}
|
23
|
+
Url: https://github.com/SilvioMoioli/gjp
|
24
|
+
Group: Develompent/Libraries/Java
|
25
|
+
Source0: %{name}.tar.xz
|
26
|
+
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
27
|
+
Provides: gjp(kit)
|
28
|
+
# no two kits should ever be installed at any given time
|
29
|
+
Conflicts: otherproviders(gjp(kit))
|
30
|
+
|
31
|
+
%description
|
32
|
+
This package has been automatically created by gjp in order to
|
33
|
+
satisfy build time dependencies of some Java packages. It should
|
34
|
+
not be used except for rebuilding those packages and it should never
|
35
|
+
be installed on end users' systems.
|
36
|
+
|
37
|
+
%prep
|
38
|
+
%setup -q
|
39
|
+
|
40
|
+
%build
|
41
|
+
# nothing to do, gjp kits are precompiled by design
|
42
|
+
|
43
|
+
%install
|
44
|
+
install -d -m 0755 %{buildroot}%{_datadir}/gjp/%{name}/
|
45
|
+
cp -a * %{buildroot}%{_datadir}/gjp/%{name}/
|
46
|
+
|
47
|
+
%files
|
48
|
+
%defattr(-,root,root)
|
49
|
+
%{_datadir}/gjp/%{name}/
|
50
|
+
|
51
|
+
%changelog
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Gjp::Archiver do
|
6
|
+
before(:each) do
|
7
|
+
@project_path = File.join("spec", "data", "test-project")
|
8
|
+
Dir.mkdir(@project_path)
|
9
|
+
|
10
|
+
Gjp::Project.init(@project_path)
|
11
|
+
@project = Gjp::Project.new(@project_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:each) do
|
15
|
+
FileUtils.rm_rf(@project_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:archiver) { Gjp::Archiver.new(@project) }
|
19
|
+
|
20
|
+
describe "#archive" do
|
21
|
+
it "archives a list of files" do
|
22
|
+
@project.from_directory do
|
23
|
+
File.open("test", "w") { |io| io.puts "test content" }
|
24
|
+
File.open("test_list", "w") { |io| io.puts "test" }
|
25
|
+
|
26
|
+
archiver.archive "test_list", "test.tar.xz"
|
27
|
+
`tar -Jtf test.tar.xz`.split.should include("test")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#archive_kit" do
|
33
|
+
it "archives a kit package files" do
|
34
|
+
@project.from_directory do
|
35
|
+
File.open(File.join("kit","kit_test"), "w") { |io| io.puts "test content" }
|
36
|
+
end
|
37
|
+
@project.finish
|
38
|
+
|
39
|
+
archiver.archive_kit
|
40
|
+
@project.from_directory do
|
41
|
+
`tar -Jtf archives/test-project-kit.tar.xz`.split.should include("kit_test")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#archive_src" do
|
47
|
+
it "archives a source package files" do
|
48
|
+
@project.from_directory do
|
49
|
+
Dir.mkdir(File.join("src", "a:b:c"))
|
50
|
+
File.open(File.join("src", "a:b:c", "src_test"), "w") { |io| io.puts "test content" }
|
51
|
+
end
|
52
|
+
@project.finish
|
53
|
+
|
54
|
+
archiver.archive_src "a:b:c"
|
55
|
+
@project.from_directory do
|
56
|
+
`tar -Jtf archives/test-project-a:b:c.tar.xz`.split.should include("src_test")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -10,19 +10,6 @@ describe Gjp::MavenRunner do
|
|
10
10
|
|
11
11
|
Gjp::Project.init(@project_path)
|
12
12
|
@project = Gjp::Project.new(@project_path)
|
13
|
-
@project.gather
|
14
|
-
|
15
|
-
# mock a Maven executable
|
16
|
-
Dir.chdir(@project_path) do
|
17
|
-
@bin_dir = File.join("kit", "mvn", "bin")
|
18
|
-
FileUtils.mkdir_p(@bin_dir)
|
19
|
-
@maven_executable = File.join(@bin_dir, "mvn")
|
20
|
-
File.open(@maven_executable, "w") { |io| io.puts "echo $0 $*>test_out" }
|
21
|
-
File.chmod(0777, @maven_executable)
|
22
|
-
end
|
23
|
-
|
24
|
-
@project.finish
|
25
|
-
|
26
13
|
@maven_runner = Gjp::MavenRunner.new(@project)
|
27
14
|
end
|
28
15
|
|
@@ -31,26 +18,56 @@ describe Gjp::MavenRunner do
|
|
31
18
|
end
|
32
19
|
|
33
20
|
describe "#find_maven_executable" do
|
34
|
-
it "
|
21
|
+
it "finds a Maven executable in kit" do
|
22
|
+
mock_maven_executable
|
35
23
|
@maven_runner.find_maven_executable.should eq @maven_executable
|
36
24
|
end
|
25
|
+
it "doesn't find a Maven executable in kit" do
|
26
|
+
@maven_runner.find_maven_executable.should be_nil
|
27
|
+
end
|
37
28
|
end
|
38
29
|
|
39
30
|
describe "#get_maven_commandline" do
|
40
31
|
it "returns commandline options for running maven" do
|
32
|
+
mock_maven_executable
|
41
33
|
kit_full_path = File.join(@project.full_path, "kit")
|
42
34
|
commandline = @maven_runner.get_maven_commandline(kit_full_path, @project.full_path)
|
43
35
|
|
44
36
|
commandline.should eq "./#{@maven_executable} -Dmaven.repo.local=`readlink -e ./kit/m2` -s`readlink -e ./kit/m2/settings.xml`"
|
45
37
|
end
|
38
|
+
it "doesn't return commandline options if Maven is not available" do
|
39
|
+
kit_full_path = File.join(@project.full_path, "kit")
|
40
|
+
commandline = @maven_runner.get_maven_commandline(kit_full_path, @project.full_path)
|
41
|
+
|
42
|
+
commandline.should be_nil
|
43
|
+
end
|
46
44
|
end
|
47
45
|
|
48
46
|
describe "#mvn" do
|
49
47
|
it "runs maven" do
|
48
|
+
mock_maven_executable
|
50
49
|
@project.from_directory do
|
51
50
|
@maven_runner.mvn(["extra-option"])
|
52
51
|
File.read("test_out").strip.should match /extra-option$/
|
53
52
|
end
|
54
53
|
end
|
54
|
+
it "doesn't run Maven if it is not available" do
|
55
|
+
@project.from_directory do
|
56
|
+
expect { @maven_runner.mvn []}.to raise_error(Gjp::MavenNotFoundException)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def mock_maven_executable
|
62
|
+
@project.gather
|
63
|
+
Dir.chdir(@project_path) do
|
64
|
+
@bin_dir = File.join("kit", "mvn", "bin")
|
65
|
+
FileUtils.mkdir_p(@bin_dir)
|
66
|
+
@maven_executable = File.join(@bin_dir, "mvn")
|
67
|
+
File.open(@maven_executable, "w") { |io| io.puts "echo $0 $*>test_out" }
|
68
|
+
File.chmod(0777, @maven_executable)
|
69
|
+
end
|
70
|
+
|
71
|
+
@project.finish
|
55
72
|
end
|
56
73
|
end
|
data/spec/lib/project_spec.rb
CHANGED
@@ -50,7 +50,7 @@ describe Gjp::Project do
|
|
50
50
|
Dir.exists?(src_path).should be_true
|
51
51
|
|
52
52
|
@project.from_directory do
|
53
|
-
@project.
|
53
|
+
@project.latest_tag(:gathering_started).should eq "gjp_gathering_started_1"
|
54
54
|
`git rev-list --all`.split("\n").length.should eq 2
|
55
55
|
end
|
56
56
|
|
@@ -85,7 +85,7 @@ describe Gjp::Project do
|
|
85
85
|
@project.take_snapshot "test", :revertable
|
86
86
|
|
87
87
|
`git rev-list --all`.split("\n").length.should eq 3
|
88
|
-
@project.
|
88
|
+
@project.latest_tag(:revertable).should eq "gjp_revertable_1"
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Gjp::Scaffolder do
|
6
|
+
before(:each) do
|
7
|
+
@project_path = File.join("spec", "data", "test-project")
|
8
|
+
Dir.mkdir(@project_path)
|
9
|
+
|
10
|
+
Gjp::Project.init(@project_path)
|
11
|
+
@project = Gjp::Project.new(@project_path)
|
12
|
+
|
13
|
+
@project.dry_run
|
14
|
+
Dir.chdir(@project_path) do
|
15
|
+
test_file = File.join("kit", "test")
|
16
|
+
File.open(test_file, "w") { |io| io.puts "kit content test file" }
|
17
|
+
end
|
18
|
+
@project.gather
|
19
|
+
|
20
|
+
@scaffolder = Gjp::Scaffolder.new(@project)
|
21
|
+
end
|
22
|
+
|
23
|
+
after(:each) do
|
24
|
+
FileUtils.rm_rf(@project_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#scaffold_kit_spec" do
|
28
|
+
it "scaffolds the first version" do
|
29
|
+
@scaffolder.scaffold_kit_spec.should be_true
|
30
|
+
|
31
|
+
@project.from_directory do
|
32
|
+
spec_lines = File.readlines(File.join("specs", "test-project-kit.spec"))
|
33
|
+
spec_lines.should include("Name: test-project-kit\n")
|
34
|
+
spec_lines.should include("Version: #{`git rev-parse --short #{@project.latest_tag(:dry_run_finished)}`}")
|
35
|
+
spec_lines.should include("Source0: %{name}.tar.xz\n")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
it "scaffolds a second version" do
|
39
|
+
@scaffolder.scaffold_kit_spec.should be_true
|
40
|
+
@project.dry_run
|
41
|
+
Dir.chdir(@project_path) do
|
42
|
+
test_file = File.join("kit", "test")
|
43
|
+
File.open(test_file, "w") { |io| io.puts "changed kit content test file" }
|
44
|
+
|
45
|
+
File.open(File.join("specs", "test-project-kit.spec"), "a") do |io|
|
46
|
+
io.write("nonconflicting line")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
@project.gather
|
50
|
+
|
51
|
+
@scaffolder.scaffold_kit_spec.should be_true
|
52
|
+
|
53
|
+
@project.from_directory do
|
54
|
+
spec_lines = File.readlines(File.join("specs", "test-project-kit.spec"))
|
55
|
+
spec_lines.should include("Name: test-project-kit\n")
|
56
|
+
spec_lines.should include("Version: #{`git rev-parse --short #{@project.latest_tag(:dry_run_finished)}`}")
|
57
|
+
spec_lines.should include("Source0: %{name}.tar.xz\n")
|
58
|
+
spec_lines.should include("nonconflicting line\n")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
it "scaffolds a conflicting version" do
|
62
|
+
@scaffolder.scaffold_kit_spec.should be_true
|
63
|
+
@project.dry_run
|
64
|
+
Dir.chdir(@project_path) do
|
65
|
+
test_file = File.join("kit", "test")
|
66
|
+
File.open(test_file, "w") { |io| io.puts "changed kit content test file" }
|
67
|
+
|
68
|
+
spec_path = File.join("specs", "test-project-kit.spec")
|
69
|
+
spec_contents = File.read spec_path
|
70
|
+
|
71
|
+
spec_contents.gsub! /^Version:.*$/, "CONFLICTING!"
|
72
|
+
|
73
|
+
File.open(spec_path, "w+") do |io|
|
74
|
+
io.write(spec_contents)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
@project.gather
|
78
|
+
|
79
|
+
@scaffolder.scaffold_kit_spec.should be_true
|
80
|
+
|
81
|
+
@project.from_directory do
|
82
|
+
spec_lines = File.readlines(File.join("specs", "test-project-kit.spec"))
|
83
|
+
spec_lines.should include("Name: test-project-kit\n")
|
84
|
+
spec_lines.should include("Source0: %{name}.tar.xz\n")
|
85
|
+
spec_lines.should include("CONFLICTING!\n")
|
86
|
+
spec_lines.should_not include("Version: #{`git rev-parse --short #{@project.latest_tag(:dry_run_finished)}`}")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
it "returns error if the phase is incorrect" do
|
90
|
+
@project.dry_run
|
91
|
+
@scaffolder.scaffold_kit_spec.should be_false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Gjp::TemplateManager do
|
6
|
+
let(:template_manager) { Gjp::TemplateManager.new }
|
7
|
+
|
8
|
+
describe "#template_path" do
|
9
|
+
it "returns the pathname where all templates are stored" do
|
10
|
+
relative_path = template_manager.template_path
|
11
|
+
|
12
|
+
File.expand_path(relative_path).should eq File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "template"))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#copy" do
|
17
|
+
it "copies a file from template to another dir" do
|
18
|
+
destination = Tempfile.new("TemplateManager spec")
|
19
|
+
destination_path = destination.path
|
20
|
+
destination.unlink
|
21
|
+
|
22
|
+
template_manager.copy(File.join("src", "CONTENTS"), destination_path)
|
23
|
+
|
24
|
+
File.exist?(destination_path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#generate" do
|
29
|
+
it "compiles a file from a template and a value objects file" do
|
30
|
+
template_path = File.join(template_manager.template_path, "test.erb")
|
31
|
+
File.open(template_path, "w") { |io| io.puts "Hello <%= world_property %>" }
|
32
|
+
|
33
|
+
destination = Tempfile.new("TemplateManager spec")
|
34
|
+
destination_path = destination.path
|
35
|
+
destination.unlink
|
36
|
+
|
37
|
+
class WorldClass
|
38
|
+
def world_property
|
39
|
+
"World!"
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_binding
|
43
|
+
binding
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
template_manager.generate("test.erb", WorldClass.new.get_binding, destination_path)
|
48
|
+
File.unlink(template_path)
|
49
|
+
|
50
|
+
File.read(destination_path).should eq "Hello World!\n"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
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.
|
4
|
+
version: 0.13.1
|
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-08-
|
12
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- bin/gjp
|
157
157
|
- gjp.gemspec
|
158
158
|
- lib/gjp.rb
|
159
|
+
- lib/gjp/archiver.rb
|
159
160
|
- lib/gjp/cli.rb
|
160
161
|
- lib/gjp/jar_table.rb
|
161
162
|
- lib/gjp/limited_network_user.rb
|
@@ -166,13 +167,18 @@ files:
|
|
166
167
|
- lib/gjp/pom.rb
|
167
168
|
- lib/gjp/pom_getter.rb
|
168
169
|
- lib/gjp/project.rb
|
170
|
+
- lib/gjp/scaffolder.rb
|
169
171
|
- lib/gjp/source_address_getter.rb
|
170
172
|
- lib/gjp/source_getter.rb
|
173
|
+
- lib/gjp/template_manager.rb
|
171
174
|
- lib/gjp/version.rb
|
172
175
|
- lib/gjp/version_matcher.rb
|
176
|
+
- lib/template/archives/CONTENTS
|
173
177
|
- lib/template/file_lists/CONTENTS
|
178
|
+
- lib/template/kit.spec
|
174
179
|
- lib/template/kit/CONTENTS
|
175
180
|
- lib/template/kit/m2/settings.xml
|
181
|
+
- lib/template/specs/CONTENTS
|
176
182
|
- lib/template/src/CONTENTS
|
177
183
|
- spec/data/ant-super-simple-code/build.xml
|
178
184
|
- spec/data/ant-super-simple-code/build/HW.class
|
@@ -190,6 +196,7 @@ files:
|
|
190
196
|
- spec/data/nailgun/pom.xml
|
191
197
|
- spec/data/struts-apps/pom.xml
|
192
198
|
- spec/data/tomcat/pom.xml
|
199
|
+
- spec/lib/archiver_spec.rb
|
193
200
|
- spec/lib/jar_table_spec.rb
|
194
201
|
- spec/lib/limited_network_user_spec_interactive.rb
|
195
202
|
- spec/lib/maven_runner_spec.rb
|
@@ -198,8 +205,10 @@ files:
|
|
198
205
|
- spec/lib/pom_getter_spec.rb
|
199
206
|
- spec/lib/pom_spec.rb
|
200
207
|
- spec/lib/project_spec.rb
|
208
|
+
- spec/lib/scaffolder_spec.rb
|
201
209
|
- spec/lib/source_address_getter_spec.rb
|
202
210
|
- spec/lib/source_getter_spec.rb
|
211
|
+
- spec/lib/template_manager_spec.rb
|
203
212
|
- spec/lib/version_matcher_spec.rb
|
204
213
|
- spec/spec_helper.rb
|
205
214
|
homepage: https://github.com/SilvioMoioli/gjp
|
@@ -243,6 +252,7 @@ test_files:
|
|
243
252
|
- spec/data/nailgun/pom.xml
|
244
253
|
- spec/data/struts-apps/pom.xml
|
245
254
|
- spec/data/tomcat/pom.xml
|
255
|
+
- spec/lib/archiver_spec.rb
|
246
256
|
- spec/lib/jar_table_spec.rb
|
247
257
|
- spec/lib/limited_network_user_spec_interactive.rb
|
248
258
|
- spec/lib/maven_runner_spec.rb
|
@@ -251,7 +261,9 @@ test_files:
|
|
251
261
|
- spec/lib/pom_getter_spec.rb
|
252
262
|
- spec/lib/pom_spec.rb
|
253
263
|
- spec/lib/project_spec.rb
|
264
|
+
- spec/lib/scaffolder_spec.rb
|
254
265
|
- spec/lib/source_address_getter_spec.rb
|
255
266
|
- spec/lib/source_getter_spec.rb
|
267
|
+
- spec/lib/template_manager_spec.rb
|
256
268
|
- spec/lib/version_matcher_spec.rb
|
257
269
|
- spec/spec_helper.rb
|