Skip to content

Commit

Permalink
Use ServerConfiguration class
Browse files Browse the repository at this point in the history
  • Loading branch information
Avanatiker committed May 5, 2024
1 parent 98a79b3 commit aaf109d
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public TeamscaleClient createTeamscaleClient() {
teamscaleServer.userAccessToken,
teamscaleServer.project
);
return new TeamscaleClient(config, null, HttpUtils.DEFAULT_READ_TIMEOUT, HttpUtils.DEFAULT_WRITE_TIMEOUT);
return new TeamscaleClient(config);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.teamscale.test_impacted.engine.options;

import com.teamscale.client.CommitDescriptor;
import com.teamscale.client.ServerConfiguration;
import com.teamscale.client.TeamscaleClient;
import com.teamscale.test_impacted.engine.ImpactedTestEngine;
import com.teamscale.test_impacted.engine.ImpactedTestEngineConfiguration;
Expand Down Expand Up @@ -105,9 +106,16 @@ private ITestSorter createTestSorter() {
}

private ImpactedTestsProvider createImpactedTestsProvider() {
TeamscaleClient client = new TeamscaleClient(serverOptions.getUrl(), serverOptions.getUserName(),
serverOptions.getUserAccessToken(), serverOptions.getProject(),
new File(reportDirectory, "server-request.txt"));
ServerConfiguration serverConfiguration = new ServerConfiguration(
serverOptions.getUrl(),
serverOptions.getUserName(),
serverOptions.getUserAccessToken(),
serverOptions.getProject()
);
TeamscaleClient client = new TeamscaleClient(
serverConfiguration,
new File(reportDirectory, "server-request.txt")
);
return new ImpactedTestsProvider(client, baseline, endCommit, partition,
isRunAllTests(), isIncludeAddedTests(), isIncludeFailedAndSkipped());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.teamscale.client

import java.io.Serializable
import java.util.*

/** Holds the branch and timestamp of a commit. */
data class CommitDescriptor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import okio.Buffer
import java.io.File
import java.io.IOException
Expand Down Expand Up @@ -42,7 +43,7 @@ class FileLoggingInterceptor(
val content = body.string()
write(content)

wrappedBody = ResponseBody.create(contentType, content)
wrappedBody = content.toResponseBody(contentType)
}
return response.newBuilder().body(wrappedBody).build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ interface ITeamscaleService {
* timestamp is given.
* @param partition The name of the logical partition to store the results into. All existing data in this
* partition will be invalidated. A partition typically corresponds to one analysis run,
* i.e. if there are two independent builds/runs, they must use different partitions.
* @see [
* How to Upload External Analysis Results to Teamscale](https://docs.teamscale.com/howto/uploading-external-results/.upload-via-command-line) for details.
* i.e., if there are two independent builds/runs, they must use different partitions.
* @see [How to Upload External Analysis Results to Teamscale](https://docs.teamscale.com/howto/uploading-external-results/.upload-via-command-line) for details.
*/
@Multipart
@POST("api/v5.9.0/projects/{projectAliasOrId}/external-analysis/session/auto-create/report")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package com.teamscale.client
import java.io.Serializable

data class ServerConfiguration(
/** The url of the Teamscale server. */
var url: String,
/** The project id for which artifacts should be uploaded. */
var project: String,
/** The user name of the Teamscale user. */
var userName: String,
/** The access token of the user. */
var userAccessToken: String
/** The url of the Teamscale server. */
var url: String,
/** The project id for which artifacts should be uploaded. */
var project: String,
/** The username of the Teamscale user. */
var userName: String,
/** The access token of the user. */
var userAccessToken: String
) : Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.time.Duration
import java.util.*

/** Helper class to interact with Teamscale. */
open class TeamscaleClient(
open class TeamscaleClient @JvmOverloads constructor(
private val config: ServerConfiguration,
logfile: File? = null,
readTimeout: Duration = HttpUtils.DEFAULT_READ_TIMEOUT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.teamscale.client

import com.teamscale.client.utils.JsonUtils.OBJECT_MAPPER
import com.teamscale.client.utils.HttpUtils
import com.teamscale.client.utils.JsonUtils.OBJECT_MAPPER
import okhttp3.*
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ object FileSystemUtils {
/**
* Returns the name of the given file without extension. Example: 'data.dat' returns 'data'.
*/
fun getFilenameWithoutExtension(fileName: String): String? {
fun getFilenameWithoutExtension(fileName: String): String {
return StringUtils.removeLastPart(fileName, '.')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ object JsonUtils {
* OBJECT_MAPPER are configured to include all fields when serializing or deserializing objects, regardless of their
* visibility modifiers (public, private, etc.).
*/
@JvmStatic val OBJECT_MAPPER: ObjectMapper =
@JvmStatic
val OBJECT_MAPPER: ObjectMapper =
JsonMapper.builder()
.visibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
.visibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
Expand All @@ -35,7 +36,8 @@ object JsonUtils {
/**
* Creates a new instance of {@link JsonFactory} using the default {@link ObjectMapper}.
*/
@JvmStatic fun createFactory() = JsonFactory(OBJECT_MAPPER)
@JvmStatic
fun createFactory() = JsonFactory(OBJECT_MAPPER)

/**
* Deserializes a JSON string into an object of the given class.
Expand All @@ -52,7 +54,8 @@ object JsonUtils {
OBJECT_MAPPER.readValue(this, T::class.java)

// ToDo: Remove when System tests are in Kotlin
@JvmStatic fun <T> String.deserialize(clazz: Class<*>) =
@JvmStatic
fun <T> String.deserialize(clazz: Class<*>) =
OBJECT_MAPPER.readValue(this, clazz) as T

// ToDo: Remove when System tests are in Kotlin
Expand Down Expand Up @@ -82,7 +85,8 @@ object JsonUtils {
* Serializes an object into its JSON representation.
* @throws JsonProcessingException if the serialization fails
*/
@JvmStatic fun Any.serialize(): String =
@JvmStatic
fun Any.serialize(): String =
OBJECT_MAPPER.writeValueAsString(this)

/**
Expand Down

0 comments on commit aaf109d

Please sign in to comment.