tetra 0.40.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/.gitignore +27 -0
  2. data/.rubocop.yml +14 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +28 -0
  5. data/MOTIVATION.md +27 -0
  6. data/README.md +106 -0
  7. data/Rakefile +9 -0
  8. data/SPECIAL_CASES.md +130 -0
  9. data/bin/tetra +29 -0
  10. data/integration-tests/commons.sh +55 -0
  11. data/lib/template/gitignore +2 -0
  12. data/lib/template/kit.spec +64 -0
  13. data/lib/template/kit/CONTENTS +8 -0
  14. data/lib/template/kit/jars/CONTENTS +1 -0
  15. data/lib/template/kit/m2/settings.xml +10 -0
  16. data/lib/template/output/CONTENTS +3 -0
  17. data/lib/template/package.spec +65 -0
  18. data/lib/template/src/CONTENTS +6 -0
  19. data/lib/tetra.rb +63 -0
  20. data/lib/tetra/ant_runner.rb +27 -0
  21. data/lib/tetra/archiver.rb +95 -0
  22. data/lib/tetra/commands/ant.rb +23 -0
  23. data/lib/tetra/commands/base.rb +89 -0
  24. data/lib/tetra/commands/download_maven_source_jars.rb +29 -0
  25. data/lib/tetra/commands/dry_run.rb +17 -0
  26. data/lib/tetra/commands/finish.rb +22 -0
  27. data/lib/tetra/commands/generate_all.rb +38 -0
  28. data/lib/tetra/commands/generate_kit_archive.rb +18 -0
  29. data/lib/tetra/commands/generate_kit_spec.rb +16 -0
  30. data/lib/tetra/commands/generate_package_archive.rb +19 -0
  31. data/lib/tetra/commands/generate_package_script.rb +21 -0
  32. data/lib/tetra/commands/generate_package_spec.rb +22 -0
  33. data/lib/tetra/commands/get_pom.rb +33 -0
  34. data/lib/tetra/commands/get_source.rb +30 -0
  35. data/lib/tetra/commands/init.rb +15 -0
  36. data/lib/tetra/commands/list_kit_missing_sources.rb +21 -0
  37. data/lib/tetra/commands/move_jars_to_kit.rb +18 -0
  38. data/lib/tetra/commands/mvn.rb +23 -0
  39. data/lib/tetra/git.rb +140 -0
  40. data/lib/tetra/kit_checker.rb +104 -0
  41. data/lib/tetra/kit_runner.rb +43 -0
  42. data/lib/tetra/kit_spec_adapter.rb +28 -0
  43. data/lib/tetra/logger.rb +28 -0
  44. data/lib/tetra/main.rb +102 -0
  45. data/lib/tetra/maven_runner.rb +47 -0
  46. data/lib/tetra/maven_website.rb +59 -0
  47. data/lib/tetra/package_spec_adapter.rb +59 -0
  48. data/lib/tetra/pom.rb +55 -0
  49. data/lib/tetra/pom_getter.rb +104 -0
  50. data/lib/tetra/project.rb +245 -0
  51. data/lib/tetra/script_generator.rb +57 -0
  52. data/lib/tetra/source_getter.rb +41 -0
  53. data/lib/tetra/spec_generator.rb +60 -0
  54. data/lib/tetra/template_manager.rb +33 -0
  55. data/lib/tetra/version.rb +6 -0
  56. data/lib/tetra/version_matcher.rb +90 -0
  57. data/spec/data/ant-super-simple-code/build.xml +133 -0
  58. data/spec/data/ant-super-simple-code/build/HW.class +0 -0
  59. data/spec/data/ant-super-simple-code/build/mypackage/HW.class +0 -0
  60. data/spec/data/ant-super-simple-code/dist/antsimple-20130618.jar +0 -0
  61. data/spec/data/ant-super-simple-code/lib/junit-4.11.jar +0 -0
  62. data/spec/data/ant-super-simple-code/lib/log4j-1.2.13.jar +0 -0
  63. data/spec/data/ant-super-simple-code/src/mypackage/HW.java +15 -0
  64. data/spec/data/antlr/antlr-2.7.2.jar +0 -0
  65. data/spec/data/antlr/pom.xml +6 -0
  66. data/spec/data/commons-logging/commons-logging-1.1.1.jar +0 -0
  67. data/spec/data/commons-logging/parent_pom.xml +420 -0
  68. data/spec/data/commons-logging/pom.xml +504 -0
  69. data/spec/data/nailgun/nailgun-0.7.1.jar +0 -0
  70. data/spec/data/nailgun/pom.xml +153 -0
  71. data/spec/data/struts-apps/pom.xml +228 -0
  72. data/spec/data/tomcat/pom.xml +33 -0
  73. data/spec/lib/ant_runner_spec.rb +45 -0
  74. data/spec/lib/archiver_spec.rb +106 -0
  75. data/spec/lib/git_spec.rb +105 -0
  76. data/spec/lib/kit_checker_spec.rb +119 -0
  77. data/spec/lib/maven_runner_spec.rb +68 -0
  78. data/spec/lib/maven_website_spec.rb +56 -0
  79. data/spec/lib/pom_getter_spec.rb +36 -0
  80. data/spec/lib/pom_spec.rb +69 -0
  81. data/spec/lib/project_spec.rb +254 -0
  82. data/spec/lib/script_generator_spec.rb +67 -0
  83. data/spec/lib/source_getter_spec.rb +36 -0
  84. data/spec/lib/spec_generator_spec.rb +130 -0
  85. data/spec/lib/template_manager_spec.rb +54 -0
  86. data/spec/lib/version_matcher_spec.rb +64 -0
  87. data/spec/spec_helper.rb +37 -0
  88. data/spec/support/kit_runner_examples.rb +15 -0
  89. data/tetra.gemspec +31 -0
  90. data/utils/delete_nonet_user.sh +8 -0
  91. data/utils/setup_nonet_user.sh +8 -0
  92. metadata +267 -0
