gjp 0.36.0 → 0.37.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/.gitignore +4 -0
  2. data/.rubocop.yml +7 -0
  3. data/.rubocop_todo.yml +241 -0
  4. data/SPECIAL_CASES.md +2 -5
  5. data/integration-tests/commons.sh +2 -0
  6. data/lib/gjp.rb +22 -1
  7. data/lib/gjp/ant_runner.rb +1 -1
  8. data/lib/gjp/archiver.rb +11 -11
  9. data/lib/gjp/commands/ant.rb +21 -0
  10. data/lib/gjp/commands/base.rb +94 -0
  11. data/lib/gjp/commands/download-maven-source-jars.rb +28 -0
  12. data/lib/gjp/commands/dry-run.rb +16 -0
  13. data/lib/gjp/commands/finish.rb +22 -0
  14. data/lib/gjp/commands/generate-all.rb +38 -0
  15. data/lib/gjp/commands/generate-kit-archive.rb +18 -0
  16. data/lib/gjp/commands/generate-kit-spec.rb +16 -0
  17. data/lib/gjp/commands/generate-package-archive.rb +19 -0
  18. data/lib/gjp/commands/generate-package-script.rb +21 -0
  19. data/lib/gjp/commands/generate-package-spec.rb +22 -0
  20. data/lib/gjp/commands/get-pom.rb +31 -0
  21. data/lib/gjp/commands/get-source.rb +35 -0
  22. data/lib/gjp/commands/init.rb +15 -0
  23. data/lib/gjp/commands/list-kit-missing-sources.rb +21 -0
  24. data/lib/gjp/commands/move-jars-to-kit.rb +18 -0
  25. data/lib/gjp/commands/mvn.rb +22 -0
  26. data/lib/gjp/git.rb +18 -8
  27. data/lib/gjp/kit_checker.rb +6 -6
  28. data/lib/gjp/kit_runner.rb +2 -2
  29. data/lib/gjp/kit_spec_adapter.rb +1 -1
  30. data/lib/gjp/main.rb +103 -0
  31. data/lib/gjp/maven_runner.rb +1 -1
  32. data/lib/gjp/maven_website.rb +8 -6
  33. data/lib/gjp/package_spec_adapter.rb +1 -1
  34. data/lib/gjp/pom.rb +3 -1
  35. data/lib/gjp/pom_getter.rb +12 -4
  36. data/lib/gjp/project.rb +4 -2
  37. data/lib/gjp/script_generator.rb +2 -1
  38. data/lib/gjp/spec_generator.rb +2 -2
  39. data/lib/gjp/version.rb +1 -1
  40. data/lib/gjp/version_matcher.rb +3 -3
  41. data/lib/template/kit.spec +1 -0
  42. data/lib/template/package.spec +1 -0
  43. data/spec/lib/ant_runner_spec.rb +3 -3
  44. data/spec/lib/archiver_spec.rb +1 -1
  45. data/spec/lib/git_spec.rb +25 -3
  46. data/spec/lib/kit_checker_spec.rb +6 -6
  47. data/spec/lib/kit_runner_spec.rb +1 -1
  48. data/spec/lib/maven_runner_spec.rb +6 -5
  49. data/spec/lib/maven_website_spec.rb +2 -2
  50. data/spec/lib/pom_getter_spec.rb +1 -1
  51. data/spec/lib/pom_spec.rb +5 -3
  52. data/spec/lib/project_spec.rb +15 -14
  53. data/spec/lib/script_generator_spec.rb +4 -2
  54. data/spec/lib/source_getter_spec.rb +1 -1
  55. data/spec/lib/spec_generator_spec.rb +2 -2
  56. data/spec/lib/template_manager_spec.rb +6 -6
  57. data/spec/lib/version_matcher_spec.rb +1 -1
  58. data/spec/spec_helper.rb +25 -23
  59. metadata +22 -3
  60. data/lib/gjp/cli.rb +0 -384
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'find'
4
- require 'pathname'
3
+ require "find"
4
+ require "pathname"
5
5
 
6
6
  module Gjp
7
7
  # runs programs from a gjp kit with gjp-specific options
@@ -21,7 +21,7 @@ module Gjp
21
21
  end
22
22
  end
23
23
 
24
- def get_binding
24
+ def public_binding
25
25
  binding
26
26
  end
27
27
  end
@@ -0,0 +1,103 @@
1
+ # encoding: UTF-8
2
+ require "clamp"
3
+
4
+ module Gjp
5
+ class MainCommand < Clamp::Command
6
+
7
+ subcommand(
8
+ "init",
9
+ "Inits a gjp project in the current directory",
10
+ Gjp::InitCommand
11
+ )
12
+
13
+ subcommand(
14
+ "dry-run",
15
+ "Starts a dry-run build",
16
+ Gjp::DryRunCommand
17
+ )
18
+
19
+ subcommand(
20
+ "mvn",
21
+ "Locates and runs Maven from any directory in kit/",
22
+ Gjp::MavenCommand
23
+ )
24
+
25
+ subcommand(
26
+ "ant",
27
+ "Locates and runs Ant from any directory in kit/",
28
+ Gjp::AntCommand
29
+ )
30
+
31
+ subcommand(
32
+ "finish",
33
+ "Ends the current dry-run",
34
+ Gjp::FinishCommand
35
+ )
36
+
37
+ subcommand(
38
+ "generate-kit-archive",
39
+ "Create or refresh the kit tarball",
40
+ Gjp::GenerateKitArchiveCommand
41
+ )
42
+
43
+ subcommand(
44
+ "generate-kit-spec",
45
+ "Create or refresh a spec file for the kit",
46
+ Gjp::GenerateKitSpecCommand
47
+ )
48
+
49
+ subcommand(
50
+ "generate-package-script",
51
+ "Create or refresh a build.sh file for a package",
52
+ Gjp::GeneratePackageScriptCommand
53
+ )
54
+
55
+ subcommand(
56
+ "generate-package-archive",
57
+ "Create or refresh a package tarball",
58
+ Gjp::GeneratePackageArchiveCommand
59
+ )
60
+
61
+ subcommand(
62
+ "generate-package-spec",
63
+ "Create or refresh a spec file for a package",
64
+ Gjp::GeneratePackageSpecCommand
65
+ )
66
+
67
+ subcommand(
68
+ "generate-all",
69
+ "Create or refresh specs, archives, scripts for a package and the kit",
70
+ Gjp::GenerateAllCommand
71
+ )
72
+
73
+ subcommand(
74
+ "move-jars-to-kit",
75
+ "Locates jars in src/ and moves them to kit/",
76
+ Gjp::MoveJarsToKitCommand
77
+ )
78
+
79
+ subcommand(
80
+ "download-maven-source-jars",
81
+ "Attempts to download Maven kit/ sources",
82
+ Gjp::DownloadMavenSourceJarsCommand
83
+ )
84
+
85
+ subcommand(
86
+ "get-pom",
87
+ "Retrieves a pom file",
88
+ Gjp::GetPomCommand
89
+ )
90
+
91
+ subcommand(
92
+ "get-source",
93
+ "Attempts to retrieve a project's sources",
94
+ Gjp::GetSourceCommand
95
+ )
96
+
97
+ subcommand(
98
+ "list-kit-missing-sources",
99
+ "Locates jars in kit/ that have no source files",
100
+ Gjp::ListKitMissingSourcesCommand
101
+ )
102
+ end
103
+ end
@@ -38,7 +38,7 @@ module Gjp
38
38
  repo_path = File.join(prefix, "kit", "m2")
39
39
  config_path = File.join(prefix, "kit", "m2", "settings.xml")
40
40
 
41
- "#{mvn_path} -Dmaven.repo.local=#{repo_path} -s#{config_path} #{options.join(' ')}"
41
+ "#{mvn_path} -Dmaven.repo.local=#{repo_path} -s#{config_path} #{options.join(" ")}"
42
42
  else
43
43
  raise ExecutableNotFoundError.new("mvn")
44
44
  end
@@ -11,34 +11,36 @@ module Gjp
11
11
  # searching by a jar sha1 hash
12
12
  # see output format at http://search.maven.org/#api
13
13
  def search_by_sha1(sha1)
14
- return search({:q => "1:\"#{sha1}\""})
14
+ return search(:q => "1:\"#{sha1}\"")
15
15
  end
16
16
 
17
17
  # returns a search result object from search.maven.com
18
18
  # searching by keyword (name)
19
19
  # see output format at http://search.maven.org/#api
20
20
  def search_by_name(name)
21
- return search({:q => name})
21
+ return search(:q => name)
22
22
  end
23
23
 
24
24
  # returns a search result object from search.maven.com
25
25
  # searching by Maven's group id and artifact id
26
26
  # see output format at http://search.maven.org/#api
27
27
  def search_by_group_id_and_artifact_id(group_id, artifact_id)
