├── .github ├── dependabot.yml ├── release.yml └── workflows │ ├── build.yml │ └── release.yml ├── .gitignore ├── .mvn ├── quality-configs │ ├── checkstyle │ │ └── checkstyle.xml │ ├── pmd │ │ └── pmd.xml │ ├── spotbugs │ │ ├── exclude.xml │ │ └── include.xml │ └── spotless │ │ └── allure.java.license └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── LICENSE ├── README.md ├── appveyor.yml ├── docker-compose.yml ├── img ├── add_task.png ├── task_fields.png └── view_artifact.png ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── io │ │ └── qameta │ │ └── allure │ │ └── bamboo │ │ ├── AllureArtifactsManager.java │ │ ├── AllureBuildCompleteAction.java │ │ ├── AllureBuildConfig.java │ │ ├── AllureBuildConfigurator.java │ │ ├── AllureBuildResult.java │ │ ├── AllureCommandLineSupport.java │ │ ├── AllureConstants.java │ │ ├── AllureDownloader.java │ │ ├── AllureExecutable.java │ │ ├── AllureExecutableProvider.java │ │ ├── AllureGenerateResult.java │ │ ├── AllureGlobalConfig.java │ │ ├── AllurePluginException.java │ │ ├── AllurePluginInstallTask.java │ │ ├── AllureReportServlet.java │ │ ├── AllureReportTask.java │ │ ├── AllureSettingsManager.java │ │ ├── AllureViewReportCondition.java │ │ ├── BambooExecutablesManager.java │ │ ├── ConfigureAllureReportAction.java │ │ ├── ViewAllureReport.java │ │ ├── config │ │ └── AllurePluginJavaConfig.java │ │ ├── info │ │ ├── AbstractAddInfo.java │ │ ├── AddExecutorInfo.java │ │ ├── AddTestRunInfo.java │ │ ├── AllurePlugins.java │ │ └── allurewidgets │ │ │ └── summary │ │ │ ├── AbstractSummary.java │ │ │ ├── Statistic.java │ │ │ ├── Summary.java │ │ │ └── Time.java │ │ └── util │ │ ├── Downloader.java │ │ ├── ExceptionUtil.java │ │ ├── FileStringReplacer.java │ │ └── ZipUtil.java └── resources │ ├── META-INF │ └── spring │ │ └── plugin-context.xml │ ├── allure-bamboo.properties │ ├── atlassian-plugin.xml │ ├── images │ ├── icon.png │ ├── logo.png │ └── logo_deprecated.png │ └── templates │ ├── editAllureBambooConfiguration.ftl │ ├── editAllureReportConfig.ftl │ ├── error.ftl │ ├── viewAllureBambooConfiguration.ftl │ └── viewAllureReport.ftl └── test ├── java └── io │ └── qameta │ └── allure │ └── bamboo │ ├── AllureCommandLineSupportTest.java │ ├── AllureDownloaderTest.java │ ├── AllureExecutableProviderTest.java │ ├── AllureExecutableTest.java │ ├── AllureReportServletTest.java │ ├── SecondAllureExecutableProviderTest.java │ └── util │ └── ExceptionUtilTest.java └── resources └── log4j.properties /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | labels: 8 | - "type:dependencies" 9 | 10 | - package-ecosystem: "maven" 11 | directory: "/" 12 | schedule: 13 | interval: "daily" 14 | labels: 15 | - "type:dependencies" 16 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | # release.yml 2 | 3 | changelog: 4 | categories: 5 | - title: '🚀 New Features' 6 | labels: 7 | - 'type:new feature' 8 | - title: '🔬 Improvements' 9 | labels: 10 | - 'type:improvement' 11 | - title: '🐞 Bug Fixes' 12 | labels: 13 | - 'type:bug' 14 | - title: '⬆️ Dependency Updates' 15 | labels: 16 | - 'type:dependencies' 17 | - title: '👻 Internal changes' 18 | labels: 19 | - 'type:internal' 20 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - '*' 7 | push: 8 | branches: 9 | - 'master' 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | - uses: actions/setup-java@v4 17 | with: 18 | distribution: 'temurin' 19 | java-version: '17' 20 | cache: 'maven' 21 | - name: Maven Build 22 | run: ./mvnw clean package 23 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | release: 5 | types: [ published ] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: actions/setup-java@v4 13 | with: 14 | distribution: 'temurin' 15 | java-version: '17' 16 | cache: 'maven' 17 | - run: echo "VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV 18 | - run: ./mvnw versions:set -DnewVersion=${{ env.VERSION }} 19 | - run: ./mvnw package 20 | - uses: actions/upload-release-asset@v1 21 | env: 22 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 23 | with: 24 | upload_url: ${{ github.event.release.upload_url }} 25 | asset_path: ./target/allure-bamboo-${{ env.VERSION }}.jar 26 | asset_name: allure-bamboo-${{ env.VERSION }}.jar 27 | asset_content_type: application/octet-stream 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .backup 2 | .idea 3 | *.iml 4 | target/* 5 | .test 6 | classes 7 | 8 | amps-* 9 | 10 | .DS_Store -------------------------------------------------------------------------------- /.mvn/quality-configs/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | -------------------------------------------------------------------------------- /.mvn/quality-configs/pmd/pmd.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | General Java quality rules. 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /.mvn/quality-configs/spotbugs/exclude.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /.mvn/quality-configs/spotbugs/include.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.mvn/quality-configs/spotless/allure.java.license: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allure-framework/allure-bamboo/d0f6f2e0dbe582fe935da71931364e1ccc81e91d/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2016-2024 Qameta Software Inc 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Allure Bamboo Plugin 2 | 3 | This repository contains source code of Allure plugin 4 | for [Atlassian Bamboo CI](https://www.atlassian.com/software/bamboo). It allows you to generate Allure report 5 | from [existing Allure XML files](https://github.com/allure-framework/allure-core/wiki#gathering-information-about-tests). 6 | 7 | ### Building and Installing 8 | 9 | #### Short way 10 | 11 | Download precompiled JAR from [releases page](https://github.com/allure-framework/allure-bamboo-plugin/releases) and 12 | install it manually as 13 | described [here](https://confluence.atlassian.com/display/UPM/Installing+add-ons#Installingadd-ons-Installingbyfileupload). 14 | We use JDK 1.8+ to compile the plugin so be sure to use Java 1.8+ for running Bamboo. 15 | 16 | #### Long way 17 | 18 | 1. Set up Atlassian plugin SDK as 19 | described [here](https://developer.atlassian.com/display/DOCS/Set+up+the+Atlassian+Plugin+SDK+and+Build+a+Project). 20 | 2. Clone this repository 21 | 3. Run `$ atlas-run` 22 | 4. Access http://localhost:6990/bamboo/ to view development instance of Bamboo 23 | 5. Verify that plugin is working as expected 24 | 6. Install **target/allure-bamboo-plugin-VERSION.jar** manually as 25 | described [here](https://confluence.atlassian.com/display/UPM/Installing+add-ons#Installingadd-ons-Installingbyfileupload). 26 | 27 | ### Configuration and Usage 28 | 29 | Please follow the guide on the official Allure docs: https://docs.qameta.io/allure/#_bamboo 30 | 31 | #### To activate debug log goto: 32 | 33 | http://localhost:6990/bamboo/admin/configLog4j.action 34 | 1. add io.qameta.allure.bamboo to classpath 35 | 2. select debug 36 | 3. Save form 37 | 38 | Logs will available in ../target/bamboo/home/logs/atlassian-bamboo.log 39 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | skip_tags: true 3 | clone_depth: 10 4 | environment: 5 | matrix: 6 | - JAVA_HOME: C:\Program Files\Java\jdk1.8.0 7 | branches: 8 | only: 9 | - master 10 | except: 11 | - gh-pages 12 | os: Windows Server 2012 13 | install: 14 | - ps: | 15 | Add-Type -AssemblyName System.IO.Compression.FileSystem 16 | if (!(Test-Path -Path "C:\maven" )) { 17 | (new-object System.Net.WebClient).DownloadFile('https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip', 'C:\maven-bin.zip') 18 | [System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven") 19 | } 20 | - cmd: SET M2_HOME=C:\maven\apache-maven-3.8.1 21 | - cmd: SET ATLAS_MVN=%M2_HOME%\bin\mvn 22 | - cmd: SET PATH=%M2_HOME%\bin;%JAVA_HOME%\bin;%PATH:C:\Ruby193\bin;=% 23 | - cmd: SET JAVA_OPTS=-XX:MaxPermSize=2g -Xmx4g 24 | - cmd: mvn --version 25 | - cmd: java -version 26 | build_script: 27 | - mvn clean package -B -Dmaven.test.skip=true 28 | test_script: 29 | - mvn clean install --batch-mode -Pqulice 30 | cache: 31 | - C:\maven\ 32 | - C:\Users\appveyor\.m2 33 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | networks: 4 | dev: 5 | driver: bridge 6 | 7 | volumes: 8 | bamboo-data: 9 | external: false 10 | bamboo-data-db: 11 | external: false 12 | bamboo-agent-data: 13 | external: false 14 | 15 | services: 16 | 17 | bamboo: 18 | image: atlassian/bamboo 19 | container_name: bamboo 20 | hostname: bamboo 21 | ports: 22 | - '54663:5436' 23 | - '8085:8085' 24 | networks: 25 | - dev 26 | volumes: 27 | - bamboo-data:/var/atlassian/application-data/bamboo 28 | environment: 29 | CATALINA_OPTS: -Xms256m -Xmx1g -Dupm.plugin.upload.enabled=true 30 | JVM_SUPPORT_RECOMMENDED_ARGS: -Dupm.plugin.upload.enabled=true 31 | BAMBOO_PROXY_NAME: 32 | BAMBOO_PROXY_PORT: 33 | BAMBOO_PROXY_SCHEME: 34 | BAMBOO_DELAYED_START: 35 | labels: 36 | com.blacklabelops.description: "Atlassian Bamboo" 37 | com.blacklabelops.service: "bamboo" 38 | 39 | db-bamboo: 40 | image: postgres 41 | container_name: postgres 42 | hostname: postgres 43 | networks: 44 | - dev 45 | volumes: 46 | - bamboo-data-db:/var/lib/postgresql/data 47 | ports: 48 | - '5432:5432' 49 | environment: 50 | POSTGRES_PASSWORD: bamboo 51 | POSTGRES_USER: bamboo 52 | POSTGRES_DB: bamboo 53 | POSTGRES_ENCODING: UTF8 54 | POSTGRES_COLLATE: C 55 | POSTGRES_COLLATE_TYPE: C 56 | PGDATA: /var/lib/postgresql/data/pgdata 57 | labels: 58 | com.blacklabelops.description: "PostgreSQL Database Server" 59 | com.blacklabelops.service: "postgresql" 60 | 61 | bamboo-agent: 62 | image: atlassian/bamboo-agent-base 63 | container_name: bamboo-agent 64 | hostname: bamboo-agent 65 | networks: 66 | - dev 67 | volumes: 68 | - bamboo-agent-data:/var/atlassian/application-data/bamboo-agent 69 | environment: 70 | BAMBOO_SERVER: http://bamboo:8085/agentServer/ -------------------------------------------------------------------------------- /img/add_task.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allure-framework/allure-bamboo/d0f6f2e0dbe582fe935da71931364e1ccc81e91d/img/add_task.png -------------------------------------------------------------------------------- /img/task_fields.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allure-framework/allure-bamboo/d0f6f2e0dbe582fe935da71931364e1ccc81e91d/img/task_fields.png -------------------------------------------------------------------------------- /img/view_artifact.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allure-framework/allure-bamboo/d0f6f2e0dbe582fe935da71931364e1ccc81e91d/img/view_artifact.png -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureBuildCompleteAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import com.atlassian.bamboo.build.BuildDefinition; 19 | import com.atlassian.bamboo.chains.ChainExecution; 20 | import com.atlassian.bamboo.chains.ChainResultsSummary; 21 | import com.atlassian.bamboo.chains.plugins.PostChainAction; 22 | import com.atlassian.bamboo.configuration.AdministrationConfiguration; 23 | import com.atlassian.bamboo.plan.cache.ImmutableChain; 24 | import com.atlassian.bamboo.resultsummary.ResultsSummary; 25 | import com.atlassian.bamboo.resultsummary.ResultsSummaryManager; 26 | import com.atlassian.bamboo.v2.build.BaseConfigurablePlugin; 27 | import com.atlassian.spring.container.ContainerManager; 28 | import com.fasterxml.jackson.databind.ObjectMapper; 29 | import com.fasterxml.jackson.databind.json.JsonMapper; 30 | import io.qameta.allure.bamboo.info.AddExecutorInfo; 31 | import io.qameta.allure.bamboo.info.allurewidgets.summary.Summary; 32 | import io.qameta.allure.bamboo.util.Downloader; 33 | import io.qameta.allure.bamboo.util.FileStringReplacer; 34 | import io.qameta.allure.bamboo.util.ZipUtil; 35 | import org.apache.commons.io.FileUtils; 36 | import org.apache.commons.lang3.StringUtils; 37 | import org.jetbrains.annotations.NotNull; 38 | import org.slf4j.Logger; 39 | import org.slf4j.LoggerFactory; 40 | 41 | import java.io.File; 42 | import java.io.IOException; 43 | import java.io.InputStream; 44 | import java.net.URL; 45 | import java.net.URLConnection; 46 | import java.nio.file.Files; 47 | import java.nio.file.Path; 48 | import java.nio.file.StandardCopyOption; 49 | import java.util.Arrays; 50 | import java.util.Collection; 51 | import java.util.List; 52 | import java.util.Map; 53 | import java.util.Objects; 54 | import java.util.Optional; 55 | import java.util.regex.Pattern; 56 | 57 | import static io.qameta.allure.bamboo.AllureBuildResult.allureBuildResult; 58 | import static io.qameta.allure.bamboo.util.ExceptionUtil.stackTraceToString; 59 | import static java.lang.String.format; 60 | import static java.util.stream.Collectors.toList; 61 | 62 | @SuppressWarnings("ConstantConditions") 63 | public class AllureBuildCompleteAction extends BaseConfigurablePlugin implements PostChainAction { 64 | 65 | private static final Logger LOGGER = LoggerFactory.getLogger(AllureBuildCompleteAction.class); 66 | private static final String HISTORY_JSON = "history.json"; 67 | private static final String HISTORY = "history"; 68 | 69 | private static final List HISTORY_FILES = Arrays.asList(HISTORY_JSON, 70 | "history-trend.json", "categories-trend.json", "duration-trend.json"); 71 | 72 | 73 | private final AllureExecutableProvider allureExecutable; 74 | private final AllureSettingsManager settingsManager; 75 | private final AllureArtifactsManager artifactsManager; 76 | private final BambooExecutablesManager executablesManager; 77 | private final ResultsSummaryManager resultsSummaryManager; 78 | private final AdministrationConfiguration adminConfiguration; 79 | 80 | public AllureBuildCompleteAction(final AllureExecutableProvider allureExecutable, 81 | final AllureSettingsManager settingsManager, 82 | final AllureArtifactsManager artifactsManager, 83 | final BambooExecutablesManager executablesManager, 84 | final ResultsSummaryManager resultsSummaryManager) { 85 | this.allureExecutable = allureExecutable; 86 | this.settingsManager = settingsManager; 87 | this.artifactsManager = artifactsManager; 88 | this.executablesManager = executablesManager; 89 | this.resultsSummaryManager = resultsSummaryManager; 90 | this.adminConfiguration = (AdministrationConfiguration) ContainerManager 91 | .getComponent("administrationConfiguration"); 92 | } 93 | 94 | @Override 95 | @SuppressWarnings({"ExecutableStatementCount", "PMD.NcssCount"}) 96 | public void execute(final @NotNull ImmutableChain chain, 97 | final @NotNull ChainResultsSummary chainResultsSummary, 98 | final @NotNull ChainExecution chainExecution) { 99 | 100 | final BuildDefinition buildDef = chain.getBuildDefinition(); 101 | final AllureGlobalConfig globalConfig = settingsManager.getSettings(); 102 | final AllureBuildConfig buildConfig = AllureBuildConfig.fromContext(buildDef.getCustomConfiguration()); 103 | final boolean allureEnabled = buildConfig.isEnabled() 104 | || !buildConfig.isEnabledSet() && globalConfig.isEnabledByDefault(); 105 | final boolean isEnabledForFailedOnly = buildConfig.isOnlyForFailed(); 106 | if (!allureEnabled || isEnabledForFailedOnly && !chainResultsSummary.isFailed()) { 107 | return; 108 | } 109 | 110 | try { 111 | 112 | final Path artifactsTempDir = Files.createTempDirectory("tmp_artifact"); 113 | final Path allureReportDir = Files.createTempDirectory("tmp_report"); 114 | 115 | buildReport(artifactsTempDir, 116 | allureReportDir, 117 | chainResultsSummary, 118 | chain, 119 | buildConfig, 120 | globalConfig, 121 | chainExecution); 122 | 123 | FileUtils.deleteQuietly(artifactsTempDir.toFile()); 124 | FileUtils.deleteQuietly(allureReportDir.toFile()); 125 | } catch (Exception e) { 126 | LOGGER.error("Failed to create tmp folders to build report.", e); 127 | } 128 | } 129 | 130 | private void buildReport(final Path artifactsTempDir, 131 | final Path allureReportDir, 132 | final ChainResultsSummary chainResultsSummary, 133 | final ImmutableChain chain, 134 | final AllureBuildConfig buildConfig, 135 | final AllureGlobalConfig globalConfig, 136 | final ChainExecution chainExecution) { 137 | 138 | final Map customBuildData = chainResultsSummary.getCustomBuildData(); 139 | try { 140 | final String executable = Optional.ofNullable(buildConfig.getExecutable()) 141 | .orElse(executablesManager.getDefaultAllureExecutable() 142 | .orElseThrow(() -> new RuntimeException("Could not find default Allure executable!" 143 | + " Please configure plugin properly!"))); 144 | 145 | LOGGER.info("Allure Report is enabled for {}", chain.getName()); 146 | LOGGER.info("Trying to get executable by name {} for {}", executable, chain.getName()); 147 | 148 | AllureExecutable allure = allureExecutable.provide(globalConfig, executable) 149 | .orElseThrow(() -> new RuntimeException("Failed to find Allure executable by name " + executable)); 150 | 151 | // Creating a copy for customize report 152 | final Path copyPath = Files.createTempDirectory("tmp_cmd"); 153 | if (globalConfig.isCustomLogoEnabled()) { 154 | allure = allure.getTempCopy(copyPath); 155 | } 156 | 157 | LOGGER.info("Starting artifacts downloading into {} for {}", artifactsTempDir, chain.getName()); 158 | final Collection artifactsPaths = artifactsManager.downloadAllArtifactsTo( 159 | chainResultsSummary, artifactsTempDir.toFile(), buildConfig.getArtifactName()); 160 | if (artifactsTempDir.toFile().list().length == 0) { 161 | allureBuildResult(false, "Build result does not have any uploaded artifacts!") 162 | .dumpToCustomData(customBuildData); 163 | } else { 164 | LOGGER.info("Starting allure generate into {} for {}", allureReportDir, chain.getName()); 165 | prepareResults(artifactsPaths.stream().map(Path::toFile).collect(toList()), chain, chainExecution); 166 | 167 | // Setting the new logo in the allure libraries before generate the report. 168 | if (globalConfig.isCustomLogoEnabled()) { 169 | allure.setCustomLogo(buildConfig.getCustomLogoUrl()); 170 | } 171 | allure.generate(artifactsPaths, allureReportDir); 172 | // Setting report name 173 | this.finalizeReport(allureReportDir, 174 | chainExecution.getPlanResultKey().getBuildNumber(), chain.getBuildName()); 175 | 176 | // Create an exportable zip with the report 177 | ZipUtil.zipReportFolder(allureReportDir, allureReportDir.resolve("report.zip")); 178 | 179 | LOGGER.info("Allure has been generated successfully for {}", chain.getName()); 180 | artifactsManager.uploadReportArtifacts(chain, chainResultsSummary, allureReportDir.toFile()) 181 | .ifPresent(result -> result.dumpToCustomData(customBuildData)); 182 | } 183 | FileUtils.deleteQuietly(copyPath.toFile()); 184 | if (globalConfig.isEnabledReportsCleanup() 185 | && buildConfig.getMaxStoredReportsCount() != null 186 | && buildConfig.getMaxStoredReportsCount() > 0) { 187 | artifactsManager.cleanupOldReportArtifacts(chain, buildConfig.getMaxStoredReportsCount()); 188 | } 189 | } catch (Exception e) { 190 | LOGGER.error("Failed to build allure report for {}", chain.getName(), e); 191 | allureBuildResult(false, stackTraceToString(e)).dumpToCustomData(customBuildData); 192 | } 193 | } 194 | 195 | private void finalizeReport(final @NotNull Path allureReportDir, 196 | final int buildNumber, 197 | final String buildName) throws IOException { 198 | 199 | // Update Report Name (It is the way now) 200 | final Path widgetsJsonPath = allureReportDir 201 | .resolve("widgets") 202 | .resolve("summary.json"); 203 | final ObjectMapper mapper = new JsonMapper(); 204 | final Summary summary = mapper.readValue(widgetsJsonPath.toFile(), Summary.class); 205 | summary.setReportName(format("Build %s - %s", buildNumber, buildName)); 206 | mapper.writeValue(widgetsJsonPath.toFile(), summary); 207 | 208 | // Deleting title from Logo 209 | final Path appJsPath = allureReportDir.resolve("app.js"); 210 | FileStringReplacer.replaceInFile(appJsPath, 211 | Pattern.compile(">Allure", 212 | Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.COMMENTS), 213 | "> " 214 | ); 215 | 216 | // Changing page title 217 | final Path indexHtmlPath = allureReportDir.resolve("index.html"); 218 | FileStringReplacer.replaceInFile(indexHtmlPath, 219 | Pattern.compile(".*", 220 | Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.COMMENTS), 221 | format(" Build %s - %s ", buildNumber, buildName) 222 | ); 223 | } 224 | 225 | private void prepareResults(final List artifactsTempDirs, 226 | final @NotNull ImmutableChain chain, 227 | final @NotNull ChainExecution chainExecution) { 228 | copyHistory(artifactsTempDirs, chain.getPlanKey().getKey(), chainExecution.getPlanResultKey().getBuildNumber()); 229 | addExecutorInfo(artifactsTempDirs, chain, chainExecution.getPlanResultKey().getBuildNumber()); 230 | } 231 | 232 | /** 233 | * Write the history file to results directory. 234 | */ 235 | private void copyHistory(final @NotNull List artifactsTempDirs, 236 | final String planKey, 237 | final int buildNumber) { 238 | try { 239 | final Path tmpDirToDownloadHistory = Files.createTempDirectory("tmp_history"); 240 | getLastBuildNumberWithHistory(planKey, buildNumber) 241 | .ifPresent(buildId -> copyHistoryFiles(planKey, tmpDirToDownloadHistory, buildId)); 242 | artifactsTempDirs.forEach(artifactsTempDir -> { 243 | try { 244 | FileUtils.copyDirectory(tmpDirToDownloadHistory.toFile(), 245 | artifactsTempDir.toPath().resolve(HISTORY).toFile()); 246 | } catch (IOException e) { 247 | LOGGER.error("Failed to copy history files from temp directory into artifacts directory", e); 248 | } 249 | }); 250 | FileUtils.deleteQuietly(tmpDirToDownloadHistory.toFile()); 251 | } catch (Exception e) { 252 | LOGGER.error("Failed to create tmp history folder", e); 253 | } 254 | } 255 | 256 | private void copyHistoryFiles(final String planKey, 257 | final Path historyDir, 258 | final Integer buildNumber) { 259 | HISTORY_FILES.forEach(historyFile -> 260 | copyArtifactToHistoryFolder(historyDir, historyFile, planKey, buildNumber) 261 | ); 262 | } 263 | 264 | private Optional getLastBuildNumberWithHistory(final String planKey, 265 | final int buildNumber) { 266 | int currentBuild = buildNumber; 267 | do { 268 | final ResultsSummary lastBuild = resultsSummaryManager.findLastBuildResultBefore(planKey, currentBuild); 269 | if (Objects.isNull(lastBuild)) { 270 | return Optional.empty(); 271 | } 272 | currentBuild = lastBuild.getBuildNumber(); 273 | } while (!historyArtifactExists(planKey, currentBuild)); 274 | return Optional.of(currentBuild); 275 | } 276 | 277 | private boolean historyArtifactExists(final String planKey, 278 | final int buildId) { 279 | final String artifactUrl = getHistoryArtifactUrl(HISTORY_JSON, planKey, buildId); 280 | final ObjectMapper mapper = new JsonMapper(); 281 | 282 | try { 283 | final Path historyTmpFile = Files.createTempFile(HISTORY, ".json"); 284 | Downloader.download(new URL(artifactUrl), historyTmpFile); 285 | mapper.readValue(historyTmpFile.toFile(), Object.class); 286 | FileUtils.deleteQuietly(historyTmpFile.toFile()); 287 | return true; 288 | } catch (Exception e) { 289 | LOGGER.info("Cannot connect to artifact or the artifact is not valid {}.", artifactUrl, e); 290 | return false; 291 | } 292 | } 293 | 294 | private void copyArtifactToHistoryFolder(final Path historyFolder, 295 | final String fileName, 296 | final String planKey, 297 | final int buildId) { 298 | try (InputStream inputStream = getArtifactContent(fileName, planKey, buildId)) { 299 | Files.createDirectories(historyFolder); 300 | Files.copy(inputStream, historyFolder.resolve(fileName), StandardCopyOption.REPLACE_EXISTING); 301 | } catch (IOException e) { 302 | LOGGER.error("Could not copy file {}", fileName); 303 | } 304 | } 305 | 306 | private InputStream getArtifactContent(final String fileName, 307 | final String planKey, 308 | final int buildId) throws IOException { 309 | final URL artifactUrl = new URL(getHistoryArtifactUrl(fileName, planKey, buildId)); 310 | final URLConnection uc = artifactUrl.openConnection(); 311 | return uc.getInputStream(); 312 | } 313 | 314 | @NotNull 315 | private String getHistoryArtifactUrl(final String fileName, 316 | final String planKey, 317 | final int buildId) { 318 | return format("%s/plugins/servlet/allure/report/%s/%s/history/%s", 319 | getBambooBaseUrl(), planKey, buildId, fileName); 320 | } 321 | 322 | private void addExecutorInfo(final @NotNull List artifactsTempDirs, 323 | final @NotNull ImmutableChain chain, 324 | final int buildNumber) { 325 | final String rootUrl = getBambooBaseUrl(); 326 | final String buildName = chain.getBuildName(); 327 | final String buildUrl = format("%s/browse/%s-%s", rootUrl, chain.getPlanKey().getKey(), buildNumber); 328 | final String reportUrl = format("%s/plugins/servlet/allure/report/%s/%s/", rootUrl, 329 | chain.getPlanKey().getKey(), buildNumber); 330 | final AddExecutorInfo executorInfo = new AddExecutorInfo( 331 | rootUrl, Integer.toString(buildNumber), buildName, buildUrl, reportUrl); 332 | artifactsTempDirs.forEach(executorInfo::invoke); 333 | } 334 | 335 | 336 | /** 337 | * Returns the base url of bamboo server. 338 | */ 339 | @NotNull 340 | private String getBambooBaseUrl() { 341 | if (this.adminConfiguration != null) { 342 | return StringUtils.isNoneBlank(this.adminConfiguration.getBaseUrl()) 343 | ? this.adminConfiguration.getBaseUrl() : ""; 344 | } 345 | return ""; 346 | } 347 | } 348 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureBuildConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import org.apache.commons.lang3.StringUtils; 19 | import org.apache.commons.lang3.math.NumberUtils; 20 | 21 | import javax.annotation.Nullable; 22 | import java.io.Serializable; 23 | import java.util.Map; 24 | 25 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_ARTIFACT_NAME; 26 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_CUSTOM_LOGO_PATH; 27 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_ENABLED; 28 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_EXECUTABLE; 29 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_FAILED_ONLY; 30 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_MAX_STORED_REPORTS_COUNT; 31 | import static java.lang.Boolean.FALSE; 32 | import static java.lang.Boolean.TRUE; 33 | import static java.util.Optional.ofNullable; 34 | 35 | public final class AllureBuildConfig implements Serializable { 36 | 37 | private static final long serialVersionUID = 1L; 38 | 39 | private static final String DEFAULT_ARTIFACT_NAME = "allure-results"; 40 | private static final String DEFAULT_CUSTOM_LOGO_URL = "https://qameta.io/allure-report/img/reportlogo.svg"; 41 | 42 | private final boolean onlyForFailed; 43 | private final String executable; 44 | private final boolean enabled; 45 | private final String artifactName; 46 | private final String logoUrl; 47 | private final Integer maxStoredReportsCount; 48 | 49 | private AllureBuildConfig(final String executable, 50 | final String enabled, 51 | final String onlyForFailed, 52 | final String artifactName, 53 | final String logoUrl, 54 | final String maxStoredReportsCount) { 55 | this.onlyForFailed = StringUtils.isBlank(onlyForFailed) 56 | ? TRUE : Boolean.parseBoolean(onlyForFailed); 57 | this.enabled = StringUtils.isBlank(enabled) 58 | ? FALSE : Boolean.parseBoolean(enabled); 59 | this.executable = executable; 60 | this.artifactName = artifactName; 61 | this.logoUrl = StringUtils.isBlank(logoUrl) 62 | ? AllureBuildConfig.DEFAULT_CUSTOM_LOGO_URL : logoUrl; 63 | this.maxStoredReportsCount = 64 | StringUtils.isBlank(maxStoredReportsCount) || !StringUtils.isNumeric(maxStoredReportsCount) 65 | ? -1 : NumberUtils.toInt(maxStoredReportsCount); 66 | } 67 | 68 | static AllureBuildConfig fromContext(final Map context) { 69 | return new AllureBuildConfig( 70 | getSingleValue(context, ALLURE_CONFIG_EXECUTABLE, null), 71 | getSingleValue(context, ALLURE_CONFIG_ENABLED, FALSE.toString()), 72 | getSingleValue(context, ALLURE_CONFIG_FAILED_ONLY, FALSE.toString()), 73 | getSingleValue(context, ALLURE_CONFIG_ARTIFACT_NAME, AllureBuildConfig.DEFAULT_ARTIFACT_NAME), 74 | getSingleValue(context, ALLURE_CONFIG_CUSTOM_LOGO_PATH, AllureBuildConfig.DEFAULT_CUSTOM_LOGO_URL), 75 | getSingleValue(context, ALLURE_CONFIG_MAX_STORED_REPORTS_COUNT, null) 76 | ); 77 | } 78 | 79 | @Nullable 80 | private static String getSingleValue(final Map context, 81 | final String key, 82 | final String defaultVal) { 83 | return ofNullable(context.get(key)) 84 | .map(value -> value instanceof String[] ? ((String[]) value)[0] : (String) value) 85 | .orElse(defaultVal); 86 | } 87 | 88 | boolean isOnlyForFailed() { 89 | return onlyForFailed; 90 | } 91 | 92 | boolean isEnabledSet() { 93 | return enabled; 94 | } 95 | 96 | public String getExecutable() { 97 | return executable; 98 | } 99 | 100 | boolean isEnabled() { 101 | return enabled; 102 | } 103 | 104 | public String getArtifactName() { 105 | return artifactName; 106 | } 107 | 108 | public String getCustomLogoUrl() { 109 | return this.logoUrl; 110 | } 111 | 112 | public Integer getMaxStoredReportsCount() { 113 | return maxStoredReportsCount; 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureBuildConfigurator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import com.atlassian.bamboo.plan.cache.ImmutablePlan; 19 | import com.atlassian.bamboo.plan.configuration.MiscellaneousPlanConfigurationPlugin; 20 | import com.atlassian.bamboo.template.TemplateRenderer; 21 | import com.atlassian.bamboo.utils.error.ErrorCollection; 22 | import com.atlassian.bamboo.v2.build.BaseConfigurablePlugin; 23 | import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration; 24 | import org.jetbrains.annotations.NotNull; 25 | 26 | import static com.atlassian.bamboo.plan.PlanClassHelper.isChain; 27 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_ENABLED; 28 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_EXECUTABLE; 29 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_FAILED_ONLY; 30 | import static java.lang.Boolean.TRUE; 31 | import static java.util.Optional.ofNullable; 32 | import static org.apache.commons.lang3.StringUtils.isEmpty; 33 | 34 | public class AllureBuildConfigurator extends BaseConfigurablePlugin 35 | implements MiscellaneousPlanConfigurationPlugin { 36 | 37 | private final BambooExecutablesManager executablesManager; 38 | private final AllureSettingsManager settingsManager; 39 | 40 | public AllureBuildConfigurator(final BambooExecutablesManager executablesManager, 41 | final AllureSettingsManager settingsManager, 42 | final TemplateRenderer templateRenderer) { 43 | this.executablesManager = executablesManager; 44 | this.settingsManager = settingsManager; 45 | this.setTemplateRenderer(templateRenderer); 46 | } 47 | 48 | @Override 49 | public boolean isApplicableTo(final @NotNull ImmutablePlan plan) { 50 | return isChain(plan); 51 | } 52 | 53 | @NotNull 54 | @Override 55 | public ErrorCollection validate(final @NotNull BuildConfiguration buildConfiguration) { 56 | final ErrorCollection collection = super.validate(buildConfiguration); 57 | if (buildConfiguration.getBoolean(ALLURE_CONFIG_ENABLED) 58 | && isEmpty(buildConfiguration.getString(ALLURE_CONFIG_EXECUTABLE))) { 59 | collection.addError(ALLURE_CONFIG_EXECUTABLE, "Cannot be empty!"); 60 | } 61 | return collection; 62 | } 63 | 64 | @Override 65 | public void prepareConfigObject(final @NotNull BuildConfiguration buildConfiguration) { 66 | super.prepareConfigObject(buildConfiguration); 67 | if (buildConfiguration.getProperty(ALLURE_CONFIG_ENABLED) == null) { 68 | ofNullable(settingsManager).map(AllureSettingsManager::getSettings).ifPresent(settings -> 69 | buildConfiguration.setProperty(ALLURE_CONFIG_ENABLED, settings.isEnabledByDefault())); 70 | } 71 | if (buildConfiguration.getProperty(ALLURE_CONFIG_FAILED_ONLY) == null) { 72 | buildConfiguration.setProperty(ALLURE_CONFIG_FAILED_ONLY, TRUE); 73 | } 74 | if (buildConfiguration.getProperty(ALLURE_CONFIG_EXECUTABLE) == null) { 75 | ofNullable(executablesManager).flatMap(BambooExecutablesManager::getDefaultAllureExecutable) 76 | .ifPresent(executable -> buildConfiguration.setProperty(ALLURE_CONFIG_EXECUTABLE, executable)); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureBuildResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import java.io.Serializable; 19 | import java.util.Map; 20 | 21 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_BUILD_REPORT_ARTIFACT_HANDLER; 22 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_BUILD_REPORT_FAILURE_DETAILS; 23 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_BUILD_REPORT_SUCCESS; 24 | import static java.lang.Boolean.parseBoolean; 25 | import static org.apache.commons.lang3.StringUtils.isEmpty; 26 | 27 | class AllureBuildResult implements Serializable { 28 | 29 | private static final long serialVersionUID = 1L; 30 | 31 | private final boolean success; 32 | private String artifactHandlerClass; 33 | private String failureDetails; 34 | 35 | AllureBuildResult(final boolean success) { 36 | this.success = success; 37 | } 38 | 39 | AllureBuildResult(final boolean success, 40 | final String failureDetails) { 41 | this.success = success; 42 | this.failureDetails = failureDetails; 43 | } 44 | 45 | static AllureBuildResult allureBuildResult(final boolean success, 46 | final String failureDetails) { 47 | return new AllureBuildResult(success, failureDetails); 48 | } 49 | 50 | static AllureBuildResult fromCustomData(final Map data) { 51 | final AllureBuildResult result = new AllureBuildResult(parseBoolean(data.get(ALLURE_BUILD_REPORT_SUCCESS))); 52 | result.setArtifactHandlerClass(data.get(ALLURE_BUILD_REPORT_ARTIFACT_HANDLER)); 53 | result.setFailureDetails(data.get(ALLURE_BUILD_REPORT_FAILURE_DETAILS)); 54 | return result; 55 | } 56 | 57 | void dumpToCustomData(final Map data) { 58 | data.put(ALLURE_BUILD_REPORT_ARTIFACT_HANDLER, artifactHandlerClass); 59 | data.put(ALLURE_BUILD_REPORT_SUCCESS, String.valueOf(success)); 60 | data.put(ALLURE_BUILD_REPORT_FAILURE_DETAILS, failureDetails); 61 | } 62 | 63 | AllureBuildResult withHandlerClass(final String artifactHandlerClass) { 64 | setArtifactHandlerClass(artifactHandlerClass); 65 | return this; 66 | } 67 | 68 | String getArtifactHandlerClass() { 69 | return artifactHandlerClass; 70 | } 71 | 72 | void setArtifactHandlerClass(final String artifactHandlerClass) { 73 | this.artifactHandlerClass = artifactHandlerClass; 74 | } 75 | 76 | boolean isSuccess() { 77 | return success; 78 | } 79 | 80 | String getFailureDetails() { 81 | return failureDetails; 82 | } 83 | 84 | void setFailureDetails(final String failureDetails) { 85 | this.failureDetails = failureDetails; 86 | } 87 | 88 | boolean hasInfo() { 89 | return !isEmpty(this.failureDetails) || !isEmpty(artifactHandlerClass); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureCommandLineSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import org.buildobjects.process.ProcBuilder; 19 | import org.jetbrains.annotations.NotNull; 20 | 21 | import java.io.File; 22 | import java.nio.file.Paths; 23 | import java.util.regex.Matcher; 24 | import java.util.regex.Pattern; 25 | 26 | import static java.lang.Integer.parseInt; 27 | import static java.util.concurrent.TimeUnit.MINUTES; 28 | import static org.apache.commons.lang3.SystemUtils.IS_OS_UNIX; 29 | import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS; 30 | 31 | public class AllureCommandLineSupport { 32 | 33 | private static final Pattern RESULT_TC_COUNT_REGEX 34 | = Pattern.compile(".+Found (\\d+) test cases.+", Pattern.DOTALL); 35 | private static final int GENERATE_TIMEOUT_MS = (int) MINUTES.toMillis(10); 36 | 37 | String runCommand(final String cmd, final String... args) { 38 | return new ProcBuilder(cmd) 39 | .withArgs(args).withTimeoutMillis(GENERATE_TIMEOUT_MS) 40 | .run().getOutputString(); 41 | } 42 | 43 | @NotNull 44 | AllureGenerateResult parseGenerateOutput(final String output) { 45 | boolean success = true; 46 | final Matcher matcher = RESULT_TC_COUNT_REGEX.matcher(output); 47 | if (matcher.matches()) { 48 | success = parseInt(matcher.group(1)) > 0; 49 | } 50 | return new AllureGenerateResult(output, success); 51 | } 52 | 53 | boolean isUnix() { 54 | return IS_OS_UNIX; 55 | } 56 | 57 | boolean isWindows() { 58 | return IS_OS_WINDOWS; 59 | } 60 | 61 | boolean hasCommand(final String command) { 62 | final File cmdFile = Paths.get(command).toFile(); 63 | // It needs to be sure that the command is a file 64 | return cmdFile.exists() && cmdFile.isFile(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | /** 19 | * The internal class with some constants needed to Allure plugin. 20 | */ 21 | final class AllureConstants { 22 | 23 | /** 24 | * The executable prefix. 25 | */ 26 | static final String ALLURE_EXECUTION_PREFIX = "system.builder.allure"; 27 | /** 28 | * The name of executable. 29 | */ 30 | static final String ALLURE_CONFIG_EXECUTABLE = "custom.allure.config.executable"; 31 | 32 | static final String ALLURE_BUILD_REPORT_SUCCESS = "custom.allure.build.report.success"; 33 | static final String ALLURE_BUILD_REPORT_ARTIFACT_HANDLER = "custom.allure.build.report.artifact.handler"; 34 | static final String ALLURE_BUILD_REPORT_FAILURE_DETAILS = "custom.allure.build.report.output"; 35 | static final String ALLURE_CONFIG_ENABLED = "custom.allure.config.enabled"; 36 | static final String ALLURE_CONFIG_FAILED_ONLY = "custom.allure.config.failed.only"; 37 | static final String ALLURE_CONFIG_ARTIFACT_NAME = "custom.allure.artifact.name"; 38 | static final String ALLURE_CONFIG_DOWNLOAD_ENABLED = "custom.allure.config.download.enabled"; 39 | static final String ALLURE_CONFIG_ENABLED_BY_DEFAULT = "custom.allure.config.enabled.default"; 40 | static final String ALLURE_CONFIG_DOWNLOAD_URL = "custom.allure.config.download.url"; 41 | static final String ALLURE_CONFIG_DOWNLOAD_CLI_URL = "custom.allure.config.download.cli.url"; 42 | static final String ALLURE_CONFIG_LOCAL_STORAGE = "custom.allure.config.local.storage"; 43 | 44 | // ALLURE CUSTOM LOGO 45 | static final String ALLURE_CONFIG_CUSTOM_LOGO_ENABLED = "custom.allure.config.logo.enabled"; 46 | static final String ALLURE_CONFIG_CUSTOM_LOGO_PATH = "custom.allure.logo.url"; 47 | 48 | // ALLURE CLEANUP OLD REPORTS 49 | static final String ALLURE_CONFIG_REPORTS_CLEANUP_ENABLED = "custom.allure.config.reports.cleanup.enabled"; 50 | static final String ALLURE_CONFIG_MAX_STORED_REPORTS_COUNT = "custom.allure.max.stored.reports.count"; 51 | 52 | private AllureConstants() { 53 | // do not instantiate 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import io.qameta.allure.bamboo.util.Downloader; 19 | import io.qameta.allure.bamboo.util.ZipUtil; 20 | import org.apache.commons.compress.archivers.ArchiveException; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | 24 | import java.io.File; 25 | import java.io.IOException; 26 | import java.net.MalformedURLException; 27 | import java.net.URL; 28 | import java.nio.file.Path; 29 | import java.nio.file.Paths; 30 | import java.util.Optional; 31 | 32 | import static java.nio.file.Files.createTempFile; 33 | import static javax.ws.rs.core.UriBuilder.fromPath; 34 | import static org.apache.commons.io.FileUtils.deleteQuietly; 35 | import static org.apache.commons.io.FileUtils.moveDirectory; 36 | 37 | public class AllureDownloader { 38 | 39 | private static final Logger LOGGER = LoggerFactory.getLogger(AllureDownloader.class); 40 | 41 | private final AllureSettingsManager settingsManager; 42 | 43 | public AllureDownloader(final AllureSettingsManager settingsManager) { 44 | this.settingsManager = settingsManager; 45 | } 46 | 47 | Optional downloadAndExtractAllureTo(final String allureHomeDir, 48 | final String version) { 49 | return downloadAllure(version).map(zipFilePath -> { 50 | try { 51 | LOGGER.info("Extracting file {} to {}...", zipFilePath, allureHomeDir); 52 | final String extractedDirName = "allure-" + version; 53 | final File homeDir = new File(allureHomeDir); 54 | final Path extractDir = zipFilePath.getParent(); 55 | ZipUtil.unzip(zipFilePath, extractDir.toString()); 56 | 57 | if (homeDir.exists()) { 58 | LOGGER.info("Directory {} already exists, removing it..", homeDir); 59 | deleteQuietly(homeDir); 60 | } 61 | moveDirectory(extractDir.resolve(extractedDirName).toFile(), homeDir); 62 | return Paths.get(allureHomeDir); 63 | } catch (ArchiveException | IOException e) { 64 | LOGGER.error("Failed to download and extract Allure of version {} to dir {}", 65 | version, allureHomeDir, e); 66 | return null; 67 | } finally { 68 | deleteQuietly(zipFilePath.toFile()); 69 | } 70 | }); 71 | } 72 | 73 | private Optional downloadAllure(final String version) { 74 | try { 75 | final URL[] urls = buildAllureDownloadUrls(version); 76 | for (URL url : urls) { 77 | try { 78 | final Path downloadToFile = createTempFile("allure", ".zip"); 79 | LOGGER.info("Downloading allure.zip from {} to {}", url, downloadToFile); 80 | return Downloader.download(url, downloadToFile); 81 | } catch (Exception e) { 82 | LOGGER.warn("Failed to download from {}. Root cause : {}.", url, e.toString()); 83 | } 84 | } 85 | } catch (Exception e) { 86 | LOGGER.error("Failed to download Allure of version {}", version, e); 87 | } 88 | return Optional.empty(); 89 | } 90 | 91 | private URL[] buildAllureDownloadUrls(final String version) throws MalformedURLException { 92 | final URL gitUrl = fromPath(settingsManager.getSettings().getDownloadBaseUrl()) 93 | .path(String.format("%s/allure-%s.zip", version, version)) 94 | .build().toURL(); 95 | final URL mavenUrl = fromPath(settingsManager.getSettings().getDownloadCliBaseUrl()) 96 | .path(String.format("allure-commandline/%s/allure-commandline-%s.zip", version, version)) 97 | .build().toURL(); 98 | return new URL[]{gitUrl, mavenUrl}; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureExecutable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import com.fasterxml.jackson.databind.ObjectMapper; 19 | import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; 20 | import io.qameta.allure.bamboo.info.AllurePlugins; 21 | import io.qameta.allure.bamboo.util.FileStringReplacer; 22 | import org.apache.commons.io.FileUtils; 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | 26 | import javax.annotation.Nonnull; 27 | import java.io.File; 28 | import java.io.IOException; 29 | import java.nio.file.Path; 30 | import java.util.Collection; 31 | import java.util.LinkedList; 32 | import java.util.regex.Pattern; 33 | 34 | import static java.util.Arrays.asList; 35 | import static java.util.stream.Collectors.toList; 36 | 37 | class AllureExecutable { 38 | 39 | private static final Logger LOGGER = LoggerFactory.getLogger(AllureExecutable.class); 40 | private static final String BASH_CMD = "/bin/bash"; 41 | private final Path cmdPath; 42 | private final AllureCommandLineSupport cmdLine; 43 | 44 | AllureExecutable(final Path cmdPath, 45 | final AllureCommandLineSupport commandLine) { 46 | this.cmdPath = cmdPath; 47 | this.cmdLine = commandLine; 48 | } 49 | 50 | @Nonnull 51 | AllureGenerateResult generate(final Collection sourceDirs, 52 | final Path targetDir) { 53 | try { 54 | final LinkedList args = new LinkedList<>(asList("generate", "-o", targetDir.toString())); 55 | args.addAll(sourceDirs.stream().map(Path::toString).collect(toList())); 56 | final String output; 57 | if (cmdLine.isUnix() && cmdLine.hasCommand(BASH_CMD)) { 58 | args.addFirst(cmdPath.toString()); 59 | output = cmdLine.runCommand(BASH_CMD, args.toArray(new String[0])); 60 | } else { 61 | output = cmdLine.runCommand(cmdPath.toString(), args.toArray(new String[0])); 62 | } 63 | LOGGER.info(output); 64 | return cmdLine.parseGenerateOutput(output); 65 | } catch (Exception e) { 66 | throw new AllurePluginException("Failed to generate allure report", e); 67 | } 68 | } 69 | 70 | public void setCustomLogo(final String logoUrl) { 71 | final String pluginName = "custom-logo-plugin"; 72 | final String allureConfigFileName = "allure.yml"; 73 | final String cssFileName = "styles.css"; 74 | 75 | final Path rootPath = this.cmdPath.getParent().getParent(); 76 | final Path configFolder = rootPath.resolve("config"); 77 | final Path logoPluginFolder = rootPath.resolve("plugins").resolve(pluginName).resolve("static"); 78 | 79 | /// Editing Yaml to add plugin 80 | final ObjectMapper objectMapper = new YAMLMapper(); 81 | try { 82 | final File configFile = configFolder.resolve(allureConfigFileName).toFile(); 83 | final AllurePlugins ap = objectMapper.readValue(configFile, AllurePlugins.class); 84 | //Saving the file only if it necessary 85 | if (ap.registerPlugin(pluginName)) { 86 | objectMapper.writeValue(configFile, ap); 87 | } 88 | //Setting new Logo 89 | FileStringReplacer.replaceInFile(logoPluginFolder.resolve(cssFileName), 90 | Pattern.compile("url\\('.+'\\)", 91 | Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.COMMENTS), 92 | "url(" + logoUrl + ")" 93 | ); 94 | 95 | // aligning logo to center 96 | FileStringReplacer.replaceInFile(logoPluginFolder.resolve(cssFileName), 97 | Pattern.compile("(?<=\\s )left", 98 | Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.COMMENTS), 99 | "center" 100 | ); 101 | // fit logo to area 102 | FileStringReplacer.replaceInFile(logoPluginFolder.resolve(cssFileName), 103 | Pattern.compile("(?<=\\s )!important;", 104 | Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.COMMENTS), 105 | "!important; background-size: contain !important;" 106 | ); 107 | // removing margin 108 | FileStringReplacer.replaceInFile(logoPluginFolder.resolve(cssFileName), 109 | Pattern.compile("10px", 110 | Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.COMMENTS), 111 | "0px" 112 | ); 113 | 114 | } catch (Exception e) { 115 | LOGGER.error("Cannot set custom logo", e); 116 | throw new AllurePluginException("Unexpected error", e); 117 | } 118 | } 119 | 120 | public AllureExecutable getTempCopy(final Path copyPath) throws IOException { 121 | final String binary = this.cmdPath.getFileName().toString(); 122 | final String binFolder = this.cmdPath.getParent().getFileName().toString(); 123 | final Path rootPath = this.cmdPath.getParent().getParent(); 124 | final String rootFolderName = rootPath.getFileName().toString(); 125 | FileUtils.copyDirectoryToDirectory(rootPath.toFile(), copyPath.toFile()); 126 | 127 | return new AllureExecutable(copyPath 128 | .resolve(rootFolderName) 129 | .resolve(binFolder) 130 | .resolve(binary), 131 | this.cmdLine 132 | ); 133 | } 134 | 135 | Path getCmdPath() { 136 | return cmdPath; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureExecutableProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import java.nio.file.Path; 23 | import java.nio.file.Paths; 24 | import java.util.Optional; 25 | import java.util.regex.Matcher; 26 | import java.util.regex.Pattern; 27 | 28 | import static java.util.Objects.requireNonNull; 29 | import static java.util.regex.Pattern.compile; 30 | 31 | public class AllureExecutableProvider { 32 | 33 | private static final Logger LOGGER = LoggerFactory.getLogger(AllureExecutableProvider.class); 34 | static final String DEFAULT_VERSION = "2.30.0"; 35 | static final String DEFAULT_PATH = "/tmp/allure/2.30.0"; 36 | static final String BIN = "bin"; 37 | private static final Pattern EXEC_NAME_PATTERN = compile("[^\\d]*(\\d[0-9\\.]{2,}[a-zA-Z0-9\\-]*)$"); 38 | 39 | private final BambooExecutablesManager bambooExecutablesManager; 40 | private final AllureDownloader allureDownloader; 41 | private final AllureCommandLineSupport cmdLine; 42 | 43 | public AllureExecutableProvider(final BambooExecutablesManager bambooExecutablesManager, 44 | final AllureDownloader allureDownloader, 45 | final AllureCommandLineSupport allureCommandLineSupport) { 46 | this.bambooExecutablesManager = requireNonNull(bambooExecutablesManager); 47 | this.allureDownloader = requireNonNull(allureDownloader); 48 | this.cmdLine = requireNonNull(allureCommandLineSupport); 49 | } 50 | 51 | Optional provide(final boolean isDownloadEnabled, final String executableName) { 52 | return bambooExecutablesManager.getExecutableByName(executableName) 53 | .map(allureHomeDir -> { 54 | LOGGER.info("Found allure executable by name '{}': '{}'", executableName, allureHomeDir); 55 | final Path cmdPath = Paths.get(allureHomeDir, BIN, getAllureExecutableName()); 56 | final AllureExecutable executable = new AllureExecutable(cmdPath, cmdLine); 57 | LOGGER.info("Checking the existence of the command path for executable '{}': '{}'", 58 | executableName, cmdPath); 59 | final boolean commandExists = cmdLine.hasCommand(cmdPath.toString()); 60 | LOGGER.info("System has command for executable '{}': {}, downloadEnabled={}", 61 | executableName, commandExists, isDownloadEnabled); 62 | if (commandExists) { 63 | return executable; 64 | } else if (isDownloadEnabled) { 65 | final Matcher nameMatcher = EXEC_NAME_PATTERN.matcher(executableName); 66 | return allureDownloader.downloadAndExtractAllureTo(allureHomeDir, 67 | nameMatcher.matches() ? nameMatcher.group(1) : DEFAULT_VERSION) 68 | .map(path -> executable).orElse(null); 69 | } 70 | return null; 71 | }); 72 | } 73 | 74 | Optional provide(final AllureGlobalConfig globalConfig, 75 | final String executableName) { 76 | return provide(globalConfig.isDownloadEnabled(), executableName); 77 | } 78 | 79 | @NotNull 80 | private String getAllureExecutableName() { 81 | return (cmdLine.isWindows()) ? "allure.bat" : "allure"; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureGenerateResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | class AllureGenerateResult { 19 | 20 | private final String output; 21 | private final boolean containsTestcases; 22 | 23 | AllureGenerateResult(final String output, 24 | final boolean containsTestCases) { 25 | this.output = output; 26 | this.containsTestcases = containsTestCases; 27 | } 28 | 29 | String getOutput() { 30 | return output; 31 | } 32 | 33 | boolean isContainsTestCases() { 34 | return containsTestcases; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureGlobalConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import org.apache.commons.lang3.StringUtils; 19 | 20 | import java.io.File; 21 | import java.io.Serializable; 22 | 23 | import static java.lang.Boolean.FALSE; 24 | import static java.lang.Boolean.TRUE; 25 | import static java.lang.Boolean.parseBoolean; 26 | import static org.apache.commons.lang3.SystemUtils.getJavaIoTmpDir; 27 | 28 | public class AllureGlobalConfig implements Serializable { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | private static final String DEFAULT_DOWNLOAD_BASE_URL 33 | = "https://github.com/allure-framework/allure2/releases/download/"; 34 | private static final String DEFAULT_CLI_BASE_URL 35 | = "https://repo.maven.apache.org/maven2/io/qameta/allure/"; 36 | public static final String DEFAULT_LOCAL_STORAGE_PATH 37 | = new File(getJavaIoTmpDir(), "allure-reports").getPath(); 38 | private final boolean downloadEnabled; 39 | private final boolean customLogoEnabled; 40 | private final boolean enabledByDefault; 41 | private final boolean enabledReportsCleanup; 42 | private final String localStoragePath; 43 | private final String downloadBaseUrl; 44 | private final String downloadCliBaseUrl; 45 | 46 | public AllureGlobalConfig() { 47 | this(TRUE.toString(), 48 | FALSE.toString(), 49 | DEFAULT_DOWNLOAD_BASE_URL, 50 | DEFAULT_LOCAL_STORAGE_PATH, 51 | DEFAULT_CLI_BASE_URL, 52 | TRUE.toString(), 53 | FALSE.toString()); 54 | } 55 | 56 | public AllureGlobalConfig(final String downloadEnabled, 57 | final String enabledByDefault, 58 | final String downloadBaseUrl, 59 | final String localStoragePath, 60 | final String cmdLineUrl, 61 | final String customLogoEnable, 62 | final String enabledReportsCleanup) { 63 | this.downloadEnabled = StringUtils.isBlank(downloadEnabled) 64 | ? TRUE : parseBoolean(downloadEnabled); 65 | this.enabledByDefault = StringUtils.isBlank(enabledByDefault) 66 | ? FALSE : parseBoolean(enabledByDefault); 67 | this.downloadBaseUrl = StringUtils.isBlank(downloadBaseUrl) 68 | ? DEFAULT_DOWNLOAD_BASE_URL : downloadBaseUrl; 69 | this.downloadCliBaseUrl = StringUtils.isBlank(cmdLineUrl) 70 | ? DEFAULT_CLI_BASE_URL : cmdLineUrl; 71 | this.localStoragePath = StringUtils.isBlank(localStoragePath) 72 | ? DEFAULT_LOCAL_STORAGE_PATH : localStoragePath; 73 | this.customLogoEnabled = StringUtils.isBlank(customLogoEnable) 74 | ? TRUE : parseBoolean(customLogoEnable); 75 | this.enabledReportsCleanup = StringUtils.isBlank(enabledReportsCleanup) 76 | ? FALSE : parseBoolean(enabledReportsCleanup); 77 | } 78 | 79 | public AllureGlobalConfig(final boolean downloadEnabled, 80 | final boolean enabledByDefault, 81 | final String downloadBaseUrl, 82 | final String localStoragePath, 83 | final boolean customLogoEnable, 84 | final boolean enabledReportsCleanup) { 85 | this.downloadEnabled = downloadEnabled; 86 | this.enabledByDefault = enabledByDefault; 87 | this.downloadBaseUrl = StringUtils.isBlank(downloadBaseUrl) 88 | ? DEFAULT_DOWNLOAD_BASE_URL : downloadBaseUrl; 89 | this.downloadCliBaseUrl = DEFAULT_CLI_BASE_URL; 90 | this.localStoragePath = StringUtils.isBlank(localStoragePath) 91 | ? DEFAULT_LOCAL_STORAGE_PATH : localStoragePath; 92 | this.customLogoEnabled = customLogoEnable; 93 | this.enabledReportsCleanup = enabledReportsCleanup; 94 | } 95 | 96 | boolean isDownloadEnabled() { 97 | return downloadEnabled; 98 | } 99 | 100 | boolean isEnabledByDefault() { 101 | return enabledByDefault; 102 | } 103 | 104 | boolean isCustomLogoEnabled() { 105 | return customLogoEnabled; 106 | } 107 | 108 | boolean isEnabledReportsCleanup() { 109 | return enabledReportsCleanup; 110 | } 111 | 112 | String getDownloadBaseUrl() { 113 | return downloadBaseUrl; 114 | } 115 | 116 | String getDownloadCliBaseUrl() { 117 | return downloadCliBaseUrl; 118 | } 119 | 120 | public String getLocalStoragePath() { 121 | return localStoragePath; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllurePluginException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | public class AllurePluginException extends RuntimeException { 19 | 20 | public AllurePluginException(final String message) { 21 | super(message); 22 | } 23 | 24 | public AllurePluginException(final String message, final Throwable throwable) { 25 | super(message, throwable); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllurePluginInstallTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import com.atlassian.sal.api.message.Message; 19 | import com.atlassian.sal.api.upgrade.PluginUpgradeTask; 20 | 21 | import java.util.Collection; 22 | import java.util.Collections; 23 | 24 | public class AllurePluginInstallTask implements PluginUpgradeTask { 25 | 26 | private final BambooExecutablesManager executablesManager; 27 | 28 | public AllurePluginInstallTask(final BambooExecutablesManager executablesManager) { 29 | this.executablesManager = executablesManager; 30 | } 31 | 32 | @Override 33 | public int getBuildNumber() { 34 | return 1; 35 | } 36 | 37 | @Override 38 | public String getShortDescription() { 39 | return "Installs Allure Plugin first time"; 40 | } 41 | 42 | @Override 43 | public Collection doUpgrade() throws Exception { 44 | if (executablesManager.getAllureExecutables().isEmpty()) { 45 | executablesManager.addDefaultAllureExecutableCapability(); 46 | } 47 | return Collections.emptySet(); 48 | } 49 | 50 | @Override 51 | public String getPluginKey() { 52 | return "io.qameta.allure.allure-bamboo"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureReportServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import com.atlassian.annotations.security.UnrestrictedAccess; 19 | import com.atlassian.bamboo.plan.PlanResultKey; 20 | import com.atlassian.bamboo.resultsummary.ResultsSummary; 21 | import com.atlassian.bamboo.resultsummary.ResultsSummaryManager; 22 | import org.apache.commons.io.IOUtils; 23 | import org.apache.commons.lang3.StringUtils; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import javax.servlet.http.HttpServlet; 28 | import javax.servlet.http.HttpServletRequest; 29 | import javax.servlet.http.HttpServletResponse; 30 | import java.io.IOException; 31 | import java.io.InputStream; 32 | import java.net.URI; 33 | import java.net.URISyntaxException; 34 | import java.net.URL; 35 | import java.nio.file.Files; 36 | import java.nio.file.Paths; 37 | import java.util.Optional; 38 | import java.util.regex.Matcher; 39 | import java.util.regex.Pattern; 40 | import java.util.stream.Stream; 41 | 42 | import static com.atlassian.bamboo.plan.PlanKeys.getPlanResultKey; 43 | import static io.qameta.allure.bamboo.AllureBuildResult.fromCustomData; 44 | import static java.lang.Integer.parseInt; 45 | 46 | @UnrestrictedAccess 47 | public class AllureReportServlet extends HttpServlet { 48 | 49 | private static final Pattern URL_PATTERN = Pattern 50 | .compile(".*/plugins/servlet/allure/report/([^/]{2,})/([^/]+)/?(.*)"); 51 | private static final Logger LOGGER = LoggerFactory.getLogger(AllureReportServlet.class); 52 | private static final String CONTENT_DISPOSITION = "Content-Disposition"; 53 | private static final String CONTENT_TYPE = "Content-Type"; 54 | private static final String FAILED_TO_SEND_FILE_OF_ALLURE_REPORT = "Failed to send file {} of Allure Report "; 55 | private static final String X_FRAME_OPTIONS = "X-Frame-Options"; 56 | 57 | private final transient AllureArtifactsManager artifactsManager; 58 | private final ResultsSummaryManager resultsSummaryManager; 59 | 60 | public AllureReportServlet(final AllureArtifactsManager artifactsManager, 61 | final ResultsSummaryManager resultsSummaryManager) { 62 | this.artifactsManager = artifactsManager; 63 | this.resultsSummaryManager = resultsSummaryManager; 64 | } 65 | 66 | public static Pattern getUrlPattern() { 67 | return URL_PATTERN; 68 | } 69 | 70 | @Override 71 | public void doGet(final HttpServletRequest request, 72 | final HttpServletResponse response) { 73 | getArtifactUrl(request, response).ifPresent(file -> { 74 | try (InputStream inputStream = new URL(file).openStream()) { 75 | setResponseHeaders(response, file); 76 | IOUtils.copy(inputStream, response.getOutputStream()); 77 | } catch (IOException e) { 78 | LOGGER.error(FAILED_TO_SEND_FILE_OF_ALLURE_REPORT, file); 79 | } 80 | }); 81 | } 82 | 83 | @Override 84 | public void doHead(final HttpServletRequest request, 85 | final HttpServletResponse response) { 86 | getArtifactUrl(request, response).ifPresent(file -> { 87 | try (InputStream inputStream = new URL(file).openStream()) { 88 | setResponseHeaders(response, file); 89 | } catch (IOException e) { 90 | response.setStatus(HttpServletResponse.SC_NOT_FOUND); 91 | LOGGER.error(FAILED_TO_SEND_FILE_OF_ALLURE_REPORT, file); 92 | } 93 | }); 94 | } 95 | 96 | private void setResponseHeaders(final HttpServletResponse response, 97 | final String fileUrl) throws IOException { 98 | 99 | try { 100 | response.setStatus(HttpServletResponse.SC_OK); 101 | final URI file = new URL(fileUrl).toURI(); 102 | final String mimeType = Optional.ofNullable(getServletContext().getMimeType(fileUrl)) 103 | .orElse(Files.probeContentType(Paths.get(file.getPath())) 104 | ); 105 | final String charsetPostfix = Stream.of("application", "text") 106 | .anyMatch(mimeType::contains) ? ";charset=utf-8" : ""; 107 | response.setHeader(CONTENT_TYPE, mimeType + charsetPostfix); 108 | response.setHeader(CONTENT_DISPOSITION, 109 | "inline; filename=\"" + Paths.get(file.getPath()).getFileName().toString() + "\""); 110 | 111 | } catch (URISyntaxException e) { 112 | // should never happen 113 | throw new AllurePluginException("Unexpected error", e); 114 | } 115 | } 116 | 117 | private Optional getArtifactUrl(final HttpServletRequest request, 118 | final HttpServletResponse response) { 119 | final Matcher matcher = URL_PATTERN.matcher(request.getRequestURI()); 120 | try { 121 | if (matcher.matches()) { 122 | if (StringUtils.isBlank(response.getHeader(X_FRAME_OPTIONS))) { 123 | response.setHeader(X_FRAME_OPTIONS, "ALLOWALL"); 124 | } 125 | final String planKey = matcher.group(1); 126 | final String buildNumber = matcher.group(2); 127 | final String filePath = matcher.group(3); 128 | if (wasUploadSuccess(response, planKey, parseInt(buildNumber))) { 129 | return artifactsManager.getArtifactUrl(planKey, buildNumber, filePath); 130 | } 131 | } else { 132 | LOGGER.info("Path {} does not match pattern", request.getRequestURI()); 133 | } 134 | } catch (Exception e) { 135 | LOGGER.error("There is a problem to parse request uri: {}", request.getRequestURI(), e); 136 | } 137 | return Optional.empty(); 138 | } 139 | 140 | private boolean wasUploadSuccess(final HttpServletResponse response, 141 | final String planKey, 142 | final int buildNumber) { 143 | final PlanResultKey planResultKey = getPlanResultKey(planKey, buildNumber); 144 | final ResultsSummary results = resultsSummaryManager.getResultsSummary(planResultKey); 145 | if (results != null) { 146 | final AllureBuildResult uploadResult = fromCustomData(results.getCustomBuildData()); 147 | if (!uploadResult.isSuccess()) { 148 | uploadResultWasNotSuccess(response, uploadResult); 149 | return false; 150 | } 151 | return true; 152 | } 153 | return false; 154 | } 155 | 156 | 157 | private void uploadResultWasNotSuccess(final HttpServletResponse response, 158 | final AllureBuildResult uploadResult) { 159 | final String errorMessage = StringUtils.isEmpty(uploadResult.getFailureDetails()) 160 | ? "Unknown error has occurred during Allure Build. Please refer the server logs for details." 161 | : "Something went wrong with Allure Report generation. Here are some details: \n" 162 | + uploadResult.getFailureDetails(); 163 | try { 164 | response.setHeader(CONTENT_TYPE, "text/plain"); 165 | response.setHeader("Content-Length", String.valueOf(errorMessage.length())); 166 | response.setHeader(CONTENT_DISPOSITION, "inline"); 167 | response.getWriter().write(errorMessage); 168 | } catch (IOException e) { 169 | LOGGER.error("Failed to render error of Allure Report build ", e); 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureReportTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import com.atlassian.bamboo.build.logger.BuildLogger; 19 | import com.atlassian.bamboo.task.TaskContext; 20 | import com.atlassian.bamboo.task.TaskResult; 21 | import com.atlassian.bamboo.task.TaskResultBuilder; 22 | import com.atlassian.bamboo.task.TaskType; 23 | import org.jetbrains.annotations.NotNull; 24 | 25 | /** 26 | * Executes report generation. 27 | */ 28 | public class AllureReportTask implements TaskType { 29 | 30 | @NotNull 31 | @Override 32 | public TaskResult execute(final @NotNull TaskContext taskContext) { 33 | final BuildLogger buildLogger = taskContext.getBuildLogger(); 34 | buildLogger.addBuildLogEntry("Allure Report Task: This allure report task is now a sham." 35 | + " It does nothing, so please use" 36 | + " the suggested way of configuration as listed in the Allure docs! "); 37 | return TaskResultBuilder.newBuilder(taskContext).success().build(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureSettingsManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import com.atlassian.sal.api.pluginsettings.PluginSettings; 19 | import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; 20 | 21 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_CUSTOM_LOGO_ENABLED; 22 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_DOWNLOAD_CLI_URL; 23 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_DOWNLOAD_ENABLED; 24 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_DOWNLOAD_URL; 25 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_ENABLED_BY_DEFAULT; 26 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_LOCAL_STORAGE; 27 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_CONFIG_REPORTS_CLEANUP_ENABLED; 28 | 29 | public class AllureSettingsManager { 30 | 31 | private final PluginSettings settings; 32 | 33 | public AllureSettingsManager(final PluginSettingsFactory settingsFactory) { 34 | this.settings = settingsFactory.createGlobalSettings(); 35 | } 36 | 37 | public AllureGlobalConfig getSettings() { 38 | final String downloadEnabled = (String) settings.get(ALLURE_CONFIG_DOWNLOAD_ENABLED); 39 | final String customLogoEnabled = (String) settings.get(ALLURE_CONFIG_CUSTOM_LOGO_ENABLED); 40 | final String enableByDefault = (String) settings.get(ALLURE_CONFIG_ENABLED_BY_DEFAULT); 41 | final String downloadBaseUrl = (String) settings.get(ALLURE_CONFIG_DOWNLOAD_URL); 42 | final String downloadCliBaseUrl = (String) settings.get(ALLURE_CONFIG_DOWNLOAD_CLI_URL); 43 | final String localStorage = (String) settings.get(ALLURE_CONFIG_LOCAL_STORAGE); 44 | final String enabledReportsCleanup = (String) settings.get(ALLURE_CONFIG_REPORTS_CLEANUP_ENABLED); 45 | 46 | return new AllureGlobalConfig( 47 | downloadEnabled, 48 | enableByDefault, 49 | downloadBaseUrl, 50 | localStorage, 51 | downloadCliBaseUrl, 52 | customLogoEnabled, 53 | enabledReportsCleanup); 54 | } 55 | 56 | public void saveSettings(final AllureGlobalConfig config) { 57 | settings.put(ALLURE_CONFIG_DOWNLOAD_ENABLED, String.valueOf(config.isDownloadEnabled())); 58 | settings.put(ALLURE_CONFIG_CUSTOM_LOGO_ENABLED, String.valueOf(config.isCustomLogoEnabled())); 59 | settings.put(ALLURE_CONFIG_DOWNLOAD_URL, String.valueOf(config.getDownloadBaseUrl())); 60 | settings.put(ALLURE_CONFIG_LOCAL_STORAGE, String.valueOf(config.getLocalStoragePath())); 61 | settings.put(ALLURE_CONFIG_ENABLED_BY_DEFAULT, String.valueOf(config.isEnabledByDefault())); 62 | settings.put(ALLURE_CONFIG_REPORTS_CLEANUP_ENABLED, String.valueOf(config.isEnabledReportsCleanup())); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/AllureViewReportCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import com.atlassian.bamboo.plan.PlanKeys; 19 | import com.atlassian.bamboo.resultsummary.ResultsSummary; 20 | import com.atlassian.bamboo.resultsummary.ResultsSummaryManager; 21 | import com.atlassian.plugin.web.Condition; 22 | import org.apache.commons.lang3.StringUtils; 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | 26 | import java.util.Map; 27 | 28 | public class AllureViewReportCondition implements Condition { 29 | 30 | private static final Logger LOGGER = LoggerFactory.getLogger(AllureViewReportCondition.class); 31 | 32 | private final ResultsSummaryManager resultsSummaryManager; 33 | 34 | public AllureViewReportCondition(final ResultsSummaryManager resultsSummaryManager) { 35 | this.resultsSummaryManager = resultsSummaryManager; 36 | } 37 | 38 | @Override 39 | public void init(final Map context) { 40 | // does nothing 41 | } 42 | 43 | @Override 44 | public boolean shouldDisplay(final Map context) { 45 | final String buildKey = StringUtils.defaultIfBlank( 46 | (String) context.get("planKey"), 47 | (String) context.get("buildKey") 48 | ); 49 | final String buildNumberString = (String) context.get("buildNumber"); 50 | if (StringUtils.isBlank(buildKey) || StringUtils.isBlank(buildNumberString)) { 51 | return false; 52 | } 53 | try { 54 | final int buildNumber = Integer.parseInt(buildNumberString); 55 | final ResultsSummary resultsSummary = this.resultsSummaryManager 56 | .getResultsSummary(PlanKeys.getPlanResultKey(buildKey, buildNumber)); 57 | if (resultsSummary != null) { 58 | final AllureBuildResult buildResult = AllureBuildResult 59 | .fromCustomData(resultsSummary.getCustomBuildData()); 60 | return buildResult.hasInfo() && (resultsSummary.isFinished() || resultsSummary.isNotBuilt()); 61 | } 62 | } catch (Exception e) { 63 | LOGGER.error("Failed to evaluate condition", e); 64 | } 65 | return false; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/BambooExecutablesManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import com.atlassian.bamboo.v2.build.agent.capability.Capability; 19 | import com.atlassian.bamboo.v2.build.agent.capability.CapabilityDefaultsHelper; 20 | import com.atlassian.bamboo.v2.build.agent.capability.CapabilityImpl; 21 | import com.atlassian.bamboo.v2.build.agent.capability.CapabilitySetManager; 22 | import com.atlassian.bamboo.v2.build.agent.capability.LocalCapabilitySet; 23 | import org.jetbrains.annotations.NotNull; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import java.util.Collection; 28 | import java.util.List; 29 | import java.util.Objects; 30 | import java.util.Optional; 31 | 32 | import static com.atlassian.bamboo.v2.build.agent.capability.CapabilitySetManagerUtils.getSharedCapabilitySet; 33 | import static io.qameta.allure.bamboo.AllureConstants.ALLURE_EXECUTION_PREFIX; 34 | import static io.qameta.allure.bamboo.AllureExecutableProvider.DEFAULT_PATH; 35 | import static io.qameta.allure.bamboo.AllureExecutableProvider.DEFAULT_VERSION; 36 | import static java.lang.String.format; 37 | import static java.util.stream.Collectors.toList; 38 | 39 | public class BambooExecutablesManager { 40 | 41 | private static final Logger LOGGER = LoggerFactory.getLogger(BambooExecutablesManager.class); 42 | private final CapabilitySetManager capabilitySetManager; 43 | 44 | public BambooExecutablesManager(final CapabilitySetManager capabilitySetManager) { 45 | this.capabilitySetManager = capabilitySetManager; 46 | } 47 | 48 | List getAllureExecutables() { 49 | return getCapabilityKeys().stream() 50 | .filter(capKey -> capKey.toLowerCase().startsWith(ALLURE_EXECUTION_PREFIX.toLowerCase())) 51 | .map(this::getCapability) 52 | .filter(Optional::isPresent) 53 | .map(Optional::get) 54 | .map(Capability::getKey) 55 | .map(cap -> cap.replaceFirst(ALLURE_EXECUTION_PREFIX + ".", "")) 56 | .collect(toList()); 57 | } 58 | 59 | Optional getDefaultAllureExecutable() { 60 | return getAllureExecutables().stream().findAny(); 61 | } 62 | 63 | Optional getExecutableByName(final String executableName) { 64 | LOGGER.debug("Trying to find a capability by executable name '{}'", executableName); 65 | return getCapabilityKeys().stream() 66 | .filter(capKey -> { 67 | final String[] strings = capKey.split("\\.", 4); 68 | final boolean matches = strings.length == 4 && executableName.equals(strings[3]); 69 | LOGGER.debug("Checking key '{}' to matches executable name '{}'={}...", 70 | capKey, executableName, matches); 71 | return matches; 72 | }) 73 | .findFirst() 74 | .map(this::getCapability) 75 | .filter(Optional::isPresent) 76 | .map(Optional::get) 77 | .map(Capability::getValue); 78 | } 79 | 80 | void addDefaultAllureExecutableCapability() { 81 | Optional.ofNullable(getSharedCapabilitySet(capabilitySetManager, LocalCapabilitySet.class)) 82 | .ifPresent(capSet -> { 83 | final String key = format("%s.allure-%s", ALLURE_EXECUTION_PREFIX, DEFAULT_VERSION); 84 | final CapabilityImpl capability = new CapabilityImpl(key, DEFAULT_PATH); 85 | capSet.addCapability(capability); 86 | capabilitySetManager.saveCapabilitySet(capSet); 87 | }); 88 | } 89 | 90 | @NotNull 91 | private Collection getCapabilityKeys() { 92 | return capabilitySetManager 93 | .getSystemCapabilityKeys(CapabilityDefaultsHelper.CAPABILITY_BUILDER_TYPE, false); 94 | } 95 | 96 | private Optional getCapability(final String capabilityKey) { 97 | return Optional.ofNullable( 98 | Objects.requireNonNull(capabilitySetManager.getSharedLocalCapabilitySet()) 99 | .getCapability(capabilityKey) 100 | ); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/ConfigureAllureReportAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import com.atlassian.bamboo.configuration.GlobalAdminAction; 19 | import com.atlassian.struts.Preparable; 20 | import org.apache.commons.lang3.StringUtils; 21 | 22 | public class ConfigureAllureReportAction extends GlobalAdminAction implements Preparable { 23 | 24 | private final transient AllureSettingsManager settingsManager; 25 | private AllureGlobalConfig config; 26 | 27 | private boolean downloadEnabled; 28 | private boolean customLogoEnabled; 29 | private boolean enabledByDefault; 30 | private boolean enabledReportsCleanup; 31 | private String localStoragePath; 32 | private String downloadBaseUrl; 33 | 34 | public ConfigureAllureReportAction(final AllureSettingsManager settingsManager) { 35 | this.settingsManager = settingsManager; 36 | } 37 | 38 | @Override 39 | public String execute() { 40 | final AllureGlobalConfig newConfig = new AllureGlobalConfig( 41 | downloadEnabled, 42 | enabledByDefault, 43 | downloadBaseUrl, 44 | localStoragePath, 45 | customLogoEnabled, 46 | enabledReportsCleanup 47 | ); 48 | settingsManager.saveSettings(newConfig); 49 | this.config = settingsManager.getSettings(); 50 | return SUCCESS; 51 | } 52 | 53 | @Override 54 | public String input() { 55 | this.downloadEnabled = this.config.isDownloadEnabled(); 56 | this.customLogoEnabled = this.config.isCustomLogoEnabled(); 57 | this.enabledByDefault = this.config.isEnabledByDefault(); 58 | this.enabledReportsCleanup = this.config.isEnabledReportsCleanup(); 59 | this.localStoragePath = this.config.getLocalStoragePath(); 60 | this.downloadBaseUrl = this.config.getDownloadBaseUrl(); 61 | return INPUT; 62 | } 63 | 64 | @Override 65 | public void validate() { 66 | if (StringUtils.isBlank(downloadBaseUrl)) { 67 | addActionError(getText("allure.config.download.url.error.required")); 68 | } 69 | if (StringUtils.isBlank(localStoragePath)) { 70 | addActionError(getText("allure.config.local.storage.required")); 71 | } 72 | } 73 | 74 | @Override 75 | public void prepare() { 76 | this.config = settingsManager.getSettings(); 77 | } 78 | 79 | public boolean isDownloadEnabled() { 80 | return downloadEnabled; 81 | } 82 | 83 | public void setDownloadEnabled(final boolean downloadEnabled) { 84 | this.downloadEnabled = downloadEnabled; 85 | } 86 | 87 | public boolean isCustomLogoEnabled() { 88 | return customLogoEnabled; 89 | } 90 | 91 | public void setCustomLogoEnabled(final boolean customLogoEnabled) { 92 | this.customLogoEnabled = customLogoEnabled; 93 | } 94 | 95 | public boolean isEnabledByDefault() { 96 | return enabledByDefault; 97 | } 98 | 99 | public void setEnabledByDefault(final boolean enabledByDefault) { 100 | this.enabledByDefault = enabledByDefault; 101 | } 102 | 103 | public boolean isEnabledReportsCleanup() { 104 | return enabledReportsCleanup; 105 | } 106 | 107 | public void setEnabledReportsCleanup(final boolean enabledReportsCleanup) { 108 | this.enabledReportsCleanup = enabledReportsCleanup; 109 | } 110 | 111 | public String getLocalStoragePath() { 112 | return localStoragePath; 113 | } 114 | 115 | public void setLocalStoragePath(final String localStoragePath) { 116 | this.localStoragePath = localStoragePath; 117 | } 118 | 119 | public String getDownloadBaseUrl() { 120 | return downloadBaseUrl; 121 | } 122 | 123 | public void setDownloadBaseUrl(final String downloadBaseUrl) { 124 | this.downloadBaseUrl = downloadBaseUrl; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/ViewAllureReport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import com.atlassian.annotations.security.UnrestrictedAccess; 19 | import com.atlassian.bamboo.build.ChainResultsAction; 20 | 21 | @UnrestrictedAccess 22 | public class ViewAllureReport extends ChainResultsAction { 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/config/AllurePluginJavaConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.config; 17 | 18 | import com.atlassian.bamboo.build.BuildDefinitionManager; 19 | import com.atlassian.bamboo.build.artifact.ArtifactLinkManager; 20 | import com.atlassian.bamboo.build.artifact.handlers.ArtifactHandlersService; 21 | import com.atlassian.bamboo.comment.CommentService; 22 | import com.atlassian.bamboo.deployments.projects.service.DeploymentProjectService; 23 | import com.atlassian.bamboo.logger.ErrorAccessor; 24 | import com.atlassian.bamboo.resultsummary.ResultsSummaryManager; 25 | import com.atlassian.bamboo.template.TemplateRenderer; 26 | import com.atlassian.bamboo.user.BambooAuthenticationContext; 27 | import com.atlassian.bamboo.v2.build.agent.capability.CapabilitySetManager; 28 | import com.atlassian.plugin.PluginAccessor; 29 | import com.atlassian.plugins.osgi.javaconfig.configs.beans.ModuleFactoryBean; 30 | import com.atlassian.plugins.osgi.javaconfig.configs.beans.PluginAccessorBean; 31 | import com.atlassian.sal.api.ApplicationProperties; 32 | import com.atlassian.sal.api.auth.LoginUriProvider; 33 | import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; 34 | import com.atlassian.sal.api.upgrade.PluginUpgradeTask; 35 | import com.atlassian.sal.api.user.UserManager; 36 | import com.atlassian.struts.TextProvider; 37 | import io.qameta.allure.bamboo.AllureArtifactsManager; 38 | import io.qameta.allure.bamboo.AllureCommandLineSupport; 39 | import io.qameta.allure.bamboo.AllureDownloader; 40 | import io.qameta.allure.bamboo.AllureExecutableProvider; 41 | import io.qameta.allure.bamboo.AllurePluginInstallTask; 42 | import io.qameta.allure.bamboo.AllureSettingsManager; 43 | import io.qameta.allure.bamboo.BambooExecutablesManager; 44 | import org.osgi.framework.ServiceRegistration; 45 | import org.springframework.beans.factory.FactoryBean; 46 | import org.springframework.context.annotation.Bean; 47 | import org.springframework.context.annotation.Configuration; 48 | import org.springframework.context.annotation.Import; 49 | 50 | import static com.atlassian.plugins.osgi.javaconfig.OsgiServices.exportOsgiService; 51 | import static com.atlassian.plugins.osgi.javaconfig.OsgiServices.importOsgiService; 52 | 53 | @SuppressWarnings({"PMD.TooManyMethods", "PMD.CouplingBetweenObjects"}) 54 | @Configuration 55 | @Import({ 56 | ModuleFactoryBean.class, 57 | PluginAccessorBean.class 58 | }) 59 | public class AllurePluginJavaConfig { 60 | 61 | 62 | // 63 | @Bean 64 | public ApplicationProperties applicationProperties() { 65 | return importOsgiService(ApplicationProperties.class); 66 | } 67 | 68 | // 69 | @Bean 70 | public TextProvider textProvider() { 71 | return importOsgiService(TextProvider.class); 72 | } 73 | 74 | // 76 | @Bean 77 | public ArtifactLinkManager artifactLinkManager() { 78 | return importOsgiService(ArtifactLinkManager.class); 79 | } 80 | 81 | // 83 | @Bean 84 | public CapabilitySetManager capabilitySetManager() { 85 | return importOsgiService(CapabilitySetManager.class); 86 | } 87 | 88 | // 90 | @Bean 91 | public ResultsSummaryManager resultsSummaryManager() { 92 | return importOsgiService(ResultsSummaryManager.class); 93 | } 94 | 95 | // 96 | @Bean 97 | public ErrorAccessor errorAccessor() { 98 | return importOsgiService(ErrorAccessor.class); 99 | } 100 | 101 | // 102 | @Bean 103 | public CommentService commentsService() { 104 | return importOsgiService(CommentService.class); 105 | } 106 | 107 | // 109 | @Bean 110 | public DeploymentProjectService deploymentProjectService() { 111 | return importOsgiService(DeploymentProjectService.class); 112 | } 113 | 114 | // 116 | @Bean 117 | public BuildDefinitionManager buildDefinitionManager() { 118 | return importOsgiService(BuildDefinitionManager.class); 119 | } 120 | 121 | // 122 | @Bean 123 | public TemplateRenderer renderer() { 124 | return importOsgiService(TemplateRenderer.class); 125 | } 126 | 127 | // 128 | @Bean 129 | public LoginUriProvider loginUriProvider() { 130 | return importOsgiService(LoginUriProvider.class); 131 | } 132 | 133 | // 134 | @Bean 135 | public UserManager userManager() { 136 | return importOsgiService(UserManager.class); 137 | } 138 | 139 | @Bean 140 | public BambooAuthenticationContext bambooAuthenticationContext() { 141 | return importOsgiService(BambooAuthenticationContext.class); 142 | } 143 | 144 | // 146 | @Bean 147 | public PluginSettingsFactory pluginSettingsFactory() { 148 | return importOsgiService(PluginSettingsFactory.class); 149 | } 150 | 151 | // 152 | @Bean 153 | public PluginAccessor pluginAccessor() { 154 | return importOsgiService(PluginAccessor.class); 155 | } 156 | // 158 | @Bean 159 | public ArtifactHandlersService artifactHandlersService() { 160 | return importOsgiService(ArtifactHandlersService.class); 161 | } 162 | 163 | // 165 | @Bean 166 | public AllureCommandLineSupport allureCommandLineSupport() { 167 | return new AllureCommandLineSupport(); 168 | } 169 | 170 | // 172 | @Bean 173 | public AllureSettingsManager allureSettings(final PluginSettingsFactory pluginSettingsFactory) { 174 | return new AllureSettingsManager(pluginSettingsFactory); 175 | } 176 | 177 | // 179 | @Bean 180 | public AllureDownloader allureDownloader(final AllureSettingsManager allureSettingsManager) { 181 | return new AllureDownloader(allureSettingsManager); 182 | } 183 | 184 | // 186 | @Bean 187 | public BambooExecutablesManager bambooExecutableManager(final CapabilitySetManager capabilitySetManager) { 188 | return new BambooExecutablesManager(capabilitySetManager); 189 | } 190 | 191 | // 193 | @Bean 194 | public AllureExecutableProvider allureExecutableProvider(final BambooExecutablesManager bambooExecutableManager, 195 | final AllureDownloader allureDownloader, 196 | final AllureCommandLineSupport allureCommandLineSupport) { 197 | return new AllureExecutableProvider( 198 | bambooExecutableManager, 199 | allureDownloader, 200 | allureCommandLineSupport 201 | ); 202 | } 203 | 204 | // 206 | @Bean 207 | public AllureArtifactsManager allureArtifactsUploader(final PluginAccessor pluginAccessor, 208 | final ArtifactHandlersService artifactHandlersService, 209 | final BuildDefinitionManager buildDefinitionManager, 210 | final ResultsSummaryManager resultsSummaryManager, 211 | final ArtifactLinkManager artifactLinkManager, 212 | final ApplicationProperties applicationProperties, 213 | final AllureSettingsManager allureSettingsManager) { 214 | return new AllureArtifactsManager( 215 | pluginAccessor, 216 | artifactHandlersService, 217 | buildDefinitionManager, 218 | resultsSummaryManager, 219 | artifactLinkManager, 220 | applicationProperties, 221 | allureSettingsManager 222 | ); 223 | } 224 | 225 | // 227 | // com.atlassian.sal.api.upgrade.PluginUpgradeTask 228 | // 229 | @Bean 230 | public PluginUpgradeTask allureInstallTask(final BambooExecutablesManager bambooExecutableManager) { 231 | return new AllurePluginInstallTask(bambooExecutableManager); 232 | } 233 | 234 | // Exports MyPluginComponent as an OSGi service 235 | @Bean 236 | public FactoryBean registerMyDelegatingService( 237 | final PluginUpgradeTask allureInstallTask) { 238 | return exportOsgiService(allureInstallTask, null, PluginUpgradeTask.class); 239 | } 240 | } 241 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/info/AbstractAddInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.info; 17 | 18 | import com.fasterxml.jackson.databind.ObjectMapper; 19 | import com.fasterxml.jackson.databind.json.JsonMapper; 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import java.io.File; 24 | import java.io.IOException; 25 | import java.io.Serializable; 26 | import java.io.Writer; 27 | import java.nio.charset.StandardCharsets; 28 | import java.nio.file.Files; 29 | import java.nio.file.Path; 30 | import java.nio.file.Paths; 31 | 32 | /** 33 | * Abstract class to provide an additional information for reports. 34 | */ 35 | public abstract class AbstractAddInfo implements Serializable { 36 | 37 | private static final Logger LOGGER = LoggerFactory.getLogger(AbstractAddInfo.class); 38 | 39 | public Path invoke(final File file) { 40 | final Path outputDirectory = Paths.get(file.toURI()); 41 | try { 42 | Files.createDirectories(outputDirectory); 43 | } catch (IOException e) { 44 | LOGGER.error("Failed to create output directory " + outputDirectory, e); 45 | } 46 | final Path testRun = outputDirectory.resolve(getFileName()); 47 | try (Writer writer = Files.newBufferedWriter(testRun, StandardCharsets.UTF_8)) { 48 | final ObjectMapper mapper = new JsonMapper(); 49 | mapper.writeValue(writer, getData()); 50 | } catch (Exception e) { 51 | LOGGER.error("Failed to add executor info into the file " + file.getAbsolutePath(), e); 52 | } 53 | return testRun; 54 | } 55 | 56 | protected abstract Object getData(); 57 | 58 | protected abstract String getFileName(); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/info/AddExecutorInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.info; 17 | 18 | import java.util.HashMap; 19 | 20 | /** 21 | * Add executor info to reports. 22 | */ 23 | public class AddExecutorInfo extends AbstractAddInfo { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | private static final String EXECUTOR_JSON = "executor.json"; 28 | 29 | private final String url; 30 | 31 | private final String buildId; 32 | 33 | private final String buildUrl; 34 | 35 | private final String buildName; 36 | 37 | private final String reportUrl; 38 | 39 | public AddExecutorInfo(final String url, 40 | final String buildId, 41 | final String buildName, 42 | final String buildUrl, 43 | final String reportUrl) { 44 | this.url = url; 45 | this.buildId = buildId; 46 | this.buildUrl = buildUrl; 47 | this.buildName = buildName; 48 | this.reportUrl = reportUrl; 49 | } 50 | 51 | @Override 52 | protected Object getData() { 53 | final HashMap data = new HashMap<>(); 54 | data.put("name", "Bamboo"); 55 | data.put("type", "bamboo"); 56 | data.put("url", url); 57 | data.put("buildOrder", buildId); 58 | data.put("buildName", buildName); 59 | data.put("buildUrl", buildUrl); 60 | data.put("reportUrl", reportUrl); 61 | return data; 62 | } 63 | 64 | @Override 65 | protected String getFileName() { 66 | return EXECUTOR_JSON; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/info/AddTestRunInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.info; 17 | 18 | import java.util.HashMap; 19 | 20 | /** 21 | * Add testRun info to reports. 22 | */ 23 | public class AddTestRunInfo extends AbstractAddInfo { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | public static final String TESTRUN_JSON = "testrun.json"; 28 | 29 | private final String name; 30 | 31 | private final long start; 32 | 33 | private final long stop; 34 | 35 | public AddTestRunInfo(final String name, 36 | final long start, 37 | final long stop) { 38 | this.name = name; 39 | this.start = start; 40 | this.stop = stop; 41 | } 42 | 43 | @Override 44 | protected Object getData() { 45 | final HashMap data = new HashMap<>(); 46 | data.put("name", name); 47 | data.put("start", start); 48 | data.put("stop", stop); 49 | return data; 50 | } 51 | 52 | @Override 53 | protected String getFileName() { 54 | return TESTRUN_JSON; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/info/AllurePlugins.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.info; 17 | 18 | import java.util.List; 19 | 20 | public class AllurePlugins { 21 | private List plugins; 22 | 23 | public AllurePlugins(final List plugins) { 24 | this.plugins = plugins; 25 | } 26 | 27 | public AllurePlugins() { 28 | // empty 29 | } 30 | 31 | public boolean isRegistered(final String pluginName) { 32 | return plugins.contains(pluginName); 33 | } 34 | 35 | public List getPlugins() { 36 | return plugins; 37 | } 38 | 39 | public boolean registerPlugin(final String pluginName) { 40 | if (!this.isRegistered(pluginName)) { 41 | this.plugins.add(pluginName); 42 | return true; 43 | } 44 | return false; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "\nplugins: " + this.plugins; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/info/allurewidgets/summary/AbstractSummary.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.info.allurewidgets.summary; 17 | 18 | import java.io.Serializable; 19 | import java.util.Optional; 20 | 21 | public abstract class AbstractSummary implements Serializable { 22 | 23 | public static final String NULL_PLACEHOLDER = ""; 24 | protected static final char COMMA_CHAR = ','; 25 | 26 | public String toStringOrNullPlaceholder(final Object value) { 27 | return Optional.ofNullable(value) 28 | .map(Object::toString) 29 | .orElse(NULL_PLACEHOLDER); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/info/allurewidgets/summary/Statistic.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.info.allurewidgets.summary; 17 | 18 | 19 | public class Statistic extends AbstractSummary { 20 | 21 | private static final long serialVersionUID = 1L; 22 | 23 | private Integer failed; 24 | private Integer broken; 25 | private Integer skipped; 26 | private Integer passed; 27 | private Integer unknown; 28 | private Integer total; 29 | 30 | /** 31 | * No args constructor for use in serialization. 32 | */ 33 | public Statistic() { 34 | // empty 35 | } 36 | 37 | public Statistic(final Integer failed, 38 | final Integer broken, 39 | final Integer skipped, 40 | final Integer passed, 41 | final Integer unknown, 42 | final Integer total) { 43 | super(); 44 | this.failed = failed; 45 | this.broken = broken; 46 | this.skipped = skipped; 47 | this.passed = passed; 48 | this.unknown = unknown; 49 | this.total = total; 50 | } 51 | 52 | public Integer getFailed() { 53 | return failed; 54 | } 55 | 56 | public void setFailed(final Integer failed) { 57 | this.failed = failed; 58 | } 59 | 60 | public Statistic withFailed(final Integer failed) { 61 | this.failed = failed; 62 | return this; 63 | } 64 | 65 | public Integer getBroken() { 66 | return broken; 67 | } 68 | 69 | public void setBroken(final Integer broken) { 70 | this.broken = broken; 71 | } 72 | 73 | public Statistic withBroken(final Integer broken) { 74 | this.broken = broken; 75 | return this; 76 | } 77 | 78 | public Integer getSkipped() { 79 | return skipped; 80 | } 81 | 82 | public void setSkipped(final Integer skipped) { 83 | this.skipped = skipped; 84 | } 85 | 86 | public Statistic withSkipped(final Integer skipped) { 87 | this.skipped = skipped; 88 | return this; 89 | } 90 | 91 | public Integer getPassed() { 92 | return passed; 93 | } 94 | 95 | public void setPassed(final Integer passed) { 96 | this.passed = passed; 97 | } 98 | 99 | public Statistic withPassed(final Integer passed) { 100 | this.passed = passed; 101 | return this; 102 | } 103 | 104 | public Integer getUnknown() { 105 | return unknown; 106 | } 107 | 108 | public void setUnknown(final Integer unknown) { 109 | this.unknown = unknown; 110 | } 111 | 112 | public Statistic withUnknown(final Integer unknown) { 113 | this.unknown = unknown; 114 | return this; 115 | } 116 | 117 | public Integer getTotal() { 118 | return total; 119 | } 120 | 121 | public void setTotal(final Integer total) { 122 | this.total = total; 123 | } 124 | 125 | public Statistic withTotal(final Integer total) { 126 | this.total = total; 127 | return this; 128 | } 129 | 130 | @Override 131 | public String toString() { 132 | final StringBuilder sb = new StringBuilder(100); 133 | sb.append(Statistic.class.getName()) 134 | .append('@').append(Integer.toHexString(System.identityHashCode(this))) 135 | .append("[failed=") 136 | .append(toStringOrNullPlaceholder(this.failed)) 137 | .append(",broken=") 138 | .append(toStringOrNullPlaceholder(this.broken)) 139 | .append(",skipped=") 140 | .append(toStringOrNullPlaceholder(this.skipped)) 141 | .append(",passed=") 142 | .append(toStringOrNullPlaceholder(this.passed)) 143 | .append(",unknown=") 144 | .append(toStringOrNullPlaceholder(this.unknown)) 145 | .append(",total=") 146 | .append(toStringOrNullPlaceholder(this.total)) 147 | .append(COMMA_CHAR); 148 | final int lastIndex = sb.length() - 1; 149 | if (sb.charAt(lastIndex) == COMMA_CHAR) { 150 | sb.setCharAt(lastIndex, ']'); 151 | } else { 152 | sb.append(']'); 153 | } 154 | return sb.toString(); 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/info/allurewidgets/summary/Summary.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.info.allurewidgets.summary; 17 | 18 | import java.util.List; 19 | 20 | public class Summary extends AbstractSummary { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | private String reportName; 25 | private List testRuns; 26 | private Statistic statistic; 27 | private Time time; 28 | 29 | /** 30 | * No args constructor for use in serialization. 31 | */ 32 | public Summary() { 33 | //empty 34 | } 35 | 36 | /** 37 | * @param statistic statistic 38 | * @param reportName report name 39 | * @param time time 40 | * @param testRuns test runs 41 | */ 42 | public Summary(final String reportName, 43 | final List testRuns, 44 | final Statistic statistic, 45 | final Time time) { 46 | super(); 47 | this.reportName = reportName; 48 | this.testRuns = testRuns; 49 | this.statistic = statistic; 50 | this.time = time; 51 | } 52 | 53 | public String getReportName() { 54 | return reportName; 55 | } 56 | 57 | public void setReportName(final String reportName) { 58 | this.reportName = reportName; 59 | } 60 | 61 | public Summary withReportName(final String reportName) { 62 | this.reportName = reportName; 63 | return this; 64 | } 65 | 66 | public List getTestRuns() { 67 | return testRuns; 68 | } 69 | 70 | public void setTestRuns(final List testRuns) { 71 | this.testRuns = testRuns; 72 | } 73 | 74 | public Summary withTestRuns(final List testRuns) { 75 | this.testRuns = testRuns; 76 | return this; 77 | } 78 | 79 | public Statistic getStatistic() { 80 | return statistic; 81 | } 82 | 83 | public void setStatistic(final Statistic statistic) { 84 | this.statistic = statistic; 85 | } 86 | 87 | public Summary withStatistic(final Statistic statistic) { 88 | this.statistic = statistic; 89 | return this; 90 | } 91 | 92 | public Time getTime() { 93 | return time; 94 | } 95 | 96 | public void setTime(final Time time) { 97 | this.time = time; 98 | } 99 | 100 | public Summary withTime(final Time time) { 101 | this.time = time; 102 | return this; 103 | } 104 | 105 | @Override 106 | public String toString() { 107 | final StringBuilder sb = new StringBuilder(100); 108 | sb.append(Summary.class.getName()).append('@') 109 | .append(Integer.toHexString(System.identityHashCode(this))) 110 | .append("[reportName=") 111 | .append(toStringOrNullPlaceholder(this.reportName)) 112 | .append(",testRuns=") 113 | .append(toStringOrNullPlaceholder(this.testRuns)) 114 | .append(",statistic=") 115 | .append(toStringOrNullPlaceholder(this.statistic)) 116 | .append(",time=") 117 | .append(toStringOrNullPlaceholder(this.time)) 118 | .append(COMMA_CHAR); 119 | final int lastIndex = sb.length() - 1; 120 | if (sb.charAt(lastIndex) == COMMA_CHAR) { 121 | sb.setCharAt(lastIndex, ']'); 122 | } else { 123 | sb.append(']'); 124 | } 125 | return sb.toString(); 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/info/allurewidgets/summary/Time.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.info.allurewidgets.summary; 17 | 18 | public class Time extends AbstractSummary { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | private Long start; 23 | private Long stop; 24 | private Integer duration; 25 | private Integer minDuration; 26 | private Integer maxDuration; 27 | private Integer sumDuration; 28 | 29 | /** 30 | * No args constructor for use in serialization. 31 | */ 32 | public Time() { 33 | // empty. 34 | } 35 | 36 | /** 37 | * @param duration duration 38 | * @param sumDuration sum of duration 39 | * @param minDuration min duration 40 | * @param stop stop time 41 | * @param start start time 42 | * @param maxDuration max duration 43 | */ 44 | public Time(final Long start, 45 | final Long stop, 46 | final Integer duration, 47 | final Integer minDuration, 48 | final Integer maxDuration, 49 | final Integer sumDuration) { 50 | super(); 51 | this.start = start; 52 | this.stop = stop; 53 | this.duration = duration; 54 | this.minDuration = minDuration; 55 | this.maxDuration = maxDuration; 56 | this.sumDuration = sumDuration; 57 | } 58 | 59 | public Long getStart() { 60 | return start; 61 | } 62 | 63 | public void setStart(final Long start) { 64 | this.start = start; 65 | } 66 | 67 | public Time withStart(final Long start) { 68 | this.start = start; 69 | return this; 70 | } 71 | 72 | public Long getStop() { 73 | return stop; 74 | } 75 | 76 | public void setStop(final Long stop) { 77 | this.stop = stop; 78 | } 79 | 80 | public Time withStop(final Long stop) { 81 | this.stop = stop; 82 | return this; 83 | } 84 | 85 | public Integer getDuration() { 86 | return duration; 87 | } 88 | 89 | public void setDuration(final Integer duration) { 90 | this.duration = duration; 91 | } 92 | 93 | public Time withDuration(final Integer duration) { 94 | this.duration = duration; 95 | return this; 96 | } 97 | 98 | public Integer getMinDuration() { 99 | return minDuration; 100 | } 101 | 102 | public void setMinDuration(final Integer minDuration) { 103 | this.minDuration = minDuration; 104 | } 105 | 106 | public Time withMinDuration(final Integer minDuration) { 107 | this.minDuration = minDuration; 108 | return this; 109 | } 110 | 111 | public Integer getMaxDuration() { 112 | return maxDuration; 113 | } 114 | 115 | public void setMaxDuration(final Integer maxDuration) { 116 | this.maxDuration = maxDuration; 117 | } 118 | 119 | public Time withMaxDuration(final Integer maxDuration) { 120 | this.maxDuration = maxDuration; 121 | return this; 122 | } 123 | 124 | public Integer getSumDuration() { 125 | return sumDuration; 126 | } 127 | 128 | public void setSumDuration(final Integer sumDuration) { 129 | this.sumDuration = sumDuration; 130 | } 131 | 132 | public Time withSumDuration(final Integer sumDuration) { 133 | this.sumDuration = sumDuration; 134 | return this; 135 | } 136 | 137 | @Override 138 | public String toString() { 139 | final StringBuilder sb = new StringBuilder(100); 140 | sb.append(Time.class.getName()).append('@') 141 | .append(Integer.toHexString(System.identityHashCode(this))) 142 | .append("[start=") 143 | .append(toStringOrNullPlaceholder(this.start)) 144 | .append(",stop=") 145 | .append(toStringOrNullPlaceholder(this.stop)) 146 | .append(",duration=") 147 | .append(toStringOrNullPlaceholder(this.duration)) 148 | .append(",minDuration=") 149 | .append(toStringOrNullPlaceholder(this.minDuration)) 150 | .append(",maxDuration=") 151 | .append(toStringOrNullPlaceholder(this.maxDuration)) 152 | .append(",sumDuration=") 153 | .append(toStringOrNullPlaceholder(this.sumDuration)) 154 | .append(COMMA_CHAR); 155 | final int lastIndex = sb.length() - 1; 156 | if (sb.charAt(lastIndex) == COMMA_CHAR) { 157 | sb.setCharAt(lastIndex, ']'); 158 | } else { 159 | sb.append(']'); 160 | } 161 | return sb.toString(); 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/util/Downloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.util; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.net.HttpURLConnection; 21 | import java.net.URL; 22 | import java.net.URLConnection; 23 | import java.nio.file.Files; 24 | import java.nio.file.Path; 25 | import java.nio.file.StandardCopyOption; 26 | import java.util.Optional; 27 | 28 | import static java.lang.Integer.getInteger; 29 | import static java.util.concurrent.TimeUnit.SECONDS; 30 | 31 | public final class Downloader { 32 | 33 | private static final int CONN_TIMEOUT_MS = (int) SECONDS.toMillis( 34 | getInteger("allure.download.conn.timeout.sec", 20)); 35 | private static final int DOWNLOAD_TIMEOUT_MS = (int) SECONDS.toMillis( 36 | getInteger("allure.download.timeout.sec", 120)); 37 | 38 | private Downloader() { 39 | // do not instantiate 40 | } 41 | 42 | public static Optional download(final URL url, 43 | final Path target) throws IOException { 44 | final URLConnection connection = url.openConnection(); 45 | connection.setConnectTimeout(CONN_TIMEOUT_MS); 46 | connection.setReadTimeout(DOWNLOAD_TIMEOUT_MS); 47 | connection.setRequestProperty("Connection", "close"); 48 | connection.setRequestProperty("Pragma", "no-cache"); 49 | ((HttpURLConnection) connection).setInstanceFollowRedirects(true); 50 | connection.connect(); 51 | try (InputStream input = connection.getInputStream()) { 52 | Files.copy(input, target, StandardCopyOption.REPLACE_EXISTING); 53 | return Optional.of(target); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/util/ExceptionUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.util; 17 | 18 | import java.io.PrintWriter; 19 | import java.io.StringWriter; 20 | 21 | public final class ExceptionUtil { 22 | 23 | private ExceptionUtil() { 24 | // do not instantiate 25 | } 26 | 27 | public static String stackTraceToString(final Throwable e) { 28 | final StringWriter sw = new StringWriter(); 29 | e.printStackTrace(new PrintWriter(sw)); 30 | return sw.toString(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/util/FileStringReplacer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.util; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | import java.io.IOException; 21 | import java.nio.charset.StandardCharsets; 22 | import java.nio.file.Files; 23 | import java.nio.file.Path; 24 | import java.util.regex.Pattern; 25 | 26 | public final class FileStringReplacer { 27 | 28 | private FileStringReplacer() { 29 | // do not instantiate 30 | } 31 | 32 | public static void replaceInFile(final Path filePath, 33 | final String oldString, 34 | final String newString) throws IOException { 35 | String content = new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8); 36 | content = content.replaceAll(oldString, newString); 37 | Files.write(filePath, content.getBytes(StandardCharsets.UTF_8)); 38 | } 39 | 40 | public static void replaceInFile(final Path filePath, 41 | final @NotNull Pattern pattern, 42 | final String newString) throws IOException { 43 | String content = new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8); 44 | content = pattern.matcher(content).replaceAll(newString); 45 | Files.write(filePath, content.getBytes(StandardCharsets.UTF_8)); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/io/qameta/allure/bamboo/util/ZipUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.util; 17 | 18 | import io.qameta.allure.bamboo.AllurePluginException; 19 | import net.lingala.zip4j.ZipFile; 20 | import org.apache.commons.compress.archivers.ArchiveEntry; 21 | import org.apache.commons.compress.archivers.ArchiveException; 22 | import org.apache.commons.compress.archivers.ArchiveInputStream; 23 | import org.apache.commons.compress.archivers.ArchiveStreamFactory; 24 | import org.apache.commons.compress.utils.IOUtils; 25 | import org.apache.commons.io.FileUtils; 26 | import org.jetbrains.annotations.NotNull; 27 | import org.slf4j.Logger; 28 | import org.slf4j.LoggerFactory; 29 | 30 | import java.io.File; 31 | import java.io.IOException; 32 | import java.io.InputStream; 33 | import java.io.OutputStream; 34 | import java.nio.file.Files; 35 | import java.nio.file.Path; 36 | import java.nio.file.Paths; 37 | import java.nio.file.StandardCopyOption; 38 | 39 | public final class ZipUtil { 40 | 41 | private static final Logger LOGGER = LoggerFactory.getLogger(ZipUtil.class); 42 | private static final String DIRECTORY_CREATE_ERROR = "The directory: %s couldn't be created successfully"; 43 | 44 | private ZipUtil() { 45 | // do not instantiate 46 | } 47 | 48 | public static void unzip(final @NotNull Path zipFilePath, 49 | final String outputDir) throws IOException, ArchiveException { 50 | 51 | final ArchiveStreamFactory asf = new ArchiveStreamFactory(); 52 | 53 | try (InputStream zipStream = Files.newInputStream(zipFilePath)) { 54 | try (ArchiveInputStream ais = asf.createArchiveInputStream(ArchiveStreamFactory.ZIP, zipStream)) { 55 | ArchiveEntry entry = ais.getNextEntry(); 56 | while (entry != null) { 57 | final Path entryPath = Paths.get(outputDir, entry.getName()); 58 | final File entryFile = entryPath.toFile(); 59 | 60 | if (!entry.isDirectory()) { 61 | final File parentEntryFile = entryFile.getParentFile(); 62 | if (parentEntryFile.isDirectory() && !(parentEntryFile.mkdirs() || parentEntryFile.exists())) { 63 | throw new IOException(String.format(DIRECTORY_CREATE_ERROR, parentEntryFile.getPath())); 64 | } 65 | 66 | try (OutputStream outputStream = Files.newOutputStream(entryPath)) { 67 | IOUtils.copy(ais, outputStream); 68 | } 69 | } else if (!(entryFile.mkdirs() || entryFile.exists())) { 70 | throw new IOException(String.format(DIRECTORY_CREATE_ERROR, entryFile.getPath())); 71 | } 72 | entry = ais.getNextEntry(); 73 | } 74 | } 75 | } 76 | } 77 | 78 | public static void zipReportFolder(final @NotNull Path srcFolder, 79 | final @NotNull Path targetDir) throws IOException { 80 | try { 81 | final Path zipReportTmpDir = Files.createTempDirectory("tmp_allure_report"); 82 | final Path zipReport = zipReportTmpDir.resolve("report.zip"); 83 | try (ZipFile zp = new ZipFile(zipReport.toFile())) { 84 | zp.addFolder(srcFolder.toFile()); 85 | } 86 | Files.move(zipReport, targetDir, StandardCopyOption.REPLACE_EXISTING); 87 | FileUtils.deleteQuietly(zipReportTmpDir.toFile()); 88 | } catch (Exception e) { 89 | LOGGER.error("Failed to zip allure report", e); 90 | throw new AllurePluginException("Unexpected error", e); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring/plugin-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/main/resources/allure-bamboo.properties: -------------------------------------------------------------------------------- 1 | allure.task.help.link=https://allurereport.org/ 2 | allure.task.help.title=Go to Allure website! 3 | webitems.system.admin.build.allureReport=Allure Report 4 | admin.allureReportConfig.edit.title=Configure Allure Reporting 5 | admin.allureReportConfig.description= 6 | allure.plugin.title=Allure Report 7 | allure.config.title=Allure Reporting 8 | custom.allure.config.enabled.label=Enable Allure Building 9 | custom.allure.config.enabled.default.label=Build Allure for all builds by default 10 | custom.allure.config.failed.only.label=Build report only for failed builds 11 | custom.allure.artifact.name.label=Artifact name to use 12 | custom.allure.config.download.enabled.label=Download if no executable present 13 | custom.allure.config.download.url.label=Allure binary base url 14 | allure.config.download.url.error.required=Allure binary base url is required 15 | custom.allure.config.local.storage.label=Allure local storage 16 | allure.config.local.storage.required=Allure local storage is required 17 | custom.allure.config.logo.enabled.label=Enable report custom logo 18 | custom.allure.logo.url.label=Custom logo 19 | custom.allure.config.reports.cleanup.enabled.label=Enable reports cleanup 20 | custom.allure.max.stored.reports.count.label=Count reports to store 21 | -------------------------------------------------------------------------------- /src/main/resources/atlassian-plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ${project.description} 4 | ${project.version} 5 | 6 | images/logo.png 7 | images/logo.png 8 | 1 9 | compatible 10 | true 11 | 12 | 13 | 14 | 15 | 16 | 17 | Tears down and saves data for MyBambooPlugin if the Chain has the plugin enabled 18 | 19 | 20 | 21 | 22 | If you enable the allure report generation in the "Other" tab, this task is automatically executed without 23 | adding it to your pipeline. However, you can still add it to your pipeline if you want to see it. 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | Plugin to configure Allure build 34 | 35 | 36 | 37 | 38 | 40 | 47 | 48 | 52 | 53 | 54 | 55 | 57 | /chain/result/viewAllure.action?buildKey=${planKey}&buildNumber=${buildNumber} 58 | /chain/result/viewAllure.action?buildKey=${planKey}&buildNumber=${buildNumber} 59 | /templates/viewAllureReport.ftl 60 | /error.ftl 61 | 62 | 63 | 64 | 65 | 66 | /allure/report/* 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 83 | 84 | 85 | 86 | 87 | 89 | /templates/editAllureReportConfig.ftl 90 | /templates/editAllureReportConfig.ftl 91 | 92 | 93 | 94 | /templates/editAllureReportConfig.ftl 95 | /templates/editAllureReportConfig.ftl 96 | /admin/editAllureReportConfig.action 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /src/main/resources/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allure-framework/allure-bamboo/d0f6f2e0dbe582fe935da71931364e1ccc81e91d/src/main/resources/images/icon.png -------------------------------------------------------------------------------- /src/main/resources/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allure-framework/allure-bamboo/d0f6f2e0dbe582fe935da71931364e1ccc81e91d/src/main/resources/images/logo.png -------------------------------------------------------------------------------- /src/main/resources/images/logo_deprecated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allure-framework/allure-bamboo/d0f6f2e0dbe582fe935da71931364e1ccc81e91d/src/main/resources/images/logo_deprecated.png -------------------------------------------------------------------------------- /src/main/resources/templates/editAllureBambooConfiguration.ftl: -------------------------------------------------------------------------------- 1 | [@ui.bambooSection titleKey="allure.config.title"] 2 | [@ww.checkbox labelKey='custom.allure.config.enabled.label' name='custom.allure.config.enabled' toggle='true' /] 3 | 4 | [@ww.checkbox labelKey='custom.allure.config.failed.only.label' name='custom.allure.config.failed.only' toggle='true' /] 5 | 6 | [@ww.select cssClass="builderSelectWidget" labelKey="executable.type" name="custom.allure.config.executable" required="true" 7 | list=uiConfigBean.getExecutableLabels('allure') dependsOn='custom.allure.config.enabled' showOn='true' 8 | extraUtility=addExecutableLink /] 9 | 10 | [@ww.textfield labelKey="custom.allure.artifact.name.label" name="custom.allure.artifact.name" required="false"/] 11 | 12 | [@ww.textfield labelKey="custom.allure.logo.url.label" name="custom.allure.logo.url" required="false"/] 13 | 14 | [@ww.textfield labelKey="custom.allure.max.stored.reports.count.label" name="custom.allure.max.stored.reports.count" required="false"/] 15 | 16 | [/@ui.bambooSection] 17 | -------------------------------------------------------------------------------- /src/main/resources/templates/editAllureReportConfig.ftl: -------------------------------------------------------------------------------- 1 | [#-- @ftlvariable name="action" type="io.qameta.allure.bamboo.ConfigureAllureReportAction" --] 2 | [#-- @ftlvariable name="" type="io.qameta.allure.bamboo.ConfigureAllureReportAction" --] 3 | 4 | 5 | 6 | [@ww.text name='allure.plugin.title' /] 7 | 8 | 9 | 10 | 11 |

