Skip to content
Merged
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
15 changes: 15 additions & 0 deletions eng/code-quality-reports/src/main/resources/revapi/revapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,21 @@
"code" : "java.method.removed",
"old" : "method void com.mysql.cj.protocol.ServerSession::setOldStatusFlags(int)",
"justification" : "Fix method removed."
},
{
"code" : "java.field.removed",
"old" : "field com.mysql.cj.conf.PropertyKey.ociConfigProfile",
"justification" : "Fix field removed."
},
{
"code" : "java.method.addedToInterface",
"new" : "method int com.mysql.cj.protocol.ServerSession::getOldStatusFlags()",
"justification" : "Method was added to an interface."
},
{
"code" : "java.method.addedToInterface",
"new" : "method void com.mysql.cj.protocol.ServerSession::setOldStatusFlags(int)",
"justification" : "Method was added to an interface."
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,18 @@
<Bug pattern="NP_NULL_ON_SOME_PATH"/>
</Match>

<!-- Incorrect flagging, already checked by if-else -->
<Match>
<Class name="com.azure.spring.cloud.autoconfigure.implementation.redis.AzureRedisAutoConfiguration"/>
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"/>
</Match>

<!-- Incorrect flagging, already checked by if-else -->
<Match>
<Class name="com.azure.spring.cloud.autoconfigure.implementation.redis.AzureRedisAutoConfiguration"/>
<Bug pattern="NP_NULL_PARAM_DEREF"/>
</Match>

<!-- The transient fields are not used if deserialization happens. -->
<Match>
<Class name="com.azure.identity.implementation.MsalAuthenticationAccount"/>
Expand Down
8 changes: 0 additions & 8 deletions sdk/spring/spring-cloud-azure-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,6 @@
<scope>test</scope>
</dependency>

<!-- for the samples -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version> <!-- {x-version-update;org.apache.httpcomponents:httpclient;external_dependency} -->
<scope>test</scope>
</dependency>

<!-- used to test AzureJdbcAutoConfiguration -->
<dependency>
<groupId>com.mysql</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public class AzureSpringBootVersionVerifier {
private static final Logger LOGGER = LoggerFactory.getLogger(AzureSpringBootVersionVerifier.class);

static final String SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_3_0 = "org.springframework.boot.autoconfigure.validation.ValidationConfigurationCustomizer";
static final String SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_3_1 = "org.springframework.boot.autoconfigure.validation.ValidationConfigurationCustomizer.ValidationConfigurationCustomizer,setIgnoreRegistrationFailure,";
/**
* Versions supported by Spring Cloud Azure, for present is [2.5, 2.6]. Update this value if needed.
* Versions supported by Spring Cloud Azure, for present is [3.0, 3.1]. Update this value if needed.
*/
private final Map<String, String> supportedVersions = new HashMap<>();

Expand All @@ -43,6 +44,7 @@ public AzureSpringBootVersionVerifier(List<String> acceptedVersions, ClassNameRe
*/
private void initDefaultSupportedBootVersionCheckMeta() {
supportedVersions.put("3.0", SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_3_0);
supportedVersions.put("3.1", SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_3_1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,33 @@ boolean resolve(String fullyQualifiedClassName) {
if (fullyQualifiedClassName == null) {
return false;
}

Class.forName(fullyQualifiedClassName);
if (fullyQualifiedClassName.contains(",")) {
String[] stringNames = fullyQualifiedClassName.split(",");
if (stringNames.length > 2) {
Class[] params = new Class[stringNames.length - 2];
for (int i = 2; i < stringNames.length; i++) {
if (stringNames[i].equals("int")) {
params[i - 2] = int.class;
continue;
}
if (stringNames[i].equals("boolean")) {
params[i - 2] = boolean.class;
continue;
}
params[i - 2] = Class.forName(stringNames[i]);
}
Class.forName(stringNames[0]).getMethod(stringNames[1], params);
} else {
Class.forName(stringNames[0]).getMethod(stringNames[1]);
}
} else {
Class.forName(fullyQualifiedClassName);
}
return true;
} catch (ClassNotFoundException ex) {
return false;
} catch (NoSuchMethodException ex) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AzureCompatibilityVerifierProperties {
/**
* Comma-delimited list of Spring Boot versions that are compatible with current Spring Cloud Azure's version.
*/
private List<String> compatibleBootVersions = Arrays.asList("3.0.x");
private List<String> compatibleBootVersions = Arrays.asList("3.0.x", "3.1.x");

public boolean isEnabled() {
return this.enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
Expand All @@ -39,7 +42,8 @@ public class AzureRedisAutoConfiguration {
@Primary
@Bean
RedisProperties redisProperties(AzureRedisProperties azureRedisProperties,
AzureResourceManager azureResourceManager) {
AzureResourceManager azureResourceManager) throws InvocationTargetException,
IllegalAccessException {
String cacheName = azureRedisProperties.getName();

String resourceGroup = azureRedisProperties.getResource().getResourceGroup();
Expand All @@ -63,7 +67,22 @@ RedisProperties redisProperties(AzureRedisProperties azureRedisProperties,
}

redisProperties.setPassword(redisCache.keys().primaryKey());
redisProperties.setSsl(useSsl);
Method setSsl = ReflectionUtils.findMethod(RedisProperties.class, "setSsl", boolean.class);
if (setSsl == null) {
Object ssl = ReflectionUtils.findMethod(RedisProperties.class, "getSsl").invoke(redisProperties);
Class<?>[] innerClasses = RedisProperties.class.getDeclaredClasses();
Class<?> targetInnerClass = null;
for (Class<?> innerClass : innerClasses) {
if (innerClass.getSimpleName().equals("Ssl")) {
targetInnerClass = innerClass;
break;
}
}
ReflectionUtils.findMethod(targetInnerClass, "setEnabled", boolean.class)
.invoke(ssl, useSsl);
} else {
setSsl.invoke(redisProperties, useSsl);
}

return redisProperties;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.implementation.compatibility;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class ClassNameResolverPredicateTest {

@Test
void testResolve() {
ClassNameResolverPredicate predicate = new ClassNameResolverPredicate();
Assertions.assertTrue(predicate.resolve("com.azure.spring.cloud.autoconfigure.implementation.compatibility.ClassNameResolverPredicateTest"));
Assertions.assertTrue(predicate.resolve("com.azure.spring.cloud.autoconfigure.implementation.compatibility.ClassNameResolverPredicateTest,testMethod"));
Assertions.assertTrue(predicate.resolve("com.azure.spring.cloud.autoconfigure.implementation.compatibility.ClassNameResolverPredicateTest,testMethod2,boolean"));
Assertions.assertTrue(predicate.resolve("com.azure.spring.cloud.autoconfigure.implementation.compatibility.ClassNameResolverPredicateTest,testMethod3,boolean,java.lang.String"));
Assertions.assertFalse(predicate.resolve("com.azure.spring.cloud.autoconfigure.implementation.compatibility.ClassNameResolverPredicateTest,testMethod4"));
}

public void testMethod() {}
public void testMethod2(boolean b) {}
public void testMethod3(boolean b, String a) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
Expand Down Expand Up @@ -107,7 +110,22 @@ void shouldConfigureWithNameAndResourceGroupAndResourceManager() {
assertThat(redisProperties.getPassword()).isEqualTo(KEY);
assertThat(redisProperties.getHost()).isEqualTo(HOST);
assertThat(redisProperties.getPort()).isEqualTo(PORT);
assertThat(redisProperties.isSsl()).isEqualTo(IS_SSL);
Method isSsl = ReflectionUtils.findMethod(RedisProperties.class, "isSsl");
if (isSsl == null) {
Object ssl = ReflectionUtils.findMethod(RedisProperties.class, "getSsl").invoke(redisProperties);
Class<?>[] innerClasses = RedisProperties.class.getDeclaredClasses();
Class<?> targetInnerClass = null;
for (Class<?> innerClass : innerClasses) {
if (innerClass.getSimpleName().equals("Ssl")) {
targetInnerClass = innerClass;
break;
}
}
assertThat(ReflectionUtils.findMethod(targetInnerClass, "isEnabled")
.invoke(ssl).equals(IS_SSL));
} else {
assertThat(isSsl.invoke(redisProperties).equals(IS_SSL));
}
});
}

Expand Down