28
- return search({:q => "g:\"#{group_id}\" AND a:\"#{artifact_id}\"", :core => "gav"})
28
+ return search(:q => "g:\"#{group_id}\" AND a:\"#{artifact_id}\"", :core => "gav")
29
29
  end
30
30
 
31
31
  # returns a search result object from search.maven.com
32
32
  # searching by Maven's id (group id, artifact id and version)
33
33
  # see output format at http://search.maven.org/#api
34
34
  def search_by_maven_id(group_id, artifact_id, version)
35
- return search({:q => "g:\"#{group_id}\" AND a:\"#{artifact_id}\" AND v:\"#{version}\""})
35
+ return search(:q => "g:\"#{group_id}\" AND a:\"#{artifact_id}\" AND v:\"#{version}\"")
36
36
  end
37
37
 
38
38
  # returns a search result object from search.maven.com
39
39
  # see input and output format at http://search.maven.org/#api
40
40
  def search(params)
41
- response = RestClient.get "http://search.maven.org/solrsearch/select", {:params => params.merge({"rows" => "100", "wt" => "json"})}
41
+ response = RestClient.get("http://search.maven.org/solrsearch/select",
42
+ :params => params.merge("rows" => "100", "wt" => "json")
43
+ )
42
44
  json = JSON.parse(response.to_s)
43
45
  return json["response"]["docs"]
44
46
  end
@@ -53,7 +55,7 @@ module Gjp
53
55
  def download_pom(group_id, artifact_id, version)
54
56
  path = "#{group_id.gsub(".", "/")}/#{artifact_id}/#{version}/#{artifact_id}-#{version}.pom"
55
57
  log.debug("downloading #{path}...")
56
- return (RestClient.get "http://search.maven.org/remotecontent", {:params => {:filepath => path}}).to_s
58
+ return (RestClient.get "http://search.maven.org/remotecontent", :params => {:filepath => path}).to_s
57
59
  end
58
60
  end
59
61
  end
@@ -41,7 +41,7 @@ module Gjp
41
41
  end
42
42
  end
43
43
 
44
- def get_binding
44
+ def public_binding
45
45
  binding
46
46
  end
47
47
 
@@ -40,7 +40,9 @@ module Gjp
40
40
  end
41
41
 
42
42
  def runtime_dependency_ids
43
- result = @doc.xpath("project/dependencies/dependency[not(optional='true') and not(scope='provided') and not(scope='test') and not(scope='system')]").map do |element|
43
+ result = @doc.xpath("project/dependencies/dependency[\
44
+ not(optional='true') and not(scope='provided') and not(scope='test') and not(scope='system')\
45
+ ]").map do |element|
44
46
  [element.xpath("groupId").text, element.xpath("artifactId").text, element.xpath("version").text]
45
47
  end
46
48
  end
@@ -16,7 +16,7 @@ module Gjp
16
16
  # saves a jar poms in <jar_filename>.pom
17
17
  # returns filename and status if found, else nil
18
18
  def get_pom(filename)
19
- content, status = (get_pom_from_jar(filename) or get_pom_from_sha1(filename) or get_pom_from_heuristic(filename))
19
+ content, status = (get_pom_from_jar(filename) || get_pom_from_sha1(filename) || get_pom_from_heuristic(filename))
20
20
  if content
21
21
  pom_filename = filename.sub(/(\.jar)?$/, ".pom")
22
22
  File.open(pom_filename, "w") { |io| io.write(content) }
@@ -52,7 +52,9 @@ module Gjp
52
52
  results = site.search_by_sha1(sha1).select {|result| result["ec"].include?(".pom")}
53
53
  result = results.first
54
54
  if result != nil