[@ww.text name='allure.plugin.title' /]

12 | 13 |

[@ww.text name='admin.allureReportConfig.description' /]

14 | 15 | [@ww.form action="saveAllureReportConfig" 16 | id="saveAllureReportConfigForm" 17 | submitLabelKey='global.buttons.update' 18 | titleKey='admin.allureReportConfig.edit.title' 19 | cancelUri='/admin/editAllureReportConfig.action' 20 | ] 21 | [@ww.checkbox labelKey='custom.allure.config.download.enabled.label' name='downloadEnabled' toggle='true' /] 22 | 23 | [@ww.checkbox labelKey='custom.allure.config.logo.enabled.label' name='customLogoEnabled' toggle='false' /] 24 | 25 | [@ww.checkbox labelKey='custom.allure.config.enabled.default.label' name='enabledByDefault' toggle='true' /] 26 | 27 | [@ww.checkbox labelKey='custom.allure.config.reports.cleanup.enabled.label' name='enabledReportsCleanup' toggle='false' /] 28 | 29 | [@ww.textfield labelKey='custom.allure.config.download.url.label' name='localStoragePath' required='true'/] 30 | 31 | [@ww.textfield labelKey='custom.allure.config.local.storage.label' name='downloadBaseUrl' required='true'/] 32 | [/@ww.form] 33 | 34 | -------------------------------------------------------------------------------- /src/main/resources/templates/error.ftl: -------------------------------------------------------------------------------- 1 | [#-- @ftlvariable name="action" type="com.atlassian.bamboo.logger.AdminErrorAction" --] 2 | [#-- @ftlvariable name="" type="com.atlassian.bamboo.logger.AdminErrorAction" --] 3 | 4 | 5 | 6 | [@ww.text name='error.title' /] 7 | 8 | 9 | 10 | 11 | [@ui.header pageKey='error.heading' /] 12 | 13 | [#if formattedActionErrors?has_content] 14 | [@ui.messageBox type='warning'] 15 | [#list formattedActionErrors as error] 16 |

${error}

17 | [/#list] 18 | [/@ui.messageBox] 19 | [/#if] 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/main/resources/templates/viewAllureBambooConfiguration.ftl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/allure-framework/allure-bamboo/d0f6f2e0dbe582fe935da71931364e1ccc81e91d/src/main/resources/templates/viewAllureBambooConfiguration.ftl -------------------------------------------------------------------------------- /src/main/resources/templates/viewAllureReport.ftl: -------------------------------------------------------------------------------- 1 | [#-- @ftlvariable name="" type="io.qameta.allure.bamboo.ViewAllureReport" --] 2 | 3 | 4 | [#assign reportUrl = "${bestBaseUrl}/plugins/servlet/allure/report/${planKey}/${buildNumber}/"] 5 | [#assign reportZipUrl = "${bestBaseUrl}/plugins/servlet/allure/report/${planKey}/${buildNumber}/report.zip"] 6 | [@ui.header pageKey='buildResult.changes.title' object='${immutablePlan.name} ${resultsSummary.buildNumber}' title=true/] 7 | 8 | 23 | 24 | 25 | Expand  26 | Download  27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/test/java/io/qameta/allure/bamboo/AllureCommandLineSupportTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import org.junit.Test; 19 | 20 | import static org.hamcrest.MatcherAssert.assertThat; 21 | import static org.hamcrest.Matchers.equalTo; 22 | 23 | public class AllureCommandLineSupportTest { 24 | 25 | private static final String OUTPUT = ", enabled: true\n" 26 | + ", enabled: true\n" 27 | + ", enabled: true\n" 28 | + ", enabled: true\n" 29 | + "Found 4 results readers\n" 30 | + "Found %d results for source 1491867175333-0\n" 31 | + "## Summary\n" 32 | + "Found %d test cases (%d failed, %d broken)\n" 33 | + "Success percentage: %s\n" 34 | + "Creating index.html...\n" 35 | + "Couldn't find template in cache for \"index.html.ftl\"(\"en_US\", UTF-8, parsed); " 36 | + "will try to load it.\n" 37 | + "TemplateLoader.findTemplateSource(\"index.html.ftl\"): Found"; 38 | 39 | private final AllureCommandLineSupport support = new AllureCommandLineSupport(); 40 | 41 | @Test 42 | public void itShouldReturnNotContainingTestcasesResult() throws Exception { 43 | final AllureGenerateResult result = support.parseGenerateOutput(String.format(OUTPUT, 0, 0, 0, 0, "Unknown")); 44 | assertThat(result.isContainsTestCases(), equalTo(false)); 45 | } 46 | 47 | @Test 48 | public void itShouldReturnContainingTestcasesResult() throws Exception { 49 | final AllureGenerateResult result = support.parseGenerateOutput(String.format(OUTPUT, 1, 5, 2, 1, "80")); 50 | assertThat(result.isContainsTestCases(), equalTo(true)); 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/io/qameta/allure/bamboo/AllureDownloaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import org.junit.After; 19 | import org.junit.Before; 20 | import org.junit.Rule; 21 | import org.junit.Test; 22 | import org.mockito.InjectMocks; 23 | import org.mockito.Mock; 24 | import org.mockito.junit.MockitoRule; 25 | 26 | import java.io.File; 27 | import java.nio.file.Paths; 28 | 29 | import static org.apache.commons.io.FileUtils.deleteQuietly; 30 | import static org.junit.Assert.assertTrue; 31 | import static org.mockito.Mockito.when; 32 | import static org.mockito.junit.MockitoJUnit.rule; 33 | 34 | public class AllureDownloaderTest { 35 | 36 | @Rule 37 | public MockitoRule mockitoRule = rule(); 38 | @Mock 39 | private AllureSettingsManager settingsManager; 40 | private AllureGlobalConfig settings; 41 | 42 | @InjectMocks 43 | private AllureDownloader downloader; 44 | 45 | private String homeDir; 46 | 47 | @Before 48 | public void setUp() { 49 | homeDir = Paths.get(System.getProperty("java.io.tmpdir"), "allure-home").toString(); 50 | settings = new AllureGlobalConfig(); 51 | when(settingsManager.getSettings()).thenReturn(settings); 52 | } 53 | 54 | @Test 55 | public void itShouldDownloadAndExtractAllureRelease() { 56 | downloader.downloadAndExtractAllureTo(homeDir, "2.17.2"); 57 | final File f = Paths.get(homeDir, "bin", "allure").toFile(); 58 | assertTrue(f.exists()); 59 | } 60 | 61 | @After 62 | public void tearDown() { 63 | deleteQuietly(Paths.get(homeDir).toFile()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/io/qameta/allure/bamboo/AllureExecutableProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import org.junit.Before; 19 | import org.junit.Rule; 20 | import org.junit.Test; 21 | import org.mockito.InjectMocks; 22 | import org.mockito.Mock; 23 | import org.mockito.junit.MockitoRule; 24 | 25 | import java.nio.file.Path; 26 | import java.nio.file.Paths; 27 | import java.util.Optional; 28 | 29 | import static io.qameta.allure.bamboo.AllureExecutableProvider.BIN; 30 | import static io.qameta.allure.bamboo.AllureExecutableProvider.DEFAULT_VERSION; 31 | import static org.mockito.ArgumentMatchers.anyString; 32 | import static org.mockito.Mockito.verify; 33 | import static org.mockito.Mockito.when; 34 | import static org.mockito.junit.MockitoJUnit.rule; 35 | 36 | public class AllureExecutableProviderTest { 37 | 38 | private static final String ALLURE_2_21_0 = "Allure 2.21.0"; 39 | private static final String EXECUTABLE_NAME_2_21_0 = "2.21.0"; 40 | private final String homeDir = "/home/allure"; 41 | 42 | @Rule 43 | public MockitoRule mockitoRule = rule(); 44 | @Mock 45 | private BambooExecutablesManager executablesManager; 46 | @Mock 47 | private AllureDownloader downloader; 48 | @Mock 49 | private AllureCommandLineSupport cmdLine; 50 | @InjectMocks 51 | private AllureExecutableProvider provider; 52 | private AllureGlobalConfig config; 53 | private Path allureCmdPath; 54 | private Path allureBatCmdPath; 55 | 56 | @Before 57 | public void setUp() throws Exception { 58 | config = new AllureGlobalConfig(); 59 | allureCmdPath = Paths.get(homeDir, BIN, "allure"); 60 | allureBatCmdPath = Paths.get(homeDir, BIN, "allure.bat"); 61 | when(downloader.downloadAndExtractAllureTo(anyString(), anyString())).thenReturn(Optional.empty()); 62 | } 63 | 64 | @Test 65 | public void itShouldProvideDefaultVersion() throws Exception { 66 | provide("Allure WITHOUT VERSION"); 67 | verify(downloader).downloadAndExtractAllureTo(homeDir, DEFAULT_VERSION); 68 | } 69 | 70 | @Test 71 | public void itShouldProvideTheGivenVersionWithFullSemverWithoutName() throws Exception { 72 | provide(EXECUTABLE_NAME_2_21_0); 73 | verify(downloader).downloadAndExtractAllureTo(homeDir, EXECUTABLE_NAME_2_21_0); 74 | } 75 | 76 | @Test 77 | public void itShouldProvideTheGivenVersionWithFullSemverWithoutMilestone() throws Exception { 78 | provide(ALLURE_2_21_0); 79 | verify(downloader).downloadAndExtractAllureTo(homeDir, EXECUTABLE_NAME_2_21_0); 80 | } 81 | 82 | @Test 83 | public void itShouldProvideTheGivenVersionWithMajorMinorWithoutMilestone() throws Exception { 84 | provide("Allure 2.13.7"); 85 | verify(downloader).downloadAndExtractAllureTo(homeDir, "2.13.7"); 86 | } 87 | 88 | @Test 89 | public void itShouldProvideTheGivenVersionWithMilestone() throws Exception { 90 | provide("Allure 2.0-BETA4"); 91 | verify(downloader).downloadAndExtractAllureTo(homeDir, "2.0-BETA4"); 92 | } 93 | 94 | private Optional provide(String executableName) { 95 | when(executablesManager.getExecutableByName(executableName)).thenReturn(Optional.of(homeDir)); 96 | return provider.provide(config, executableName); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/io/qameta/allure/bamboo/AllureExecutableTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import org.junit.Before; 19 | import org.junit.Rule; 20 | import org.junit.Test; 21 | import org.mockito.Mock; 22 | import org.mockito.junit.MockitoRule; 23 | 24 | import java.nio.file.Files; 25 | import java.nio.file.Path; 26 | import java.nio.file.Paths; 27 | 28 | import static java.util.Collections.singleton; 29 | import static org.mockito.Mockito.verify; 30 | import static org.mockito.Mockito.when; 31 | import static org.mockito.junit.MockitoJUnit.rule; 32 | 33 | public class AllureExecutableTest { 34 | private static final String OPTIONS = "-o"; 35 | private static final String GENERATE = "generate"; 36 | private static final String BIN_BASH = "/bin/bash"; 37 | @Rule 38 | public MockitoRule mockitoRule = rule(); 39 | 40 | private final Path path = Paths.get("/tmp/where-allure/installed"); 41 | 42 | @Mock 43 | private AllureCommandLineSupport cmdLine; 44 | 45 | private AllureExecutable executable; 46 | private Path fromDir; 47 | private Path toDir; 48 | 49 | @Before 50 | @SuppressWarnings("UnstableApiUsage") 51 | public void setUp() throws Exception { 52 | executable = new AllureExecutable(path, cmdLine); 53 | fromDir = Files.createTempDirectory("tmp_from"); 54 | toDir = Files.createTempDirectory("tmp_to"); 55 | } 56 | 57 | @Test 58 | public void itShouldInvokeAllureGenerateOnUnixWithBash() throws Exception { 59 | when(cmdLine.hasCommand(BIN_BASH)) 60 | .thenReturn(true); 61 | when(cmdLine.isUnix()) 62 | .thenReturn(true); 63 | 64 | executable.generate(singleton(fromDir), toDir); 65 | 66 | verify(cmdLine) 67 | .runCommand(BIN_BASH, path.toString(), GENERATE, OPTIONS, toDir.toString(), fromDir.toString()); 68 | } 69 | 70 | @Test 71 | public void itShouldInvokeAllureGenerateOnUnixWithoutBash() throws Exception { 72 | when(cmdLine.hasCommand(BIN_BASH)) 73 | .thenReturn(false); 74 | when(cmdLine.isUnix()) 75 | .thenReturn(true); 76 | 77 | executable.generate(singleton(fromDir), toDir); 78 | 79 | verify(cmdLine) 80 | .runCommand(path.toString(), GENERATE, OPTIONS, toDir.toString(), fromDir.toString()); 81 | } 82 | 83 | @Test 84 | public void itShouldInvokeAllureGenerateOnWindows() throws Exception { 85 | when(cmdLine.isUnix()) 86 | .thenReturn(false); 87 | 88 | executable.generate(singleton(fromDir), toDir); 89 | 90 | verify(cmdLine) 91 | .runCommand(path.toString(), GENERATE, OPTIONS, toDir.toString(), fromDir.toString()); 92 | 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/test/java/io/qameta/allure/bamboo/AllureReportServletTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import org.junit.Test; 19 | 20 | import java.util.regex.Matcher; 21 | 22 | import static io.qameta.allure.bamboo.AllureReportServlet.getUrlPattern; 23 | import static org.junit.Assert.assertTrue; 24 | 25 | public class AllureReportServletTest { 26 | 27 | @Test 28 | public void itShouldMatchThePattern() throws Exception { 29 | final Matcher matcher = getUrlPattern().matcher("/plugins/servlet/allure/report/STPCI-STPITCONFLUENCE60/15/"); 30 | assertTrue(matcher.matches()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/io/qameta/allure/bamboo/SecondAllureExecutableProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo; 17 | 18 | import org.junit.Before; 19 | import org.junit.Rule; 20 | import org.junit.Test; 21 | import org.mockito.InjectMocks; 22 | import org.mockito.Mock; 23 | import org.mockito.junit.MockitoRule; 24 | 25 | import java.nio.file.Path; 26 | import java.nio.file.Paths; 27 | import java.util.Optional; 28 | 29 | import static io.qameta.allure.bamboo.AllureExecutableProvider.BIN; 30 | import static org.hamcrest.CoreMatchers.equalTo; 31 | import static org.hamcrest.MatcherAssert.assertThat; 32 | import static org.mockito.Mockito.when; 33 | import static org.mockito.junit.MockitoJUnit.rule; 34 | 35 | public class SecondAllureExecutableProviderTest { 36 | 37 | private static final String ALLURE_2_21_0 = "Allure 2.21.0"; 38 | private static final String EXECUTABLE_NAME_2_21_0 = "2.21.0"; 39 | private final String homeDir = "/home/allure"; 40 | 41 | @Rule 42 | public MockitoRule mockitoRule = rule(); 43 | @Mock 44 | private BambooExecutablesManager executablesManager; 45 | @Mock 46 | private AllureDownloader downloader; 47 | @Mock 48 | private AllureCommandLineSupport cmdLine; 49 | @InjectMocks 50 | private AllureExecutableProvider provider; 51 | private AllureGlobalConfig config; 52 | private Path allureCmdPath; 53 | private Path allureBatCmdPath; 54 | 55 | @Before 56 | public void setUp() throws Exception { 57 | config = new AllureGlobalConfig(); 58 | allureCmdPath = Paths.get(homeDir, BIN, "allure"); 59 | allureBatCmdPath = Paths.get(homeDir, BIN, "allure.bat"); 60 | } 61 | 62 | @Test 63 | public void itShouldProvideExecutableForUnix() throws Exception { 64 | when(cmdLine.hasCommand(allureCmdPath.toString())).thenReturn(true); 65 | when(cmdLine.isWindows()).thenReturn(false); 66 | 67 | final Optional res = provide("Allure 2.0-BETA5"); 68 | 69 | assertThat(res.isPresent(), equalTo(true)); 70 | assertThat(res.get().getCmdPath(), equalTo(allureCmdPath)); 71 | } 72 | 73 | @Test 74 | public void itShouldProvideExecutableForWindows() throws Exception { 75 | when(cmdLine.hasCommand(allureBatCmdPath.toString())).thenReturn(true); 76 | when(cmdLine.isWindows()).thenReturn(true); 77 | 78 | final Optional res = provide(ALLURE_2_21_0); 79 | 80 | assertThat(res.isPresent(), equalTo(true)); 81 | assertThat(res.get().getCmdPath(), equalTo(allureBatCmdPath)); 82 | } 83 | 84 | private Optional provide(String executableName) { 85 | when(executablesManager.getExecutableByName(executableName)).thenReturn(Optional.of(homeDir)); 86 | return provider.provide(config, executableName); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/io/qameta/allure/bamboo/util/ExceptionUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2024 Qameta Software Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.qameta.allure.bamboo.util; 17 | 18 | import org.junit.Test; 19 | 20 | import static io.qameta.allure.bamboo.util.ExceptionUtil.stackTraceToString; 21 | import static org.hamcrest.MatcherAssert.assertThat; 22 | import static org.hamcrest.Matchers.containsString; 23 | 24 | public class ExceptionUtilTest { 25 | 26 | @Test 27 | public void itShouldPrintStackTraceIntoString() { 28 | try { 29 | throw new RuntimeException("Print me please"); 30 | } catch (RuntimeException e) { 31 | final String trace = stackTraceToString(e); 32 | assertThat(trace, containsString("RuntimeException: Print me please")); 33 | assertThat(trace, containsString("itShouldPrintStackTraceIntoString(ExceptionUtilTest.java:29)")); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, stdout 2 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 3 | log4j.appender.stdout.Target=System.out 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%m%n 6 | log4j.logger.org.mortbay.log=INFO 7 | --------------------------------------------------------------------------------