gjp 0.37.0 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. data/.rubocop.yml +3 -0
  2. data/.rubocop_todo.yml +0 -130
  3. data/Rakefile +2 -2
  4. data/gjp.gemspec +2 -2
  5. data/integration-tests/commons.sh +1 -1
  6. data/lib/gjp.rb +12 -12
  7. data/lib/gjp/ant_runner.rb +2 -2
  8. data/lib/gjp/archiver.rb +13 -11
  9. data/lib/gjp/commands/ant.rb +1 -1
  10. data/lib/gjp/commands/base.rb +25 -26
  11. data/lib/gjp/commands/{download-maven-source-jars.rb → download_maven_source_jars.rb} +0 -0
  12. data/lib/gjp/commands/{dry-run.rb → dry_run.rb} +0 -0
  13. data/lib/gjp/commands/finish.rb +0 -1
  14. data/lib/gjp/commands/{generate-all.rb → generate_all.rb} +3 -4
  15. data/lib/gjp/commands/{generate-kit-archive.rb → generate_kit_archive.rb} +0 -1
  16. data/lib/gjp/commands/{generate-kit-spec.rb → generate_kit_spec.rb} +0 -1
  17. data/lib/gjp/commands/{generate-package-archive.rb → generate_package_archive.rb} +1 -2
  18. data/lib/gjp/commands/{generate-package-script.rb → generate_package_script.rb} +1 -2
  19. data/lib/gjp/commands/{generate-package-spec.rb → generate_package_spec.rb} +3 -4
  20. data/lib/gjp/commands/{get-pom.rb → get_pom.rb} +10 -9
  21. data/lib/gjp/commands/{get-source.rb → get_source.rb} +4 -5
  22. data/lib/gjp/commands/init.rb +0 -1
  23. data/lib/gjp/commands/{list-kit-missing-sources.rb → list_kit_missing_sources.rb} +1 -2
  24. data/lib/gjp/commands/{move-jars-to-kit.rb → move_jars_to_kit.rb} +0 -1
  25. data/lib/gjp/commands/mvn.rb +1 -2
  26. data/lib/gjp/git.rb +16 -14
  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 -2
  30. data/lib/gjp/logger.rb +16 -13
  31. data/lib/gjp/main.rb +0 -1
  32. data/lib/gjp/maven_runner.rb +2 -2
  33. data/lib/gjp/maven_website.rb +14 -14
  34. data/lib/gjp/package_spec_adapter.rb +9 -8
  35. data/lib/gjp/pom.rb +13 -14
  36. data/lib/gjp/pom_getter.rb +18 -16
  37. data/lib/gjp/project.rb +21 -22
  38. data/lib/gjp/script_generator.rb +8 -8
  39. data/lib/gjp/source_getter.rb +3 -3
  40. data/lib/gjp/spec_generator.rb +3 -3
  41. data/lib/gjp/template_manager.rb +2 -2
  42. data/lib/gjp/version.rb +1 -1
  43. data/lib/gjp/version_matcher.rb +32 -35
  44. data/spec/lib/archiver_spec.rb +3 -3
  45. data/spec/lib/git_spec.rb +1 -1
  46. data/spec/lib/kit_checker_spec.rb +10 -10
  47. data/spec/lib/pom_getter_spec.rb +2 -3
  48. data/spec/lib/pom_spec.rb +2 -3
  49. data/spec/lib/project_spec.rb +10 -10
  50. data/spec/lib/script_generator_spec.rb +1 -2
  51. data/spec/lib/source_getter_spec.rb +0 -1
  52. data/spec/lib/spec_generator_spec.rb +0 -1
  53. data/spec/lib/template_manager_spec.rb +1 -1
  54. data/spec/lib/version_matcher_spec.rb +8 -9
  55. data/spec/spec_helper.rb +0 -3
  56. metadata +13 -13
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Gjp
4
4
  class GenerateKitArchiveCommand < Gjp::BaseCommand
