tetra 0.49.0 → 0.50.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.rubocop.yml +2 -2
  2. data/SPECIAL_CASES.md +20 -8
  3. data/integration-tests/build-commons.sh +5 -10
  4. data/lib/template/kit.spec +1 -1
  5. data/lib/template/package.spec +7 -1
  6. data/lib/tetra.rb +1 -2
  7. data/lib/tetra/facades/git.rb +39 -18
  8. data/lib/tetra/facades/process_runner.rb +13 -4
  9. data/lib/tetra/main.rb +6 -0
  10. data/lib/tetra/packages/kit_package.rb +0 -6
  11. data/lib/tetra/packages/package.rb +4 -6
  12. data/lib/tetra/pom.rb +2 -5
  13. data/lib/tetra/project.rb +85 -30
  14. data/lib/tetra/ui/ant_subcommand.rb +1 -1
  15. data/lib/tetra/ui/dry_run_subcommand.rb +36 -22
  16. data/lib/tetra/ui/generate_all_subcommand.rb +1 -1
  17. data/lib/tetra/ui/generate_archive_subcommand.rb +2 -2
  18. data/lib/tetra/ui/generate_kit_subcommand.rb +2 -2
  19. data/lib/tetra/ui/generate_script_subcommand.rb +1 -1
  20. data/lib/tetra/ui/generate_spec_subcommand.rb +10 -3
  21. data/lib/tetra/ui/get_pom_subcommand.rb +18 -16
  22. data/lib/tetra/ui/move_jars_to_kit_subcommand.rb +1 -1
  23. data/lib/tetra/ui/mvn_subcommand.rb +1 -1
  24. data/lib/tetra/ui/patch_subcommand.rb +18 -0
  25. data/lib/tetra/ui/subcommand.rb +14 -5
  26. data/lib/tetra/version.rb +1 -1
  27. data/spec/lib/git_spec.rb +69 -30
  28. data/spec/lib/kit_package_spec.rb +0 -16
  29. data/spec/lib/{built_package_spec.rb → package_spec.rb} +2 -15
  30. data/spec/lib/project_spec.rb +56 -13
  31. data/spec/lib/{speccable.rb → speccable_spec.rb} +5 -5
  32. metadata +5 -9
  33. data/integration-tests/apache-maven-3.1.1-bin.zip +0 -0
  34. data/integration-tests/build-obs.sh +0 -19
  35. data/lib/tetra/facades/tar.rb +0 -20
  36. data/lib/tetra/packages/archivable.rb +0 -18
  37. data/spec/lib/archivable_spec.rb +0 -36
@@ -13,7 +13,7 @@ module Tetra
13
13
  def execute
14
14
  checking_exceptions do
15
15
  project = Tetra::Project.new(".")
16
- ensure_dry_running(true, project) do
16
+ ensure_dry_running(:is_in_progress, project) do
17
17
  path = Tetra::Kit.new(project).find_executable("ant")
18
18
  Tetra::Ant.new(project.full_path, path).ant(@options)
19
19
  end
@@ -14,30 +14,44 @@ module Tetra
14
14
  def execute
15
15
  checking_exceptions do
16
16
  project = Tetra::Project.new(".")
17
+ send(command, project)
18
+ end
19
+ end
17
20
 
18
- if command == "start"
19
- if project.dry_run
20
- puts "Now dry-running, please start your build."
21
- puts "To run a Maven installation from the kit, use \"tetra mvn\"."
22
- puts "If the build succeedes end this dry run with \"tetra dry-run finish\"."
23
- puts "If the build does not succeed use \"tetra dry-run abort\" to undo any change."
24
- else
25
- puts "Dry-run already in progress."
26
- puts "Use \"tetra dry-run finish\" to end it or \"tetra dry-run abort\" to undo changes."
27
- end
28
- elsif command == "finish"
29
- if project.finish
30
- puts "Dry-run finished."
31
- else
32
- puts "No dry-run is in progress."
33
- end
34
- elsif command == "abort"
35
- if project.abort
36
- puts "Project reverted as before dry-run."
37
- else
38
- puts "No dry-run is in progress."
39
- end
21
+ def start(project)
22
+ if !project.dry_running?
23
+ if project.src_patched?
24
+ puts "Some files in src/ were changed since last dry-run."
25
+ puts "Use \"tetra patch message\" to include changes in a patch before dry-running."
26
+ puts "Dry run not started."
27
+ else
28
+ project.dry_run
29
+ puts "Now dry-running, please start your build."
30
+ puts "To run a Maven installation from the kit, use \"tetra mvn\"."
31
+ puts "If the build succeedes end this dry run with \"tetra dry-run finish\"."
32
+ puts "If the build does not succeed use \"tetra dry-run abort\" to undo any change."
40
33
  end
