Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ private static Function<CallSiteSpecification, CallSiteResult> generateAdviceClo
if (result.isSuccess()) {
Extension.EXTENSIONS.stream()
.filter(ext -> ext.appliesTo(spec))
.forEach(
ext -> {
try {
ext.apply(configuration, result);
} catch (final Throwable e) {
result.addError(e, ErrorCode.EXTENSION_ERROR, ext.getClass());
}
});
.forEach(ext -> {
try {
ext.apply(configuration, result);
} catch (final Throwable e) {
result.addError(e, ErrorCode.EXTENSION_ERROR, ext.getClass());
}
});
}
return result;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,10 @@ public void visit(final String key, final Object value) {

@Override
public void visitEnd() {
adviceData.forEach(
(adviceCtor, list) ->
list.stream()
.map(
data ->
adviceCtor.build(advice, parameters, data.signature, data.invokeDynamic))
.forEach(spec.advices::add));
adviceData.forEach((adviceCtor, list) ->
list.stream()
.map(data -> adviceCtor.build(advice, parameters, data.signature, data.invokeDynamic))
.forEach(spec.advices::add));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,10 @@ private AdviceMetadata(final AnnotationExpr kind, final Expression tag) {
private static AdviceMetadata findAdviceMetadata(final BodyDeclaration<?> target) {
return target.getAnnotations().stream()
.filter(AdviceMetadata::isAdviceAnnotation)
.map(
annotation -> {
final Expression tag = getAnnotationExpression(annotation);
return new AdviceMetadata(annotation, tag);
})
.map(annotation -> {
final Expression tag = getAnnotationExpression(annotation);
return new AdviceMetadata(annotation, tag);
})
.findFirst()
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ public abstract class BaseCsiPluginTest {
protected static void assertNoErrors(HasErrors hasErrors) {
List<String> errors =
hasErrors.getErrors().stream()
.map(
error -> {
String causeString = error.getCause() == null ? "-" : error.getCauseString();
return error.getMessage() + ": " + causeString;
})
.map(error -> {
String causeString = error.getCause() == null ? "-" : error.getCauseString();
return error.getMessage() + ": " + causeString;
})
.collect(Collectors.toList());
assertEquals(Collections.emptyList(), errors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,38 @@ public CallSiteAssert build() {

protected Set<Class<?>> getSpi(ClassOrInterfaceDeclaration type) {
return type.getAnnotationByName("AutoService")
.<Set<Class<?>>>map(
annotation ->
annotation.asNormalAnnotationExpr().getPairs().stream()
.filter(pair -> pair.getNameAsString().equals("value"))
.flatMap(
pair ->
pair.getValue().asArrayInitializerExpr().getValues().stream()
.map(
value ->
value
.asClassExpr()
.getType()
.resolve()
.asReferenceType()
.getTypeDeclaration()
.get()
.getQualifiedName()))
.map(AssertBuilder::loadClass)
.collect(Collectors.toSet()))
.<Set<Class<?>>>map(annotation ->
annotation.asNormalAnnotationExpr().getPairs().stream()
.filter(pair -> pair.getNameAsString().equals("value"))
.flatMap(pair ->
pair.getValue().asArrayInitializerExpr().getValues().stream()
.map(value ->
value
.asClassExpr()
.getType()
.resolve()
.asReferenceType()
.getTypeDeclaration()
.get()
.getQualifiedName()))
.map(AssertBuilder::loadClass)
.collect(Collectors.toSet()))
.orElse(Collections.emptySet());
}

protected Set<Class<?>> getInterfaces(ClassOrInterfaceDeclaration type) {
return type.getImplementedTypes().stream()
.map(
implementedType -> {
String qualifiedName =
implementedType
.asClassOrInterfaceType()
.resolve()
.asReferenceType()
.getTypeDeclaration()
.get()
.getQualifiedName();
return loadClass(qualifiedName);
})
.map(implementedType -> {
String qualifiedName =
implementedType
.asClassOrInterfaceType()
.resolve()
.asReferenceType()
.getTypeDeclaration()
.get()
.getQualifiedName();
return loadClass(qualifiedName);
})
.collect(Collectors.toSet());
}

Expand Down Expand Up @@ -139,45 +135,41 @@ protected Set<Class<?>> getHelpers(ClassOrInterfaceDeclaration type) {
return methodCalls.stream()
.filter(methodCall -> methodCall.getNameAsString().equals("addHelpers"))
.flatMap(methodCall -> methodCall.getArguments().stream())
.map(
arg -> {
String className = arg.asStringLiteralExpr().asString();
return typeResolver().resolveType(classNameToType(className));
})
.map(arg -> {
String className = arg.asStringLiteralExpr().asString();
return typeResolver().resolveType(classNameToType(className));
})
.collect(Collectors.toSet());
}

protected List<AdviceAssert> getAdvices(ClassOrInterfaceDeclaration type) {
MethodDeclaration acceptMethod = type.getMethodsByName("accept").get(0);
return getMethodCalls(acceptMethod).stream()
.filter(methodCall -> methodCall.getNameAsString().equals("addAdvice"))
.map(
methodCall -> {
String adviceType = methodCall.getArgument(0).asFieldAccessExpr().getNameAsString();
String owner = methodCall.getArgument(1).asStringLiteralExpr().asString();
String method = methodCall.getArgument(2).asStringLiteralExpr().asString();
String descriptor = methodCall.getArgument(3).asStringLiteralExpr().asString();
List<String> statements =
methodCall
.getArgument(4)
.asLambdaExpr()
.getBody()
.asBlockStmt()
.getStatements()
.stream()
.map(Object::toString)
.collect(Collectors.toList());
return new AdviceAssert(adviceType, owner, method, descriptor, statements);
})
.map(methodCall -> {
String adviceType = methodCall.getArgument(0).asFieldAccessExpr().getNameAsString();
String owner = methodCall.getArgument(1).asStringLiteralExpr().asString();
String method = methodCall.getArgument(2).asStringLiteralExpr().asString();
String descriptor = methodCall.getArgument(3).asStringLiteralExpr().asString();
List<String> statements =
methodCall
.getArgument(4)
.asLambdaExpr()
.getBody()
.asBlockStmt()
.getStatements()
.stream()
.map(Object::toString)
.collect(Collectors.toList());
return new AdviceAssert(adviceType, owner, method, descriptor, statements);
})
.collect(Collectors.toList());
}

protected static List<MethodCallExpr> getMethodCalls(MethodDeclaration method) {
return method.getBody().get().asBlockStmt().getStatements().stream()
.filter(
stmt ->
stmt.isExpressionStmt()
&& stmt.asExpressionStmt().getExpression().isMethodCallExpr())
.filter(stmt ->
stmt.isExpressionStmt() && stmt.asExpressionStmt().getExpression().isMethodCallExpr())
.map(stmt -> stmt.asExpressionStmt().getExpression().asMethodCallExpr())
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,33 +272,27 @@ public IastExtensionCallSiteAssert build() {
protected List<AdviceAssert> getAdvices(ClassOrInterfaceDeclaration type) {
return getMethodCalls(type.getMethodsByName("accept").get(0)).stream()
.filter(methodCall -> methodCall.getNameAsString().equals("addAdvice"))
.map(
methodCall -> {
String owner = methodCall.getArgument(1).asStringLiteralExpr().asString();
String method = methodCall.getArgument(2).asStringLiteralExpr().asString();
String descriptor = methodCall.getArgument(3).asStringLiteralExpr().asString();
List<com.github.javaparser.ast.stmt.Statement> statements =
methodCall
.getArgument(4)
.asLambdaExpr()
.getBody()
.asBlockStmt()
.getStatements();
IfStmt instrumentedStmt = statements.get(0).asIfStmt();
IfStmt executedStmt = statements.get(1).asIfStmt();
List<String> nonIfStatements =
statements.stream()
.filter(stmt -> !stmt.isIfStmt())
.map(Object::toString)
.collect(Collectors.toList());
return new IastExtensionAdviceAssert(
owner,
method,
descriptor,
buildMetricAsserter(instrumentedStmt),
buildMetricAsserter(executedStmt),
nonIfStatements);
})
.map(methodCall -> {
String owner = methodCall.getArgument(1).asStringLiteralExpr().asString();
String method = methodCall.getArgument(2).asStringLiteralExpr().asString();
String descriptor = methodCall.getArgument(3).asStringLiteralExpr().asString();
List<com.github.javaparser.ast.stmt.Statement> statements =
methodCall.getArgument(4).asLambdaExpr().getBody().asBlockStmt().getStatements();
IfStmt instrumentedStmt = statements.get(0).asIfStmt();
IfStmt executedStmt = statements.get(1).asIfStmt();
List<String> nonIfStatements =
statements.stream()
.filter(stmt -> !stmt.isIfStmt())
.map(Object::toString)
.collect(Collectors.toList());
return new IastExtensionAdviceAssert(
owner,
method,
descriptor,
buildMetricAsserter(instrumentedStmt),
buildMetricAsserter(executedStmt),
nonIfStatements);
})
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,13 @@ OkHttpClient configureHttpClient(final OkHttpClient httpClient) {
builder.retryOnConnectionFailure(false).followRedirects(false).followSslRedirects(false);
}
if (!requestHeaders.isEmpty()) {
builder.addInterceptor(
chain -> {
final Request.Builder requestBuilder = chain.request().newBuilder();
for (Map.Entry<String, String> header : requestHeaders.entrySet()) {
requestBuilder.header(header.getKey(), header.getValue());
}
return chain.proceed(requestBuilder.build());
});
builder.addInterceptor(chain -> {
final Request.Builder requestBuilder = chain.request().newBuilder();
for (Map.Entry<String, String> header : requestHeaders.entrySet()) {
requestBuilder.header(header.getKey(), header.getValue());
}
return chain.proceed(requestBuilder.build());
});
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,13 @@ public void createRemaining(Config config) {
private OkHttpClient injectTestAgentSessionHeaderInterceptor(String testSessionToken) {
return agentHttpClient
.newBuilder()
.addInterceptor(
chain ->
chain.proceed(
chain
.request()
.newBuilder()
.header(X_DATADOG_TEST_SESSION_TOKEN, testSessionToken)
.build()))
.addInterceptor(chain ->
chain.proceed(
chain
.request()
.newBuilder()
.header(X_DATADOG_TEST_SESSION_TOKEN, testSessionToken)
.build()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,11 @@ private static OkHttpClient buildHttpClient(
final OkHttpClient.Builder builder = new OkHttpClient.Builder();

try {
builder.eventListenerFactory(
call -> {
Request request = call.request();
CustomListener listener = request.tag(CustomListener.class);
return listener != null ? listener : EventListener.NONE;
});
builder.eventListenerFactory(call -> {
Request request = call.request();
CustomListener listener = request.tag(CustomListener.class);
return listener != null ? listener : EventListener.NONE;
});
} catch (NoSuchMethodError e) {
// A workaround for OKHTTP instrumentation tests
// where the version of OKHTTP conflicts with the one used in this module.
Expand Down Expand Up @@ -213,17 +212,12 @@ private static OkHttpClient buildHttpClient(
if (proxyHost != null) {
builder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
if (proxyUsername != null) {
builder.proxyAuthenticator(
(route, response) -> {
final String credential =
Credentials.basic(proxyUsername, proxyPassword == null ? "" : proxyPassword);

return response
.request()
.newBuilder()
.header("Proxy-Authorization", credential)
.build();
});
builder.proxyAuthenticator((route, response) -> {
final String credential =
Credentials.basic(proxyUsername, proxyPassword == null ? "" : proxyPassword);

return response.request().newBuilder().header("Proxy-Authorization", credential).build();
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,18 @@ void setUp() throws IOException {
// server.
intakeClient =
new OkHttpClient.Builder()
.addInterceptor(
chain -> {
final Request original = chain.request();
final HttpUrl local =
original
.url()
.newBuilder()
.scheme("http")
.host(server.getHostName())
.port(server.getPort())
.build();
return chain.proceed(original.newBuilder().url(local).build());
})
.addInterceptor(chain -> {
final Request original = chain.request();
final HttpUrl local =
original
.url()
.newBuilder()
.scheme("http")
.host(server.getHostName())
.port(server.getPort())
.build();
return chain.proceed(original.newBuilder().url(local).build());
})
.build();
}

Expand Down
Loading
Loading