tetra 0.43.0 → 0.44.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/.rubocop.yml +1 -1
  2. data/README.md +2 -2
  3. data/SPECIAL_CASES.md +8 -8
  4. data/integration-tests/build-commons.sh +5 -6
  5. data/lib/template/gitignore +1 -1
  6. data/lib/template/{output → packages}/CONTENTS +0 -0
  7. data/lib/template/packages/kit/CONTENTS +3 -0
  8. data/lib/tetra.rb +14 -14
  9. data/lib/tetra/commands/generate_all.rb +7 -11
  10. data/lib/tetra/commands/{generate_package_archive.rb → generate_archive.rb} +3 -3
  11. data/lib/tetra/commands/{generate_kit_spec.rb → generate_kit.rb} +5 -2
  12. data/lib/tetra/commands/generate_script.rb +18 -0
  13. data/lib/tetra/commands/{generate_package_spec.rb → generate_spec.rb} +3 -3
  14. data/lib/tetra/git.rb +0 -8
  15. data/lib/tetra/main.rb +9 -15
  16. data/lib/tetra/packages/archivable.rb +26 -0
  17. data/lib/tetra/{package.rb → packages/built_package.rb} +11 -25
  18. data/lib/tetra/{glue_kit_item.rb → packages/glue_kit_item.rb} +14 -15
  19. data/lib/tetra/{jar_kit_item.rb → packages/jar_kit_item.rb} +13 -15
  20. data/lib/tetra/{kit.rb → packages/kit.rb} +0 -0
  21. data/lib/tetra/{maven_kit_item.rb → packages/maven_kit_item.rb} +13 -13
  22. data/lib/tetra/packages/scriptable.rb +48 -0
  23. data/lib/tetra/{spec_generator.rb → packages/speccable.rb} +12 -22
  24. data/lib/tetra/project.rb +19 -10
  25. data/lib/tetra/version.rb +1 -1
  26. data/spec/lib/archivable_spec.rb +36 -0
  27. data/spec/lib/{package_spec.rb → built_package_spec.rb} +4 -4
  28. data/spec/lib/git_spec.rb +0 -6
  29. data/spec/lib/glue_kit_item_spec.rb +1 -1
  30. data/spec/lib/maven_kit_item_spec.rb +2 -2
  31. data/spec/lib/project_spec.rb +8 -0
  32. data/spec/lib/{script_generator_spec.rb → scriptable_spec.rb} +8 -11
  33. data/spec/lib/{spec_generator_spec.rb → speccable.rb} +11 -20
  34. metadata +20 -20
  35. data/lib/tetra/archiver.rb +0 -31
  36. data/lib/tetra/commands/generate_kit_archive.rb +0 -18
  37. data/lib/tetra/commands/generate_package_script.rb +0 -18
  38. data/lib/tetra/script_generator.rb +0 -58
  39. data/spec/lib/archiver_spec.rb +0 -50
@@ -4,21 +4,14 @@ module Tetra
4
4
  # represents a prebuilt package dependency from a jar file
5
5
  # in a kit
6
6
  class JarKitItem
7
- # implement to_spec
8
- include SpecGenerator
7
+ include Archivable
8
+ include Speccable
9
+
9
10
  attr_reader :project
10
11
  attr_reader :package_name
11
- attr_reader :spec_dir
12
- attr_reader :template_spec_name
13
12
  attr_reader :conflicts
14
-
15
- # implement to_archive
16
- include Archiver
17
13
  attr_reader :source_dir
18
14
  attr_reader :source_paths
19
- attr_reader :destination_dir
20
-
21
- # template-specific attributes
22
15
  attr_reader :provides_symbol
23
16
  attr_reader :provides_version
24
17
  attr_reader :install_dir
@@ -29,17 +22,22 @@ module Tetra
29
22
 
30
23
  @project = project
31
24
  @package_name = "kit-item-#{name.to_s.gsub(".", "-")}"
32
- @spec_dir = "kit"
33
- @template_spec_name = "kit_item.spec"
34
25
  @conflicts = false
