From c141a15215e4cb767ffe42ccf9dc27225acd2847 Mon Sep 17 00:00:00 2001 From: Ludy Date: Wed, 20 Aug 2025 16:38:21 +0200 Subject: [PATCH] refactor(build): centralize security disable condition in shared Gradle property (#4209) # Description of Changes - Introduced `ext.isSecurityDisabled` closure in root `build.gradle` to consolidate logic for determining if security features should be disabled. - Removed duplicated conditional checks from `sourceSets` configurations in both root and `app/core` `build.gradle` files. - Updated dependency inclusion for `:proprietary` module to use the new `isSecurityDisabled()` method for clarity and maintainability. - Simplified build logic by reducing repeated environment and property checks. This change improves maintainability by ensuring that the security disable condition is defined in one place, reducing the risk of inconsistencies across modules. --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --- app/core/build.gradle | 5 ----- build.gradle | 43 ++++++++----------------------------------- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/app/core/build.gradle b/app/core/build.gradle index c9905a308..409e1711d 100644 --- a/app/core/build.gradle +++ b/app/core/build.gradle @@ -114,11 +114,6 @@ sourceSets { } test { java { - if (System.getenv('DOCKER_ENABLE_SECURITY') == 'false' || System.getenv('DISABLE_ADDITIONAL_FEATURES') == 'true' - || (project.hasProperty('DISABLE_ADDITIONAL_FEATURES') - && System.getProperty('DISABLE_ADDITIONAL_FEATURES') == 'true')) { - exclude 'stirling/software/proprietary/security/**' - } if (System.getenv('STIRLING_PDF_DESKTOP_UI') == 'false') { exclude 'stirling/software/SPDF/UI/impl/**' } diff --git a/build.gradle b/build.gradle index 1cd58b00e..4059d48fe 100644 --- a/build.gradle +++ b/build.gradle @@ -34,6 +34,13 @@ ext { tempJrePath = null } +ext.isSecurityDisabled = { -> + System.getenv('DOCKER_ENABLE_SECURITY') == 'false' || + System.getenv('DISABLE_ADDITIONAL_FEATURES') == 'true' || + (project.hasProperty('DISABLE_ADDITIONAL_FEATURES') && + System.getProperty('DISABLE_ADDITIONAL_FEATURES') == 'true') +} + jar { enabled = false manifest { @@ -222,37 +229,6 @@ licenseReport { outputDir = project.layout.buildDirectory.dir("reports/dependency-license").get().asFile.path } -sourceSets { - main { - java { - if (System.getenv('DOCKER_ENABLE_SECURITY') == 'false' || System.getenv('DISABLE_ADDITIONAL_FEATURES') == 'true' - || (project.hasProperty('DISABLE_ADDITIONAL_FEATURES') - && System.getProperty('DISABLE_ADDITIONAL_FEATURES') == 'true')) { - exclude 'stirling/software/proprietary/security/**' - } - - if (System.getenv('STIRLING_PDF_DESKTOP_UI') == 'false') { - exclude 'stirling/software/SPDF/UI/impl/**' - } - - } - } - - test { - java { - if (System.getenv('DOCKER_ENABLE_SECURITY') == 'false' || System.getenv('DISABLE_ADDITIONAL_FEATURES') == 'true' - || (project.hasProperty('DISABLE_ADDITIONAL_FEATURES') - && System.getProperty('DISABLE_ADDITIONAL_FEATURES') == 'true')) { - exclude 'stirling/software/proprietary/security/**' - } - - if (System.getenv('STIRLING_PDF_DESKTOP_UI') == 'false') { - exclude 'stirling/software/SPDF/UI/impl/**' - } - } - } -} - // Configure the forked spring boot run task to properly delegate to the stirling-pdf module tasks.named('forkedSpringBootRun') { dependsOn ':stirling-pdf:bootRun' @@ -575,9 +551,7 @@ swaggerhubUpload { dependencies { implementation project(':stirling-pdf') implementation project(':common') - if (System.getenv('DISABLE_ADDITIONAL_FEATURES') != 'true' - || (project.hasProperty('DISABLE_ADDITIONAL_FEATURES') - && System.getProperty('DISABLE_ADDITIONAL_FEATURES') != 'true')) { + if (rootProject.ext.isSecurityDisabled()) { implementation project(':proprietary') } @@ -592,7 +566,6 @@ tasks.named("test") { useJUnitPlatform() } - // Make sure all relevant processes depend on writeVersion processResources.dependsOn(writeVersion)