@@ -0,0 +1,106 @@
1
+ # encoding: UTF-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Tetra::Archiver do
6
+ before(:each) do
7
+ @project_path = File.join("spec", "data", "test-project")
8
+ Dir.mkdir(@project_path)
9
+
10
+ Tetra::Project.init(@project_path)
11
+ @project = Tetra::Project.new(@project_path)
12
+ end
13
+
14
+ after(:each) do
15
+ FileUtils.rm_rf(@project_path)
16
+ end
17
+
18
+ let(:archiver) { Tetra::Archiver.new(@project) }
19
+
20
+ describe "#archive_single" 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
+
25
+ archiver.archive_single(".", "test.tar.xz")
26
+ expect(`tar -Jtf test.tar.xz`.split).to include("test")
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "#archive_incremental" do
32
+ it "archives an increment of a directory" do
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
54
+ end
55
+
56
+ describe "#archive_kit" do
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
78
+
79
+ @project.from_directory do
80
+ File.open(File.join("kit", "kit_test2"), "w") { |io| io.puts "test content" }
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
90
+ end
91
+
92
+ describe "#archive_package" do
93
+ it "archives a package files" do
94
+ @project.from_directory do
95
+ Dir.mkdir(File.join("src", "package-name"))
96
+ File.open(File.join("src", "package-name", "src_test"), "w") { |io| io.puts "test content" }
97
+ end
98
+ @project.finish(false)
99
+
100
+ archiver.archive_package "package-name"
101
+ @project.from_directory do
102
+ expect(`tar -Jtf output/package-name/package-name.tar.xz`.split).to include("src_test")
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,105 @@
1
+ # encoding: UTF-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Tetra::Git do
6
+ before(:each) do
7
+ @git_path = File.expand_path(File.join("spec", "data", "test-repo"))
8
+ Dir.mkdir(@git_path)
9
+
10
+ @git = Tetra::Git.new(@git_path)
11
+ @git.init
12
+ end
13
+
14
+ after(:each) do
15
+ FileUtils.rm_rf(@git_path)
16
+ end
17
+
18
+ describe "#init" do
19
+ it "complains if a double initialization is attempted" do
20
+ expect do
21
+ @git.init
22
+ end.to raise_error(Tetra::GitAlreadyInitedError)
23
+ end
24
+ end
25
+
26
+ describe "#commit_whole_directory" do
27
+ it "commits all contents of a directory to git for later use" do
28
+ Dir.chdir(@git_path) do
29
+ File.open("file1", "w") do |file|
30
+ file.write "test"
31
+ end
32
+
33
+ # check that gitignore files are moved correctly
34
+ File.open(".gitignore", "w") do |file|
35
+ file.write "file1o"
36
+ end
37
+
38
+ @git.commit_whole_directory("test", "test")
39
+
40
+ files = `git ls-tree --name-only -r HEAD`.split("\n")
41
+
42
+ expect(files).to include("file1")
43
+ expect(files).to include(".gitignore_disabled_by_tetra")
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "#changed_files_since" do
49
+ it "lists files changed since a tetra tag" do
50
+ Dir.chdir(@git_path) do
51
+ File.open("file1", "w") do |file|
52
+ file.write "test"
53
+ end
54
+
55
+ @git.commit_whole_directory("test", "test")
56
+
57
+ File.open("file2", "w") do |file|
58
+ file.write "test"
59
+ end
60
+
61
+ @git.commit_whole_directory("test end")
62
+
63
+ files = @git.changed_files_since("test")
64
+
65
+ expect(files).not_to include("file1")
66
+ expect(files).to include("file2")
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "#changed_files_between" do
72
+ it "lists files changed between tetra tags" do
73
+ Dir.chdir(@git_path) do
74
+ File.open("file1", "w") do |file|
75
+ file.write "test"
76
+ end
77
+
78
+ @git.commit_whole_directory("test", "test_start")
79
+
80
+ File.open("file2", "w") do |file|
81
+ file.write "test"
82
+ end
83
+ Dir.mkdir("subdir")
84
+ File.open(File.join("subdir", "file3"), "w") do |file|
85
+ file.write "test"
86
+ end
87
+
88
+ @git.commit_whole_directory("test", "test_end")
89
+
90
+ File.open("file4", "w") do |file|
91
+ file.write "test"
92
+ end
93
+
94
+ @git.commit_whole_directory("test")
95
+
96
+ files = @git.changed_files_between("test_start", "test_end", "subdir")
97
+
98
+ expect(files).not_to include("file1")
99
+ expect(files).not_to include("file2")
100
+ expect(files).to include("subdir/file3")
101
+ expect(files).not_to include("file4")
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,119 @@
1
+ # encoding: UTF-8
2
+
3
+ require "spec_helper"
4
+ require "rubygems"
5
+ require "zip"
6
+
7
+ describe Tetra::KitChecker do
8
+ include Tetra::Mockers
9
+
10
+ before(:each) do
11
+ create_mock_project
12
+ @kit_checker = Tetra::KitChecker.new(@project)
13
+ end
14
+
15
+ after(:each) do
16
+ delete_mock_project
17
+ end
18
+
19
+ describe "#kit_file_paths" do
20
+ it "returns an array of paths found in kit" do
21
+ @project.from_directory("kit") do
22
+ FileUtils.touch("top_level")
23
+ FileUtils.mkdir_p("directory")
24
+ FileUtils.touch(File.join("directory", "in_directory"))
25
+ Zip::File.open("zipped.zip", Zip::File::CREATE) do |zipfile|
26
+ Dir[File.join("directory", "**", "**")].each do |file|
27
+ zipfile.add(file.sub("/directory", ""), file)
28
+ end
29
+ end
30
+ end
31
+
32
+ all_files = @kit_checker.kit_file_paths
33
+
34
+ expect(all_files).to include ["top_level", nil]
35
+ expect(all_files).not_to include ["directory", nil]
36
+ expect(all_files).to include ["directory/in_directory", nil]
37
+ expect(all_files).to include ["zipped.zip", nil]
38
+ expect(all_files).to include ["directory/in_directory", "zipped.zip"]
39
+ end
40
+ end
41
+
42
+ describe "#source_class_names" do
43
+ it "distills source class names in kit" do
44
+ all_files = [
45
+ ["path/to/ClassOne.java", nil],
46
+ ["path/to/ClassTwo.java", "path/to/archive.jar"],
47
+ ["ClassThree.java", "another_archive.jar"],
48
+ ["path/to/CompiledClass.class", "yet_another.jar"]
49
+ ]
50
+
51
+ class_names = @kit_checker.source_class_names(all_files)
52
+
53
+ expect(class_names).to include "path.to.ClassOne"
54
+ expect(class_names).to include "path.to.ClassTwo"
55
+ expect(class_names).to include "ClassThree"
56
+ expect(class_names).not_to include "path.to.CompiledClass"
57
+ end
58
+ end
59
+
60
+ describe "#compiled_classes" do
61
+ it "distills source class names in kit" do
62
+ all_files = [
63
+ ["path/to/ClassOne.class", nil],
64
+ ["path/to/ClassTwo.class", "path/to/archive.jar"],
65
+ ["ClassThree.class", "another_archive.jar"],
66
+ ["path/to/SourceClass.java", "yet_another.jar"]
67
+ ]
68
+
69
+ classes = @kit_checker.compiled_classes(all_files)
70
+
71
+ expect(classes[nil]).to include "path.to.ClassOne"
72
+ expect(classes["path/to/archive.jar"]).to include "path.to.ClassTwo"
73
+ expect(classes["another_archive.jar"]).to include "ClassThree"
74
+ expect(classes["yet_another.jar"]).to be_nil
75
+ end
76
+ end
77
+
78
+ describe "#unsourced_archives" do
79
+ it "returns a list of jars wich source files are missing" do
80
+ @project.from_directory("kit") do
81
+ FileUtils.mkdir_p("package1")
82
+ FileUtils.touch(File.join("package1", "UnsourcedClass.class"))
83
+
84
+ FileUtils.mkdir_p("package2")
85
+ FileUtils.touch(File.join("package2", "SourcedClass.java"))
86
+ Zip::File.open("zipped-source-2.jar", Zip::File::CREATE) do |zipfile|
87
+ Dir[File.join("package2", "**", "**")].each do |file|
88
+ zipfile.add(file.sub("/package2", ""), file)
89
+ end
90
+ end
91
+ FileUtils.rm(File.join("package2", "SourcedClass.java"))
92
+ FileUtils.touch(File.join("package2", "SourcedClass.class"))
93
+ Zip::File.open("zipped-2.jar", Zip::File::CREATE) do |zipfile|
94
+ Dir[File.join("package2", "**", "**")].each do |file|
95
+ zipfile.add(file.sub("/package2", ""), file)
96
+ end
97
+ end
98
+
99
+ FileUtils.mkdir_p("package3")
100
+ FileUtils.touch(File.join("package3", "SourcedSameArchive.java"))
101
+ FileUtils.touch(File.join("package3", "SourcedSameArchive.class"))
102
+ Zip::File.open("zipped-3.zip", Zip::File::CREATE) do |zipfile|
103
+ Dir[File.join("package3", "**", "**")].each do |file|
104
+ zipfile.add(file.sub("/package3", ""), file)
105
+ end
106
+ end
107
+ end
108
+
109
+ unsourced = @kit_checker.unsourced_archives
110
+ expect(unsourced.length).to eq 1
111
+
112
+ expect(unsourced.first[:archive]).to be_nil
113
+ expect(unsourced.first[:class_names]).to include "package1.UnsourcedClass"
114
+ expect(unsourced.first[:class_names]).to include "package2.SourcedClass"
115
+ expect(unsourced.first[:class_names]).to include "package3.SourcedSameArchive"
116
+ expect(unsourced.first[:unsourced_class_names]).to include "package1.UnsourcedClass"
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,68 @@
1
+ # encoding: UTF-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Tetra::MavenRunner do
6
+ it_behaves_like Tetra::KitRunner
7
+ include Tetra::Mockers
8
+
9
+ before(:each) do
10
+ create_mock_project
11
+ @kit_runner = Tetra::MavenRunner.new(@project)
12
+ end
13
+
14
+ after(:each) do
15
+ delete_mock_project
16
+ end
17
+
18
+ describe "#get_maven_commandline" do
19
+ it "returns commandline options for running maven" do
20
+ executable_path = create_mock_executable("mvn")
21
+
22
+ @project.from_directory do
23
+ commandline = @kit_runner.get_maven_commandline(".", ["--otheroption"])
24
+ expected_commandline = "./#{executable_path} -Dmaven.repo.local=./kit/m2 -s./kit/m2/settings.xml --otheroption"
25
+ expect(commandline).to eq expected_commandline
26
+ end
27
+ end
28
+ it "doesn't return commandline options if Maven is not available" do
29
+ expect { @kit_runner.get_maven_commandline(".", []) }.to raise_error(Tetra::ExecutableNotFoundError)
30
+ end
31
+ end
32
+
33
+ describe "#mvn" do
34
+ it "runs maven" do
35
+ create_mock_executable("mvn")
36
+ @project.from_directory do
37
+ @kit_runner.mvn(["extra-option"])
38
+ expect(File.read("test_out").strip).to match(/extra-option$/)
39
+ end
40
+ end
41
+ it "doesn't run Maven if it is not available" do
42
+ @project.from_directory do
43
+ expect { @kit_runner.mvn([]) }.to raise_error(Tetra::ExecutableNotFoundError)
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "#get_source_jar" do
49
+ it "runs maven to get a source jar" do
50
+ create_mock_executable("mvn")
51
+ @project.from_directory do
52
+ @kit_runner.get_source_jar("test_group", "test_artifact_id", "test_version")
53
+ expected = /dependency:get -Dartifact=test_group:test_artifact_id:test_version:jar:sources -Dtransitive=false$/
54
+ expect(File.read("test_out").strip).to match expected
55
+ end
56
+ end
57
+ end
58
+
59
+ describe "#get_effective_pom" do
60
+ it "runs maven to get an effective pom" do
61
+ create_mock_executable("mvn")
62
+ @project.from_directory do
63
+ expect(@kit_runner.get_effective_pom("test.pom")).to eq "test.pom.effective"
64
+ expect(File.read("test_out").strip).to match(/help:effective-pom -ftest.pom -Doutput=test.pom.effective$/)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: UTF-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Tetra::MavenWebsite do
6
+ let(:site) { Tetra::MavenWebsite.new }
7
+
8
+ describe "#search_by_sha1" do
9
+ it "uses search.maven.org to look for poms by jar SHA1" do
10
+ result = site.search_by_sha1("546b5220622c4d9b2da45ad1899224b6ce1c8830").first
11
+
12
+ expect(result["g"]).to eq("antlr")
13
+ expect(result["a"]).to eq("antlrall")
14
+ expect(result["v"]).to eq("2.7.2")
15
+ end
16
+ end
17
+
18
+ describe "#search_by_name" do
19
+ it "uses search.maven.org to look for poms by keyword (name)" do
20
+ result = site.search_by_name("jruby").first
21
+
22
+ # not much to test here
23
+ expect(result).not_to be_nil
24
+ end
25
+ end
26
+
27
+ describe "#search_by_group_id_and_artifact_id" do
28
+ it "uses search.maven.org to look for poms by group and artifact id" do
29
+ results = site.search_by_group_id_and_artifact_id("antlr", "antlrall")
30
+
31
+ expect(results.any? { |result| result["id"] == "antlr:antlrall:2.7.2" }).to be_truthy
32
+ end
33
+ end
34
+
35
+ describe "#search_by_maven_id" do
36
+ it "uses search.maven.org to look for poms by group id, artifact id and version" do
37
+ result = site.search_by_maven_id("antlr", "antlrall", "2.7.2")
38
+
39
+ expect(result.first["id"]).to eq("antlr:antlrall:2.7.2")
40
+ end
41
+ end
42
+
43
+ describe "#get_maven_id_from" do
44
+ it "uses search.maven.org to look for poms" do
45
+ expect(site.get_maven_id_from("g" => 1, "a" => 2, "v" => 3)).to eq([1, 2, 3])
46
+ end
47
+ end
48
+
49
+ describe "#download_pom" do
50
+ it "gets a pom from search.maven.org" do
51
+ dir_path = File.join("spec", "data", "antlr")
52
+ pom_path = File.join(dir_path, "pom.xml")
53
+ expect(site.download_pom("antlr", "antlrall", "2.7.2")).to eq(File.read(pom_path))
54
+ end
55
+ end
56
+ end