├── .gitignore ├── LICENSE ├── README.md ├── img ├── admin.png ├── config.png └── trends.png ├── pom.xml └── src └── main ├── java └── org │ └── jenkinsci │ └── plugins │ └── drupal │ ├── beans │ ├── DrupalExtension.java │ ├── DrupalTest.java │ └── DrushInvocation.java │ ├── builders │ ├── DrupalInstanceBuilder.java │ ├── DrupalReviewBuilder.java │ └── DrupalTestsBuilder.java │ ├── config │ └── DrushInstallation.java │ ├── projects │ ├── DrupalBuild.java │ └── DrupalProject.java │ └── scm │ └── DrushMakefileSCM.java └── resources ├── index.jelly └── org └── jenkinsci └── plugins └── drupal ├── builders ├── DrupalInstanceBuilder │ ├── config.jelly │ ├── help-db.html │ ├── help-profile.html │ ├── help-refresh.html │ ├── help-root.html │ └── help-updb.html ├── DrupalReviewBuilder │ ├── config.jelly │ ├── config.properties │ ├── help-except.html │ ├── help-ignoresPass.html │ ├── help-logs.html │ ├── help-root.html │ └── help.html └── DrupalTestsBuilder │ ├── config.jelly │ ├── config.properties │ ├── help-exceptClasses.html │ ├── help-exceptGroups.html │ ├── help-logs.html │ ├── help-root.html │ └── help-uri.html ├── config └── DrushInstallation │ └── config.jelly ├── projects └── DrupalProject │ └── newJobDetail.jelly └── scm └── DrushMakefileSCM ├── config.jelly ├── help-makefile.html └── help-root.html /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | work 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [Jenkins](https://jenkins-ci.org/) plugin to [review code](https://www.drupal.org/project/coder) and [run tests](https://www.drupal.org/simpletest) on [Drupal](https://www.drupal.org/). 2 | 3 | #### Screenshots 4 | 5 | ##### Ploting results 6 | 7 | ![trend graphs](https://raw.github.com/jenkinsci/drupal-developer-plugin/master/img/trends.png) 8 | 9 | ##### Administration interface 10 | 11 | ![admin interface](https://raw.github.com/jenkinsci/drupal-developer-plugin/master/img/admin.png) 12 | 13 | #### Quick start 14 | 15 | * Install [drush 7+](http://docs.drush.org/en/master/install/) globally or configure the path to Drush on `http:///configure` 16 | * Install [Checkstyle](https://wiki.jenkins-ci.org/display/JENKINS/Checkstyle+Plugin), [JUnit](https://wiki.jenkins-ci.org/display/JENKINS/JUnit+Plugin) and [PHP Built-in Web Server](https://wiki.jenkins-ci.org/display/JENKINS/PHP+Built-in+Web+Server+Plugin) 17 | * Create a local database: `CREATE DATABASE db;` 18 | * Create a Freestyle project that looks like [this](https://github.com/jenkinsci/drupal-developer-plugin/blob/master/img/config.png), or create a Drupal project 19 | * Update the database URL 20 | 21 | #### Compilation 22 | 23 | * `git clone https://github.com/jenkinsci/drupal-developer-plugin` 24 | * `cd drupal-developer-plugin/` 25 | * `git checkout tags/drupal-developer-0.1` 26 | * `mvn clean install -DskipTests=true` 27 | 28 | #### Installation 29 | 30 | ##### Install depdendencies 31 | 32 | `http:///pluginManager/`: 33 | * [SCM API](https://wiki.jenkins-ci.org/display/JENKINS/SCM+API+Plugin) 34 | * [Checkstyle](https://wiki.jenkins-ci.org/display/JENKINS/Checkstyle+Plugin), [JUnit](https://wiki.jenkins-ci.org/display/JENKINS/JUnit+Plugin) and [PHP Built-in Web Server](https://wiki.jenkins-ci.org/display/JENKINS/PHP+Built-in+Web+Server+Plugin) are not required but are relevant 35 | 36 | ##### Install the plugin 37 | 38 | Either from the command line: 39 | * `wget http:///jnlpJars/jenkins-cli.jar` 40 | * `java -jar jenkins-cli.jar -s http:/// install-plugin ./drupal-developer.hpi` 41 | * `/etc/init.d/jenkins restart` 42 | 43 | Or from the web interface: 44 | * Go to `http:///pluginManager/advanced` 45 | * Upload `./target/drupal-developer.hpi` 46 | * Restart Jenkins 47 | 48 | #### Usage 49 | 50 | ##### 1. Create Local Database 51 | 52 | * `CREATE DATABASE db;` 53 | 54 | ##### 2. Install drush 7+ 55 | 56 | * `git clone https://github.com/drush-ops/drush.git /var/lib/jenkins/tools/drush` 57 | * `cd /var/libs/jenkins/tools/drush` 58 | * `git checkout tags/7.0.0-rc2` 59 | * `curl -sSL https://getcomposer.org/installer | php` 60 | * `php composer.phar install` 61 | * Go to `http:///configure` 62 | * Under `Drush installations`, set `Path to Drush home` to `/var/lib/jenkins/tools/drush` 63 | 64 | ##### 3. Create Project 65 | 66 | Create a new 'Freestyle' project. 67 | 68 | Alternatively you may create a 'Drupal' project which generates a ready-to-use job to review code and run tests on a vanilla Drupal core. If you use this option then you may skip most of the instrutions below: just update the database URL and possibly set up a web server. 69 | 70 | ##### 4. Configure Source Code Management 71 | 72 | Configure the Source Code Management section to fetch a full Drupal code base. Here are a few options: 73 | 74 | 1. If you just want to run tests on a Drupal core, you may use [Git](https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin): 75 | * Repository: `http://git.drupal.org/project/drupal.git` 76 | * Branch Specifier: `tags/7.38` 77 | 2. If your own code repository includes a Drupal core, then just pull it 78 | 3. If it does not, then you may combine your own repo with the drupal.org repo using [Multiple SCMs](https://wiki.jenkins-ci.org/display/JENKINS/Multiple+SCMs+Plugin) 79 | 4. Alternatively you may use a `Drush Makefile` source 80 | 81 | By default Jenkins pulls code into the workspace root but you might want to put Drupal into a subdirectory to keep things clean (e.g. `$WORKSPACE/drupal`): 82 | * If using [Git](https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin): set option `Additional Behaviours / Check out to a sub-directory` to `drupal` 83 | * If using [Subversion](https://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin): set option `Local module directory` to `drupal` 84 | * If using a Drush Makefile: set option `Drupal root directory` to `drupal` 85 | 86 | Note that a Drush Makefile source will fetch the code every time a new build runs. Using a regular source like Git or Subversion is probably more efficient. 87 | 88 | Also only Drupal 7 code is supported. 89 | 90 | ##### 5. Configure Local Web Server 91 | 92 | Some tests fail if Drupal does not run behind a web server. Here are a couple of solutions: 93 | * Either install [PHP Built-in Web Server](https://wiki.jenkins-ci.org/display/JENKINS/PHP+Built-in+Web+Server+Plugin) (requires PHP >= 5.4.0) e.g.: 94 | * Port: `8000` 95 | * Host: `localhost` 96 | * Document root: `drupal` (or leave empty if the Drupal root is the workspace root) 97 | * Or install Apache locally and make it point at the Drupal root (e.g. `/var/lib/jenkins/jobs/myproject/workspace/drupal`) 98 | 99 | ##### 6. Configure Builds 100 | 101 | Add build steps: 102 | * `Build a Drupal instance` 103 | * `Review code on Drupal` 104 | * `Run tests on Drupal` 105 | 106 | The default values should work though you need to update a few things: 107 | * Update the database URL in step `Build a Drupal instance` to point at your database 108 | * If you have checked out Drupal into a subdirectory (e.g. `drupal`) then update the Drupal root directory of every step accordingly ; otherwise, just leave it empty 109 | * The URI of step `Run tests on Drupal` should match what you have configured on your webserver (e.g. `http://localhost:8000`) 110 | 111 | Note that if your code base does not include a copy of the Coder module, then step `Review code on Drupal` will automatically download it into `$DRUPAL/modules/`. 112 | 113 | ##### 7. Plot results 114 | 115 | Plot Code Review results using [Checkstyle](https://wiki.jenkins-ci.org/display/JENKINS/Checkstyle+Plugin): 116 | * Create a post-build action `Publish Checkstyle analysis results` 117 | * If the logs directory for the code review is `logs_codereview` then set `Checkstyle results` to `logs_codereview/**` 118 | * You might want to set the unstable threshold to 0 normal warning, and the failed threshold to 0 high warning 119 | 120 | Plot Test results using [JUnit](https://wiki.jenkins-ci.org/display/JENKINS/JUnit+Plugin): 121 | * Create a post-build action `Publish JUnit test result report` 122 | * If the logs directory for the tests is `logs_tests` then set `Test report XMLs` to `logs_tests/**` 123 | 124 | ##### 8. Build The Project 125 | 126 | * Click on `Build Now`: Jenkins should start reviewing and testing the code base 127 | * After a few builds complete, trend graphs should show up 128 | 129 | #### Dependencies 130 | 131 | * [drush 7+](http://www.drush.org/en/master/install/) 132 | * [SCM API](https://wiki.jenkins-ci.org/display/JENKINS/SCM+API+Plugin) 133 | * [Checkstyle](https://wiki.jenkins-ci.org/display/JENKINS/Checkstyle+Plugin), [JUnit](https://wiki.jenkins-ci.org/display/JENKINS/JUnit+Plugin) and [PHP Built-in Web Server](https://wiki.jenkins-ci.org/display/JENKINS/PHP+Built-in+Web+Server+Plugin) (or Apache) are not required but are relevant 134 | 135 | #### Troubleshooting 136 | 137 | Q: The plugin is installed but the build steps do not show up 138 | A: Make sure dependencies are installed and up to date 139 | 140 | Q: Many tests fail with this kind of error: 141 | `Test UserEditedOwnAccountTestCase->testUserEditedOwnAccount() failed:` 142 | `GET http://localhost/user returned 0 (0 bytes).` 143 | `in /var/lib/jenkins/jobs/drupal/workspace/modules/user/user.test on line 2047` 144 | A: Make sure Drupal runs behind a web server 145 | -------------------------------------------------------------------------------- /img/admin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/drupal-developer-plugin/8ee2f4a15068a967b637b3375325870d1ebe160b/img/admin.png -------------------------------------------------------------------------------- /img/config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/drupal-developer-plugin/8ee2f4a15068a967b637b3375325870d1ebe160b/img/config.png -------------------------------------------------------------------------------- /img/trends.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/drupal-developer-plugin/8ee2f4a15068a967b637b3375325870d1ebe160b/img/trends.png -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.jenkins-ci.plugins 7 | plugin 8 | 1.580 9 | 10 | 11 | 12 | org.jenkins-ci.plugins 13 | drupal-developer 14 | 0.9-SNAPSHOT 15 | hpi 16 | Drupal Developer 17 | Review code and run tests on Drupal. 18 | https://wiki.jenkins-ci.org/display/JENKINS/Drupal+Developer+Plugin 19 | 20 | 21 | 22 | GNU General Public License v2.0 23 | http://opensource.org/licenses/GPL-2.0 24 | 25 | 26 | 27 | 28 | 29 | fengtan 30 | Fengtan 31 | https://github.com/fengtan/ 32 | 33 | 34 | 35 | 36 | scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git 37 | scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git 38 | http://github.com/jenkinsci/${project.artifactId}-plugin 39 | HEAD 40 | 41 | 42 | 43 | 44 | repo.jenkins-ci.org 45 | http://repo.jenkins-ci.org/public/ 46 | 47 | 48 | 49 | 50 | 51 | repo.jenkins-ci.org 52 | http://repo.jenkins-ci.org/public/ 53 | 54 | 55 | 56 | 57 | 58 | org.apache.commons 59 | commons-collections4 60 | 4.0 61 | 62 | 63 | org.apache.commons 64 | commons-lang3 65 | 3.1 66 | 67 | 68 | commons-io 69 | commons-io 70 | 2.7 71 | 72 | 73 | com.googlecode.json-simple 74 | json-simple 75 | 1.1.1 76 | 77 | 78 | org.jenkins-ci.plugins 79 | scm-api 80 | 0.2 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/drupal/beans/DrupalExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Fengtan 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package org.jenkinsci.plugins.drupal.beans; 20 | 21 | /** 22 | * Drupal extension (theme/module). 23 | * 24 | * @author Fengtan https://github.com/fengtan/ 25 | * 26 | */ 27 | public class DrupalExtension { 28 | 29 | private String name; 30 | private String type; 31 | private String status; 32 | private String version; 33 | 34 | public DrupalExtension(String name, String type, String status, String version) { 35 | this.name = name; 36 | this.type = type; 37 | this.status = status; 38 | this.version = version; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public String getType() { 46 | return type; 47 | } 48 | 49 | public String getStatus() { 50 | return status; 51 | } 52 | 53 | public String getVersion() { 54 | return version; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/drupal/beans/DrupalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Fengtan 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package org.jenkinsci.plugins.drupal.beans; 20 | 21 | /** 22 | * Drupal test class. 23 | * 24 | * @author Fengtan https://github.com/fengtan/ 25 | * 26 | */ 27 | public class DrupalTest { 28 | 29 | private String group; 30 | private String className; 31 | 32 | public DrupalTest(String group, String className) { 33 | this.group = group; 34 | this.className = className; 35 | } 36 | 37 | public String getGroup() { 38 | return group; 39 | } 40 | 41 | public String getClassName() { 42 | return className; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/drupal/beans/DrushInvocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Fengtan 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package org.jenkinsci.plugins.drupal.beans; 20 | 21 | import hudson.EnvVars; 22 | import hudson.FilePath; 23 | import hudson.Launcher; 24 | import hudson.Launcher.ProcStarter; 25 | import hudson.model.TaskListener; 26 | import hudson.model.Computer; 27 | import hudson.tools.ToolInstallation; 28 | import hudson.util.ArgumentListBuilder; 29 | import hudson.util.StreamTaskListener; 30 | 31 | import java.io.ByteArrayOutputStream; 32 | import java.io.File; 33 | import java.io.IOException; 34 | import java.io.OutputStream; 35 | import java.util.Collection; 36 | import java.util.HashMap; 37 | import java.util.HashSet; 38 | import java.util.Map; 39 | import java.util.Objects; 40 | 41 | import org.apache.commons.collections.CollectionUtils; 42 | import org.apache.commons.collections.MapUtils; 43 | import org.apache.commons.io.output.NullOutputStream; 44 | import org.apache.commons.lang.StringUtils; 45 | import org.jenkinsci.plugins.drupal.config.DrushInstallation; 46 | import org.json.simple.JSONArray; 47 | import org.json.simple.JSONObject; 48 | import org.json.simple.JSONValue; 49 | 50 | /** 51 | * Invoke Drush commands. 52 | * 53 | * @author Fengtan https://github.com/fengtan/ 54 | * 55 | */ 56 | public class DrushInvocation { 57 | 58 | protected final FilePath root; 59 | protected final FilePath workspace; 60 | protected final Launcher launcher; 61 | protected final TaskListener listener; 62 | protected final EnvVars environment; 63 | 64 | public DrushInvocation(FilePath root, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars environment) { 65 | this.root = root; 66 | this.workspace = workspace; 67 | this.launcher = launcher; 68 | this.listener = listener; 69 | this.environment = environment; 70 | } 71 | 72 | /** 73 | * Get default Drush options. 74 | */ 75 | protected ArgumentListBuilder getArgumentListBuilder() { 76 | return new ArgumentListBuilder(getDrushExe()).add("--yes").add("--nocolor").add("--root="+root.getRemote()); 77 | } 78 | 79 | /** 80 | * Get Drush executable. 81 | */ 82 | protected String getDrushExe() { 83 | DrushInstallation installation = getDrushInstallation(); 84 | String defaultExe = launcher.isUnix() ? "drush" : "drush.bat"; 85 | if (installation == null) { 86 | listener.getLogger().println("[DRUPAL] No Drush installation configured, fall back to '"+defaultExe+"'"); 87 | return defaultExe; 88 | } 89 | try { 90 | installation = installation.forNode(Computer.currentComputer().getNode(), listener); 91 | installation = installation.forEnvironment(environment); 92 | String exe = installation.getExecutable(launcher); 93 | if (exe == null) { 94 | listener.getLogger().println("[DRUPAL] Drush executable '"+exe+"' from installation '"+installation.getName()+"' could not be found, fall back to '"+defaultExe+"'"); 95 | return defaultExe; 96 | } 97 | return exe; 98 | } catch (IOException e) { 99 | listener.getLogger().println("[DRUPAL] Fall back to '"+defaultExe+"' due to error: "+e.getMessage()); 100 | return defaultExe; 101 | } catch (InterruptedException e) { 102 | listener.getLogger().println("[DRUPAL] Fall back to '"+defaultExe+"' due to error: "+e.getMessage()); 103 | return defaultExe; 104 | } 105 | } 106 | 107 | /** 108 | * Get first Drush installation configured, or null if no installation is configured. 109 | */ 110 | protected DrushInstallation getDrushInstallation() { 111 | DrushInstallation[] installations = ToolInstallation.all().get(DrushInstallation.DescriptorImpl.class).getInstallations(); 112 | return (installations.length > 0) ? installations[0] : null; 113 | } 114 | 115 | /** 116 | * Execute a Drush command. 117 | */ 118 | protected boolean execute(ArgumentListBuilder args) throws IOException, InterruptedException { 119 | return execute(args, null); 120 | } 121 | 122 | /** 123 | * Execute a Drush command. 124 | */ 125 | protected boolean execute(ArgumentListBuilder args, TaskListener out) throws IOException, InterruptedException { 126 | ProcStarter starter = launcher.launch().pwd(workspace).cmds(args); 127 | if (out == null) { 128 | // Output stdout/stderr into listener. 129 | starter.stdout(listener); 130 | } else { 131 | // Output stdout into out. 132 | // Do not output stderr since this breaks the XML formatting on stdout. 133 | starter.stdout(out).stderr(NullOutputStream.NULL_OUTPUT_STREAM); 134 | } 135 | starter.join(); 136 | return true; 137 | } 138 | 139 | /** 140 | * Run update.php. 141 | */ 142 | public boolean upDb() throws IOException, InterruptedException { 143 | ArgumentListBuilder args = getArgumentListBuilder(); 144 | args.add("updatedb"); 145 | return execute(args); 146 | } 147 | 148 | /** 149 | * Make a Drupal site using a Makefile. 150 | */ 151 | public boolean make(File makefile) throws IOException, InterruptedException { 152 | ArgumentListBuilder args = getArgumentListBuilder(); 153 | args.add("make"); 154 | args.add(makefile.getAbsolutePath()); 155 | args.add(root.getRemote()); 156 | return execute(args); 157 | } 158 | 159 | /** 160 | * Install a Drupal site using an installation profile. 161 | */ 162 | public boolean siteInstall(String db, String profile) throws IOException, InterruptedException { 163 | ArgumentListBuilder args = getArgumentListBuilder(); 164 | args.add("site-install"); 165 | args.add(profile); 166 | args.add("--db-url="+db); 167 | return execute(args); 168 | } 169 | 170 | /** 171 | * Download projects/modules into a destination directory. 172 | */ 173 | public boolean download(String projects, String destination) throws IOException, InterruptedException { 174 | ArgumentListBuilder args = getArgumentListBuilder(); 175 | args.add("pm-download").add(projects); 176 | if (StringUtils.isNotEmpty(destination)) { 177 | args.add("--destination="+destination); 178 | } 179 | return execute(args); 180 | } 181 | 182 | /** 183 | * Enable extensions/modules. 184 | */ 185 | public boolean enable(String extensions) throws IOException, InterruptedException { 186 | ArgumentListBuilder args = getArgumentListBuilder(); 187 | args.add("pm-enable").add(extensions); 188 | return execute(args); 189 | } 190 | 191 | /** 192 | * Get a map of projects installed on Drupal, keyed by machine name. 193 | */ 194 | public Map getProjects(boolean modulesOnly, boolean enabledOnly) { 195 | ArgumentListBuilder args = getArgumentListBuilder(); 196 | args.add("pm-list").add("--pipe").add("--format=json"); 197 | if (modulesOnly) { 198 | args.add("--type=module"); 199 | } 200 | if (enabledOnly) { 201 | args.add("--status=enabled"); 202 | } 203 | 204 | OutputStream json = new ByteArrayOutputStream(); 205 | try { 206 | execute(args, new StreamTaskListener(json)); 207 | } catch (IOException e1) { 208 | listener.getLogger().println(e1); 209 | return MapUtils.EMPTY_MAP; 210 | } catch (InterruptedException e2) { 211 | listener.getLogger().println(e2); 212 | return MapUtils.EMPTY_MAP; 213 | } 214 | 215 | Map projects = new HashMap(); 216 | JSONObject entries = (JSONObject) JSONValue.parse(json.toString()); 217 | if (entries == null) { 218 | listener.getLogger().println("[DRUPAL] Could not list available projects"); 219 | return MapUtils.EMPTY_MAP; 220 | } 221 | for (Object name: entries.keySet()) { 222 | JSONObject entry = (JSONObject) entries.get(name); 223 | DrupalExtension project = new DrupalExtension( 224 | Objects.toString(name, ""), 225 | Objects.toString(entry.get("type"), ""), 226 | Objects.toString(entry.get("status"), ""), 227 | Objects.toString(entry.get("version"), "") 228 | ); 229 | projects.put(name.toString(), project); 230 | } 231 | 232 | return projects; 233 | } 234 | 235 | /** 236 | * Check if a module exists / is enabled 237 | */ 238 | public boolean isModuleInstalled(String name, boolean enabledOnly) { 239 | return getProjects(true, enabledOnly).keySet().contains(name); 240 | } 241 | 242 | /** 243 | * Return true if the site is already installed, false otherwise. 244 | */ 245 | public boolean status() { 246 | ArgumentListBuilder args = getArgumentListBuilder(); 247 | args.add("status").add("--format=json"); 248 | 249 | OutputStream json = new ByteArrayOutputStream(); 250 | try { 251 | execute(args, new StreamTaskListener(json)); 252 | } catch (IOException e1) { 253 | listener.getLogger().println(e1); 254 | return false; 255 | } catch (InterruptedException e2) { 256 | listener.getLogger().println(e2); 257 | return false; 258 | } 259 | 260 | JSONObject values = (JSONObject) JSONValue.parse(json.toString()); 261 | if (values == null) { 262 | listener.getLogger().println("[DRUPAL] Could not determine the site status."); 263 | return false; 264 | } 265 | 266 | return values.containsKey("db-name"); 267 | } 268 | 269 | /** 270 | * Get a list of test classes available. 271 | */ 272 | public Collection getTests() { 273 | ArgumentListBuilder args = getArgumentListBuilder(); 274 | args.add("test-run").add("--format=json"); 275 | 276 | OutputStream json = new ByteArrayOutputStream(); 277 | try { 278 | execute(args, new StreamTaskListener(json)); 279 | } catch (IOException e1) { 280 | listener.getLogger().println(e1); 281 | return CollectionUtils.EMPTY_COLLECTION; 282 | } catch (InterruptedException e2) { 283 | listener.getLogger().println(e2); 284 | return CollectionUtils.EMPTY_COLLECTION; 285 | } 286 | 287 | Collection tests = new HashSet(); 288 | JSONArray entries = (JSONArray) JSONValue.parse(json.toString()); 289 | if (entries == null) { 290 | listener.getLogger().println("[DRUPAL] Could not list available tests"); 291 | return CollectionUtils.EMPTY_COLLECTION; 292 | } 293 | for (Object entry: entries) { 294 | JSONObject test = (JSONObject) entry; 295 | tests.add(new DrupalTest(test.get("group").toString(), test.get("class").toString())); 296 | } 297 | 298 | return tests; 299 | } 300 | 301 | /** 302 | * Run tests. 303 | */ 304 | public boolean testRun(File outputDir, String uri, Collection targets) throws IOException, InterruptedException { 305 | ArgumentListBuilder args = getArgumentListBuilder(); 306 | args.add("test-run"); 307 | args.add("--xml="+outputDir.getAbsolutePath()); 308 | if (StringUtils.isNotEmpty(uri)) { 309 | args.add("--uri="+uri); 310 | } 311 | args.add(StringUtils.join(targets, ",")); 312 | return execute(args); 313 | } 314 | 315 | /** 316 | * Run a code review. 317 | */ 318 | public boolean coderReview(File outputDir, Collection reviews, final Collection projectNames, boolean ignoresPass) throws IOException, InterruptedException { 319 | // Make sure Coder is enabled. 320 | DrupalExtension coder = getProjects(true, true).get("coder"); 321 | if (coder == null) { 322 | listener.getLogger().println("[DRUPAL] Coder does not exist: aborting code review"); 323 | return false; 324 | } 325 | 326 | // Build command depending on Coder's version. 327 | ArgumentListBuilder args = getArgumentListBuilder(); 328 | args.add("coder-review"); 329 | if (coder.getVersion().startsWith("7.x-2")) { 330 | args.add("--minor"); 331 | args.add("--checkstyle"); 332 | args.add("--reviews="+StringUtils.join(reviews, ",")); 333 | } else if (coder.getVersion().startsWith("7.x-1")) { 334 | args.add("minor"); 335 | args.add("checkstyle"); 336 | for (String review: reviews) { 337 | args.add(review); 338 | } 339 | } else { 340 | listener.getLogger().println("[DRUPAL] Unsupported Coder version "+coder.getVersion()); 341 | return false; 342 | } 343 | 344 | // Ignores pass if needed. 345 | // This option works only with coder-7.x-2.4+. 346 | if (ignoresPass) { 347 | if (coder.getVersion().startsWith("7.x-2") && (Integer.parseInt(coder.getVersion().replaceFirst("7\\.x-2\\.", "")) >= 4)) { 348 | args.add("--ignores-pass"); 349 | } else { 350 | listener.getLogger().println("[DRUPAL] 'Ignores pass' option is available only with Coder-7.x-2.4+, ignoring option"); 351 | } 352 | } 353 | 354 | // In coder-7.x-2.x, 'drush coder-review comment' fails with error "use --reviews or --comment". Same for i18n. 355 | // Ignore projects involved in conflicts. 356 | Collection conflicts = CollectionUtils.intersection(projectNames, reviews); 357 | if (!conflicts.isEmpty()) { 358 | listener.getLogger().println("[DRUPAL] Ignoring project(s) conflicting with Coder options: "+StringUtils.join(conflicts, ", ")); 359 | } 360 | for (String projectName: projectNames) { 361 | if (!conflicts.contains(projectName)) { 362 | args.add(projectName); 363 | } 364 | } 365 | 366 | // Run command. 367 | File outputFile = new File(outputDir, "coder_review.xml"); 368 | return execute(args, new StreamTaskListener(outputFile)); 369 | } 370 | 371 | } 372 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/drupal/builders/DrupalInstanceBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Fengtan 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package org.jenkinsci.plugins.drupal.builders; 20 | 21 | import hudson.Extension; 22 | import hudson.FilePath; 23 | import hudson.Launcher; 24 | import hudson.model.BuildListener; 25 | import hudson.model.AbstractBuild; 26 | import hudson.model.AbstractProject; 27 | import hudson.tasks.BuildStepDescriptor; 28 | import hudson.tasks.Builder; 29 | import hudson.util.FormValidation; 30 | 31 | import java.io.File; 32 | import java.io.IOException; 33 | 34 | import net.sf.json.JSONObject; 35 | 36 | import org.jenkinsci.plugins.drupal.beans.DrushInvocation; 37 | import org.kohsuke.stapler.AncestorInPath; 38 | import org.kohsuke.stapler.DataBoundConstructor; 39 | import org.kohsuke.stapler.QueryParameter; 40 | import org.kohsuke.stapler.StaplerRequest; 41 | 42 | /** 43 | * Install a Drupal instance. 44 | * 45 | * @author Fengtan https://github.com/fengtan/ 46 | * 47 | */ 48 | public class DrupalInstanceBuilder extends Builder { 49 | 50 | public final String db; 51 | public final String root; 52 | public final String profile; 53 | public final boolean refresh; 54 | public final boolean updb; 55 | 56 | @DataBoundConstructor 57 | public DrupalInstanceBuilder(String db, String root, String profile, boolean refresh, boolean updb) { 58 | this.db = db; 59 | this.root = root; 60 | this.profile = profile; 61 | this.refresh = refresh; 62 | this.updb = updb; 63 | } 64 | 65 | @Override 66 | public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { 67 | // Create Drupal installation if needed. 68 | DrushInvocation drush = new DrushInvocation(new FilePath(new File(root)), build.getWorkspace(), launcher, listener, build.getEnvironment(listener)); 69 | if (refresh || !drush.status()) { 70 | listener.getLogger().println("[DRUPAL] No Drupal installation detected, installing Drupal..."); 71 | drush.siteInstall(db, profile); 72 | } else { 73 | listener.getLogger().println("[DRUPAL] Drupal is already installed, skipping installation"); 74 | } 75 | 76 | // Run update.php if needed. 77 | if (updb) { 78 | drush.upDb(); 79 | } 80 | 81 | return true; 82 | } 83 | 84 | @Extension 85 | public static final class DescriptorImpl extends BuildStepDescriptor { 86 | /** 87 | * Load the persisted global configuration. 88 | */ 89 | public DescriptorImpl() { 90 | load(); 91 | } 92 | 93 | /** 94 | * This builder can be used with all kinds of project types. 95 | */ 96 | public boolean isApplicable(Class aClass) { 97 | return true; 98 | } 99 | 100 | /** 101 | * Human readable name is used in the configuration screen. 102 | */ 103 | public String getDisplayName() { 104 | return "Build a Drupal instance"; 105 | } 106 | 107 | @Override 108 | public boolean configure(StaplerRequest req, JSONObject formData) throws FormException { 109 | save(); 110 | return super.configure(req, formData); 111 | } 112 | 113 | /** 114 | * Field 'db' should not be empty. 115 | */ 116 | public FormValidation doCheckDb(@QueryParameter String value) { 117 | if (value.length() == 0) { 118 | return FormValidation.error("Please set a database URL"); 119 | } 120 | return FormValidation.ok(); 121 | } 122 | 123 | /** 124 | * Field 'root' should be a valid directory. 125 | */ 126 | public FormValidation doCheckRoot(@AncestorInPath AbstractProject project, @QueryParameter String value) throws IOException { 127 | if (value.length() == 0) { 128 | return FormValidation.warning("Workspace root will be used as Drupal root"); 129 | } 130 | if (project != null) { 131 | return FilePath.validateFileMask(project.getSomeWorkspace(), value); 132 | } 133 | return FormValidation.ok(); 134 | } 135 | 136 | } 137 | } 138 | 139 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/drupal/builders/DrupalReviewBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Fengtan 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package org.jenkinsci.plugins.drupal.builders; 20 | 21 | import hudson.Extension; 22 | import hudson.FilePath; 23 | import hudson.Launcher; 24 | import hudson.Util; 25 | import hudson.model.BuildListener; 26 | import hudson.model.AbstractBuild; 27 | import hudson.model.AbstractProject; 28 | import hudson.tasks.BuildStepDescriptor; 29 | import hudson.tasks.Builder; 30 | import hudson.util.FormValidation; 31 | 32 | import java.io.File; 33 | import java.io.IOException; 34 | import java.util.Arrays; 35 | import java.util.Collection; 36 | import java.util.HashSet; 37 | 38 | import net.sf.json.JSONObject; 39 | 40 | import org.apache.commons.collections4.CollectionUtils; 41 | import org.apache.commons.collections4.Transformer; 42 | import org.apache.commons.io.FilenameUtils; 43 | import org.apache.tools.ant.DirectoryScanner; 44 | import org.apache.tools.ant.types.FileSet; 45 | import org.jenkinsci.plugins.drupal.beans.DrushInvocation; 46 | import org.kohsuke.stapler.AncestorInPath; 47 | import org.kohsuke.stapler.DataBoundConstructor; 48 | import org.kohsuke.stapler.QueryParameter; 49 | import org.kohsuke.stapler.StaplerRequest; 50 | 51 | /** 52 | * Run Coder Review on Drupal. 53 | * 54 | * @author Fengtan https://github.com/fengtan/ 55 | * 56 | */ 57 | public class DrupalReviewBuilder extends Builder { 58 | 59 | // 'drush dl coder' downloads coder-7.x-1.3 so we will use 'drush dl coder-7.x-2.5' explicitly. 60 | private static final String CODER_RELEASE = "coder-7.x-2.5"; 61 | 62 | public final boolean style; 63 | public final boolean comment; 64 | public final boolean sql; 65 | public final boolean security; 66 | public final boolean i18n; 67 | 68 | public final String root; 69 | public final String logs; 70 | public final String except; 71 | public final boolean ignoresPass; 72 | 73 | @DataBoundConstructor 74 | public DrupalReviewBuilder(boolean style, boolean comment, boolean sql, boolean security, boolean i18n, String root, String logs, String except, boolean ignoresPass) { 75 | this.style = style; 76 | this.comment = comment; 77 | this.sql = sql; 78 | this.security = security; 79 | this.i18n = i18n; 80 | this.root = root; 81 | this.logs = logs; 82 | this.except = except; 83 | this.ignoresPass = ignoresPass; 84 | } 85 | 86 | @Override 87 | public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { 88 | // Make sure logs directory exists. 89 | File logsDir = new File(build.getWorkspace().getRemote(), logs); 90 | if (!logsDir.exists()) { 91 | listener.getLogger().println("[DRUPAL] Creating logs directory "+logs); 92 | logsDir.mkdir(); 93 | } 94 | 95 | // Download and enable Coder if necessary. 96 | final File rootDir = new File(build.getWorkspace().getRemote(), root); 97 | DrushInvocation drush = new DrushInvocation(new FilePath(rootDir), build.getWorkspace(), launcher, listener, build.getEnvironment(listener)); 98 | if (drush.isModuleInstalled("coder", false)) { 99 | listener.getLogger().println("[DRUPAL] Coder already exists"); 100 | } else { 101 | listener.getLogger().println("[DRUPAL] Coder does not exist. Downloading Coder..."); 102 | drush.download(CODER_RELEASE, "modules"); 103 | } 104 | if (drush.isModuleInstalled("coder_review", true)) { 105 | listener.getLogger().println("[DRUPAL] Coder is already enabled"); 106 | } else { 107 | listener.getLogger().println("[DRUPAL] Coder is not enabled. Enabling Coder..."); 108 | drush.enable("coder_review"); 109 | } 110 | 111 | Collection reviews = new HashSet(); 112 | if (this.style) reviews.add("style"); 113 | if (this.comment) reviews.add("comment"); 114 | if (this.sql) reviews.add("sql"); 115 | if (this.security) reviews.add("security"); 116 | if (this.i18n) reviews.add("i18n"); 117 | 118 | // Remove projects the user wants to exclude. 119 | // **/*.info matches all modules, themes and installation profiles. 120 | // Installation profiles cannot be reviewed and will be just ignored by Coder. 121 | FileSet fileSet = Util.createFileSet(rootDir, "**/*.info", except); 122 | DirectoryScanner scanner = fileSet.getDirectoryScanner(); 123 | Collection projects = Arrays.asList(scanner.getIncludedFiles()); 124 | 125 | // Transform sites/all/modules/mymodule/mymodule.module into mymodule. 126 | CollectionUtils.transform(projects, new Transformer() { 127 | @Override 128 | public String transform(String project) { 129 | return FilenameUtils.getBaseName(project); 130 | } 131 | }); 132 | 133 | // Run code review. 134 | drush.coderReview(logsDir, reviews, projects, ignoresPass); 135 | 136 | return true; 137 | } 138 | 139 | @Extension 140 | public static final class DescriptorImpl extends BuildStepDescriptor { 141 | /** 142 | * Load the persisted global configuration. 143 | */ 144 | public DescriptorImpl() { 145 | load(); 146 | } 147 | 148 | /** 149 | * This builder can be used with all kinds of project types. 150 | */ 151 | public boolean isApplicable(Class aClass) { 152 | return true; 153 | } 154 | 155 | /** 156 | * Human readable name used in the configuration screen. 157 | */ 158 | public String getDisplayName() { 159 | return "Review code on Drupal"; 160 | } 161 | 162 | @Override 163 | public boolean configure(StaplerRequest req, JSONObject formData) throws FormException { 164 | save(); 165 | return super.configure(req, formData); 166 | } 167 | 168 | /** 169 | * Field 'root' should be a valid directory. 170 | */ 171 | public FormValidation doCheckRoot(@AncestorInPath AbstractProject project, @QueryParameter String value) throws IOException { 172 | if (value.length() == 0) { 173 | return FormValidation.warning("Workspace root will be used as Drupal root"); 174 | } 175 | if (project != null) { 176 | return FilePath.validateFileMask(project.getSomeWorkspace(), value); 177 | } 178 | return FormValidation.ok(); 179 | } 180 | 181 | /** 182 | * Field 'logs' should not be empty. 183 | */ 184 | public FormValidation doCheckLogs(@QueryParameter String value) throws IOException { 185 | if (value.length() == 0) { 186 | return FormValidation.error("Please set a logs directory"); 187 | } 188 | return FormValidation.ok(); 189 | } 190 | 191 | } 192 | } 193 | 194 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/drupal/builders/DrupalTestsBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Fengtan 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package org.jenkinsci.plugins.drupal.builders; 20 | 21 | import hudson.Extension; 22 | import hudson.FilePath; 23 | import hudson.Launcher; 24 | import hudson.model.BuildListener; 25 | import hudson.model.AbstractBuild; 26 | import hudson.model.AbstractProject; 27 | import hudson.tasks.BuildStepDescriptor; 28 | import hudson.tasks.Builder; 29 | import hudson.util.FormValidation; 30 | 31 | import java.io.File; 32 | import java.io.IOException; 33 | import java.util.ArrayList; 34 | import java.util.Arrays; 35 | import java.util.Collection; 36 | import java.util.Collections; 37 | import java.util.List; 38 | 39 | import net.sf.json.JSONObject; 40 | 41 | import org.apache.commons.collections.Closure; 42 | import org.apache.commons.collections.CollectionUtils; 43 | import org.apache.commons.lang3.StringUtils; 44 | import org.jenkinsci.plugins.drupal.beans.DrupalTest; 45 | import org.jenkinsci.plugins.drupal.beans.DrushInvocation; 46 | import org.kohsuke.stapler.AncestorInPath; 47 | import org.kohsuke.stapler.DataBoundConstructor; 48 | import org.kohsuke.stapler.QueryParameter; 49 | import org.kohsuke.stapler.StaplerRequest; 50 | 51 | /** 52 | * Run Simpletest on Drupal. 53 | * 54 | * @author Fengtan https://github.com/fengtan/ 55 | * 56 | */ 57 | public class DrupalTestsBuilder extends Builder { 58 | 59 | public final String uri; 60 | public final String root; 61 | public final String logs; 62 | public final String exceptGroups; 63 | public final String exceptClasses; 64 | 65 | @DataBoundConstructor 66 | public DrupalTestsBuilder(String uri, String root, String logs, String exceptGroups, String exceptClasses) { 67 | this.uri = uri; 68 | this.root = root; 69 | this.logs = logs; 70 | this.exceptGroups = exceptGroups; 71 | this.exceptClasses = exceptClasses; 72 | } 73 | 74 | @Override 75 | public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { 76 | // Make sure logs directory exists. 77 | File logsDir = new File(build.getWorkspace().getRemote(), logs); 78 | if (!logsDir.exists()) { 79 | listener.getLogger().println("[DRUPAL] Creating logs directory "+logs); 80 | logsDir.mkdir(); 81 | } 82 | 83 | // Enable Simpletest if necessary. 84 | File rootDir = new File(build.getWorkspace().getRemote(), root); 85 | DrushInvocation drush = new DrushInvocation(new FilePath(rootDir), build.getWorkspace(), launcher, listener, build.getEnvironment(listener)); 86 | if (drush.isModuleInstalled("simpletest", true)) { 87 | listener.getLogger().println("[DRUPAL] Simpletest is already enabled"); 88 | } else { 89 | listener.getLogger().println("[DRUPAL] Simpletest is not enabled. Enabling Simpletest..."); 90 | drush.enable("simpletest"); 91 | } 92 | 93 | // Build list of targets and filter out excluded groups/classes. 94 | final List targets = new ArrayList(); 95 | final Collection groups = Arrays.asList(exceptGroups.toLowerCase().split(",[\\s]*")); 96 | final Collection classes = Arrays.asList(exceptClasses.toLowerCase().split(",[\\s]*")); 97 | CollectionUtils.forAllDo(drush.getTests(), new Closure() { 98 | @Override 99 | public void execute(Object input) { 100 | DrupalTest test = (DrupalTest) input; 101 | if (!groups.contains(test.getGroup().toLowerCase()) && !classes.contains(test.getClassName().toLowerCase())) { 102 | targets.add(test.getClassName()); 103 | } 104 | } 105 | }); 106 | Collections.sort(targets); 107 | 108 | // Run Simpletest. 109 | if (CollectionUtils.isEmpty(targets)) { 110 | listener.getLogger().println("[DRUPAL] No test groups/classes to run"); 111 | } else { 112 | drush.testRun(logsDir, uri, targets); 113 | } 114 | 115 | return true; 116 | } 117 | 118 | @Extension 119 | public static final class DescriptorImpl extends BuildStepDescriptor { 120 | /** 121 | * Load the persisted global configuration. 122 | */ 123 | public DescriptorImpl() { 124 | load(); 125 | } 126 | 127 | /** 128 | * This builder can be used with all kinds of project types. 129 | */ 130 | public boolean isApplicable(Class aClass) { 131 | return true; 132 | } 133 | 134 | /** 135 | * Human readable name used in the configuration screen. 136 | */ 137 | public String getDisplayName() { 138 | return "Run tests on Drupal"; 139 | } 140 | 141 | @Override 142 | public boolean configure(StaplerRequest req, JSONObject formData) throws FormException { 143 | save(); 144 | return super.configure(req, formData); 145 | } 146 | 147 | /** 148 | * Field 'uri' should not be empty. 149 | */ 150 | public FormValidation doCheckUri(@QueryParameter String value) throws IOException { 151 | if (value.length() == 0) { 152 | return FormValidation.error("Please set a URI"); 153 | } 154 | return FormValidation.ok(); 155 | } 156 | 157 | /** 158 | * Field 'root' should be a valid directory. 159 | */ 160 | public FormValidation doCheckRoot(@AncestorInPath AbstractProject project, @QueryParameter String value) throws IOException { 161 | if (value.length() == 0) { 162 | return FormValidation.warning("Workspace root will be used as Drupal root"); 163 | } 164 | if (project != null) { 165 | return FilePath.validateFileMask(project.getSomeWorkspace(), value); 166 | } 167 | return FormValidation.ok(); 168 | } 169 | 170 | /** 171 | * Field 'logs' should not be empty. 172 | */ 173 | public FormValidation doCheckLogs(@QueryParameter String value) throws IOException { 174 | if (value.length() == 0) { 175 | return FormValidation.error("Please set a logs directory"); 176 | } 177 | return FormValidation.ok(); 178 | } 179 | 180 | } 181 | } 182 | 183 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/drupal/config/DrushInstallation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Fengtan 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package org.jenkinsci.plugins.drupal.config; 20 | 21 | import static hudson.init.InitMilestone.EXTENSIONS_AUGMENTED; 22 | import hudson.EnvVars; 23 | import hudson.Extension; 24 | import hudson.Functions; 25 | import hudson.Launcher; 26 | import hudson.Util; 27 | import hudson.init.Initializer; 28 | import hudson.model.EnvironmentSpecific; 29 | import hudson.model.TaskListener; 30 | import hudson.model.Node; 31 | import hudson.remoting.Callable; 32 | import hudson.slaves.NodeSpecific; 33 | import hudson.tools.ToolInstaller; 34 | import hudson.tools.ToolProperty; 35 | import hudson.tools.ToolDescriptor; 36 | import hudson.tools.ToolInstallation; 37 | import hudson.util.FormValidation; 38 | 39 | import java.io.File; 40 | import java.io.IOException; 41 | import java.util.Collections; 42 | import java.util.List; 43 | 44 | import jenkins.model.Jenkins; 45 | import net.sf.json.JSONObject; 46 | 47 | import org.kohsuke.stapler.DataBoundConstructor; 48 | import org.kohsuke.stapler.QueryParameter; 49 | import org.kohsuke.stapler.StaplerRequest; 50 | 51 | /** 52 | * Handle Drush installations. 53 | * 54 | * @author Fengtan https://github.com/fengtan/ 55 | * 56 | */ 57 | public class DrushInstallation extends ToolInstallation implements NodeSpecific, EnvironmentSpecific { 58 | 59 | @DataBoundConstructor 60 | public DrushInstallation(String name, String home, List> properties) { 61 | super(name, home, properties); 62 | } 63 | 64 | @Override 65 | public void buildEnvVars(EnvVars env) { 66 | env.put("DRUSH_HOME", getHome()); 67 | } 68 | 69 | /** 70 | * Get executable path of this Drush installation on the given target system. 71 | */ 72 | public String getExecutable(Launcher launcher) throws IOException, InterruptedException { 73 | return launcher.getChannel().call(new Callable() { 74 | public String call() throws IOException { 75 | File exe = getExeFile(); 76 | return exe.exists() ? exe.getPath() : null; 77 | } 78 | }); 79 | } 80 | 81 | /** 82 | * Get executable file. 83 | */ 84 | private File getExeFile() { 85 | String execName = Functions.isWindows() ? "drush.bat" : "drush"; 86 | String home = Util.replaceMacro(getHome(), EnvVars.masterEnvVars); 87 | return new File(home, execName); 88 | } 89 | 90 | /** 91 | * Check if the executable exists. 92 | */ 93 | public boolean getExists() throws IOException, InterruptedException { 94 | return getExecutable(new Launcher.LocalLauncher(TaskListener.NULL)) != null; 95 | } 96 | 97 | @Override 98 | public DrushInstallation forEnvironment(EnvVars environment) { 99 | return new DrushInstallation(getName(), environment.expand(getHome()), getProperties().toList()); 100 | } 101 | 102 | @Override 103 | public DrushInstallation forNode(Node node, TaskListener log) throws IOException, InterruptedException { 104 | return new DrushInstallation(getName(), translateFor(node, log), getProperties().toList()); 105 | } 106 | 107 | @Override 108 | public DescriptorImpl getDescriptor() { 109 | return (DescriptorImpl) Jenkins.getInstance().getDescriptorOrDie(getClass()); 110 | } 111 | 112 | @Initializer(after=EXTENSIONS_AUGMENTED) 113 | public static void onLoaded() { 114 | // Create default tool installation if needed. 115 | DescriptorImpl descriptor = (DescriptorImpl) Jenkins.getInstance().getDescriptor(DrushInstallation.class); 116 | DrushInstallation[] installations = descriptor.getInstallations(); 117 | 118 | // No need to initialize if there's already something. 119 | if (installations != null && installations.length > 0) { 120 | return; 121 | } 122 | 123 | DrushInstallation tool = new DrushInstallation("Default", "", Collections.>emptyList()); 124 | descriptor.setInstallations(new DrushInstallation[] { tool }); 125 | descriptor.save(); 126 | } 127 | 128 | @Extension 129 | public static class DescriptorImpl extends ToolDescriptor { 130 | 131 | @Override 132 | public String getDisplayName() { 133 | return "Drush"; 134 | } 135 | 136 | @Override 137 | public List getDefaultInstallers() { 138 | return Collections.EMPTY_LIST; 139 | } 140 | 141 | /** 142 | * Load the persisted global configuration. 143 | */ 144 | public DescriptorImpl() { 145 | super(); 146 | load(); 147 | } 148 | 149 | @Override 150 | public boolean configure(StaplerRequest req, JSONObject json) throws FormException { 151 | setInstallations(req.bindJSONToList(clazz, json.get("tool")).toArray(new DrushInstallation[0])); 152 | save(); 153 | return true; 154 | } 155 | 156 | /** 157 | * Installation name should not be empty. 158 | */ 159 | public FormValidation doCheckName(@QueryParameter String value) { 160 | return FormValidation.validateRequired(value); 161 | } 162 | 163 | } 164 | 165 | } -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/drupal/projects/DrupalBuild.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Fengtan 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package org.jenkinsci.plugins.drupal.projects; 20 | 21 | import hudson.model.Build; 22 | 23 | import java.io.File; 24 | import java.io.IOException; 25 | 26 | /** 27 | * Drupal build. 28 | * 29 | * @author Fengtan https://github.com/fengtan/ 30 | * 31 | */ 32 | public class DrupalBuild extends Build { 33 | 34 | public DrupalBuild(DrupalProject project) throws IOException { 35 | super(project); 36 | } 37 | 38 | public DrupalBuild(DrupalProject project, File buildDir) throws IOException { 39 | super(project, buildDir); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/drupal/projects/DrupalProject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Fengtan 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package org.jenkinsci.plugins.drupal.projects; 20 | 21 | import hudson.Extension; 22 | import hudson.model.ItemGroup; 23 | import hudson.model.TopLevelItem; 24 | import hudson.model.Project; 25 | 26 | import java.io.IOException; 27 | import java.util.logging.Logger; 28 | 29 | import jenkins.model.Jenkins; 30 | 31 | import org.jenkinsci.plugins.drupal.builders.DrupalInstanceBuilder; 32 | import org.jenkinsci.plugins.drupal.builders.DrupalReviewBuilder; 33 | import org.jenkinsci.plugins.drupal.builders.DrupalTestsBuilder; 34 | import org.jenkinsci.plugins.drupal.scm.DrushMakefileSCM; 35 | 36 | /** 37 | * Drupal project (top level item). 38 | * 39 | * @author Fengtan https://github.com/fengtan/ 40 | * 41 | */ 42 | public class DrupalProject extends Project implements TopLevelItem { 43 | 44 | private static final Logger LOGGER = Logger.getLogger(DrupalProject.class.getName()); 45 | 46 | public DrupalProject(ItemGroup parent, String name) { 47 | super(parent, name); 48 | } 49 | 50 | @Override 51 | protected Class getBuildClass() { 52 | return DrupalBuild.class; 53 | } 54 | 55 | public DescriptorImpl getDescriptor() { 56 | return (DescriptorImpl) Jenkins.getInstance().getDescriptorOrDie(getClass()); 57 | } 58 | 59 | @Extension 60 | public static final class DescriptorImpl extends AbstractProjectDescriptor { 61 | 62 | /** 63 | * Human readable name used in the configuration screen. 64 | */ 65 | public String getDisplayName() { 66 | return "Drupal project"; 67 | } 68 | 69 | @Override 70 | public DrupalProject newInstance(ItemGroup parent, String name) { 71 | DrupalProject project = new DrupalProject(parent, name); 72 | 73 | // Add SCM. 74 | try { 75 | project.setScm(new DrushMakefileSCM("api=2\r\ncore=7.x\r\nprojects[drupal][version]=7.38", "drupal")); 76 | } catch (IOException e) { 77 | LOGGER.warning("[DRUPAL] Unable to instantiate Makefile SCM: "+e.toString()); 78 | } 79 | 80 | // Add builders. 81 | project.getBuildersList().add(new DrupalInstanceBuilder("mysql://user:password@localhost/db", "drupal", "standard", false, false)); 82 | project.getBuildersList().add(new DrupalReviewBuilder(true, true, true, true, true, "drupal", "logs_codereview", "", false)); 83 | project.getBuildersList().add(new DrupalTestsBuilder("http://localhost/", "drupal", "logs_tests", "", "")); 84 | 85 | // Add publishers. 86 | // project.getPublishersList().add(new CheckStylePublisher("", "", "low", "", false, "", "", "0", "", "", "", "", "", "", "0", "", "", "", "", "", "", false, false, false, false, false, "logs_codereview/*")); 87 | // project.getPublishersList().add(new JUnitResultArchiver("logs_tests/*")); 88 | 89 | return project; 90 | } 91 | 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/drupal/scm/DrushMakefileSCM.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Fengtan 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | package org.jenkinsci.plugins.drupal.scm; 20 | 21 | import hudson.Extension; 22 | import hudson.FilePath; 23 | import hudson.Launcher; 24 | import hudson.model.TaskListener; 25 | import hudson.model.AbstractProject; 26 | import hudson.model.Job; 27 | import hudson.model.Run; 28 | import hudson.scm.ChangeLogParser; 29 | import hudson.scm.PollingResult; 30 | import hudson.scm.SCMDescriptor; 31 | import hudson.scm.SCMRevisionState; 32 | import hudson.scm.SCM; 33 | import hudson.util.FormValidation; 34 | 35 | import java.io.File; 36 | import java.io.IOException; 37 | 38 | import org.apache.commons.io.FileUtils; 39 | import org.jenkinsci.plugins.drupal.beans.DrushInvocation; 40 | import org.kohsuke.stapler.AncestorInPath; 41 | import org.kohsuke.stapler.DataBoundConstructor; 42 | import org.kohsuke.stapler.QueryParameter; 43 | 44 | /** 45 | * Checkout Drupal source code based on a Drush Makefile. 46 | * 47 | * @author Fengtan https://github.com/fengtan/ 48 | * 49 | */ 50 | public class DrushMakefileSCM extends SCM { 51 | 52 | // Save Makefile data into this file. 53 | private static final String MAKEFILE_FILE = "drupal.make"; 54 | 55 | private final String makefile; 56 | private final String root; 57 | 58 | @DataBoundConstructor 59 | public DrushMakefileSCM(String makefile, String root) { 60 | this.makefile = makefile; 61 | this.root = root; 62 | } 63 | 64 | public String getMakefile() { 65 | return makefile; 66 | } 67 | 68 | public String getRoot() { 69 | return root; 70 | } 71 | 72 | @Override 73 | public PollingResult compareRemoteRevisionWith(Job project, Launcher launcher, FilePath workspace, TaskListener listener, SCMRevisionState _baseline) { 74 | return PollingResult.NO_CHANGES; 75 | } 76 | 77 | @Override 78 | public void checkout(Run build, Launcher launcher, FilePath workspace, TaskListener listener, File changelogFile, SCMRevisionState baseline) throws IOException, InterruptedException { 79 | // If necessary, delete destination directory so we can install Drupal (unless Drupal root is workspace root). 80 | File rootDir = new File(workspace.getRemote(), root); 81 | FilePath rootPath = new FilePath(rootDir); 82 | if (rootDir.exists() && !rootPath.getRemote().equals(workspace.getRemote())) { 83 | listener.getLogger().println("[DRUPAL] Deleting destination directory "+rootDir.getAbsolutePath()); 84 | // Make sure drupal/sites/defaults is writable so we can delete its contents. 85 | File defaultDir = new File(rootDir, "sites/default"); 86 | defaultDir.setWritable(true); 87 | FileUtils.deleteDirectory(rootDir); 88 | } 89 | 90 | // Save Makefile into local file. 91 | File makefileFile = new File(workspace.getRemote(), MAKEFILE_FILE); 92 | listener.getLogger().println("[DRUPAL] Saving Makefile into "+makefileFile.getAbsolutePath()); 93 | FileUtils.writeStringToFile(makefileFile, makefile); 94 | 95 | // Make Drupal. 96 | DrushInvocation drush = new DrushInvocation(rootPath, workspace, launcher, listener, build.getEnvironment(listener)); 97 | drush.make(makefileFile); 98 | } 99 | 100 | @Override 101 | public ChangeLogParser createChangeLogParser() { 102 | return null; 103 | } 104 | 105 | @Extension 106 | public static class DescriptorImpl extends SCMDescriptor { 107 | /** 108 | * Load the persisted global configuration. 109 | */ 110 | public DescriptorImpl() { 111 | super(DrushMakefileSCM.class, null); 112 | load(); 113 | } 114 | 115 | /** 116 | * Human readable name is used in the configuration screen. 117 | */ 118 | @Override 119 | public String getDisplayName() { 120 | return "Drush Makefile"; 121 | } 122 | 123 | /** 124 | * Field 'makefile' should not be empty. 125 | */ 126 | public FormValidation doCheckMakefile(@QueryParameter String value) { 127 | if (value.length() == 0) { 128 | return FormValidation.error("Please set a Makefile"); 129 | } 130 | return FormValidation.ok(); 131 | } 132 | 133 | /** 134 | * Field 'root' cannot be empty ('drush make' expects an empty directory so workspace root cannot be used as Drupal root). 135 | */ 136 | public FormValidation doCheckRoot(@AncestorInPath AbstractProject project, @QueryParameter String value) throws IOException { 137 | if (value.length() == 0) { 138 | return FormValidation.error("Please set a Drupal root"); 139 | } 140 | return FormValidation.ok(); 141 | } 142 | 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 | 2 |
3 | Review code and run tests on Drupal. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalInstanceBuilder/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalInstanceBuilder/help-db.html: -------------------------------------------------------------------------------- 1 |
2 | Specify the database connection string, e.g. mysql://user:password@localhost/db 3 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalInstanceBuilder/help-profile.html: -------------------------------------------------------------------------------- 1 |
2 | Specify an installation profile. Drupal 7 natively includes three installation profiles: 'minimal', 'standard' and 'testing'. 3 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalInstanceBuilder/help-refresh.html: -------------------------------------------------------------------------------- 1 |
2 |

If checked, every build will wipe out and recreate a fresh Drupal instance.

3 |

Note that creating a fresh Drupal instance sends an email to the site administrator (by default admin@example.net) which may be annoying.

4 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalInstanceBuilder/help-root.html: -------------------------------------------------------------------------------- 1 |
2 | Specify a local directory for the Drupal root (relative to the workspace root). If left empty, the workspace root itself will be used. 3 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalInstanceBuilder/help-updb.html: -------------------------------------------------------------------------------- 1 |
2 | If checked, every build will run update.php. This option only makes sense if 'Create a fresh installation for every build' is unchecked. 3 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalReviewBuilder/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalReviewBuilder/config.properties: -------------------------------------------------------------------------------- 1 | title.link={0} -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalReviewBuilder/help-except.html: -------------------------------------------------------------------------------- 1 |
2 |

Specify modules/themes that should not be reviewed, relative to the Drupal root directory.

3 |

For instance if you want to review only custom code then you might want to exclude contributed and core projects: 4 |

 5 |     sites/all/modules/contrib/**,
 6 |     sites/all/themes/contrib/**,
 7 |     modules/**,
 8 |     themes/**,
 9 |     profiles/**
10 |     
11 |

12 |

This field supports FileSet includes.

13 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalReviewBuilder/help-ignoresPass.html: -------------------------------------------------------------------------------- 1 |
2 |

If checked, warnings flagged as ignored will pass.

3 |

Note that the ignore system was introduced in Coder 7.x-2.4. This option will be ignored if using an older version of Coder.

4 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalReviewBuilder/help-logs.html: -------------------------------------------------------------------------------- 1 |
2 | Specify a local directory to dump code review results (relative to the workspace root). Use the Checkstyle plugin to interpret results in a post-build action. 3 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalReviewBuilder/help-root.html: -------------------------------------------------------------------------------- 1 |
2 | Specify a local directory for the Drupal root (relative to the workspace root). If left empty, the workspace root itself will be used. 3 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalReviewBuilder/help.html: -------------------------------------------------------------------------------- 1 |
2 |

Review code using the Coder Review module.

3 |

If your code base does not include Coder, then Coder will be downloaded automatically.

4 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalTestsBuilder/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalTestsBuilder/config.properties: -------------------------------------------------------------------------------- 1 | uri.description=The Drupal site should be web accessible: you may either configure the PHP Built-in Web Server Plugin or configure Apache to point at the Drupal root. -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalTestsBuilder/help-exceptClasses.html: -------------------------------------------------------------------------------- 1 |
2 |

Specify Simpletest classes that should not be tested, for instance 'UserLoginTestCase'.

3 |

Multiple classes can be separated by a comma.

4 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalTestsBuilder/help-exceptGroups.html: -------------------------------------------------------------------------------- 1 |
2 | Specify Simpletest groups that should not be tested. For instance if you want to run tests only on custom code then you might want to exclude core groups: 3 |
4 |   Actions, Aggregator, AJAX, Batch API, Block, Blog, Book, Bootstrap, Cache, Color, Comment, Contact, Contextual, Dashboard, Database, DBLog, Entity API, Field API, Field types, Field UI, File, File API, File API (remote), Filter, Form API, Forum, Help, Image, Locale, Mail, Menu, Module, Node, OpenID, Pager, Path, Path API, PHP, Poll, Profile, RDF, Search, Session, Shortcut, SimpleTest, Statistics, Syslog, System, Taxonomy, Theme, Tracker, Translation, Trigger, Update, Update API, Upgrade path, User, XML-RPC
5 |   
6 | Multiple groups can be separated by a comma. 7 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalTestsBuilder/help-logs.html: -------------------------------------------------------------------------------- 1 |
2 | Specify a local directory to dump test results (relative to the workspace root). Use the JUnit plugin to interpret results in a post-build action. 3 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalTestsBuilder/help-root.html: -------------------------------------------------------------------------------- 1 |
2 | Specify a local directory for the Drupal root (relative to the workspace root). If left empty, the workspace root itself will be used. 3 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/builders/DrupalTestsBuilder/help-uri.html: -------------------------------------------------------------------------------- 1 |
2 | URI of the Drupal site. Simpletest requires this option to be set. 3 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/config/DrushInstallation/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/projects/DrupalProject/newJobDetail.jelly: -------------------------------------------------------------------------------- 1 | 2 |
3 | Build a Drupal instance, review code and run tests. 4 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/scm/DrushMakefileSCM/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/scm/DrushMakefileSCM/help-makefile.html: -------------------------------------------------------------------------------- 1 |
2 |

Specify the content of the Makefile. Support for YAML Makefiles depends on the version of Drush you have installed.

3 |

This example will generate a vanilla Drupal 7.38: 4 |

 5 |     api=2
 6 |     core=7.x
 7 |     projects[drupal][version]=7.38
 8 |     
9 |

10 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/drupal/scm/DrushMakefileSCM/help-root.html: -------------------------------------------------------------------------------- 1 |
2 | Specify a local directory for the Drupal root (relative to the workspace root). 3 |
--------------------------------------------------------------------------------