5
-
6
5
  option ["-f", "--full"], :flag, "create a full archive (not incremental)"
7
6
 
8
7
  def execute
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Gjp
4
4
  class GenerateKitSpecCommand < Gjp::BaseCommand
5
-
6
5
  def execute
7
6
  checking_exceptions do
8
7
  project = Gjp::Project.new(".")
@@ -2,8 +2,7 @@
2
2
 
3
3
  module Gjp
4
4
  class GeneratePackageArchiveCommand < Gjp::BaseCommand
5
-
6
- parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", :default => "."
5
+ parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", default: "."
7
6
 
8
7
  def execute
9
8
  checking_exceptions do
@@ -2,8 +2,7 @@
2
2
 
3
3
  module Gjp
4
4
  class GeneratePackageScriptCommand < Gjp::BaseCommand
5
-
6
- parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", :default => "."
5
+ parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", default: "."
7
6
 
8
7
  def execute
9
8
  checking_exceptions do
@@ -2,10 +2,9 @@
2
2
 
3
3
  module Gjp
4
4
  class GeneratePackageSpecCommand < Gjp::BaseCommand
5
-
6
- option ["-f", "--filter"], "FILTER", "filter files to be installed by this spec", :default => "*.jar"
7
- parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", :default => "."
8
- parameter "[POM]", "a pom file path", :default => "pom.xml"
5
+ option ["-f", "--filter"], "FILTER", "filter files to be installed by this spec", default: "*.jar"
6
+ parameter "[DIRECTORY]", "path to a package directory (src/<package name>)", default: "."
7
+ parameter "[POM]", "a pom file path", default: "pom.xml"
9
8
 
10
9
  def execute
11
10
  checking_exceptions do
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Gjp
4
4
  class GetPomCommand < Gjp::BaseCommand
5
-
6
5
  parameter "NAME", "a jar file name or a `name-version` string (heuristic)"
7
6
 
8
7
  def execute
@@ -12,18 +11,20 @@ module Gjp
12
11
 
13
12
  path, status = pom_getter.get_pom(name)
14
13
  if path
15
- text_status = if status == :found_in_jar
16
- "was inside the jar"
17
- elsif status == :found_via_sha1
18
- "found by sha1 search from search.maven.org"
19
- elsif status == :found_via_heuristic
20
- "found by heuristic search from search.maven.org"
21
- end
14
+ text_status = (
15
+ if status == :found_in_jar
16
+ "was inside the jar"
17
+ elsif status == :found_via_sha1
18
+ "found by sha1 search from search.maven.org"
19
+ elsif status == :found_via_heuristic
20
+ "found by heuristic search from search.maven.org"
21
+ end
22
+ )
22
23
 
23
24
  puts "#{format_path(path, project)} written, #{text_status}"
24
25
  else
25
26
  puts "#{name}'s pom not found. Try:"
26
- puts "http://google.com/#q=#{URI::encode(pom_getter.cleanup_name(name) + " pom")}"
27
+ puts "http://google.com/#q=#{URI.encode(pom_getter.cleanup_name(name) + " pom")}"
27
28
  end
28
29
  end
29
30
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Gjp
4
4
  class GetSourceCommand < Gjp::BaseCommand
5
-
6
5
  parameter "POM", "a pom file path or URI"
7
6
 
8
7
  def execute
@@ -17,17 +16,17 @@ module Gjp
17
16
  effective_pom_path = Gjp::MavenRunner.new(project).get_effective_pom(pom)
18
17
  puts "Source jar not found in Maven. Try looking here:"
19
18
  pom = Gjp::Pom.new(effective_pom_path)
20
- if pom.url && !pom.url.empty?
19
+ unless pom.url.empty?
21
20
  puts "Website: #{pom.url}"
22
21
  end
