diff --git a/allure-generator/build.gradle.kts b/allure-generator/build.gradle.kts index eb42c7d1f..0dc89681a 100644 --- a/allure-generator/build.gradle.kts +++ b/allure-generator/build.gradle.kts @@ -91,6 +91,11 @@ tasks.processResources { tasks.test { dependsOn(testWeb) + jvmArgs = listOf( + "--add-opens", + "java.base/java.lang=ALL-UNNAMED", + "java.base/java.util=ALL-UNNAMED", + ) } val allurePlugin by configurations.existing @@ -116,6 +121,7 @@ dependencies { testImplementation("io.qameta.allure:allure-junit-platform") testImplementation("org.apache.commons:commons-lang3") testImplementation("org.assertj:assertj-core") + testImplementation("org.junit-pioneer:junit-pioneer") testImplementation("org.junit.jupiter:junit-jupiter") testImplementation("org.mockito:mockito-core") testImplementation("org.slf4j:slf4j-simple") diff --git a/allure-generator/src/main/java/io/qameta/allure/core/ReportWebGenerator.java b/allure-generator/src/main/java/io/qameta/allure/core/ReportWebGenerator.java index f88df103e..6b6776721 100644 --- a/allure-generator/src/main/java/io/qameta/allure/core/ReportWebGenerator.java +++ b/allure-generator/src/main/java/io/qameta/allure/core/ReportWebGenerator.java @@ -16,6 +16,7 @@ package io.qameta.allure.core; import freemarker.template.Template; +import io.qameta.allure.Constants; import io.qameta.allure.PluginConfiguration; import io.qameta.allure.ReportGenerationException; import io.qameta.allure.ReportStorage; @@ -35,6 +36,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.UUID; @@ -141,7 +143,10 @@ public void generate(final Configuration configuration, dataModel.put("reportDataFiles", reportDataFiles); } - dataModel.put("analyticsDisable", false); + final boolean analyticsDisable = Optional.ofNullable(System.getenv(Constants.NO_ANALYTICS)) + .map(Boolean::parseBoolean) + .orElse(false); + dataModel.put("analyticsDisable", analyticsDisable); dataModel.put("reportUuid", UUID.randomUUID().toString()); dataModel.put("allureVersion", "dev"); diff --git a/allure-generator/src/test/java/io/qameta/allure/core/ReportWebGeneratorTest.java b/allure-generator/src/test/java/io/qameta/allure/core/ReportWebGeneratorTest.java new file mode 100644 index 000000000..f53fa7a0b --- /dev/null +++ b/allure-generator/src/test/java/io/qameta/allure/core/ReportWebGeneratorTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016-2023 Qameta Software OÜ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.qameta.allure.core; + +import io.qameta.allure.DefaultConfiguration; +import io.qameta.allure.context.FreemarkerContext; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.junitpioneer.jupiter.SetEnvironmentVariable; + +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.util.Collections; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author charlie (Dmitry Baev). + */ +class ReportWebGeneratorTest { + + @SetEnvironmentVariable(key = "ALLURE_NO_ANALYTICS", value = "true") + @Test + void shouldDisableAnalytics(@TempDir final Path tempDirectory) { + final DefaultConfiguration configuration = new DefaultConfiguration(Collections.singletonList(new FreemarkerContext()), Collections.emptyList()); + final InMemoryReportStorage reportStorage = new InMemoryReportStorage(); + new ReportWebGenerator() + .generate( + configuration, + reportStorage, + tempDirectory + ); + + final Path indexHtml = tempDirectory.resolve("index.html"); + + assertThat(indexHtml) + .isRegularFile() + .content(StandardCharsets.UTF_8) + .doesNotContain("googletagmanager"); + } +} diff --git a/build.gradle.kts b/build.gradle.kts index 0f93b1b1e..7f16af185 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -87,6 +87,7 @@ subprojects { dependency("org.assertj:assertj-core:3.24.2") dependency("org.eclipse.jetty:jetty-server:9.4.51.v20230217") dependency("org.freemarker:freemarker:2.3.32") + dependency("org.junit-pioneer:junit-pioneer:2.1.0") dependency("org.mockito:mockito-core:5.5.0") dependency("org.projectlombok:lombok:1.18.30") dependency("org.zeroturnaround:zt-zip:1.16")