gjp 0.37.0 → 0.38.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +0 -130
- data/Rakefile +2 -2
- data/gjp.gemspec +2 -2
- data/integration-tests/commons.sh +1 -1
- data/lib/gjp.rb +12 -12
- data/lib/gjp/ant_runner.rb +2 -2
- data/lib/gjp/archiver.rb +13 -11
- data/lib/gjp/commands/ant.rb +1 -1
- data/lib/gjp/commands/base.rb +25 -26
- data/lib/gjp/commands/{download-maven-source-jars.rb → download_maven_source_jars.rb} +0 -0
- data/lib/gjp/commands/{dry-run.rb → dry_run.rb} +0 -0
- data/lib/gjp/commands/finish.rb +0 -1
- data/lib/gjp/commands/{generate-all.rb → generate_all.rb} +3 -4
- data/lib/gjp/commands/{generate-kit-archive.rb → generate_kit_archive.rb} +0 -1
- data/lib/gjp/commands/{generate-kit-spec.rb → generate_kit_spec.rb} +0 -1
- data/lib/gjp/commands/{generate-package-archive.rb → generate_package_archive.rb} +1 -2
- data/lib/gjp/commands/{generate-package-script.rb → generate_package_script.rb} +1 -2
- data/lib/gjp/commands/{generate-package-spec.rb → generate_package_spec.rb} +3 -4
- data/lib/gjp/commands/{get-pom.rb → get_pom.rb} +10 -9
- data/lib/gjp/commands/{get-source.rb → get_source.rb} +4 -5
- data/lib/gjp/commands/init.rb +0 -1
- data/lib/gjp/commands/{list-kit-missing-sources.rb → list_kit_missing_sources.rb} +1 -2
- data/lib/gjp/commands/{move-jars-to-kit.rb → move_jars_to_kit.rb} +0 -1
- data/lib/gjp/commands/mvn.rb +1 -2
- data/lib/gjp/git.rb +16 -14
- data/lib/gjp/kit_checker.rb +6 -6
- data/lib/gjp/kit_runner.rb +2 -2
- data/lib/gjp/kit_spec_adapter.rb +1 -2
- data/lib/gjp/logger.rb +16 -13
- data/lib/gjp/main.rb +0 -1
- data/lib/gjp/maven_runner.rb +2 -2
- data/lib/gjp/maven_website.rb +14 -14
- data/lib/gjp/package_spec_adapter.rb +9 -8
- data/lib/gjp/pom.rb +13 -14
- data/lib/gjp/pom_getter.rb +18 -16
- data/lib/gjp/project.rb +21 -22
- data/lib/gjp/script_generator.rb +8 -8
- data/lib/gjp/source_getter.rb +3 -3
- data/lib/gjp/spec_generator.rb +3 -3
- data/lib/gjp/template_manager.rb +2 -2
- data/lib/gjp/version.rb +1 -1
- data/lib/gjp/version_matcher.rb +32 -35
- data/spec/lib/archiver_spec.rb +3 -3
- data/spec/lib/git_spec.rb +1 -1
- data/spec/lib/kit_checker_spec.rb +10 -10
- data/spec/lib/pom_getter_spec.rb +2 -3
- data/spec/lib/pom_spec.rb +2 -3
- data/spec/lib/project_spec.rb +10 -10
- data/spec/lib/script_generator_spec.rb +1 -2
- data/spec/lib/source_getter_spec.rb +0 -1
- data/spec/lib/spec_generator_spec.rb +0 -1
- data/spec/lib/template_manager_spec.rb +1 -1
- data/spec/lib/version_matcher_spec.rb +8 -9
- data/spec/spec_helper.rb +0 -3
- metadata +13 -13
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# encoding: UTF-8
|
2
2
|
|
3
3
|
module Gjp
|
4
4
|
# encapsulates details of a package needed by the spec file
|
@@ -21,11 +21,13 @@ module Gjp
|
|
21
21
|
def initialize(project, package_name, pom, filter)
|
22
22
|
@name = package_name
|
23
23
|
@version = pom.version
|
24
|
-
@license =
|
25
|
-
pom.license_name
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
@license = (
|
25
|
+
if pom.license_name != ""
|
26
|
+
pom.license_name
|
27
|
+
else
|
28
|
+
"Apache-2.0"
|
29
|
+
end
|
30
|
+
)
|
29
31
|
@summary = cleanup_description(pom.description, 60)
|
30
32
|
@url = pom.url
|
31
33
|
@project_name = project.name
|
@@ -49,10 +51,9 @@ module Gjp
|
|
49
51
|
raw
|
50
52
|
.gsub(/[\s]+/, " ")
|
51
53
|
.strip
|
52
|
-
.slice(0..max_length -1)
|
54
|
+
.slice(0..max_length - 1)
|
53
55
|
.sub(/\s\w+$/, "")
|
54
56
|
.sub(/\.+$/, "")
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
58
|
-
|
data/lib/gjp/pom.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# encoding: UTF-8
|
2
2
|
|
3
3
|
require "nokogiri"
|
4
4
|
require "open-uri"
|
@@ -10,33 +10,33 @@ module Gjp
|
|
10
10
|
@doc = Nokogiri::XML(open(filename).read)
|
11
11
|
@doc.remove_namespaces!
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def group_id
|
15
|
-
@doc.xpath("project/groupId").text
|
15
|
+
@doc.xpath("project/groupId").text || ""
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def artifact_id
|
19
|
-
@doc.xpath("project/artifactId").text
|
19
|
+
@doc.xpath("project/artifactId").text || ""
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def name
|
23
|
-
@doc.xpath("project/name").text
|
23
|
+
@doc.xpath("project/name").text || ""
|
24
24
|
end
|
25
25
|
|
26
26
|
def version
|
27
|
-
@doc.xpath("project/version").text
|
27
|
+
@doc.xpath("project/version").text || ""
|
28
28
|
end
|
29
29
|
|
30
30
|
def description
|
31
|
-
@doc.xpath("project/description").text
|
31
|
+
@doc.xpath("project/description").text || ""
|
32
32
|
end
|
33
33
|
|
34
34
|
def url
|
35
|
-
@doc.xpath("project/url").text
|
35
|
+
@doc.xpath("project/url").text || ""
|
36
36
|
end
|
37
37
|
|
38
38
|
def license_name
|
39
|
-
@doc.xpath("project/licenses/license/name").text
|
39
|
+
@doc.xpath("project/licenses/license/name").text || ""
|
40
40
|
end
|
41
41
|
|
42
42
|
def runtime_dependency_ids
|
@@ -48,12 +48,11 @@ module Gjp
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def scm_connection
|
51
|
-
@doc.xpath("project/scm/connection").text
|
51
|
+
@doc.xpath("project/scm/connection").text || ""
|
52
52
|
end
|
53
53
|
|
54
54
|
def scm_url
|
55
|
-
@doc.xpath("project/scm/url").text
|
55
|
+
@doc.xpath("project/scm/url").text || ""
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
data/lib/gjp/pom_getter.rb
CHANGED
@@ -11,7 +11,7 @@ require "gjp/version_matcher"
|
|
11
11
|
module Gjp
|
12
12
|
# attempts to get java projects' pom file
|
13
13
|
class PomGetter
|
14
|
-
include
|
14
|
+
include Logging
|
15
15
|
|
16
16
|
# saves a jar poms in <jar_filename>.pom
|
17
17
|
# returns filename and status if found, else nil
|
@@ -39,9 +39,9 @@ module Gjp
|
|
39
39
|
rescue TypeError
|
40
40
|
log.warn("#{file} seems to be a valid jar archive but is corrupt, skipping")
|
41
41
|
end
|
42
|
-
|
42
|
+
nil
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
# returns a pom from search.maven.org with a jar sha1 search
|
46
46
|
def get_pom_from_sha1(file)
|
47
47
|
log.debug("Attempting SHA1 POM lookup for #{file}")
|
@@ -49,9 +49,9 @@ module Gjp
|
|
49
49
|
if File.file?(file)
|
50
50
|
site = MavenWebsite.new
|
51
51
|
sha1 = Digest::SHA1.hexdigest File.read(file)
|
52
|
-
results = site.search_by_sha1(sha1).select {|result| result["ec"].include?(".pom")}
|
53
|
-
result = results.first
|
54
|
-
|
52
|
+
results = site.search_by_sha1(sha1).select { |result| result["ec"].include?(".pom") }
|
53
|
+
result = results.first
|
54
|
+
unless result.nil?
|
55
55
|
log.info("pom.xml for #{file} found on search.maven.org for sha1 #{sha1}\
|
56
56
|
(#{result["g"]}:#{result["a"]}:#{result["v"]})"
|
57
57
|
)
|
@@ -77,23 +77,25 @@ module Gjp
|
|
77
77
|
|
78
78
|
result = site.search_by_name(my_artifact_id).first
|
79
79
|
log.debug("Artifact id search result: #{result}")
|
80
|
-
|
80
|
+
unless result.nil?
|
81
81
|
group_id, artifact_id, version = site.get_maven_id_from result
|
82
82
|
results = site.search_by_group_id_and_artifact_id(group_id, artifact_id)
|
83
83
|
log.debug("All versions: #{results}")
|
84
|
-
their_versions = results.map {|doc| doc["v"]}
|
85
|
-
best_matched_version =
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
84
|
+
their_versions = results.map { |doc| doc["v"] }
|
85
|
+
best_matched_version = (
|
86
|
+
if !my_version.nil?
|
87
|
+
version_matcher.best_match(my_version, their_versions)
|
88
|
+
else
|
89
|
+
their_versions.max
|
90
|
+
end
|
91
|
+
)
|
92
|
+
best_matched_result = (results.select { |result| result["v"] == best_matched_version }).first
|
93
|
+
|
92
94
|
group_id, artifact_id, version = site.get_maven_id_from(best_matched_result)
|
93
95
|
log.warn("pom.xml for #{filename} found on search.maven.org with heuristic search\
|
94
96
|
(#{group_id}:#{artifact_id}:#{version})"
|
95
97
|
)
|
96
|
-
|
98
|
+
|
97
99
|
return site.download_pom(group_id, artifact_id, version), :found_via_heuristic
|
98
100
|
end
|
99
101
|
rescue RestClient::ResourceNotFound
|
data/lib/gjp/project.rb
CHANGED
@@ -5,12 +5,12 @@ require "find"
|
|
5
5
|
module Gjp
|
6
6
|
# encapsulates a Gjp project directory
|
7
7
|
class Project
|
8
|
-
include
|
8
|
+
include Logging
|
9
9
|
|
10
10
|
attr_accessor :full_path
|
11
11
|
attr_accessor :git
|
12
12
|
|
13
|
-
def initialize(path)
|
13
|
+
def initialize(path)
|
14
14
|
@full_path = Gjp::Project.find_project_dir(File.expand_path(path))
|
15
15
|
@git = Gjp::Git.new(@full_path)
|
16
16
|
end
|
@@ -45,20 +45,17 @@ module Gjp
|
|
45
45
|
# returns the package name corresponding to the specified dir, if any
|
46
46
|
# raises NoPackageDirectoryError if dir is not a (sub)directory of a package
|
47
47
|
def get_package_name(dir)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
rescue ArgumentError, NoProjectDirectoryError
|
60
|
-
raise NoPackageDirectoryError.new(dir)
|
61
|
-
end
|
48
|
+
dir_path = Pathname.new(File.expand_path(dir)).relative_path_from(Pathname.new(@full_path))
|
49
|
+
components = dir_path.to_s.split(File::SEPARATOR)
|
50
|
+
if components.count >= 2 &&
|
51
|
+
components.first == "src" &&
|
52
|
+
Dir.exist?(File.join(@full_path, components[0], components[1]))
|
53
|
+
components[1]
|
54
|
+
else
|
55
|
+
raise NoPackageDirectoryError
|
56
|
+
end
|
57
|
+
rescue ArgumentError, NoProjectDirectoryError
|
58
|
+
raise NoPackageDirectoryError.new(dir)
|
62
59
|
end
|
63
60
|
|
64
61
|
# inits a new project directory structure
|
@@ -123,11 +120,13 @@ module Gjp
|
|
123
120
|
|
124
121
|
# takes a revertable snapshot of this project
|
125
122
|
def take_snapshot(message, tag_prefix = nil, tag_message = nil)
|
126
|
-
tag =
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
123
|
+
tag = (
|
124
|
+
if tag_prefix
|
125
|
+
"#{tag_prefix}_#{latest_tag_count(tag_prefix) + 1}"
|
126
|
+
else
|
127
|
+
nil
|
128
|
+
end
|
129
|
+
)
|
131
130
|
|
132
131
|
@git.commit_whole_directory(message, tag, tag_message)
|
133
132
|
end
|
@@ -208,7 +207,7 @@ module Gjp
|
|
208
207
|
end
|
209
208
|
|
210
209
|
# moves any .jar from src/ to kit/ and links it back
|
211
|
-
def purge_jars
|
210
|
+
def purge_jars
|
212
211
|
from_directory do
|
213
212
|
result = []
|
214
213
|
Find.find("src") do |file|
|
data/lib/gjp/script_generator.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module Gjp
|
4
4
|
# generates build scripts from bash_history
|
5
5
|
class ScriptGenerator
|
6
|
-
include
|
6
|
+
include Logging
|
7
7
|
|
8
8
|
def initialize(project, history_path)
|
9
9
|
@project = project
|
@@ -11,17 +11,17 @@ module Gjp
|
|
11
11
|
@maven_runner = Gjp::MavenRunner.new(project)
|
12
12
|
@history_path = history_path
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def generate_build_script(name)
|
16
16
|
@project.from_directory do
|
17
17
|
history_lines = File.readlines(@history_path).map { |e| e.strip }
|
18
18
|
relevant_lines =
|
19
19
|
history_lines
|
20
20
|
.reverse
|
21
|
-
.take_while { |e| e.match(/gjp +dry-run/)
|
21
|
+
.take_while { |e| e.match(/gjp +dry-run/).nil? }
|
22
22
|
.reverse
|
23
|
-
.take_while { |e| e.match(/gjp +finish/)
|
24
|
-
.select { |e| e.match(/^#/)
|
23
|
+
.take_while { |e| e.match(/gjp +finish/).nil? }
|
24
|
+
.select { |e| e.match(/^#/).nil? }
|
25
25
|
|
26
26
|
script_lines = [
|
27
27
|
"#!/bin/bash",
|
@@ -42,13 +42,13 @@ 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",
|
45
|
+
conflict_count = @project.merge_new_content(new_content, result_path, "Build script generated",
|
46
46
|
"generate_#{name}_build_script")
|
47
47
|
|
48
48
|
destination_dir = File.join("output", name)
|
49
49
|
FileUtils.mkdir_p(destination_dir)
|
50
|
-
destination_script_path = File.join(destination_dir, script_name)
|
51
|
-
FileUtils.symlink(File.expand_path(result_path), destination_script_path, :
|
50
|
+
destination_script_path = File.join(destination_dir, script_name)
|
51
|
+
FileUtils.symlink(File.expand_path(result_path), destination_script_path, force: true)
|
52
52
|
|
53
53
|
[result_path, conflict_count]
|
54
54
|
end
|
data/lib/gjp/source_getter.rb
CHANGED
@@ -5,7 +5,7 @@ require "rest_client"
|
|
5
5
|
module Gjp
|
6
6
|
# attempts to get java projects' sources
|
7
7
|
class SourceGetter
|
8
|
-
include
|
8
|
+
include Logging
|
9
9
|
|
10
10
|
# attempts to download a project's sources
|
11
11
|
def get_maven_source_jar(project, pom_path)
|
@@ -20,7 +20,7 @@ module Gjp
|
|
20
20
|
maven_runner = Gjp::MavenRunner.new(project)
|
21
21
|
|
22
22
|
project.from_directory do
|
23
|
-
paths = Find.find(".").reject {|path| artifact_from_path(path)
|
23
|
+
paths = Find.find(".").reject { |path| artifact_from_path(path).nil? }.sort
|
24
24
|
|
25
25
|
succeded_paths = paths.select.with_index do |path, i|
|
26
26
|
group_id, artifact_id, version = artifact_from_path(path)
|
@@ -37,7 +37,7 @@ module Gjp
|
|
37
37
|
# if possible, turn path into a Maven artifact name, otherwise return nil
|
38
38
|
def artifact_from_path(path)
|
39
39
|
match = path.match(/\.\/kit\/m2\/(.+)\/(.+)\/(.+)\/\2-\3.*\.jar$/)
|
40
|
-
|
40
|
+
unless match.nil?
|
41
41
|
[match[1].gsub("/", "."), match[2], match[3]]
|
42
42
|
end
|
43
43
|
end
|
data/lib/gjp/spec_generator.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module Gjp
|
4
4
|
# creates and updates spec files
|
5
5
|
class SpecGenerator
|
6
|
-
include
|
6
|
+
include Logging
|
7
7
|
|
8
8
|
def initialize(project)
|
9
9
|
@project = project
|
@@ -47,14 +47,14 @@ module Gjp
|
|
47
47
|
# generates a spec file from a template and 3-way merges it
|
48
48
|
def generate_merging(template, binding, path, tag_prefix)
|
49
49
|
new_content = TemplateManager.new.generate(template, binding)
|
50
|
-
@project.merge_new_content(new_content, path, "Spec generated", tag_prefix)
|
50
|
+
@project.merge_new_content(new_content, path, "Spec generated", tag_prefix)
|
51
51
|
end
|
52
52
|
|
53
53
|
# links a spec file in a subdirectory of output/
|
54
54
|
def symlink_to_output(spec_path, destination_dir)
|
55
55
|
spec_name = Pathname.new(spec_path).basename.to_s
|
56
56
|
destination_spec_path = File.join(destination_dir, spec_name)
|
57
|
-
FileUtils.symlink(File.expand_path(spec_path), destination_spec_path, :
|
57
|
+
FileUtils.symlink(File.expand_path(spec_path), destination_spec_path, force: true)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
data/lib/gjp/template_manager.rb
CHANGED
@@ -5,7 +5,7 @@ require "erb"
|
|
5
5
|
module Gjp
|
6
6
|
# operates on files in template/
|
7
7
|
class TemplateManager
|
8
|
-
include
|
8
|
+
include Logging
|
9
9
|
|
10
10
|
attr_reader :template_path
|
11
11
|
|
@@ -25,7 +25,7 @@ module Gjp
|
|
25
25
|
erb = ERB.new File.read(File.join(template_path, template_name)), nil, "<>"
|
26
26
|
new_content = erb.result(object_binding)
|
27
27
|
|
28
|
-
|
28
|
+
unless destination_path.nil?
|
29
29
|
File.open(destination_path, "w") { |io| io.write new_content }
|
30
30
|
end
|
31
31
|
|
data/lib/gjp/version.rb
CHANGED
data/lib/gjp/version_matcher.rb
CHANGED
@@ -4,23 +4,23 @@ require "text"
|
|
4
4
|
|
5
5
|
module Gjp
|
6
6
|
# heuristically matches version strings
|
7
|
-
class VersionMatcher
|
8
|
-
include
|
7
|
+
class VersionMatcher
|
8
|
+
include Logging
|
9
9
|
|
10
|
-
|
10
|
+
# heuristically splits a full name into an artifact name and version string
|
11
11
|
# assumes that version strings begin with a numeric character and are separated
|
12
12
|
# by a ., -, _, ~ or space
|
13
13
|
# returns a [name, version] pair
|
14
|
-
|
14
|
+
def split_version(full_name)
|
15
15
|
matches = full_name.match(/(.*?)(?:[\.\-\_ ~,]?([0-9].*))?$/)
|
16
|
-
if matches
|
16
|
+
if !matches.nil? && matches.length > 1
|
17
17
|
[matches[1], matches[2]]
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
else
|
19
|
+
[full_string, nil]
|
20
|
+
end
|
21
|
+
end
|
22
22
|
|
23
|
-
|
23
|
+
# returns the "best match" between a version number and a set of available version numbers
|
24
24
|
# using a heuristic criterion. Idea:
|
25
25
|
# - split the version number in chunks divided by ., - etc.
|
26
26
|
# - every chunk with same index is "compared", differences make up a score
|
@@ -29,57 +29,55 @@ module Gjp
|
|
29
29
|
# - lowest score wins
|
30
30
|
def best_match(my_version, their_versions)
|
31
31
|
log.debug("version comparison: #{my_version} vs #{their_versions.join(", ")}")
|
32
|
-
|
32
|
+
|
33
33
|
my_chunks = my_version.split(/[\.\-\_ ~,]/)
|
34
34
|
their_chunks_hash = Hash[
|
35
35
|
their_versions.map do |their_version|
|
36
|
-
their_chunks_for_version =
|
37
|
-
their_version.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
their_chunks_for_version = (
|
37
|
+
if !their_version.nil?
|
38
|
+
their_version.split(/[\.\-\_ ~,]/)
|
39
|
+
else
|
40
|
+
[]
|
41
|
+
end
|
42
|
+
)
|
43
|
+
their_chunks_for_version += [nil] * [my_chunks.length - their_chunks_for_version.length, 0].max
|
42
44
|
[their_version, their_chunks_for_version]
|
43
45
|
end
|
44
46
|
]
|
45
|
-
|
46
|
-
max_chunks_length = ([my_chunks.length] + their_chunks_hash.values.map {|chunk| chunk.length}).max
|
47
|
-
|
47
|
+
|
48
|
+
max_chunks_length = ([my_chunks.length] + their_chunks_hash.values.map { |chunk| chunk.length }).max
|
49
|
+
|
48
50
|
scoreboard = []
|
49
51
|
their_versions.each do |their_version|
|
50
52
|
their_chunks = their_chunks_hash[their_version]
|
51
53
|
score = 0
|
52
54
|
their_chunks.each_with_index do |their_chunk, i|
|
53
|
-
score_multiplier = 100**(max_chunks_length -i -1)
|
55
|
+
score_multiplier = 100**(max_chunks_length - i - 1)
|
54
56
|
my_chunk = my_chunks[i]
|
55
57
|
score += chunk_distance(my_chunk, their_chunk) * score_multiplier
|
56
58
|
end
|
57
|
-
scoreboard << {:
|
59
|
+
scoreboard << { version: their_version, score: score }
|
58
60
|
end
|
59
|
-
|
60
|
-
scoreboard = scoreboard.sort_by {|element| element[:score]}
|
61
|
+
|
62
|
+
scoreboard = scoreboard.sort_by { |element| element[:score] }
|
61
63
|
|
62
64
|
log.debug("scoreboard: ")
|
63
65
|
scoreboard.each_with_index do |element, i|
|
64
|
-
log.debug(" #{i+1}. #{element[:version]} (score: #{element[:score]})")
|
65
|
-
end
|
66
|
-
|
67
|
-
winner = scoreboard.first
|
68
|
-
|
69
|
-
if winner != nil
|
70
|
-
return winner[:version]
|
66
|
+
log.debug(" #{i + 1}. #{element[:version]} (score: #{element[:score]})")
|
71
67
|
end
|
68
|
+
|
69
|
+
return scoreboard.first[:version] unless scoreboard.first.nil?
|
72
70
|
end
|
73
|
-
|
71
|
+
|
74
72
|
# returns a score representing the distance between two version chunks
|
75
73
|
# for integers, the score is the difference between their values
|
76
74
|
# for strings, the score is the Levenshtein distance
|
77
75
|
# in any case score is normalized between 0 (identical) and 99 (very different/uncomparable)
|
78
76
|
def chunk_distance(my_chunk, their_chunk)
|
79
|
-
if my_chunk
|
77
|
+
if my_chunk.nil?
|
80
78
|
my_chunk = "0"
|
81
79
|
end
|
82
|
-
if their_chunk
|
80
|
+
if their_chunk.nil?
|
83
81
|
their_chunk = "0"
|
84
82
|
end
|
85
83
|
if my_chunk.is_i? && their_chunk.is_i?
|
@@ -89,7 +87,6 @@ module Gjp
|
|
89
87
|
end
|
90
88
|
end
|
91
89
|
end
|
92
|
-
|
93
90
|
end
|
94
91
|
|
95
92
|
class String
|