Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy plugin dependencies to test-dependencies directory #74

Merged
merged 1 commit into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 0.16.1 (unreleased)

* copy plugin dependencies to `test-dependencies` directory instead of `plugins` directory to mimic the behavior of
the Maven HPI plugin
([#74](https://github.com/jenkinsci/gradle-jpi-plugin/pull/74))

## 0.16.0 (2016-03-22)

* updated Gradle to version 2.8
Expand Down
17 changes: 6 additions & 11 deletions src/main/groovy/org/jenkinsci/gradle/plugins/jpi/JpiPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin
import static org.gradle.api.logging.LogLevel.INFO
import static org.gradle.api.plugins.JavaPlugin.RUNTIME_CONFIGURATION_NAME
import static org.gradle.api.tasks.SourceSet.TEST_SOURCE_SET_NAME
import static org.gradle.util.GFileUtils.copyFile
import static org.jenkinsci.gradle.plugins.jpi.JpiManifest.attributesToMap

/**
Expand Down Expand Up @@ -140,7 +139,7 @@ class JpiPlugin implements Plugin<Project> {
configureConfigurations(gradleProject)
configureJpi(gradleProject)
configureJar(gradleProject)
configureTestResources(gradleProject)
configureTestDependencies(gradleProject)
configurePublishing(gradleProject)
configureTestHpl(gradleProject)
}
Expand Down Expand Up @@ -184,9 +183,8 @@ class JpiPlugin implements Plugin<Project> {
}
}

private static configureTestResources(Project project) {
private static configureTestDependencies(Project project) {
JavaPluginConvention javaConvention = project.convention.getPlugin(JavaPluginConvention)
Task processTestResources = project.tasks.getByName(javaConvention.sourceSets.test.processResourcesTaskName)
Configuration plugins = project.configurations.create('pluginResources')

project.afterEvaluate {
Expand All @@ -199,15 +197,12 @@ class JpiPlugin implements Plugin<Project> {
project.dependencies.add(plugins.name, "${it.group}:${it.name}:${it.version}")
}
}
processTestResources.inputs.files(plugins)
}

processTestResources.doLast {
File targetDir = javaConvention.sourceSets.test.output.resourcesDir
plugins.resolvedConfiguration.resolvedArtifacts.findAll { it.extension in ['hpi', 'jpi'] }.each {
copyFile(it.file, new File(targetDir, "plugins/${it.name}.${it.extension}"))
}
}
TestDependenciesTask task = project.tasks.create(TestDependenciesTask.TASK_NAME, TestDependenciesTask)
task.pluginsConfiguration = plugins

project.tasks.getByName(javaConvention.sourceSets.test.processResourcesTaskName).dependsOn(task)
}

private static configureLocalizer(Project project) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jenkinsci.gradle.plugins.jpi

import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.Configuration
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction

import static org.gradle.util.GFileUtils.copyFile

class TestDependenciesTask extends DefaultTask {
public static final String TASK_NAME = 'resolveTestDependencies'

@InputFiles
Configuration pluginsConfiguration

@OutputDirectory
File testDependenciesDir

TestDependenciesTask() {
JavaPluginConvention javaConvention = project.convention.getPlugin(JavaPluginConvention)
testDependenciesDir = new File(javaConvention.sourceSets.test.output.resourcesDir, 'test-dependencies')
}

@TaskAction
void resolveTestDependencies() {
List<String> artifacts = []
pluginsConfiguration.resolvedConfiguration.resolvedArtifacts.findAll { it.extension in ['hpi', 'jpi'] }.each {
copyFile(it.file, new File(testDependenciesDir, "${it.name}.${it.extension}"))
artifacts << it.name
}
new File(testDependenciesDir, 'index').setText(artifacts.join('\n'), 'UTF-8')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.jenkinsci.gradle.plugins.jpi

import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification

class TestDependenciesTaskIntegrationSpec extends Specification {
@Rule
final TemporaryFolder project = new TemporaryFolder()

def 'resolves test dependencies'() {
given:
prepareFile('build.gradle') << getClass().getResource('resolveTestDependencies.gradle').text

when:
def result = GradleRunner.create()
.withProjectDir(project.root)
.withPluginClasspath(pluginClasspath)
.withArguments('processTestResources')
.build()

then:
result.task(':resolveTestDependencies').outcome == TaskOutcome.SUCCESS
result.task(':processTestResources').outcome == TaskOutcome.UP_TO_DATE
File dir = new File(project.root, 'build/resources/test/test-dependencies')
dir.directory
new File(dir, 'index').text == 'structs\nconfig-file-provider\ncloudbees-folder\ntoken-macro\ncredentials'
new File(dir, 'structs.hpi').exists()
new File(dir, 'config-file-provider.hpi').exists()
new File(dir, 'cloudbees-folder.hpi').exists()
new File(dir, 'token-macro.hpi').exists()
new File(dir, 'credentials.hpi').exists()
}

private File prepareFile(String relativeFilePath) {
def newFile = new File(project.root, relativeFilePath)
newFile.parentFile.mkdirs()
newFile.createNewFile()
newFile
}

private List<File> getPluginClasspath() {
getClass()
.classLoader
.getResource('plugin-classpath.txt')
.readLines()
.collect { new File(it) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id 'org.jenkins-ci.jpi'
}

dependencies {
jenkinsPlugins 'org.jenkins-ci.plugins:structs:1.1@jar'
optionalJenkinsPlugins 'org.jenkins-ci.plugins:config-file-provider:2.8.1@jar'
jenkinsTest 'org.jenkins-ci.plugins:cloudbees-folder:4.4@jar'
}