use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project maven-archetype by apache.
the class DefaultArchetypeSelectionQueryer method selectVersion.
private Archetype selectVersion(Map<String, List<Archetype>> catalogs, String groupId, String artifactId) throws PrompterException {
SortedMap<ArtifactVersion, Archetype> archetypeVersionsMap = new TreeMap<ArtifactVersion, Archetype>();
for (Map.Entry<String, List<Archetype>> entry : catalogs.entrySet()) {
for (Archetype archetype : entry.getValue()) {
if (!groupId.equals(archetype.getGroupId()) || !artifactId.equals(archetype.getArtifactId())) {
continue;
}
ArtifactVersion version = new DefaultArtifactVersion(archetype.getVersion());
// don't override the first catalog containing a defined version of the artifact
if (!archetypeVersionsMap.containsKey(version)) {
archetypeVersionsMap.put(version, archetype);
}
}
}
if (archetypeVersionsMap.size() == 1) {
return archetypeVersionsMap.values().iterator().next();
}
// let the user choose between available versions
StringBuilder query = new StringBuilder("Choose " + groupId + ":" + artifactId + " version: \n");
List<String> answers = new ArrayList<String>();
Map<String, Archetype> answerMap = new HashMap<String, Archetype>();
int counter = 1;
String mapKey = null;
for (Map.Entry<ArtifactVersion, Archetype> entry : archetypeVersionsMap.entrySet()) {
ArtifactVersion version = entry.getKey();
Archetype archetype = entry.getValue();
mapKey = String.valueOf(counter);
query.append(mapKey + ": " + version + "\n");
answers.add(mapKey);
answerMap.put(mapKey, archetype);
counter++;
}
query.append("Choose a number: ");
Archetype archetype = null;
do {
String answer = prompter.prompt(query.toString(), answers, mapKey);
archetype = answerMap.get(answer);
} while (archetype == null);
return archetype;
}
use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project azure-tools-for-java by Microsoft.
the class WhatsNewAction method getVersion.
@Nonnull
private static DefaultArtifactVersion getVersion(String content) {
try (final Scanner scanner = new Scanner(content)) {
// Read the first comment line to get the whats new version
final String versionLine = scanner.nextLine();
final Matcher matcher = Pattern.compile(VERSION_PATTERN).matcher(versionLine);
return matcher.matches() ? new DefaultArtifactVersion(matcher.group(1)) : new DefaultArtifactVersion("0");
}
}
use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project azure-tools-for-java by Microsoft.
the class SpringCloudDependencyManager method getCompatibleVersions.
public static List<DependencyArtifact> getCompatibleVersions(List<DependencyArtifact> dependencies, String springBootVersionStr) throws AzureExecutionException, IOException, DocumentException {
List<DependencyArtifact> res = new ArrayList<>();
DefaultArtifactVersion springBootVersion = new DefaultArtifactVersion(springBootVersionStr);
for (DependencyArtifact dependency : dependencies) {
if (StringUtils.isNotEmpty(dependency.getCurrentVersion()) && isCompatibleVersion(dependency.getCurrentVersion(), springBootVersionStr)) {
continue;
}
List<String> latestVersions = getMavenCentralVersions(dependency.getGroupId(), dependency.getArtifactId());
String targetVersionText = getCompatibleVersionWithBootVersion(latestVersions, springBootVersion);
if (StringUtils.isEmpty(targetVersionText)) {
if (isGreaterOrEqualVersion(springBootVersionStr, LATEST_SPRING_BOOT_RELEASE) && !latestVersions.isEmpty()) {
// to handle the ege case: spring-cloud-starter-config 2.2.5.RELEASE supports spring boot 2.3.0
// here for newest spring boot versions, use the latest versions
targetVersionText = latestVersions.get(latestVersions.size() - 1);
} else {
throw new AzureExecutionException(String.format("Cannot get compatible version for %s:%s with Spring Boot with version %s", dependency.getGroupId(), dependency.getArtifactId(), springBootVersionStr));
}
}
dependency.setCompatibleVersion(targetVersionText);
if (!StringUtils.equals(dependency.getCurrentVersion(), targetVersionText)) {
res.add(dependency);
}
}
return res;
}
use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project azure-tools-for-java by Microsoft.
the class SpringCloudDependencyManager method isGreaterOrEqualVersion.
public static boolean isGreaterOrEqualVersion(String versionStr1, String versionStr2) {
DefaultArtifactVersion version1 = new DefaultArtifactVersion(versionStr1);
DefaultArtifactVersion version2 = new DefaultArtifactVersion(versionStr2);
return version1.compareTo(version2) >= 0;
}
use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project spring-boot by spring-projects.
the class CombinedPatchAndQualifierDependencyVersion method parse.
static CombinedPatchAndQualifierDependencyVersion parse(String version) {
Matcher matcher = PATTERN.matcher(version);
if (!matcher.matches()) {
return null;
}
ArtifactVersion artifactVersion = new DefaultArtifactVersion(matcher.group(1) + "." + matcher.group(2));
if (artifactVersion.getQualifier() != null && artifactVersion.getQualifier().equals(version)) {
return null;
}
return new CombinedPatchAndQualifierDependencyVersion(artifactVersion, version);
}
Aggregations