)"""
117 | self.write(self._indent(' '))
118 | self.format_children(layout)
119 | self.writeln('')
120 |
121 | def visit_span(self, layout):
122 | """display links (using )"""
123 | #TODO: translate in docbook
124 | self.write('' % self.handle_attrs(layout))
125 | self.format_children(layout)
126 | self.write('')
127 |
128 | def visit_link(self, layout):
129 | """display links (using )"""
130 | self.write('%s' % (layout.url,
131 | self.handle_attrs(layout),
132 | layout.label))
133 |
134 | def visit_verbatimtext(self, layout):
135 | """display verbatim text (using )"""
136 | self.writeln(self._indent(' '))
137 | self.write(layout.data.replace('&', '&').replace('<', '<'))
138 | self.writeln(self._indent(' '))
139 |
140 | def visit_text(self, layout):
141 | """add some text"""
142 | self.write(layout.data.replace('&', '&').replace('<', '<'))
143 |
144 | def _indent(self, string):
145 | """correctly indent string according to section"""
146 | return ' ' * 2*(self.section) + string
147 |
--------------------------------------------------------------------------------
/clonedigger/logilab/common/ureports/html_writer.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2004-2005 LOGILAB S.A. (Paris, FRANCE).
2 | # http://www.logilab.fr/ -- mailto:contact@logilab.fr
3 | #
4 | # This program is free software; you can redistribute it and/or modify it under
5 | # the terms of the GNU General Public License as published by the Free Software
6 | # Foundation; either version 2 of the License, or (at your option) any later
7 | # version.
8 | #
9 | # This program is distributed in the hope that it will be useful, but WITHOUT
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
12 | #
13 | # You should have received a copy of the GNU General Public License along with
14 | # this program; if not, write to the Free Software Foundation, Inc.,
15 | # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 | """HTML formatting drivers for ureports
17 | """
18 | from __future__ import unicode_literals
19 | from __future__ import print_function
20 | from __future__ import division
21 | from __future__ import absolute_import
22 | from future import standard_library
23 | standard_library.install_aliases()
24 | from builtins import range
25 | from builtins import *
26 |
27 | __revision__ = "$Id: html_writer.py,v 1.10 2006-03-08 09:47:29 katia Exp $"
28 |
29 | from cgi import escape
30 |
31 | from clonedigger.logilab.common.ureports import BaseWriter
32 |
33 |
34 | class HTMLWriter(BaseWriter):
35 | """format layouts as HTML"""
36 |
37 | def __init__(self, snipet=None):
38 | super(HTMLWriter, self).__init__(self)
39 | self.snipet = snipet
40 |
41 | def handle_attrs(self, layout):
42 | """get an attribute string from layout member attributes"""
43 | attrs = ''
44 | klass = getattr(layout, 'klass', None)
45 | if klass:
46 | attrs += ' class="%s"' % klass
47 | nid = getattr(layout, 'id', None)
48 | if nid:
49 | attrs += ' id="%s"' % nid
50 | return attrs
51 |
52 | def begin_format(self, layout):
53 | """begin to format a layout"""
54 | super(HTMLWriter, self).begin_format(layout)
55 | if self.snipet is None:
56 | self.writeln('')
57 | self.writeln('')
58 |
59 | def end_format(self, layout):
60 | """finished to format a layout"""
61 | if self.snipet is None:
62 | self.writeln('')
63 | self.writeln('')
64 |
65 |
66 | def visit_section(self, layout):
67 | """display a section as html, using div + h[section level]"""
68 | self.section += 1
69 | self.writeln('' % self.handle_attrs(layout))
70 | self.format_children(layout)
71 | self.writeln('
')
72 | self.section -= 1
73 |
74 | def visit_title(self, layout):
75 | """display a title using """
76 | self.write('' % (self.section, self.handle_attrs(layout)))
77 | self.format_children(layout)
78 | self.writeln('' % self.section)
79 |
80 | def visit_table(self, layout):
81 | """display a table as html"""
82 | self.writeln('' % self.handle_attrs(layout))
83 | table_content = self.get_table_content(layout)
84 | for i in range(len(table_content)):
85 | row = table_content[i]
86 | if i == 0 and layout.rheaders:
87 | self.writeln('' % (i%2 and 'even' or 'odd'))
92 | for j in range(len(row)):
93 | cell = row[j] or ' '
94 | if (layout.rheaders and i == 0) or \
95 | (layout.cheaders and j == 0) or \
96 | (layout.rrheaders and i+1 == len(table_content)) or \
97 | (layout.rcheaders and j+1 == len(row)):
98 | self.writeln('%s | ' % cell)
99 | else:
100 | self.writeln('%s | ' % cell)
101 | self.writeln('
')
102 | self.writeln('
')
103 |
104 | def visit_list(self, layout):
105 | """display a list as html"""
106 | self.writeln('' % self.handle_attrs(layout))
107 | for row in list(self.compute_content(layout)):
108 | self.writeln('- %s
' % row)
109 | self.writeln('
')
110 |
111 | def visit_paragraph(self, layout):
112 | """display links (using )"""
113 | self.write('
')
114 | self.format_children(layout)
115 | self.write('
')
116 |
117 | def visit_span(self, layout):
118 | """display links (using )"""
119 | self.write('' % self.handle_attrs(layout))
120 | self.format_children(layout)
121 | self.write('')
122 |
123 | def visit_link(self, layout):
124 | """display links (using )"""
125 | self.write(' %s' % (layout.url,
126 | self.handle_attrs(layout),
127 | layout.label))
128 | def visit_verbatimtext(self, layout):
129 | """display verbatim text (using
)"""
130 | self.write('')
131 | self.write(layout.data.replace('&', '&').replace('<', '<'))
132 | self.write('
')
133 |
134 | def visit_text(self, layout):
135 | """add some text"""
136 | data = layout.data
137 | if layout.escaped:
138 | data = data.replace('&', '&').replace('<', '<')
139 | self.write(data)
140 |
--------------------------------------------------------------------------------
/clonedigger/logilab/common/ureports/text_writer.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2004-2005 LOGILAB S.A. (Paris, FRANCE).
2 | # http://www.logilab.fr/ -- mailto:contact@logilab.fr
3 | #
4 | # This program is free software; you can redistribute it and/or modify it under
5 | # the terms of the GNU General Public License as published by the Free Software
6 | # Foundation; either version 2 of the License, or (at your option) any later
7 | # version.
8 | #
9 | # This program is distributed in the hope that it will be useful, but WITHOUT
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
12 | #
13 | # You should have received a copy of the GNU General Public License along with
14 | # this program; if not, write to the Free Software Foundation, Inc.,
15 | # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 | """Text formatting drivers for ureports"""
17 | from __future__ import print_function
18 | from __future__ import unicode_literals
19 | from __future__ import division
20 | from __future__ import absolute_import
21 | from future import standard_library
22 | standard_library.install_aliases()
23 | from builtins import range
24 | from builtins import *
25 |
26 | __revision__ = "$Id: text_writer.py,v 1.9 2005-11-22 13:13:13 syt Exp $"
27 |
28 | from os import linesep
29 |
30 | from clonedigger.logilab.common.ureports import BaseWriter
31 |
32 | TITLE_UNDERLINES = ['', '=', '-', '`', '.', '~', '^']
33 | BULLETS = ['*', '-']
34 |
35 | class TextWriter(BaseWriter):
36 | """format layouts as text
37 | (ReStructured inspiration but not totally handled yet)
38 | """
39 | def begin_format(self, layout):
40 | super(TextWriter, self).begin_format(layout)
41 | self.list_level = 0
42 | self.pending_urls = []
43 |
44 | def visit_section(self, layout):
45 | """display a section as text
46 | """
47 | self.section += 1
48 | self.writeln()
49 | self.format_children(layout)
50 | if self.pending_urls:
51 | self.writeln()
52 | for label, url in self.pending_urls:
53 | self.writeln('.. _`%s`: %s' % (label, url))
54 | self.pending_urls = []
55 | self.section -= 1
56 | self.writeln()
57 |
58 | def visit_title(self, layout):
59 | title = ''.join(list(self.compute_content(layout)))
60 | self.writeln(title)
61 | try:
62 | self.writeln(TITLE_UNDERLINES[self.section] * len(title))
63 | except IndexError:
64 | print("FIXME TITLE TOO DEEP. TURNING TITLE INTO TEXT")
65 |
66 | def visit_paragraph(self, layout):
67 | """enter a paragraph"""
68 | self.format_children(layout)
69 | self.writeln()
70 |
71 | def visit_span(self, layout):
72 | """enter a span"""
73 | self.format_children(layout)
74 |
75 | def visit_table(self, layout):
76 | """display a table as text"""
77 | table_content = self.get_table_content(layout)
78 | # get columns width
79 | cols_width = [0]*len(table_content[0])
80 | for row in table_content:
81 | for index in range(len(row)):
82 | col = row[index]
83 | cols_width[index] = max(cols_width[index], len(col))
84 | if layout.klass == 'field':
85 | self.field_table(layout, table_content, cols_width)
86 | else:
87 | self.default_table(layout, table_content, cols_width)
88 | self.writeln()
89 |
90 | def default_table(self, layout, table_content, cols_width):
91 | """format a table"""
92 | cols_width = [size+1 for size in cols_width]
93 | format_strings = ' '.join(['%%-%ss'] * len(cols_width))
94 | format_strings = format_strings % tuple(cols_width)
95 | format_strings = format_strings.split(' ')
96 | table_linesep = '\n+' + '+'.join(['-'*w for w in cols_width]) + '+\n'
97 | headsep = '\n+' + '+'.join(['='*w for w in cols_width]) + '+\n'
98 | # FIXME: layout.cheaders
99 | self.write(table_linesep)
100 | for i in range(len(table_content)):
101 | self.write('|')
102 | line = table_content[i]
103 | for j in range(len(line)):
104 | self.write(format_strings[j] % line[j])
105 | self.write('|')
106 | if i == 0 and layout.rheaders:
107 | self.write(headsep)
108 | else:
109 | self.write(table_linesep)
110 |
111 | def field_table(self, layout, table_content, cols_width):
112 | """special case for field table"""
113 | assert layout.cols == 2
114 | format_string = '%s%%-%ss: %%s' % (linesep, cols_width[0])
115 | for field, value in table_content:
116 | self.write(format_string % (field, value))
117 |
118 |
119 | def visit_list(self, layout):
120 | """display a list layout as text"""
121 | bullet = BULLETS[self.list_level % len(BULLETS)]
122 | indent = ' ' * self.list_level
123 | self.list_level += 1
124 | for child in layout.children:
125 | self.write('%s%s%s ' % (linesep, indent, bullet))
126 | child.accept(self)
127 | self.list_level -= 1
128 |
129 | def visit_link(self, layout):
130 | """add a hyperlink"""
131 | if layout.label != layout.url:
132 | self.write('`%s`_' % layout.label)
133 | self.pending_urls.append( (layout.label, layout.url) )
134 | else:
135 | self.write(layout.url)
136 |
137 | def visit_verbatimtext(self, layout):
138 | """display a verbatim layout as text (so difficult ;)
139 | """
140 | self.writeln('::\n')
141 | for line in layout.data.splitlines():
142 | self.writeln(' ' + line)
143 | self.writeln()
144 |
145 | def visit_text(self, layout):
146 | """add some text"""
147 | self.write(layout.data)
148 |
149 |
150 |
--------------------------------------------------------------------------------
/clonedigger/logilab/common/visitor.py:
--------------------------------------------------------------------------------
1 | # This program is free software; you can redistribute it and/or modify it under
2 | # the terms of the GNU General Public License as published by the Free Software
3 | # Foundation; either version 2 of the License, or (at your option) any later
4 | # version.
5 | #
6 | # This program is distributed in the hope that it will be useful, but WITHOUT
7 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 | #
10 | # You should have received a copy of the GNU General Public License along with
11 | # this program; if not, write to the Free Software Foundation, Inc.,
12 | # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
13 | """ Copyright (c) 2002-2003 LOGILAB S.A. (Paris, FRANCE).
14 | http://www.logilab.fr/ -- mailto:contact@logilab.fr
15 |
16 | a generic visitor abstract implementation
17 | """
18 | from __future__ import unicode_literals
19 | from __future__ import print_function
20 | from __future__ import division
21 | from __future__ import absolute_import
22 | from future import standard_library
23 | standard_library.install_aliases()
24 | from builtins import next
25 | from builtins import *
26 | from builtins import object
27 |
28 | def no_filter(_):
29 | return 1
30 |
31 |
32 | # Iterators ###################################################################
33 | class FilteredIterator(object):
34 |
35 | def __init__(self, node, list_func, filter_func=None):
36 | self._next = [(node, 0)]
37 | if filter_func is None:
38 | filter_func = no_filter
39 | self._list = list_func(node, filter_func)
40 |
41 | def __next__(self):
42 | try:
43 | return self._list.pop(0)
44 | except :
45 | return None
46 |
47 |
48 | # Base Visitor ################################################################
49 | class Visitor(object):
50 |
51 | def __init__(self, iterator_class, filter_func=None):
52 | self._iter_class = iterator_class
53 | self.filter = filter_func
54 |
55 | def visit(self, node, *args, **kargs):
56 | """
57 | launch the visit on a given node
58 |
59 | call 'open_visit' before the begining of the visit, with extra args
60 | given
61 | when all nodes have been visited, call the 'close_visit' method
62 | """
63 | self.open_visit(node, *args, **kargs)
64 | return self.close_visit(self._visit(node))
65 |
66 | def _visit(self, node):
67 | iterator = self._get_iterator(node)
68 | n = next(iterator)
69 | while n:
70 | result = n.accept(self)
71 | n = next(iterator)
72 | return result
73 |
74 | def _get_iterator(self, node):
75 | return self._iter_class(node, self.filter)
76 |
77 | def open_visit(self, *args, **kargs):
78 | """
79 | method called at the beginning of the visit
80 | """
81 | pass
82 |
83 | def close_visit(self, result):
84 | """
85 | method called at the end of the visit
86 | """
87 | return result
88 |
89 |
90 |
91 | # standard visited mixin ######################################################
92 | class VisitedMixIn(object):
93 | """
94 | Visited interface allow node visitors to use the node
95 | """
96 | def get_visit_name(self):
97 | """
98 | return the visit name for the mixed class. When calling 'accept', the
99 | method <'visit_' + name returned by this method> will be called on the
100 | visitor
101 | """
102 | try:
103 | return self.TYPE.replace('-', '_')
104 | except:
105 | return self.__class__.__name__.lower()
106 |
107 | def accept(self, visitor, *args, **kwargs):
108 | func = getattr(visitor, 'visit_%s' % self.get_visit_name())
109 | return func(self, *args, **kwargs)
110 |
111 | def leave(self, visitor, *args, **kwargs):
112 | func = getattr(visitor, 'leave_%s' % self.get_visit_name())
113 | return func(self, *args, **kwargs)
114 |
115 |
116 |
--------------------------------------------------------------------------------
/clonedigger/logilab/common/xmlrpcutils.py:
--------------------------------------------------------------------------------
1 | # This program is free software; you can redistribute it and/or modify it under
2 | # the terms of the GNU General Public License as published by the Free Software
3 | # Foundation; either version 2 of the License, or (at your option) any later
4 | # version.
5 | #
6 | # This program is distributed in the hope that it will be useful, but WITHOUT
7 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
9 | #
10 | # You should have received a copy of the GNU General Public License along with
11 | # this program; if not, write to the Free Software Foundation, Inc.,
12 | # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
13 | """XML-RPC utilities
14 |
15 | Copyright (c) 2003-2004 LOGILAB S.A. (Paris, FRANCE).
16 | http://www.logilab.fr/ -- mailto:contact@logilab.fr
17 | """
18 | from __future__ import unicode_literals
19 | from __future__ import print_function
20 | from __future__ import division
21 | from __future__ import absolute_import
22 | from future import standard_library
23 | standard_library.install_aliases()
24 | from builtins import str
25 | from builtins import *
26 | from builtins import object
27 |
28 | __revision__ = "$Id: xmlrpcutils.py,v 1.3 2005-11-22 13:13:03 syt Exp $"
29 |
30 | import xmlrpc.client
31 | from base64 import encodestring
32 | #from cStringIO import StringIO
33 |
34 | ProtocolError = xmlrpc.client.ProtocolError
35 |
36 | ## class BasicAuthTransport(xmlrpclib.Transport):
37 | ## def __init__(self, username=None, password=None):
38 | ## self.username = username
39 | ## self.password = password
40 | ## self.verbose = None
41 | ## self.has_ssl = httplib.__dict__.has_key("HTTPConnection")
42 |
43 | ## def request(self, host, handler, request_body, verbose=None):
44 | ## # issue XML-RPC request
45 | ## if self.has_ssl:
46 | ## if host.startswith("https:"): h = httplib.HTTPSConnection(host)
47 | ## else: h = httplib.HTTPConnection(host)
48 | ## else: h = httplib.HTTP(host)
49 |
50 | ## h.putrequest("POST", handler)
51 |
52 | ## # required by HTTP/1.1
53 | ## if not self.has_ssl: # HTTPConnection already does 1.1
54 | ## h.putheader("Host", host)
55 | ## h.putheader("Connection", "close")
56 |
57 | ## if request_body: h.send(request_body)
58 | ## if self.has_ssl:
59 | ## response = h.getresponse()
60 | ## if response.status != 200:
61 | ## raise xmlrpclib.ProtocolError(host + handler,
62 | ## response.status,
63 | ## response.reason,
64 | ## response.msg)
65 | ## file = response.fp
66 | ## else:
67 | ## errcode, errmsg, headers = h.getreply()
68 | ## if errcode != 200:
69 | ## raise xmlrpclib.ProtocolError(host + handler, errcode,
70 | ## errmsg, headers)
71 |
72 | ## file = h.getfile()
73 |
74 | ## return self.parse_response(file)
75 |
76 |
77 |
78 | class AuthMixin(object):
79 | """basic http authentication mixin for xmlrpc transports"""
80 |
81 | def __init__(self, username, password, encoding):
82 | self.verbose = 0
83 | self.username = username
84 | self.password = password
85 | self.encoding = encoding
86 |
87 | def request(self, host, handler, request_body, verbose=0):
88 | """issue XML-RPC request"""
89 | h = self.make_connection(host)
90 | h.putrequest("POST", handler)
91 | # required by XML-RPC
92 | h.putheader("User-Agent", self.user_agent)
93 | h.putheader("Content-Type", "text/xml")
94 | h.putheader("Content-Length", str(len(request_body)))
95 | h.putheader("Host", host)
96 | h.putheader("Connection", "close")
97 | # basic auth
98 | if self.username is not None and self.password is not None:
99 | h.putheader("AUTHORIZATION", "Basic %s" % encodestring(
100 | "%s:%s" % (self.username, self.password)).replace("\012", ""))
101 | h.endheaders()
102 | # send body
103 | if request_body:
104 | h.send(request_body)
105 | # get and check reply
106 | errcode, errmsg, headers = h.getreply()
107 | if errcode != 200:
108 | raise ProtocolError(host + handler, errcode, errmsg, headers)
109 | file = h.getfile()
110 | ## # FIXME: encoding ??? iirc, this fix a bug in xmlrpclib but...
111 | ## data = h.getfile().read()
112 | ## if self.encoding != 'UTF-8':
113 | ## data = data.replace("version='1.0'",
114 | ## "version='1.0' encoding='%s'" % self.encoding)
115 | ## result = StringIO()
116 | ## result.write(data)
117 | ## result.seek(0)
118 | ## return self.parse_response(result)
119 | return self.parse_response(file)
120 |
121 | class BasicAuthTransport(AuthMixin, xmlrpc.client.Transport):
122 | """basic http authentication transport"""
123 |
124 | class BasicAuthSafeTransport(AuthMixin, xmlrpc.client.SafeTransport):
125 | """basic https authentication transport"""
126 |
127 |
128 | def connect(url, user=None, passwd=None, encoding='ISO-8859-1'):
129 | """return an xml rpc server on , using user / password if specified
130 | """
131 | if user or passwd:
132 | assert user and passwd is not None
133 | if url.startswith('https://'):
134 | transport = BasicAuthSafeTransport(user, passwd, encoding)
135 | else:
136 | transport = BasicAuthTransport(user, passwd, encoding)
137 | else:
138 | transport = None
139 | server = xmlrpc.client.ServerProxy(url, transport, encoding=encoding)
140 | return server
141 |
--------------------------------------------------------------------------------
/clonedigger/lua_antlr.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | from __future__ import absolute_import
3 | from __future__ import unicode_literals
4 | from __future__ import division
5 | from future import standard_library
6 | standard_library.install_aliases()
7 | from builtins import *
8 | from builtins import object
9 | # Copyright 2008 Peter Bulychev
10 | # http://clonedigger.sourceforge.net
11 | #
12 | # This file is part of Clone Digger.
13 | #
14 | # Clone Digger is free software: you can redistribute it and/or modify
15 | # it under the terms of the GNU General Public License as published by
16 | # the Free Software Foundation, either version 3 of the License, or
17 | # (at your option) any later version.
18 | #
19 | # Clone Digger is distributed in the hope that it will be useful,
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 | # GNU General Public License for more details.
23 | #
24 | # You should have received a copy of the GNU General Public License
25 | # along with Clone Digger. If not, see .
26 |
27 | import os
28 | import xml.parsers.expat
29 |
30 | from .abstract_syntax_tree import *
31 |
32 | class LuaANTLRSourceFile (SourceFile):
33 | extension = 'lua'
34 | size_threshold = 5
35 | distance_threshold = 5
36 | def __init__(self, file_name):
37 | SourceFile.__init__(self, file_name)
38 | class ExpatHandler(object):
39 | def __init__(self, start_node, parent):
40 | self.parent = parent
41 | self.stack = [start_node]
42 | def start_element(expat_self, xml_node_name, attrs):
43 | line_number = int(attrs["line_number"])-1
44 | line_numbers = [line_number]
45 | if line_numbers == [-1]:
46 | line_numbers = []
47 | name = attrs["name"]
48 | r = AbstractSyntaxTree(name, line_numbers, self)
49 | if name in ["stat", "chunk"]:
50 | r.markAsStatement()
51 | else:
52 | assert(xml_node_name == "node")
53 | expat_self.stack[-1].addChild(r)
54 | expat_self.stack.append(r)
55 | def end_element(self, name):
56 | self.stack.pop()
57 |
58 | tree_file_name = 'temporary_ast.xml'
59 | producer_class_path = os.path.join('.','lua_antlr', 'TreeProducer.jar')
60 | antlr_class_path = os.path.join('.','antlr_runtime','antlr-runtime-3.1.jar')
61 | if os.name in ['mac', 'posix']:
62 | class_path_delimeter = ':'
63 | elif os.name in ['nt', 'dos', 'ce']:
64 | class_path_delimeter = ';'
65 | else:
66 | print('unsupported OS')
67 | assert(0)
68 |
69 | if os.system('java -classpath ' + producer_class_path + class_path_delimeter + antlr_class_path + ' TreeProducer %s %s 2>err.log'%(file_name, tree_file_name)):
70 | f = open('err.log')
71 | s = f.read()
72 | f.close()
73 | raise s
74 | f = open('err.log')
75 | s = f.read()
76 | f.close()
77 | if s:
78 | print(s)
79 |
80 | self._tree = AbstractSyntaxTree('program')
81 | handler = ExpatHandler(self._tree, self)
82 | p = xml.parsers.expat.ParserCreate()
83 | p.StartElementHandler = handler.start_element
84 | p.EndElementHandler = handler.end_element
85 | f = open(tree_file_name)
86 | p.ParseFile(f)
87 | f.close()
88 | # os.remove(tree_file_name)
89 |
--------------------------------------------------------------------------------
/clonedigger/lua_antlr/Lua.g:
--------------------------------------------------------------------------------
1 | /*
2 | * Lua 5.1 grammar
3 | *
4 | * Nicolai Mainiero
5 | * May 2007
6 | *
7 | * This is a Lua (http://www.lua.org) grammar for the version 5.1 for ANTLR 3.
8 | * I tested it with basic and extended examples and it worked fine. It is also used
9 | * for LunarEclipse (http://lunareclipse.sf.net) a Lua editor based on Eclipse.
10 | *
11 | * Thanks to Johannes Luber and Gavin Lambert who helped me with some mutually left recursion.
12 | *
13 | */
14 |
15 | grammar Lua;
16 |
17 | options {
18 | backtrack=true;
19 | }
20 |
21 | chunk : (stat (';')?)* (laststat (';')?)?;
22 |
23 | block : chunk;
24 |
25 | stat : varlist1 '=' explist1 |
26 | functioncall |
27 | 'do' block 'end' |
28 | 'while' exp 'do' block 'end' |
29 | 'repeat' block 'until' exp |
30 | 'if' exp 'then' block ('elseif' exp 'then' block)* ('else' block)? 'end' |
31 | 'for' NAME '=' exp ',' exp (',' exp)? 'do' block 'end' |
32 | 'for' namelist 'in' explist1 'do' block 'end' |
33 | 'function' funcname funcbody |
34 | 'local' 'function' NAME funcbody |
35 | 'local' namelist ('=' explist1)? ;
36 |
37 | laststat : 'return' (explist1)? | 'break';
38 |
39 | funcname : NAME ('.' NAME)* (':' NAME)? ;
40 |
41 | varlist1 : var (',' var)*;
42 |
43 |
44 | namelist : NAME (',' NAME)*;
45 |
46 | explist1 : (exp ',')* exp;
47 |
48 | exp : ('nil' | 'false' | 'true' | number | string | '...' | function | prefixexp | tableconstructor | unop exp) (binop exp)* ;
49 |
50 | var: (NAME | '(' exp ')' varSuffix) varSuffix*;
51 |
52 | prefixexp: varOrExp nameAndArgs*;
53 |
54 | functioncall: varOrExp nameAndArgs+;
55 |
56 | /*
57 | var : NAME | prefixexp '[' exp ']' | prefixexp '.' NAME;
58 |
59 | prefixexp : var | functioncall | '(' exp ')';
60 |
61 | functioncall : prefixexp args | prefixexp ':' NAME args ;
62 | */
63 |
64 | varOrExp: var | '(' exp ')';
65 |
66 | nameAndArgs: (':' NAME)? args;
67 |
68 | varSuffix: nameAndArgs* ('[' exp ']' | '.' NAME);
69 |
70 | args : '(' (explist1)? ')' | tableconstructor | string ;
71 |
72 | function : 'function' funcbody;
73 |
74 | funcbody : '(' (parlist1)? ')' block 'end';
75 |
76 | parlist1 : namelist (',' '...')? | '...';
77 |
78 | tableconstructor : '{' (fieldlist)? '}';
79 |
80 | fieldlist : field (fieldsep field)* (fieldsep)?;
81 |
82 | field : '[' exp ']' '=' exp | NAME '=' exp | exp;
83 |
84 | fieldsep : ',' | ';';
85 |
86 | binop : '+' | '-' | '*' | '/' | '^' | '%' | '..' |
87 | '<' | '<=' | '>' | '>=' | '==' | '~=' |
88 | 'and' | 'or';
89 |
90 | unop : '-' | 'not' | '#';
91 |
92 | number : INT | FLOAT | EXP | HEX;
93 |
94 | string : NORMALSTRING | CHARSTRING | LONGSTRING;
95 |
96 |
97 | // LEXER
98 |
99 | NAME :('a'..'z'|'A'..'Z'|'_')(options{greedy=true;}: 'a'..'z'|'A'..'Z'|'_'|'0'..'9')*
100 | ;
101 |
102 | INT : ('0'..'9')+;
103 |
104 | FLOAT :INT '.' INT ;
105 |
106 | EXP : (INT| FLOAT) ('E'|'e') ('-')? INT;
107 |
108 | HEX :'0x' ('0'..'9'| 'a'..'f')+ ;
109 |
110 |
111 |
112 | NORMALSTRING
113 | : '"' ( EscapeSequence | ~('\\'|'"') )* '"'
114 | ;
115 |
116 | CHARSTRING
117 | : '\'' ( EscapeSequence | ~('\''|'\\') )* '\''
118 | ;
119 |
120 | LONGSTRING
121 | : '['('=')*'[' ( EscapeSequence | ~('\\'|']') )* ']'('=')*']'
122 | ;
123 |
124 | fragment
125 | EscapeSequence
126 | : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
127 | | UnicodeEscape
128 | | OctalEscape
129 | ;
130 |
131 | fragment
132 | OctalEscape
133 | : '\\' ('0'..'3') ('0'..'7') ('0'..'7')
134 | | '\\' ('0'..'7') ('0'..'7')
135 | | '\\' ('0'..'7')
136 | ;
137 |
138 | fragment
139 | UnicodeEscape
140 | : '\\' 'u' HexDigit HexDigit HexDigit HexDigit
141 | ;
142 |
143 | fragment
144 | HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;
145 |
146 |
147 | COMMENT
148 | : '--[[' ( options {greedy=false;} : . )* ']]' {skip();}
149 | ;
150 |
151 | LINE_COMMENT
152 | : '--' ~('\n'|'\r')* '\r'? '\n' {skip();}
153 | ;
154 |
155 |
156 | WS : (' '|'\t'|'\u000C') {skip();}
157 | ;
158 |
159 | NEWLINE : ('\r')? '\n' {skip();}
160 | ;
161 |
--------------------------------------------------------------------------------
/clonedigger/lua_antlr/TreeProducer.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/clonedigger/lua_antlr/TreeProducer.jar
--------------------------------------------------------------------------------
/clonedigger/lua_antlr/TreeProducer.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2008 Peter Bulychev
2 | *
3 | * This file is part of Clone Digger.
4 | *
5 | * Clone Digger is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * Clone Digger is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with Clone Digger. If not, see .
17 | */
18 | import org.antlr.runtime.*;
19 | import org.antlr.stringtemplate.*;
20 | import org.antlr.runtime.tree.*;
21 |
22 | import org.antlr.runtime.tree.ParseTree;
23 |
24 | import org.antlr.runtime.*;
25 | import org.antlr.runtime.tree.*;
26 | import org.antlr.runtime.debug.*;
27 |
28 | import java.lang.reflect.*;
29 | import java.io.*;
30 | import java.util.*;
31 | import java.text.*;
32 | import java.lang.*;
33 |
34 |
35 |
36 | public class TreeProducer
37 | {
38 | public TreeProducer ()
39 | {
40 | super ();
41 | }
42 |
43 | /*
44 | * forXml function was taken from http://www.javapractices.com/topic/TopicAction.do?Id=96
45 | * the license is: http://creativecommons.org/licenses/by/3.0/
46 | */
47 | public static String forXML (String aText)
48 | {
49 | final StringBuilder result = new StringBuilder ();
50 | final StringCharacterIterator iterator =
51 | new StringCharacterIterator (aText);
52 | char character = iterator.current ();
53 | while (character != CharacterIterator.DONE)
54 | {
55 | if (character == '<')
56 | {
57 | result.append ("<");
58 | }
59 | else if (character == '>')
60 | {
61 | result.append (">");
62 | }
63 | else if (character == '\"')
64 | {
65 | result.append (""");
66 | }
67 | else if (character == '\'')
68 | {
69 | result.append ("'");
70 | }
71 | else if (character == '&')
72 | {
73 | result.append ("&");
74 | }
75 | else
76 | {
77 | //the char is not a special one
78 | // //add it to the result as is
79 | result.append (character);
80 | }
81 | character = iterator.next ();
82 | }
83 | return result.toString ();
84 | }
85 | // }
86 |
87 | public static void printTree (ParseTree tree, PrintWriter outputStream, String indent)
88 | {
89 | // String xml_node_name = (tree.is_statement?"statement_node":"node");
90 | String xml_node_name = "node";
91 | int lineno;
92 | if ( tree.payload instanceof Token ) {
93 | Token t = (Token)tree.payload;
94 | lineno = t.getLine();
95 | } else {
96 | lineno = 0;
97 | }
98 |
99 | outputStream.println (indent + "<" + xml_node_name + " name=\"" + forXML ("" + tree) + "\"" +
100 | " line_number=\"" + lineno + "\" " +
101 | ">");
102 | for (int i = 0; i < tree.getChildCount (); i += 1)
103 | {
104 | printTree ((ParseTree )tree.getChild (i), outputStream, indent + " ");
105 | }
106 | outputStream.println (indent + ""+xml_node_name+">");
107 | }
108 |
109 | public static void main (String[]args) throws Exception
110 | {
111 | ANTLRFileStream input = new ANTLRFileStream (args[0]);
112 | LuaLexer lexer = new LuaLexer (input);
113 | CommonTokenStream tokens = new CommonTokenStream (lexer);
114 |
115 | ParseTreeBuilder builder = new ParseTreeBuilder("chunk");
116 |
117 | LuaParser parser = new LuaParser (tokens, builder);
118 |
119 | parser.chunk();
120 | ParseTree tree = builder.getTree();
121 |
122 | PrintWriter outputStream =
123 | new PrintWriter (new FileWriter (args[1], false));
124 | outputStream.println ("");
125 | printTree (tree, outputStream, "");
126 | outputStream.close ();
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/clonedigger/lua_antlr/build_jar.sh:
--------------------------------------------------------------------------------
1 | export CLASSPATH=/home/peter/antlr/antlr-3.1.jar:/home/peter/antlr/antlr-3.0.1/lib/stringtemplate-3.1b1.jar:/home/peter/antlr/antlr-3.0.1/lib/antlr-2.7.7.jar:.
2 | java org.antlr.Tool -debug Lua.g
3 | javac *.java
4 | jar -cf TreeProducer.jar *.class
5 | rm *.class
6 |
--------------------------------------------------------------------------------
/clonedigger/suffix_tree.py:
--------------------------------------------------------------------------------
1 | from __future__ import unicode_literals
2 | from __future__ import print_function
3 | from __future__ import division
4 | from __future__ import absolute_import
5 | from future import standard_library
6 | standard_library.install_aliases()
7 | from builtins import str
8 | from builtins import range
9 | from builtins import *
10 | from builtins import object
11 | # Copyright 2008 Peter Bulychev
12 | # http://clonedigger.sourceforge.net
13 | #
14 | # This file is part of Clone Digger.
15 | #
16 | # Clone Digger is free software: you can redistribute it and/or modify
17 | # it under the terms of the GNU General Public License as published by
18 | # the Free Software Foundation, either version 3 of the License, or
19 | # (at your option) any later version.
20 | #
21 | # Clone Digger is distributed in the hope that it will be useful,
22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | # GNU General Public License for more details.
25 | #
26 | # You should have received a copy of the GNU General Public License
27 | # along with Clone Digger. If not, see .
28 |
29 |
30 | class SuffixTree(object):
31 | class StringPosition(object):
32 | def __init__(self, string, position,prevelem):
33 | self.string = string
34 | self.position = position
35 | self.prevelem = prevelem
36 | class SuffixTreeNode(object):
37 | def __init__(self):
38 | self.childs = {} #
39 | self.string_positions = []
40 | self.ending_strings = []
41 |
42 | def __init__(self, f_code):
43 | self._node = self.SuffixTreeNode()
44 | self._f_code = f_code
45 | def _add(self, string, prevelem):
46 | pos = 0
47 | node = self._node
48 | for pos in range(len(string)):
49 | e = string[pos]
50 | code = self._f_code(e)
51 | node.string_positions.append(self.StringPosition(string, pos, prevelem))
52 | if code not in node.childs:
53 | node.childs[code] = self.SuffixTreeNode()
54 | node = node.childs[code]
55 | node.ending_strings.append(self.StringPosition(string, pos+1, prevelem))
56 | def add(self, string):
57 | for i in range(len(string)):
58 | if i == 0:
59 | prevelem = None
60 | else:
61 | prevelem = self._f_code(string[i-1])
62 | self._add(string[i:],prevelem)
63 | def getBestMaxSubstrings(self, threshold, f, f_elem, node = None, initial_threshold=None):
64 | if initial_threshold==None:
65 | initial_threshold = threshold
66 | def check_left_diverse_and_add(s1, s2, p):
67 | if ((s1.prevelem == None) or (s2.prevelem == None) or (s1.prevelem != s2.prevelem)) and s1.position>p:
68 | candidate = (s1.string[:s1.position-p], s2.string[:s2.position-p])
69 | if f_elem(candidate[0]) >= initial_threshold or \
70 | f_elem(candidate[1]) >= initial_threshold:
71 | r.append(candidate)
72 | return True
73 | else:
74 | return False
75 | if node == None:
76 | node = self._node
77 | r = []
78 | if threshold <= 0:
79 | for s1 in node.ending_strings:
80 | for s2 in node.string_positions:
81 | if s1.string == s2.string:
82 | continue
83 | check_left_diverse_and_add(s1, s2, 0)
84 | for i in range(len(node.ending_strings)):
85 | for j in range(i):
86 | s1 = node.ending_strings[i]
87 | s2 = node.ending_strings[j]
88 | check_left_diverse_and_add(s1, s2, 0)
89 | for i in range(len(list(node.childs.keys()))):
90 | for j in range(i):
91 | c1 = list(node.childs.keys())[i]
92 | c2 = list(node.childs.keys())[j]
93 | for s1 in node.childs[c1].string_positions + node.childs[c1].ending_strings:
94 | for s2 in node.childs[c2].string_positions + node.childs[c2].ending_strings:
95 | check_left_diverse_and_add(s1, s2, 1)
96 | for (code, child) in list(node.childs.items()):
97 | r += self.getBestMaxSubstrings(threshold - f(code), f, f_elem, child, initial_threshold)
98 | return r
99 |
100 | if __name__ == '__main__':
101 | class Elem(object):
102 | def __init__(self, code):
103 | self._code = code
104 | def getCode(self):
105 | return self._code
106 | def __str__(self):
107 | return str(self._code)
108 | def test1():
109 | t = SuffixTree()
110 | for w in ['abcPeter', 'Pet1erbca', 'Peter', 'aPet0--']:
111 | t.add([Elem(c) for c in w])
112 | maxs = t.getBestMaxSubstrings(3)
113 | l = []
114 | for (s1, s2) in maxs:
115 | l.append([''.join([str(e) for e in s1]), ''.join([str(e) for e in s2])])
116 | assert(l == [['Pe1t', 'P2et'], ['P3et', 'Pe4t'], ['Pet', 'Pet'], ['Pet', 'Pet'], ['Pet', 'Pet'], ['Peter', 'Peter']])
117 | def test2():
118 | t = SuffixTree()
119 | for w in ['a', 'aa']:
120 | t.add([Elem(c) for c in w])
121 | maxs = t.getBestMaxSubstrings(0)
122 | l = []
123 | for (s1, s2) in maxs:
124 | l.append([''.join([str(e) for e in s1]), ''.join([str(e) for e in s2])])
125 | assert(l == [['a', 'a'], ['a', 'a'], ['a', 'a']])
126 | for s in dir():
127 | if s.find('test') == 0:
128 | eval(s + '()')
129 |
130 |
--------------------------------------------------------------------------------
/eclipse_plugin_manual/Run.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/eclipse_plugin_manual/Run.gif
--------------------------------------------------------------------------------
/eclipse_plugin_manual/RunDone.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/eclipse_plugin_manual/RunDone.gif
--------------------------------------------------------------------------------
/eclipse_plugin_manual/RunFirst.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/eclipse_plugin_manual/RunFirst.gif
--------------------------------------------------------------------------------
/eclipse_plugin_manual/RunInstall.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/eclipse_plugin_manual/RunInstall.gif
--------------------------------------------------------------------------------
/eclipse_plugin_manual/RunPopup.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/eclipse_plugin_manual/RunPopup.gif
--------------------------------------------------------------------------------
/eclipse_plugin_manual/SUpdate.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/eclipse_plugin_manual/SUpdate.gif
--------------------------------------------------------------------------------
/eclipse_plugin_manual/SUpdateAdd.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/eclipse_plugin_manual/SUpdateAdd.gif
--------------------------------------------------------------------------------
/eclipse_plugin_manual/SUpdateInstall.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/eclipse_plugin_manual/SUpdateInstall.gif
--------------------------------------------------------------------------------
/eclipse_plugin_manual/Update.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/eclipse_plugin_manual/Update.gif
--------------------------------------------------------------------------------
/eclipse_plugin_manual/eclipse_plugin_manual.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | CloneDigger Eclipse plugin manual
4 |
5 |
6 |
7 | Requirements
8 |
11 | Install from SVN
12 | Go to the update manager (inside the help menu) and
13 | add update site:
14 | http://clonedigger.svn.sourceforge.net/svnroot/clonedigger/trunk/org.clonedigger.feature/
15 | (Eclipse should do the rest)
16 |
17 | 
18 |
19 |
Using
20 | Now, you can check your projects for clones. Just run
21 | clonedigger
22 | wizard from main menu.
23 |
24 | On the first page of a wizard you may select files to dig,
25 | choose
26 | language (for now clonedigger support only java and python) and select
27 | digging options (fast mode clone size and clone distance). Click "next" button when you will
28 | ready .
29 |
30 | On the first run plugin will try to download the last version
31 | of
32 | clonedigger from PyPi repository.
33 |
34 | After that you will see the
35 | console output during the dig phase. When Clone Digger will ready you may press final button.
36 |
37 | Now you will see the report. Before each clone there is a "Go
38 | to this
39 | fragment in Eclipse" link, you may follow this links to automatically
40 | find and select clone in eclipse environment.
41 | Tip: be careful! When you will edit your
42 | code and
43 | add some new lines to it report will gone out of sync and "Go to this
44 | fragment in Eclipse" links will be broken.
45 | Feature: you may run clonedigger wizard
46 | from project
47 | tree, just select desired files or folders by holding {ctrl} button and
48 | this file will be checked on the first wizard page when it appear.
49 | 
Update CloneDigger
50 | instance
51 | You can update clonedigger instance in plugin by clicking
52 | Update
53 | CloneDigger menu item. CloneDigger will be downloaded next time you run
54 | the wizard.
by Anatoly Zapadinsky
--------------------------------------------------------------------------------
/org.clonedigger.feature/build.properties:
--------------------------------------------------------------------------------
1 | bin.includes = feature.xml
2 | src.includes = .project,\
3 | feature.xml,\
4 | build.properties,\
5 | site.xml
6 |
--------------------------------------------------------------------------------
/org.clonedigger.feature/feature.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 | [Enter Feature Description here.]
10 |
11 |
12 |
13 | ...
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/org.clonedigger.feature/features/org.clonedigger.feature_1.1.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger.feature/features/org.clonedigger.feature_1.1.3.jar
--------------------------------------------------------------------------------
/org.clonedigger.feature/features/org.clonedigger.feature_1.1.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger.feature/features/org.clonedigger.feature_1.1.4.jar
--------------------------------------------------------------------------------
/org.clonedigger.feature/features/org.clonedigger.feature_1.1.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger.feature/features/org.clonedigger.feature_1.1.5.jar
--------------------------------------------------------------------------------
/org.clonedigger.feature/features/org.clonedigger.feature_1.1.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger.feature/features/org.clonedigger.feature_1.1.6.jar
--------------------------------------------------------------------------------
/org.clonedigger.feature/features/org.clonedigger.feature_1.1.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger.feature/features/org.clonedigger.feature_1.1.7.jar
--------------------------------------------------------------------------------
/org.clonedigger.feature/features/org.clonedigger.feature_1.1.8.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger.feature/features/org.clonedigger.feature_1.1.8.jar
--------------------------------------------------------------------------------
/org.clonedigger.feature/plugins/org.clonedigger_1.1.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger.feature/plugins/org.clonedigger_1.1.3.jar
--------------------------------------------------------------------------------
/org.clonedigger.feature/plugins/org.clonedigger_1.1.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger.feature/plugins/org.clonedigger_1.1.4.jar
--------------------------------------------------------------------------------
/org.clonedigger.feature/plugins/org.clonedigger_1.1.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger.feature/plugins/org.clonedigger_1.1.5.jar
--------------------------------------------------------------------------------
/org.clonedigger.feature/plugins/org.clonedigger_1.1.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger.feature/plugins/org.clonedigger_1.1.6.jar
--------------------------------------------------------------------------------
/org.clonedigger.feature/plugins/org.clonedigger_1.1.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger.feature/plugins/org.clonedigger_1.1.7.jar
--------------------------------------------------------------------------------
/org.clonedigger.feature/plugins/org.clonedigger_1.1.8.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger.feature/plugins/org.clonedigger_1.1.8.jar
--------------------------------------------------------------------------------
/org.clonedigger.feature/site.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/org.clonedigger/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/org.clonedigger/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | #Thu Jul 24 12:47:50 MSD 2008
2 | eclipse.preferences.version=1
3 | encoding/setup.py=UTF-8
4 |
--------------------------------------------------------------------------------
/org.clonedigger/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Wed Jul 23 21:54:52 MSD 2008
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4 | org.eclipse.jdt.core.compiler.compliance=1.5
5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7 | org.eclipse.jdt.core.compiler.source=1.5
8 |
--------------------------------------------------------------------------------
/org.clonedigger/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Bundle-ManifestVersion: 2
3 | Bundle-Name: Helloworld Plug-in
4 | Bundle-SymbolicName: org.clonedigger;singleton:=true
5 | Bundle-Version: 1.1.8
6 | Bundle-Activator: org.clonedigger.Activator
7 | Bundle-Vendor: Clone Digger
8 | Require-Bundle: org.eclipse.ui,
9 | org.eclipse.core.runtime,
10 | org.eclipse.ui.ide,
11 | org.eclipse.core.resources;bundle-version="3.2.0",
12 | org.eclipse.ui.editors;bundle-version="3.2.0",
13 | org.eclipse.ui.browser;bundle-version="3.2.0",
14 | org.python.pydev;bundle-version="1.3.18"
15 | Bundle-RequiredExecutionEnvironment: J2SE-1.5
16 | Import-Package: org.eclipse.core.filesystem,
17 | org.eclipse.jdt.core,
18 | org.eclipse.jface.text
19 | Export-Package: org.clonedigger,
20 | org.clonedigger.actions
21 | Bundle-ActivationPolicy: lazy
22 |
--------------------------------------------------------------------------------
/org.clonedigger/build.properties:
--------------------------------------------------------------------------------
1 | source.. = src/
2 | output.. = bin/
3 | bin.includes = plugin.xml,\
4 | META-INF/,\
5 | .,\
6 | runclonedigger.py,\
7 | bin/,\
8 | icons/,\
9 | setup.py,\
10 | ez_setup.py
11 | src.includes = src/,\
12 | plugin.xml,\
13 | icons/,\
14 | META-INF/,\
15 | runclonedigger.py,\
16 | .project,\
17 | .settings/,\
18 | .pydevproject,\
19 | .classpath,\
20 | build.properties,\
21 | bin/,\
22 | setup.py,\
23 | ez_setup.py
24 |
--------------------------------------------------------------------------------
/org.clonedigger/icons/icon.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jlachowski/clonedigger/f5f2a182a35f880c0c345db3d240ddb20ecfb09d/org.clonedigger/icons/icon.gif
--------------------------------------------------------------------------------
/org.clonedigger/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
10 |
17 |
25 |
26 |
33 |
34 |
35 |
36 |
38 |
43 |
44 |
45 |
47 |
50 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/org.clonedigger/runclonedigger.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | from __future__ import print_function
3 | from __future__ import unicode_literals
4 | from __future__ import division
5 | from __future__ import absolute_import
6 | from future import standard_library
7 | standard_library.install_aliases()
8 | from builtins import *
9 | import sys
10 | import os
11 | python_path = os.environ['PYTHONPATH']
12 | try:
13 | import clonedigger.clonedigger
14 | if not os.path.abspath(clonedigger.clonedigger.__file__).startswith(os.path.abspath(python_path)):
15 | raise ImportError
16 | except ImportError:
17 | if not os.path.exists(python_path):
18 | os.mkdir(python_path)
19 | os.chdir(python_path)
20 | print('Missing Clone Digger')
21 | print('We will try now to install it to local directory', python_path)
22 | print('please wait...')
23 | sys.argv = [sys.argv[0], 'easy_install', '--exclude-scripts', '-U', '--always-copy', '--install-dir', python_path, 'clonedigger']
24 | try:
25 | import setup
26 | except:
27 | import setup
28 | sys.exit(143)
29 | clonedigger.clonedigger.main()
30 |
--------------------------------------------------------------------------------
/org.clonedigger/setup.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | This module contains the tool of collective.recipe.buildbot
4 | """
5 | from __future__ import unicode_literals
6 | from __future__ import print_function
7 | from __future__ import division
8 | from __future__ import absolute_import
9 | from future import standard_library
10 | standard_library.install_aliases()
11 | from builtins import *
12 |
13 | from ez_setup import use_setuptools
14 | use_setuptools()
15 |
16 | import os
17 | from setuptools import setup, find_packages
18 |
19 | def read(*rnames):
20 | return open(os.path.join(os.getcwd(), *rnames)).read()
21 |
22 | version = '1.0.4-beta'
23 |
24 | long_description = ""
25 |
26 | entry_points = {"console_scripts": [
27 | "clonedigger = clonedigger.clonedigger:main"
28 | ],
29 | }
30 |
31 | setup(name='clonedigger',
32 | version=version,
33 | description=("Clone Digger aimed to detect similar code in Python "
34 | "and Java programs."),
35 | long_description=long_description,
36 | # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers
37 | classifiers=[
38 | 'Intended Audience :: Developers',
39 | 'Topic :: Software Development :: Libraries :: Python Modules',
40 | ],
41 | keywords='buildout buildbot',
42 | author='Peter Bulychev',
43 | author_email='peter.bulychev@gmail.com',
44 | url='http://clonedigger.sourceforge.net',
45 | license='GPL',
46 | packages=find_packages(),
47 | include_package_data=True,
48 | zip_safe=False,
49 | install_requires=['setuptools'],
50 | entry_points=entry_points,
51 | )
52 |
53 |
--------------------------------------------------------------------------------
/org.clonedigger/src/org/clonedigger/Activator.java:
--------------------------------------------------------------------------------
1 | package org.clonedigger;
2 |
3 | import org.eclipse.core.runtime.IStatus;
4 | import org.eclipse.core.runtime.Status;
5 | import org.eclipse.jface.resource.ImageDescriptor;
6 | import org.eclipse.ui.plugin.AbstractUIPlugin;
7 | import org.osgi.framework.BundleContext;
8 |
9 | /**
10 | * The activator class controls the plug-in life cycle
11 | */
12 | public class Activator extends AbstractUIPlugin {
13 |
14 | // The plug-in ID
15 | public static final String PLUGIN_ID = "org.clonedigger";
16 |
17 | // The shared instance
18 | private static Activator plugin;
19 |
20 | public Activator() {
21 | }
22 |
23 | /*
24 | * (non-Javadoc)
25 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
26 | */
27 | public void start(BundleContext context) throws Exception {
28 | super.start(context);
29 | plugin = this;
30 | }
31 |
32 | /*
33 | * (non-Javadoc)
34 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
35 | */
36 | public void stop(BundleContext context) throws Exception {
37 | plugin = null;
38 | super.stop(context);
39 | }
40 |
41 | /**
42 | * Returns the shared instance
43 | *
44 | * @return the shared instance
45 | */
46 | public static Activator getDefault() {
47 | return plugin;
48 | }
49 |
50 | public static void log(Throwable e) {
51 | try {
52 | Status s = new Status(IStatus.ERROR, PLUGIN_ID,
53 | e.getMessage() != null ? e.getMessage() : "No message gotten.", e);
54 | getDefault().getLog().log(s);
55 | } catch (Throwable e1) {
56 | //logging should never fail!
57 | }
58 | }
59 |
60 | /**
61 | * Returns an image descriptor for the image file at the given
62 | * plug-in relative path
63 | *
64 | * @param path the path
65 | * @return the image descriptor
66 | */
67 | public static ImageDescriptor getImageDescriptor(String path) {
68 | return imageDescriptorFromPlugin(PLUGIN_ID, path);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/org.clonedigger/src/org/clonedigger/ResultBrowser.java:
--------------------------------------------------------------------------------
1 | package org.clonedigger;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.net.URI;
8 | import java.net.URISyntaxException;
9 | import java.nio.MappedByteBuffer;
10 | import java.nio.channels.FileChannel;
11 |
12 | import org.eclipse.core.filesystem.EFS;
13 | import org.eclipse.core.filesystem.IFileStore;
14 | import org.eclipse.core.resources.IFile;
15 | import org.eclipse.core.resources.ResourcesPlugin;
16 | import org.eclipse.core.runtime.Path;
17 | import org.eclipse.jface.text.BadLocationException;
18 | import org.eclipse.jface.text.IDocument;
19 | import org.eclipse.swt.SWT;
20 | import org.eclipse.swt.browser.LocationEvent;
21 | import org.eclipse.swt.browser.LocationListener;
22 | import org.eclipse.swt.widgets.Composite;
23 | import org.eclipse.swt.widgets.FileDialog;
24 | import org.eclipse.swt.widgets.Shell;
25 | import org.eclipse.ui.IEditorInput;
26 | import org.eclipse.ui.IWorkbenchPage;
27 | import org.eclipse.ui.PartInitException;
28 | import org.eclipse.ui.PlatformUI;
29 | import org.eclipse.ui.ide.FileStoreEditorInput;
30 | import org.eclipse.ui.ide.IDE;
31 | import org.eclipse.ui.internal.browser.WebBrowserEditor;
32 | import org.eclipse.ui.part.FileEditorInput;
33 | import org.eclipse.ui.texteditor.ITextEditor;
34 |
35 | /**
36 | * Implementation of WebBrowser with support for "clone:" links.
37 | * Make a hook on location change event and navigate to editor.
38 | */
39 | @SuppressWarnings("restriction")
40 | public class ResultBrowser extends WebBrowserEditor {
41 |
42 | private class CloneLocation implements LocationListener
43 | {
44 |
45 | public void changed(LocationEvent event) {}
46 |
47 | public void changing(LocationEvent event)
48 | {
49 | boolean WINDOWS = java.io.File.separatorChar == '\\';
50 |
51 | if(event.location.startsWith("clone:"))
52 | {
53 | event.doit = false;
54 | try
55 | {
56 | String [] args = event.location.split("clone://|\\?|&");
57 |
58 | //patch on strange browsersupport behavior on links with "\" character
59 | args[1] = args[1].replaceAll("/+$", "");
60 | if(WINDOWS) args[1] = args[1].replaceAll("/", "\\\\");
61 |
62 | IWorkbenchPage page = PlatformUI.getWorkbench()
63 | .getActiveWorkbenchWindow().getActivePage();
64 |
65 | IFile file = ResourcesPlugin.getWorkspace().getRoot().
66 | getFileForLocation(Path.fromOSString(args[1]));
67 |
68 | IEditorInput editInput = null;
69 |
70 | if(file == null)
71 | {
72 | // Process external files, files that arent present in workspace for some reasons.
73 | IFileStore fileStore = EFS.getLocalFileSystem().getStore(
74 | new URI("file:/" + args[1].replaceAll("^/+", "").replaceAll("\\\\", "/")));
75 | editInput = new FileStoreEditorInput(fileStore);
76 | }
77 | else
78 | {
79 | editInput = new FileEditorInput(file);
80 | }
81 |
82 | ITextEditor editor =
83 | (ITextEditor)IDE.openEditor(page, editInput,
84 | IDE.getEditorDescriptor(args[1]).getId(), true);
85 | //"org.python.pydev.editor.PythonEditor", true);
86 | IDocument doc = editor.getDocumentProvider().getDocument(editInput);
87 |
88 | try
89 | {
90 | int start = doc.getLineInformation(Integer.parseInt(args[2])).getOffset();
91 | int end = doc.getLineInformation(Integer.parseInt(args[3]) + 1).getOffset();
92 | editor.setHighlightRange(start, end-start, true);
93 | }
94 | catch (BadLocationException e) {
95 | Activator.log(e);
96 | }
97 | }
98 | catch (PartInitException e) {
99 | Activator.log(e);
100 | } catch (URISyntaxException e) {
101 | Activator.log(e);
102 | }
103 | }
104 |
105 | if(event.location.startsWith("http:")) event.doit = false;
106 |
107 | if(event.location.startsWith(System.getProperty("java.io.tmpdir")) ||
108 | event.location.startsWith("file:"))
109 | {
110 | String src = event.location;
111 | if(src.startsWith("file:"))
112 | {
113 | src = src.replaceAll("^file:", "");
114 | src = src.replaceAll("^/+", "");
115 | if(!WINDOWS) src = "/" + src;
116 | }
117 |
118 | event.doit = false;
119 | Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
120 | //SaveAsDialog dialog = new SaveAsDialog(shell);
121 | FileDialog dialog = new FileDialog(shell, SWT.SAVE);
122 | String[] exts = {"*.html"};
123 | dialog.setFilterExtensions(exts);
124 | String dest = dialog.open();
125 | if(dest != null)
126 | //if(dialog.open() == Window.OK)
127 | {
128 | //String dest = dialog.getResult().toOSString();
129 |
130 | //ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(dest)).
131 |
132 | //dest = ResourcesPlugin.getPlugin().find(new Path(dest)).getPath();
133 | //if(WINDOWS) dest = dest.replaceAll("^/+", "");
134 |
135 | try {
136 | copy(new File(src), new File(dest));
137 | } catch (IOException e) {
138 | Activator.log(e);
139 | }
140 | }
141 | }
142 | }
143 | }
144 |
145 | public static void copy(File source, File dest) throws IOException {
146 | FileChannel in = null, out = null;
147 | try {
148 | in = new FileInputStream(source).getChannel();
149 | out = new FileOutputStream(dest).getChannel();
150 |
151 | long size = in.size();
152 | MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
153 |
154 | out.write(buf);
155 |
156 | } finally {
157 | if (in != null) in.close();
158 | if (out != null) out.close();
159 | }
160 | }
161 |
162 | public ResultBrowser() {
163 | }
164 |
165 | @Override
166 | public void createPartControl(Composite parent) {
167 | super.createPartControl(parent);
168 | if(webBrowser == null || webBrowser.getBrowser() == null)
169 | Activator.log(new Exception("No Browser support found"));
170 | webBrowser.getBrowser().addLocationListener(new CloneLocation());
171 | }
172 |
173 | }
174 |
175 |
176 |
--------------------------------------------------------------------------------
/org.clonedigger/src/org/clonedigger/actions/UpdateAction.java:
--------------------------------------------------------------------------------
1 | package org.clonedigger.actions;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 |
6 | import org.clonedigger.Activator;
7 | import org.eclipse.core.runtime.FileLocator;
8 | import org.eclipse.core.runtime.Platform;
9 | import org.eclipse.jface.action.IAction;
10 | import org.eclipse.jface.dialogs.MessageDialog;
11 | import org.eclipse.jface.viewers.ISelection;
12 | import org.eclipse.ui.IWorkbenchWindow;
13 | import org.eclipse.ui.IWorkbenchWindowActionDelegate;
14 | import org.osgi.framework.Bundle;
15 |
16 | /**
17 | * Implementation of Update CloneDigger action.
18 | */
19 | public class UpdateAction implements IWorkbenchWindowActionDelegate
20 | {
21 | boolean WINDOWS = java.io.File.separatorChar == '\\';
22 |
23 | public UpdateAction() {
24 | }
25 |
26 | public void dispose() {
27 | }
28 |
29 | public void init(IWorkbenchWindow window) {
30 | }
31 |
32 | /**
33 | * Recursively delete directory.
34 | * @param f
35 | * @throws java.io.IOException
36 | */
37 | private void delrec(File f) throws java.io.IOException {
38 | if (f.isDirectory()) {
39 | File[] fs=f.listFiles();
40 | for (int i=0;i