|
| 1 | +/* |
| 2 | + * Copyright 2023 SpotBugs team |
| 3 | + * |
| 4 | + * <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | + * except in compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * <p>http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * <p>Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 | + * express or implied. See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | +package com.github.spotbugs.snom |
| 15 | + |
| 16 | +import org.gradle.testkit.runner.GradleRunner |
| 17 | +import org.gradle.testkit.runner.TaskOutcome |
| 18 | +import spock.lang.Specification |
| 19 | + |
| 20 | +import java.nio.file.Files |
| 21 | +import java.nio.file.Path |
| 22 | + |
| 23 | +/** |
| 24 | + * @see <a href="https://github.com/spotbugs/spotbugs-gradle-plugin/issues/909">GitHub Issues</a> |
| 25 | + */ |
| 26 | +class Issue909 extends Specification { |
| 27 | + Path rootDir |
| 28 | + Path buildFile |
| 29 | + |
| 30 | + def setup() { |
| 31 | + rootDir = Files.createTempDirectory("spotbugs-gradle-plugin") |
| 32 | + buildFile = rootDir.resolve("build.gradle") |
| 33 | + buildFile.toFile() << """ |
| 34 | +plugins { |
| 35 | + id "java" |
| 36 | + id "com.github.spotbugs" |
| 37 | +} |
| 38 | +repositories { |
| 39 | + mavenCentral() |
| 40 | +} |
| 41 | +tasks.spotbugsMain { |
| 42 | + reports { |
| 43 | + html { |
| 44 | + required = true |
| 45 | + stylesheet = resources.text.fromString("I am not valid XSL") |
| 46 | + } |
| 47 | + } |
| 48 | +} |
| 49 | + """ |
| 50 | + Path sourceDir = rootDir.resolve("src").resolve("main").resolve("java") |
| 51 | + sourceDir.toFile().mkdirs() |
| 52 | + Path sourceFile = sourceDir.resolve("Foo.java") |
| 53 | + sourceFile.toFile() << """ |
| 54 | +public class Foo { |
| 55 | + public static void main(String... args) { |
| 56 | + System.out.println("Hello, SpotBugs!"); |
| 57 | + } |
| 58 | +} |
| 59 | +""" |
| 60 | + } |
| 61 | + |
| 62 | + def "cannot generate HTML report if invalid XSL is provided"() { |
| 63 | + when: |
| 64 | + def result = GradleRunner.create() |
| 65 | + .withProjectDir(rootDir.toFile()) |
| 66 | + .withArguments('spotbugsMain') |
| 67 | + .withPluginClasspath() |
| 68 | + .buildAndFail() |
| 69 | + |
| 70 | + then: |
| 71 | + TaskOutcome.FAILED == result.task(":spotbugsMain").outcome |
| 72 | + } |
| 73 | +} |
0 commit comments