use of org.apache.servicecomb.foundation.common.Version in project java-chassis by ServiceComb.
the class VersionRuleRangeParser method parse.
@Override
public VersionRule parse(String strVersionRule) {
int pos = strVersionRule.indexOf('-');
if (pos <= 0 || pos == strVersionRule.length() - 1) {
return null;
}
Version from = new Version(strVersionRule.substring(0, pos));
Version to = new Version(strVersionRule.substring(pos + 1));
return new RangeVersionRule(from.getVersion() + "-" + to.getVersion(), from, to);
}
use of org.apache.servicecomb.foundation.common.Version in project java-chassis by ServiceComb.
the class MicroserviceFactory method createMicroserviceFromConfiguration.
private Microservice createMicroserviceFromConfiguration(Configuration configuration) {
Microservice microservice = new Microservice();
EnvironmentConfiguration envConfig = new EnvironmentConfiguration();
if (!StringUtils.isEmpty(envConfig.getString(APP_MAPPING)) && !StringUtils.isEmpty(envConfig.getString(envConfig.getString(APP_MAPPING)))) {
microservice.setAppId(envConfig.getString(envConfig.getString(APP_MAPPING)));
} else {
microservice.setAppId(BootStrapProperties.readApplication(configuration));
}
if (!StringUtils.isEmpty(envConfig.getString(SERVICE_MAPPING)) && !StringUtils.isEmpty(envConfig.getString(envConfig.getString(SERVICE_MAPPING)))) {
microservice.setServiceName(envConfig.getString(envConfig.getString(SERVICE_MAPPING)));
} else {
microservice.setServiceName(BootStrapProperties.readServiceName(configuration));
}
String version;
if (!StringUtils.isEmpty(envConfig.getString(VERSION_MAPPING)) && !StringUtils.isEmpty(envConfig.getString(envConfig.getString(VERSION_MAPPING)))) {
version = envConfig.getString(envConfig.getString(VERSION_MAPPING));
} else {
version = BootStrapProperties.readServiceVersion(configuration);
}
// just check version format
new Version(version);
microservice.setVersion(version);
microservice.setDescription(BootStrapProperties.readServiceDescription(configuration));
microservice.setLevel(BootStrapProperties.readServiceRole(configuration));
microservice.setPaths(ConfigurePropertyUtils.getMicroservicePaths(configuration));
Map<String, String> propertiesMap = MicroservicePropertiesLoader.INSTANCE.loadProperties(configuration);
microservice.setProperties(propertiesMap);
microservice.setEnvironment(BootStrapProperties.readServiceEnvironment(configuration));
// set alias name when allow cross app
if (microservice.allowCrossApp()) {
microservice.setAlias(Microservice.generateAbsoluteMicroserviceName(microservice.getAppId(), microservice.getServiceName()));
}
microservice.setFramework(createFramework());
microservice.setRegisterBy(CONFIG_DEFAULT_REGISTER_BY);
return microservice;
}
use of org.apache.servicecomb.foundation.common.Version in project java-chassis by ServiceComb.
the class TestVersion method testHashCode.
@Test
public void testHashCode() {
version = new Version(s1, s1, s1, s1);
Assert.assertEquals(version.getVersion().hashCode(), version.hashCode());
}
use of org.apache.servicecomb.foundation.common.Version in project java-chassis by ServiceComb.
the class TestVersion method constructFromStringInvalidBuildNegative.
@Test
public void constructFromStringInvalidBuildNegative() {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage(Matchers.is("build \"-1\" can not be negative, version \"1.1.1.-1\"."));
version = new Version("1.1.1.-1");
}
use of org.apache.servicecomb.foundation.common.Version in project java-chassis by ServiceComb.
the class TestVersion method constructFromStringInvalidPatchDot.
@Test
public void constructFromStringInvalidPatchDot() {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage(Matchers.is("Invalid build \"\", version \"1.1.1.\"."));
expectedException.expectCause(Matchers.instanceOf(NumberFormatException.class));
version = new Version("1.1.1.");
}
Aggregations