34
+ else
35
+ puts "Dry-run already in progress."
36
+ puts "Use \"tetra dry-run finish\" to end it or \"tetra dry-run abort\" to undo changes."
37
+ end
38
+ end
39
+
40
+ def finish(project)
41
+ if project.dry_running?
42
+ project.finish
43
+ puts "Dry-run finished."
44
+ else
45
+ puts "No dry-run is in progress."
46
+ end
47
+ end
48
+
49
+ def abort(project)
50
+ if project.dry_running?
51
+ project.abort
52
+ puts "Project reverted as before dry-run."
53
+ else
54
+ puts "No dry-run is in progress."
41
55
  end
42
56
  end
43
57
  end
@@ -9,7 +9,7 @@ module Tetra
9
9
  def execute
10
10
  checking_exceptions do
11
11
  project = Tetra::Project.new(".")
12
- ensure_dry_running(false, project) do
12
+ ensure_dry_running(:has_finished, project) do
13
13
  GenerateKitSubcommand.new(@invocation_path).execute
14
14
 
15
15
  GenerateScriptSubcommand.new(@invocation_path).execute
@@ -6,8 +6,8 @@ module Tetra
6
6
  def execute
7
7
  checking_exceptions do
8
8
  project = Tetra::Project.new(".")
9
- ensure_dry_running(false, project) do
10
- result_path = Tetra::Package.new(project).to_archive
9
+ ensure_dry_running(:has_finished, project) do
10
+ result_path = project.archive_sources
11
11
  print_generation_result(project, result_path)
12
12
  end
13
13
  end
@@ -6,12 +6,12 @@ module Tetra
6
6
  def execute
7
7
  checking_exceptions do
8
8
  project = Tetra::Project.new(".")
9
- ensure_dry_running(false, project) do
9
+ ensure_dry_running(:has_finished, project) do
10
10
  kit = Tetra::KitPackage.new(project)
11
11
  result_path, conflict_count = kit.to_spec
12
12
  print_generation_result(project, result_path, conflict_count)
13
13
 
14
- result_path = kit.to_archive
14
+ result_path = project.archive_kit
15
15
  print_generation_result(project, result_path)
16
16
  end
17
17
  end
@@ -6,7 +6,7 @@ module Tetra
6
6
  def execute
7
7
  checking_exceptions do
8
8
  project = Tetra::Project.new(".")
9
- ensure_dry_running(false, project) do
9
+ ensure_dry_running(:has_finished, project) do
10
10
  history = File.join(Dir.home, ".bash_history")
11
11
  result_path, conflict_count =
12
12
  Tetra::Package.new(project).to_script(history)
@@ -9,10 +9,17 @@ module Tetra
9
9
  def execute
10
10
  checking_exceptions do
11
11
  project = Tetra::Project.new(".")
12
- ensure_dry_running(false, project) do
13
- result_path, conflict_count =
14
- Tetra::Package.new(project, pom, filter).to_spec
12
+ ensure_dry_running(:has_finished, project) do
13
+ patches = project.write_source_patches
14
+ package = Tetra::Package.new(project, pom, filter, patches)
15
+
16
+ patches.each do |patch|
17
+ print_generation_result(project, patch)
18
+ end
19
+
20
+ result_path, conflict_count = package.to_spec
15
21
  print_generation_result(project, result_path, conflict_count)
22
+ puts "Warning: #{pom} not found, some spec fields will be left blank" unless File.file?(pom)
16
23
  end
17
24
  end
18
25
  end
@@ -8,24 +8,26 @@ module Tetra
8
8
  def execute
