Skip to content

Commit

Permalink
Merge pull request #95 from cqse/reuse-ereportformat
Browse files Browse the repository at this point in the history
Reuse ereportformat
  • Loading branch information
DreierF committed Oct 7, 2019
2 parents 7b005a5 + ae94efc commit 0460d14
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ We use [semantic versioning][semver]

# Next Release
- [documentation] Configuration for SAP NetWeaver Java (>= 7.50) is now documented
- [feature] teamscale-client accepts `String` as report format as well
- [feature] teamscale-client allows attaching arbitrary `Interceptor`s to Teamscale service

# 15.1.0
- [feature] supplying a `class-dir` option is no longer mandatory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.teamscale.jacoco.agent;

import com.teamscale.jacoco.agent.util.LoggingUtils;
import eu.cqse.teamscale.client.HttpUtils;
import com.teamscale.client.HttpUtils;
import org.jacoco.agent.rt.RT;
import org.slf4j.Logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.teamscale.jacoco.agent.store.file.TimestampedFileStore;
import com.teamscale.jacoco.agent.util.Benchmark;
import com.teamscale.jacoco.agent.util.LoggingUtils;
import eu.cqse.teamscale.client.HttpUtils;
import com.teamscale.client.HttpUtils;
import okhttp3.HttpUrl;
import okhttp3.ResponseBody;
import org.conqat.lib.commons.filesystem.FileSystemUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eu.cqse.teamscale.client;
package com.teamscale.client;

import okhttp3.OkHttpClient;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface ITeamscaleService {
@POST("p/{projectName}/external-report/")
Call<ResponseBody> uploadExternalReport(
@Path("projectName") String projectName,
@Query("format") EReportFormat format,
@Query("format") String format,
@Query("t") CommitDescriptor commit,
@Query("adjusttimestamp") boolean adjustTimestamp,
@Query("movetolastcommit") boolean moveToLastCommit,
Expand All @@ -34,6 +34,21 @@ Call<ResponseBody> uploadExternalReport(
@Part("report") RequestBody report
);

/** Report upload API with {@link EReportFormat}. */
default Call<ResponseBody> uploadExternalReport(
String projectName,
EReportFormat format,
CommitDescriptor commit,
boolean adjustTimestamp,
boolean moveToLastCommit,
String partition,
String message,
RequestBody report
) {
return uploadExternalReport(projectName, format.name(), commit, adjustTimestamp, moveToLastCommit, partition,
message, report);
}

/** Report upload API for multiple reports at once. */
@Multipart
@POST("p/{projectName}/external-report/")
Expand Down Expand Up @@ -68,8 +83,8 @@ Call<List<PrioritizableTestCluster>> getImpactedTests(
);

/**
* Uploads the given report body to Teamscale as blocking call
* with adjusttimestamp and movetolastcommit set to true.
* Uploads the given report body to Teamscale as blocking call with adjusttimestamp and movetolastcommit set to
* true.
*
* @return Returns the request body if successful, otherwise throws an IOException.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.teamscale.client;

import eu.cqse.teamscale.client.HttpUtils;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
Expand All @@ -19,21 +19,29 @@ public class TeamscaleServiceGenerator {
* Generates a {@link Retrofit} instance for the given service, which uses basic auth to authenticate against the
* server and which sets the accept header to json.
*/
public static <S> S createService(Class<S> serviceClass, HttpUrl baseUrl, String username, String accessToken) {
public static <S> S createService(Class<S> serviceClass, HttpUrl baseUrl, String username, String accessToken,
Interceptor... interceptors) {
Retrofit retrofit = HttpUtils.createRetrofit(
retrofitBuilder -> retrofitBuilder.baseUrl(baseUrl).addConverterFactory(MoshiConverterFactory.create()),
okHttpBuilder -> okHttpBuilder
okHttpBuilder -> addInterceptors(okHttpBuilder, interceptors)
.addInterceptor(TeamscaleServiceGenerator.getBasicAuthInterceptor(username, accessToken))
.addInterceptor(new AcceptJsonInterceptor())
);
return retrofit.create(serviceClass);
}

private static OkHttpClient.Builder addInterceptors(OkHttpClient.Builder builder, Interceptor... interceptors) {
for (Interceptor interceptor : interceptors) {
builder.addInterceptor(interceptor);
}
return builder;
}

public static <S> S createServiceWithRequestLogging(Class<S> serviceClass, HttpUrl baseUrl, String username,
String accessToken, File file) {
String accessToken, File file, Interceptor... interceptors) {
Retrofit retrofit = HttpUtils.createRetrofit(
retrofitBuilder -> retrofitBuilder.baseUrl(baseUrl).addConverterFactory(MoshiConverterFactory.create()),
okHttpBuilder -> okHttpBuilder
okHttpBuilder -> addInterceptors(okHttpBuilder, interceptors)
.addInterceptor(TeamscaleServiceGenerator.getBasicAuthInterceptor(username, accessToken))
.addInterceptor(new AcceptJsonInterceptor())
.addInterceptor(new FileLoggingInterceptor(file))
Expand Down

0 comments on commit 0460d14

Please sign in to comment.