23
- if pom.scm_connection && !pom.scm_connection.empty?
22
+ unless pom.scm_connection.empty?
24
23
  puts "SCM connection: #{pom.scm_connection}"
25
24
  end
26
- if pom.scm_url && !pom.scm_url.empty?
25
+ unless pom.scm_url.empty?
27
26
  puts "SCM connection: #{pom.scm_url}"
28
27
  end
29
28
  puts "The effective POM: #{effective_pom_path}"
30
- puts "Google: http://google.com/#q=#{URI::encode(pom.name + " sources")}"
29
+ puts "Google: http://google.com/#q=#{URI.encode(pom.name + " sources")}"
31
30
  end
32
31
  end
33
32
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Gjp
4
4
  class InitCommand < Gjp::BaseCommand
5
-
6
5
  def execute
7
6
  checking_exceptions do
8
7
  Gjp::Project.init(".")
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Gjp
4
4
  class ListKitMissingSourcesCommand < Gjp::BaseCommand
5
-
6
5
  def execute
7
6
  checking_exceptions do
8
7
  project = Gjp::Project.new(".")
@@ -11,7 +10,7 @@ module Gjp
11
10
  ensure_dry_running(false, project) do
12
11
  puts "Some source files were not found in these archives:"
13
12
  kit_checker.unsourced_archives.each do |archive|
14
- percentage = "%.2f" % (100.0 * archive[:unsourced_class_names].length()/archive[:class_names].length())
13
+ percentage = "%.2f" % (100.0 * archive[:unsourced_class_names].length / archive[:class_names].length)
15
14
  puts "#{format_path(archive[:archive], project)} (~#{percentage}% missing)"
16
15
  end
17
16
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Gjp
4
4
  class MoveJarsToKitCommand < Gjp::BaseCommand
5
-
6
5
  def execute
7
6
  checking_exceptions do
8
7
  project = Gjp::Project.new(".")
@@ -2,8 +2,7 @@
2
2
 
3
3
  module Gjp
4
4
  class MavenCommand < Gjp::BaseCommand
5
-
6
- parameter "[MAVEN OPTIONS] ...", "mvn options", :attribute_name => "dummy"
5
+ parameter "[MAVEN OPTIONS] ...", "mvn options", attribute_name: "dummy"
7
6
 
8
7
  # override parsing in order to pipe everything to mvn
9
8
  def parse(args)
data/lib/gjp/git.rb CHANGED
@@ -4,7 +4,7 @@ module Gjp
4
4
  # facade to git, currently implemented with calls to the git command
5
5
  # prefixes all tags with "gjp_"
6
6
  class Git
7
- include Logger
7
+ include Logging
8
8
 
9
9
  # inits a new git manager object pointing to the specified
10
10
  # directory
@@ -15,7 +15,7 @@ module Gjp
15
15
  # inits a repo
16
16
  def init
17
17
  Dir.chdir(@directory) do
18
- if Dir.exists?(".git") == false
18
+ if Dir.exist?(".git") == false
19
19
  `git init`
20
20
  else
21
21
  raise GitAlreadyInitedError
@@ -34,11 +34,13 @@ module Gjp
34
34
  def changed_files_between(start_tag, end_tag, directory)
35
35
  Dir.chdir(@directory) do
36
36
  prefixed_start_tag = "gjp_#{start_tag}"
37
- prefixed_end_tag = if end_tag
38
- "gjp_#{end_tag}"
39
- else
40
- "HEAD"
41
- end
37
+ prefixed_end_tag = (
38
+ if end_tag
39
+ "gjp_#{end_tag}"
40
+ else
41
+ "HEAD"
42
+ end
43
+ )
42
44
  `git diff-tree --no-commit-id --name-only -r #{prefixed_start_tag} #{prefixed_end_tag} -- #{directory}`
43
45
  .split("\n")
44
46
  end
@@ -63,8 +65,8 @@ module Gjp
63
65
  `git add .`