35
-
36
26
  @source_dir = File.join("kit", "jars")
37
27
  @source_paths = [path]
38
- @destination_dir = @package_name
39
-
40
28
  @provides_symbol = "tetra-jar(#{name})"
41
29
  @provides_version = hash
42
30
  @install_dir = "jars"
43
31
  end
32
+
33
+ def to_archive
34
+ _to_archive(@project, @package_name, @source_dir,
35
+ @source_paths, @project.kit_packages_dir)
36
+ end
37
+
38
+ def to_spec
39
+ _to_spec(@project, @package_name, "kit_item.spec",
40
+ @project.kit_packages_dir)
41
+ end
44
42
  end
45
43
  end
File without changes
@@ -4,21 +4,14 @@ module Tetra
4
4
  # represents a prebuilt package dependency from a Maven local repo
5
5
  # in a kit
6
6
  class MavenKitItem
7
- # implement to_spec
8
- include SpecGenerator
7
+ include Archivable
8
+ include Speccable
9
+
9
10
  attr_reader :project
10
11
  attr_reader :package_name
11
- attr_reader :spec_dir
12
- attr_reader :template_spec_name
13
12
  attr_reader :conflicts
14
-
15
- # implement to_archive
16
- include Archiver
17
13
  attr_reader :source_dir
18
14
  attr_reader :source_paths
19
- attr_reader :destination_dir
20
-
21
- # template-specific attributes
22
15
  attr_reader :provides_symbol
23
16
  attr_reader :provides_version
24
17
  attr_reader :install_dir
@@ -31,8 +24,6 @@ module Tetra
31
24
 
32
25
  @project = project
33
26
  @package_name = "kit-item-#{group_id.gsub(".", "-")}-#{artifact_id}-#{version}"
34
- @spec_dir = "kit"
35
- @template_spec_name = "kit_item.spec"
36
27
  @conflicts = false
37
28
 
38
29
  @provides_symbol = "tetra-mvn(#{group_id}:#{artifact_id})"
@@ -41,7 +32,16 @@ module Tetra
41
32
 
42
33
  @source_dir = File.join("kit", "m2")
43
34
  @source_paths = source_paths
44
- @destination_dir = @package_name
35
+ end
36
+
37
+ def to_archive
38
+ _to_archive(@project, @package_name, @source_dir,
39
+ @source_paths, @project.kit_packages_dir)
40
+ end
41
+
42
+ def to_spec
43
+ _to_spec(@project, @package_name, "kit_item.spec",
44
+ @project.kit_packages_dir)
45
45
  end
46
46
 
47
47
  private
