diff --git a/README.md b/README.md index a995640..87ee6c7 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,7 @@ Gradle Sonar Packaging Plugin ========= -This is a gradle plugin for building plugins for [SonarQube] it is a port of the original maven plugin. - -Waffle Board (Issues) ------------- -[![Stories in Ready](https://badge.waffle.io/iwarapter/gradle-sonar-packaging-plugin.png?label=ready&title=Ready)](https://waffle.io/iwarapter/gradle-sonar-packaging-plugin) -[![Stories in Ready](https://badge.waffle.io/iwarapter/gradle-sonar-packaging-plugin.png?label=In Progress&title=In Progress)](https://waffle.io/iwarapter/gradle-sonar-packaging-plugin) +This is a gradle plugin for building plugins for [SonarQube] it is a port of the original maven plugin. Build Status ------------ @@ -28,7 +23,7 @@ buildscript { } } dependencies { - classpath "gradle.plugin.com.iadams.plugins:gradle-sonar-packaging-plugin:0.1.2" + classpath "gradle.plugin.com.iadams.plugins:gradle-sonar-packaging-plugin:0.1.3" } } @@ -37,7 +32,7 @@ apply plugin: "com.iadams.sonar-packaging" Build script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1: ``` plugins { - id "com.iadams.sonar-packaging" version "0.1.2" + id "com.iadams.sonar-packaging" version "0.1.3" } ``` diff --git a/build.gradle b/build.gradle index 08c1b1e..fd05532 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ apply from: "$rootDir/gradle/sonar.gradle" apply from: "$rootDir/gradle/groovydoc.gradle" group = 'com.iadams.plugins' -version = '0.1.2' +version = '0.1.3-SNAPSHOT' description = 'Gradle plugin for packaging SonarQube plugins.' @@ -35,7 +35,28 @@ dependencies { compile gradleApi() compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7' - testCompile ('com.netflix.nebula:nebula-test:3.1.0') { exclude group: 'org.codehaus.groovy' } + testCompile gradleTestKit() + testCompile 'org.spockframework:spock-core:1.0-groovy-2.4', { + exclude module: 'groovy-all' + } +} + +// Write the plugin's classpath to a file to share with the tests +task createClasspathManifest { + def outputDir = file("$buildDir/$name") + + inputs.files sourceSets.main.runtimeClasspath + outputs.dir outputDir + + doLast { + outputDir.mkdirs() + file("$outputDir/plugin-classpath.txt").text = sourceSets.main.runtimeClasspath.join("\n") + } +} + +// Add the classpath file to the test runtime classpath +dependencies { + testRuntime files(createClasspathManifest) } pluginBundle { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e8c6bf7..9411448 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 597d077..f5584bc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Oct 18 14:09:38 BST 2015 +#Sun Nov 29 12:08:32 GMT 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip diff --git a/gradlew b/gradlew index 97fac78..9d82f78 100755 --- a/gradlew +++ b/gradlew @@ -56,9 +56,9 @@ while [ -h "$PRG" ] ; do fi done SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- +cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" -cd "$SAVED" >&- +cd "$SAVED" >/dev/null CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar diff --git a/src/integTest/groovy/com/iadams/gradle/plugins/GradleCompatabilityIntegSpec.groovy b/src/integTest/groovy/com/iadams/gradle/plugins/GradleCompatabilityIntegSpec.groovy index 31ae4d5..d9a623f 100644 --- a/src/integTest/groovy/com/iadams/gradle/plugins/GradleCompatabilityIntegSpec.groovy +++ b/src/integTest/groovy/com/iadams/gradle/plugins/GradleCompatabilityIntegSpec.groovy @@ -25,36 +25,82 @@ package com.iadams.gradle.plugins import com.iadams.gradle.plugins.utils.SonarPackagingBaseIntegSpec +import org.gradle.testkit.runner.GradleRunner import spock.lang.Unroll -/** - * Created by iwarapter - */ +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS + class GradleCompatabilityIntegSpec extends SonarPackagingBaseIntegSpec { @Unroll - def "should use Gradle #requestedGradleVersion when requested"() { + def "compatible with gradle #gradleVersion"() { setup: def sub1 = addSubproject('example-squid') def sub2 = addSubproject('sonar-example-plugin') - writeHelloWorld('com.example', sub1) - writeHelloWorld('com.example', sub2) + writeHelloWorld('com.example', sub1.name) + writeHelloWorld('com.example', sub2.name) copyResources('build.gradle', 'sonar-example-plugin/build.gradle') - fork = true - //remoteDebug = true - and: - gradleVersion = requestedGradleVersion + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withGradleVersion(gradleVersion) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.task(':sonar-example-plugin:build').outcome == SUCCESS + manifestContains('sonar-example-plugin/build/libs/sonar-example-plugin-1.0.jar', 'Plugin-Description', 'An Example Plugin!') + manifestContains('sonar-example-plugin/build/libs/sonar-example-plugin-1.0.jar', 'Plugin-Key', 'example') + manifestContains('sonar-example-plugin/build/libs/sonar-example-plugin-1.0.jar', 'Plugin-Class', 'com.example.HelloWorld') + manifestContains('sonar-example-plugin/build/libs/sonar-example-plugin-1.0.jar', 'Plugin-Name', 'Example') + + where: + //using the new framework + gradleVersion << ['2.8', '2.9'] + } + + @Unroll + def "compatible with legacy gradle #gradleVersion"() { + setup: + def sub1 = addSubproject('example-squid') + def sub2 = addSubproject('sonar-example-plugin') + + writeHelloWorld('com.example', sub1.name) + writeHelloWorld('com.example', sub2.name) + copyResources('legacy_build.gradle', 'sonar-example-plugin/build.gradle') + + def classpathString = pluginClasspath + .collect { it.absolutePath.replace('\\', '\\\\') } // escape backslashes in Windows paths + .collect { "'$it'" } + .join(", ") + + new File(sub2, 'build.gradle') << """ + buildscript { + dependencies { + classpath files($classpathString) + } + } + """ when: - runTasksSuccessfully('build') + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withGradleVersion(gradleVersion) + .withArguments('build') + .build() then: + result.task(':sonar-example-plugin:build').outcome == SUCCESS manifestContains('sonar-example-plugin/build/libs/sonar-example-plugin-1.0.jar', 'Plugin-Description', 'An Example Plugin!') + manifestContains('sonar-example-plugin/build/libs/sonar-example-plugin-1.0.jar', 'Plugin-Key', 'example') + manifestContains('sonar-example-plugin/build/libs/sonar-example-plugin-1.0.jar', 'Plugin-Class', 'com.example.HelloWorld') + manifestContains('sonar-example-plugin/build/libs/sonar-example-plugin-1.0.jar', 'Plugin-Name', 'Example') where: - //Add future versions, not backwards compatible. - requestedGradleVersion << ['2.3', '2.4', '2.5', '2.6', '2.7'] + //testing the older versions + gradleVersion << ['2.5', '2.6', '2.7'] } } diff --git a/src/integTest/groovy/com/iadams/gradle/plugins/PackageDependenciesIntegTest.groovy b/src/integTest/groovy/com/iadams/gradle/plugins/PackageDependenciesIntegTest.groovy index 67887e3..bb8d0cd 100644 --- a/src/integTest/groovy/com/iadams/gradle/plugins/PackageDependenciesIntegTest.groovy +++ b/src/integTest/groovy/com/iadams/gradle/plugins/PackageDependenciesIntegTest.groovy @@ -25,11 +25,11 @@ package com.iadams.gradle.plugins import com.iadams.gradle.plugins.utils.SonarPackagingBaseIntegSpec -import nebula.test.functional.ExecutionResult +import org.gradle.testkit.runner.GradleRunner + +import static org.gradle.testkit.runner.TaskOutcome.FAILED +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS -/** - * Created by iwarapter - */ class PackageDependenciesIntegTest extends SonarPackagingBaseIntegSpec { def setup() { @@ -39,12 +39,18 @@ class PackageDependenciesIntegTest extends SonarPackagingBaseIntegSpec { def "sonar provided dependencies are NOT packaged"() { setup: - //forked for dependency resolution. - fork = true copyResources('deps-to-exclude.gradle', 'build.gradle') - expect: - runTasksSuccessfully('build') + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.task(':build').outcome == SUCCESS + file('build/libs/example-1.0.jar').exists() !dependencyExists('build/libs/example-1.0.jar', "META-INF/lib/commons-lang-2.5.jar") !dependencyExists('build/libs/example-1.0.jar', 'META-INF/lib/sonar-plugin-api-2.4.jar') !dependencyExists('build/libs/example-1.0.jar', 'META-INF/lib/sonar-plugin-api-5.2-RC2.jar') @@ -52,46 +58,70 @@ class PackageDependenciesIntegTest extends SonarPackagingBaseIntegSpec { def "sonar plugins are not packaged"() { setup: - //forked for dependency resolution. - fork = true copyResources('build-with-sonar-plugin.gradle', 'build.gradle') - expect: - ExecutionResult result = runTasksSuccessfully('build') + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.task(':build').outcome == SUCCESS + file('build/libs/example-1.0.jar').exists() !dependencyExists('build/libs/example-1.0.jar', "META-INF/lib/commons-lang-2.5.jar") !dependencyExists('build/libs/example-1.0.jar', "META-INF/lib/sonar-surefire-plugin-2.4.jar") } def "package dependencies NOT provided by sonar"() { setup: - //forked for dependency resolution. - fork = true copyResources('should-be-packaged.gradle', 'build.gradle') - expect: - runTasksSuccessfully('build') + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.task(':build').outcome == SUCCESS + file('build/libs/example-1.0.jar').exists() dependencyExists('build/libs/example-1.0.jar', "META-INF/lib/commons-email-1.2.jar") } def "provided scope dependencies should NOT be packaged"() { setup: - //forked for dependency resolution. - fork = true copyResources('provided-should-not-be-packaged.gradle', 'build.gradle') - expect: - runTasksSuccessfully('build') + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.task(':build').outcome == SUCCESS + file('build/libs/example-1.0.jar').exists() !dependencyExists('build/libs/example-1.0.jar', "META-INF/lib/commons-email-1.2.jar") } def "package dependencies excluded from api"() { setup: - //forked for dependency resolution. - fork = true copyResources('package-excluded-api-deps.gradle', 'build.gradle') - expect: - runTasksSuccessfully('build') + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.task(':build').outcome == SUCCESS + file('build/libs/example-1.0.jar').exists() dependencyExists('build/libs/example-1.0.jar', "META-INF/lib/plexus-utils-1.5.6.jar") } @@ -102,50 +132,81 @@ class PackageDependenciesIntegTest extends SonarPackagingBaseIntegSpec { copyResources('build-without-api.gradle', 'build.gradle') when: - ExecutionResult result = runTasksWithFailure('build') + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .buildAndFail() then: - result.standardError.contains("org.codehaus.sonar:sonar-plugin-api or org.sonarsource.sonarqube:sonar-plugin-api should be declared in dependencies") + result.task(':pluginPackaging').outcome == FAILED + result.output.contains("org.codehaus.sonar:sonar-plugin-api or org.sonarsource.sonarqube:sonar-plugin-api should be declared in dependencies") } def "build with api in provided scope passes"() { given: copyResources('api-in-provided-scope.gradle', 'build.gradle') - fork = true - expect: - runTasksSuccessfully('build') + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.task(':build').outcome == SUCCESS + file('build/libs/example-1.0.jar').exists() } def "build with old api passes"() { given: copyResources('build-with-old-api.gradle', 'build.gradle') - fork = true - expect: - runTasksSuccessfully('build') + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.task(':build').outcome == SUCCESS + file('build/libs/example-1.0.jar').exists() } def "build with api passes"() { given: copyResources('build-with-api.gradle', 'build.gradle') - fork = true - expect: - runTasksSuccessfully('build') + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.task(':build').outcome == SUCCESS + file('build/libs/example-1.0.jar').exists() } def "build with logging deps logs warnings"() { setup: copyResources('build-with-logging-deps.gradle', 'build.gradle') - fork = true when: - ExecutionResult result = runTasksSuccessfully('build') + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() then: - result.standardOutput.contains("The following dependencies should be defined with scope 'provided': [log4j]") - result.standardOutput.contains("The following dependencies should be defined with scope 'provided': [gwt-user]") + result.task(':build').outcome == SUCCESS + file('build/libs/example-1.0.jar').exists() + result.output.contains("The following dependencies should be defined with scope 'provided': [log4j]") + result.output.contains("The following dependencies should be defined with scope 'provided': [gwt-user]") } def "build with parent and plugin dependencies fails"() { @@ -153,10 +214,15 @@ class PackageDependenciesIntegTest extends SonarPackagingBaseIntegSpec { copyResources('require-plugin-and-parent.gradle', 'build.gradle') when: - ExecutionResult result = runTasksWithFailure('build') + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .buildAndFail() then: - result.standardError.contains("The plugin 'example' can't be both part of the plugin 'java' and having a dependency on 'scm:1.0-SNAPSHOT'") + result.task(":pluginPackaging").outcome == FAILED + result.output.contains("The plugin 'example' can't be both part of the plugin 'java' and having a dependency on 'scm:1.0-SNAPSHOT'") } def "cannot define self as parent"() { @@ -164,22 +230,49 @@ class PackageDependenciesIntegTest extends SonarPackagingBaseIntegSpec { copyResources('self-parent.gradle', 'build.gradle') when: - ExecutionResult result = runTasksWithFailure('build') + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .buildAndFail() then: - result.standardError.contains("The plugin 'example' can't be his own parent. Please remove the 'Plugin-Parent' property.") + result.task(":pluginPackaging").outcome == FAILED + result.output.contains("The plugin 'example' can't be his own parent. Please remove the 'Plugin-Parent' property.") } def "dependencies with classifiers"() { setup: copyResources('dependencies-with-classifier.gradle', 'build.gradle') - fork = true when: - runTasksSuccessfully('build') + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() then: + result.task(":build").outcome == SUCCESS + file('build/libs/example-1.0.jar').exists() dependencyExists('build/libs/example-1.0.jar', "META-INF/lib/grappa-2.0.0-beta.4-all.jar") manifestContains('build/libs/example-1.0.jar', 'Plugin-Dependencies', 'META-INF/lib/grappa-2.0.0-beta.4-all.jar META-INF/lib/asm-debug-all-5.0.3.jar META-INF/lib/jitescript-0.4.0.jar') } + + def "issue #7"() { + setup: + copyResources('issue-7.gradle', 'build.gradle') + + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.task(":build").outcome == SUCCESS + file('build/libs/example-1.0.jar').exists() + !dependencyExists('build/libs/example-1.0.jar', "META-INF/lib/log4j-1.2.17.jar") + } } diff --git a/src/integTest/groovy/com/iadams/gradle/plugins/SonarPackagingIntegSpec.groovy b/src/integTest/groovy/com/iadams/gradle/plugins/SonarPackagingIntegSpec.groovy index c87ab39..6e2e947 100644 --- a/src/integTest/groovy/com/iadams/gradle/plugins/SonarPackagingIntegSpec.groovy +++ b/src/integTest/groovy/com/iadams/gradle/plugins/SonarPackagingIntegSpec.groovy @@ -25,11 +25,12 @@ package com.iadams.gradle.plugins import com.iadams.gradle.plugins.utils.SonarPackagingBaseIntegSpec -import nebula.test.functional.ExecutionResult +import org.gradle.testkit.runner.GradleRunner + +import static org.gradle.testkit.runner.TaskOutcome.FAILED +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS +import static org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE -/** - * Created by iwarapter - */ class SonarPackagingIntegSpec extends SonarPackagingBaseIntegSpec { def "applying plugins provides all tasks"() { @@ -38,11 +39,16 @@ class SonarPackagingIntegSpec extends SonarPackagingBaseIntegSpec { copyResources('build.gradle', 'build.gradle') when: - ExecutionResult result = runTasksSuccessfully('tasks') + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('tasks') + .withPluginClasspath(pluginClasspath) + .build() then: - result.standardOutput.contains('localDeploy - Copies the built plugin to the local server.') - result.standardOutput.contains('restartServer - Restarts a SonarQube server running in dev mode.') + result.task(":tasks").outcome == SUCCESS + result.output.contains('localDeploy - Copies the built plugin to the local server.') + result.output.contains('restartServer - Restarts a SonarQube server running in dev mode.') } def "we can deploy the plugin to a directory"() { @@ -51,36 +57,47 @@ class SonarPackagingIntegSpec extends SonarPackagingBaseIntegSpec { copyResources('build.gradle', 'build.gradle') directory('build/myServer') settingsFile << '''rootProject.name="example"''' - fork = true when: - runTasksSuccessfully('build') - runTasksSuccessfully('localDeploy') + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build', 'localDeploy') + .withPluginClasspath(pluginClasspath) + .build() then: - fileExists('build/myServer/example-1.0.jar') + result.task(":build").outcome == SUCCESS + file('build/myServer/example-1.0.jar').exists() } + def "deploy plugin shows up-to-date if no change"() { setup: writeHelloWorld('com.example') copyResources('build.gradle', 'build.gradle') directory('build/myServer') settingsFile << '''rootProject.name="example"''' - fork = true when: - runTasksSuccessfully('build') - runTasksSuccessfully('localDeploy') + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build', 'localDeploy') + .withPluginClasspath(pluginClasspath) + .build() then: - fileExists('build/myServer/example-1.0.jar') + result.task(":build").outcome == SUCCESS + file('build/myServer/example-1.0.jar').exists() when: - ExecutionResult result = runTasksSuccessfully('localDeploy') + result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('localDeploy') + .withPluginClasspath(pluginClasspath) + .build() then: - result.wasUpToDate(':localDeploy') + result.task(':localDeploy').outcome == UP_TO_DATE } def 'setup example build'() { @@ -88,10 +105,16 @@ class SonarPackagingIntegSpec extends SonarPackagingBaseIntegSpec { writeHelloWorld('com.example') copyResources('build.gradle', 'build.gradle') settingsFile << '''rootProject.name="example"''' - fork = true - expect: - runTasksSuccessfully('build') + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.task(":build").outcome == SUCCESS manifestContains('build/libs/example-1.0.jar', 'Plugin-Description', 'An Example Plugin!') } @@ -108,14 +131,19 @@ class SonarPackagingIntegSpec extends SonarPackagingBaseIntegSpec { version = '1.0' }''' - fork = true - - writeHelloWorld('com.example', squid) - writeHelloWorld('com.example', checks) + writeHelloWorld('com.example', squid.name) + writeHelloWorld('com.example', checks.name) copyResources('multi-project-build.gradle', 'sonar-example-plugin/build.gradle') - expect: - runTasksSuccessfully('build') + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.task(":sonar-example-plugin:build").outcome == SUCCESS manifestContains('sonar-example-plugin/build/libs/sonar-example-plugin-1.0.jar', 'Plugin-Description', 'An Example Plugin!') dependencyExists('sonar-example-plugin/build/libs/sonar-example-plugin-1.0.jar', 'META-INF/lib/example-squid-1.0.jar') dependencyExists('sonar-example-plugin/build/libs/sonar-example-plugin-1.0.jar', 'META-INF/lib/example-checks-1.0.jar') @@ -123,18 +151,25 @@ class SonarPackagingIntegSpec extends SonarPackagingBaseIntegSpec { def "invalid pluginKey causes failure"() { setup: - buildFile << """apply plugin: 'com.iadams.sonar-packaging' + buildFile << """plugins { + id 'com.iadams.sonar-packaging' + } - sonarPackaging { - pluginKey = 'key-with.bad%characters' - pluginClass = ' org.sonar.plugins.example.SamplePlugin' - pluginDescription = 'Sample Plugin!' - }""" + sonarPackaging { + pluginKey = 'key-with.bad%characters' + pluginClass = ' org.sonar.plugins.example.SamplePlugin' + pluginDescription = 'Sample Plugin!' + }""" when: - ExecutionResult result = runTasksWithFailure('build') + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('build') + .withPluginClasspath(pluginClasspath) + .buildAndFail() then: - result.standardError.contains('Plugin key is badly formatted. Please use ascii letters and digits only: ') + result.task(":pluginPackaging").outcome == FAILED + result.output.contains('Plugin key is badly formatted. Please use ascii letters and digits only: ') } } diff --git a/src/integTest/groovy/com/iadams/gradle/plugins/utils/SonarPackagingBaseIntegSpec.groovy b/src/integTest/groovy/com/iadams/gradle/plugins/utils/SonarPackagingBaseIntegSpec.groovy index 4d4d9b9..555a807 100644 --- a/src/integTest/groovy/com/iadams/gradle/plugins/utils/SonarPackagingBaseIntegSpec.groovy +++ b/src/integTest/groovy/com/iadams/gradle/plugins/utils/SonarPackagingBaseIntegSpec.groovy @@ -24,15 +24,35 @@ */ package com.iadams.gradle.plugins.utils -import nebula.test.IntegrationSpec +import org.apache.commons.io.FileUtils +import org.junit.Rule +import org.junit.rules.TemporaryFolder +import spock.lang.Specification import java.util.jar.JarEntry import java.util.jar.JarFile -/** - * Created by iwarapter - */ -class SonarPackagingBaseIntegSpec extends IntegrationSpec { +class SonarPackagingBaseIntegSpec extends Specification { + + @Rule + TemporaryFolder testProjectDir + File buildFile + File settingsFile + + List pluginClasspath + + def setup() { + buildFile = testProjectDir.newFile('build.gradle') + + def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.txt") + if (pluginClasspathResource == null) { + throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.") + } + + pluginClasspath = pluginClasspathResource.readLines().collect { new File(it) } + + settingsFile = testProjectDir.newFile('settings.gradle') + } /** * Given a jar file asserts the key/value pair exists in the manifest. @@ -62,4 +82,67 @@ class SonarPackagingBaseIntegSpec extends IntegrationSpec { return false } } + + /** + * Copy a given set of files/directories + * + * @param srcDir + * @param destination + */ + protected void copyResources(String srcDir, String destination) { + ClassLoader classLoader = getClass().getClassLoader() + URL resource = classLoader.getResource(srcDir) + if (resource == null) { + throw new SonarPackagingIntegSpecException("Could not find classpath resource: $srcDir") + } + + File destinationFile = file(destination) + File resourceFile = new File(resource.toURI()) + if (resourceFile.file) { + FileUtils.copyFile(resourceFile, destinationFile) + } else { + FileUtils.copyDirectory(resourceFile, destinationFile) + } + } + + protected void writeHelloWorld(String packageDotted, String baseDir = '') { + def path = baseDir +'/src/main/java/' + packageDotted.replace('.', '/') + directory(path) + def javaFile = testProjectDir.newFile(path + '/HelloWorld.java') + javaFile << """package ${packageDotted}; + public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello Integration Test"); + } + } + """.stripIndent() + } + + protected File file(String path, File baseDir = testProjectDir.root) { + def splitted = path.split('/') + def directory = splitted.size() > 1 ? directory(splitted[0..-2].join('/'), baseDir) : baseDir + def file = new File(directory, splitted[-1]) + file.createNewFile() + file + } + + protected File directory(String path, File baseDir = testProjectDir.root) { + new File(baseDir, path).with { + mkdirs() + it + } + } + + protected File addSubproject(String subprojectName, String subBuildGradleText){ + def subProjFolder = testProjectDir.newFolder(subprojectName) + testProjectDir.newFile("$subprojectName/build.gradle") << "$subBuildGradleText\n" + settingsFile << "include '$subprojectName'\n" + subProjFolder + } + + protected File addSubproject(String subprojectName) { + def subProjFolder = testProjectDir.newFolder(subprojectName) + settingsFile << "include '$subprojectName'\n" + subProjFolder + } } diff --git a/src/integTest/groovy/com/iadams/gradle/plugins/utils/SonarPackagingIntegSpecException.groovy b/src/integTest/groovy/com/iadams/gradle/plugins/utils/SonarPackagingIntegSpecException.groovy new file mode 100644 index 0000000..e63e313 --- /dev/null +++ b/src/integTest/groovy/com/iadams/gradle/plugins/utils/SonarPackagingIntegSpecException.groovy @@ -0,0 +1,40 @@ +/* + * Gradle Sonar Packaging Plugin + * The MIT License (MIT) + * + * Copyright (c) 2015 Iain Adams + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.iadams.gradle.plugins.utils + +/** + * @author iwarapter + * + * Custom Exception for failures initiating functional tests. + */ +class SonarPackagingIntegSpecException extends Exception { + SonarPackagingIntegSpecException(String message, Throwable cause) { + super(message, cause) + } + + SonarPackagingIntegSpecException(String message) { + super(message) + } +} diff --git a/src/integTest/resources/api-in-provided-scope.gradle b/src/integTest/resources/api-in-provided-scope.gradle index d3ddd70..969415f 100644 --- a/src/integTest/resources/api-in-provided-scope.gradle +++ b/src/integTest/resources/api-in-provided-scope.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/integTest/resources/build-with-api.gradle b/src/integTest/resources/build-with-api.gradle index bc245af..2896bf3 100644 --- a/src/integTest/resources/build-with-api.gradle +++ b/src/integTest/resources/build-with-api.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/integTest/resources/build-with-logging-deps.gradle b/src/integTest/resources/build-with-logging-deps.gradle index 7cd7dc1..a290988 100644 --- a/src/integTest/resources/build-with-logging-deps.gradle +++ b/src/integTest/resources/build-with-logging-deps.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/integTest/resources/build-with-old-api.gradle b/src/integTest/resources/build-with-old-api.gradle index cc07710..ece5236 100644 --- a/src/integTest/resources/build-with-old-api.gradle +++ b/src/integTest/resources/build-with-old-api.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/integTest/resources/build-with-sonar-plugin.gradle b/src/integTest/resources/build-with-sonar-plugin.gradle index fc42ce3..c918a2e 100644 --- a/src/integTest/resources/build-with-sonar-plugin.gradle +++ b/src/integTest/resources/build-with-sonar-plugin.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/integTest/resources/build-without-api.gradle b/src/integTest/resources/build-without-api.gradle index 091213f..7e60e84 100644 --- a/src/integTest/resources/build-without-api.gradle +++ b/src/integTest/resources/build-without-api.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} version = '1.0' diff --git a/src/integTest/resources/build.gradle b/src/integTest/resources/build.gradle index ae57fff..973b550 100644 --- a/src/integTest/resources/build.gradle +++ b/src/integTest/resources/build.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() @@ -18,4 +20,4 @@ sonarPackaging { pluginClass = 'com.example.HelloWorld' pluginName = 'Example' pluginDescription = 'An Example Plugin!' -} \ No newline at end of file +} diff --git a/src/integTest/resources/dependencies-with-classifier.gradle b/src/integTest/resources/dependencies-with-classifier.gradle index 66f0bb3..3694fa2 100644 --- a/src/integTest/resources/dependencies-with-classifier.gradle +++ b/src/integTest/resources/dependencies-with-classifier.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/integTest/resources/deps-to-exclude.gradle b/src/integTest/resources/deps-to-exclude.gradle index da6bb02..3a0f3ad 100644 --- a/src/integTest/resources/deps-to-exclude.gradle +++ b/src/integTest/resources/deps-to-exclude.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/integTest/resources/issue-7.gradle b/src/integTest/resources/issue-7.gradle new file mode 100644 index 0000000..a577b1a --- /dev/null +++ b/src/integTest/resources/issue-7.gradle @@ -0,0 +1,29 @@ +plugins { + id 'com.iadams.sonar-packaging' +} + +repositories { + mavenCentral() +} + +dependencies { + provided 'org.codehaus.sonar:sonar-plugin-api:4.5.2' + compile 'org.codehaus.sonar.sslr:sslr-core:1.20' + compile 'org.codehaus.sonar.sslr-squid-bridge:sslr-squid-bridge:2.5.3' + + compile 'log4j:log4j:1.2.17' +} + +configurations { + compile.exclude group: 'log4j', module: 'log4j' +} + +version = '1.0' + +sonarPackaging { + pluginDir = "$buildDir/myServer" + pluginKey = 'example' + pluginClass = 'org.sonar.plugins.sample.SamplePlugin' + pluginName = 'Example' + pluginDescription = 'An Example Plugin!' +} \ No newline at end of file diff --git a/src/integTest/resources/legacy_build.gradle b/src/integTest/resources/legacy_build.gradle new file mode 100644 index 0000000..ff0183d --- /dev/null +++ b/src/integTest/resources/legacy_build.gradle @@ -0,0 +1,21 @@ +apply plugin: 'com.iadams.sonar-packaging' + +repositories { + mavenCentral() +} + +dependencies { + provided 'org.codehaus.sonar:sonar-plugin-api:4.5.2' + compile 'org.codehaus.sonar.sslr:sslr-core:1.20' + compile 'org.codehaus.sonar.sslr-squid-bridge:sslr-squid-bridge:2.5.3' +} + +version = '1.0' + +sonarPackaging { + pluginDir = "$buildDir/myServer" + pluginKey = 'example' + pluginClass = 'com.example.HelloWorld' + pluginName = 'Example' + pluginDescription = 'An Example Plugin!' +} diff --git a/src/integTest/resources/multi-project-build.gradle b/src/integTest/resources/multi-project-build.gradle index 9c58352..92098bd 100644 --- a/src/integTest/resources/multi-project-build.gradle +++ b/src/integTest/resources/multi-project-build.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/integTest/resources/package-excluded-api-deps.gradle b/src/integTest/resources/package-excluded-api-deps.gradle index 6af4eab..73b3922 100644 --- a/src/integTest/resources/package-excluded-api-deps.gradle +++ b/src/integTest/resources/package-excluded-api-deps.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/integTest/resources/provided-should-not-be-packaged.gradle b/src/integTest/resources/provided-should-not-be-packaged.gradle index 50e0924..3fdbe95 100644 --- a/src/integTest/resources/provided-should-not-be-packaged.gradle +++ b/src/integTest/resources/provided-should-not-be-packaged.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/integTest/resources/require-plugin-and-parent.gradle b/src/integTest/resources/require-plugin-and-parent.gradle index d69d478..f2fd061 100644 --- a/src/integTest/resources/require-plugin-and-parent.gradle +++ b/src/integTest/resources/require-plugin-and-parent.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/integTest/resources/self-parent.gradle b/src/integTest/resources/self-parent.gradle index ec04884..9cf8162 100644 --- a/src/integTest/resources/self-parent.gradle +++ b/src/integTest/resources/self-parent.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/integTest/resources/should-be-packaged.gradle b/src/integTest/resources/should-be-packaged.gradle index e23370e..bb90adf 100644 --- a/src/integTest/resources/should-be-packaged.gradle +++ b/src/integTest/resources/should-be-packaged.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.iadams.sonar-packaging' +plugins { + id 'com.iadams.sonar-packaging' +} repositories { mavenCentral() diff --git a/src/test/groovy/com/iadams/gradle/plugins/SonarPackagingPluginSpec.groovy b/src/test/groovy/com/iadams/gradle/plugins/SonarPackagingPluginSpec.groovy index 9ff8d2d..231ac50 100644 --- a/src/test/groovy/com/iadams/gradle/plugins/SonarPackagingPluginSpec.groovy +++ b/src/test/groovy/com/iadams/gradle/plugins/SonarPackagingPluginSpec.groovy @@ -24,23 +24,22 @@ */ package com.iadams.gradle.plugins -import nebula.test.PluginProjectSpec +import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.testfixtures.ProjectBuilder +import spock.lang.Specification /** * Created by iwarapter */ -class SonarPackagingPluginSpec extends PluginProjectSpec { +class SonarPackagingPluginSpec extends Specification { static final String PLUGIN_ID = 'com.iadams.sonar-packaging' - - @Override - String getPluginName() { - return PLUGIN_ID - } + Project project def setup() { - project.apply plugin: pluginName + project = ProjectBuilder.builder().build() + project.pluginManager.apply PLUGIN_ID } def "apply creates sonarPackaging extension"() { diff --git a/src/test/groovy/com/iadams/gradle/plugins/core/PluginManifestSpec.groovy b/src/test/groovy/com/iadams/gradle/plugins/core/PluginManifestSpec.groovy index 0bd022d..6eb69ed 100644 --- a/src/test/groovy/com/iadams/gradle/plugins/core/PluginManifestSpec.groovy +++ b/src/test/groovy/com/iadams/gradle/plugins/core/PluginManifestSpec.groovy @@ -24,12 +24,14 @@ */ package com.iadams.gradle.plugins.core +import spock.lang.Ignore import spock.lang.Specification /** * Created by iwarapter */ class PluginManifestSpec extends Specification { + @Ignore def "AddManifestProperty"() { setup: PluginManifest manifest = new PluginManifest()