use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project BIMserver by opensourceBIM.
the class MavenPluginLocation method getLatestVersion.
public MavenPluginVersion getLatestVersion() {
Artifact artifact = new DefaultArtifact(groupId + ":" + artifactId + ":LATEST");
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.setRepositories(mavenPluginRepository.getRepositories());
try {
VersionRangeResult rangeResult = mavenPluginRepository.getSystem().resolveVersionRange(mavenPluginRepository.getSession(), rangeRequest);
List<Version> versions = rangeResult.getVersions();
if (!versions.isEmpty()) {
Version version = versions.get(0);
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
Artifact versionArtifact = new DefaultArtifact(groupId + ":" + artifactId + ":pom:" + version.toString());
descriptorRequest.setArtifact(versionArtifact);
descriptorRequest.setRepositories(mavenPluginRepository.getRepositories());
MavenPluginVersion mavenPluginVersion = new MavenPluginVersion(versionArtifact, version);
ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(descriptorResult.getArtifact());
request.setRepositories(mavenPluginRepository.getRepositories());
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
File pomFile = resolveArtifact.getArtifact().getFile();
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try (FileReader fileReader = new FileReader(pomFile)) {
try {
Model model = mavenreader.read(fileReader);
mavenPluginVersion.setModel(model);
} catch (XmlPullParserException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
for (org.eclipse.aether.graph.Dependency dependency : descriptorResult.getDependencies()) {
DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(dependency.getArtifact().getVersion());
mavenPluginVersion.addDependency(new MavenDependency(dependency.getArtifact(), artifactVersion));
}
return mavenPluginVersion;
}
} catch (VersionRangeResolutionException e) {
e.printStackTrace();
} catch (ArtifactDescriptorException e) {
e.printStackTrace();
} catch (ArtifactResolutionException e) {
e.printStackTrace();
}
return null;
}
use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project maven-git-versioning-extension by qoomon.
the class VersioningModelProcessor method deduceProjectVersion.
private ProjectVersion deduceProjectVersion(GAV gav, File gitDir) throws IOException {
FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder().findGitDir(gitDir);
logger.debug(gav + "git directory " + repositoryBuilder.getGitDir());
try (Repository repository = repositoryBuilder.build()) {
final String headCommit = getHeadCommit(repository);
String projectBranchName = null;
String projectTagName = null;
VersionFormatDescription projectVersionFormatDescription = null;
Map<String, String> projectVersionDataMap = buildCommonVersionDataMap(headCommit, gav);
if (!configuration.getTagVersionDescriptions().isEmpty()) {
final List<String> headTags = getHeadTags(repository);
if (!headTags.isEmpty()) {
for (VersionFormatDescription versionFormatDescription : configuration.getTagVersionDescriptions()) {
String tagName = headTags.stream().sequential().filter(tag -> tag.matches(versionFormatDescription.pattern)).sorted((versionLeft, versionRight) -> {
DefaultArtifactVersion tagVersionLeft = new DefaultArtifactVersion(removePrefix(versionLeft, versionFormatDescription.prefix));
DefaultArtifactVersion tagVersionRight = new DefaultArtifactVersion(removePrefix(versionRight, versionFormatDescription.prefix));
// -1 revert sorting, latest version first
return tagVersionLeft.compareTo(tagVersionRight) * -1;
}).findFirst().orElse(null);
if (tagName != null) {
projectTagName = tagName;
projectVersionFormatDescription = versionFormatDescription;
projectVersionDataMap.put("tag", removePrefix(projectTagName, projectVersionFormatDescription.prefix));
projectVersionDataMap.putAll(getRegexGroupValueMap(projectVersionFormatDescription.pattern, projectTagName));
break;
}
}
}
}
if (projectTagName == null) {
final String branchName = getHeadBranch(repository).orElseThrow(() -> new ModelParseException(gitDir + ": No Branch Name provided in Detached HEAD state. See documentation.", 0, 0));
projectBranchName = branchName;
projectVersionFormatDescription = configuration.getBranchVersionDescriptions().stream().filter(versionFormatDescription -> branchName.matches(versionFormatDescription.pattern)).findFirst().orElseThrow(() -> new ModelParseException(gitDir + ": No version format for branch '" + branchName + "' found.", 0, 0));
projectVersionDataMap.put("branch", removePrefix(projectBranchName, projectVersionFormatDescription.prefix));
projectVersionDataMap.putAll(getRegexGroupValueMap(projectVersionFormatDescription.pattern, projectBranchName));
}
String version = StrSubstitutor.replace(projectVersionFormatDescription.versionFormat, projectVersionDataMap);
ProjectVersion projectVersion = new ProjectVersion(escapeVersion(version), headCommit, projectBranchName, projectTagName);
logger.info(gav.getArtifactId() + ":" + gav.getVersion() + (projectVersion.getTag() != null ? " - tag: " + projectVersion.getTag() : "") + (projectVersion.getTag() != null ? " - branch: " + projectVersion.getBranch() : "") + " -> version: " + projectVersion.getVersion());
return projectVersion;
}
}
use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project liferay-ide by liferay.
the class MavenUtil method getVersion.
public static String getVersion(String version) {
String retval = null;
DefaultArtifactVersion v = new DefaultArtifactVersion(version);
retval = v.getMajorVersion() + "." + v.getMinorVersion() + "." + v.getIncrementalVersion();
if ("0.0.0".equals(retval)) {
retval = v.getQualifier();
}
try {
Version.parseVersion(retval);
} catch (Exception e) {
retval = "0.0.0";
}
return retval;
}
use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project herd by FINRAOS.
the class EmrClusterDefinitionHelper method validateEmrClusterDefinitionConfiguration.
/**
* Validates an EMR cluster definition configuration.
*
* @param emrClusterDefinition the EMR cluster definition configuration
*
* @throws IllegalArgumentException if any validation errors were found
*/
public void validateEmrClusterDefinitionConfiguration(EmrClusterDefinition emrClusterDefinition) throws IllegalArgumentException {
Assert.notNull(emrClusterDefinition, "An EMR cluster definition configuration must be specified.");
Assert.isTrue(StringUtils.isNotBlank(emrClusterDefinition.getSubnetId()), "Subnet ID must be specified");
for (String token : emrClusterDefinition.getSubnetId().split(",")) {
Assert.isTrue(StringUtils.isNotBlank(token), "No blank is allowed in the list of subnet IDs");
}
Assert.isTrue(!emrHelper.isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions()) || CollectionUtils.isNotEmpty(emrClusterDefinition.getInstanceFleets()), "Instance group definitions or instance fleets must be specified.");
if (!emrHelper.isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions())) {
// Check master instances.
Assert.notNull(emrClusterDefinition.getInstanceDefinitions().getMasterInstances(), "Master instances must be specified.");
validateMasterInstanceDefinition(emrClusterDefinition.getInstanceDefinitions().getMasterInstances());
// Check core instances.
if (emrClusterDefinition.getInstanceDefinitions().getCoreInstances() != null) {
validateInstanceDefinition("core", emrClusterDefinition.getInstanceDefinitions().getCoreInstances(), 0);
// If instance count is <= 0, remove the entire core instance definition since it is redundant.
if (emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceCount() <= 0) {
emrClusterDefinition.getInstanceDefinitions().setCoreInstances(null);
}
}
// Check task instances
if (emrClusterDefinition.getInstanceDefinitions().getTaskInstances() != null) {
validateInstanceDefinition("task", emrClusterDefinition.getInstanceDefinitions().getTaskInstances(), 1);
}
// Check that total number of instances does not exceed the max allowed.
int maxEmrInstanceCount = configurationHelper.getProperty(ConfigurationValue.MAX_EMR_INSTANCES_COUNT, Integer.class);
if (maxEmrInstanceCount > 0) {
int instancesRequested = emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceCount();
if (emrClusterDefinition.getInstanceDefinitions().getCoreInstances() != null) {
instancesRequested += emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceCount();
}
if (emrClusterDefinition.getInstanceDefinitions().getTaskInstances() != null) {
instancesRequested += emrClusterDefinition.getInstanceDefinitions().getTaskInstances().getInstanceCount();
}
Assert.isTrue((maxEmrInstanceCount >= instancesRequested), "Total number of instances requested can not exceed : " + maxEmrInstanceCount);
}
}
// Validate node tags including checking for required tags and detecting any duplicate node tag names in case sensitive manner.
Assert.notEmpty(emrClusterDefinition.getNodeTags(), "Node tags must be specified.");
HashSet<String> nodeTagNameValidationSet = new HashSet<>();
for (NodeTag nodeTag : emrClusterDefinition.getNodeTags()) {
Assert.hasText(nodeTag.getTagName(), "A node tag name must be specified.");
Assert.hasText(nodeTag.getTagValue(), "A node tag value must be specified.");
Assert.isTrue(!nodeTagNameValidationSet.contains(nodeTag.getTagName()), String.format("Duplicate node tag \"%s\" is found.", nodeTag.getTagName()));
nodeTagNameValidationSet.add(nodeTag.getTagName());
}
// Validate the mandatory AWS tags are there
for (String mandatoryTag : herdStringHelper.splitStringWithDefaultDelimiter(configurationHelper.getProperty(ConfigurationValue.MANDATORY_AWS_TAGS))) {
Assert.isTrue(nodeTagNameValidationSet.contains(mandatoryTag), String.format("Mandatory AWS tag not specified: \"%s\"", mandatoryTag));
}
emrClusterDefinition.setAdditionalMasterSecurityGroups(assertNotBlankAndTrim(emrClusterDefinition.getAdditionalMasterSecurityGroups(), "additionalMasterSecurityGroup"));
emrClusterDefinition.setAdditionalSlaveSecurityGroups(assertNotBlankAndTrim(emrClusterDefinition.getAdditionalSlaveSecurityGroups(), "additionalSlaveSecurityGroup"));
// Fail if security configuration is specified for EMR version less than 4.8.0.
if (StringUtils.isNotBlank(emrClusterDefinition.getSecurityConfiguration())) {
final DefaultArtifactVersion securityConfigurationMinEmrVersion = new DefaultArtifactVersion("4.8.0");
Assert.isTrue(StringUtils.isNotBlank(emrClusterDefinition.getReleaseLabel()) && securityConfigurationMinEmrVersion.compareTo(new DefaultArtifactVersion(emrClusterDefinition.getReleaseLabel().replaceFirst("^(emr-)", ""))) <= 0, "EMR security configuration is not supported prior to EMR release 4.8.0.");
}
}
use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project azure-tools-for-java by Microsoft.
the class WhatsNewAction method actionPerformed.
@Override
@AzureOperation(name = "common.load_whatsnew", type = AzureOperation.Type.ACTION)
public void actionPerformed(@Nonnull final AnActionEvent event) {
final boolean manually = !"AzurePluginStartupActivity".equals(event.getPlace());
final String content = getWhatsNewContent();
final DefaultArtifactVersion currentVersion = getVersion(content);
final DefaultArtifactVersion lastVersion = getLastVersion();
if (manually || compare(currentVersion, lastVersion)) {
saveVersion(currentVersion);
doShow(content, currentVersion, manually, Objects.requireNonNull(event.getProject()));
}
}
Aggregations