Gradle plugin sources sets are now treated correctly
This commit is contained in:
61
build.gradle
61
build.gradle
@@ -1,42 +1,47 @@
|
||||
subprojects {
|
||||
apply plugin: 'groovy'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'groovy'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
group = 'io.codearte.accurest'
|
||||
version = '1.0.0-SNAPSHOT'
|
||||
group = 'io.codearte.accurest'
|
||||
version = '1.0.0-SNAPSHOT'
|
||||
|
||||
sourceCompatibility = 1.7
|
||||
targetCompatibility = 1.7
|
||||
sourceCompatibility = 1.7
|
||||
targetCompatibility = 1.7
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'org.codehaus.groovy:groovy-all:2.3.6'
|
||||
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
|
||||
}
|
||||
dependencies {
|
||||
compile 'org.codehaus.groovy:groovy-all:2.3.6'
|
||||
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
maven(MavenPublication) {
|
||||
groupId 'io.codearte.accurest'
|
||||
version '1.0.0-SNAPSHOT'
|
||||
publishing {
|
||||
publications {
|
||||
maven(MavenPublication) {
|
||||
groupId 'io.codearte.accurest'
|
||||
version '1.0.0-SNAPSHOT'
|
||||
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
}
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project(':core') {
|
||||
dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
project(':gradle-plugin') {
|
||||
dependencies {
|
||||
compile project(':core')
|
||||
compile gradleApi()
|
||||
}
|
||||
dependencies {
|
||||
compile project(':core')
|
||||
compile gradleApi()
|
||||
}
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.2.1'
|
||||
gradleVersion = '2.2.1'
|
||||
}
|
||||
@@ -66,8 +66,8 @@ class ClassBuilder {
|
||||
|
||||
String build() {
|
||||
BlockBuilder clazz = new BlockBuilder("\t")
|
||||
.addLine("package $packageName" + suffix)
|
||||
.addEmptyLine()
|
||||
.addLine("package $packageName" + suffix)
|
||||
.addEmptyLine()
|
||||
|
||||
imports.sort().each {
|
||||
clazz.addLine("import $it" + suffix)
|
||||
@@ -93,7 +93,7 @@ class ClassBuilder {
|
||||
clazz.startBlock()
|
||||
rules.sort().each {
|
||||
clazz.addLine("@Rule")
|
||||
clazz.addLine("public " + it + " " + NamesUtil.uncapitalize(it) + " = new $it()" + suffix)
|
||||
clazz.addLine("public " + it + " " + NamesUtil.camelCase(it) + " = new $it()" + suffix)
|
||||
}
|
||||
clazz.endBlock()
|
||||
if (!rules.empty) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package io.coderate.accurest.builder
|
||||
/**
|
||||
* @author Jakub Kubrynski
|
||||
*/
|
||||
class JavaMethodBodyBuilder {
|
||||
class JUnitMethodBodyBuilder {
|
||||
/*
|
||||
given()
|
||||
.contentType("application/json")
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.coderate.accurest.builder
|
||||
|
||||
import io.coderate.accurest.util.NamesUtil
|
||||
import groovy.json.JsonSlurper
|
||||
import io.coderate.accurest.util.StubMappingConverter
|
||||
|
||||
/**
|
||||
* @author Jakub Kubrynski
|
||||
@@ -19,8 +19,8 @@ class MethodBuilder {
|
||||
}
|
||||
|
||||
static MethodBuilder createTestMethod(File stubsFile, TestFramework lang) {
|
||||
Map stubContent = new JsonSlurper().parse(stubsFile)
|
||||
String methodName = NamesUtil.uncapitalize(NamesUtil.toLastDot(NamesUtil.afterLast(stubsFile.path, File.separator)))
|
||||
Map stubContent = StubMappingConverter.toStubMappingOnServerSide(stubsFile)
|
||||
String methodName = NamesUtil.camelCase(NamesUtil.toLastDot(NamesUtil.afterLast(stubsFile.path, File.separator)))
|
||||
return new MethodBuilder(methodName, stubContent, lang)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class NamesUtil {
|
||||
|
||||
static String afterLast(String string, String separator) {
|
||||
if (string?.indexOf(separator) > -1) {
|
||||
return string.substring(string.lastIndexOf(separator)+1)
|
||||
return string.substring(string.lastIndexOf(separator) + 1)
|
||||
}
|
||||
return string
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class NamesUtil {
|
||||
return afterLast(string, '.')
|
||||
}
|
||||
|
||||
static String uncapitalize(String className) {
|
||||
static String camelCase(String className) {
|
||||
if (!className) {
|
||||
return className
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package io.coderate.accurest.util
|
||||
|
||||
import groovy.json.JsonSlurper
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
class StubMappingConverter {
|
||||
|
||||
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile(/^\$\{(.*)\}:\$\{(.*)\}$/)
|
||||
public static final int SERVER_SIDE_GROUP = 2
|
||||
|
||||
static Map toStubMappingOnServerSide(File stubMapping) {
|
||||
def json = new JsonSlurper().parse(stubMapping)
|
||||
convertPlaceholders(json as Map, { String value ->
|
||||
getGroupFromMatchingPattern(value)
|
||||
})
|
||||
return json
|
||||
}
|
||||
|
||||
private static void convertPlaceholders(Map map, Closure closure) {
|
||||
map.each {
|
||||
if (it instanceof Map.Entry) {
|
||||
Map.Entry entry = it as Map.Entry
|
||||
if (entry.value instanceof String) {
|
||||
String value = entry.value as String
|
||||
entry.value = closure(value)
|
||||
} else if (entry.value instanceof Map) {
|
||||
convertPlaceholders(entry.value as Map, closure)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Object getGroupFromMatchingPattern(String value) {
|
||||
return value.matches(PLACEHOLDER_PATTERN) ? PLACEHOLDER_PATTERN.matcher(value)[0][SERVER_SIDE_GROUP] : value
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,9 +7,11 @@
|
||||
"equalTo": "text/plain"
|
||||
}
|
||||
},
|
||||
"bodyPatterns" : [ {
|
||||
"matches" : "{\"client\":\"1234\"}"
|
||||
} ]
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches": "{\"client\":\"1234\"}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 400
|
||||
|
||||
@@ -9,24 +9,44 @@ import org.gradle.api.Project
|
||||
*/
|
||||
class AccurestGradlePlugin implements Plugin<Project> {
|
||||
|
||||
private static final String TASK_NAME = 'generateAccurest'
|
||||
|
||||
private static final Class IDEA_PLUGIN_CLASS = org.gradle.plugins.ide.idea.IdeaPlugin
|
||||
|
||||
@Override
|
||||
void apply(Project project) {
|
||||
project.extensions.create('accurest', AccurestPluginExtension)
|
||||
project.task('generateAccurest') << {
|
||||
AccurestPluginExtension accurest = project.accurest
|
||||
AccurestPluginExtension extension = project.extensions.create('accurest', AccurestPluginExtension)
|
||||
|
||||
project.compileTestGroovy.dependsOn(TASK_NAME)
|
||||
|
||||
project.task(TASK_NAME) << {
|
||||
project.logger.info("Accurest Plugin: Invoking test sources generation")
|
||||
|
||||
// project.sourceSets.test.allSource.class.getDeclaredMethods().each {println it.name}
|
||||
project.sourceSets.test.groovy {
|
||||
srcDir extension.generatedTestSourcesDir
|
||||
}
|
||||
|
||||
try {
|
||||
TestGenerator generator = new TestGenerator(project.projectDir.path + '/src/test/resources/' + accurest.stubsBaseDirectory, accurest.basePackageForTests,
|
||||
accurest.baseClassForTests, accurest.ruleClassForTests,
|
||||
accurest.targetFramework, project.buildDir.path + '/' + accurest.generatedTestSourcesDir)
|
||||
TestGenerator generator = new TestGenerator(project.projectDir.path + '/src/test/resources/' + extension.stubsBaseDirectory, extension.basePackageForTests,
|
||||
extension.baseClassForTests, extension.ruleClassForTests,
|
||||
extension.targetFramework, extension.generatedTestSourcesDir)
|
||||
generator.generate()
|
||||
} catch (IllegalStateException e) {
|
||||
project.logger.error("Accurest Plugin: {}", e.getMessage())
|
||||
}
|
||||
}
|
||||
|
||||
project.afterEvaluate {
|
||||
def hasIdea = project.plugins.findPlugin(IDEA_PLUGIN_CLASS)
|
||||
if (hasIdea) {
|
||||
project.idea {
|
||||
module {
|
||||
testSourceDirs += new File(extension.generatedTestSourcesDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,5 +9,5 @@ class AccurestPluginExtension {
|
||||
String basePackageForTests = 'io.codearte.accurest.tests'
|
||||
String baseClassForTests
|
||||
String ruleClassForTests
|
||||
String generatedTestSourcesDir = "generated-test-sources"
|
||||
String generatedTestSourcesDir = 'build/generated-sources/accurest'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user