下面列出了怎么用org.springframework.core.SpringVersion的API类实例代码及写法,或者点击链接到github查看源代码。
private RuntimeEnvironmentInfo(Class spiClass, String implementationName, String implementationVersion,
String platformType, String platformApiVersion, String platformClientVersion,
String platformHostVersion, Map<String, String> platformSpecificInfo) {
Assert.notNull(spiClass, "spiClass is required");
Assert.notNull(implementationName, "implementationName is required");
Assert.notNull(implementationVersion, "implementationVersion is required");
Assert.notNull(platformType, "platformType is required");
Assert.notNull(platformApiVersion, "platformApiVersion is required");
Assert.notNull(platformClientVersion, "platformClientVersion is required");
Assert.notNull(platformHostVersion, "platformHostVersion is required");
this.spiVersion = RuntimeVersionUtils.getVersion(spiClass);
this.implementationName = implementationName;
this.implementationVersion = implementationVersion;
this.platformType = platformType;
this.platformApiVersion = platformApiVersion;
this.platformClientVersion = platformClientVersion;
this.platformHostVersion = platformHostVersion;
this.javaVersion = System.getProperty("java.version");
this.springVersion = SpringVersion.getVersion();
this.springBootVersion = RuntimeVersionUtils.getSpringBootVersion();
this.platformSpecificInfo.putAll(platformSpecificInfo);
}
@Test
public void testCreatingRuntimeEnvironmentInfo() {
RuntimeEnvironmentInfo rei = new RuntimeEnvironmentInfo.Builder()
.spiClass(AppDeployer.class)
.implementationName("TestDeployer")
.implementationVersion("1.0.0")
.platformClientVersion("1.2.0")
.platformHostVersion("1.1.0")
.platformType("Test")
.platformApiVersion("1")
.addPlatformSpecificInfo("foo", "bar")
.build();
assertThat(rei.getSpiVersion(), is(RuntimeVersionUtils.getVersion(AppDeployer.class)));
assertThat(rei.getImplementationName(), is("TestDeployer"));
assertThat(rei.getImplementationVersion(), is("1.0.0"));
assertThat(rei.getPlatformType(), is("Test"));
assertThat(rei.getPlatformApiVersion(), is("1"));
assertThat(rei.getPlatformClientVersion(), is("1.2.0"));
assertThat(rei.getPlatformHostVersion(), is("1.1.0"));
assertThat(rei.getJavaVersion(), is(System.getProperty("java.version")));
assertThat(rei.getSpringVersion(), is(SpringVersion.getVersion()));
assertThat(rei.getSpringBootVersion(), is(RuntimeVersionUtils.getSpringBootVersion()));
assertThat(rei.getPlatformSpecificInfo().get("foo"), is("bar"));
}
private String tryObjenesisProxyCreation(ClassPool cp) {
if (cp.find("org.springframework.objenesis.SpringObjenesis") == null) {
return "";
}
// do not know why 4.2.6 AND 4.3.0 does not work, probably cglib version and cache problem
if (SpringVersion.getVersion().startsWith("4.2.6") ||
SpringVersion.getVersion().startsWith("4.3.0")) {
return "";
}
return
"org.springframework.objenesis.SpringObjenesis objenesis = new org.springframework.objenesis.SpringObjenesis();" +
"if (objenesis.isWorthTrying()) {" +
// "try {" +
"Class proxyClass = e.createClass();" +
"Object proxyInstance = objenesis.newInstance(proxyClass, false);" +
"((org.springframework.cglib.proxy.Factory) proxyInstance).setCallbacks(new org.springframework.cglib.proxy.Callback[] {handler});" +
"return proxyInstance;" +
// "}" +
// "catch (Throwable ex) {}" +
"}";
}
@BeforeClass
public static void before() {
// We skip the tests if we are running against Spring 5.2.x - SpringBoot 1.5 is deprecated and no longer
// breaking changes in the latest Spring releases have not been supported in it.
// TODO: Update the check to verify any Spring version above 5.2
assumeFalse(Objects.requireNonNull(SpringVersion.getVersion()).startsWith("5.2"));
}
@BeforeClass
public static void before() {
// We skip the tests if we are running against Spring 5.2.x - SpringBoot 1.5 is deprecated and no longer
// breaking changes in the latest Spring releases have not been supported in it.
// TODO: Update the check to verify any Spring version above 5.2
assumeFalse(Objects.requireNonNull(SpringVersion.getVersion()).startsWith("5.2"));
}
@BeforeClass
public static void before() {
// We skip the tests if we are running against Spring 5.2.x - SpringBoot 1.5 is deprecated and no longer
// breaking changes in the latest Spring releases have not been supported in it.
// TODO: Update the check to verify any Spring version above 5.2
assumeFalse(Objects.requireNonNull(SpringVersion.getVersion()).startsWith("5.2"));
}
@Test
@SuppressWarnings("unchecked")
public void springVersionSetCorrectly() {
callRuntimeExceptionEndpoint();
Report report = verifyAndGetReport(delivery);
// Check that the Spring version is set as expected
Map<String, Object> deviceMetadata = report.getDevice();
Map<String, Object> runtimeVersions =
(Map<String, Object>) deviceMetadata.get("runtimeVersions");
assertEquals(SpringVersion.getVersion(), runtimeVersions.get("springFramework"));
assertEquals(SpringBootVersion.getVersion(), runtimeVersions.get("springBoot"));
}
private static ConverterManager createDefaultConverterManager() {
String springVersion = SpringVersion.getVersion();
if(springVersion == null) {
LOG.debug("Could not determine the Spring Version. Guessing > Spring 3.0. If this does not work, please ensure to explicitly set converterManager");
return new ConversionServiceConverterManager();
} else if(springVersion.compareTo("3.0") > 0) {
return new ConversionServiceConverterManager();
} else {
return new ConverterManagerImpl();
}
}
@Test
public void springVersionIsNull() {
spy(SpringVersion.class);
when(SpringVersion.getVersion()).thenReturn(null);
DefaultObjectDirectoryMapper mapper = new DefaultObjectDirectoryMapper();
// LDAP-300
assertThat(Whitebox.getInternalState(mapper,"converterManager")).isNotNull();
}
public static void main(String[] args) {
System.err.println(SpringVersion.getVersion());
}
private void addSpringRuntimeVersion(Map<String, Object> device) {
Diagnostics.addDeviceRuntimeVersion(device, "springFramework", SpringVersion.getVersion());
}
public String getSpringVersion() {
return SpringVersion.getVersion();
}