64
66
  `git commit -m "#{message}"`
65
67
 
66
- if tag != nil
67
- if tag_message != nil
68
+ unless tag.nil?
69
+ if !tag_message.nil?
68
70
  `git tag gjp_#{tag} -m "#{tag_message}"`
69
71
  else
70
72
  `git tag gjp_#{tag}`
@@ -77,11 +79,11 @@ module Gjp
77
79
  def get_tag_maximum_suffix(prefix)
78
80
  Dir.chdir(@directory) do
79
81
  `git tag`.split.map do |tag|
80
- if tag =~ /^gjp_#{prefix}_([0-9]+)$/
81
- $1.to_i
82
- else
83
- 0
84
- end
82
+ if tag =~ /^gjp_#{prefix}_([0-9]+)$/
83
+ Regexp.last_match[1].to_i
84
+ else
85
+ 0
86
+ end
85
87
  end.max || 0
86
88
  end
87
89
  end
@@ -6,9 +6,9 @@ require "zip"
6
6
  module Gjp
7
7
  # checks kits for errors
8
8
  class KitChecker
9
- include Logger
9
+ include Logging
10
10
 
11
- def initialize(project)
11
+ def initialize(project)
12
12
  @project = project
13
13
  end
14
14
 
@@ -45,14 +45,14 @@ module Gjp
45
45
  path =~ /\.java$/
46
46
  end
47
47
 
48
- # heuristically add all possible package names, walking
48
+ # heuristically add all possible package names, walking
49
49
  # back the directory tree all the way back to root.
50
50
  # This could add non-existent names, but allows not looking
51
51
  # in the file at all
52
52
  class_names = source_paths.map do |path, archive|
53
53
  class_name = path_to_class(path)
54
54
  parts = class_name.split(".")
55
- last_index = parts.length() -1
55
+ last_index = parts.length - 1
56
56
  (0..last_index).map do |i|
57
57
  parts[i..last_index].join(".")
58
58
  end
@@ -69,7 +69,7 @@ module Gjp
69
69
  path =~ /\.class$/
70
70
  end.each do |path, archive|
71
71
  class_name = path_to_class(path)
72
- if result[archive] == nil
72
+ if result[archive].nil?
73
73
  result[archive] = [class_name]
74
74
  else
75
75
  result[archive] << class_name
@@ -90,7 +90,7 @@ module Gjp
90
90
  unsourced_class_names = class_names.select do |class_name|
91
91
  source_class_names.include?(class_name) == false
92
92
  end
93
- {:archive => archive, :class_names => class_names, :unsourced_class_names => unsourced_class_names}
93
+ { archive: archive, class_names: class_names, unsourced_class_names: unsourced_class_names }
94
94
  end.select do |archive|
95
95
  archive[:unsourced_class_names].any?
96
96
  end
@@ -6,9 +6,9 @@ require "pathname"
6
6
  module Gjp
7
7
  # runs programs from a gjp kit with gjp-specific options
8
8
  class KitRunner
9
- include Logger
9
+ include Logging
10
10
 
11
- def initialize(project)
11
+ def initialize(project)
12
12
  @project = project
13
13
  end
14
14
 
@@ -1,4 +1,4 @@
1
- # encoding: UTF-8
1
+ # encoding: UTF-8
2
2
 
3
3
  module Gjp
4
4
  # encapsulates details of a kit needed by the spec file
@@ -26,4 +26,3 @@ module Gjp
26
26
  end
27
27
  end
28
28
  end
29
-
data/lib/gjp/logger.rb CHANGED
@@ -1,27 +1,30 @@
1
1
  # encoding: UTF-8
2
2
 
3
+ require "singleton"
4
+ require "forwardable"
3
5
  require "logger"
4
6
 
5
7
  module Gjp
6
- module Logger
7
- @@logger = nil
8
+ class Logger
9
+ include Singleton
10
+ extend Forwardable
8
11
 
