From e35783041f080c4e36f1704b9c24cc4e5fa2bf6f Mon Sep 17 00:00:00 2001 From: Michael Clarke Date: Mon, 4 Mar 2019 19:24:36 +0000 Subject: [PATCH] Initial Commit --- .gitignore | 14 + LICENSE | 674 ++++++++++++++++++ README.md | 14 + build.gradle | 95 +++ gradle.properties | 1 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 56172 bytes gradle/wrapper/gradle-wrapper.properties | 5 + gradlew | 172 +++++ gradlew.bat | 84 +++ settings.gradle | 2 + .../plugin/CommunityBranchPlugin.java | 70 ++ .../CommunityBranchPluginBootstrap.java | 90 +++ .../sonarqube/plugin/ce/CommunityBranch.java | 113 +++ .../ce/CommunityBranchLoaderDelegate.java | 129 ++++ ...munityReportAnalysisComponentProvider.java | 36 + ...ssReferenceElevatedClassLoaderFactory.java | 50 ++ ...ultElevatedClassLoaderFactoryProvider.java | 43 ++ .../ElevatedClassLoaderFactory.java | 87 +++ .../ElevatedClassLoaderFactoryProvider.java | 7 + .../plugin/classloader/ProviderType.java | 51 ++ .../ReflectiveElevatedClassLoaderFactory.java | 88 +++ .../scanner/CommunityBranchConfiguration.java | 73 ++ .../CommunityBranchConfigurationLoader.java | 141 ++++ .../CommunityBranchParamsValidator.java | 48 ++ .../CommunityProjectBranchesLoader.java | 92 +++ .../CommunityProjectPullRequestsLoader.java | 90 +++ .../CommunityBranchFeatureExtension.java | 35 + .../CommunityBranchSupportDelegate.java | 116 +++ .../plugin/server/CommunityComponentKey.java | 77 ++ .../CommunityBranchPluginBootstrapTest.java | 198 +++++ .../plugin/CommunityBranchPluginTest.java | 125 ++++ .../ce/CommunityBranchLoaderDelegateTest.java | 325 +++++++++ .../plugin/ce/CommunityBranchTest.java | 115 +++ ...tyReportAnalysisComponentProviderTest.java | 38 + ...ferenceElevatedClassLoaderFactoryTest.java | 108 +++ ...levatedClassLoaderFactoryProviderTest.java | 27 + .../ElevatedClassLoaderFactoryTest.java | 76 ++ .../plugin/classloader/ProviderTypeTest.java | 50 ++ ...lectiveElevatedClassLoaderFactoryTest.java | 194 +++++ ...ommunityBranchConfigurationLoaderTest.java | 466 ++++++++++++ .../CommunityBranchParamsValidatorTest.java | 83 +++ .../CommunityProjectBranchesLoaderTest.java | 162 +++++ ...ommunityProjectPullRequestsLoaderTest.java | 165 +++++ .../CommunityBranchFeatureExtensionTest.java | 34 + .../CommunityBranchSupportDelegateTest.java | 350 +++++++++ 45 files changed, 5013 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPlugin.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPluginBootstrap.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranch.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchLoaderDelegate.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityReportAnalysisComponentProvider.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ClassReferenceElevatedClassLoaderFactory.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/DefaultElevatedClassLoaderFactoryProvider.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ElevatedClassLoaderFactory.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ElevatedClassLoaderFactoryProvider.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ProviderType.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ReflectiveElevatedClassLoaderFactory.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchConfiguration.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchConfigurationLoader.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchParamsValidator.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectBranchesLoader.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectPullRequestsLoader.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchFeatureExtension.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchSupportDelegate.java create mode 100644 src/main/java/com/github/mc1arke/sonarqube/plugin/server/CommunityComponentKey.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPluginBootstrapTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPluginTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchLoaderDelegateTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityReportAnalysisComponentProviderTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ClassReferenceElevatedClassLoaderFactoryTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/DefaultElevatedClassLoaderFactoryProviderTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ElevatedClassLoaderFactoryTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ProviderTypeTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ReflectiveElevatedClassLoaderFactoryTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchConfigurationLoaderTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchParamsValidatorTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectBranchesLoaderTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectPullRequestsLoaderTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchFeatureExtensionTest.java create mode 100644 src/test/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchSupportDelegateTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..1190b5945 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +#Mac +.DS_Store + +#Gradle +/.gradle/ +/build/ + +#Intellij +/out/ +/.idea/ +*.iml + +#Project libs +/sonarqube-lib/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..f288702d2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 000000000..3fe94b68f --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mc1arke_sonarqube-community-branch-plugin&metric=alert_status)](https://sonarcloud.io/dashboard?id=mc1arke_sonarqube-community-branch-plugin) + +# Sonarqube Community Branch Plugin +A plugin for SonarQube to allow branch analysis in the Community version. + +# Installation +Copy the plugin JAR file to the `extensions/plugins/`directory of your SonarQube instance and restart SonarQube. + +# Compatibility +The latest release of the plugin supports SonarQube Community edition 7.4 and above. + +# Features +The plugin is intended to support the features and parameters specified in the SonarQube documentation, with the following caveats +* __Pull Requests:__ Analysis of Pull Requests is fully supported, but the decoration of pull requests with any issues is not currently supported diff --git a/build.gradle b/build.gradle new file mode 100644 index 000000000..ca1ff154e --- /dev/null +++ b/build.gradle @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +plugins { + id('java') + id('jacoco') + id('org.sonarqube') version('2.7') + id('info.solidsoft.pitest') version('1.4.0') + id('com.iadams.sonar-packaging') version('1.0-RC1') + id('net.researchgate.release') version('2.6.0') +} + +group 'com.github.mc1arke.sonarqube.plugin' + +repositories { + mavenCentral() + ivy { + url 'https://binaries.sonarsource.com/' + layout 'pattern', { + artifact '/Distribution/[module]/[module]-[revision].[ext]' + } + } +} + +def sonarqubeVersion = '7.4' +def sonarqubeLibDir = "${projectDir}/sonarqube-lib" +def sonarLibraries = "${sonarqubeLibDir}/sonarqube-${sonarqubeVersion}/lib" + +configurations { + zip +} + +compileJava { + options.compilerArgs += '-proc:none' +} + + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' + compileOnly fileTree(dir: sonarLibraries, include: '**/*.jar') + testCompile fileTree(dir: sonarLibraries, include: '**/*.jar') + testCompile group: 'junit', name: 'junit', version: '4.12' + testCompile group: 'org.mockito', name: 'mockito-core', version: '2.24.0' + zip "sonarqube:sonarqube:${sonarqubeVersion}@zip" + compileOnly group: 'org.sonarsource.sonarqube', name: 'sonar-plugin-api', version: "${sonarqubeVersion}" +} + + +project.afterEvaluate { + if (file("${sonarLibraries}").exists()) { + return + } + println 'Extracting SonarQube libraries (this may take a while)...' + configurations.zip.resolvedConfiguration.resolvedArtifacts.each { artifact -> + copy { + from zipTree(artifact.getFile()) + into "${sonarqubeLibDir}" + } + } +} + +sonarPackaging { + pluginKey = 'communityBranchPlugin' + pluginClass = 'com.github.mc1arke.sonarqube.plugin.CommunityBranchPluginBootstrap' + pluginName = 'Community Branch Plugin' + pluginDescription = 'Enables branch and pull request analysis in SonarQube Community Edition, without having to upgrade to Developer Edition' + pluginLicense = 'GNU LGPL 3' + pluginUrl = 'https://github.com/mc1arke/sonarqube-community-branch-plugin' + pluginIssueTrackerUrl = 'https://github.com/mc1arke/sonarqube-community-branch-plugin/issues' + skipDependenciesPackaging = true + useChildFirstClassLoader = false + organization['name'] = 'Michael Clarke' + organization['url'] = '' +} + +release { + git { + requireBranch = '(master|release-\\d+\\.\\d+|\\d+\\.\\d+)' + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 000000000..8d0c7be96 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +version=1.0.0-SNAPSHOT diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..28861d273a5d270fd8f65dd74570c17c9c507736 GIT binary patch literal 56172 zcmagFV{~WVwk?_pE4FRhwr$(CRk3Z`c2coz+fFL^#m=jD_df5v|GoR1_hGCxKaAPt z?5)i;2YO!$(jcHHKtMl#0s#RD{xu*V;Q#dm0)qVemK9YIq?MEtqXz*}_=lrH_H#1- zUkBB{_ILXK>nJNICn+YXtU@O%b}u_MDI-lwHxDaKOEoh!+oZ&>#JqQWH$^)pIW0R) zElKkO>LS!6^{7~jvK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e --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip diff --git a/gradlew b/gradlew new file mode 100644 index 000000000..cccdd3d51 --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 000000000..f9553162f --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 000000000..d3d9ef3d8 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'sonarqube-community-branch-plugin' + diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPlugin.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPlugin.java new file mode 100644 index 000000000..6e6130ceb --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPlugin.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin; + +import com.github.mc1arke.sonarqube.plugin.ce.CommunityReportAnalysisComponentProvider; +import com.github.mc1arke.sonarqube.plugin.scanner.CommunityBranchConfigurationLoader; +import com.github.mc1arke.sonarqube.plugin.scanner.CommunityBranchParamsValidator; +import com.github.mc1arke.sonarqube.plugin.scanner.CommunityProjectBranchesLoader; +import com.github.mc1arke.sonarqube.plugin.scanner.CommunityProjectPullRequestsLoader; +import com.github.mc1arke.sonarqube.plugin.server.CommunityBranchFeatureExtension; +import com.github.mc1arke.sonarqube.plugin.server.CommunityBranchSupportDelegate; +import org.sonar.api.CoreProperties; +import org.sonar.api.Plugin; +import org.sonar.api.PropertyType; +import org.sonar.api.SonarQubeSide; +import org.sonar.api.config.PropertyDefinition; +import org.sonar.api.resources.Qualifiers; +import org.sonar.core.config.PurgeConstants; + +/** + * @author Michael Clarke + */ +public class CommunityBranchPlugin implements Plugin { + + @Override + public void define(Context context) { + if (SonarQubeSide.SCANNER == context.getRuntime().getSonarQubeSide()) { + context.addExtensions(CommunityProjectBranchesLoader.class, CommunityProjectPullRequestsLoader.class, + CommunityBranchConfigurationLoader.class, CommunityBranchParamsValidator.class); + } else if (SonarQubeSide.COMPUTE_ENGINE == context.getRuntime().getSonarQubeSide()) { + context.addExtension(CommunityReportAnalysisComponentProvider.class); + } else if (SonarQubeSide.SERVER == context.getRuntime().getSonarQubeSide()) { + context.addExtensions(CommunityBranchFeatureExtension.class, CommunityBranchSupportDelegate.class); + } + + context.addExtensions( + /* org.sonar.db.purge.PurgeConfiguration uses the value for the this property if it's configured, so it only + needs to be specified here, but doesn't need any additional classes to perform the relevant purge/cleanup + */ + PropertyDefinition.builder(PurgeConstants.DAYS_BEFORE_DELETING_INACTIVE_SHORT_LIVING_BRANCHES) + .name("Number of days before purging inactive short living branches").description( + "Short living branches are permanently deleted when there are no analysis for the configured number of days.") + .category(CoreProperties.CATEGORY_GENERAL) + .subCategory(CoreProperties.SUBCATEGORY_DATABASE_CLEANER).defaultValue("30") + .type(PropertyType.INTEGER).build(), + + //the name and description shown on the UI are automatically loaded from core.properties so don't need to be specified here + PropertyDefinition.builder(CoreProperties.LONG_LIVED_BRANCHES_REGEX).onQualifiers(Qualifiers.PROJECT) + .category(CoreProperties.CATEGORY_GENERAL).subCategory(CoreProperties.SUBCATEGORY_BRANCHES) + .defaultValue(CommunityBranchConfigurationLoader.DEFAULT_BRANCH_REGEX).build()); + + } + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPluginBootstrap.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPluginBootstrap.java new file mode 100644 index 000000000..103333614 --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPluginBootstrap.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin; + +import com.github.mc1arke.sonarqube.plugin.classloader.DefaultElevatedClassLoaderFactoryProvider; +import com.github.mc1arke.sonarqube.plugin.classloader.ElevatedClassLoaderFactory; +import com.github.mc1arke.sonarqube.plugin.classloader.ElevatedClassLoaderFactoryProvider; +import org.sonar.api.Plugin; + +import java.util.Objects; + + +/** + * The entry-point class used by SonarQube to launch this plugin. Since SonarQube runs all its plugin in isolated + * ClassLoaders with limited access to SonarQube's core classes, this class works its way through the ClassLoader + * chain used to load this class, and finds the 'API' ClassLoader used by SonarQube to filter out 'non-core' classes. + * {@link DefaultElevatedClassLoaderFactoryProvider} is used to create a {@link ElevatedClassLoaderFactory} which generates a + * suitable ClassLoader with access to this plugin's classes and SonarQube's core classes. This resulting ClassLoader is + * used to load the class {@link CommunityBranchPlugin}, thereby allowing any instance generated from this class, and + * any dependencies of this class to have access to classes from SonarQube core. + * + * @author Michael Clarke + * @see DefaultElevatedClassLoaderFactoryProvider + * @see ElevatedClassLoaderFactory + * @see CommunityBranchPlugin + */ +public class CommunityBranchPluginBootstrap implements Plugin { + + private final ElevatedClassLoaderFactoryProvider elevatedClassLoaderFactoryProvider; + + public CommunityBranchPluginBootstrap() { + this(DefaultElevatedClassLoaderFactoryProvider.getInstance()); + } + + /*package*/ CommunityBranchPluginBootstrap(ElevatedClassLoaderFactoryProvider elevatedClassLoaderFactoryProvider) { + super(); + this.elevatedClassLoaderFactoryProvider = elevatedClassLoaderFactoryProvider; + } + + @Override + public void define(Context context) { + try { + ClassLoader classLoader = + elevatedClassLoaderFactoryProvider.createFactory(context).createClassLoader(getClass()); + Class targetClass = classLoader.loadClass(getClass().getName().replace("Bootstrap", "")); + Object instance = targetClass.newInstance(); + if (!(instance instanceof Plugin)) { + throw new IllegalStateException( + String.format("Expected loaded class to be instance of '%s' but was '%s'", + Plugin.class.getName(), instance.getClass().getName())); + } + ((Plugin) instance).define(context); + } catch (ReflectiveOperationException ex) { + throw new IllegalStateException("Could not create CommunityBranchPlugin instance", ex); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + CommunityBranchPluginBootstrap that = (CommunityBranchPluginBootstrap) o; + return Objects.equals(elevatedClassLoaderFactoryProvider, that.elevatedClassLoaderFactoryProvider); + } + + @Override + public int hashCode() { + return Objects.hash(elevatedClassLoaderFactoryProvider); + } +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranch.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranch.java new file mode 100644 index 000000000..09ae22762 --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranch.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.ce; + +import org.apache.logging.log4j.util.Strings; +import org.sonar.ce.task.projectanalysis.analysis.Branch; +import org.sonar.core.component.ComponentKeys; +import org.sonar.db.component.BranchType; +import org.sonar.db.component.ComponentDto; +import org.sonar.scanner.protocol.output.ScannerReport; + +import java.util.Optional; + +/** + * @author Michael Clarke + */ +public class CommunityBranch implements Branch { + + private final String name; + private final BranchType branchType; + private final boolean main; + private final String mergeBranchUuid; + private final String pullRequestKey; + + public CommunityBranch(String name, BranchType branchType, boolean main, String mergeBranchUuid, + String pullRequestKey) { + super(); + this.name = name; + this.branchType = branchType; + this.main = main; + this.mergeBranchUuid = mergeBranchUuid; + this.pullRequestKey = pullRequestKey; + } + + @Override + public String getName() { + return name; + } + + @Override + public BranchType getType() { + return branchType; + } + + @Override + public boolean isMain() { + return main; + } + + @Override + public boolean isLegacyFeature() { + return false; + } + + @Override + public Optional getMergeBranchUuid() { + return Optional.ofNullable(mergeBranchUuid); + } + + @Override + public boolean supportsCrossProjectCpd() { + return main; + } + + @Override + public String getPullRequestKey() { + if (BranchType.PULL_REQUEST != branchType) { + throw new IllegalStateException("Only a branch of type PULL_REQUEST can have a pull request ID"); + } + return pullRequestKey; + } + + // This method can be removed when removing support for all SonarQube versions before 7.6 + @Override + public String generateKey(ScannerReport.Component projectKey, ScannerReport.Component fileOrDirPath) { + return generateKey(projectKey.getKey(), null == fileOrDirPath ? null : fileOrDirPath.getPath()); + } + + //@Override for SonarQube 7.6 + public String generateKey(String projectKey, String fileOrDirPath) { + String effectiveKey; + if (null == fileOrDirPath) { + effectiveKey = projectKey; + } else { + effectiveKey = ComponentKeys.createEffectiveKey(projectKey, Strings.trimToNull(fileOrDirPath)); + } + + if (main) { + return effectiveKey; + } else if (BranchType.PULL_REQUEST == branchType) { + return ComponentDto.generatePullRequestKey(effectiveKey, pullRequestKey); + } else { + return ComponentDto.generateBranchKey(effectiveKey, name); + } + } + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchLoaderDelegate.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchLoaderDelegate.java new file mode 100644 index 000000000..484be4c01 --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchLoaderDelegate.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.ce; + +import org.apache.commons.lang.StringUtils; +import org.sonar.ce.task.projectanalysis.analysis.Branch; +import org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolder; +import org.sonar.ce.task.projectanalysis.component.BranchLoaderDelegate; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; +import org.sonar.db.component.BranchDto; +import org.sonar.db.component.BranchType; +import org.sonar.scanner.protocol.output.ScannerReport; +import org.sonar.server.project.Project; + +import java.util.Optional; + +/** + * @author Michael Clarke + */ +public class CommunityBranchLoaderDelegate implements BranchLoaderDelegate { + + private final DbClient dbClient; + private final MutableAnalysisMetadataHolder metadataHolder; + + public CommunityBranchLoaderDelegate(DbClient dbClient, MutableAnalysisMetadataHolder analysisMetadataHolder) { + this.dbClient = dbClient; + this.metadataHolder = analysisMetadataHolder; + } + + @Override + public void load(ScannerReport.Metadata metadata) { + Branch branch = load(metadata, metadataHolder.getProject(), dbClient); + + metadataHolder.setBranch(branch); + metadataHolder.setPullRequestKey(metadata.getPullRequestKey()); + } + + private static Branch load(ScannerReport.Metadata metadata, Project project, DbClient dbClient) { + String branchName = StringUtils.trimToNull(metadata.getBranchName()); + String projectUuid = StringUtils.trimToNull(project.getUuid()); + + if (null == branchName) { + Optional branchDto = findBranchByUuid(projectUuid, dbClient); + if (branchDto.isPresent()) { + BranchDto dto = branchDto.get(); + return new CommunityBranch(dto.getKey(), dto.getBranchType(), dto.isMain(), null, null); + } else { + throw new IllegalStateException("Could not find main branch"); + } + } else { + String targetBranch = StringUtils.trimToNull(metadata.getMergeBranchName()); + ScannerReport.Metadata.BranchType branchType = metadata.getBranchType(); + + if (ScannerReport.Metadata.BranchType.PULL_REQUEST == branchType) { + return createPullRequest(metadata, dbClient, branchName, projectUuid, targetBranch); + } else if (ScannerReport.Metadata.BranchType.LONG == branchType || + ScannerReport.Metadata.BranchType.SHORT == branchType) { + return createBranch(dbClient, branchName, projectUuid, targetBranch, branchType); + } else { + throw new IllegalStateException(String.format("Invalid branch type '%s'", branchType.name())); + } + } + } + + private static Branch createPullRequest(ScannerReport.Metadata metadata, DbClient dbClient, String branchName, + String projectUuid, String targetBranch) { + Optional branchDto = findBranchByKey(projectUuid, targetBranch, dbClient); + if (branchDto.isPresent()) { + String pullRequestKey = metadata.getPullRequestKey(); + + BranchDto dto = branchDto.get(); + return new CommunityBranch(branchName, BranchType.PULL_REQUEST, dto.isMain(), dto.getMergeBranchUuid(), + pullRequestKey); + } else { + throw new IllegalStateException( + String.format("Could not find target branch '%s' in project", targetBranch)); + } + } + + private static Branch createBranch(DbClient dbClient, String branchName, String projectUuid, String targetBranch, + ScannerReport.Metadata.BranchType branchType) { + String targetUuid; + if (null == targetBranch) { + targetUuid = projectUuid; + } else { + Optional branchDto = findBranchByKey(projectUuid, targetBranch, dbClient); + if (branchDto.isPresent()) { + targetUuid = branchDto.get().getUuid(); + } else { + throw new IllegalStateException( + String.format("Could not find target branch '%s' in project", targetBranch)); + } + } + return new CommunityBranch(branchName, ScannerReport.Metadata.BranchType.LONG == branchType ? BranchType.LONG : + BranchType.SHORT, + findBranchByKey(projectUuid, branchName, dbClient).map(BranchDto::isMain) + .orElse(false), targetUuid, null); + } + + private static Optional findBranchByUuid(String projectUuid, DbClient dbClient) { + try (DbSession dbSession = dbClient.openSession(false)) { + return dbClient.branchDao().selectByUuid(dbSession, projectUuid); + } + } + + private static Optional findBranchByKey(String projectUuid, String key, DbClient dbClient) { + try (DbSession dbSession = dbClient.openSession(false)) { + return dbClient.branchDao().selectByBranchKey(dbSession, projectUuid, key); + } + } + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityReportAnalysisComponentProvider.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityReportAnalysisComponentProvider.java new file mode 100644 index 000000000..68eb92c9c --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityReportAnalysisComponentProvider.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.ce; + +import org.sonar.ce.task.projectanalysis.container.ReportAnalysisComponentProvider; + +import java.util.Collections; +import java.util.List; + +/** + * @author Michael Clarke + */ +public class CommunityReportAnalysisComponentProvider implements ReportAnalysisComponentProvider { + + @Override + public List getComponents() { + return Collections.singletonList(CommunityBranchLoaderDelegate.class); + } + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ClassReferenceElevatedClassLoaderFactory.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ClassReferenceElevatedClassLoaderFactory.java new file mode 100644 index 000000000..76b6d5cd5 --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ClassReferenceElevatedClassLoaderFactory.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.classloader; + +import org.sonar.api.Plugin; + +/** + * A {@link ElevatedClassLoaderFactory} that uses a ClassLoader from an exposed SonarQube core class as a delegate for + * attempting to load any classes that are not found from the plugin's ClassLoader. + * + * @author Michael Clarke + */ +public class ClassReferenceElevatedClassLoaderFactory implements ElevatedClassLoaderFactory { + + private final String className; + + /*package*/ ClassReferenceElevatedClassLoaderFactory(String className) { + super(); + this.className = className; + } + + @Override + public ClassLoader createClassLoader(Class pluginClass) { + Class coreClass; + try { + coreClass = Class.forName(className); + } catch (ClassNotFoundException e) { + throw new IllegalStateException( + String.format("Could not load class '%s' from Plugin Classloader", className), e); + } + return createClassLoader(pluginClass.getClassLoader(), coreClass.getClassLoader()); + } + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/DefaultElevatedClassLoaderFactoryProvider.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/DefaultElevatedClassLoaderFactoryProvider.java new file mode 100644 index 000000000..742d761de --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/DefaultElevatedClassLoaderFactoryProvider.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.classloader; + +import org.sonar.api.Plugin; + +public final class DefaultElevatedClassLoaderFactoryProvider implements ElevatedClassLoaderFactoryProvider { + + private static final DefaultElevatedClassLoaderFactoryProvider INSTANCE = + new DefaultElevatedClassLoaderFactoryProvider(); + + private DefaultElevatedClassLoaderFactoryProvider() { + super(); + } + + @Override + public ElevatedClassLoaderFactory createFactory(Plugin.Context context) { + return ProviderType.fromName( + context.getBootConfiguration().get(ElevatedClassLoaderFactoryProvider.class.getName() + ".providerType") + .orElse(ProviderType.CLASS_REFERENCE.name())).createFactory(context); + } + + public static DefaultElevatedClassLoaderFactoryProvider getInstance() { + return INSTANCE; + } + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ElevatedClassLoaderFactory.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ElevatedClassLoaderFactory.java new file mode 100644 index 000000000..a9ae8d0e1 --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ElevatedClassLoaderFactory.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.classloader; + +import org.sonar.api.Plugin; + +import java.net.URLClassLoader; + +/** + * @author Michael Clarke + */ +public interface ElevatedClassLoaderFactory { + + /** + * Create a ClassLoader with access to the classes currently exposed to the given pluginClass instance, + * delegating any other class look-ups to SonarQube's core ClassLoader + * + * @param pluginClass the plugin class to create an elevated classloader for + * @return a ClassLoader with access to SonarQube and plugin classes, with no filtering of which SonarQube classes + * can be loaded + */ + ClassLoader createClassLoader(Class pluginClass); + + + /** + * Creates a ClassLoader that delegates class calls to a new URLClassloader referencing he same Jars as the provided + * pluginClassLoader but using the coreClassLoader as a fall back if the requested class + * could not be found, and then falling back to the original pluginClassLoader if the class still could + * not be found. This allows loading classes from the plugin, from SonarQube core, and from any sibling plugins that + * have been defined as dependencies of the current plugin. + * + * @param pluginClassLoader the ClassLoader to find the current Plugin's classes from, and to fall back to in the + * event a class from a dependent plugin is required + * @param coreClassLoader the SonarQube core ClassLoader to use for loading non plugin classes from + * @return a ClassLoader capable of loading both Plugin classes and SonarQube core classes + */ + /*package*/ + default ClassLoader createClassLoader(ClassLoader pluginClassLoader, ClassLoader coreClassLoader) { + if (!(pluginClassLoader instanceof URLClassLoader)) { + throw new IllegalStateException(String.format("Incorrect ClassLoader type. Expected '%s' but got '%s'", + URLClassLoader.class.getName(), + pluginClassLoader.getClass().getName())); + } + + /* + Sonar analysis wants us to use try-with-resources to close the following Classloader after use. Unfortunately + Sonar doesn't give us any indication of the plugin being closed/unloaded and the plugin doesn't upload all its + classes upfront, so the ClassLoader can't be closed outside of the JVM shutting down. The following line is + therefore marked as 'NOSONAR' to suppress the warning. + */ + ClassLoader newPluginClassLoader = + URLClassLoader.newInstance(((URLClassLoader) pluginClassLoader).getURLs(), coreClassLoader); //NOSONAR + return new ClassLoader() { + @Override + public Class loadClass(String name) throws ClassNotFoundException { + return loadClass(name, false); + } + + @Override + public Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + try { + return newPluginClassLoader.loadClass(name); + } catch (ClassNotFoundException ex) { + return pluginClassLoader.loadClass(name); + } + } + }; + + + } +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ElevatedClassLoaderFactoryProvider.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ElevatedClassLoaderFactoryProvider.java new file mode 100644 index 000000000..739c46e2c --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ElevatedClassLoaderFactoryProvider.java @@ -0,0 +1,7 @@ +package com.github.mc1arke.sonarqube.plugin.classloader; + +import org.sonar.api.Plugin; + +public interface ElevatedClassLoaderFactoryProvider { + ElevatedClassLoaderFactory createFactory(Plugin.Context context); +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ProviderType.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ProviderType.java new file mode 100644 index 000000000..1f028b91e --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ProviderType.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.classloader; + +import org.sonar.api.Plugin; +import org.sonar.api.rules.ActiveRule; + +import java.util.Arrays; + +/*package*/ enum ProviderType { + CLASS_REFERENCE { + @Override + ElevatedClassLoaderFactory createFactory(Plugin.Context context) { + return new ClassReferenceElevatedClassLoaderFactory(context.getBootConfiguration() + .get(ElevatedClassLoaderFactoryProvider.class + .getName() + ".targetType").orElse(ActiveRule.class.getName())); + } + }, + + REFLECTIVE { + @Override + ElevatedClassLoaderFactory createFactory(Plugin.Context context) { + return new ReflectiveElevatedClassLoaderFactory(); + } + }; + + abstract ElevatedClassLoaderFactory createFactory(Plugin.Context context); + + /*package*/ + static ProviderType fromName(String name) { + return Arrays.stream(values()).filter(v -> v.name().equals(name)).findFirst().orElseThrow( + () -> new IllegalStateException(String.format("No provider with type '%s' could be found", name))); + } + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ReflectiveElevatedClassLoaderFactory.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ReflectiveElevatedClassLoaderFactory.java new file mode 100644 index 000000000..d2ba16b49 --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/classloader/ReflectiveElevatedClassLoaderFactory.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.classloader; + +import org.sonar.api.Plugin; + +import java.lang.reflect.Field; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * Provides a facility for creating the relevant ClassLoader by using reflection to access the necessary fields in + * org.sonar.classloader.ClassRealm and org.sonar.classloader.ClassloaderRef. + * + * @author Michael Clarke + */ +public class ReflectiveElevatedClassLoaderFactory implements ElevatedClassLoaderFactory { + + private static final String CLASS_REALM_NAME = "org.sonar.classloader.ClassRealm"; + + @Override + public ClassLoader createClassLoader(Class pluginClass) { + ClassLoader pluginClassLoader = + AccessController.doPrivileged((PrivilegedAction) pluginClass::getClassLoader); + + if (!CLASS_REALM_NAME.equals(pluginClassLoader.getClass().getName())) { + throw new IllegalStateException( + String.format("Expected classloader of type '%s' but got '%s'", CLASS_REALM_NAME, + pluginClassLoader.getClass().getName())); + } + + + try { + return createFromPluginClassLoader(pluginClassLoader); + } catch (ReflectiveOperationException e) { + throw new IllegalStateException("Could not access ClassLoader chain using reflection", e); + } + } + + + private ClassLoader createFromPluginClassLoader(ClassLoader pluginClassLoader) throws ReflectiveOperationException { + Field parentRefField = pluginClassLoader.getClass().getDeclaredField("parentRef"); + parentRefField.setAccessible(true); + Object classLoaderRef = parentRefField.get(pluginClassLoader); + + Field classloaderField = classLoaderRef.getClass().getDeclaredField("classloader"); + classloaderField.setAccessible(true); + + ClassLoader pluginParentClassLoader = (ClassLoader) classloaderField.get(classLoaderRef); + + if (!CLASS_REALM_NAME.equals(pluginParentClassLoader.getClass().getName())) { + throw new IllegalStateException( + String.format("Expected classloader of type '%s' but got '%s'", CLASS_REALM_NAME, + pluginParentClassLoader.getClass().getName())); + } + + Field keyField = pluginParentClassLoader.getClass().getDeclaredField("key"); + keyField.setAccessible(true); + String key = (String) keyField.get(pluginParentClassLoader); + + if ("_api_".equals(key)) { + ClassLoader coreClassLoader = pluginParentClassLoader.getParent(); + return createClassLoader(pluginClassLoader, coreClassLoader); + } else { + throw new IllegalStateException( + String.format("Expected classloader with key '_api_' but found key '%s'", key)); + } + + + } + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchConfiguration.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchConfiguration.java new file mode 100644 index 000000000..17a6fe177 --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchConfiguration.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.scanner; + +import org.sonar.scanner.scan.branch.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchType; + +/** + * @author Michael Clarke + */ +public class CommunityBranchConfiguration implements BranchConfiguration { + + private final String branchName; + private final BranchType branchType; + private final String longLivingSonarReferenceBranch; + private final String targetScmBranch; + private final String pullRequestKey; + + /*package*/ CommunityBranchConfiguration(String branchName, BranchType branchType, + String longLivingSonarReferenceBranch, String targetScmBranch, + String pullRequestKey) { + this.branchName = branchName; + this.branchType = branchType; + this.longLivingSonarReferenceBranch = longLivingSonarReferenceBranch; + this.targetScmBranch = targetScmBranch; + this.pullRequestKey = pullRequestKey; + } + + @Override + public BranchType branchType() { + return branchType; + } + + @Override + public String branchName() { + return branchName; + } + + @Override + public String longLivingSonarReferenceBranch() { + return longLivingSonarReferenceBranch; + } + + @Override + public String targetScmBranch() { + return targetScmBranch; + } + + @Override + public String pullRequestKey() { + if (BranchType.PULL_REQUEST != branchType) { + throw new IllegalStateException("Only a branch of type PULL_REQUEST can have a Pull Request key"); + } + + return pullRequestKey; + } +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchConfigurationLoader.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchConfigurationLoader.java new file mode 100644 index 000000000..f0c64e3d4 --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchConfigurationLoader.java @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.scanner; + +import org.sonar.api.CoreProperties; +import org.sonar.api.utils.MessageException; +import org.sonar.core.config.ScannerProperties; +import org.sonar.scanner.scan.branch.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchConfigurationLoader; +import org.sonar.scanner.scan.branch.BranchInfo; +import org.sonar.scanner.scan.branch.BranchType; +import org.sonar.scanner.scan.branch.DefaultBranchConfiguration; +import org.sonar.scanner.scan.branch.ProjectBranches; +import org.sonar.scanner.scan.branch.ProjectPullRequests; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.function.Supplier; + +/** + * @author Michael Clarke + */ +public class CommunityBranchConfigurationLoader implements BranchConfigurationLoader { + + public static final String DEFAULT_BRANCH_REGEX = "(branch|release).*"; + + + private static final Set BRANCH_ANALYSIS_PARAMETERS = + new HashSet<>(Arrays.asList(ScannerProperties.BRANCH_NAME, ScannerProperties.BRANCH_TARGET)); + + private static final Set PULL_REQUEST_ANALYSIS_PARAMETERS = new HashSet<>( + Arrays.asList(ScannerProperties.PULL_REQUEST_BRANCH, ScannerProperties.PULL_REQUEST_KEY, + ScannerProperties.PULL_REQUEST_BASE)); + + @Override + public BranchConfiguration load(Map localSettings, Supplier> supplier, + ProjectBranches projectBranches, ProjectPullRequests projectPullRequests) { + if (projectBranches.isEmpty()) { + // it would be nice to identify the 'primary' branch directly, but different projects work differently: using any of master, develop, main etc as primary + // A project/global configuration entry could be used to drive this in the future, but the current documented SonarQube parameters need followed for now + throw MessageException + .of("No branches currently exist in this project. Please scan the main branch without passing any branch parameters."); + } + if (BRANCH_ANALYSIS_PARAMETERS.stream().anyMatch(localSettings::containsKey)) { + return createBranchConfiguration(localSettings.get(ScannerProperties.BRANCH_NAME), + localSettings.get(ScannerProperties.BRANCH_TARGET), supplier, + projectBranches); + } else if (PULL_REQUEST_ANALYSIS_PARAMETERS.stream().anyMatch(localSettings::containsKey)) { + return createPullRequestConfiguration(localSettings.get(ScannerProperties.PULL_REQUEST_KEY), + localSettings.get(ScannerProperties.PULL_REQUEST_BRANCH), + localSettings.get(ScannerProperties.PULL_REQUEST_BASE), + projectBranches); + } + + return new DefaultBranchConfiguration(); + } + + private static BranchConfiguration createBranchConfiguration(String branchName, String branchTarget, + Supplier> settingsSupplier, + ProjectBranches branches) { + if (null == branchTarget || branchTarget.isEmpty()) { + branchTarget = branches.defaultBranchName(); + } + + BranchInfo existingBranch = branches.get(branchName); + + if (null == existingBranch) { + final BranchType branchType = computeBranchType(settingsSupplier, branchName); + final BranchInfo targetBranch = findTargetBranch(branchTarget, branches); + return new CommunityBranchConfiguration(branchName, branchType, targetBranch.name(), branchTarget, null); + } + + if (BranchType.LONG == existingBranch.type()) { + return new CommunityBranchConfiguration(branchName, existingBranch.type(), branchName, null, null); + } else { + return new CommunityBranchConfiguration(branchName, existingBranch.type(), branchTarget, branchTarget, + null); + } + } + + private static BranchType computeBranchType(Supplier> settingsSupplier, String branchName) { + String longLivedBranchesRegex = settingsSupplier.get().get(CoreProperties.LONG_LIVED_BRANCHES_REGEX); + if (null == longLivedBranchesRegex) { + longLivedBranchesRegex = DEFAULT_BRANCH_REGEX; + } + if (branchName.matches(longLivedBranchesRegex)) { + return BranchType.LONG; + } else { + return BranchType.SHORT; + } + } + + private static BranchConfiguration createPullRequestConfiguration(String pullRequestKey, String pullRequestBranch, + String pullRequestBase, + ProjectBranches branches) { + if (null == pullRequestBase || pullRequestBase.isEmpty()) { + pullRequestBase = branches.defaultBranchName(); + } + + findTargetBranch(pullRequestBase, branches); + return new CommunityBranchConfiguration(pullRequestBranch, BranchType.PULL_REQUEST, pullRequestBase, + pullRequestBase, pullRequestKey); + } + + private static BranchInfo findTargetBranch(String targetBranch, ProjectBranches branches) { + final BranchInfo target = branches.get(targetBranch); + + if (null == target) { + throw MessageException.of("Could not target requested branch", new IllegalStateException( + String.format("Target branch '%s' does not exist", targetBranch))); + } + + if (BranchType.LONG == target.type()) { + return target; + } else { + throw MessageException.of("Could not target requested branch", new IllegalStateException( + String.format("Expected branch type of %s but got %s", BranchType.LONG.name(), + target.type().name()))); + } + } + + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchParamsValidator.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchParamsValidator.java new file mode 100644 index 000000000..28fd96ba2 --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchParamsValidator.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.scanner; + +import org.sonar.core.config.ScannerProperties; +import org.sonar.scanner.bootstrap.GlobalConfiguration; +import org.sonar.scanner.scan.branch.BranchParamsValidator; + +import java.util.List; + +/** + * @author Michael Clarke + */ +public class CommunityBranchParamsValidator implements BranchParamsValidator { + + private final GlobalConfiguration globalConfiguration; + + public CommunityBranchParamsValidator(GlobalConfiguration globalConfiguration) { + super(); + this.globalConfiguration = globalConfiguration; + } + + @Override + public void validate(List validationMessages, String deprecatedBranchName) { + if (null != deprecatedBranchName && (globalConfiguration.hasKey(ScannerProperties.BRANCH_NAME) || + globalConfiguration.hasKey(ScannerProperties.BRANCH_TARGET))) { + validationMessages.add(String.format( + "The legacy 'sonar.branch' parameter cannot be used at the same time as '%s' or '%s'", + ScannerProperties.BRANCH_NAME, ScannerProperties.BRANCH_TARGET)); + } + } +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectBranchesLoader.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectBranchesLoader.java new file mode 100644 index 000000000..967495ea7 --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectBranchesLoader.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.scanner; + +import com.google.gson.Gson; +import org.sonar.api.utils.MessageException; +import org.sonar.scanner.bootstrap.ScannerWsClient; +import org.sonar.scanner.protocol.GsonHelper; +import org.sonar.scanner.scan.branch.BranchInfo; +import org.sonar.scanner.scan.branch.ProjectBranches; +import org.sonar.scanner.scan.branch.ProjectBranchesLoader; +import org.sonar.scanner.util.ScannerUtils; +import org.sonar.server.branch.ws.ProjectBranchesParameters; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.HttpException; +import org.sonarqube.ws.client.WsResponse; + +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.List; + +/** + * Loads the branches currently known by SonarQube from the server component for client applications. + * + * @author Michael Clarke + */ +public class CommunityProjectBranchesLoader implements ProjectBranchesLoader { + + private static final String PROJECT_BRANCHES_URL = + String.format("/%s/%s?%s=", ProjectBranchesParameters.CONTROLLER, ProjectBranchesParameters.ACTION_LIST, + ProjectBranchesParameters.PARAM_PROJECT); + + private final ScannerWsClient scannerWsClient; + private final Gson gson; + + public CommunityProjectBranchesLoader(ScannerWsClient scannerWsClient) { + super(); + this.scannerWsClient = scannerWsClient; + this.gson = GsonHelper.create(); + } + + @Override + public ProjectBranches load(String projectKey) { + GetRequest branchesGetRequest = new GetRequest(PROJECT_BRANCHES_URL + ScannerUtils.encodeForUrl(projectKey)); + + try (WsResponse branchesResponse = scannerWsClient.call(branchesGetRequest); Reader reader = branchesResponse + .contentReader()) { + BranchesResponse parsedResponse = gson.fromJson(reader, BranchesResponse.class); + return new ProjectBranches(parsedResponse.getBranches()); + } catch (IOException e) { + throw MessageException.of("Could not load branches from server", e); + } catch (HttpException e) { + if (404 == e.code()) { + return new ProjectBranches(new ArrayList<>()); + } else { + throw MessageException.of("Could not load branches from server", e); + } + } + } + + /*package*/ static class BranchesResponse { + + private final List branches; + + /*package*/ BranchesResponse(List branches) { + super(); + this.branches = branches; + } + + /*package*/ List getBranches() { + return branches; + } + } + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectPullRequestsLoader.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectPullRequestsLoader.java new file mode 100644 index 000000000..6849ac51d --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectPullRequestsLoader.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.scanner; + +import com.google.gson.Gson; +import org.sonar.api.utils.MessageException; +import org.sonar.scanner.bootstrap.ScannerWsClient; +import org.sonar.scanner.protocol.GsonHelper; +import org.sonar.scanner.scan.branch.ProjectPullRequests; +import org.sonar.scanner.scan.branch.ProjectPullRequestsLoader; +import org.sonar.scanner.scan.branch.PullRequestInfo; +import org.sonar.scanner.util.ScannerUtils; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.HttpException; +import org.sonarqube.ws.client.WsResponse; + +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.List; + +/** + * Loads the Pull Requests currently known by SonarQube from the server component for client applications. + * + * @author Michael Clarke + */ +public class CommunityProjectPullRequestsLoader implements ProjectPullRequestsLoader { + + private static final String PROJECT_PULL_REQUESTS_URL = "/api/project_pull_requests/list?project="; + + private final ScannerWsClient scannerWsClient; + private final Gson gson; + + public CommunityProjectPullRequestsLoader(ScannerWsClient scannerWsClient) { + super(); + this.scannerWsClient = scannerWsClient; + this.gson = GsonHelper.create(); + } + + @Override + public ProjectPullRequests load(String projectKey) { + GetRequest branchesGetRequest = + new GetRequest(PROJECT_PULL_REQUESTS_URL + ScannerUtils.encodeForUrl(projectKey)); + + try (WsResponse branchesResponse = scannerWsClient.call(branchesGetRequest); Reader reader = branchesResponse + .contentReader()) { + PullRequestsResponse parsedResponse = gson.fromJson(reader, PullRequestsResponse.class); + return new ProjectPullRequests(parsedResponse.getPullRequests()); + } catch (IOException e) { + throw MessageException.of("Could not load pull requests from server", e); + } catch (HttpException e) { + if (404 == e.code()) { + return new ProjectPullRequests(new ArrayList<>()); + } else { + throw MessageException.of("Could not load pull requests from server", e); + } + } + } + + /*package*/ static class PullRequestsResponse { + + private final List pullRequests; + + /*package*/ PullRequestsResponse(List pullRequests) { + super(); + this.pullRequests = pullRequests; + } + + /*package*/ List getPullRequests() { + return pullRequests; + } + } + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchFeatureExtension.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchFeatureExtension.java new file mode 100644 index 000000000..02668429c --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchFeatureExtension.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.server; + +import org.sonar.server.branch.BranchFeatureExtension; + +/** + * Enables branch management in SonarQube. + * + * @author Michael Clarke + */ +public class CommunityBranchFeatureExtension implements BranchFeatureExtension { + + @Override + public boolean isEnabled() { + return true; + } + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchSupportDelegate.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchSupportDelegate.java new file mode 100644 index 000000000..76647ff54 --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchSupportDelegate.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.server; + +import org.apache.commons.lang.StringUtils; +import org.sonar.core.util.UuidFactory; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; +import org.sonar.db.ce.CeTaskCharacteristicDto; +import org.sonar.db.component.BranchDto; +import org.sonar.db.component.BranchType; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.organization.OrganizationDto; +import org.sonar.server.ce.queue.BranchSupport; +import org.sonar.server.ce.queue.BranchSupportDelegate; + +import java.time.Clock; +import java.util.Date; +import java.util.Map; +import java.util.Optional; + +/** + * @author Michael Clarke + */ +public class CommunityBranchSupportDelegate implements BranchSupportDelegate { + + private final UuidFactory uuidFactory; + private final DbClient dbClient; + private final Clock clock; + + public CommunityBranchSupportDelegate(UuidFactory uuidFactory, DbClient dbClient, Clock clock) { + super(); + this.uuidFactory = uuidFactory; + this.dbClient = dbClient; + this.clock = clock; + } + + @Override + public CommunityComponentKey createComponentKey(String projectKey, Map characteristics) { + String branchTypeParam = StringUtils.trimToNull(characteristics.get(CeTaskCharacteristicDto.BRANCH_TYPE_KEY)); + + if (null == branchTypeParam) { + String pullRequest = StringUtils.trimToNull(characteristics.get(CeTaskCharacteristicDto.PULL_REQUEST)); + if (null == pullRequest) { + throw new IllegalArgumentException(String.format("One of '%s' or '%s' parameters must be specified", + CeTaskCharacteristicDto.BRANCH_TYPE_KEY, + CeTaskCharacteristicDto.PULL_REQUEST)); + } else { + return new CommunityComponentKey(projectKey, + ComponentDto.generatePullRequestKey(projectKey, pullRequest), null, + pullRequest, null); + } + } + + String branch = StringUtils.trimToNull(characteristics.get(CeTaskCharacteristicDto.BRANCH_KEY)); + + try { + BranchType branchType = BranchType.valueOf(branchTypeParam); + if (branchType == BranchType.LONG || branchType == BranchType.SHORT) { + return new CommunityComponentKey(projectKey, ComponentDto.generateBranchKey(projectKey, branch), + new BranchSupport.Branch(branch, branchType), null, null); + } + } catch (IllegalArgumentException ex) { + throw new IllegalArgumentException(String.format("Unsupported branch type '%s'", branchTypeParam), ex); + } + + throw new IllegalArgumentException(String.format("Unsupported branch type '%s'", branchTypeParam)); + } + + @Override + public ComponentDto createBranchComponent(DbSession dbSession, BranchSupport.ComponentKey componentKey, + OrganizationDto organization, ComponentDto mainComponentDto, + BranchDto mainComponentBranchDto) { + if (!componentKey.getKey().equals(mainComponentDto.getKey())) { + throw new IllegalStateException("Component Key and Main Component Key do not match"); + } + + Optional branchOptional = componentKey.getBranch(); + if (branchOptional.isPresent() && branchOptional.get().getName().equals(mainComponentBranchDto.getKey()) && + mainComponentBranchDto.getBranchType() == branchOptional.get().getType()) { + return mainComponentDto; + } + + String branchUuid = uuidFactory.create(); + + // borrowed from https://github.com/SonarSource/sonarqube/blob/e80c0f3d1e5cd459f88b7e0c41a2d9a7519e260f/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImpl.java + ComponentDto branchDto = mainComponentDto.copy(); + branchDto.setUuid(branchUuid); + branchDto.setProjectUuid(branchUuid); + branchDto.setRootUuid(branchUuid); + branchDto.setUuidPath(ComponentDto.UUID_PATH_OF_ROOT); + branchDto.setModuleUuidPath(ComponentDto.UUID_PATH_SEPARATOR + branchUuid + ComponentDto.UUID_PATH_SEPARATOR); + branchDto.setMainBranchProjectUuid(mainComponentDto.uuid()); + branchDto.setDbKey(componentKey.getDbKey()); + branchDto.setCreatedAt(new Date(clock.millis())); + dbClient.componentDao().insert(dbSession, branchDto); + return branchDto; + } + +} diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/server/CommunityComponentKey.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/server/CommunityComponentKey.java new file mode 100644 index 000000000..e2651179b --- /dev/null +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/server/CommunityComponentKey.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.server; + +import org.sonar.server.ce.queue.BranchSupport; + +import java.util.Optional; + +/** + * @author Michael Clarke + */ +/*package*/ class CommunityComponentKey extends BranchSupport.ComponentKey { + + private final String key; + private final String dbKey; + private final String deprecatedBranchName; + private final BranchSupport.Branch branch; + private final String pullRequestKey; + + /*package*/ CommunityComponentKey(String key, String dbKey, BranchSupport.Branch branch, String pullRequestKey, + String deprecatedBranchName) { + this.key = key; + this.dbKey = dbKey; + this.deprecatedBranchName = deprecatedBranchName; + this.branch = branch; + this.pullRequestKey = pullRequestKey; + } + + @Override + public String getKey() { + return key; + } + + @Override + public String getDbKey() { + return dbKey; + } + + @Override + public Optional getDeprecatedBranchName() { + return Optional.ofNullable(deprecatedBranchName); + } + + @Override + public Optional getBranch() { + return Optional.ofNullable(branch); + } + + @Override + public Optional getPullRequestKey() { + return Optional.ofNullable(pullRequestKey); + } + + @Override + public CommunityComponentKey getMainBranchComponentKey() { + if (key.equals(dbKey)) { + return this; + } + return new CommunityComponentKey(key, key, null, null, deprecatedBranchName); + } +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPluginBootstrapTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPluginBootstrapTest.java new file mode 100644 index 000000000..5f37a183f --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPluginBootstrapTest.java @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin; + +import com.github.mc1arke.sonarqube.plugin.classloader.DefaultElevatedClassLoaderFactoryProvider; +import com.github.mc1arke.sonarqube.plugin.classloader.ElevatedClassLoaderFactory; +import com.github.mc1arke.sonarqube.plugin.classloader.ElevatedClassLoaderFactoryProvider; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.core.IsEqual; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mockito; +import org.sonar.api.Plugin; +import org.sonar.api.SonarQubeSide; +import org.sonar.api.SonarRuntime; +import org.sonar.api.config.Configuration; + +import java.util.Optional; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +/** + * @author Michael Clarke + */ +public class CommunityBranchPluginBootstrapTest { + + private final ExpectedException expectedException = ExpectedException.none(); + + @Rule + public ExpectedException expectedException() { + return expectedException; + } + + @Before + public void setup() { + MockPlugin.invokedContext = null; + } + + @Test + public void testDefineInvokedOnSuccessLoad() throws ClassNotFoundException { + Plugin.Context context = spy(mock(Plugin.Context.class)); + Configuration configuration = mock(Configuration.class); + when(context.getBootConfiguration()).thenReturn(configuration); + when(configuration.get(any())).thenReturn(Optional.empty()); + SonarRuntime sonarRuntime = mock(SonarRuntime.class); + when(context.getRuntime()).thenReturn(sonarRuntime); + when(sonarRuntime.getSonarQubeSide()).thenReturn(SonarQubeSide.SERVER); + + ClassLoader classLoader = mock(ClassLoader.class); + when(classLoader.loadClass(any())).thenReturn((Class) MockPlugin.class); + + ElevatedClassLoaderFactory elevatedClassLoaderFactory = mock(ElevatedClassLoaderFactory.class); + when(elevatedClassLoaderFactory.createClassLoader(any())).thenReturn(classLoader); + + ElevatedClassLoaderFactoryProvider elevatedClassLoaderFactoryProvider = + mock(ElevatedClassLoaderFactoryProvider.class); + when(elevatedClassLoaderFactoryProvider.createFactory(any())).thenReturn(elevatedClassLoaderFactory); + + CommunityBranchPluginBootstrap testCase = + new CommunityBranchPluginBootstrap(elevatedClassLoaderFactoryProvider); + testCase.define(context); + + assertEquals(context, MockPlugin.invokedContext); + } + + @Test + public void testFailureOnIncorrectClassTypeReturned() throws ReflectiveOperationException { + ClassLoader classLoader = mock(ClassLoader.class); + doReturn(this.getClass()).when(classLoader).loadClass(any()); + + ElevatedClassLoaderFactory classLoaderFactory = mock(ElevatedClassLoaderFactory.class); + when(classLoaderFactory.createClassLoader(any())).thenReturn(classLoader); + + Plugin.Context context = mock(Plugin.Context.class, Mockito.RETURNS_DEEP_STUBS); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo( + "Expected loaded class to be instance of 'org.sonar.api.Plugin' but was '" + getClass().getName() + + "'")); + + ElevatedClassLoaderFactory elevatedClassLoaderFactory = mock(ElevatedClassLoaderFactory.class); + when(elevatedClassLoaderFactory.createClassLoader(any())).thenReturn(classLoader); + + ElevatedClassLoaderFactoryProvider elevatedClassLoaderFactoryProvider = + mock(ElevatedClassLoaderFactoryProvider.class); + when(elevatedClassLoaderFactoryProvider.createFactory(any())).thenReturn(elevatedClassLoaderFactory); + + + CommunityBranchPluginBootstrap testCase = + new CommunityBranchPluginBootstrap(elevatedClassLoaderFactoryProvider); + testCase.define(context); + } + + @Test + public void testFailureOnReflectiveOperationException() throws ReflectiveOperationException { + ClassLoader classLoader = mock(ClassLoader.class); + doThrow(new ClassNotFoundException("Whoops")).when(classLoader).loadClass(any()); + + Plugin.Context context = mock(Plugin.Context.class, Mockito.RETURNS_DEEP_STUBS); + + expectedException.expectCause(new BaseMatcher() { + + @Override + public void describeTo(Description description) { + description.appendText("Cause matcher"); + } + + @Override + public boolean matches(Object item) { + if (item instanceof ClassNotFoundException) { + return "Whoops".equals(((ClassNotFoundException) item).getMessage()); + } + return false; + } + }); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo("Could not create CommunityBranchPlugin instance")); + + + ElevatedClassLoaderFactory elevatedClassLoaderFactory = mock(ElevatedClassLoaderFactory.class); + when(elevatedClassLoaderFactory.createClassLoader(any())).thenReturn(classLoader); + + ElevatedClassLoaderFactoryProvider elevatedClassLoaderFactoryProvider = + mock(ElevatedClassLoaderFactoryProvider.class); + when(elevatedClassLoaderFactoryProvider.createFactory(any())).thenReturn(elevatedClassLoaderFactory); + + + CommunityBranchPluginBootstrap testCase = + new CommunityBranchPluginBootstrap(elevatedClassLoaderFactoryProvider); + testCase.define(context); + } + + @Test + public void testNoArgsConstructor() { + assertEquals(new CommunityBranchPluginBootstrap(DefaultElevatedClassLoaderFactoryProvider.getInstance()), + new CommunityBranchPluginBootstrap()); + assertEquals( + new CommunityBranchPluginBootstrap(DefaultElevatedClassLoaderFactoryProvider.getInstance()).hashCode(), + new CommunityBranchPluginBootstrap().hashCode()); + + } + + @Test + public void testEqualsSameInstance() { + CommunityBranchPluginBootstrap testCase = new CommunityBranchPluginBootstrap(); + assertEquals(testCase, testCase); + } + + @Test + public void testNotEqualsUnrelatedClasses() { + assertNotEquals(new CommunityBranchPluginBootstrap(), ""); + assertNotEquals(new CommunityBranchPluginBootstrap(), null); + } + + @Test + public void testDifferentHashCode() { + assertNotEquals(new CommunityBranchPluginBootstrap(mock(ElevatedClassLoaderFactoryProvider.class)).hashCode(), + new CommunityBranchPluginBootstrap(mock(ElevatedClassLoaderFactoryProvider.class)).hashCode()); + } + + + public static class MockPlugin implements Plugin { + + private static Context invokedContext; + + @Override + public void define(Context context) { + invokedContext = context; + } + } +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPluginTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPluginTest.java new file mode 100644 index 000000000..91482f55d --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPluginTest.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin; + +import com.github.mc1arke.sonarqube.plugin.ce.CommunityReportAnalysisComponentProvider; +import com.github.mc1arke.sonarqube.plugin.scanner.CommunityBranchConfigurationLoader; +import com.github.mc1arke.sonarqube.plugin.scanner.CommunityBranchParamsValidator; +import com.github.mc1arke.sonarqube.plugin.scanner.CommunityProjectBranchesLoader; +import com.github.mc1arke.sonarqube.plugin.scanner.CommunityProjectPullRequestsLoader; +import com.github.mc1arke.sonarqube.plugin.server.CommunityBranchFeatureExtension; +import com.github.mc1arke.sonarqube.plugin.server.CommunityBranchSupportDelegate; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.sonar.api.Plugin; +import org.sonar.api.SonarQubeSide; + +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * @author Michael Clarke + */ +public class CommunityBranchPluginTest { + + private final ExpectedException expectedException = ExpectedException.none(); + + @Rule + public ExpectedException expectedException() { + return expectedException; + } + + @Test + public void testScannerSideDefine() { + CommunityBranchPlugin testCase = new CommunityBranchPlugin(); + + Plugin.Context context = spy(mock(Plugin.Context.class, Mockito.RETURNS_DEEP_STUBS)); + when(context.getRuntime().getSonarQubeSide()).thenReturn(SonarQubeSide.SCANNER); + + testCase.define(context); + + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Object.class); + verify(context, times(2)) + .addExtensions(argumentCaptor.capture(), argumentCaptor.capture(), argumentCaptor.capture()); + + + assertEquals(Arrays.asList(CommunityProjectBranchesLoader.class, CommunityProjectPullRequestsLoader.class, + CommunityBranchConfigurationLoader.class, CommunityBranchParamsValidator.class), + argumentCaptor.getAllValues().subList(0, 4)); + } + + @Test + public void testComputeEngineSideDefine() { + CommunityBranchPlugin testCase = new CommunityBranchPlugin(); + + Plugin.Context context = spy(mock(Plugin.Context.class, Mockito.RETURNS_DEEP_STUBS)); + when(context.getRuntime().getSonarQubeSide()).thenReturn(SonarQubeSide.COMPUTE_ENGINE); + + testCase.define(context); + + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Object.class); + verify(context).addExtension(argumentCaptor.capture()); + + + assertEquals(CommunityReportAnalysisComponentProvider.class, argumentCaptor.getValue()); + } + + + @Test + public void testServerSideDefine() { + CommunityBranchPlugin testCase = new CommunityBranchPlugin(); + + Plugin.Context context = spy(mock(Plugin.Context.class, Mockito.RETURNS_DEEP_STUBS)); + when(context.getRuntime().getSonarQubeSide()).thenReturn(SonarQubeSide.SERVER); + + testCase.define(context); + + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Object.class); + verify(context, times(2)) + .addExtensions(argumentCaptor.capture(), argumentCaptor.capture(), argumentCaptor.capture()); + + + assertEquals(Arrays.asList(CommunityBranchFeatureExtension.class, CommunityBranchSupportDelegate.class), + argumentCaptor.getAllValues().subList(0, 2)); + } + + @Test + public void testDefine() { + CommunityBranchPlugin testCase = new CommunityBranchPlugin(); + + Plugin.Context context = spy(mock(Plugin.Context.class, Mockito.RETURNS_DEEP_STUBS)); + + testCase.define(context); + + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Object.class); + verify(context).addExtensions(argumentCaptor.capture(), argumentCaptor.capture(), argumentCaptor.capture()); + + + assertEquals(2, argumentCaptor.getAllValues().size()); + } +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchLoaderDelegateTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchLoaderDelegateTest.java new file mode 100644 index 000000000..dc8fdf1b6 --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchLoaderDelegateTest.java @@ -0,0 +1,325 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.ce; + +import org.hamcrest.core.IsEqual; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderImpl; +import org.sonar.db.DbClient; +import org.sonar.db.component.BranchDao; +import org.sonar.db.component.BranchDto; +import org.sonar.db.component.BranchType; +import org.sonar.scanner.protocol.output.ScannerReport; +import org.sonar.server.project.Project; + +import java.util.ArrayList; +import java.util.Optional; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author Michael Clarke + */ +public class CommunityBranchLoaderDelegateTest { + + private final ExpectedException expectedException = ExpectedException.none(); + + @Rule + public ExpectedException expectedException() { + return expectedException; + } + + @Test + public void testNoBranchDetailsNoExistingBranchThrowsException() { + + BranchDao branchDao = mock(BranchDao.class); + when(branchDao.selectByBranchKey(any(), any(), any())).thenReturn(Optional.empty()); + + ScannerReport.Metadata metadata = ScannerReport.Metadata.getDefaultInstance(); + DbClient dbClient = mock(DbClient.class); + when(dbClient.branchDao()).thenReturn(branchDao); + AnalysisMetadataHolderImpl metadataHolder = new AnalysisMetadataHolderImpl(); + metadataHolder.setProject(new Project("uuid", "key", "name", "description", new ArrayList<>())); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo("Could not find main branch")); + + new CommunityBranchLoaderDelegate(dbClient, metadataHolder).load(metadata); + } + + @Test + public void testNoBranchDetailsExistingBranchMatch() { + BranchDto branchDto = mock(BranchDto.class); + when(branchDto.getBranchType()).thenReturn(BranchType.SHORT); + when(branchDto.getKey()).thenReturn("branchKey"); + when(branchDto.getMergeBranchUuid()).thenReturn("mergeBranchUuid"); + when(branchDto.getProjectUuid()).thenReturn("projectUuid"); + when(branchDto.getUuid()).thenReturn("branchUuid"); + + BranchDao branchDao = mock(BranchDao.class); + when(branchDao.selectByUuid(any(), any())).thenReturn(Optional.of(branchDto)); + + ScannerReport.Metadata metadata = ScannerReport.Metadata.getDefaultInstance(); + DbClient dbClient = mock(DbClient.class); + when(dbClient.branchDao()).thenReturn(branchDao); + AnalysisMetadataHolderImpl metadataHolder = new AnalysisMetadataHolderImpl(); + metadataHolder.setProject(new Project("uuid", "key", "name", "description", new ArrayList<>())); + + new CommunityBranchLoaderDelegate(dbClient, metadataHolder).load(metadata); + + assertEquals(BranchType.SHORT, metadataHolder.getBranch().getType()); + assertFalse(metadataHolder.getBranch().getMergeBranchUuid().isPresent()); + assertEquals("branchKey", metadataHolder.getBranch().getName()); + assertFalse(metadataHolder.getBranch().isLegacyFeature()); + assertFalse(metadataHolder.getBranch().isMain()); + assertFalse(metadataHolder.getBranch().supportsCrossProjectCpd()); + } + + @Test + public void testBranchNameNoMatchingBranch() { + + BranchDao branchDao = mock(BranchDao.class); + when(branchDao.selectByBranchKey(any(), any(), any())).thenReturn(Optional.empty()); + + ScannerReport.Metadata metadata = + ScannerReport.Metadata.getDefaultInstance().toBuilder().setBranchName("branch").build(); + + DbClient dbClient = mock(DbClient.class); + when(dbClient.branchDao()).thenReturn(branchDao); + AnalysisMetadataHolderImpl metadataHolder = new AnalysisMetadataHolderImpl(); + metadataHolder.setProject(new Project("uuid", "key", "name", "description", new ArrayList<>())); + + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo("Invalid branch type 'UNSET'")); + + new CommunityBranchLoaderDelegate(dbClient, metadataHolder).load(metadata); + } + + @Test + public void testBranchNameMatchingShortBranch() { + BranchDto branchDto = mock(BranchDto.class); + when(branchDto.getBranchType()).thenReturn(BranchType.SHORT); + when(branchDto.getKey()).thenReturn("branchKey"); + when(branchDto.getMergeBranchUuid()).thenReturn("mergeBranchUuid"); + when(branchDto.getProjectUuid()).thenReturn("projectUuid"); + when(branchDto.getUuid()).thenReturn("branchUuid"); + + BranchDao branchDao = mock(BranchDao.class); + when(branchDao.selectByBranchKey(any(), eq("projectUuid"), eq("branch"))).thenReturn(Optional.of(branchDto)); + + ScannerReport.Metadata metadata = + ScannerReport.Metadata.getDefaultInstance().toBuilder().setBranchName("branch") + .setBranchType(ScannerReport.Metadata.BranchType.SHORT).build(); + + DbClient dbClient = mock(DbClient.class); + when(dbClient.branchDao()).thenReturn(branchDao); + AnalysisMetadataHolderImpl metadataHolder = new AnalysisMetadataHolderImpl(); + metadataHolder.setProject(new Project("projectUuid", "key", "name", "description", new ArrayList<>())); + + new CommunityBranchLoaderDelegate(dbClient, metadataHolder).load(metadata); + + assertEquals(BranchType.SHORT, metadataHolder.getBranch().getType()); + assertTrue(metadataHolder.getBranch().getMergeBranchUuid().isPresent()); + assertEquals("projectUuid", metadataHolder.getBranch().getMergeBranchUuid().get()); + assertEquals("branch", metadataHolder.getBranch().getName()); + assertFalse(metadataHolder.getBranch().isLegacyFeature()); + assertFalse(metadataHolder.getBranch().isMain()); + assertFalse(metadataHolder.getBranch().supportsCrossProjectCpd()); + } + + @Test + public void testBranchNameMatchingLongBranch() { + BranchDto branchDto = mock(BranchDto.class); + when(branchDto.getBranchType()).thenReturn(BranchType.LONG); + when(branchDto.getKey()).thenReturn("branchKey"); + when(branchDto.getMergeBranchUuid()).thenReturn("mergeBranchUuid"); + when(branchDto.getProjectUuid()).thenReturn("projectUuid"); + when(branchDto.getUuid()).thenReturn("branchUuid"); + + BranchDao branchDao = mock(BranchDao.class); + when(branchDao.selectByBranchKey(any(), eq("projectUuid"), eq("branch"))).thenReturn(Optional.of(branchDto)); + + ScannerReport.Metadata metadata = + ScannerReport.Metadata.getDefaultInstance().toBuilder().setBranchName("branch") + .setBranchType(ScannerReport.Metadata.BranchType.LONG).build(); + + DbClient dbClient = mock(DbClient.class); + when(dbClient.branchDao()).thenReturn(branchDao); + AnalysisMetadataHolderImpl metadataHolder = new AnalysisMetadataHolderImpl(); + metadataHolder.setProject(new Project("projectUuid", "key", "name", "description", new ArrayList<>())); + + new CommunityBranchLoaderDelegate(dbClient, metadataHolder).load(metadata); + + assertEquals(BranchType.LONG, metadataHolder.getBranch().getType()); + assertTrue(metadataHolder.getBranch().getMergeBranchUuid().isPresent()); + assertEquals("projectUuid", metadataHolder.getBranch().getMergeBranchUuid().get()); + assertEquals("branch", metadataHolder.getBranch().getName()); + assertFalse(metadataHolder.getBranch().isLegacyFeature()); + assertFalse(metadataHolder.getBranch().isMain()); + assertFalse(metadataHolder.getBranch().supportsCrossProjectCpd()); + } + + @Test + public void testBranchNamePullRequest() { + BranchDto branchDto = mock(BranchDto.class); + when(branchDto.getBranchType()).thenReturn(BranchType.PULL_REQUEST); + when(branchDto.getKey()).thenReturn("branchKey"); + when(branchDto.getMergeBranchUuid()).thenReturn("mergeBranchUuid"); + when(branchDto.getProjectUuid()).thenReturn("projectUuid"); + when(branchDto.getUuid()).thenReturn("branchUuid"); + + BranchDao branchDao = mock(BranchDao.class); + when(branchDao.selectByBranchKey(any(), eq("projectUuid"), eq("branch"))).thenReturn(Optional.of(branchDto)); + + ScannerReport.Metadata metadata = + ScannerReport.Metadata.getDefaultInstance().toBuilder().setBranchName("sourceBranch") + .setMergeBranchName("branch").setBranchType(ScannerReport.Metadata.BranchType.PULL_REQUEST) + .build(); + + DbClient dbClient = mock(DbClient.class); + when(dbClient.branchDao()).thenReturn(branchDao); + AnalysisMetadataHolderImpl metadataHolder = new AnalysisMetadataHolderImpl(); + metadataHolder.setProject(new Project("projectUuid", "key", "name", "description", new ArrayList<>())); + + new CommunityBranchLoaderDelegate(dbClient, metadataHolder).load(metadata); + + assertEquals(BranchType.PULL_REQUEST, metadataHolder.getBranch().getType()); + assertTrue(metadataHolder.getBranch().getMergeBranchUuid().isPresent()); + assertEquals("mergeBranchUuid", metadataHolder.getBranch().getMergeBranchUuid().get()); + assertEquals("sourceBranch", metadataHolder.getBranch().getName()); + assertFalse(metadataHolder.getBranch().isLegacyFeature()); + assertFalse(metadataHolder.getBranch().isMain()); + assertFalse(metadataHolder.getBranch().supportsCrossProjectCpd()); + } + + @Test + public void testBranchNamePullRequestNoSuchTarget() { + BranchDao branchDao = mock(BranchDao.class); + when(branchDao.selectByBranchKey(any(), eq("projectUuid"), eq("branch"))).thenReturn(Optional.empty()); + + ScannerReport.Metadata metadata = + ScannerReport.Metadata.getDefaultInstance().toBuilder().setBranchName("sourceBranch") + .setMergeBranchName("branch").setBranchType(ScannerReport.Metadata.BranchType.PULL_REQUEST) + .build(); + + DbClient dbClient = mock(DbClient.class); + when(dbClient.branchDao()).thenReturn(branchDao); + AnalysisMetadataHolderImpl metadataHolder = new AnalysisMetadataHolderImpl(); + metadataHolder.setProject(new Project("projectUuid", "key", "name", "description", new ArrayList<>())); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo("Could not find target branch 'branch' in project")); + + + new CommunityBranchLoaderDelegate(dbClient, metadataHolder).load(metadata); + + assertEquals(BranchType.PULL_REQUEST, metadataHolder.getBranch().getType()); + assertTrue(metadataHolder.getBranch().getMergeBranchUuid().isPresent()); + assertEquals("mergeBranchUuid", metadataHolder.getBranch().getMergeBranchUuid().get()); + assertEquals("sourceBranch", metadataHolder.getBranch().getName()); + assertFalse(metadataHolder.getBranch().isLegacyFeature()); + assertFalse(metadataHolder.getBranch().isMain()); + assertFalse(metadataHolder.getBranch().supportsCrossProjectCpd()); + } + + + @Test + public void testBranchNameMatchingShortBranchWithTargetBranch() { + BranchDto sourceBranchDto = mock(BranchDto.class); + when(sourceBranchDto.getBranchType()).thenReturn(BranchType.SHORT); + when(sourceBranchDto.getKey()).thenReturn("branchKey"); + when(sourceBranchDto.getMergeBranchUuid()).thenReturn("mergeBranchUuid"); + when(sourceBranchDto.getProjectUuid()).thenReturn("projectUuid"); + when(sourceBranchDto.getUuid()).thenReturn("branchUuid"); + + BranchDto targetBranchDto = mock(BranchDto.class); + when(targetBranchDto.getBranchType()).thenReturn(BranchType.LONG); + when(targetBranchDto.getKey()).thenReturn("targetBranchKey"); + when(targetBranchDto.getMergeBranchUuid()).thenReturn("targetMergeBranchUuid"); + when(targetBranchDto.getProjectUuid()).thenReturn("projectUuid"); + when(targetBranchDto.getUuid()).thenReturn("targetBranchUuid"); + + BranchDao branchDao = mock(BranchDao.class); + when(branchDao.selectByBranchKey(any(), eq("projectUuid"), eq("branch"))) + .thenReturn(Optional.of(sourceBranchDto)); + when(branchDao.selectByBranchKey(any(), eq("projectUuid"), eq("mergeBranchName"))) + .thenReturn(Optional.of(targetBranchDto)); + + ScannerReport.Metadata metadata = + ScannerReport.Metadata.getDefaultInstance().toBuilder().setBranchName("branch") + .setBranchType(ScannerReport.Metadata.BranchType.SHORT).setMergeBranchName("mergeBranchName") + .build(); + + DbClient dbClient = mock(DbClient.class); + when(dbClient.branchDao()).thenReturn(branchDao); + AnalysisMetadataHolderImpl metadataHolder = new AnalysisMetadataHolderImpl(); + metadataHolder.setProject(new Project("projectUuid", "key", "name", "description", new ArrayList<>())); + + new CommunityBranchLoaderDelegate(dbClient, metadataHolder).load(metadata); + + assertEquals(BranchType.SHORT, metadataHolder.getBranch().getType()); + assertTrue(metadataHolder.getBranch().getMergeBranchUuid().isPresent()); + assertEquals("targetBranchUuid", metadataHolder.getBranch().getMergeBranchUuid().get()); + assertEquals("branch", metadataHolder.getBranch().getName()); + assertFalse(metadataHolder.getBranch().isLegacyFeature()); + assertFalse(metadataHolder.getBranch().isMain()); + assertFalse(metadataHolder.getBranch().supportsCrossProjectCpd()); + } + + @Test + public void testBranchNameMatchingShortBranchWithTargetBranchMissingTargetBranch() { + BranchDto sourceBranchDto = mock(BranchDto.class); + when(sourceBranchDto.getBranchType()).thenReturn(BranchType.SHORT); + when(sourceBranchDto.getKey()).thenReturn("branchKey"); + when(sourceBranchDto.getMergeBranchUuid()).thenReturn("mergeBranchUuid"); + when(sourceBranchDto.getProjectUuid()).thenReturn("projectUuid"); + when(sourceBranchDto.getUuid()).thenReturn("branchUuid"); + + BranchDao branchDao = mock(BranchDao.class); + when(branchDao.selectByBranchKey(any(), eq("projectUuid"), eq("branch"))) + .thenReturn(Optional.of(sourceBranchDto)); + when(branchDao.selectByBranchKey(any(), eq("projectUuid"), eq("mergeBranchName"))).thenReturn(Optional.empty()); + + ScannerReport.Metadata metadata = + ScannerReport.Metadata.getDefaultInstance().toBuilder().setBranchName("branch") + .setBranchType(ScannerReport.Metadata.BranchType.SHORT).setMergeBranchName("mergeBranchName") + .build(); + + DbClient dbClient = mock(DbClient.class); + when(dbClient.branchDao()).thenReturn(branchDao); + AnalysisMetadataHolderImpl metadataHolder = new AnalysisMetadataHolderImpl(); + metadataHolder.setProject(new Project("projectUuid", "key", "name", "description", new ArrayList<>())); + + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo("Could not find target branch 'mergeBranchName' in project")); + + new CommunityBranchLoaderDelegate(dbClient, metadataHolder).load(metadata); + } + +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchTest.java new file mode 100644 index 000000000..f7fdbdef2 --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.ce; + +import org.hamcrest.core.IsEqual; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.db.component.BranchType; +import org.sonar.scanner.protocol.output.ScannerReport; + +import static org.junit.Assert.assertEquals; + +/** + * @author Michael Clarke + */ +public class CommunityBranchTest { + + private final ExpectedException expectedException = ExpectedException.none(); + + @Rule + public ExpectedException expectedException() { + return expectedException; + } + + @Test + public void testGenerateKeyMainBranchNullFileOfPath() { + CommunityBranch testCase = new CommunityBranch("name", BranchType.PULL_REQUEST, true, null, null); + + ScannerReport.Component projectKey = + ScannerReport.Component.getDefaultInstance().toBuilder().setKey("projectKey").build(); + + assertEquals("projectKey", testCase.generateKey(projectKey, null)); + } + + @Test + public void testGenerateKeyMainBranchNonNullFileOfPathHolder() { + CommunityBranch testCase = new CommunityBranch("name", BranchType.PULL_REQUEST, true, null, null); + + ScannerReport.Component projectKey = + ScannerReport.Component.getDefaultInstance().toBuilder().setKey("projectKey").build(); + ScannerReport.Component fileOrPath = ScannerReport.Component.getDefaultInstance(); + + assertEquals("projectKey", testCase.generateKey(projectKey, fileOrPath)); + } + + @Test + public void testGenerateKeyMainBranchNonNullFileOfPathContent() { + CommunityBranch testCase = new CommunityBranch("name", BranchType.PULL_REQUEST, true, null, null); + + ScannerReport.Component projectKey = + ScannerReport.Component.getDefaultInstance().toBuilder().setKey("projectKey").build(); + ScannerReport.Component fileOrPath = + ScannerReport.Component.getDefaultInstance().toBuilder().setPath("path").build(); + + assertEquals("projectKey:path", testCase.generateKey(projectKey, fileOrPath)); + } + + @Test + public void testGenerateKeyNonMainBranchNonNullFileOfPathContentPullRequest() { + CommunityBranch testCase = new CommunityBranch("name", BranchType.PULL_REQUEST, false, null, "pullRequestKey"); + + ScannerReport.Component projectKey = + ScannerReport.Component.getDefaultInstance().toBuilder().setKey("projectKey").build(); + ScannerReport.Component fileOrPath = + ScannerReport.Component.getDefaultInstance().toBuilder().setPath("path").build(); + + assertEquals("projectKey:path:PULL_REQUEST:pullRequestKey", testCase.generateKey(projectKey, fileOrPath)); + } + + @Test + public void testGenerateKeyNonMainBranchNonNullFileOfPathContentShortBranch() { + CommunityBranch testCase = new CommunityBranch("name", BranchType.SHORT, false, null, null); + + ScannerReport.Component projectKey = + ScannerReport.Component.getDefaultInstance().toBuilder().setKey("projectKey").build(); + ScannerReport.Component fileOrPath = + ScannerReport.Component.getDefaultInstance().toBuilder().setPath("path").build(); + + assertEquals("projectKey:path:BRANCH:name", testCase.generateKey(projectKey, fileOrPath)); + } + + + @Test + public void testGetPulRequestKey() { + assertEquals("prKey", + new CommunityBranch("name", BranchType.PULL_REQUEST, false, null, "prKey").getPullRequestKey()); + } + + @Test + public void testGetPulRequestKeyNonPullRequest() { + expectedException + .expectMessage(IsEqual.equalTo("Only a branch of type PULL_REQUEST can have a pull request ID")); + expectedException.expect(IllegalStateException.class); + + new CommunityBranch("name", BranchType.SHORT, false, null, "prKey").getPullRequestKey(); + } + +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityReportAnalysisComponentProviderTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityReportAnalysisComponentProviderTest.java new file mode 100644 index 000000000..d1d0e40a7 --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityReportAnalysisComponentProviderTest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.ce; + +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * @author Michael Clarke + */ +public class CommunityReportAnalysisComponentProviderTest { + + @Test + public void testGetComponents() { + List result = new CommunityReportAnalysisComponentProvider().getComponents(); + assertEquals(1, result.size()); + assertEquals(CommunityBranchLoaderDelegate.class, result.get(0)); + } +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ClassReferenceElevatedClassLoaderFactoryTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ClassReferenceElevatedClassLoaderFactoryTest.java new file mode 100644 index 000000000..11926450c --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ClassReferenceElevatedClassLoaderFactoryTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.classloader; + +import org.hamcrest.core.IsEqual; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.ArgumentCaptor; +import org.sonar.api.Plugin; +import org.sonar.api.batch.rule.ActiveRule; +import org.sonar.classloader.ClassloaderBuilder; +import org.sonar.classloader.Mask; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.Arrays; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +/** + * @author Michael Clarke + */ +public class ClassReferenceElevatedClassLoaderFactoryTest { + + private final ExpectedException expectedException = ExpectedException.none(); + + @Rule + public ExpectedException expectedException() { + return expectedException; + } + + @Test + public void testExceptionOnNoSuchClass() { + ClassReferenceElevatedClassLoaderFactory testCase = new ClassReferenceElevatedClassLoaderFactory("1"); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo("Could not load class '1' from Plugin Classloader")); + + testCase.createClassLoader(((Plugin) context -> { + }).getClass()); + } + + @Test + public void testClassloaderReturnedOnHappyPath() { + ClassReferenceElevatedClassLoaderFactory testCase = + spy(new ClassReferenceElevatedClassLoaderFactory(getClass().getName())); + testCase.createClassLoader(((Plugin) context -> { + }).getClass()); + + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(ClassLoader.class); + verify(testCase).createClassLoader(argumentCaptor.capture(), argumentCaptor.capture()); + + assertEquals(Arrays.asList(getClass().getClassLoader(), getClass().getClassLoader()), + argumentCaptor.getAllValues()); + } + + @Test + public void testLoadClass() throws ClassNotFoundException, MalformedURLException { + ClassloaderBuilder builder = new ClassloaderBuilder(); + builder.newClassloader("_api_", getClass().getClassLoader()); + builder.setMask("_api_", new Mask().addInclusion("java/").addInclusion("org/sonar/api/")); + + builder.newClassloader("_customPlugin"); + builder.setParent("_customPlugin", "_api_", new Mask()); + builder.setLoadingOrder("_customPlugin", ClassloaderBuilder.LoadingOrder.SELF_FIRST); + + File[] sonarQubeDistributions = new File("sonarqube-lib/").listFiles(); + + for (File pluginJar : new File(sonarQubeDistributions[0], "extensions/plugins/").listFiles()) { + builder.addURL("_customPlugin", pluginJar.toURI().toURL()); + } + + Map loaders = builder.build(); + ClassLoader classLoader = loaders.get("_customPlugin"); + + Class loadedClass = + (Class) classLoader.loadClass("org.sonar.plugins.scm.svn.SvnPlugin"); + + ClassReferenceElevatedClassLoaderFactory testCase = + new ClassReferenceElevatedClassLoaderFactory(ActiveRule.class.getName()); + ClassLoader elevatedLoader = testCase.createClassLoader(loadedClass); + Class elevatedClass = elevatedLoader.loadClass(loadedClass.getName()); + // Getting closer than this is going to be difficult since the URLClassLoader that actually loads is an inner class of evelvatedClassLoader + assertNotSame(elevatedLoader, elevatedClass.getClassLoader()); + } + +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/DefaultElevatedClassLoaderFactoryProviderTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/DefaultElevatedClassLoaderFactoryProviderTest.java new file mode 100644 index 000000000..40444ba2f --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/DefaultElevatedClassLoaderFactoryProviderTest.java @@ -0,0 +1,27 @@ +package com.github.mc1arke.sonarqube.plugin.classloader; + +import org.junit.Test; +import org.sonar.api.Plugin; +import org.sonar.api.config.Configuration; + +import java.util.Optional; + +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class DefaultElevatedClassLoaderFactoryProviderTest { + + @Test + public void validFactoryReturnedOnNoPropertiesSet() { + Plugin.Context context = mock(Plugin.Context.class); + Configuration configuration = mock(Configuration.class); + when(context.getBootConfiguration()).thenReturn(configuration); + when(configuration.get(any())).thenReturn(Optional.empty()); + + assertTrue(DefaultElevatedClassLoaderFactoryProvider.getInstance() + .createFactory(context) instanceof ClassReferenceElevatedClassLoaderFactory); + } + +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ElevatedClassLoaderFactoryTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ElevatedClassLoaderFactoryTest.java new file mode 100644 index 000000000..7096a38b5 --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ElevatedClassLoaderFactoryTest.java @@ -0,0 +1,76 @@ +package com.github.mc1arke.sonarqube.plugin.classloader; + +import org.hamcrest.core.IsEqual; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.Plugin; + +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; + +import static org.junit.Assert.assertEquals; + +public class ElevatedClassLoaderFactoryTest { + + private final ExpectedException expectedException = ExpectedException.none(); + + @Rule + public ExpectedException expectedException() { + return expectedException; + } + + @Test + public void testExceptionOnInvalidLoader() { + ElevatedClassLoaderFactory testCase = new ElevatedClassLoaderFactoryImpl(); + + ClassLoader classLoaderImpl = new ClassLoader() { + }; + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo( + "Incorrect ClassLoader type. Expected 'java.net.URLClassLoader' but got '" + + classLoaderImpl.getClass().getName() + "'")); + + testCase.createClassLoader(classLoaderImpl, classLoaderImpl); + } + + @Test + public void testFallthroughClassLoading() throws IOException, ClassNotFoundException { + ElevatedClassLoaderFactory testCase = new ElevatedClassLoaderFactoryImpl(); + + try (URLClassLoader classLoader1 = new URLClassLoader(new URL[]{}) { + public Class loadClass(String name) throws ClassNotFoundException { + if ("1".equals(name)) { + throw new ClassNotFoundException("Not here"); + } + return this.getClass(); + } + }; URLClassLoader classLoader2 = new URLClassLoader(new URL[]{}) { + public Class loadClass(String name) throws ClassNotFoundException { + if ("2".equals(name)) { + throw new ClassNotFoundException("Whoops"); + } + return this.getClass(); + } + }) { + ClassLoader createdClassLoader = testCase.createClassLoader(classLoader2, classLoader1); + assertEquals(classLoader2.getClass(), createdClassLoader.loadClass("1")); + + expectedException.expect(ClassNotFoundException.class); + expectedException.expectMessage(IsEqual.equalTo("Whoops")); + + createdClassLoader.loadClass("2"); + } + } + + + private static class ElevatedClassLoaderFactoryImpl implements ElevatedClassLoaderFactory { + + @Override + public ClassLoader createClassLoader(Class pluginClass) { + return null; + } + } +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ProviderTypeTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ProviderTypeTest.java new file mode 100644 index 000000000..e49245994 --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ProviderTypeTest.java @@ -0,0 +1,50 @@ +package com.github.mc1arke.sonarqube.plugin.classloader; + +import org.hamcrest.core.IsEqual; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.Plugin; +import org.sonar.api.config.Configuration; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ProviderTypeTest { + + private final ExpectedException expectedException = ExpectedException.none(); + + @Rule + public ExpectedException expectedException() { + return expectedException; + } + + @Test + public void testReflectiveTypeMatched() { + Plugin.Context context = mock(Plugin.Context.class); + Configuration configuration = mock(Configuration.class); + when(context.getBootConfiguration()).thenReturn(configuration); + + assertTrue(ProviderType.fromName("REFLECTIVE") + .createFactory(context) instanceof ReflectiveElevatedClassLoaderFactory); + } + + @Test + public void testClassReferenceTypeMatched() { + Plugin.Context context = mock(Plugin.Context.class); + Configuration configuration = mock(Configuration.class); + when(context.getBootConfiguration()).thenReturn(configuration); + + assertTrue(ProviderType.fromName("CLASS_REFERENCE") + .createFactory(context) instanceof ClassReferenceElevatedClassLoaderFactory); + } + + @Test + public void errorOnInvalidConfig() { + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo("No provider with type 'xxx' could be found")); + + ProviderType.fromName("xxx"); + } +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ReflectiveElevatedClassLoaderFactoryTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ReflectiveElevatedClassLoaderFactoryTest.java new file mode 100644 index 000000000..b548ac833 --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/classloader/ReflectiveElevatedClassLoaderFactoryTest.java @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.classloader; + +import org.hamcrest.core.IsEqual; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.internal.configuration.plugins.Plugins; +import org.sonar.api.Plugin; +import org.sonar.classloader.ClassloaderBuilder; +import org.sonar.classloader.Mask; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Map; + +import static org.junit.Assert.assertNotSame; + +/** + * @author Michael Clarke + */ +public class ReflectiveElevatedClassLoaderFactoryTest { + + private final ExpectedException expectedException = ExpectedException.none(); + + @Rule + public ExpectedException expectedException() { + return expectedException; + } + + @Test + public void testLoadClass() throws ClassNotFoundException, MalformedURLException { + ClassloaderBuilder builder = new ClassloaderBuilder(); + builder.newClassloader("_api_", getClass().getClassLoader()); + builder.setMask("_api_", new Mask().addInclusion("java/").addInclusion("org/sonar/api/")); + + builder.newClassloader("_customPlugin"); + builder.setParent("_customPlugin", "_api_", new Mask()); + builder.setLoadingOrder("_customPlugin", ClassloaderBuilder.LoadingOrder.SELF_FIRST); + + File[] sonarQubeDistributions = new File("sonarqube-lib/").listFiles(); + + for (File pluginJar : new File(sonarQubeDistributions[0], "extensions/plugins/").listFiles()) { + builder.addURL("_customPlugin", pluginJar.toURI().toURL()); + } + + Map loaders = builder.build(); + ClassLoader classLoader = loaders.get("_customPlugin"); + + Class loadedClass = + (Class) classLoader.loadClass("org.sonar.plugins.scm.svn.SvnPlugin"); + + ReflectiveElevatedClassLoaderFactory testCase = new ReflectiveElevatedClassLoaderFactory(); + ClassLoader elevatedLoader = testCase.createClassLoader(loadedClass); + Class elevatedClass = elevatedLoader.loadClass(loadedClass.getName()); + // Getting closer than this is going to be difficult since the URLClassLoader that actually loads is an inner class of evelvatedClassLoader + assertNotSame(elevatedLoader, elevatedClass.getClassLoader()); + } + + + @Test + public void testLoadClassInvalidClassRealmKey() + throws ClassNotFoundException, IllegalAccessException, InstantiationException, MalformedURLException { + ClassloaderBuilder builder = new ClassloaderBuilder(); + builder.newClassloader("_xxx_", getClass().getClassLoader()); + builder.setMask("_xxx_", new Mask().addInclusion("java/").addInclusion("org/sonar/api/")); + + builder.newClassloader("_customPlugin"); + builder.setParent("_customPlugin", "_xxx_", new Mask()); + builder.setLoadingOrder("_customPlugin", ClassloaderBuilder.LoadingOrder.SELF_FIRST); + + File[] sonarQubeDistributions = new File("sonarqube-lib/").listFiles(); + + for (File pluginJar : new File(sonarQubeDistributions[0], "extensions/plugins/").listFiles()) { + builder.addURL("_customPlugin", pluginJar.toURI().toURL()); + } + + Map loaders = builder.build(); + ClassLoader classLoader = loaders.get("_customPlugin"); + + Class loadedClass = + (Class) classLoader.loadClass("org.sonar.plugins.scm.svn.SvnPlugin"); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo("Expected classloader with key '_api_' but found key '_xxx_'")); + + ReflectiveElevatedClassLoaderFactory testCase = new ReflectiveElevatedClassLoaderFactory(); + testCase.createClassLoader(loadedClass); + + } + + + @Test + public void testLoadClassNoParentRef() + throws ClassNotFoundException, IllegalAccessException, InstantiationException, MalformedURLException { + ClassloaderBuilder builder = new ClassloaderBuilder(); + builder.newClassloader("_xxx_", getClass().getClassLoader()); + builder.setMask("_xxx_", new Mask()); + + File[] sonarQubeDistributions = new File("sonarqube-lib/").listFiles(); + + for (File pluginJar : new File(sonarQubeDistributions[0], "extensions/plugins/").listFiles()) { + builder.addURL("_xxx_", pluginJar.toURI().toURL()); + } + + Map loaders = builder.build(); + ClassLoader classLoader = loaders.get("_xxx_"); + + Class loadedClass = + (Class) classLoader.loadClass("org.sonar.plugins.scm.svn.SvnPlugin"); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo("Could not access ClassLoader chain using reflection")); + + ReflectiveElevatedClassLoaderFactory testCase = new ReflectiveElevatedClassLoaderFactory(); + testCase.createClassLoader(loadedClass); + + } + + @Test + public void testLoadClassInvalidApiClassloader() + throws ClassNotFoundException, IllegalAccessException, InstantiationException, MalformedURLException { + ClassloaderBuilder builder = new ClassloaderBuilder(); + builder.newClassloader("_customPlugin"); + builder.setParent("_customPlugin", new URLClassLoader(new URL[0]), new Mask()); + builder.setLoadingOrder("_customPlugin", ClassloaderBuilder.LoadingOrder.SELF_FIRST); + + File[] sonarQubeDistributions = new File("sonarqube-lib/").listFiles(); + + for (File pluginJar : new File(sonarQubeDistributions[0], "extensions/plugins/").listFiles()) { + builder.addURL("_customPlugin", pluginJar.toURI().toURL()); + } + + Map loaders = builder.build(); + ClassLoader classLoader = loaders.get("_customPlugin"); + + Class loadedClass = + (Class) classLoader.loadClass("org.sonar.plugins.scm.svn.SvnPlugin"); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo( + "Expected classloader of type 'org.sonar.classloader.ClassRealm' but got 'java.net.URLClassLoader'")); + + ReflectiveElevatedClassLoaderFactory testCase = new ReflectiveElevatedClassLoaderFactory(); + testCase.createClassLoader((Class) loadedClass); + + } + + @Test + public void testLoadClassInvalidClassloader() throws ClassNotFoundException, MalformedURLException { + + File[] sonarQubeDistributions = new File("sonarqube-lib/").listFiles(); + File[] plugins = new File(sonarQubeDistributions[0], "extensions/plugins/").listFiles(); + + URL[] urls = new URL[plugins.length]; + int i = 0; + for (File pluginJar : plugins) { + urls[i++] = pluginJar.toURI().toURL(); + } + + ClassLoader classLoader = new URLClassLoader(urls); + + Class loadedClass = + (Class) classLoader.loadClass("org.sonar.plugins.scm.svn.SvnPlugin"); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo( + "Expected classloader of type 'org.sonar.classloader.ClassRealm' but got 'java.net.URLClassLoader'")); + + ReflectiveElevatedClassLoaderFactory testCase = new ReflectiveElevatedClassLoaderFactory(); + testCase.createClassLoader((Class) loadedClass); + + } + +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchConfigurationLoaderTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchConfigurationLoaderTest.java new file mode 100644 index 000000000..28129de56 --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchConfigurationLoaderTest.java @@ -0,0 +1,466 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.scanner; + +import org.hamcrest.CustomMatcher; +import org.hamcrest.core.IsEqual; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.CoreProperties; +import org.sonar.api.utils.MessageException; +import org.sonar.scanner.scan.branch.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchInfo; +import org.sonar.scanner.scan.branch.BranchType; +import org.sonar.scanner.scan.branch.DefaultBranchConfiguration; +import org.sonar.scanner.scan.branch.ProjectBranches; +import org.sonar.scanner.scan.branch.ProjectPullRequests; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author Michael Clarke + */ +public class CommunityBranchConfigurationLoaderTest { + + private final Supplier> supplier = mock(Supplier.class); + private final ExpectedException expectedException = ExpectedException.none(); + + @Rule + public ExpectedException expectedException() { + return expectedException; + } + + @Test + public void testExceptionWhenNoExistingBranch() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + ProjectBranches branchInfo = mock(ProjectBranches.class); + when(branchInfo.isEmpty()).thenReturn(true); + + expectedException.expect(MessageException.class); + expectedException.expectMessage(IsEqual.equalTo( + "No branches currently exist in this project. Please scan the main branch without passing any branch parameters.")); + + testCase.load(new HashMap<>(), supplier, branchInfo, mock(ProjectPullRequests.class)); + } + + @Test + public void testDefaultBranchInfoWhenNoParametersSpecified() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + assertEquals(DefaultBranchConfiguration.class, + testCase.load(new HashMap<>(), supplier, mock(ProjectBranches.class), + mock(ProjectPullRequests.class)).getClass()); + } + + @Test + public void testValidBranchInfoWhenAllBranchParametersSpecified() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.branch.name", "feature/shortLivedFeatureBranch"); + parameters.put("sonar.branch.target", "master"); + + BranchInfo mockTargetBranchInfo = mock(BranchInfo.class); + when(mockTargetBranchInfo.name()).thenReturn("masterBranchInfo"); + when(mockTargetBranchInfo.type()).thenReturn(BranchType.LONG); + + ProjectBranches projectBranches = mock(ProjectBranches.class); + when(projectBranches.get("master")).thenReturn(mockTargetBranchInfo); + + when(supplier.get()).thenReturn(new HashMap<>()); + + BranchConfiguration result = + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + + assertEquals("master", result.targetScmBranch()); + assertEquals("feature/shortLivedFeatureBranch", result.branchName()); + assertEquals("masterBranchInfo", result.longLivingSonarReferenceBranch()); + assertTrue(result.isShortOrPullRequest()); + + expectedException + .expectMessage(IsEqual.equalTo("Only a branch of type PULL_REQUEST can have a Pull Request key")); + expectedException.expect(IllegalStateException.class); + + result.pullRequestKey(); + } + + @Test + public void testValidBranchInfoWhenOnlySourceBranchSpecifiedAndMasterExists() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.branch.name", "feature/shortLivedBranch"); + + BranchInfo mockTargetBranchInfo = mock(BranchInfo.class); + when(mockTargetBranchInfo.name()).thenReturn("defaultBranchInfo"); + when(mockTargetBranchInfo.type()).thenReturn(BranchType.LONG); + + ProjectBranches projectBranches = mock(ProjectBranches.class); + when(projectBranches.get("masterxxx")).thenReturn(mockTargetBranchInfo); + when(projectBranches.defaultBranchName()).thenReturn("masterxxx"); + + when(supplier.get()).thenReturn(new HashMap<>()); + + BranchConfiguration result = + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + + assertEquals("masterxxx", result.targetScmBranch()); + assertEquals("feature/shortLivedBranch", result.branchName()); + assertEquals("defaultBranchInfo", result.longLivingSonarReferenceBranch()); + assertTrue(result.isShortOrPullRequest()); + } + + @Test + public void testValidBranchInfoWhenOnlySourceBranchSpecifiedAndMasterExists2() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.branch.name", "feature/shortLivedBranch"); + parameters.put("sonar.branch.target", ""); + + BranchInfo mockTargetBranchInfo = mock(BranchInfo.class); + when(mockTargetBranchInfo.name()).thenReturn("defaultBranchInfo"); + when(mockTargetBranchInfo.type()).thenReturn(BranchType.LONG); + + ProjectBranches projectBranches = mock(ProjectBranches.class); + when(projectBranches.get("masterxxx")).thenReturn(mockTargetBranchInfo); + when(projectBranches.defaultBranchName()).thenReturn("masterxxx"); + + when(supplier.get()).thenReturn(new HashMap<>()); + + BranchConfiguration result = + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + + assertEquals("masterxxx", result.targetScmBranch()); + assertEquals("feature/shortLivedBranch", result.branchName()); + assertEquals("defaultBranchInfo", result.longLivingSonarReferenceBranch()); + assertTrue(result.isShortOrPullRequest()); + } + + @Test + public void testExceptionWhenOnlySourceBranchSpecifiedAndNoMasterExists() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.branch.name", "feature/shortLivedBranch"); + + BranchInfo mockTargetBranchInfo = mock(BranchInfo.class); + when(mockTargetBranchInfo.name()).thenReturn("defaultBranchInfo"); + when(mockTargetBranchInfo.type()).thenReturn(BranchType.LONG); + + ProjectBranches projectBranches = mock(ProjectBranches.class); + + when(supplier.get()).thenReturn(new HashMap<>()); + + expectedException.expect(MessageException.class); + expectedException.expectMessage(IsEqual.equalTo("Could not target requested branch")); + + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + + } + + + @Test + public void testShortLivedBranchInvalidTarget() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.branch.name", "feature/shortLivedBranch"); + parameters.put("sonar.branch.target", "feature/otherShortLivedBranch"); + + BranchInfo mockTargetBranchInfo = mock(BranchInfo.class); + when(mockTargetBranchInfo.name()).thenReturn("feature/otherShortLivedBranch"); + when(mockTargetBranchInfo.type()).thenReturn(BranchType.SHORT); + + ProjectBranches projectBranches = mock(ProjectBranches.class); + when(projectBranches.get("feature/otherShortLivedBranch")).thenReturn(mockTargetBranchInfo); + + when(supplier.get()).thenReturn(new HashMap<>()); + + expectedException.expect(MessageException.class); + expectedException.expectMessage(IsEqual.equalTo("Could not target requested branch")); + expectedException.expectCause(new CustomMatcher("Cause checker") { + @Override + public boolean matches(Object item) { + return item instanceof IllegalStateException && + ((IllegalStateException) item).getMessage().equals("Expected branch type of LONG but got SHORT"); + } + }); + + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + } + + @Test + public void testUnknownTargetBranch() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.branch.name", "feature/shortLivedBranch"); + parameters.put("sonar.branch.target", "feature/otherShortLivedBranch"); + + ProjectBranches projectBranches = mock(ProjectBranches.class); + + when(supplier.get()).thenReturn(new HashMap<>()); + + expectedException.expect(MessageException.class); + expectedException.expectMessage(IsEqual.equalTo("Could not target requested branch")); + expectedException.expectCause(new CustomMatcher("Cause checker") { + @Override + public boolean matches(Object item) { + return item instanceof IllegalStateException && ((IllegalStateException) item).getMessage() + .equals("Target branch 'feature/otherShortLivedBranch' does not exist"); + } + }); + + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + } + + + @Test + public void testShortLivedBranchExistingSourceAllParametersCorrect() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.branch.name", "feature/shortLivedBranch"); + parameters.put("sonar.branch.target", "longLivedBranch"); + + BranchInfo mockTargetBranchInfo = mock(BranchInfo.class); + when(mockTargetBranchInfo.name()).thenReturn("longLivedBranch"); + when(mockTargetBranchInfo.type()).thenReturn(BranchType.LONG); + + BranchInfo mockSourceBranchInfo = mock(BranchInfo.class); + when(mockSourceBranchInfo.name()).thenReturn("shortLivedBranch"); + when(mockSourceBranchInfo.type()).thenReturn(BranchType.SHORT); + + + ProjectBranches projectBranches = mock(ProjectBranches.class); + when(projectBranches.get("longLivedBranch")).thenReturn(mockTargetBranchInfo); + when(projectBranches.get("feature/shortLivedBranch")).thenReturn(mockSourceBranchInfo); + + when(supplier.get()).thenReturn(new HashMap<>()); + + BranchConfiguration result = + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + + assertEquals("longLivedBranch", result.targetScmBranch()); + assertEquals("feature/shortLivedBranch", result.branchName()); + assertEquals("longLivedBranch", result.longLivingSonarReferenceBranch()); + assertTrue(result.isShortOrPullRequest()); + } + + @Test + public void testExistingShortLivedBranchOnlySourceParametersRetargetMaster() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.branch.name", "feature/shortLivedBranch"); + + BranchInfo mockTargetBranchInfo = mock(BranchInfo.class); + when(mockTargetBranchInfo.name()).thenReturn("longLivedBranch"); + when(mockTargetBranchInfo.type()).thenReturn(BranchType.LONG); + + BranchInfo mockSourceBranchInfo = mock(BranchInfo.class); + when(mockSourceBranchInfo.name()).thenReturn("shortLivedBranch"); + when(mockSourceBranchInfo.branchTargetName()).thenReturn("otherLongLivedBranch"); + when(mockSourceBranchInfo.type()).thenReturn(BranchType.SHORT); + + + ProjectBranches projectBranches = mock(ProjectBranches.class); + when(projectBranches.get("master")).thenReturn(mockTargetBranchInfo); + when(projectBranches.get("feature/shortLivedBranch")).thenReturn(mockSourceBranchInfo); + when(projectBranches.defaultBranchName()).thenReturn("master"); + + when(supplier.get()).thenReturn(new HashMap<>()); + + BranchConfiguration result = + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + + assertEquals("master", result.targetScmBranch()); + assertEquals("feature/shortLivedBranch", result.branchName()); + assertEquals("master", result.longLivingSonarReferenceBranch()); + assertTrue(result.isShortOrPullRequest()); + } + + @Test + public void testExistingLongLivedBranchOnlySourceParameters() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.branch.name", "longLivedBranch"); + + BranchInfo mockTargetBranchInfo = mock(BranchInfo.class); + when(mockTargetBranchInfo.name()).thenReturn("longLivedBranch"); + when(mockTargetBranchInfo.type()).thenReturn(BranchType.LONG); + + + ProjectBranches projectBranches = mock(ProjectBranches.class); + when(projectBranches.get("longLivedBranch")).thenReturn(mockTargetBranchInfo); + + when(supplier.get()).thenReturn(new HashMap<>()); + + BranchConfiguration result = + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + + assertNull(result.targetScmBranch()); + assertEquals("longLivedBranch", result.branchName()); + assertEquals("longLivedBranch", result.longLivingSonarReferenceBranch()); + assertFalse(result.isShortOrPullRequest()); + } + + @Test + public void testPullRequestAllParameters() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.pullrequest.branch", "feature/sourceBranch"); + parameters.put("sonar.pullrequest.base", "target"); + parameters.put("sonar.pullrequest.key", "pr-key"); + + BranchInfo mockTargetBranchInfo = mock(BranchInfo.class); + when(mockTargetBranchInfo.name()).thenReturn("targetInfo"); + when(mockTargetBranchInfo.type()).thenReturn(BranchType.LONG); + + + ProjectBranches projectBranches = mock(ProjectBranches.class); + when(projectBranches.get("target")).thenReturn(mockTargetBranchInfo); + + when(supplier.get()).thenReturn(new HashMap<>()); + + BranchConfiguration result = + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + + assertEquals("target", result.targetScmBranch()); + assertEquals("feature/sourceBranch", result.branchName()); + assertEquals("target", result.longLivingSonarReferenceBranch()); + assertTrue(result.isShortOrPullRequest()); + assertEquals("pr-key", result.pullRequestKey()); + } + + + @Test + public void testPullRequestMandatoryParameters() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.pullrequest.branch", "feature/sourceBranch"); + parameters.put("sonar.pullrequest.key", "pr-key"); + + BranchInfo mockTargetBranchInfo = mock(BranchInfo.class); + when(mockTargetBranchInfo.name()).thenReturn("masterInfo"); + when(mockTargetBranchInfo.type()).thenReturn(BranchType.LONG); + + + ProjectBranches projectBranches = mock(ProjectBranches.class); + when(projectBranches.get("master")).thenReturn(mockTargetBranchInfo); + when(projectBranches.defaultBranchName()).thenReturn("master"); + + when(supplier.get()).thenReturn(new HashMap<>()); + + BranchConfiguration result = + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + + assertEquals("master", result.targetScmBranch()); + assertEquals("feature/sourceBranch", result.branchName()); + assertEquals("master", result.longLivingSonarReferenceBranch()); + assertTrue(result.isShortOrPullRequest()); + } + + @Test + public void testPullRequestMandatoryParameters2() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.pullrequest.branch", "feature/sourceBranch"); + parameters.put("sonar.pullrequest.key", "pr-key"); + parameters.put("sonar.pullrequest.base", ""); + + BranchInfo mockTargetBranchInfo = mock(BranchInfo.class); + when(mockTargetBranchInfo.name()).thenReturn("masterInfo"); + when(mockTargetBranchInfo.type()).thenReturn(BranchType.LONG); + + + ProjectBranches projectBranches = mock(ProjectBranches.class); + when(projectBranches.get("master")).thenReturn(mockTargetBranchInfo); + when(projectBranches.defaultBranchName()).thenReturn("master"); + + when(supplier.get()).thenReturn(new HashMap<>()); + + BranchConfiguration result = + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + + assertEquals("master", result.targetScmBranch()); + assertEquals("feature/sourceBranch", result.branchName()); + assertEquals("master", result.longLivingSonarReferenceBranch()); + assertTrue(result.isShortOrPullRequest()); + } + + + @Test + public void testPullRequestNoSuchTarget() { + CommunityBranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(); + Map parameters = new HashMap<>(); + parameters.put("sonar.pullrequest.branch", "feature/sourceBranch"); + parameters.put("sonar.pullrequest.base", "missingTarget"); + parameters.put("sonar.pullrequest.key", "pr-key"); + + + ProjectBranches projectBranches = mock(ProjectBranches.class); + + when(supplier.get()).thenReturn(new HashMap<>()); + + expectedException.expect(MessageException.class); + expectedException.expectMessage(IsEqual.equalTo("Could not target requested branch")); + expectedException.expectCause(new CustomMatcher("Cause checker") { + @Override + public boolean matches(Object item) { + return item instanceof IllegalStateException && ((IllegalStateException) item).getMessage() + .equals("Target branch 'missingTarget' does not exist"); + } + }); + + testCase.load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)); + } + + @Test + public void testComputeBranchType() { + Map settings = new HashMap<>(); + settings.put(CoreProperties.LONG_LIVED_BRANCHES_REGEX, "(master|release/.+)"); + when(supplier.get()).thenReturn(settings); + + BranchInfo branchInfo = mock(BranchInfo.class); + when(branchInfo.type()).thenReturn(BranchType.LONG); + + ProjectBranches projectBranches = mock(ProjectBranches.class); + when(projectBranches.defaultBranchName()).thenReturn("master"); + when(projectBranches.get(eq("master"))).thenReturn(branchInfo); + + Map parameters = new HashMap<>(); + parameters.put("sonar.branch.name", "release/1.2"); + + assertEquals(BranchType.LONG, new CommunityBranchConfigurationLoader() + .load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)).branchType()); + + parameters = new HashMap<>(); + parameters.put("sonar.branch.name", "master-dummy"); + + assertEquals(BranchType.SHORT, new CommunityBranchConfigurationLoader() + .load(parameters, supplier, projectBranches, mock(ProjectPullRequests.class)).branchType()); + + } + + +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchParamsValidatorTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchParamsValidatorTest.java new file mode 100644 index 000000000..15a89e5fc --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityBranchParamsValidatorTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.scanner; + +import org.junit.Test; +import org.sonar.scanner.bootstrap.GlobalConfiguration; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author Michael Clarke + */ +public class CommunityBranchParamsValidatorTest { + + @Test + public void testNoMessagesOnNoParams() { + List messages = new ArrayList<>(); + + GlobalConfiguration globalConfiguration = mock(GlobalConfiguration.class); + new CommunityBranchParamsValidator(globalConfiguration).validate(messages, null); + assertTrue(messages.isEmpty()); + } + + @Test + public void testNoMessagesOnlyLegacyBranch() { + List messages = new ArrayList<>(); + + GlobalConfiguration globalConfiguration = mock(GlobalConfiguration.class); + new CommunityBranchParamsValidator(globalConfiguration).validate(messages, "legacy"); + assertTrue(messages.isEmpty()); + } + + @Test + public void testMessagesBranchParamsAndLegacyBranch() { + List messages = new ArrayList<>(); + + GlobalConfiguration globalConfiguration = mock(GlobalConfiguration.class); + when(globalConfiguration.hasKey(any())).thenReturn(true); + new CommunityBranchParamsValidator(globalConfiguration).validate(messages, "legacy"); + assertEquals(1, messages.size()); + assertEquals( + "The legacy 'sonar.branch' parameter cannot be used at the same time as 'sonar.branch.name' or 'sonar.branch.target'", + messages.get(0)); + } + + @Test + public void testMessagesBranchParamsAndLegacyBranch2() { + List messages = new ArrayList<>(); + + GlobalConfiguration globalConfiguration = mock(GlobalConfiguration.class); + when(globalConfiguration.hasKey(eq("sonar.branch.target"))).thenReturn(true); + when(globalConfiguration.hasKey(eq("sonar.branch"))).thenReturn(true); + new CommunityBranchParamsValidator(globalConfiguration).validate(messages, "legacy"); + assertEquals(1, messages.size()); + assertEquals( + "The legacy 'sonar.branch' parameter cannot be used at the same time as 'sonar.branch.name' or 'sonar.branch.target'", + messages.get(0)); + } +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectBranchesLoaderTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectBranchesLoaderTest.java new file mode 100644 index 000000000..b52083e3e --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectBranchesLoaderTest.java @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.scanner; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.MessageException; +import org.sonar.scanner.bootstrap.ScannerWsClient; +import org.sonar.scanner.protocol.GsonHelper; +import org.sonar.scanner.scan.branch.BranchInfo; +import org.sonar.scanner.scan.branch.BranchType; +import org.sonar.scanner.scan.branch.ProjectBranches; +import org.sonarqube.ws.client.HttpException; +import org.sonarqube.ws.client.WsResponse; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author Michael Clarke + */ +public class CommunityProjectBranchesLoaderTest { + + private final ScannerWsClient scannerWsClient = mock(ScannerWsClient.class); + private final ExpectedException expectedException = ExpectedException.none(); + + @Rule + public ExpectedException expectedException() { + return expectedException; + } + + @Test + public void testEmptyBranchesOnEmptyServerResponse() { + WsResponse mockResponse = mock(WsResponse.class); + when(scannerWsClient.call(any())).thenReturn(mockResponse); + + StringReader stringReader = new StringReader( + GsonHelper.create().toJson(new CommunityProjectBranchesLoader.BranchesResponse(new ArrayList<>()))); + when(mockResponse.contentReader()).thenReturn(stringReader); + + CommunityProjectBranchesLoader testCase = new CommunityProjectBranchesLoader(scannerWsClient); + ProjectBranches response = testCase.load("projectKey"); + assertTrue(response.isEmpty()); + } + + @Test + public void testAllBranchesFromNonEmptyServerResponse() { + WsResponse mockResponse = mock(WsResponse.class); + when(scannerWsClient.call(any())).thenReturn(mockResponse); + + List infos = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + infos.add(new BranchInfo("key" + i, BranchType.LONG, i == 1, "target" + i)); + } + + StringReader stringReader = new StringReader( + GsonHelper.create().toJson(new CommunityProjectBranchesLoader.BranchesResponse(infos))); + when(mockResponse.contentReader()).thenReturn(stringReader); + + CommunityProjectBranchesLoader testCase = new CommunityProjectBranchesLoader(scannerWsClient); + ProjectBranches response = testCase.load("key"); + assertFalse(response.isEmpty()); + for (BranchInfo info : infos) { + BranchInfo responseInfo = response.get(info.name()); + assertNotNull(responseInfo); + assertEquals(info.branchTargetName(), responseInfo.branchTargetName()); + assertEquals(info.isMain(), responseInfo.isMain()); + assertEquals(info.name(), responseInfo.name()); + assertEquals(info.type(), responseInfo.type()); + } + } + + @Test + public void testMessageExceptionOnIOException() { + WsResponse mockResponse = mock(WsResponse.class); + when(scannerWsClient.call(any())).thenReturn(mockResponse); + + Reader mockReader = new BufferedReader(new StringReader( + GsonHelper.create().toJson(new CommunityProjectBranchesLoader.BranchesResponse(new ArrayList<>())))) { + public void close() throws IOException { + throw new IOException("Dummy IO Exception"); + } + }; + when(mockResponse.contentReader()).thenReturn(mockReader); + + expectedException.expectMessage("Could not load branches from server"); + expectedException.expect(MessageException.class); + + CommunityProjectBranchesLoader testCase = new CommunityProjectBranchesLoader(scannerWsClient); + testCase.load("project"); + + + } + + + @Test + public void testErrorOnNon404HttpResponse() { + WsResponse mockResponse = mock(WsResponse.class); + when(scannerWsClient.call(any())).thenReturn(mockResponse); + + Reader mockReader = new BufferedReader(new StringReader( + GsonHelper.create().toJson(new CommunityProjectBranchesLoader.BranchesResponse(new ArrayList<>())))) { + public void close() { + throw new HttpException("url", 12, "content"); + } + }; + when(mockResponse.contentReader()).thenReturn(mockReader); + + expectedException.expectMessage("Could not load branches from server"); + expectedException.expect(MessageException.class); + + CommunityProjectBranchesLoader testCase = new CommunityProjectBranchesLoader(scannerWsClient); + testCase.load("project"); + } + + + @Test + public void testEmptyListOn404HttpResponse() { + WsResponse mockResponse = mock(WsResponse.class); + when(scannerWsClient.call(any())).thenReturn(mockResponse); + + Reader mockReader = new BufferedReader(new StringReader( + GsonHelper.create().toJson(new CommunityProjectBranchesLoader.BranchesResponse(new ArrayList<>())))) { + public void close() { + throw new HttpException("url", 404, "content"); + } + }; + when(mockResponse.contentReader()).thenReturn(mockReader); + + CommunityProjectBranchesLoader testCase = new CommunityProjectBranchesLoader(scannerWsClient); + assertTrue(testCase.load("project").isEmpty()); + } +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectPullRequestsLoaderTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectPullRequestsLoaderTest.java new file mode 100644 index 000000000..b8deed8df --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/scanner/CommunityProjectPullRequestsLoaderTest.java @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.scanner; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.MessageException; +import org.sonar.scanner.bootstrap.ScannerWsClient; +import org.sonar.scanner.protocol.GsonHelper; +import org.sonar.scanner.scan.branch.ProjectPullRequests; +import org.sonar.scanner.scan.branch.PullRequestInfo; +import org.sonarqube.ws.client.HttpException; +import org.sonarqube.ws.client.WsResponse; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author Michael Clarke + */ +public class CommunityProjectPullRequestsLoaderTest { + + private final ScannerWsClient scannerWsClient = mock(ScannerWsClient.class); + private final ExpectedException expectedException = ExpectedException.none(); + + @Rule + public ExpectedException expectedException() { + return expectedException; + } + + @Test + public void testEmptyBranchesOnEmptyServerResponse() { + WsResponse mockResponse = mock(WsResponse.class); + when(scannerWsClient.call(any())).thenReturn(mockResponse); + + StringReader stringReader = new StringReader(GsonHelper.create() + .toJson(new CommunityProjectPullRequestsLoader.PullRequestsResponse( + new ArrayList<>()))); + when(mockResponse.contentReader()).thenReturn(stringReader); + + CommunityProjectPullRequestsLoader testCase = new CommunityProjectPullRequestsLoader(scannerWsClient); + ProjectPullRequests response = testCase.load("projectKey"); + assertTrue(response.isEmpty()); + } + + @Test + public void testAllBranchesFromNonEmptyServerResponse() { + WsResponse mockResponse = mock(WsResponse.class); + when(scannerWsClient.call(any())).thenReturn(mockResponse); + + List infos = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + infos.add(new PullRequestInfo("key" + i, "branch" + i, "base" + i, i)); + } + + StringReader stringReader = new StringReader( + GsonHelper.create().toJson(new CommunityProjectPullRequestsLoader.PullRequestsResponse(infos))); + when(mockResponse.contentReader()).thenReturn(stringReader); + + CommunityProjectPullRequestsLoader testCase = new CommunityProjectPullRequestsLoader(scannerWsClient); + ProjectPullRequests response = testCase.load("key"); + assertFalse(response.isEmpty()); + for (PullRequestInfo info : infos) { + PullRequestInfo responseInfo = response.get(info.getBranch()); + assertNotNull(responseInfo); + assertEquals(info.getAnalysisDate(), responseInfo.getAnalysisDate()); + assertEquals(info.getBase(), responseInfo.getBase()); + assertEquals(info.getBranch(), responseInfo.getBranch()); + assertEquals(info.getKey(), responseInfo.getKey()); + } + } + + @Test + public void testMessageExceptionOnIOException() { + WsResponse mockResponse = mock(WsResponse.class); + when(scannerWsClient.call(any())).thenReturn(mockResponse); + + Reader mockReader = new BufferedReader(new StringReader(GsonHelper.create() + .toJson(new CommunityProjectPullRequestsLoader.PullRequestsResponse( + new ArrayList<>())))) { + public void close() throws IOException { + throw new IOException("Dummy IO Exception"); + } + }; + when(mockResponse.contentReader()).thenReturn(mockReader); + + expectedException.expectMessage("Could not load pull requests from server"); + expectedException.expect(MessageException.class); + + CommunityProjectPullRequestsLoader testCase = new CommunityProjectPullRequestsLoader(scannerWsClient); + testCase.load("project"); + + + } + + + @Test + public void testErrorOnNon404HttpResponse() { + WsResponse mockResponse = mock(WsResponse.class); + when(scannerWsClient.call(any())).thenReturn(mockResponse); + + Reader mockReader = new BufferedReader(new StringReader(GsonHelper.create() + .toJson(new CommunityProjectPullRequestsLoader.PullRequestsResponse( + new ArrayList<>())))) { + public void close() { + throw new HttpException("url", 12, "content"); + } + }; + when(mockResponse.contentReader()).thenReturn(mockReader); + + expectedException.expectMessage("Could not load pull requests from server"); + expectedException.expect(MessageException.class); + + CommunityProjectPullRequestsLoader testCase = new CommunityProjectPullRequestsLoader(scannerWsClient); + testCase.load("project"); + } + + + @Test + public void testEmptyListOn404HttpResponse() { + WsResponse mockResponse = mock(WsResponse.class); + when(scannerWsClient.call(any())).thenReturn(mockResponse); + + Reader mockReader = new BufferedReader(new StringReader(GsonHelper.create() + .toJson(new CommunityProjectPullRequestsLoader.PullRequestsResponse( + new ArrayList<>())))) { + public void close() { + throw new HttpException("url", 404, "content"); + } + }; + when(mockResponse.contentReader()).thenReturn(mockReader); + + CommunityProjectPullRequestsLoader testCase = new CommunityProjectPullRequestsLoader(scannerWsClient); + assertTrue(testCase.load("project").isEmpty()); + } +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchFeatureExtensionTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchFeatureExtensionTest.java new file mode 100644 index 000000000..5cf7dbb18 --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchFeatureExtensionTest.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.server; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * @author Michael Clarke + */ +public class CommunityBranchFeatureExtensionTest { + + @Test + public void testEnabled() { + assertTrue(new CommunityBranchFeatureExtension().isEnabled()); + } +} diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchSupportDelegateTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchSupportDelegateTest.java new file mode 100644 index 000000000..f31ea380a --- /dev/null +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/server/CommunityBranchSupportDelegateTest.java @@ -0,0 +1,350 @@ +/* + * Copyright (C) 2019 Michael Clarke + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +package com.github.mc1arke.sonarqube.plugin.server; + +import org.hamcrest.core.IsEqual; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.sonar.core.util.SequenceUuidFactory; +import org.sonar.core.util.UuidFactory; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; +import org.sonar.db.component.BranchDto; +import org.sonar.db.component.BranchType; +import org.sonar.db.component.ComponentDao; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.organization.OrganizationDto; +import org.sonar.server.ce.queue.BranchSupport; + +import java.time.Clock; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * @author Michael Clarke + */ +public class CommunityBranchSupportDelegateTest { + + private final ExpectedException expectedException = ExpectedException.none(); + + @Rule + public ExpectedException expectedException() { + return expectedException; + } + + @Test + public void testCreateComponentKeyShortBranch() { + Map params = new HashMap<>(); + params.put("branch", "feature/dummy"); + params.put("branchType", "SHORT"); + + BranchSupport.ComponentKey componentKey = + new CommunityBranchSupportDelegate(new SequenceUuidFactory(), mock(DbClient.class), mock(Clock.class)) + .createComponentKey("xxx", params); + assertEquals("xxx:BRANCH:feature/dummy", componentKey.getDbKey()); + assertEquals("xxx", componentKey.getKey()); + assertFalse(componentKey.getPullRequestKey().isPresent()); + assertFalse(componentKey.isMainBranch()); + assertTrue(componentKey.getBranch().isPresent()); + assertEquals("feature/dummy", componentKey.getBranch().get().getName()); + assertFalse(componentKey.isDeprecatedBranch()); + assertTrue(componentKey.getMainBranchComponentKey().isMainBranch()); + assertEquals(BranchType.SHORT, componentKey.getBranch().get().getType()); + } + + @Test + public void testCreateComponentKeyLongBranch() { + Map params = new HashMap<>(); + params.put("branch", "release-1.1"); + params.put("branchType", "LONG"); + + BranchSupport.ComponentKey componentKey = + new CommunityBranchSupportDelegate(new SequenceUuidFactory(), mock(DbClient.class), mock(Clock.class)) + .createComponentKey("yyy", params); + + assertEquals("yyy:BRANCH:release-1.1", componentKey.getDbKey()); + assertEquals("yyy", componentKey.getKey()); + assertFalse(componentKey.getPullRequestKey().isPresent()); + assertFalse(componentKey.isMainBranch()); + assertTrue(componentKey.getBranch().isPresent()); + assertEquals("release-1.1", componentKey.getBranch().get().getName()); + assertFalse(componentKey.isDeprecatedBranch()); + assertTrue(componentKey.getMainBranchComponentKey().isMainBranch()); + assertEquals(BranchType.LONG, componentKey.getBranch().get().getType()); + } + + @Test + public void testCreateComponentKeyPullRequest() { + Map params = new HashMap<>(); + params.put("pullRequest", "pullrequestkey"); + + CommunityComponentKey componentKey = + new CommunityBranchSupportDelegate(new SequenceUuidFactory(), mock(DbClient.class), mock(Clock.class)) + .createComponentKey("yyy", params); + assertEquals("yyy:PULL_REQUEST:pullrequestkey", componentKey.getDbKey()); + assertEquals("yyy", componentKey.getKey()); + assertTrue(componentKey.getPullRequestKey().isPresent()); + assertEquals("pullrequestkey", componentKey.getPullRequestKey().get()); + assertFalse(componentKey.isMainBranch()); + assertFalse(componentKey.getBranch().isPresent()); + assertFalse(componentKey.isDeprecatedBranch()); + assertTrue(componentKey.getMainBranchComponentKey().isMainBranch()); + CommunityComponentKey mainBranchComponentKey = componentKey.getMainBranchComponentKey(); + assertSame(mainBranchComponentKey, mainBranchComponentKey.getMainBranchComponentKey()); + } + + + @Test + public void testCreateComponentKeyMissingBranchTypeAndPullParameters() { + Map params = new HashMap<>(); + + expectedException.expect(IllegalArgumentException.class); + expectedException + .expectMessage(IsEqual.equalTo("One of 'branchType' or 'pullRequest' parameters must be specified")); + + new CommunityBranchSupportDelegate(new SequenceUuidFactory(), mock(DbClient.class), mock(Clock.class)) + .createComponentKey("xxx", params); + } + + @Test + public void testCreateComponentKeyInvalidBranchTypeParameter() { + Map params = new HashMap<>(); + params.put("branchType", "abc"); + + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage(IsEqual.equalTo("Unsupported branch type 'abc'")); + + new CommunityBranchSupportDelegate(new SequenceUuidFactory(), mock(DbClient.class), mock(Clock.class)) + .createComponentKey("xxx", params); + } + + @Test + public void testCreateComponentKeyInvalidBranchTypeParameter2() { + Map params = new HashMap<>(); + params.put("branchType", "PULL_REQUEST"); + + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage(IsEqual.equalTo("Unsupported branch type 'PULL_REQUEST'")); + + new CommunityBranchSupportDelegate(new SequenceUuidFactory(), mock(DbClient.class), mock(Clock.class)) + .createComponentKey("xxx", params); + } + + @Test + public void testCreateBranchComponentComponentKeyComponentFtoKeyMismatch() { + DbSession dbSession = mock(DbSession.class); + OrganizationDto organizationDto = mock(OrganizationDto.class); + + ComponentDto componentDto = mock(ComponentDto.class); + when(componentDto.getKey()).thenReturn("otherComponentKey"); + when(componentDto.uuid()).thenReturn("componentUuid"); + + ComponentDto copyComponentDto = spy(ComponentDto.class); + when(componentDto.copy()).thenReturn(copyComponentDto); + + BranchDto branchDto = mock(BranchDto.class); + when(branchDto.getUuid()).thenReturn("componentUuid"); + + Clock clock = mock(Clock.class); + when(clock.millis()).thenReturn(12345678901234L); + + BranchSupport.ComponentKey componentKey = mock(BranchSupport.ComponentKey.class); + when(componentKey.getKey()).thenReturn("componentKey"); + when(componentKey.getDbKey()).thenReturn("dbKey"); + when(componentKey.getBranch()).thenReturn(Optional.of(new BranchSupport.Branch("dummy", BranchType.LONG))); + when(componentKey.getPullRequestKey()).thenReturn(Optional.empty()); + + ComponentDao componentDao = spy(mock(ComponentDao.class)); + + DbClient dbClient = mock(DbClient.class); + when(dbClient.componentDao()).thenReturn(componentDao); + + UuidFactory uuidFactory = new SequenceUuidFactory(); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage(IsEqual.equalTo("Component Key and Main Component Key do not match")); + + new CommunityBranchSupportDelegate(uuidFactory, dbClient, clock) + .createBranchComponent(dbSession, componentKey, organizationDto, componentDto, branchDto); + + } + + @Test + public void testCreateBranchComponent() { + DbSession dbSession = mock(DbSession.class); + OrganizationDto organizationDto = mock(OrganizationDto.class); + + ComponentDto componentDto = mock(ComponentDto.class); + when(componentDto.getKey()).thenReturn("componentKey"); + when(componentDto.uuid()).thenReturn("componentUuid"); + + ComponentDto copyComponentDto = spy(ComponentDto.class); + when(componentDto.copy()).thenReturn(copyComponentDto); + + BranchDto branchDto = mock(BranchDto.class); + when(branchDto.getUuid()).thenReturn("componentUuid"); + + Clock clock = mock(Clock.class); + when(clock.millis()).thenReturn(12345678901234L); + + BranchSupport.ComponentKey componentKey = mock(BranchSupport.ComponentKey.class); + when(componentKey.getKey()).thenReturn("componentKey"); + when(componentKey.getDbKey()).thenReturn("dbKey"); + when(componentKey.getBranch()).thenReturn(Optional.of(new BranchSupport.Branch("dummy", BranchType.LONG))); + when(componentKey.getPullRequestKey()).thenReturn(Optional.empty()); + + ComponentDao componentDao = spy(mock(ComponentDao.class)); + + DbClient dbClient = mock(DbClient.class); + when(dbClient.componentDao()).thenReturn(componentDao); + + UuidFactory uuidFactory = mock(UuidFactory.class); + when(uuidFactory.create()).then(new Answer() { + private int i = 0; + + @Override + public String answer(InvocationOnMock invocationOnMock) { + return "uuid" + (i++); + } + }); + + ComponentDto result = new CommunityBranchSupportDelegate(uuidFactory, dbClient, clock) + .createBranchComponent(dbSession, componentKey, organizationDto, componentDto, branchDto); + + verify(componentDao).insert(dbSession, copyComponentDto); + verify(copyComponentDto).setUuid("uuid0"); + verify(copyComponentDto).setProjectUuid("uuid0"); + verify(copyComponentDto).setRootUuid("uuid0"); + verify(copyComponentDto).setUuidPath("."); + verify(copyComponentDto).setModuleUuidPath(".uuid0."); + verify(copyComponentDto).setMainBranchProjectUuid("componentUuid"); + verify(copyComponentDto).setDbKey(componentKey.getDbKey()); + verify(copyComponentDto).setCreatedAt(new Date(12345678901234L)); + + assertSame(copyComponentDto, result); + + + } + + @Test + public void testCreateBranchComponentUseExistingDto() { + DbSession dbSession = mock(DbSession.class); + OrganizationDto organizationDto = mock(OrganizationDto.class); + + ComponentDto componentDto = mock(ComponentDto.class); + when(componentDto.getKey()).thenReturn("componentKey"); + when(componentDto.uuid()).thenReturn("componentUuid"); + + ComponentDto copyComponentDto = spy(ComponentDto.class); + when(componentDto.copy()).thenReturn(copyComponentDto); + + BranchDto branchDto = mock(BranchDto.class); + when(branchDto.getUuid()).thenReturn("componentUuid"); + when(branchDto.getKey()).thenReturn("dummy"); + when(branchDto.getBranchType()).thenReturn(BranchType.LONG); + + Clock clock = mock(Clock.class); + when(clock.millis()).thenReturn(1234567890123L); + + BranchSupport.ComponentKey componentKey = mock(BranchSupport.ComponentKey.class); + when(componentKey.getKey()).thenReturn("componentKey"); + when(componentKey.getDbKey()).thenReturn("dbKey"); + when(componentKey.getBranch()).thenReturn(Optional.of(new BranchSupport.Branch("dummy", BranchType.LONG))); + when(componentKey.getPullRequestKey()).thenReturn(Optional.empty()); + + ComponentDao componentDao = spy(mock(ComponentDao.class)); + + DbClient dbClient = mock(DbClient.class); + when(dbClient.componentDao()).thenReturn(componentDao); + + UuidFactory uuidFactory = new SequenceUuidFactory(); + + ComponentDto result = new CommunityBranchSupportDelegate(uuidFactory, dbClient, clock) + .createBranchComponent(dbSession, componentKey, organizationDto, componentDto, branchDto); + + assertSame(componentDto, result); + + } + + @Test + public void testCreateBranchComponentUseExistingDto2() { + DbSession dbSession = mock(DbSession.class); + OrganizationDto organizationDto = mock(OrganizationDto.class); + + ComponentDto componentDto = mock(ComponentDto.class); + when(componentDto.getKey()).thenReturn("componentKey"); + when(componentDto.uuid()).thenReturn("componentUuid"); + + ComponentDto copyComponentDto = spy(ComponentDto.class); + when(componentDto.copy()).thenReturn(copyComponentDto); + + BranchDto branchDto = mock(BranchDto.class); + when(branchDto.getUuid()).thenReturn("componentUuid"); + when(branchDto.getKey()).thenReturn("dummy"); + when(branchDto.getBranchType()).thenReturn(BranchType.SHORT); + + Clock clock = mock(Clock.class); + when(clock.millis()).thenReturn(1234567890123L); + + BranchSupport.ComponentKey componentKey = mock(BranchSupport.ComponentKey.class); + when(componentKey.getKey()).thenReturn("componentKey"); + when(componentKey.getDbKey()).thenReturn("dbKey"); + when(componentKey.getBranch()).thenReturn(Optional.empty()); + when(componentKey.getPullRequestKey()).thenReturn(Optional.empty()); + + ComponentDao componentDao = spy(mock(ComponentDao.class)); + + DbClient dbClient = mock(DbClient.class); + when(dbClient.componentDao()).thenReturn(componentDao); + + UuidFactory uuidFactory = new SequenceUuidFactory(); + + ComponentDto result = new CommunityBranchSupportDelegate(uuidFactory, dbClient, clock) + .createBranchComponent(dbSession, componentKey, organizationDto, componentDto, branchDto); + + verify(componentDao).insert(dbSession, copyComponentDto); + verify(copyComponentDto).setUuid("1"); + verify(copyComponentDto).setProjectUuid("1"); + verify(copyComponentDto).setRootUuid("1"); + verify(copyComponentDto).setUuidPath("."); + verify(copyComponentDto).setModuleUuidPath(".1."); + verify(copyComponentDto).setMainBranchProjectUuid("componentUuid"); + verify(copyComponentDto).setDbKey(componentKey.getDbKey()); + verify(copyComponentDto).setCreatedAt(new Date(1234567890123L)); + + assertSame(copyComponentDto, result); + + } + + +}