com.github.zafarkhaja.semver.ParseException Java Examples

The following examples show how to use com.github.zafarkhaja.semver.ParseException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PackageService.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
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()));
	}
}
 
Example #2
Source File: Version.java    From data-prep with Apache License 2.0 5 votes vote down vote up
public static com.github.zafarkhaja.semver.Version fromInternal(Version internalVersion) {
    String versionId = internalVersion.getVersionId();
    final String versionAsString = StringUtils.substringBefore(versionId, "-");
    try {
        return com.github.zafarkhaja.semver.Version.valueOf(versionAsString);
    } catch (IllegalArgumentException | ParseException e) {
        LOGGER.info("Couldn't parse version {}. Message was: {}", versionId, e.getMessage());
        return com.github.zafarkhaja.semver.Version.forIntegers(0);
    }
}