9
- # returns a logger instance
10
- def self.log
11
- if @@logger == nil
12
- @@logger = ::Logger.new(STDERR)
13
- @@logger.datetime_format = "%Y-%m-%d %H:%M "
14
- @@logger.level = ::Logger::ERROR
15
- @@logger.formatter = proc do |severity, datetime, progname, msg|
16
- "#{severity.chars.first}: #{msg}\n"
17
- end
12
+ def_delegators :@logger, :debug, :info, :warn, :error, :fatal, :level=
13
+
14
+ def initialize
15
+ @logger = ::Logger.new(STDERR)
16
+ @logger.datetime_format = "%Y-%m-%d %H:%M "
17
+ @logger.level = ::Logger::ERROR
18
+ @logger.formatter = proc do |severity, datetime, progname, msg|
19
+ "#{severity.chars.first}: #{msg}\n"
18
20
  end
19
- @@logger
20
21
  end
22
+ end
21
23
 
24
+ module Logging
22
25
  # convenience instance method
23
26
  def log
24
- Gjp::Logger.log
27
+ Gjp::Logger.instance
25
28
  end
26
29
  end
27
30
  end
data/lib/gjp/main.rb CHANGED
@@ -3,7 +3,6 @@ require "clamp"
3
3
 
4
4
  module Gjp
5
5
  class MainCommand < Clamp::Command
6
-
7
6
  subcommand(
8
7
  "init",
9
8
  "Inits a gjp project in the current directory",
@@ -3,7 +3,7 @@
3
3
  module Gjp
4
4
  # runs Maven with gjp-specific options
5
5
  class MavenRunner < KitRunner
6
- include Logger
6
+ include Logging
7
7
 
8
8
  # runs Maven in a subprocess
9
9
  def mvn(options)
@@ -33,7 +33,7 @@ module Gjp
33
33
  def get_maven_commandline(prefix, options)
34
34
  executable = find_executable("mvn")
35
35
 
36
- if executable != nil
36
+ if !executable.nil?
37
37
  mvn_path = File.join(prefix, executable)
38
38
  repo_path = File.join(prefix, "kit", "m2")
39
39
  config_path = File.join(prefix, "kit", "m2", "settings.xml")
@@ -4,58 +4,58 @@ require "text"
4
4
 
5
5
  module Gjp
6
6
  # Facade to search.maven.org
7
- class MavenWebsite
8
- include Logger
7
+ class MavenWebsite
8
+ include Logging
9
9
 
10
10
  # returns a search result object from search.maven.com
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
+ 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
+ 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
+ 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
+ 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",
42
- :params => params.merge("rows" => "100", "wt" => "json")
43
- )
44
- json = JSON.parse(response.to_s)
45
- return json["response"]["docs"]
41
+ response = RestClient.get("http://search.maven.org/solrsearch/select",
42
+ params: params.merge("rows" => "100", "wt" => "json")
43
+ )
44
+ json = JSON.parse(response.to_s)
45
+ json["response"]["docs"]
46
46
  end
47
47
 
48
48
  # returns a Maven's triple (artifactId, groupId, version)
49
49
  # from a result object
50
50
  def get_maven_id_from(result)
51
- return result["g"], result["a"], result["v"]
51
+ [result["g"], result["a"], result["v"]]
52
52
  end
53
-
53
+
54
54
  # downloads a POM from a search.maven.com search result
55
55
  def download_pom(group_id, artifact_id, version)
56
56
  path = "#{group_id.gsub(".", "/")}/#{artifact_id}/#{version}/#{artifact_id}-#{version}.pom"
57
57
  log.debug("downloading #{path}...")
58
- return (RestClient.get "http://search.maven.org/remotecontent", :params => {:filepath => path}).to_s
58
+ (RestClient.get "http://search.maven.org/remotecontent", params: { filepath: path }).to_s
59
59
  end
60
60
  end
61
61
  end