本文整理汇总了Java中com.github.zafarkhaja.semver.Version类的典型用法代码示例。如果您正苦于以下问题:Java Version类的具体用法?Java Version怎么用?Java Version使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Version类属于com.github.zafarkhaja.semver包,在下文中一共展示了Version类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateUploadRequest
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
private void validateUploadRequest(UploadRequest uploadRequest) {
Assert.notNull(uploadRequest.getRepoName(), "Repo name can not be null");
Assert.notNull(uploadRequest.getName(), "Name of package can not be null");
Assert.notNull(uploadRequest.getVersion(), "Version can not be null");
try {
Version.valueOf(uploadRequest.getVersion().trim());
}
catch (ParseException e) {
throw new SkipperException("UploadRequest doesn't have a valid semantic version. Version = " +
uploadRequest.getVersion().trim());
}
Assert.notNull(uploadRequest.getExtension(), "Extension can not be null");
Assert.isTrue(uploadRequest.getExtension().equals("zip"), "Extension must be 'zip', not "
+ uploadRequest.getExtension());
Assert.notNull(uploadRequest.getPackageFileAsBytes(), "Package file as bytes must not be null");
Assert.isTrue(uploadRequest.getPackageFileAsBytes().length != 0, "Package file as bytes must not be empty");
PackageMetadata existingPackageMetadata = this.packageMetadataRepository.findByRepositoryNameAndNameAndVersion(
uploadRequest.getRepoName().trim(), uploadRequest.getName().trim(), uploadRequest.getVersion().trim());
if (existingPackageMetadata != null) {
throw new SkipperException(String.format("Failed to upload the package. " + "" +
"Package [%s:%s] in Repository [%s] already exists.",
uploadRequest.getName(), uploadRequest.getVersion(), uploadRequest.getRepoName().trim()));
} }
示例2: main
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
public static void main(String[] args) {
Locale.setDefault(Locale.US);
org.apache.log4j.BasicConfigurator.configure();
try {
Properties properties = new Properties();
InputStream stream = Application.class.getResourceAsStream("application.properties");
properties.load(stream);
stream.close();
version = Version.valueOf(properties.getProperty("version"));
} catch (IOException e) {
e.printStackTrace();
}
launch(args);
}
示例3: readFromZip
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
public static Project readFromZip(Path target) throws IOException {
final Version version = readFileVersion(target);
Application.getDatastorage().flush();
logger.info("Loading project made with version " + version.toString());
boolean useBase64Images = version.lessThan(Version.forIntegers(0, 3, 0));
if (!useBase64Images) {
// Extract images form the archive
ZipUtil.unpack(target.toFile(), Application.getDatastorage().getPath().toFile(), new NameMapper() {
@Override
public String map(String name) {
if (name.startsWith("data/")) {
logger.debug("Found file in archive " + name);
return name.substring(5);
} else {
return null;
}
}
});
}
final Gson gson = buildGson(useBase64Images ? ImageType.BASE64 : ImageType.REFERENCE);
return fromBytes(ZipUtil.unpackEntry(target.toFile(), PROJECT_JSON_FILENAME), gson);
}
示例4: compare
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
@Override
public int compare(LibProfile p0, LibProfile p1) {
if (p0.description.name.equals(p1.description.name)) {
try {
// Compare by version string according to SemVer rules
Version v0 = VersionWrapper.valueOf(p0.description.version);
Version v1 = VersionWrapper.valueOf(p1.description.version);
return v0.compareWithBuildsTo(v1);
} catch (Exception e) {
// if versions do not adhere to semver rules and cannot be
// easily transformed into compliant version string,
// do string compare as fallback
return p0.description.version.compareTo(p1.description.version);
}
}
return p0.description.name.compareTo(p1.description.name);
}
示例5: getUniqueLibraries
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
/**
* Given a number of profiles, return distinct libraries with their highest version
* @param profiles
* @return a {@link Map} containing unique library names -> highest version
*/
public static Map<String,String> getUniqueLibraries(Collection<LibProfile> profiles) {
HashMap<String,String> result = new HashMap<String,String>();
for (LibProfile p: profiles) {
if (!result.containsKey(p.description.name))
result.put(p.description.name, p.description.version);
else {
try {
Version v1 = VersionWrapper.valueOf(result.get(p.description.name));
Version v2 = VersionWrapper.valueOf(p.description.version);
if (v2.greaterThan(v1))
result.put(p.description.name, p.description.version);
} catch (Exception e) { /* if at least one version is not semver compliant */ }
}
}
return result;
}
示例6: parseVersion
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
public static String parseVersion(String version) {
if (!version.startsWith("(") && !version.startsWith("[")) {
// first see if it actually is a range
try {
Version.valueOf(version);
}
catch (Exception e) {
// remove ^ for wildcard ranges
if ((version.startsWith("^") || version.startsWith("||")) && (version.contains("x")
|| version.contains("X") || version.contains("*"))) {
version = version.substring(1);
}
try {
version = ExpressionParser.newInstance().parse(version).mavenRange();
}
catch (Exception ex) {
throw new ManifestParsingException("Unable to parse version range %s.",
version);
}
}
}
return version;
}
示例7: version
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
static Version version() throws IOException, InterruptedException {
Command dockerCompose = new Command(new Executable() {
@Override
public String commandName() {
return "docker-compose";
}
@Override
public Process execute(String... commands) throws IOException {
List<String> args = ImmutableList.<String>builder()
.add(defaultDockerComposePath())
.add(commands)
.build();
return new ProcessBuilder(args).redirectErrorStream(true).start();
}
}, log::trace);
String versionOutput = dockerCompose.execute(Command.throwingOnError(), "-v");
return DockerComposeVersion.parseFromDockerComposeVersion(versionOutput);
}
示例8: testStateChanges_withHealthCheck
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
/**
* This test is not currently enabled in Circle as it does not provide a sufficiently recent version of docker-compose.
*
* @see <a href="https://github.com/palantir/docker-compose-rule/issues/156">Issue #156</a>
*/
@Test
public void testStateChanges_withHealthCheck() throws IOException, InterruptedException {
assumeThat("docker version", Docker.version(), new GreaterOrEqual<>(Version.forIntegers(1, 12, 0)));
assumeThat("docker-compose version", DockerCompose.version(), new GreaterOrEqual<>(Version.forIntegers(1, 10, 0)));
DockerCompose dockerCompose = new DefaultDockerCompose(
DockerComposeFiles.from("src/test/resources/native-healthcheck.yaml"),
dockerMachine,
ProjectName.random());
// The withHealthcheck service's healthcheck checks every 100ms whether the file "healthy" exists
Container container = new Container("withHealthcheck", docker, dockerCompose);
assertEquals(State.DOWN, container.state());
container.up();
assertEquals(State.UNHEALTHY, container.state());
dockerCompose.exec(noOptions(), "withHealthcheck", arguments("touch", "healthy"));
wait.until(container::state, equalTo(State.HEALTHY));
dockerCompose.exec(noOptions(), "withHealthcheck", arguments("rm", "healthy"));
wait.until(container::state, equalTo(State.UNHEALTHY));
container.kill();
assertEquals(State.DOWN, container.state());
}
示例9: runtimeEnvironmentInfo
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
private RuntimeEnvironmentInfo runtimeEnvironmentInfo(Class spiClass, Class implementationClass) {
CloudFoundryClient client = connectionConfiguration.cloudFoundryClient(
connectionConfiguration.connectionContext(connectionConfiguration.cloudFoundryConnectionProperties()),
connectionConfiguration.tokenProvider(connectionConfiguration.cloudFoundryConnectionProperties()));
Version version = connectionConfiguration.version(client);
return new RuntimeEnvironmentInfo.Builder()
.implementationName(implementationClass.getSimpleName())
.spiClass(spiClass)
.implementationVersion(RuntimeVersionUtils.getVersion(CloudFoundryAppDeployer.class))
.platformType("Cloud Foundry")
.platformClientVersion(RuntimeVersionUtils.getVersion(client.getClass()))
.platformApiVersion(version.toString())
.platformHostVersion("unknown")
.addPlatformSpecificInfo("API Endpoint", connectionConfiguration.cloudFoundryConnectionProperties().getUrl().toString())
.build();
}
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-cloudfoundry,代码行数:17,代码来源:CloudFoundryDeployerAutoConfiguration.java
示例10: versionNameConditionMet
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
private boolean versionNameConditionMet(final String versionName, final Element element) {
// Drop out quickly if there's no versionName set otherwise the try/catch below is doomed to fail.
if (versionName.isEmpty()) return false;
int comparison;
try {
final Version conditionVersion = Version.valueOf(versionName);
final Version currentVersion = Version.valueOf(this.versionName);
comparison = Version.BUILD_AWARE_ORDER.compare(conditionVersion, currentVersion);
} catch (final IllegalArgumentException | com.github.zafarkhaja.semver.ParseException e) {
messager.printMessage(Diagnostic.Kind.ERROR, String.format("Failed to parse versionName: %1$s. " +
"Please use a versionName that matches the specification on http://semver.org/", versionName),
element);
// Assume the break condition is met if the versionName is invalid.
return true;
}
return !versionName.isEmpty() && comparison <= 0;
}
示例11: inferScope
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
public static Optional<Scope> inferScope(Version before, Version after) {
int major = after.getMajorVersion() - before.getMajorVersion();
int minor = after.getMinorVersion() - before.getMinorVersion();
int patch = after.getPatchVersion() - before.getPatchVersion();
if (major == 1 && after.getMinorVersion() == 0 && after.getPatchVersion() == 0) {
return Optional.of(Scope.MAJOR);
} else if (major == 0 && minor == 1 && after.getPatchVersion() == 0) {
return Optional.of(Scope.MINOR);
} else if (major == 0 && minor == 0 && patch == 1) {
return Optional.of(Scope.PATCH);
} else {
logger.debug(
"Invalid increment between the following versions. Cannot infer scope between: {} -> {}",
before,
after);
return Optional.empty();
}
}
示例12: createVersionWithOptionalSuffix
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
@VisibleForTesting
static String createVersionWithOptionalSuffix(
@NonNull final String versionStr,
final String suffix)
{
final Version version;
if (suffix == null || "".equals(suffix) || versionStr.endsWith(suffix))
{
// there is no suffix, or the same suffix was already added earlier when a migration was not completed
version = Version.valueOf(versionStr);
}
else
{
final Version tmp = Version.valueOf(versionStr);
version = tmp.setBuildMetadata(tmp.getBuildMetadata() + "x" + suffix);
}
return version.toString();
}
示例13: initLegacySupport
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
protected void initLegacySupport() {
String currentVersionStr = "0.0.0";
try {
// we use reflection, because otherwise the compile time version would be "stamped" into the jar
Field versionName = BaseNoGui.class.getField("VERSION_NAME");
currentVersionStr = (String) versionName.get(null);
} catch (NoSuchFieldException | SecurityException
| IllegalArgumentException | IllegalAccessException e) {
log("Error getting the Arduino IDE version", e);
}
Version currentVersion = VersionHelper.valueOf(currentVersionStr);
Version v165 = VersionHelper.valueOf("1.6.5");
if (currentVersion.lessThan(v165)) {
log("WARNING! Your Arduino IDE v" + currentVersion + " is too old. Flowerino Plugin "
+ "has been tested with Arduino IDE starting with v" + v165 + ". Unexpected errors may appear.");
} else if (currentVersion.lessThan(VersionHelper.valueOf("1.6.6"))) {
libraryInstallerWrapper = new LibraryInstallerWrapperPre166();
} else {
libraryInstallerWrapper = new LibraryInstallerWrapper();
}
}
开发者ID:flower-platform,项目名称:flower-platform-arduino-ide-plugin,代码行数:22,代码来源:FlowerPlatformPlugin.java
示例14: isVersionSupported
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
@Override
public boolean isVersionSupported(String platform, String version) {
checkNotNull(platform);
checkNotNull(version);
// get the semantic version expression for the platform
String expression = platformMap.get(platform);
LOGGER.debug("Check {} against {}", version, expression);
if (null != expression) {
return Version.valueOf(version).satisfies(expression);
} else {
// If no rule is available for a platform return true as default
return true;
}
}
示例15: test
import com.github.zafarkhaja.semver.Version; //导入依赖的package包/类
@Test
public void test() {
// Wildcard - 1.* which is equivalent to >=1.0.0 & <2.0.0
// Tilde operator - ~1.5 which is equivalent to >=1.5.0 & <2.0.0
// Range - 1.0-2.0 which is equivalent to >=1.0.0 & <=2.0.0
// Negation operator - !(1.*) which is equivalent to <1.0.0 & >=2.0.0
// Short notation - 1 which is equivalent to =1.0.0
// Parenthesized expression - ~1.3 | (1.4.* & !=1.4.5) | ~2
assertThat(Version.valueOf("1.0.0-beta").satisfies(">=1.0.0 & <2.0.0"), is(false));
assertThat(Version.valueOf("1.5.0").satisfies(">=1.0.0 & < 2.0.0"), is(true));
assertThat(Version.valueOf("1.5.0").satisfies("~1.0"), is(true));
}