code_clone_detector 0.1.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/CHANGELOG.md +10 -1
- data/README.md +4 -1
- data/code_clone_detector.gemspec +1 -1
- data/exe/code_clone_detector +102 -0
- data/lib/code_clone_detector/hello.rb +2 -0
- data/lib/code_clone_detector/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3ad9bbb37d394ff8d6c7889f97bcaeeea88438aa2edd034b531247403b066ae
|
4
|
+
data.tar.gz: 010efab64699e544f7f3ae01cd631321225a814f4746dd970ecb4a696987680f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc5b19b19e2b553a057cb057f9798914e0ef96c8607067cca8a37d82bef053b8299fe86b56a01bb3996dda122b9bd4f3754fb2fb6d8ba967f1222bfcf618227c
|
7
|
+
data.tar.gz: b5111df9e521e4dc3be5ad0de6e1011063b1db375719c5e05bc1396c82a7387f2cab1827ce9bfaa55cca8d882730698e0d15f32d70f8963ad00a61c5f8f2a6a3
|
data/.rubocop.yml
CHANGED
@@ -5,9 +5,15 @@ Style/StringLiterals:
|
|
5
5
|
Enabled: true
|
6
6
|
EnforcedStyle: double_quotes
|
7
7
|
|
8
|
+
Documentation:
|
9
|
+
Enabled: false
|
10
|
+
|
8
11
|
Style/StringLiteralsInInterpolation:
|
9
12
|
Enabled: true
|
10
13
|
EnforcedStyle: double_quotes
|
11
14
|
|
12
15
|
Layout/LineLength:
|
13
16
|
Max: 120
|
17
|
+
|
18
|
+
Metrics/BlockLength:
|
19
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
|
-
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [1.0.1] - 2023-03-07
|
4
|
+
|
5
|
+
- Fix bug in specifying the array index
|
6
|
+
|
7
|
+
## [1.0.0] - 2023-03-07
|
8
|
+
|
9
|
+
- Add function to detect code clone
|
2
10
|
|
3
11
|
## [0.1.0] - 2023-03-04
|
4
12
|
|
5
13
|
- Initial release
|
14
|
+
- Add function that returns hello world
|
data/README.md
CHANGED
@@ -22,8 +22,11 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
Execute as:
|
26
26
|
|
27
|
+
$ bundle exec code_clone_detector
|
28
|
+
|
29
|
+
You can detect the largest code clone.
|
27
30
|
## Development
|
28
31
|
|
29
32
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/code_clone_detector.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
24
24
|
end
|
25
25
|
spec.bindir = "exe"
|
26
|
-
spec.executables =
|
26
|
+
spec.executables = ["code_clone_detector"]
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
29
|
# Uncomment to register a new dependency of your gem
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "code_clone_detector"
|
5
|
+
|
6
|
+
require "ripper"
|
7
|
+
|
8
|
+
code = []
|
9
|
+
|
10
|
+
Dir.glob("**/*") do |item|
|
11
|
+
if item.include?(".rb")
|
12
|
+
File.open(item, "r") do |f|
|
13
|
+
tmp = f.read
|
14
|
+
code.push([item.to_s, Ripper.lex(tmp)])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
max = 0
|
20
|
+
sx = 0
|
21
|
+
ex = 0
|
22
|
+
sy = 0
|
23
|
+
ey = 0
|
24
|
+
index1 = 0
|
25
|
+
index2 = 0
|
26
|
+
|
27
|
+
(0..code.size - 2).each do |a|
|
28
|
+
(a + 1..code.size - 1).each do |b|
|
29
|
+
array = []
|
30
|
+
|
31
|
+
x = 0
|
32
|
+
|
33
|
+
code[a][1].each do |i|
|
34
|
+
array.push([])
|
35
|
+
code[b][1].each do |j|
|
36
|
+
if i[2] == j[2]
|
37
|
+
array[x].push(1)
|
38
|
+
else
|
39
|
+
array[x].push(0)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
x += 1
|
43
|
+
end
|
44
|
+
|
45
|
+
tmp_max = 0
|
46
|
+
tmp_sx = 0
|
47
|
+
tmp_ex = 0
|
48
|
+
tmp_sy = 0
|
49
|
+
tmp_ey = 0
|
50
|
+
|
51
|
+
array.size.times do |i|
|
52
|
+
array[i].size.times do |j|
|
53
|
+
next unless array[i - 1][j - 1].nil? || array[i - 1][j - 1].zero?
|
54
|
+
next unless array[i][j] == 1
|
55
|
+
|
56
|
+
maxv = 1
|
57
|
+
x = j
|
58
|
+
y = i
|
59
|
+
while !array[y + 1].nil? && !array[y + 1][x + 1].nil? && array[y + 1][x + 1] == 1
|
60
|
+
maxv += 1
|
61
|
+
x += 1
|
62
|
+
y += 1
|
63
|
+
end
|
64
|
+
next unless maxv > tmp_max
|
65
|
+
|
66
|
+
tmp_max = maxv
|
67
|
+
tmp_sx = j
|
68
|
+
tmp_ex = x
|
69
|
+
tmp_sy = i
|
70
|
+
tmp_ey = y
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
next unless tmp_max > max
|
75
|
+
|
76
|
+
max = tmp_max
|
77
|
+
sx = tmp_sx
|
78
|
+
ex = tmp_ex
|
79
|
+
sy = tmp_sy
|
80
|
+
ey = tmp_ey
|
81
|
+
index1 = a
|
82
|
+
index2 = b
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
file_1_name = code[index1][0]
|
87
|
+
file1 = code[index1][1]
|
88
|
+
file_2_name = code[index2][0]
|
89
|
+
file2 = code[index2][1]
|
90
|
+
print "#{file_1_name}:"
|
91
|
+
print "#{file1[sy][0][0]},#{file1[sy][0][1]} ~ #{file1[ey][0][0]},#{file1[ey][0][1]}\n"
|
92
|
+
code[1][1][sy..ey].transpose[2].each do |i|
|
93
|
+
print i
|
94
|
+
end
|
95
|
+
|
96
|
+
puts "===============================\n\n"
|
97
|
+
|
98
|
+
print "#{file_2_name}:"
|
99
|
+
print "#{file2[sx][0][0]},#{file2[sx][0][1]} ~ #{file2[ex][0][0]},#{file2[ex][0][1]}\n"
|
100
|
+
code[3][1][sx..ex].transpose[2].each do |i|
|
101
|
+
print i
|
102
|
+
end
|
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_clone_detector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MK-nn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
15
15
|
- okuken99@gmail.com
|
16
|
-
executables:
|
16
|
+
executables:
|
17
|
+
- code_clone_detector
|
17
18
|
extensions: []
|
18
19
|
extra_rdoc_files: []
|
19
20
|
files:
|
@@ -30,6 +31,7 @@ files:
|
|
30
31
|
- bin/console
|
31
32
|
- bin/setup
|
32
33
|
- code_clone_detector.gemspec
|
34
|
+
- exe/code_clone_detector
|
33
35
|
- lib/code_clone_detector.rb
|
34
36
|
- lib/code_clone_detector/hello.rb
|
35
37
|
- lib/code_clone_detector/version.rb
|