9
9
  checking_exceptions do
10
10
  project = Tetra::Project.new(".")
11
- pom_getter = Tetra::PomGetter.new
11
+ ensure_dry_running(:is_not_in_progress, project) do
12
+ pom_getter = Tetra::PomGetter.new
12
13
 
13
- path, status = pom_getter.get_pom(name)
14
- if path
15
- text_status = (
16
- if status == :found_in_jar
17
- "was inside the jar"
18
- elsif status == :found_via_sha1
19
- "found by sha1 search from search.maven.org"
20
- elsif status == :found_via_heuristic
21
- "found by heuristic search from search.maven.org"
22
- end
23
- )
14
+ path, status = pom_getter.get_pom(name)
15
+ if path
16
+ text_status = (
17
+ if status == :found_in_jar
18
+ "was inside the jar"
19
+ elsif status == :found_via_sha1
20
+ "found by sha1 search from search.maven.org"
21
+ elsif status == :found_via_heuristic
22
+ "found by heuristic search from search.maven.org"
23
+ end
24
+ )
24
25
 
25
- puts "#{format_path(path, project)} written, #{text_status}"
26
- else
27
- puts "#{name}'s pom not found. Try:"
28
- puts "http://google.com/#q=#{URI.encode(pom_getter.cleanup_name(name) + ' pom')}"
26
+ puts "#{format_path(path, project)} written, #{text_status}"
27
+ else
28
+ puts "#{name}'s pom not found. Try:"
29
+ puts "http://google.com/#q=#{URI.encode(pom_getter.cleanup_name(name) + ' pom')}"
30
+ end
29
31
  end
30
32
  end
31
33
  end
@@ -7,7 +7,7 @@ module Tetra
7
7
  checking_exceptions do
8
8
  project = Tetra::Project.new(".")
9
9
 
10
- ensure_dry_running(false, project) do
10
+ ensure_dry_running(:is_not_in_progress, project) do
11
11
  project.purge_jars.each do |original, final|
12
12
  puts "Replaced #{original} with symlink pointing to to #{final}"
13
13
  end
@@ -13,7 +13,7 @@ module Tetra
13
13
  def execute
14
14
  checking_exceptions do
15
15
  project = Tetra::Project.new(".")
16
- ensure_dry_running(true, project) do
16
+ ensure_dry_running(:is_in_progress, project) do
17
17
  path = Tetra::Kit.new(project).find_executable("mvn")
18
18
  Tetra::Mvn.new(project.full_path, path).mvn(@options)
19
19
  end
@@ -0,0 +1,18 @@
1
+ # encoding: UTF-8
2
+
3
+ module Tetra
4
+ # tetra patch
5
+ class PatchSubcommand < Tetra::Subcommand
6
+ option %w(-n --new-tarball), :flag, "suppress patch creation, roll all changes so far in the tarball"
7
+ parameter "[MESSAGE]", "a short patch description", default: "Sources updated"
8
+
9
+ def execute
10
+ checking_exceptions do
11
+ project = Tetra::Project.new(".")
12
+ ensure_dry_running(:is_not_in_progress, project) do
13
+ project.commit_sources(message, new_tarball?)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -45,14 +45,23 @@ module Tetra
45
45
  @options = args
46
46
  end
47
47
 
48
- # prints an error message and exits unless there is a dry-run in progress
48
+ # prints an error message and exits unless a dry-running
49
+ # condition is met. Conditions can be: :is_in_progress, :is_not_in_progress
50
+ # or :has_finished
49
51
  def ensure_dry_running(state, project)
50
- if project.dry_running? == state
52
+ dry_running = project.dry_running?
53
+ has_finished = !project.version.nil?
54
+
55
+ if (state == :is_in_progress && dry_running) ||
56
+ (state == :is_not_in_progress && !dry_running) ||
57
+ (state == :has_finished && !dry_running && has_finished)
51
58
  yield
52
59
  else
53
- if state == true
60
+ if (state == :is_in_progress) ||
61
+ (state == :has_finished && !dry_running && !has_finished)
54
62
  puts "Please start a dry-run first, use \"tetra dry-run start\""
