Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Add commons_test library #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ dependencies {
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
implementation 'org.apache.httpcomponents:httpmime:4.5.13'
implementation 'com.wooga.gradle:gradle-commons:[1,2)'

testImplementation 'com.wooga.gradle:gradle-commons-test:[1,2)'
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package wooga.gradle.appcenter


import com.wooga.gradle.test.PropertyLocation
import spock.lang.Unroll

import static com.wooga.gradle.PlatformUtils.escapedPath

class AppCenterPluginIntegrationSpec extends IntegrationSpec {

def setup() {
Expand All @@ -11,23 +13,6 @@ class AppCenterPluginIntegrationSpec extends IntegrationSpec {
""".stripIndent()
}

enum PropertyLocation {
none, script, property, env

String reason() {
switch (this) {
case script:
return "value is provided in script"
case property:
return "value is provided in props"
case env:
return "value is set in env"
default:
return "no value was configured"
}
}
}

String envNameFromProperty(String property) {
"APP_CENTER_${property.replaceAll(/([A-Z.])/, "_\$1").toUpperCase()}"
}
Expand All @@ -47,7 +32,7 @@ class AppCenterPluginIntegrationSpec extends IntegrationSpec {
and: "a gradle.properties"
def propertiesFile = createFile("gradle.properties")

def escapedValue = (value instanceof String) ? escapedPath(value) : value
def escapedValue = (value instanceof String) ? escapedPath(value) : value

switch (location) {
case PropertyLocation.script:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,7 @@ import org.junit.Rule
import org.junit.contrib.java.lang.system.EnvironmentVariables
import org.junit.contrib.java.lang.system.ProvideSystemProperty

class IntegrationSpec extends nebula.test.IntegrationSpec {

@Rule
ProvideSystemProperty properties = new ProvideSystemProperty("ignoreDeprecations", "true")

@Rule
public EnvironmentVariables environmentVariables = new EnvironmentVariables()

def escapedPath(String path) {
String osName = System.getProperty("os.name").toLowerCase()
if (osName.contains("windows")) {
path = StringEscapeUtils.escapeJava(path)
return path.replace('\\', '\\\\')
}
path
}
class IntegrationSpec extends com.wooga.gradle.test.IntegrationSpec {

def setup() {
def gradleVersion = System.getenv("GRADLE_VERSION")
Expand All @@ -47,62 +32,4 @@ class IntegrationSpec extends nebula.test.IntegrationSpec {
fork = true
}
}

Boolean outputContains(ExecutionResult result, String message) {
result.standardOutput.contains(message) || result.standardError.contains(message)
}

String wrapValueBasedOnType(Object rawValue, String type) {
def value
def rawValueEscaped = String.isInstance(rawValue) ? "'${rawValue}'" : rawValue
def subtypeMatches = type =~ /(?<mainType>\w+)<(?<subType>[\w<>]+)>/
def subType = (subtypeMatches.matches()) ? subtypeMatches.group("subType") : null
type = (subtypeMatches.matches()) ? subtypeMatches.group("mainType") : type
switch (type) {
case "Closure":
if (subType) {
value = "{${wrapValueBasedOnType(rawValue, subType)}}"
} else {
value = "{$rawValueEscaped}"
}
break
case "Callable":
value = "new java.util.concurrent.Callable<${rawValue.class.typeName}>() {@Override ${rawValue.class.typeName} call() throws Exception { $rawValueEscaped }}"
break
case "Object":
value = "new Object() {@Override String toString() { ${rawValueEscaped}.toString() }}"
break
case "Provider":
switch (subType) {
case "RegularFile":
value = "project.layout.file(${wrapValueBasedOnType(rawValue, "Provider<File>")})"
break
default:
value = "project.provider(${wrapValueBasedOnType(rawValue, "Closure<${subType}>")})"
break
}
break
case "String":
value = "$rawValueEscaped"
break
case "String[]":
value = "'{${rawValue.collect { '"' + it + '"' }.join(",")}}'.split(',')"
break
case "File":
value = "new File('${escapedPath(rawValue.toString())}')"
break
case "String...":
value = "${rawValue.collect { '"' + it + '"' }.join(", ")}"
break
case "List":
value = "[${rawValue.collect { '"' + it + '"' }.join(", ")}]"
break
case "Long":
value = "${rawValue}L"
break
default:
value = rawValue
}
value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import spock.lang.Unroll
import wooga.gradle.appcenter.AppCenterPlugin
import wooga.gradle.appcenter.IntegrationSpec

import static com.wooga.gradle.PlatformUtils.escapedPath

class AppCenterUploadTaskIntegrationSpec extends IntegrationSpec {
static String apiToken = System.env["ATLAS_APP_CENTER_INTEGRATION_API_TOKEN"]
static String owner = System.env["ATLAS_APP_CENTER_OWNER"]
Expand Down