55
- log.info("pom.xml for #{file} found on search.maven.org for sha1 #{sha1} (#{result["g"]}:#{result["a"]}:#{result["v"]})")
55
+ log.info("pom.xml for #{file} found on search.maven.org for sha1 #{sha1}\
56
+ (#{result["g"]}:#{result["a"]}:#{result["v"]})"
57
+ )
56
58
  group_id, artifact_id, version = site.get_maven_id_from result
57
59
  return site.download_pom(group_id, artifact_id, version), :found_via_sha1
58
60
  end
@@ -80,11 +82,17 @@ module Gjp
80
82
  results = site.search_by_group_id_and_artifact_id(group_id, artifact_id)
81
83
  log.debug("All versions: #{results}")
82
84
  their_versions = results.map {|doc| doc["v"]}
83
- best_matched_version = if my_version != nil then version_matcher.best_match(my_version, their_versions) else their_versions.max end
85
+ best_matched_version = if my_version != nil
86
+ version_matcher.best_match(my_version, their_versions)
87
+ else
88
+ their_versions.max
89
+ end
84
90
  best_matched_result = (results.select{|result| result["v"] == best_matched_version}).first
85
91
 
86
92
  group_id, artifact_id, version = site.get_maven_id_from(best_matched_result)
87
- log.warn("pom.xml for #{filename} found on search.maven.org with heuristic search (#{group_id}:#{artifact_id}:#{version})")
93
+ log.warn("pom.xml for #{filename} found on search.maven.org with heuristic search\
94
+ (#{group_id}:#{artifact_id}:#{version})"
95
+ )
88
96
 
89
97
  return site.download_pom(group_id, artifact_id, version), :found_via_heuristic
90
98
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'find'
3
+ require "find"
4
4
 
5
5
  module Gjp
6
6
  # encapsulates a Gjp project directory
@@ -49,7 +49,9 @@ module Gjp
49
49
  dir_path = Pathname.new(File.expand_path(dir)).relative_path_from(Pathname.new(@full_path))
50
50
  components = dir_path.to_s.split(File::SEPARATOR)
51
51
 
52
- if components.count >= 2 && components.first == "src" && Dir.exist?(File.join(@full_path, components[0], components[1]))
52
+ if components.count >= 2 &&
53
+ components.first == "src" &&
54
+ Dir.exist?(File.join(@full_path, components[0], components[1]))
53
55
  components[1]
54
56
  else
55
57
  raise NoPackageDirectoryError
@@ -42,7 +42,8 @@ module Gjp
42
42
 
43
43
  script_name = "build.sh"
44
44
  result_path = File.join("src", name, script_name)
45
- conflict_count = @project.merge_new_content(new_content, result_path, "Build script generated", "generate_#{name}_build_script")
45
+ conflict_count = @project.merge_new_content(new_content, result_path, "Build script generated",
46
+ "generate_#{name}_build_script")
46
47
 
47
48
  destination_dir = File.join("output", name)
48
49
  FileUtils.mkdir_p(destination_dir)
@@ -17,7 +17,7 @@ module Gjp
17
17
  FileUtils.mkdir_p(output_dir)
18
18
 
19
19
  adapter = Gjp::KitSpecAdapter.new(@project)
20
- conflict_count = generate_merging("kit.spec", adapter.get_binding, spec_path, :generate_kit_spec)
20
+ conflict_count = generate_merging("kit.spec", adapter.public_binding, spec_path, :generate_kit_spec)
21
21
 
22
22
  symlink_to_output(spec_path, output_dir)
23
23
 
@@ -34,7 +34,7 @@ module Gjp
34
34
  FileUtils.mkdir_p(output_dir)
35
35
 
36
36
  adapter = Gjp::PackageSpecAdapter.new(@project, name, pom, filter)
37
- conflict_count = generate_merging("package.spec", adapter.get_binding, spec_path, "generate_#{name}_spec")
37
+ conflict_count = generate_merging("package.spec", adapter.public_binding, spec_path, "generate_#{name}_spec")
38
38
 
39
39
  symlink_to_output(spec_path, output_dir)
40
40
 
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Gjp
4
- VERSION = "0.36.0"
4
+ VERSION = "0.37.0"
5
5
  end
@@ -28,13 +28,13 @@ module Gjp
28
28
  # - score weighs differently on chunk index (first chunks are most important)
29
29
  # - lowest score wins
30
30
  def best_match(my_version, their_versions)
31
- log.debug("version comparison: #{my_version} vs #{their_versions.join(', ')}")
31
+ log.debug("version comparison: #{my_version} vs #{their_versions.join(", ")}")
32
32
 
33
- my_chunks = my_version.split /[\.\-\_ ~,]/
33
+ my_chunks = my_version.split(/[\.\-\_ ~,]/)
34
34
  their_chunks_hash = Hash[
35
35
  their_versions.map do |their_version|
36
36
  their_chunks_for_version = if their_version != nil
37
- their_version.split /[\.\-\_ ~,]/
37
+ their_version.split(/[\.\-\_ ~,]/)
38
38
  else
39
39
  []
40
40
  end
@@ -52,6 +52,7 @@ be installed on end users' systems.
52
52
  # nothing to do, gjp kits are precompiled by design
53
53
 
54
54
  %install
55
+ export NO_BRP_CHECK_BYTECODE_VERSION=true
55
56
  install -d -m 0755 %{buildroot}%{_datadir}/gjp/%{name}/
56
57
  cp -a * %{buildroot}%{_datadir}/gjp/%{name}/
57
58
  %fdupes -s %{buildroot}%{_datadir}/gjp/%{name}/
@@ -50,6 +50,7 @@ cd ../../
50
50
  sh src/<%= name %>/build.sh
51
51
 
52
52
  %install
53
+ export NO_BRP_CHECK_BYTECODE_VERSION=true
53
54
  mkdir -p %{buildroot}%{_javadir}
54
55
  <% outputs.each do |output| %>
55
56
  cp -a <%= output %> %{buildroot}%{_javadir}/<%= File.basename(output) %>
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
4
- require 'lib/kit_runner_spec'
3
+ require "spec_helper"
4
+ require "lib/kit_runner_spec"
5
5
 
6
6
  describe Gjp::AntRunner do
7
7
  it_behaves_like Gjp::KitRunner
@@ -34,7 +34,7 @@ describe Gjp::AntRunner do
34
34
  executable_path = create_mock_executable("ant")
35
35
  @project.from_directory do
36
36
  @kit_runner.ant(["extra-option"])
37
- File.read("test_out").strip.should match /extra-option$/
37
+ File.read("test_out").strip.should match(/extra-option$/)
38
38
  end
39
39
  end
40
40
  it "doesn't run Ant if it is not available" do
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Gjp::Archiver do
6
6
  before(:each) do
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Gjp::Git do
6
6
  before(:each) do
@@ -17,9 +17,31 @@ describe Gjp::Git do
17
17
 
18
18
  describe "#init" do
19
19
  it "complains if a double initialization is attempted" do
20
- expect {
20
+ expect do
21
21
  @git.init
22
- }.to raise_error(Gjp::GitAlreadyInitedError)
22
+ end.to raise_error(Gjp::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
+ files.should include("file1")
43
+ files.should include(".gitignore_disabled_by_gjp")
44
+ end
23
45
  end
24
46
  end
25
47
 
@@ -39,7 +39,7 @@ describe Gjp::KitChecker do
39
39
  end
40
40
  end
41
41
 
42
- describe "#get_source_classes" do
42
+ describe "#source_class_names" do
43
43
  it "distills source class names in kit" do
44
44
  all_files = [
45
45
  ["path/to/ClassOne.java", nil],
@@ -48,7 +48,7 @@ describe Gjp::KitChecker do
48
48
  ["path/to/CompiledClass.class", "yet_another.jar"],
49
49
  ]
50
50
 
51
- class_names = @kit_checker.get_source_class_names(all_files)
51
+ class_names = @kit_checker.source_class_names(all_files)
52
52
 
53
53
  class_names.should include "path.to.ClassOne"
54
54
  class_names.should include "path.to.ClassTwo"
@@ -57,7 +57,7 @@ describe Gjp::KitChecker do
57
57
  end
58
58
  end
59
59
 
60
- describe "#get_compiled_classes" do
60
+ describe "#compiled_classes" do
61
61
  it "distills source class names in kit" do
62
62
  all_files = [
63
63
  ["path/to/ClassOne.class", nil],
@@ -66,7 +66,7 @@ describe Gjp::KitChecker do
66
66
  ["path/to/SourceClass.java", "yet_another.jar"],
67
67
  ]
68
68
 
69
- classes = @kit_checker.get_compiled_classes(all_files)
69
+ classes = @kit_checker.compiled_classes(all_files)
70
70
 
71
71
  classes[nil].should include "path.to.ClassOne"
72
72
  classes["path/to/archive.jar"].should include "path.to.ClassTwo"
@@ -75,7 +75,7 @@ describe Gjp::KitChecker do
75
75
  end
76
76
  end
77
77
 
78
- describe "#get_unsourced" do
78
+ describe "#unsourced_archives" do
79
79
  it "returns a list of jars wich source files are missing" do
80
80
  @project.from_directory("kit") do
81
81
  FileUtils.mkdir_p("package1")
@@ -106,7 +106,7 @@ describe Gjp::KitChecker do
106
106
  end
107
107
  end
108
108
 
109
- unsourced = @kit_checker.get_unsourced
109
+ unsourced = @kit_checker.unsourced_archives
110
110
  unsourced.length().should eq 1
111
111
 
112
112
  unsourced.first[:archive].should be_nil