55
- else
63
+ elsif (state == :is_not_in_progress) ||
64
+ (state == :has_finished && dry_running)
56
65
  puts "Please finish or abort this dry-run first, use \"tetra dry-run finish\" or \"tetra dry-run abort\""
57
66
  end
58
67
  end
@@ -61,7 +70,7 @@ module Tetra
61
70
  # outputs output of a file generation
62
71
  def print_generation_result(project, result_path, conflict_count = 0)
63
72
  puts "#{format_path(result_path, project)} generated"
64
- puts "Warning: #{conflict_count} unresolved conflicts" if conflict_count > 0
73
+ puts "Warning: #{conflict_count} unresolved conflicts, please review and commit" if conflict_count > 0
65
74
  end
66
75
 
67
76
  # generates a version of path relative to the current directory
data/lib/tetra/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  # base module for tetra
4
4
  module Tetra
5
- VERSION = "0.49.0"
5
+ VERSION = "0.50.0"
6
6
  end
data/spec/lib/git_spec.rb CHANGED
@@ -41,53 +41,92 @@ describe Tetra::Git do
41
41
  describe "#commit_whole_directory" do
42
42
  it "commits all contents of a directory to git for later use" do
43
43
  Dir.chdir(@git_path) do
44
- File.open("file1", "w") do |file|
45
- file.write "test"
46
- end
44
+ FileUtils.touch("file1")
45
+ Dir.mkdir("subdir")
46
+ FileUtils.touch(File.join("subdir", "file2"))
47
47
 
48
- @git.commit_whole_directory("test")
48
+ @git.commit_whole_directory("subdir", "test")
49
49
 
50
50
  files = `git ls-tree --name-only -r HEAD`.split("\n")
51
51
 
52
- expect(files).to include("file1")
52
+ expect(files).not_to include("file1")
53
+ expect(files).to include("subdir/file2")
53
54
  end
54
55
  end
55
56
  end
56
57
 
57
- describe "#changed_files_between" do
58
- it "lists files changed between tetra tags" do
58
+ describe "#changed_files" do
59
+ it "checks if a directory is clean from changes" do
59
60
  Dir.chdir(@git_path) do
60
- File.open("file1", "w") do |file|
61
- file.write "test"
62
- end
61
+ @git.commit_file(".", "initial commit")
62
+ Dir.mkdir("directory")
63
+ FileUtils.touch(File.join("directory", "file"))
64
+ expect(@git.changed_files("directory", "HEAD")).to include("directory/file")
63
65
 
64
- @git.commit_whole_directory("test\ntetra: test_start")
66
+ `git add directory/file`
67
+ expect(@git.changed_files("directory", "HEAD")).to include("directory/file")
65
68
 
66
- File.open("file2", "w") do |file|
67
- file.write "test"
68
- end
69
- Dir.mkdir("subdir")
70
- File.open(File.join("subdir", "file3"), "w") do |file|
71
- file.write "test"
72
- end
69
+ @git.commit_file(File.join("directory", "file"), "test")
70
+ expect(@git.changed_files("directory", "HEAD")).to be_empty
71
+
72
+ expect(@git.changed_files("directory", "HEAD~")).to include("directory/file")
73
+ end
74
+ end
75
+ end
73
76
 
74
- @git.commit_whole_directory("test\ntetra: test_end")
77
+ describe "#archive" do
78
+ it "archives a version of a directory" do
79
+ Dir.chdir(@git_path) do
80
+ @git.commit_file(".", "initial commit")
75
81
 
76
- File.open("file4", "w") do |file|
77
- file.write "test"
78
- end
82
+ FileUtils.touch(File.join("outside_not_archived"))
83
+ Dir.mkdir("directory")
84
+ FileUtils.touch(File.join("directory", "file"))
85
+ @git.commit_file("directory", "test")
79
86
 
80
- @git.commit_whole_directory("test\ntetra: test_after")
87
+ FileUtils.touch(File.join("directory", "later_not_archived"))
81
88
 
82
- start_id = @git.latest_id("tetra: test_start")
83
- end_id = @git.latest_id("tetra: test_end")
89
+ @git.commit_file("directory", "later")
84
90
 
85
- files = @git.changed_files_between(start_id, end_id, "subdir")
91
+ destination_path = @git.archive("directory", @git.latest_id("test"), "archive.tar.xz")
92
+ expect(destination_path).to match(/archive.tar.xz$/)
86
93
 
87
- expect(files).not_to include("file1")
88
- expect(files).not_to include("file2")
89
- expect(files).to include("subdir/file3")
90
- expect(files).not_to include("file4")
94
+ file_list = `tar --list -f archive.tar.xz`.split
95
+ expect(file_list).not_to include("outside_not_archived")
96
+ expect(file_list).to include("directory/file")
97
+ expect(file_list).not_to include("directory/later_not_archived")
98
+ end
99
+ end
100
+ end
101
+
102
+ describe "#format_patch" do
103
+ it "creates patch files from commits" do
104
+ Dir.chdir(@git_path) do
105
+ outside_dir_file = File.join("outside_dir")
106
+ inside_dir_not_patched_file = File.join("directory", "inside_dir_not_patched")
107
+ inside_dir_patched_file = File.join("directory", "inside_dir_patched")
108
+
109
+ Dir.mkdir("directory")
110
+ FileUtils.touch(outside_dir_file)
111
+ FileUtils.touch(inside_dir_not_patched_file)
112
+ FileUtils.touch(inside_dir_patched_file)
113
+ @git.commit_file(".", "initial")
114
+
115
+ File.open(outside_dir_file, "w") { |f| f.write("A") }
116
+ File.open(inside_dir_patched_file, "w") { |f| f.write("A") }
117
+ @git.commit_file(".", "patch")
118
+
119
+ Dir.mkdir("patches")
120
+ patch_names = @git.format_patch("directory", "HEAD~", "patches")
121
+
122
+ expect(patch_names).to include("patches/0001-patch.patch")
123
+
124
+ patch_contents = File.readlines(File.join("patches", "0001-patch.patch"))
125
+ expect(patch_contents).to include("--- a/#{inside_dir_patched_file}\n")
126
+ expect(patch_contents).not_to include("--- a/#{outside_dir_file}\n")
127
+ expect(patch_contents).not_to include("--- a/#{inside_dir_not_patched_file}\n")
128
+ expect(patch_contents).to include("@@ -0,0 +1 @@\n")
129
+ expect(patch_contents).to include("+A\n")
91
130
  end
92
131
  end
93
132
  end
@@ -28,20 +28,4 @@ describe Tetra::KitPackage do
28
28
  end
29
29
  end
30
30
  end
31
-
32
- describe "#to_archive" do
33
- it "generates an archive" do
34
- @project.from_directory(File.join("kit", "m2")) do
35
- FileUtils.touch("kit.content")
36
- end
37
-
38
- expected_filename = File::SEPARATOR + "#{package_name}.tar.xz"
39
- expect(instance.to_archive).to end_with(expected_filename)
40
-
41
- @project.from_directory do
42
- contents = `tar --list -f packages/#{package_name}/#{package_name}.tar.xz`.split
43
- expect(contents).to include("./m2/kit.content")
44
- end
45
- end
46
- end
47
31
  end
@@ -33,7 +33,8 @@ describe Tetra::Package do
33
33
 
34
34
  FileUtils.copy(File.join("spec", "data", "nailgun", "pom.xml"), @project_path)
35
35
 
36
- @package = Tetra::Package.new(@project, File.join(@project_path, "pom.xml"), "*.jar")
36
+ patches = @project.write_source_patches
37
+ @package = Tetra::Package.new(@project, File.join(@project_path, "pom.xml"), "*.jar", patches)
37
38
  end
38
39
 
39
40
  after(:each) do
@@ -56,18 +57,4 @@ describe Tetra::Package do
56
57
  end
57
58
  end
58
59
  end
59
-
60
- describe "#to_archive" do
61
- it "generates an archive" do
62
- @project.from_directory("src") do
63
- FileUtils.touch("src_test")
64
- end
65
- @project.finish
66
-
67
- @package.to_archive
68
- @project.from_directory do
69
- expect(`tar -Jtf packages/test-project/test-project.tar.xz`.split).to include("./src_test")
70
- end
71
- end
72
- end
73
60
  end