code_clone_detector 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/CHANGELOG.md +6 -1
- data/README.md +4 -1
- data/code_clone_detector.gemspec +1 -1
- data/exe/code_clone_detector +101 -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: cb73e7027d251f842500379f60cb202a1701f3d7f68d3d7d198fb0cc7ed5eb9d
|
4
|
+
data.tar.gz: 6f7149b3302e525180ad6ccf39b726f8a53006d4c76de704de49d72c28894e6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16b0d96d934ae327e46c768eadbec033545a3ac4d404f9655edfe2496650f89eeea301edd6a1e9a85bcd6b788b9bc761a48fcf1ddb41ed3c6a937b96af06e71f
|
7
|
+
data.tar.gz: 7df5043efe1bd00a89cd37d17dfd90e9467c71b684325e91ffb1dfde23c9de8352f9821a9914c7c120da4ceaa9b09fcbed560eefe2904a7b907c9097c9cc83cd
|
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
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,101 @@
|
|
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[1][1].each do |i|
|
34
|
+
array.push([])
|
35
|
+
code[3][1].each do |j|
|
36
|
+
if i[1] == j[1]
|
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
|
+
array.size.times do |i|
|
51
|
+
array[i].size.times do |j|
|
52
|
+
next unless array[i - 1][j - 1].nil? || array[i - 1][j - 1].zero?
|
53
|
+
next unless array[i][j] == 1
|
54
|
+
|
55
|
+
maxv = 1
|
56
|
+
x = j
|
57
|
+
y = i
|
58
|
+
while !array[y + 1].nil? && !array[y + 1][x + 1].nil? && array[y + 1][x + 1] == 1
|
59
|
+
maxv += 1
|
60
|
+
x += 1
|
61
|
+
y += 1
|
62
|
+
end
|
63
|
+
next unless maxv > tmp_max
|
64
|
+
|
65
|
+
tmp_max = maxv
|
66
|
+
tmp_sx = j
|
67
|
+
tmp_ex = x
|
68
|
+
tmp_sy = i
|
69
|
+
tmp_ey = y
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
next unless tmp_max > max
|
74
|
+
|
75
|
+
max = tmp_max
|
76
|
+
sx = tmp_sx
|
77
|
+
ex = tmp_ex
|
78
|
+
sy = tmp_sy
|
79
|
+
ey = tmp_ey
|
80
|
+
index1 = a
|
81
|
+
index2 = b
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
file_1_name = code[index1][0]
|
86
|
+
file1 = code[index1][1]
|
87
|
+
file_2_name = code[index2][0]
|
88
|
+
file2 = code[index2][1]
|
89
|
+
print "#{file_1_name}:"
|
90
|
+
print "#{file1[sy][0][0]},#{file1[sy][0][1]} ~ #{file1[ey][0][0]},#{file1[ey][0][1]}\n"
|
91
|
+
code[1][1][sy..ey].transpose[2].each do |i|
|
92
|
+
print i
|
93
|
+
end
|
94
|
+
|
95
|
+
puts "\n"
|
96
|
+
|
97
|
+
print "#{file_2_name}:"
|
98
|
+
print "#{file2[sx][0][0]},#{file2[sx][0][1]} ~ #{file2[ex][0][0]},#{file2[ex][0][1]}\n"
|
99
|
+
code[3][1][sx..ex].transpose[2].each do |i|
|
100
|
+
print i
|
101
|
+
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:
|
4
|
+
version: 1.0.0
|
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
|