@@ -0,0 +1,48 @@
1
+ # encoding: UTF-8
2
+
3
+ module Tetra
4
+ # generates a package build script from bash_history
5
+ module Scriptable
6
+ def _to_script(project, history_path)
7
+ ant_runner = Tetra::AntRunner.new(project)
8
+ maven_runner = Tetra::MavenRunner.new(project)
9
+
10
+ project.from_directory do
11
+ history_lines = File.readlines(history_path).map { |e| e.strip }
12
+ relevant_lines =
13
+ history_lines
14
+ .reverse
15
+ .take_while { |e| e.match(/tetra +dry-run/).nil? }
16
+ .reverse
17
+ .take_while { |e| e.match(/tetra +finish/).nil? }
18
+ .select { |e| e.match(/^#/).nil? }
19
+
20
+ script_lines = [
21
+ "#!/bin/bash",
22
+ "set -xe",
23
+ "PROJECT_PREFIX=`readlink -e .`",
24
+ "cd #{project.latest_dry_run_directory}"
25
+ ] +
26
+ relevant_lines.map do |line|
27
+ if line =~ /tetra +mvn/
28
+ line.gsub(/tetra +mvn/, "#{maven_runner.get_maven_commandline("$PROJECT_PREFIX", ["-o"])}")
29
+ elsif line =~ /tetra +ant/
30
+ line.gsub(/tetra +ant/, "#{ant_runner.get_ant_commandline("$PROJECT_PREFIX")}")
31
+ else
32
+ line
33
+ end
34
+ end
35
+
36
+ new_content = script_lines.join("\n") + "\n"
37
+
38
+ result_dir = File.join(project.packages_dir, project.name)
39
+ FileUtils.mkdir_p(result_dir)
40
+ result_path = File.join(result_dir, "build.sh")
41
+ conflict_count = project.merge_new_content(new_content, result_path, "Build script generated",
42
+ "generate_build_script")
43
+
44
+ [result_path, conflict_count]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,40 +1,31 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Tetra
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
-
4
+ # adds methods to generate a spec file from a package object
5
+ module Speccable
12
6
  # saves a specfile for this object in correct directories
13
7
  # returns the spec path and the conflict count with the previously generated
14
8
  # version, if any
15
- def to_spec
9
+ # destination_dir/name/name.spec
10
+ def _to_spec(project, name, template_spec_name, destination_dir)
16
11
  project.from_directory do
17
- spec_name = "#{package_name}.spec"
12
+ spec_name = "#{name}.spec"
13
+ spec_dir = File.join(destination_dir, name)
14
+ FileUtils.mkdir_p(spec_dir)
15
+
18
16
  spec_path = File.join(spec_dir, spec_name)
19
17
 
20
18
  new_content = generate(template_spec_name, binding)
21
- label = "Spec for #{package_name} generated"
19
+ label = "Spec for #{name} generated"
22
20
  conflict_count = project.merge_new_content(new_content, spec_path,
23
- label, "generate_#{package_name}_spec")
24
-
25
- output_dir = File.join("output", package_name)
26
- FileUtils.mkdir_p(output_dir)
27
-
28
- spec_link_path = File.join(output_dir, spec_name)
29
- FileUtils.symlink(File.expand_path(spec_path), spec_link_path, force: true)
30
-
31
- [spec_link_path, conflict_count]
21
+ label, "generate_#{name}_spec")
22
+ [spec_path, conflict_count]
32
23
  end
33
24
  end
34
25
 
35
26
  # returns the spec template path, exposed for testing
36
27
  def template_path
37
- File.join(File.dirname(__FILE__), "..", "template")
28
+ File.join(File.dirname(__FILE__), "..", "..", "template")
38
29
  end
39
30
 
40
31
  private
@@ -43,7 +34,6 @@ module Tetra
43
34
  # if destination_path is given, write it to that file, otherwise just
44
35
  # return it
45
36
  def generate(template_name, object_binding, destination_path = nil)
46
- template_path = File.join(File.dirname(__FILE__), "..", "template")
47
37
  erb = ERB.new File.read(File.join(template_path, template_name)), nil, "<>"
48
38
  new_content = erb.result(object_binding)
49
39
 
data/lib/tetra/project.rb CHANGED
@@ -21,6 +21,14 @@ module Tetra
21
21
  latest_tag_count(:dry_run_finished)
22
22
  end
23
23
 
24
+ def packages_dir
25
+ "packages"
26
+ end
27
+
28
+ def kit_packages_dir
29
+ File.join(packages_dir, "kit")
30
+ end
31
+
24
32
  # finds the project directory up in the tree, like git does
25
33
  def self.find_project_dir(starting_dir)
26
34
  result = starting_dir
@@ -54,8 +62,8 @@ module Tetra
54
62
  template_path = File.join(File.dirname(__FILE__), "..", "template")
55
63
 
56
64
  templates = {
57
- "output" => ".",
58
65
  "kit" => ".",
66
+ "packages" => ".",
59
67
  "src" => ".",
60
68
  "gitignore" => ".gitignore"
61
69
  }
@@ -107,6 +115,16 @@ module Tetra
107
115
 
108
116
  # takes a revertable snapshot of this project
109
117
  def take_snapshot(message, tag_prefix, tag_message = nil)
118
+ # rename all .gitignore files by default as
119
+ # they prevent snapshotting
120
+ from_directory("src") do
121
+ Find.find(".") do |file|
122
+ next unless file =~ /\.gitignore$/
123
+
124
+ FileUtils.mv(file, "#{file}_disabled_by_tetra")
125
+ end
126
+ end
127
+
110
128
  @git.commit_whole_directory(message, next_tag(tag_prefix), tag_message)
111
129
  end
112
130
 
@@ -219,13 +237,4 @@ module Tetra
219
237
  @directory = directory
220
238
  end
221
239
  end
222
-
223
- # current directory is not a tetra package directory
224
- class NoPackageDirectoryError < StandardError
225
- attr_reader :directory
226
-
227
- def initialize(directory)
228
- @directory = directory
229
- end
230
- end
231
240
  end
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.43.0"
5
+ VERSION = "0.44.0"
6
6
  end
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Tetra::Archivable do
6
+ include Tetra::Mockers
7
+
8
+ # mock
9
+ class TestArchivableClass
10
+ include Tetra::Archivable
11
+ end
12
+
13
+ before(:each) do
14
+ create_mock_project
15
+ end
16
+
17
+ let(:instance) { TestArchivableClass.new }
18
+
19
+ after(:each) do
20
+ delete_mock_project
21
+ end
22
+
23
+ describe "#to_archive" do
24
+ it "generates an archive" do
25
+ @project.from_directory("kit") do
26
+ FileUtils.touch("kit_test")
27
+ end
28
+
29
+ instance._to_archive(@project, "test-package", "kit", ["*"], @project.packages_dir)
30
+
31
+ @project.from_directory do
32
+ expect(`tar -Jtf packages/test-package/test-package.tar.xz`.split).to include("kit_test")
33
+ end
34
+ end
35
+ end
36
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Tetra::Package do
5
+ describe Tetra::BuiltPackage do
6
6
  include Tetra::Mockers
7
7
 
8
8
  before(:each) do
@@ -33,7 +33,7 @@ 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
+ @package = Tetra::BuiltPackage.new(@project, File.join(@project_path, "pom.xml"), "*.jar")
37
37
  end
38
38
 
39
39
  after(:each) do
@@ -45,7 +45,7 @@ describe Tetra::Package do
45
45
  @package.to_spec
46
46
 
47
47
  @project.from_directory do
48
- spec_lines = File.readlines(File.join("output", "test-project", "test-project.spec"))
48
+ spec_lines = File.readlines(File.join("packages", "test-project", "test-project.spec"))
49
49
  expect(spec_lines).to include("Name: test-project\n")
50
50
  expect(spec_lines).to include("License: The Apache Software License, Version 2.0\n")
51
51
  expect(spec_lines).to include("Summary: Nailgun is a client, protocol, and server for running Java\n")
@@ -68,7 +68,7 @@ da39a3ee5e6b4b0d3255bfef95601890afd80709\n")
68
68
 
69
69
  @package.to_archive
70
70
  @project.from_directory do
71
- expect(`tar -Jtf output/test-project/test-project.tar.xz`.split).to include("src_test")
71
+ expect(`tar -Jtf packages/test-project/test-project.tar.xz`.split).to include("src_test")
72
72
  end
73
73
  end
74
74
  end
data/spec/lib/git_spec.rb CHANGED
@@ -30,17 +30,11 @@ describe Tetra::Git do
30
30
  file.write "test"
31
31
  end
32
32
 
33
- # check that gitignore files are moved correctly
34
- File.open(".gitignore", "w") do |file|
35
- file.write "file1o"
36
- end
37
-
38
33
  @git.commit_whole_directory("test", :test)
39
34
 
40
35
  files = `git ls-tree --name-only -r HEAD`.split("\n")
41
36
 
42
37
  expect(files).to include("file1")
43
- expect(files).to include(".gitignore_disabled_by_tetra")
44
38
  end
45
39
  end
46
40
  end
@@ -21,7 +21,7 @@ describe Tetra::GlueKitItem do
21
21
 
22
22
  @project.from_directory do
23
23
  package_name = instance.package_name
24
- spec_lines = File.readlines(File.join("output", package_name, "#{package_name}.spec"))
24
+ spec_lines = File.readlines(File.join("packages", "kit", package_name, "#{package_name}.spec"))
25
25
 
26
26
  expect(spec_lines).to include("Conflicts: otherproviders(tetra-glue)\n")
27
27
  expect(spec_lines).to include("Provides: tetra-glue == test-project-0\n")
@@ -39,7 +39,7 @@ describe Tetra::MavenKitItem do
39
39
  expect(maven_kit_item.to_spec).to be_truthy
40
40
 
41
41
  @project.from_directory do
42
- spec_lines = File.readlines(File.join("output", package_name, "#{package_name}.spec"))
42
+ spec_lines = File.readlines(File.join("packages", "kit", package_name, "#{package_name}.spec"))
43
43
 
44
44
  expect(spec_lines).to include("# spec file for a build-time dependency of project \"test-project\"\n")
45
45
  expect(spec_lines).to include("Name: kit-item-com-company-project-artifact-1.0\n")
@@ -65,7 +65,7 @@ describe Tetra::MavenKitItem do
65
65
  expect(maven_kit_item.to_archive).to end_with(expected_filename)
66
66
 
67
67
  @project.from_directory do
68
- contents = `tar -Jtf output/#{package_name}/#{package_name}.tar.xz`.split
68
+ contents = `tar -Jtf packages/kit/#{package_name}/#{package_name}.tar.xz`.split
69
69
  expect(contents).to include("com/company/project/artifact/1.0/artifact-1.0.pom")
70
70
  expect(contents).to include("com/company/project/artifact/1.0/artifact.jar")
71
71
  end
@@ -68,8 +68,16 @@ describe Tetra::Project do
68
68
  @project.from_directory do
69
69
  FileUtils.touch(File.join("kit", "test"))
70
70
 
71
+ # check that gitignore files are moved correctly
72
+ File.open(File.join("src", ".gitignore"), "w") do |file|
73
+ file.write "file"
74
+ end
75
+
71
76
  @project.take_snapshot("test", :revertable)
72
77
 
78
+ files = `git ls-tree --name-only -r HEAD`.split("\n")
79
+ expect(files).to include("src/.gitignore_disabled_by_tetra")
80
+
73
81
  expect(`git rev-list --all`.split("\n").length).to eq 2
74
82
  expect(@project.latest_tag(:revertable)).to eq "revertable_1"
75
83
  end
@@ -2,13 +2,11 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Tetra::ScriptGenerator do
6
- before(:each) do
7
- @project_path = File.join("spec", "data", "test-project")
8
- Dir.mkdir(@project_path)
5
+ describe Tetra::Scriptable do
6
+ include Tetra::Mockers
9
7
 
10
- Tetra::Project.init(@project_path)
11
- @project = Tetra::Project.new(@project_path)
8
+ before(:each) do
9
+ create_mock_project
12
10
 
13
11
  @project.from_directory do
14
12
  File.open("history", "w") do |io|
@@ -22,23 +20,22 @@ describe Tetra::ScriptGenerator do
22
20
 
23
21
  FileUtils.mkdir_p(File.join("src", "test-package"))
24
22
  @project.dry_run
25
-
26
- @generator = Tetra::ScriptGenerator.new(@project, "history")
27
23
  end
28
24
 
29
25
  mock_maven_executable
30
26
  end
31
27
 
32
28
  after(:each) do
33
- FileUtils.rm_rf(@project_path)
29
+ delete_mock_project
34
30
  end
35
31
 
36
32
  describe "#generate_build_script" do
37
33
  it "generates a build script from the history" do
38
34
  @project.from_directory do
39
- @generator.generate_build_script
35
+ @package = Tetra::BuiltPackage.new(@project)
36
+ @package.to_script("history")
40
37
 
41
- lines = File.readlines(File.join("src", "build.sh"))
38
+ lines = File.readlines(File.join("packages", "test-project", "build.sh"))
42
39
 
43
40
  expect(lines).to include("#!/bin/bash\n")
44
41
  expect(lines).to include("cd somewhere significant\n")