forked from abayer/gradle-hpi-plugin
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy plugin dependencies to test-dependencies directory instead of pl…
…ugins directory to mimic the behavior of the Maven HPI plugin
- Loading branch information
Showing
5 changed files
with
105 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/groovy/org/jenkinsci/gradle/plugins/jpi/TestDependenciesTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/groovy/org/jenkinsci/gradle/plugins/jpi/TestDependenciesTaskIntegrationSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/test/resources/org/jenkinsci/gradle/plugins/jpi/resolveTestDependencies.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |