├── .gitignore
├── LICENSE.txt
├── README.md
├── deploy_jars_to_repo.txt
├── pom.xml
└── src
├── main
├── java
│ └── it
│ │ └── unibz
│ │ └── sonarqube
│ │ └── plugin
│ │ ├── CodeSmellsAntiPatternsPlugin.java
│ │ ├── CodeSmellsAntiPatternsRulesDefinition.java
│ │ └── CodeSmellsAntiPatternsSensor.java
└── main.iml
└── test
├── antipattern-rules-profile.xml
├── java
├── AntiPatternRulesIT.java
└── plugin
│ └── CodeSmellsAntiPatternsSensorTest.java
├── projects
└── antipatterns
│ ├── .sonar
│ └── .sonar_lock
│ └── AntiSingletonAndClassDataPrivate.java
└── test.iml
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/java,eclipse,intellij,sonarqube
3 |
4 | ### Eclipse ###
5 |
6 | .metadata
7 | bin/
8 | tmp/
9 | *.tmp
10 | *.bak
11 | *.swp
12 | *~.nib
13 | local.properties
14 | .settings/
15 | .loadpath
16 | .recommenders
17 |
18 | # External tool builders
19 | .externalToolBuilders/
20 |
21 | # Locally stored "Eclipse launch configurations"
22 | *.launch
23 |
24 | # PyDev specific (Python IDE for Eclipse)
25 | *.pydevproject
26 |
27 | # CDT-specific (C/C++ Development Tooling)
28 | .cproject
29 |
30 | # CDT- autotools
31 | .autotools
32 |
33 | # Java annotation processor (APT)
34 | .factorypath
35 |
36 | # PDT-specific (PHP Development Tools)
37 | .buildpath
38 |
39 | # sbteclipse plugin
40 | .target
41 |
42 | # Tern plugin
43 | .tern-project
44 |
45 | # TeXlipse plugin
46 | .texlipse
47 |
48 | # STS (Spring Tool Suite)
49 | .springBeans
50 |
51 | # Code Recommenders
52 | .recommenders/
53 |
54 | # Annotation Processing
55 | .apt_generated/
56 |
57 | # Scala IDE specific (Scala & Java development for Eclipse)
58 | .cache-main
59 | .scala_dependencies
60 | .worksheet
61 |
62 | ### Eclipse Patch ###
63 | # Eclipse Core
64 | .project
65 |
66 | # JDT-specific (Eclipse Java Development Tools)
67 | .classpath
68 |
69 | # Annotation Processing
70 | .apt_generated
71 |
72 | ### Intellij ###
73 | # Ignore everything
74 | .idea
75 |
76 | # CMake
77 | cmake-build-*/
78 |
79 | # Mongo Explorer plugin
80 | .idea/**/mongoSettings.xml
81 |
82 | # File-based project format
83 | *.iws
84 |
85 | # IntelliJ
86 | out/
87 |
88 | ### Java ###
89 | # Compiled class file
90 | *.class
91 |
92 | # Log file
93 | *.log
94 |
95 | # BlueJ files
96 | *.ctxt
97 |
98 | # Mobile Tools for Java (J2ME)
99 | .mtj.tmp/
100 |
101 | # Package Files #
102 | *.jar
103 | *.war
104 | *.nar
105 | *.ear
106 | *.zip
107 | *.tar.gz
108 | *.rar
109 |
110 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
111 | hs_err_pid*
112 |
113 | ### SonarQube ###
114 | # SonarQube ignore files.
115 | #
116 | # https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
117 | # Sonar Scanner working directories
118 | .sonar/
119 | .scannerwork/
120 |
121 | # http://www.sonarlint.org/commandline/
122 | # SonarLint working directories, configuration files (including credentials)
123 | .sonarlint/
124 |
125 |
126 | # End of https://www.gitignore.io/api/java,eclipse,intellij,sonarqube
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | Sonarqube anti-pattern and code smell detection plugin
635 | Copyright (C) 2017 Giuseppe Aina, Alexandru Stan, Davide Taibi, Gustavs Venters
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Sonarqube anti-pattern and code smell detection plugin Copyright (C) 2017 Giuseppe Aina, Alexandru Stan, Davide Taibi, Gustavs Venters
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | This sonarqube plugin detects anti patterns and code smells, as defined by Martin Fowler[1](#myfootnote1), by means of the [Ptidej 5 library](https://bitbucket.org/ptidejteam/ptidej-5).
2 |
3 | ## Antipatterns and code smells detected (Metrics)
4 |
5 | **AntiSingleton:** A class that provides mutable class variables, which consequently could be used as global variables.
6 |
7 | **BaseClassKnowsDerivedClass:** A class that invokes or has at least binary-class relationship pointing to one of its subclasses.
8 |
9 | **BaseClassShouldBeAbstract:** A class that has many subclasses without being abstract.
10 |
11 | **Blob:** A large controller class that depends on data stored in surrounding data classes. A large class declares many fields and methods with a low cohesion.
12 |
13 | **ClassDataShouldBePrivate:** A class that exposes its fields, thus violating the principle of encapsulation.
14 |
15 | **ComplexClass:** A class that has (at least) one large and complex method, in terms of cyclomatic complexity and LOCs.
16 |
17 | **FunctionalDecomposition:** A main class, i.e., a class with a procedural name, such as Compute or Display, in which inheritance and polymorphism are scarcely used, that is associated with small classes, which declare many private fields and implement only a few methods.
18 |
19 | **LargeClass:** A class that has grown too large in term of LOCs.
20 |
21 | **LazyClass:** A class that has few fields and methods.
22 |
23 | **LongMethod:** A class that has (at least) a method that is very long, in term of LOCs.
24 |
25 | **LongParameterList:** A class that has (at least) one method with a too long list of parameters in comparison to the average number of parameters per methods in the system.
26 |
27 | **ManyFieldAttributesButNotComplex:** A class that declares many attributes but which is not complex and, hence, more likely to be some kind of data class holding values without providing behaviour.
28 |
29 | **MessageChains:** A class that uses a long chain of method invocations to realise (at least) one of its functionality.
30 |
31 | **RefusedParentBequest:** A class that redefines inherited method using empty bodies, thus breaking polymorphism.
32 |
33 | **SpaghettiCode:** A class with no structure, declaring long methods with no parameters, and utilising global variables.
34 |
35 | **SpeculativeGenerality:** A class that is defined as abstract but that has very few children, which do not make use of its methods
36 |
37 | **SwissArmyKnife:** A complex class that offers a high number of services, for example, a complex class implementing a high number of interfaces.
38 |
39 | **TraditionBreaker:** A class that inherits from a large parent class but that provides little behaviour and without subclasses.
40 |
41 | ## Licence
42 |
43 | GNU Public License v3.
44 |
45 | ## Compatibility
46 | This plug-in has been tested with Sonarqube 6.3 and 6.7
47 |
48 | ## How to install
49 |
50 | 1. Copy jar file in the plugins folder of your Sonarqube installation.
51 |
52 | 2. Restart the Sonarqube process in your machine.
53 |
54 | 3. Add plugin rules to your Quality Profile. They can be filtered by repository or tag name:
55 | 1. _Repository:_ "Code-smell rules repository Java"
56 | 2. _Tags:_ "antipattern","code-smell"
57 |
58 | ## Compiling the source code
59 |
60 | Run `mvn clean verify` to ensure the launching of integration tests while building
61 |
62 | Run `mvn sonar:sonar -Dsonar.login=PRIVATE_TOKEN` to analyse the project on [sonarcloud.io](https://sonarcloud.io/dashboard?id=it.unibz.sonarqube_extension%3Acodesmellsantipatterns)
63 |
64 | ## Roadmap
65 |
66 | * Increasing analysis performances
67 | * Standalone implementation (without the ptidej-5 libraries)
68 | * Integration tests and reimplementation of every single code smell from [ptidej source](https://github.com/ptidejteam/SmellDetectionCaller/tree/master/SAD/src/sad/codesmell/detection/repository)
69 | * Empirical study to test the code smell effectiveness
70 |
71 |
72 | ## References
73 |
74 | 1: Fowler, Martin. "CodeSmell". http://martinfowler.com/. Retrieved July 2014
75 |
--------------------------------------------------------------------------------
/deploy_jars_to_repo.txt:
--------------------------------------------------------------------------------
1 | # The jars in /lib directory can be added to a maven repo using the commands in this file
2 | # - Needs admin access to the repo (in Windows login data is normally saved in C:/Users//.m2/settings.xml)
3 | # - https://maven.apache.org/settings.html
4 | #
5 | # To make a repository made from [https://github.com/renaudcerrato/appengine-maven-repository] public:
6 | # - in resource/RepositoryResource.java, remove/comment the lines with annotation @RolesAllowed(.., ROLE_READ, ..)
7 | # - recompile project in google console
8 |
9 | mvn deploy:deploy-file -DgroupId=ptidej
10 | -DartifactId=ptidej
11 | -Dversion=1.0
12 | -Dpackaging=jar
13 | -Dfile=${project.basedir}/lib/ptidej-1.0.jar
14 | -DrepositoryId=gv-maven-repo
15 | -Durl=https://gv-maven-repo.appspot.com/
16 |
17 | mvn deploy:deploy-file -DgroupId=padl-analyses
18 | -DartifactId=padl-analyses
19 | -Dversion=1.0
20 | -Dpackaging=jar
21 | -Dfile=${project.basedir}/lib/padl-analyses-1.0.jar
22 | -DrepositoryId=gv-maven-repo
23 | -Durl=https://gv-maven-repo.appspot.com/
24 |
25 | mvn deploy:deploy-file -DgroupId=padl-aol
26 | -DartifactId=padl-aol
27 | -Dversion=1.0
28 | -Dpackaging=jar
29 | -Dfile=${project.basedir}/lib/padl-aol-1.0.jar
30 | -DrepositoryId=gv-maven-repo
31 | -Durl=https://gv-maven-repo.appspot.com/
32 |
33 | mvn deploy:deploy-file -DgroupId=commons-csv
34 | -DartifactId=commons-csv
35 | -Dversion=1.0
36 | -Dpackaging=jar
37 | -Dfile=${project.basedir}/lib/commons-csv-1.0.jar
38 | -DrepositoryId=gv-maven-repo
39 | -Durl=https://gv-maven-repo.appspot.com/
40 |
41 | mvn deploy:deploy-file -DgroupId=lang
42 | -DartifactId=lang
43 | -Dversion=1.0
44 | -Dpackaging=jar
45 | -Dfile=${project.basedir}/lib/lang-1.0.jar
46 | -DrepositoryId=gv-maven-repo
47 | -Durl=https://gv-maven-repo.appspot.com/
48 |
49 | mvn deploy:deploy-file -DgroupId=padl-cpp
50 | -DartifactId=padl-cpp
51 | -Dversion=1.0
52 | -Dpackaging=jar
53 | -Dfile=${project.basedir}/lib/padl-cpp-1.0.jar
54 | -DrepositoryId=gv-maven-repo
55 | -Durl=https://gv-maven-repo.appspot.com/
56 |
57 | mvn deploy:deploy-file -DgroupId=padl-csharpv1
58 | -DartifactId=padl-csharpv1
59 | -Dversion=1.0
60 | -Dpackaging=jar
61 | -Dfile=${project.basedir}/lib/padl-csharpv1-1.0.jar
62 | -DrepositoryId=gv-maven-repo
63 | -Durl=https://gv-maven-repo.appspot.com/
64 |
65 | mvn deploy:deploy-file -DgroupId=padl-csharpv2
66 | -DartifactId=padl-csharpv2
67 | -Dversion=1.0
68 | -Dpackaging=jar
69 | -Dfile=${project.basedir}/lib/padl-csharpv2-1.0.jar
70 | -DrepositoryId=gv-maven-repo
71 | -Durl=https://gv-maven-repo.appspot.com/
72 |
73 | mvn deploy:deploy-file -DgroupId=padl-creator-cpp
74 | -DartifactId=padl-creator-cpp
75 | -Dversion=1.0
76 | -Dpackaging=jar
77 | -Dfile=${project.basedir}/lib/padl-creator-cpp-1.0.jar
78 | -DrepositoryId=gv-maven-repo
79 | -Durl=https://gv-maven-repo.appspot.com/
80 |
81 | mvn deploy:deploy-file -DgroupId=padl-creator
82 | -DartifactId=padl-creator
83 | -Dversion=1.0
84 | -Dpackaging=jar
85 | -Dfile=${project.basedir}/lib/padl-creator-1.0.jar
86 | -DrepositoryId=gv-maven-repo
87 | -Durl=https://gv-maven-repo.appspot.com/
88 |
89 | mvn deploy:deploy-file -DgroupId=cfparse
90 | -DartifactId=cfparse
91 | -Dversion=1.0
92 | -Dpackaging=jar
93 | -Dfile=${project.basedir}/lib/cfparse-1.0.jar
94 | -DrepositoryId=gv-maven-repo
95 | -Durl=https://gv-maven-repo.appspot.com/
96 |
97 | mvn deploy:deploy-file -DgroupId=bcel-findbugs
98 | -DartifactId=bcel-findbugs
99 | -Dversion=1.0
100 | -Dpackaging=jar
101 | -Dfile=${project.basedir}/lib/bcel-findbugs-1.0.jar
102 | -DrepositoryId=gv-maven-repo
103 | -Durl=https://gv-maven-repo.appspot.com/
104 |
105 | mvn deploy:deploy-file -DgroupId=ptidej-smell
106 | -DartifactId=ptidej-smell
107 | -Dversion=1.0
108 | -Dpackaging=jar
109 | -Dfile=${project.basedir}/lib/ptidej-smell-1.0.jar
110 | -DrepositoryId=gv-maven-repo
111 | -Durl=https://gv-maven-repo.appspot.com/
112 |
113 | mvn deploy:deploy-file -DgroupId=javax.annotation
114 | -DartifactId=javax.annotation
115 | -Dversion=1.0
116 | -Dpackaging=jar
117 | -Dfile=${project.basedir}/lib/javax.annotation-1.0.jar
118 | -DrepositoryId=gv-maven-repo
119 | -Durl=https://gv-maven-repo.appspot.com/
120 |
121 | mvn deploy:deploy-file -DgroupId=javax.inject
122 | -DartifactId=javax.inject
123 | -Dversion=1.0
124 | -Dpackaging=jar
125 | -Dfile=${project.basedir}/lib/javax.inject-1.0.jar
126 | -DrepositoryId=gv-maven-repo
127 | -Durl=https://gv-maven-repo.appspot.com/
128 |
129 | mvn deploy:deploy-file -DgroupId=motifs
130 | -DartifactId=motifs
131 | -Dversion=1.0
132 | -Dpackaging=jar
133 | -Dfile=${project.basedir}/lib/motifs-1.0.jar
134 | -DrepositoryId=gv-maven-repo
135 | -Durl=https://gv-maven-repo.appspot.com/
136 |
137 | mvn deploy:deploy-file -DgroupId=org.eclipse.core.runtime_3.11.1.v20150903
138 | -DartifactId=org.eclipse.core.runtime_3.11.1.v20150903
139 | -Dversion=1804
140 | -Dpackaging=jar
141 | -Dfile=${project.basedir}/lib/org.eclipse.core.runtime_3.11.1.v20150903-1804.jar
142 | -DrepositoryId=gv-maven-repo
143 | -Durl=https://gv-maven-repo.appspot.com/
144 |
145 | mvn deploy:deploy-file -DgroupId=org.eclipse.core.resources
146 | -DartifactId=org.eclipse.core.resources
147 | -Dversion=1.0
148 | -Dpackaging=jar
149 | -Dfile=${project.basedir}/lib/org.eclipse.core.resources-1.0.jar
150 | -DrepositoryId=gv-maven-repo
151 | -Durl=https://gv-maven-repo.appspot.com/
152 |
153 | mvn deploy:deploy-file -DgroupId=org.eclipse.core.contenttype
154 | -DartifactId=org.eclipse.core.contenttype
155 | -Dversion=1.0
156 | -Dpackaging=jar
157 | -Dfile=${project.basedir}/lib/org.eclipse.core.contenttype-1.0.jar
158 | -DrepositoryId=gv-maven-repo
159 | -Durl=https://gv-maven-repo.appspot.com/
160 |
161 | mvn deploy:deploy-file -DgroupId=org.eclipse.core.jobs
162 | -DartifactId=org.eclipse.core.jobs
163 | -Dversion=1.0
164 | -Dpackaging=jar
165 | -Dfile=${project.basedir}/lib/org.eclipse.core.jobs-1.0.jar
166 | -DrepositoryId=gv-maven-repo
167 | -Durl=https://gv-maven-repo.appspot.com/
168 |
169 | mvn deploy:deploy-file -DgroupId=org.eclipse.equinox.app
170 | -DartifactId=org.eclipse.equinox.app
171 | -Dversion=1.0
172 | -Dpackaging=jar
173 | -Dfile=${project.basedir}/lib/org.eclipse.equinox.app-1.0.jar
174 | -DrepositoryId=gv-maven-repo
175 | -Durl=https://gv-maven-repo.appspot.com/
176 |
177 | mvn deploy:deploy-file -DgroupId=org.eclipse.equinox.common
178 | -DartifactId=org.eclipse.equinox.common
179 | -Dversion=1.0
180 | -Dpackaging=jar
181 | -Dfile=${project.basedir}/lib/org.eclipse.equinox.common-1.0.jar
182 | -DrepositoryId=gv-maven-repo
183 | -Durl=https://gv-maven-repo.appspot.com/
184 |
185 | mvn deploy:deploy-file -DgroupId=org.eclipse.equinox.preferences
186 | -DartifactId=org.eclipse.equinox.preferences
187 | -Dversion=1.0
188 | -Dpackaging=jar
189 | -Dfile=${project.basedir}/lib/org.eclipse.equinox.preferences-1.0.jar
190 | -DrepositoryId=gv-maven-repo
191 | -Durl=https://gv-maven-repo.appspot.com/
192 |
193 | mvn deploy:deploy-file -DgroupId=org.eclipse.equinox.registry
194 | -DartifactId=org.eclipse.equinox.registry
195 | -Dversion=1.0
196 | -Dpackaging=jar
197 | -Dfile=${project.basedir}/lib/org.eclipse.equinox.registry-1.0.jar
198 | -DrepositoryId=gv-maven-repo
199 | -Durl=https://gv-maven-repo.appspot.com/
200 |
201 | mvn deploy:deploy-file -DgroupId=org.eclipse.jdt.compiler.apt
202 | -DartifactId=org.eclipse.jdt.compiler.apt
203 | -Dversion=1.0
204 | -Dpackaging=jar
205 | -Dfile=${project.basedir}/lib/org.eclipse.jdt.compiler.apt-1.0.jar
206 | -DrepositoryId=gv-maven-repo
207 | -Durl=https://gv-maven-repo.appspot.com/
208 |
209 | mvn deploy:deploy-file -DgroupId=org.eclipse.jdt.compiler.tool
210 | -DartifactId=org.eclipse.jdt.compiler.tool
211 | -Dversion=1.0
212 | -Dpackaging=jar
213 | -Dfile=${project.basedir}/lib/org.eclipse.jdt.compiler.tool-1.0.jar
214 | -DrepositoryId=gv-maven-repo
215 | -Durl=https://gv-maven-repo.appspot.com/
216 |
217 | mvn deploy:deploy-file -DgroupId=org.eclipse.jdt.core
218 | -DartifactId=org.eclipse.jdt.core
219 | -Dversion=1.0
220 | -Dpackaging=jar
221 | -Dfile=${project.basedir}/lib/org.eclipse.jdt.core-1.0.jar
222 | -DrepositoryId=gv-maven-repo
223 | -Durl=https://gv-maven-repo.appspot.com/
224 |
225 | mvn deploy:deploy-file -DgroupId=org.eclipse.jface.text
226 | -DartifactId=org.eclipse.jface.text
227 | -Dversion=1.0
228 | -Dpackaging=jar
229 | -Dfile=${project.basedir}/lib/org.eclipse.jface.text-1.0.jar
230 | -DrepositoryId=gv-maven-repo
231 | -Durl=https://gv-maven-repo.appspot.com/
232 |
233 | mvn deploy:deploy-file -DgroupId=org.eclipse.osgi.compatibility.state
234 | -DartifactId=org.eclipse.osgi.compatibility.state
235 | -Dversion=1.0
236 | -Dpackaging=jar
237 | -Dfile=${project.basedir}/lib/org.eclipse.osgi.compatibility.state-1.0.jar
238 | -DrepositoryId=gv-maven-repo
239 | -Durl=https://gv-maven-repo.appspot.com/
240 |
241 | mvn deploy:deploy-file -DgroupId=org.eclipse.osgi
242 | -DartifactId=org.eclipse.osgi
243 | -Dversion=1.0
244 | -Dpackaging=jar
245 | -Dfile=${project.basedir}/lib/org.eclipse.osgi-1.0.jar
246 | -DrepositoryId=gv-maven-repo
247 | -Durl=https://gv-maven-repo.appspot.com/
248 |
249 | mvn deploy:deploy-file -DgroupId=org.eclipse.text
250 | -DartifactId=org.eclipse.text
251 | -Dversion=1.0
252 | -Dpackaging=jar
253 | -Dfile=${project.basedir}/lib/org.eclipse.text-1.0.jar
254 | -DrepositoryId=gv-maven-repo
255 | -Durl=https://gv-maven-repo.appspot.com/
256 |
257 | mvn deploy:deploy-file -DgroupId=org.eclipse.core.runtime.compatibility.registry
258 | -DartifactId=org.eclipse.core.runtime.compatibility.registry
259 | -Dversion=1.0
260 | -Dpackaging=jar
261 | -Dfile=${project.basedir}/lib/org.eclipse.core.runtime.compatibility.registry-1.0.jar
262 | -DrepositoryId=gv-maven-repo
263 | -Durl=https://gv-maven-repo.appspot.com/
264 |
265 |
266 | mvn deploy:deploy-file -DgroupId=commons-io-for-padl
267 | -DartifactId=commons-io
268 | -Dversion=1.0
269 | -Dpackaging=jar
270 | -Dfile=${project.basedir}/lib/commons-io-1.0.jar
271 | -DrepositoryId=gv-maven-repo
272 | -Durl=https://gv-maven-repo.appspot.com/
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 | it.unibz.sonarqube_extension
6 | codesmellsantipatterns
7 | 0.8
8 | Code Smells and Anti Patterns detection
9 | A plugin for analysing code smells and antipatterns through the ptidej library
10 | https://github.com/davidetaibi/sonarqube-anti-patterns-code-smells
11 | 2016
12 |
13 | sonar-plugin
14 |
15 | UTF-8
16 | 6.3
17 | 1.8
18 |
19 |
20 |
21 |
22 | Free University of Bozen-Bolzano
23 | https://www.unibz.it
24 |
25 |
26 |
27 |
28 | GNU GPLv3
29 | http://www.gnu.org/licenses/
30 | repo
31 |
32 |
33 |
34 |
35 |
36 | GAina
37 | Giuseppe Aina
38 | +1
39 |
40 |
41 | AStan
42 | Alexandru Stan
43 | +1
44 |
45 |
46 | DTaibi
47 | Davide Taibi
48 | +1
49 |
50 |
51 | GVenters
52 | Gustavs Venters
53 | +1
54 |
55 |
56 |
57 |
58 | scm:git:git@github.com:davidetaibi/sonarqube-anti-patterns-code-smells.git
59 | scm:git:git@github.com:davidetaibi/sonarqube-anti-patterns-code-smells.git
60 | https://github.com/davidetaibi/sonarqube-anti-patterns-code-smells
61 |
62 |
63 |
64 | Git
65 | https://github.com/davidetaibi/sonarqube-anti-patterns-code-smells/issues
66 |
67 |
68 |
69 |
70 |
71 | gv-maven-repo
72 | gv-maven-repo
73 | https://gv-maven-repo.appspot.com/
74 |
75 |
76 |
77 |
78 |
79 |
80 | org.sonarsource.sonarqube
81 | sonar-plugin-api
82 | ${sonar.apiVersion}
83 | provided
84 |
85 |
86 |
87 |
88 | org.sonarsource.orchestrator
89 | sonar-orchestrator
90 | 3.13
91 |
92 |
93 | commons-logging
94 | commons-logging
95 | 1.2
96 | provided
97 |
98 |
99 |
100 |
101 | padl-analyses
102 | padl-analyses
103 | 1.0
104 |
105 |
106 |
107 | padl-aol
108 | padl-aol
109 | 1.0
110 |
111 |
112 |
113 | org.apache.commons
114 | commons-csv
115 | 1.0
116 |
117 |
118 |
119 | lang
120 | lang
121 | 1.0
122 |
123 |
124 |
125 | commons-io-for-padl
126 | commons-io
127 | 1.0
128 |
129 |
130 |
131 | ptidej
132 | ptidej
133 | 1.0
134 |
135 |
136 |
137 | padl-cpp
138 | padl-cpp
139 | 1.0
140 |
141 |
142 |
143 | padl-csharpv1
144 | padl-csharpv1
145 | 1.0
146 |
147 |
148 |
149 | padl-csharpv2
150 | padl-csharpv2
151 | 1.0
152 |
153 |
154 |
155 | padl-creator-cpp
156 | padl-creator-cpp
157 | 1.0
158 |
159 |
160 |
161 | padl-creator
162 | padl-creator
163 | 1.0
164 |
165 |
166 |
167 | cfparse
168 | cfparse
169 | 1.0
170 |
171 |
172 |
173 | bcel-findbugs
174 | bcel-findbugs
175 | 1.0
176 |
177 |
178 |
179 |
180 |
181 | ptidej-smell
182 | ptidej-smell
183 | 1.0
184 |
185 |
186 |
187 | org.eclipse.core.runtime_3.11.1.v20150903
188 | org.eclipse.core.runtime_3.11.1.v20150903
189 | 1804
190 |
191 |
192 |
193 | org.eclipse.core.resources
194 | org.eclipse.core.resources
195 | 1.0
196 |
197 |
198 |
199 |
200 | javax.annotation
201 | javax.annotation
202 | 1.0
203 |
204 |
205 |
206 | javax.inject
207 | javax.inject
208 | 1.0
209 |
210 |
211 |
212 |
213 | org.eclipse.core.contenttype
214 | org.eclipse.core.contenttype
215 | 1.0
216 |
217 |
218 |
219 | org.eclipse.core.jobs
220 | org.eclipse.core.jobs
221 | 1.0
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 | org.eclipse.equinox.app
233 | org.eclipse.equinox.app
234 | 1.0
235 |
236 |
237 |
238 | org.eclipse.equinox.common
239 | org.eclipse.equinox.common
240 | 1.0
241 |
242 |
243 |
244 | org.eclipse.equinox.preferences
245 | org.eclipse.equinox.preferences
246 | 1.0
247 |
248 |
249 |
250 | org.eclipse.equinox.registry
251 | org.eclipse.equinox.registry
252 | 1.0
253 |
254 |
255 |
256 | org.eclipse.jdt.compiler.apt
257 | org.eclipse.jdt.compiler.apt
258 | 1.0
259 |
260 |
261 |
262 | org.eclipse.jdt.compiler.tool
263 | org.eclipse.jdt.compiler.tool
264 | 1.0
265 |
266 |
267 |
268 | org.eclipse.jdt.core
269 | org.eclipse.jdt.core
270 | 1.0
271 |
272 |
273 |
274 | org.eclipse.jface.text
275 | org.eclipse.jface.text
276 | 1.0
277 |
278 |
279 |
280 | org.eclipse.osgi.compatibility.state
281 | org.eclipse.osgi.compatibility.state
282 | 1.0
283 |
284 |
285 |
286 | org.eclipse.osgi
287 | org.eclipse.osgi
288 | 1.0
289 |
290 |
291 |
292 | org.eclipse.text
293 | org.eclipse.text
294 | 1.0
295 |
296 |
297 |
298 | org.eclipse.core.runtime.compatibility.registry
299 | org.eclipse.core.runtime.compatibility.registry
300 | 1.0
301 |
302 |
303 |
304 | motifs
305 | motifs
306 | 1.0
307 |
308 |
309 |
310 |
311 | org.mockito
312 | mockito-core
313 | 2.10.0
314 | test
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 | org.sonarsource.sonar-packaging-maven-plugin
326 | sonar-packaging-maven-plugin
327 | 1.17
328 | true
329 |
330 | it.unibz.sonarqube.plugin.CodeSmellsAntiPatternsPlugin
331 | codesmellsantipatterns
332 | ${project.name}
333 | sonar-codesmellsantipatterns-plugin-${project.version}
334 |
335 |
336 |
337 |
338 | org.apache.maven.plugins
339 | maven-compiler-plugin
340 | 3.6.1
341 |
342 | ${jdk.min.version}
343 | ${jdk.min.version}
344 |
345 |
346 |
347 |
348 |
349 | org.codehaus.mojo
350 | native2ascii-maven-plugin
351 | 1.0-beta-1
352 |
353 |
354 |
355 | native2ascii
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 | org.apache.maven.plugins
364 | maven-failsafe-plugin
365 | 2.20.1
366 |
367 |
368 |
369 | integration-test
370 | verify
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 | org.sonarsource.scanner.maven
379 | sonar-maven-plugin
380 | 3.2
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 | sonar
389 |
390 | true
391 |
392 |
393 | https://sonarcloud.io
394 | smells-good
395 | java
396 |
397 |
398 |
399 |
400 |
401 |
402 |
--------------------------------------------------------------------------------
/src/main/java/it/unibz/sonarqube/plugin/CodeSmellsAntiPatternsPlugin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Sonarqube anti-pattern and code smell detection plugin
3 | * Copyright (C) 2017 Giuseppe Aina, Alexandru Stan, Davide Taibi, Gustavs Venters
4 | *
5 | * This program 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 | * This program 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 this program. If not, see .
17 | */
18 | package it.unibz.sonarqube.plugin;
19 |
20 | import org.sonar.api.Plugin;
21 |
22 |
23 |
24 | public class CodeSmellsAntiPatternsPlugin implements Plugin {
25 |
26 | @Override
27 | public void define(Context context) {
28 | context.addExtensions(
29 | CodeSmellsAntiPatternsRulesDefinition.class,
30 | CodeSmellsAntiPatternsSensor.class
31 | );
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/it/unibz/sonarqube/plugin/CodeSmellsAntiPatternsRulesDefinition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Sonarqube anti-pattern and code smell detection plugin
3 | * Copyright (C) 2017 Giuseppe Aina, Alexandru Stan, Davide Taibi, Gustavs Venters
4 | *
5 | * This program 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 | * This program 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 this program. If not, see .
17 | */
18 | package it.unibz.sonarqube.plugin;
19 |
20 | import org.slf4j.Logger;
21 | import org.slf4j.LoggerFactory;
22 | import org.sonar.api.rule.RuleKey;
23 | import org.sonar.api.rule.Severity;
24 | import org.sonar.api.server.rule.RuleParamType;
25 | import org.sonar.api.server.rule.RulesDefinition;
26 |
27 | public class CodeSmellsAntiPatternsRulesDefinition implements RulesDefinition {
28 |
29 |
30 | private static Logger LOG = LoggerFactory.getLogger(CodeSmellsAntiPatternsRulesDefinition.class);
31 |
32 |
33 | static final String REPOSITORY = "code_smells";
34 | static final RuleKey COMPLEX_CLASS = RuleKey.of(REPOSITORY, "complex_class");
35 | static final RuleKey BLOB_CLASS = RuleKey.of(REPOSITORY, "blob_class");
36 | static final RuleKey CLASS_DATA_PRIVATE = RuleKey.of(REPOSITORY, "class_data_private");
37 | static final RuleKey FUNCTIONAL_DECOMPOSITION = RuleKey.of(REPOSITORY, "functional_decomposition");
38 | static final RuleKey SPAGHETTI_CODE = RuleKey.of(REPOSITORY, "spaghetti_code");
39 | static final RuleKey ANTISINGLETON = RuleKey.of(REPOSITORY, "antisingleton");
40 | static final RuleKey BASECLASS_KNOWS_DERIVED = RuleKey.of(REPOSITORY, "baseclass_knows_derived");
41 | static final RuleKey BASECLASS_ABSTRACT = RuleKey.of(REPOSITORY, "baseclass_abstract");
42 | static final RuleKey LARGE_CLASS = RuleKey.of(REPOSITORY, "large_class");
43 | static final RuleKey LAZY_CLASS = RuleKey.of(REPOSITORY, "lazy_class");
44 | static final RuleKey LONG_METHOD = RuleKey.of(REPOSITORY, "long_method");
45 | static final RuleKey LONG_PARAMETER_LIST = RuleKey.of(REPOSITORY, "long_parameter_list");
46 | static final RuleKey MANY_FIELD_ATTRIBUTES_NOT_COMPLEX = RuleKey.of(REPOSITORY, "many_field_attributes_not_complex");
47 | static final RuleKey MESSAGE_CHAINS = RuleKey.of(REPOSITORY, "message_chains");
48 | static final RuleKey REFUSED_PARENT_BEQUEST = RuleKey.of(REPOSITORY, "refused_parent_bequest");
49 | static final RuleKey SPECULATIVE_GENERALITY = RuleKey.of(REPOSITORY, "speculative_generality");
50 | static final RuleKey SWISS_ARMY_KNIFE = RuleKey.of(REPOSITORY, "swiss_army_knife");
51 | static final RuleKey TRADITION_BREAKER = RuleKey.of(REPOSITORY, "tradition_breaker");
52 | static final RuleKey[] ALL_RULES =
53 | {COMPLEX_CLASS, BLOB_CLASS, CLASS_DATA_PRIVATE, FUNCTIONAL_DECOMPOSITION, SPAGHETTI_CODE,
54 | ANTISINGLETON, BASECLASS_KNOWS_DERIVED, BASECLASS_ABSTRACT, LARGE_CLASS, LAZY_CLASS,
55 | LONG_METHOD, LONG_PARAMETER_LIST, MANY_FIELD_ATTRIBUTES_NOT_COMPLEX, MESSAGE_CHAINS,
56 | REFUSED_PARENT_BEQUEST, SPECULATIVE_GENERALITY, SWISS_ARMY_KNIFE, TRADITION_BREAKER };
57 |
58 | private static final String TAG_CODESMELL = "code-smell";
59 | private static final String TAG_ANTIPATTERN = "antipattern";
60 |
61 | private static final String ACCEPT_WHITESPACE_PARAM = "acceptWhitespace";
62 | private static final String ACCEPT_WHITESPACES_DESCRIPTION = "Accept whitespaces on the line";
63 |
64 | @Override
65 | public void define(final Context context) {
66 |
67 | final NewRepository repository = context.createRepository(REPOSITORY, "java").setName("Code-smell rules repository");
68 |
69 |
70 | final NewRule complex_class = repository.createRule(COMPLEX_CLASS.rule())
71 | .setName("Complex Class")
72 | .setHtmlDescription("A class having a high cyclomatic complexity")
73 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
74 | .setSeverity(Severity.MAJOR);
75 | complex_class
76 | .setDebtRemediationFunction(complex_class.debtRemediationFunctions().linearWithOffset("1h", "30min"));
77 | complex_class.createParam(ACCEPT_WHITESPACE_PARAM)
78 | .setDefaultValue("false")
79 | .setType(RuleParamType.BOOLEAN)
80 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
81 |
82 | final NewRule blob = repository.createRule(BLOB_CLASS.rule())
83 | .setName("Blob class")
84 | .setHtmlDescription("A large class with different responsibilities that monopolizes most of the system’s processing")
85 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
86 | .setSeverity(Severity.MAJOR);
87 | blob .setDebtRemediationFunction(blob.debtRemediationFunctions().linearWithOffset("1h", "30min"));
88 | blob.createParam(ACCEPT_WHITESPACE_PARAM)
89 | .setDefaultValue("false")
90 | .setType(RuleParamType.BOOLEAN)
91 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
92 |
93 | final NewRule clDataPrivate = repository.createRule(CLASS_DATA_PRIVATE.rule())
94 | .setName("Class Data Should be Private")
95 | .setHtmlDescription("A class exposing its attributes, violating the information hiding principle")
96 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
97 | .setSeverity(Severity.MAJOR);
98 | clDataPrivate
99 | .setDebtRemediationFunction(clDataPrivate.debtRemediationFunctions().linearWithOffset("1h", "30min"));
100 | clDataPrivate.createParam(ACCEPT_WHITESPACE_PARAM)
101 | .setDefaultValue("false")
102 | .setType(RuleParamType.BOOLEAN)
103 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
104 |
105 | final NewRule functDecomposition = repository.createRule(FUNCTIONAL_DECOMPOSITION.rule())
106 | .setName("Functional Decomposition")
107 | .setHtmlDescription("A class where inheritance and polymorphism are poorly used, declaring many private fields and implementing few methods")
108 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
109 | .setSeverity(Severity.MAJOR);
110 | functDecomposition
111 | .setDebtRemediationFunction(functDecomposition.debtRemediationFunctions().linearWithOffset("1h", "30min"));
112 | functDecomposition.createParam(ACCEPT_WHITESPACE_PARAM)
113 | .setDefaultValue("false")
114 | .setType(RuleParamType.BOOLEAN)
115 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
116 |
117 | final NewRule spaghettiCode = repository.createRule(SPAGHETTI_CODE.rule())
118 | .setName("Spaghetti Code")
119 | .setHtmlDescription("A class without structure that declares long methods without parameters")
120 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
121 | .setSeverity(Severity.MAJOR);
122 | spaghettiCode
123 | .setDebtRemediationFunction(spaghettiCode.debtRemediationFunctions().linearWithOffset("1h", "30min"));
124 | spaghettiCode.createParam(ACCEPT_WHITESPACE_PARAM)
125 | .setDefaultValue("false")
126 | .setType(RuleParamType.BOOLEAN)
127 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
128 |
129 | final NewRule antisingleton = repository.createRule(ANTISINGLETON.rule())
130 | .setName("Antisingleton")
131 | .setHtmlDescription("A class that provides mutable class variables, which consequently could be used as global variables")
132 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
133 | .setSeverity(Severity.MAJOR);
134 | antisingleton
135 | .setDebtRemediationFunction(antisingleton.debtRemediationFunctions().linearWithOffset("1h", "30min"));
136 | antisingleton.createParam(ACCEPT_WHITESPACE_PARAM)
137 | .setDefaultValue("false")
138 | .setType(RuleParamType.BOOLEAN)
139 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
140 |
141 | final NewRule baseclassknows = repository.createRule(BASECLASS_KNOWS_DERIVED.rule())
142 | .setName("BaseClassKnowsDerivedClass")
143 | .setHtmlDescription("A class that invokes or has at least binary-class relationship pointing to one of its subclasses")
144 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
145 | .setSeverity(Severity.MAJOR);
146 | baseclassknows
147 | .setDebtRemediationFunction(baseclassknows.debtRemediationFunctions().linearWithOffset("1h", "30min"));
148 | baseclassknows.createParam(ACCEPT_WHITESPACE_PARAM)
149 | .setDefaultValue("false")
150 | .setType(RuleParamType.BOOLEAN)
151 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
152 |
153 | final NewRule baseclassabstr = repository.createRule(BASECLASS_ABSTRACT.rule())
154 | .setName("BaseClassShouldBeAbstract")
155 | .setHtmlDescription("A class that has many subclasses without being abstract")
156 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
157 | .setSeverity(Severity.MAJOR);
158 | baseclassabstr
159 | .setDebtRemediationFunction(baseclassabstr.debtRemediationFunctions().linearWithOffset("1h", "30min"));
160 | baseclassabstr.createParam(ACCEPT_WHITESPACE_PARAM)
161 | .setDefaultValue("false")
162 | .setType(RuleParamType.BOOLEAN)
163 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
164 |
165 | final NewRule large_class = repository.createRule(LARGE_CLASS.rule())
166 | .setName("Large class")
167 | .setHtmlDescription("A class that has grown too large in term of LOCs")
168 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
169 | .setSeverity(Severity.MAJOR);
170 | large_class
171 | .setDebtRemediationFunction(large_class.debtRemediationFunctions().linearWithOffset("1h", "30min"));
172 | large_class.createParam(ACCEPT_WHITESPACE_PARAM)
173 | .setDefaultValue("false")
174 | .setType(RuleParamType.BOOLEAN)
175 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
176 |
177 | final NewRule lazy_class = repository.createRule(LAZY_CLASS.rule())
178 | .setName("Lazy class")
179 | .setHtmlDescription("A class that has few fields and methods.")
180 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
181 | .setSeverity(Severity.MAJOR);
182 | lazy_class
183 | .setDebtRemediationFunction(lazy_class.debtRemediationFunctions().linearWithOffset("1h", "30min"));
184 | lazy_class.createParam(ACCEPT_WHITESPACE_PARAM)
185 | .setDefaultValue("false")
186 | .setType(RuleParamType.BOOLEAN)
187 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
188 |
189 | final NewRule long_method = repository.createRule(LONG_METHOD.rule())
190 | .setName("Long method")
191 | .setHtmlDescription("A class that has (at least) a method that is very long, in term of LOCs")
192 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
193 | .setSeverity(Severity.MAJOR);
194 | long_method
195 | .setDebtRemediationFunction(long_method.debtRemediationFunctions().linearWithOffset("1h", "30min"));
196 | long_method.createParam(ACCEPT_WHITESPACE_PARAM)
197 | .setDefaultValue("false")
198 | .setType(RuleParamType.BOOLEAN)
199 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
200 |
201 | final NewRule tradition_breaker = repository.createRule(TRADITION_BREAKER.rule())
202 | .setName("Tradition breaker")
203 | .setHtmlDescription("A class that inherits from a large parent class but that provides little behaviour and without subclasses")
204 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
205 | .setSeverity(Severity.MAJOR);
206 | tradition_breaker
207 | .setDebtRemediationFunction(tradition_breaker.debtRemediationFunctions().linearWithOffset("1h", "30min"));
208 | tradition_breaker.createParam(ACCEPT_WHITESPACE_PARAM)
209 | .setDefaultValue("false")
210 | .setType(RuleParamType.BOOLEAN)
211 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
212 |
213 | final NewRule long_parameter_list = repository.createRule(LONG_PARAMETER_LIST.rule())
214 | .setName("Long parameter list")
215 | .setHtmlDescription(" A class that has (at least) one method with a too long list of parameters in comparison to the average number of parameters per methods in the system")
216 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
217 | .setSeverity(Severity.MAJOR);
218 | long_parameter_list
219 | .setDebtRemediationFunction(long_parameter_list.debtRemediationFunctions().linearWithOffset("1h", "30min"));
220 | long_parameter_list.createParam(ACCEPT_WHITESPACE_PARAM)
221 | .setDefaultValue("false")
222 | .setType(RuleParamType.BOOLEAN)
223 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
224 |
225 | final NewRule many_field_attributes_not_complex = repository.createRule(MANY_FIELD_ATTRIBUTES_NOT_COMPLEX.rule())
226 | .setName("Many field attribute not complex")
227 | .setHtmlDescription("A class that declares many attributes but which is not complex and, hence, more likely to be some kind of data class holding values without providing behaviour")
228 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
229 | .setSeverity(Severity.MAJOR);
230 | many_field_attributes_not_complex
231 | .setDebtRemediationFunction(many_field_attributes_not_complex.debtRemediationFunctions().linearWithOffset("1h", "30min"));
232 | many_field_attributes_not_complex.createParam(ACCEPT_WHITESPACE_PARAM)
233 | .setDefaultValue("false")
234 | .setType(RuleParamType.BOOLEAN)
235 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
236 |
237 | final NewRule message_chains = repository.createRule(MESSAGE_CHAINS.rule())
238 | .setName("Message chains")
239 | .setHtmlDescription("A class that uses a long chain of method invocations to realise (at least) one of its functionality")
240 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
241 | .setSeverity(Severity.MAJOR);
242 | message_chains
243 | .setDebtRemediationFunction(message_chains.debtRemediationFunctions().linearWithOffset("1h", "30min"));
244 | message_chains.createParam(ACCEPT_WHITESPACE_PARAM)
245 | .setDefaultValue("false")
246 | .setType(RuleParamType.BOOLEAN)
247 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
248 |
249 | final NewRule refused_parent_bequest = repository.createRule(REFUSED_PARENT_BEQUEST.rule())
250 | .setName("Refused parent bequest")
251 | .setHtmlDescription("A class that redefines inherited method using empty bodies, thus breaking polymorphism")
252 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
253 | .setSeverity(Severity.MAJOR);
254 | refused_parent_bequest
255 | .setDebtRemediationFunction(refused_parent_bequest.debtRemediationFunctions().linearWithOffset("1h", "30min"));
256 | refused_parent_bequest.createParam(ACCEPT_WHITESPACE_PARAM)
257 | .setDefaultValue("false")
258 | .setType(RuleParamType.BOOLEAN)
259 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
260 |
261 | final NewRule speculative_generality = repository.createRule(SPECULATIVE_GENERALITY.rule())
262 | .setName("Speculative generality")
263 | .setHtmlDescription("A class that is defined as abstract but that has very few children, which do not make use of its methods")
264 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
265 | .setSeverity(Severity.MAJOR);
266 | speculative_generality
267 | .setDebtRemediationFunction(speculative_generality.debtRemediationFunctions().linearWithOffset("1h", "30min"));
268 | speculative_generality.createParam(ACCEPT_WHITESPACE_PARAM)
269 | .setDefaultValue("false")
270 | .setType(RuleParamType.BOOLEAN)
271 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
272 |
273 | final NewRule swiss_army_knife = repository.createRule(SWISS_ARMY_KNIFE.rule())
274 | .setName("Swiss army knife")
275 | .setHtmlDescription("A complex class that offers a high number of services, for example, a complex class implementing a high number of interfaces")
276 | .setTags(TAG_CODESMELL, TAG_ANTIPATTERN)
277 | .setSeverity(Severity.MAJOR);
278 | swiss_army_knife
279 | .setDebtRemediationFunction(swiss_army_knife.debtRemediationFunctions().linearWithOffset("1h", "30min"));
280 | swiss_army_knife.createParam(ACCEPT_WHITESPACE_PARAM)
281 | .setDefaultValue("false")
282 | .setType(RuleParamType.BOOLEAN)
283 | .setDescription(ACCEPT_WHITESPACES_DESCRIPTION);
284 |
285 |
286 | // don't forget to call done() to finalize the definition
287 | repository.done();
288 | }
289 | }
290 |
--------------------------------------------------------------------------------
/src/main/java/it/unibz/sonarqube/plugin/CodeSmellsAntiPatternsSensor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Sonarqube anti-pattern and code smell detection plugin
3 | * Copyright (C) 2017 Giuseppe Aina, Alexandru Stan, Davide Taibi, Gustavs Venters
4 | *
5 | * This program 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 | * This program 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 this program. If not, see .
17 | */
18 | package it.unibz.sonarqube.plugin;
19 |
20 | import java.io.*;
21 | import java.util.ArrayList;
22 | import java.util.Collections;
23 | import java.util.List;
24 | import java.util.Properties;
25 |
26 | import org.slf4j.Logger;
27 | import org.slf4j.LoggerFactory;
28 | import org.sonar.api.batch.fs.*;
29 | import org.sonar.api.batch.sensor.Sensor;
30 | import org.sonar.api.batch.sensor.SensorContext;
31 | import org.sonar.api.batch.sensor.SensorDescriptor;
32 | import org.sonar.api.batch.sensor.issue.NewIssue;
33 | import org.sonar.api.batch.sensor.issue.NewIssueLocation;
34 |
35 | import padl.creator.javafile.eclipse.astVisitors.ConditionalModelAnnotator;
36 | import padl.creator.javafile.eclipse.astVisitors.LOCModelAnnotator;
37 | import padl.kernel.ICodeLevelModel;
38 | import padl.kernel.IFactory;
39 | import padl.kernel.impl.Factory;
40 | import ptidej.solver.Occurrence;
41 | import ptidej.solver.OccurrenceBuilder;
42 | import ptidej.solver.OccurrenceComponent;
43 | import padl.creator.javafile.eclipse.CompleteJavaFileCreator;
44 | import sad.designsmell.detection.IDesignSmellDetection;
45 |
46 | import javax.annotation.Nonnull;
47 |
48 | public class CodeSmellsAntiPatternsSensor implements Sensor {
49 |
50 | private static final String ANTISINGLETON = "AntiSingleton";
51 | private static final String BASE_CLASS_KNOWS_DERIVED_CLASS = "BaseClassKnowsDerivedClass";
52 | private static final String BASE_CLASS_SHOULD_BE_ABSTRACT = "BaseClassShouldBeAbstract";
53 | private static final String BLOB = "Blob";
54 | private static final String CLASS_DATA_SHOULD_BE_PRIVATE = "ClassDataShouldBePrivate";
55 | private static final String COMPLEX_CLASS = "ComplexClass";
56 | private static final String FUNCTIONAL_DECOMPOSITION = "FunctionalDecomposition";
57 | private static final String LARGE_CLASS = "LargeClass";
58 | private static final String LAZY_CLASS = "LazyClass";
59 | private static final String LONG_METHOD = "LongMethod";
60 | private static final String LONG_PARAMETER_LIST = "LongParameterList";
61 | private static final String MANY_FIELD_ATTRIBUTES_BUT_NOT_COMPLEX = "ManyFieldAttributesButNotComplex";
62 | private static final String MESSAGE_CHAINS = "MessageChains";
63 | private static final String REFUSED_PARENT_BEQUEST = "RefusedParentBequest";
64 | private static final String SPAGHETT_ICODE = "SpaghettiCode";
65 | private static final String SPECULATIVE_GENERALITY = "SpeculativeGenerality";
66 | private static final String SWISS_ARMY_KNIFE = "SwissArmyKnife";
67 | private static final String TRADITION_BREAKER = "TraditionBreaker";
68 |
69 |
70 | private static final String[] CODE_SMELLS = new String[] { ANTISINGLETON,
71 | BASE_CLASS_KNOWS_DERIVED_CLASS, BASE_CLASS_SHOULD_BE_ABSTRACT, BLOB,
72 | CLASS_DATA_SHOULD_BE_PRIVATE, COMPLEX_CLASS,
73 | FUNCTIONAL_DECOMPOSITION, LARGE_CLASS, LAZY_CLASS, LONG_METHOD,
74 | LONG_PARAMETER_LIST, MANY_FIELD_ATTRIBUTES_BUT_NOT_COMPLEX,
75 | MESSAGE_CHAINS, REFUSED_PARENT_BEQUEST, SPAGHETT_ICODE,
76 | SPECULATIVE_GENERALITY, SWISS_ARMY_KNIFE, TRADITION_BREAKER };
77 |
78 |
79 |
80 | private static Logger LOG = LoggerFactory.getLogger(CodeSmellsAntiPatternsSensor.class);
81 | private SensorContext context;
82 | private IFactory factory = Factory.getInstance();
83 |
84 | @Override
85 | public void describe(@Nonnull final SensorDescriptor sensorDescriptor) {
86 | sensorDescriptor
87 | .name("Code Smell Anti-pattern Sensor")
88 | .onlyOnLanguage("java")
89 | .createIssuesForRuleRepository(CodeSmellsAntiPatternsRulesDefinition.REPOSITORY);
90 | }
91 |
92 | @Override
93 | public void execute(@Nonnull final SensorContext sensorContext) {
94 | context = sensorContext;
95 |
96 | final String sonarBaseDir = context.settings().getString("sonar.projectBaseDir");
97 | final String sonarSources = context.settings().getString("sonar.sources");
98 | final String sonarModules = context.settings().getString("sonar.modules");
99 | LOG.debug("BaseDir {}", sonarBaseDir);
100 | LOG.debug("Sources {}", sonarSources);
101 | LOG.debug("Modules {}", sonarModules);
102 |
103 | //https://docs.sonarqube.org/display/SCAN/Advanced+SonarQube+Scanner+Usages
104 | List sourcePathList = new ArrayList<>();
105 | if (sonarModules == null && sonarSources == null)
106 | sourcePathList.add(".");
107 | else if (sonarModules == null)
108 | Collections.addAll(sourcePathList, sonarSources.split(","));
109 | else if (sonarSources == null)
110 | Collections.addAll(sourcePathList, sonarModules.split(","));
111 | else
112 | for (String moduleName : sonarModules.split(","))
113 | for (String sourceName : sonarSources.split(","))
114 | sourcePathList.add(moduleName + File.separatorChar + sourceName);
115 | LOG.debug("Source path entries {}", sourcePathList);
116 |
117 | final String[] sourcePathEntries = sourcePathList.toArray(new String[0]);
118 | final String[] classpathEntries = new String[] { "" };
119 |
120 | final long startTime = System.currentTimeMillis();
121 | final CompleteJavaFileCreator creator;
122 | final ICodeLevelModel codeLevelModel;
123 | try {
124 | creator = new CompleteJavaFileCreator(sourcePathEntries, classpathEntries, sourcePathEntries);
125 | codeLevelModel = factory.createCodeLevelModel("Codesmells");
126 | codeLevelModel.create(creator);
127 | } catch (Exception e) {
128 | LOG.error("Could not create code level model, creating took {}ms", (System.currentTimeMillis() - startTime), e);
129 | return;
130 | }
131 | LOG.info("Code level model built in {}ms", (System.currentTimeMillis() - startTime));
132 | LOG.info("Code level model contains {} top-level entities", codeLevelModel.getNumberOfTopLevelEntities());
133 |
134 | final LOCModelAnnotator locModelAnnotator = new LOCModelAnnotator(codeLevelModel);
135 | creator.applyAnnotator(locModelAnnotator);
136 | final ConditionalModelAnnotator conditionalModelAnnotator = new ConditionalModelAnnotator(codeLevelModel);
137 | creator.applyAnnotator(conditionalModelAnnotator);
138 |
139 | for (final String codesmellName : CODE_SMELLS) {
140 | detectCodeSmell(codeLevelModel, codesmellName);
141 | }
142 | }
143 |
144 | /**
145 | * Detects the code-smell using the padl code level model
146 | */
147 | private void detectCodeSmell(final ICodeLevelModel codeLevelModel, final String codesmellName) {
148 | try {
149 | final Class> detectionClass = Class.forName("sad.designsmell.detection.repository." + codesmellName
150 | + '.' + codesmellName + "Detection");
151 | final IDesignSmellDetection detection = (IDesignSmellDetection) detectionClass.newInstance();
152 | detection.detect(codeLevelModel);
153 | final ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
154 | detection.output(new PrintWriter(byteOutput));
155 |
156 | final Properties properties = new Properties();
157 | properties.load(new ByteArrayInputStream(byteOutput.toByteArray()));
158 |
159 | final OccurrenceBuilder solutionBuilder = OccurrenceBuilder.getInstance();
160 | //final Occurrence[] solutions = solutionBuilder.getCanonicalOccurrences(properties);
161 | final Occurrence[] allOccurrences = solutionBuilder.getAllOccurrences(properties);
162 | LOG.debug("Classes infected by {}: {}", codesmellName, allOccurrences.length);
163 | saveClassesDefects(codesmellName, allOccurrences);
164 |
165 | } catch (ClassNotFoundException e) {
166 | LOG.error("Detection class not found for {}", codesmellName, e);
167 | } catch (IllegalAccessException | InstantiationException e) {
168 | LOG.error("Could not instantiate IDesignSmellDetection for {}", codesmellName, e);
169 | } catch (IOException e) {
170 | LOG.error("Could not load properties from memory for {}", codesmellName, e);
171 | }
172 | }
173 |
174 | /**
175 | * Saves all code-smell occurrences found in padl code level model
176 | */
177 | private void saveClassesDefects(final String codesmellName, final Occurrence[] allOccurrences) {
178 | final FilePredicates f = context.fileSystem().predicates();
179 | final FilePredicate fp = f.hasExtension("java");
180 | final Iterable files = context.fileSystem().inputFiles(fp);
181 |
182 | for (final Occurrence occ : allOccurrences) {
183 | @SuppressWarnings("unchecked")
184 | final ArrayList listOccComponents = (ArrayList) occ.getComponents();
185 | if (!listOccComponents.isEmpty()) {
186 | final OccurrenceComponent solutionComponent;
187 | if (codesmellName.matches(ANTISINGLETON + "|" + REFUSED_PARENT_BEQUEST)) {
188 | solutionComponent = listOccComponents.get(1);
189 | } else {
190 | solutionComponent = listOccComponents.get(0);
191 | }
192 | final String rawClassName = solutionComponent.getDisplayValue();
193 | final String className = rawClassName.substring(rawClassName.lastIndexOf('.') + 1).trim();
194 | LOG.debug("Infected class detected by ptidej: {}", rawClassName);
195 |
196 | for (final InputFile file : files) {
197 | final String[] parts = file.relativePath().split("[./]");
198 | final String clName = parts[Math.max(parts.length - 2, 0)]; // part before "."
199 | if (clName.equals(className)) {
200 | saveIssue(codesmellName, file);
201 | break;
202 | }
203 | }
204 | }
205 | }
206 | }
207 |
208 | /**
209 | * Adds code-smell to the issues of a Sonarqube project file.
210 | */
211 | private void saveIssue(final String codesmellName, final InputFile file) {
212 | if (file == null) {
213 | LOG.error("Input file from absolutePath is null");
214 | return;
215 | }
216 | NewIssue newIssue;
217 | NewIssueLocation primaryLocation;
218 | switch (codesmellName) {
219 | case COMPLEX_CLASS:
220 | newIssue = context.newIssue()
221 | .forRule(CodeSmellsAntiPatternsRulesDefinition.COMPLEX_CLASS);
222 | primaryLocation = newIssue.newLocation()
223 | .on(file)
224 | .at(file.selectLine(1))
225 | .message("Complex class");
226 | newIssue.at(primaryLocation);
227 | newIssue.save();
228 | break;
229 | case BLOB:
230 | newIssue = context.newIssue()
231 | .forRule(CodeSmellsAntiPatternsRulesDefinition.BLOB_CLASS);
232 | primaryLocation = newIssue.newLocation()
233 | .on(file)
234 | .at(file.selectLine(1))
235 | .message("Blob class");
236 | newIssue.at(primaryLocation);
237 | newIssue.save();
238 | break;
239 | case CLASS_DATA_SHOULD_BE_PRIVATE:
240 | newIssue = context.newIssue()
241 | .forRule(CodeSmellsAntiPatternsRulesDefinition.CLASS_DATA_PRIVATE);
242 | primaryLocation = newIssue.newLocation()
243 | .on(file)
244 | .at(file.selectLine(1))
245 | .message("Class data should be private");
246 | newIssue.at(primaryLocation);
247 | newIssue.save();
248 | break;
249 |
250 | case FUNCTIONAL_DECOMPOSITION:
251 | newIssue = context.newIssue()
252 | .forRule(CodeSmellsAntiPatternsRulesDefinition.FUNCTIONAL_DECOMPOSITION);
253 | primaryLocation = newIssue.newLocation()
254 | .on(file)
255 | .at(file.selectLine(1))
256 | .message("Functional decomposition");
257 | newIssue.at(primaryLocation);
258 | newIssue.save();
259 | break;
260 | case SPAGHETT_ICODE:
261 | newIssue = context.newIssue()
262 | .forRule(CodeSmellsAntiPatternsRulesDefinition.SPAGHETTI_CODE);
263 | primaryLocation = newIssue.newLocation()
264 | .on(file)
265 | .at(file.selectLine(1))
266 | .message("Spaghetti code");
267 | newIssue.at(primaryLocation);
268 | newIssue.save();
269 | break;
270 | case ANTISINGLETON:
271 | newIssue = context.newIssue()
272 | .forRule(CodeSmellsAntiPatternsRulesDefinition.ANTISINGLETON);
273 | primaryLocation = newIssue.newLocation()
274 | .on(file)
275 | .at(file.selectLine(1))
276 | .message("Anti-singleton");
277 | newIssue.at(primaryLocation);
278 | newIssue.save();
279 | break;
280 | case BASE_CLASS_KNOWS_DERIVED_CLASS:
281 | newIssue = context.newIssue()
282 | .forRule(CodeSmellsAntiPatternsRulesDefinition.BASECLASS_KNOWS_DERIVED);
283 | primaryLocation = newIssue.newLocation()
284 | .on(file)
285 | .at(file.selectLine(1))
286 | .message("Base-class knows derived class");
287 | newIssue.at(primaryLocation);
288 | newIssue.save();
289 | break;
290 | case BASE_CLASS_SHOULD_BE_ABSTRACT:
291 | newIssue = context.newIssue()
292 | .forRule(CodeSmellsAntiPatternsRulesDefinition.BASECLASS_ABSTRACT);
293 | primaryLocation = newIssue.newLocation()
294 | .on(file)
295 | .at(file.selectLine(1))
296 | .message("Base-class should be abstract");
297 | newIssue.at(primaryLocation);
298 | newIssue.save();
299 | break;
300 | case LARGE_CLASS:
301 | newIssue = context.newIssue()
302 | .forRule(CodeSmellsAntiPatternsRulesDefinition.LARGE_CLASS);
303 | primaryLocation = newIssue.newLocation()
304 | .on(file)
305 | .at(file.selectLine(1))
306 | .message("Large class");
307 | newIssue.at(primaryLocation);
308 | newIssue.save();
309 | break;
310 | case LAZY_CLASS:
311 | newIssue = context.newIssue()
312 | .forRule(CodeSmellsAntiPatternsRulesDefinition.LAZY_CLASS);
313 | primaryLocation = newIssue.newLocation()
314 | .on(file)
315 | .at(file.selectLine(1))
316 | .message("Lazy class");
317 | newIssue.at(primaryLocation);
318 | newIssue.save();
319 | break;
320 | case LONG_METHOD:
321 | newIssue = context.newIssue()
322 | .forRule(CodeSmellsAntiPatternsRulesDefinition.LONG_METHOD);
323 | primaryLocation = newIssue.newLocation()
324 | .on(file)
325 | .at(file.selectLine(1))
326 | .message("Long method");
327 | newIssue.at(primaryLocation);
328 | newIssue.save();
329 | break;
330 | case LONG_PARAMETER_LIST:
331 | newIssue = context.newIssue()
332 | .forRule(CodeSmellsAntiPatternsRulesDefinition.LONG_PARAMETER_LIST);
333 | primaryLocation = newIssue.newLocation()
334 | .on(file)
335 | .at(file.selectLine(1))
336 | .message("Long parameter list");
337 | newIssue.at(primaryLocation);
338 | newIssue.save();
339 | break;
340 | case MANY_FIELD_ATTRIBUTES_BUT_NOT_COMPLEX:
341 | newIssue = context.newIssue()
342 | .forRule(CodeSmellsAntiPatternsRulesDefinition.MANY_FIELD_ATTRIBUTES_NOT_COMPLEX);
343 | primaryLocation = newIssue.newLocation()
344 | .on(file)
345 | .at(file.selectLine(1))
346 | .message("Many field attributes but not complex");
347 | newIssue.at(primaryLocation);
348 | newIssue.save();
349 | break;
350 | case MESSAGE_CHAINS:
351 | newIssue = context.newIssue()
352 | .forRule(CodeSmellsAntiPatternsRulesDefinition.MESSAGE_CHAINS);
353 | primaryLocation = newIssue.newLocation()
354 | .on(file)
355 | .at(file.selectLine(1))
356 | .message("Message chains");
357 | newIssue.at(primaryLocation);
358 | newIssue.save();
359 | break;
360 | case REFUSED_PARENT_BEQUEST:
361 | newIssue = context.newIssue()
362 | .forRule(CodeSmellsAntiPatternsRulesDefinition.REFUSED_PARENT_BEQUEST);
363 | primaryLocation = newIssue.newLocation()
364 | .on(file)
365 | .at(file.selectLine(1))
366 | .message("Refused parent bequest");
367 | newIssue.at(primaryLocation);
368 | newIssue.save();
369 | break;
370 | case SPECULATIVE_GENERALITY:
371 | newIssue = context.newIssue()
372 | .forRule(CodeSmellsAntiPatternsRulesDefinition.SPECULATIVE_GENERALITY);
373 | primaryLocation = newIssue.newLocation()
374 | .on(file)
375 | .at(file.selectLine(1))
376 | .message("Speculative generality");
377 | newIssue.at(primaryLocation);
378 | newIssue.save();
379 | break;
380 | case SWISS_ARMY_KNIFE:
381 | newIssue = context.newIssue()
382 | .forRule(CodeSmellsAntiPatternsRulesDefinition.SWISS_ARMY_KNIFE);
383 | primaryLocation = newIssue.newLocation()
384 | .on(file)
385 | .at(file.selectLine(1))
386 | .message("Swiss army knife");
387 | newIssue.at(primaryLocation);
388 | newIssue.save();
389 | break;
390 | case TRADITION_BREAKER:
391 | newIssue = context.newIssue()
392 | .forRule(CodeSmellsAntiPatternsRulesDefinition.TRADITION_BREAKER);
393 | primaryLocation = newIssue.newLocation()
394 | .on(file)
395 | .at(file.selectLine(1))
396 | .message("Tradition breaker");
397 | newIssue.at(primaryLocation);
398 | newIssue.save();
399 | break;
400 | default:
401 | LOG.error("No such code-smell defined: {}", codesmellName);
402 | }
403 | }
404 |
405 | public void setFactory(IFactory factory) {
406 | this.factory = factory;
407 | }
408 | }
--------------------------------------------------------------------------------
/src/main/main.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
--------------------------------------------------------------------------------
/src/test/antipattern-rules-profile.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | custom-rules-profile
4 | java
5 |
6 |
7 | code_smells
8 | class_data_private
9 | MAJOR
10 |
11 |
12 |
13 | code_smells
14 | antisingleton
15 | MAJOR
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/test/java/AntiPatternRulesIT.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Sonarqube anti-pattern and code smell detection plugin
3 | * Copyright (C) 2017 Giuseppe Aina, Alexandru Stan, Davide Taibi, Gustavs Venters
4 | *
5 | * This program 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 | * This program 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 this program. If not, see .
17 | */
18 | import com.sonar.orchestrator.Orchestrator;
19 | import com.sonar.orchestrator.build.SonarScanner;
20 | import com.sonar.orchestrator.locator.FileLocation;
21 | import org.junit.*;
22 | import org.sonar.wsclient.issue.Issue;
23 | import org.sonar.wsclient.issue.IssueClient;
24 | import org.sonar.wsclient.issue.IssueQuery;
25 |
26 | import java.io.File;
27 | import java.util.List;
28 | import org.apache.commons.io.FileUtils;
29 |
30 | public class AntiPatternRulesIT {
31 |
32 | @ClassRule
33 | public static Orchestrator orchestrator = Orchestrator.builderEnv()
34 | .setOrchestratorProperty("javaVersion", "4.2.1")
35 | .setSonarVersion("6.3")
36 | .addPlugin("java")
37 | .addPlugin(FileLocation.byWildcardMavenFilename(new File("target"), "sonar-codesmellsantipatterns-plugin-*.jar"))
38 | .restoreProfileAtStartup(FileLocation.of(new File("src/test/antipattern-rules-profile.xml")))
39 | .build();
40 |
41 | private static IssueClient issueClient;
42 | private static final String PROJECT_KEY = "antipattern-rules";
43 |
44 | @BeforeClass
45 | public static void init() {
46 | orchestrator.resetData();
47 | orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
48 |
49 | SonarScanner build = SonarScanner.create();
50 | build
51 | .setProperty("javaVersion", "4.2.1")
52 | .setProjectVersion("1.0")
53 | .setSourceEncoding("UTF-8")
54 | .setSourceDirs(".")
55 | .setLanguage("java")
56 | .setProfile("custom-rules-profile")
57 | .setProjectDir(new File("src/test/projects/antipatterns"))
58 | .setProjectKey(PROJECT_KEY)
59 | .setProjectName(PROJECT_KEY);
60 | orchestrator.executeBuild(build);
61 |
62 | issueClient = orchestrator.getServer().wsClient().issueClient();
63 | }
64 |
65 | @Test
66 | public void classDataPrivate() {
67 | final List issues = issueClient.find(IssueQuery.create().rules("code_smells:class_data_private")).list();
68 | Assert.assertEquals(1, issues.size());
69 | }
70 |
71 | @Test
72 | public void antiSingleton() {
73 | final List issues = issueClient.find(IssueQuery.create().rules("code_smells:antisingleton")).list();
74 | Assert.assertEquals(1, issues.size());
75 | }
76 |
77 | @AfterClass
78 | public static void tearDown() {
79 | if (orchestrator != null) {
80 | orchestrator.stop();
81 | }
82 | }
83 |
84 | }
--------------------------------------------------------------------------------
/src/test/java/plugin/CodeSmellsAntiPatternsSensorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Sonarqube anti-pattern and code smell detection plugin
3 | * Copyright (C) 2017 Giuseppe Aina, Alexandru Stan, Davide Taibi, Gustavs Venters
4 | *
5 | * This program 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 | * This program 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 this program. If not, see .
17 | */
18 | package plugin;
19 |
20 | import it.unibz.sonarqube.plugin.CodeSmellsAntiPatternsSensor;
21 | import org.junit.Test;
22 | import org.mockito.Mock;
23 | import org.mockito.Mockito;
24 | import org.sonar.api.batch.sensor.SensorContext;
25 | import org.sonar.api.config.Settings;
26 | import padl.creator.javafile.eclipse.CompleteJavaFileCreator;
27 | import padl.kernel.ICodeLevelModel;
28 | import padl.kernel.exception.CreationException;
29 | import padl.kernel.exception.ModelDeclarationException;
30 | import padl.kernel.impl.Factory;
31 |
32 | public class CodeSmellsAntiPatternsSensorTest {
33 |
34 | @Mock
35 | SensorContext sensorContext = Mockito.mock(SensorContext.class);
36 |
37 | @Mock
38 | Settings settings = Mockito.mock(Settings.class);
39 |
40 | @Mock
41 | Factory factory = Mockito.mock(Factory.class);
42 |
43 | @Mock
44 | ICodeLevelModel codeLevelModel = Mockito.mock(ICodeLevelModel.class);
45 |
46 | @Test
47 | public void testExecuteWithExceptions() throws CreationException {
48 | CodeSmellsAntiPatternsSensor testSensor = new CodeSmellsAntiPatternsSensor();
49 | Mockito.when(sensorContext.settings()).thenReturn(settings);
50 | Mockito.when(settings.getString(Mockito.anyString())).thenReturn("");
51 | testSensor.setFactory(factory);
52 | Mockito.when(factory.createCodeLevelModel(Mockito.anyString())).thenReturn(codeLevelModel);
53 | Mockito.when(codeLevelModel.toString()).thenReturn("Test code level model");
54 | Mockito.doThrow(new ModelDeclarationException("This exception should not be thrown")).when(codeLevelModel).create(Mockito.any(CompleteJavaFileCreator.class));
55 | testSensor.execute(sensorContext);
56 | }
57 |
58 | }
--------------------------------------------------------------------------------
/src/test/projects/antipatterns/.sonar/.sonar_lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davidetaibi/sonarqube-anti-patterns-code-smells/94aa41519670309fe961e1422efc82d39da80e4e/src/test/projects/antipatterns/.sonar/.sonar_lock
--------------------------------------------------------------------------------
/src/test/projects/antipatterns/AntiSingletonAndClassDataPrivate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Sonarqube anti-pattern and code smell detection plugin
3 | * Copyright (C) 2017 Giuseppe Aina, Alexandru Stan, Davide Taibi, Gustavs Venters
4 | *
5 | * This program 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 | * This program 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 this program. If not, see .
17 | */
18 | public class AntiSingletonAndClassDataPrivate {
19 |
20 | public static int j = 1;
21 |
22 | public static void main(String[] args) {
23 | j++;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/test/test.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------