tetra 0.40.0 → 0.41.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +48 -0
- data/MOTIVATION.md +9 -3
- data/README.md +5 -5
- data/SPECIAL_CASES.md +1 -3
- data/integration-tests/{commons.sh → build-commons.sh} +26 -6
- data/integration-tests/build-obs.sh +21 -0
- data/lib/template/kit_item.spec +53 -0
- data/lib/template/package.spec +4 -2
- data/lib/tetra.rb +5 -3
- data/lib/tetra/archiver.rb +23 -87
- data/lib/tetra/commands/generate_all.rb +13 -16
- data/lib/tetra/commands/generate_kit_archive.rb +4 -4
- data/lib/tetra/commands/generate_kit_spec.rb +4 -2
- data/lib/tetra/commands/generate_package_archive.rb +1 -1
- data/lib/tetra/commands/generate_package_spec.rb +2 -2
- data/lib/tetra/git.rb +19 -10
- data/lib/tetra/glue_kit_item.rb +42 -0
- data/lib/tetra/jar_kit_item.rb +45 -0
- data/lib/tetra/kit.rb +73 -0
- data/lib/tetra/maven_kit_item.rb +64 -0
- data/lib/tetra/package.rb +82 -0
- data/lib/tetra/project.rb +26 -22
- data/lib/tetra/spec_generator.rb +38 -42
- data/lib/tetra/version.rb +1 -1
- data/spec/lib/archiver_spec.rb +30 -86
- data/spec/lib/git_spec.rb +8 -8
- data/spec/lib/glue_kit_item_spec.rb +31 -0
- data/spec/lib/kit_spec.rb +67 -0
- data/spec/lib/maven_kit_item_spec.rb +74 -0
- data/spec/lib/package_spec.rb +78 -0
- data/spec/lib/project_spec.rb +1 -1
- data/spec/lib/spec_generator_spec.rb +59 -87
- metadata +15 -8
- data/lib/template/kit.spec +0 -64
- data/lib/tetra/kit_spec_adapter.rb +0 -28
- data/lib/tetra/package_spec_adapter.rb +0 -59
- data/lib/tetra/template_manager.rb +0 -33
- data/spec/lib/template_manager_spec.rb +0 -54
data/lib/tetra/spec_generator.rb
CHANGED
@@ -1,60 +1,56 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
module Tetra
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
4
|
+
# implements a to_spec method
|
5
|
+
module SpecGenerator
|
6
|
+
# expected attributes:
|
7
|
+
# project (Tetra::Project)
|
8
|
+
# package_name (string)
|
9
|
+
# spec_dir (string)
|
10
|
+
# template_spec_name (string)
|
11
|
+
|
12
|
+
# saves a specfile for this object in correct directories
|
13
|
+
# returns the spec path and the conflict count with the previously generated
|
14
|
+
# version, if any
|
15
|
+
def to_spec
|
16
|
+
project.from_directory do
|
17
|
+
spec_name = "#{package_name}.spec"
|
18
|
+
spec_path = File.join(spec_dir, spec_name)
|
19
|
+
|
20
|
+
new_content = generate(template_spec_name, binding)
|
21
|
+
conflict_count = project.merge_new_content(new_content, spec_path,
|
22
|
+
"Spec generated", "generate_#{package_name}_spec")
|
23
|
+
|
24
|
+
output_dir = File.join("output", package_name)
|
17
25
|
FileUtils.mkdir_p(output_dir)
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
symlink_to_output(spec_path, output_dir)
|
27
|
+
spec_link_path = File.join(output_dir, spec_name)
|
28
|
+
FileUtils.symlink(File.expand_path(spec_path), spec_link_path, force: true)
|
23
29
|
|
24
30
|
[spec_path, conflict_count]
|
25
31
|
end
|
26
32
|
end
|
27
33
|
|
28
|
-
|
29
|
-
|
30
|
-
|
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)
|
35
|
-
|
36
|
-
adapter = Tetra::PackageSpecAdapter.new(@project, name, pom, filter)
|
37
|
-
conflict_count = generate_merging("package.spec", adapter.public_binding, spec_path, "generate_#{name}_spec")
|
38
|
-
|
39
|
-
symlink_to_output(spec_path, output_dir)
|
40
|
-
|
41
|
-
[spec_path, conflict_count]
|
42
|
-
end
|
34
|
+
# returns the spec template path, exposed for testing
|
35
|
+
def template_path
|
36
|
+
File.join(File.dirname(__FILE__), "..", "template")
|
43
37
|
end
|
44
38
|
|
45
39
|
private
|
46
40
|
|
47
|
-
# generates
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
41
|
+
# generates content from an ERB template and an object binding
|
42
|
+
# if destination_path is given, write it to that file, otherwise just
|
43
|
+
# return it
|
44
|
+
def generate(template_name, object_binding, destination_path = nil)
|
45
|
+
template_path = File.join(File.dirname(__FILE__), "..", "template")
|
46
|
+
erb = ERB.new File.read(File.join(template_path, template_name)), nil, "<>"
|
47
|
+
new_content = erb.result(object_binding)
|
48
|
+
|
49
|
+
unless destination_path.nil?
|
50
|
+
File.open(destination_path, "w") { |io| io.write new_content }
|
51
|
+
end
|
52
52
|
|
53
|
-
|
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)
|
53
|
+
new_content
|
58
54
|
end
|
59
55
|
end
|
60
56
|
end
|
data/lib/tetra/version.rb
CHANGED
data/spec/lib/archiver_spec.rb
CHANGED
@@ -3,103 +3,47 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
describe Tetra::Archiver do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Tetra::
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@
|
23
|
-
|
24
|
-
|
25
|
-
archiver.archive_single(".", "test.tar.xz")
|
26
|
-
expect(`tar -Jtf test.tar.xz`.split).to include("test")
|
27
|
-
end
|
6
|
+
include Tetra::Mockers
|
7
|
+
|
8
|
+
# mock
|
9
|
+
class TestArchiverClass
|
10
|
+
include Tetra::Archiver
|
11
|
+
|
12
|
+
attr_reader :project
|
13
|
+
attr_reader :package_name
|
14
|
+
attr_reader :source_dir
|
15
|
+
attr_reader :source_paths
|
16
|
+
attr_reader :destination_dir
|
17
|
+
|
18
|
+
def initialize(project)
|
19
|
+
@project = project
|
20
|
+
@package_name = "test-package"
|
21
|
+
@source_dir = "kit"
|
22
|
+
@source_paths = ["*"]
|
23
|
+
@destination_dir = "test-package"
|
28
24
|
end
|
29
25
|
end
|
30
26
|
|
31
|
-
|
32
|
-
|
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
|
-
expect(`tar -Jtf test.tar.xz`.split).to 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
|
-
expect(files).to include("test")
|
50
|
-
expect(files).to include("test3")
|
51
|
-
expect(files).not_to include("test2")
|
52
|
-
end
|
53
|
-
end
|
27
|
+
before(:each) do
|
28
|
+
create_mock_project
|
54
29
|
end
|
55
30
|
|
56
|
-
|
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(true)
|
64
|
-
@project.from_directory do
|
65
|
-
expect(`tar -Jtf output/test-project-kit/test-project-kit.tar.xz`.split).to include("kit_test")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
it "archives a kit package files incrementally" do
|
69
|
-
@project.from_directory do
|
70
|
-
File.open(File.join("kit", "kit_test"), "w") { |io| io.puts "test content" }
|
71
|
-
end
|
72
|
-
@project.finish(false)
|
73
|
-
|
74
|
-
archiver.archive_kit(false)
|
75
|
-
@project.from_directory do
|
76
|
-
expect(`tar -Jtf output/test-project-kit/test-project-kit.tar.xz`.split).to include("kit_test")
|
77
|
-
end
|
31
|
+
let(:instance) { TestArchiverClass.new(@project) }
|
78
32
|
|
79
|
-
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
archiver.archive_kit(false)
|
84
|
-
@project.from_directory do
|
85
|
-
files = `tar -Jtf output/test-project-kit/test-project-kit_0001.tar.xz`.split
|
86
|
-
expect(files).to include("kit_test2")
|
87
|
-
expect(files).not_to include("kit_test")
|
88
|
-
end
|
89
|
-
end
|
33
|
+
after(:each) do
|
34
|
+
delete_mock_project
|
90
35
|
end
|
91
36
|
|
92
|
-
describe "#
|
93
|
-
it "
|
94
|
-
@project.from_directory do
|
95
|
-
|
96
|
-
File.open(File.join("src", "package-name", "src_test"), "w") { |io| io.puts "test content" }
|
37
|
+
describe "#to_archive" do
|
38
|
+
it "generates an archive" do
|
39
|
+
@project.from_directory("kit") do
|
40
|
+
FileUtils.touch("kit_test")
|
97
41
|
end
|
98
|
-
@project.finish(false)
|
99
42
|
|
100
|
-
|
43
|
+
instance.to_archive
|
44
|
+
|
101
45
|
@project.from_directory do
|
102
|
-
expect(`tar -Jtf output/package-
|
46
|
+
expect(`tar -Jtf output/test-package/test-package.tar.xz`.split).to include("kit_test")
|
103
47
|
end
|
104
48
|
end
|
105
49
|
end
|
data/spec/lib/git_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe Tetra::Git do
|
|
35
35
|
file.write "file1o"
|
36
36
|
end
|
37
37
|
|
38
|
-
@git.commit_whole_directory("test",
|
38
|
+
@git.commit_whole_directory("test", :test)
|
39
39
|
|
40
40
|
files = `git ls-tree --name-only -r HEAD`.split("\n")
|
41
41
|
|
@@ -52,15 +52,15 @@ describe Tetra::Git do
|
|
52
52
|
file.write "test"
|
53
53
|
end
|
54
54
|
|
55
|
-
@git.commit_whole_directory("test",
|
55
|
+
@git.commit_whole_directory("test", :test_start)
|
56
56
|
|
57
57
|
File.open("file2", "w") do |file|
|
58
58
|
file.write "test"
|
59
59
|
end
|
60
60
|
|
61
|
-
@git.commit_whole_directory("test end")
|
61
|
+
@git.commit_whole_directory("test end", :test_end)
|
62
62
|
|
63
|
-
files = @git.changed_files_since(
|
63
|
+
files = @git.changed_files_since(:test_start)
|
64
64
|
|
65
65
|
expect(files).not_to include("file1")
|
66
66
|
expect(files).to include("file2")
|
@@ -75,7 +75,7 @@ describe Tetra::Git do
|
|
75
75
|
file.write "test"
|
76
76
|
end
|
77
77
|
|
78
|
-
@git.commit_whole_directory("test",
|
78
|
+
@git.commit_whole_directory("test", :test_start)
|
79
79
|
|
80
80
|
File.open("file2", "w") do |file|
|
81
81
|
file.write "test"
|
@@ -85,15 +85,15 @@ describe Tetra::Git do
|
|
85
85
|
file.write "test"
|
86
86
|
end
|
87
87
|
|
88
|
-
@git.commit_whole_directory("test",
|
88
|
+
@git.commit_whole_directory("test", :test_end)
|
89
89
|
|
90
90
|
File.open("file4", "w") do |file|
|
91
91
|
file.write "test"
|
92
92
|
end
|
93
93
|
|
94
|
-
@git.commit_whole_directory("test")
|
94
|
+
@git.commit_whole_directory("test", :test_after)
|
95
95
|
|
96
|
-
files = @git.changed_files_between(
|
96
|
+
files = @git.changed_files_between(:test_start, :test_end, "subdir")
|
97
97
|
|
98
98
|
expect(files).not_to include("file1")
|
99
99
|
expect(files).not_to include("file2")
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Tetra::GlueKitItem do
|
6
|
+
include Tetra::Mockers
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
create_mock_project
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:each) do
|
13
|
+
delete_mock_project
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:instance) { Tetra::GlueKitItem.new(@project, []) }
|
17
|
+
|
18
|
+
describe "#to_spec" do
|
19
|
+
it "generates a specfile" do
|
20
|
+
expect(instance.to_spec).to be_truthy
|
21
|
+
|
22
|
+
@project.from_directory do
|
23
|
+
package_name = instance.package_name
|
24
|
+
spec_lines = File.readlines(File.join("output", package_name, "#{package_name}.spec"))
|
25
|
+
|
26
|
+
expect(spec_lines).to include("Conflicts: otherproviders(tetra-glue)\n")
|
27
|
+
expect(spec_lines).to include("Provides: tetra-glue == test-project-0\n")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Tetra::Kit do
|
6
|
+
include Tetra::Mockers
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
create_mock_project
|
10
|
+
|
11
|
+
@project.dry_run
|
12
|
+
@project.finish(false)
|
13
|
+
|
14
|
+
@kit = Tetra::Kit.new(@project)
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:each) do
|
18
|
+
delete_mock_project
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#maven_kit_items" do
|
22
|
+
it "finds binary packages" do
|
23
|
+
@project.from_directory(File.join("kit", "m2")) do
|
24
|
+
maven_kit_item_path = File.join(".", "com", "company",
|
25
|
+
"project", "artifact", "1.0")
|
26
|
+
FileUtils.mkdir_p(maven_kit_item_path)
|
27
|
+
|
28
|
+
expected_source_paths = [
|
29
|
+
File.join(maven_kit_item_path, "artifact-1.0.jar"),
|
30
|
+
File.join(maven_kit_item_path, "artifact-1.0.pom"),
|
31
|
+
File.join(maven_kit_item_path, "artifact-1.0.sha1")
|
32
|
+
]
|
33
|
+
|
34
|
+
expected_source_paths.each do |file|
|
35
|
+
FileUtils.touch(file)
|
36
|
+
end
|
37
|
+
|
38
|
+
actual_maven_kit_item = @kit.maven_kit_items.first
|
39
|
+
expect(actual_maven_kit_item.source_paths.sort).to eql(expected_source_paths)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#jar_kit_items" do
|
45
|
+
it "finds binary packages" do
|
46
|
+
@project.from_directory(File.join("kit", "jars")) do
|
47
|
+
FileUtils.touch("test1.jar")
|
48
|
+
end
|
49
|
+
|
50
|
+
actual_jar_kit_item = @kit.jar_kit_items.first
|
51
|
+
expect(actual_jar_kit_item.source_paths).to eql([Pathname.new("test1.jar")])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#glue_kit_items" do
|
56
|
+
it "finds binary packages" do
|
57
|
+
@project.from_directory(File.join("kit")) do
|
58
|
+
FileUtils.touch(File.join("jars", "test1.jar"))
|
59
|
+
FileUtils.touch("test2.jar")
|
60
|
+
end
|
61
|
+
|
62
|
+
actual_glue_kit_items = @kit.glue_kit_items(@kit.jar_kit_items).first
|
63
|
+
expect(actual_glue_kit_items.source_paths).not_to include(Pathname.new("test1.jar"))
|
64
|
+
expect(actual_glue_kit_items.source_paths).to include(Pathname.new("test2.jar"))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Tetra::MavenKitItem do
|
6
|
+
include Tetra::Mockers
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
create_mock_project
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:each) do
|
13
|
+
delete_mock_project
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:group_id) { "com.company.project" }
|
17
|
+
let(:artifact_id) { "artifact" }
|
18
|
+
let(:version) { "1.0" }
|
19
|
+
let(:dir) { File.join(group_id.gsub(".", File::SEPARATOR), artifact_id, version) }
|
20
|
+
let(:pom) { File.join(dir, "#{artifact_id}-#{version}.pom") }
|
21
|
+
let(:jar) { File.join(dir, "#{artifact_id}.jar") }
|
22
|
+
let(:package_name) { "kit-item-#{group_id.gsub(".", "-")}-#{artifact_id}-#{version}" }
|
23
|
+
let(:maven_kit_item) { Tetra::MavenKitItem.new(@project, pom, [pom, jar]) }
|
24
|
+
|
25
|
+
describe "#provides_symbol" do
|
26
|
+
it "returns the sepec Provides: symbol" do
|
27
|
+
expect(maven_kit_item.provides_symbol).to eq("tetra-mvn(com.company.project:artifact)")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#provides_version" do
|
32
|
+
it "returns the spec Provides: version" do
|
33
|
+
expect(maven_kit_item.provides_version).to eq("1.0")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#to_spec" do
|
38
|
+
it "generates a specfile" do
|
39
|
+
expect(maven_kit_item.to_spec).to be_truthy
|
40
|
+
|
41
|
+
@project.from_directory do
|
42
|
+
spec_lines = File.readlines(File.join("output", package_name, "#{package_name}.spec"))
|
43
|
+
|
44
|
+
expect(spec_lines).to include("# spec file for a build-time dependency of project \"test-project\"\n")
|
45
|
+
expect(spec_lines).to include("Name: kit-item-com-company-project-artifact-1.0\n")
|
46
|
+
expect(spec_lines).to include("Summary: Build-time dependency of project \"test-project\"\n")
|
47
|
+
expect(spec_lines).to include("Provides: tetra-mvn(#{group_id}:#{artifact_id}) == #{version}\n")
|
48
|
+
|
49
|
+
expect(spec_lines).to include("install -d -m 0755 %{buildroot}%{_datadir}/tetra/m2\n")
|
50
|
+
expect(spec_lines).to include("cp -a * %{buildroot}%{_datadir}/tetra/m2\n")
|
51
|
+
expect(spec_lines).to include("%{_datadir}/tetra/m2\n")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#to_archive" do
|
57
|
+
it "generates an archive" do
|
58
|
+
@project.from_directory(File.join("kit", "m2")) do
|
59
|
+
FileUtils.mkdir_p(dir)
|
60
|
+
FileUtils.touch(pom)
|
61
|
+
FileUtils.touch(jar)
|
62
|
+
end
|
63
|
+
|
64
|
+
expected_filename = File::SEPARATOR + "kit-item-com-company-project-artifact-1.0.tar.xz"
|
65
|
+
expect(maven_kit_item.to_archive).to end_with(expected_filename)
|
66
|
+
|
67
|
+
@project.from_directory do
|
68
|
+
contents = `tar -Jtf output/#{package_name}/#{package_name}.tar.xz`.split
|
69
|
+
expect(contents).to include("com/company/project/artifact/1.0/artifact-1.0.pom")
|
70
|
+
expect(contents).to include("com/company/project/artifact/1.0/artifact.jar")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|