Search in sources :

Example 6 with DefaultArtifactVersion

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;
}
Also used : Archetype(org.apache.maven.archetype.catalog.Archetype) HashMap(java.util.HashMap) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 7 with DefaultArtifactVersion

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");
    }
}
Also used : Scanner(java.util.Scanner) Matcher(java.util.regex.Matcher) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Nonnull(javax.annotation.Nonnull)

Example 8 with DefaultArtifactVersion

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;
}
Also used : DependencyArtifact(com.microsoft.azure.toolkit.intellij.springcloud.dependency.DependencyArtifact) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion)

Example 9 with DefaultArtifactVersion

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;
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion)

Example 10 with DefaultArtifactVersion

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);
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) Matcher(java.util.regex.Matcher) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion)

Aggregations

DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)37 ArtifactVersion (org.apache.maven.artifact.versioning.ArtifactVersion)12 File (java.io.File)8 IOException (java.io.IOException)7 Model (org.apache.maven.model.Model)5 FileNotFoundException (java.io.FileNotFoundException)4 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)4 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 Artifact (org.apache.maven.artifact.Artifact)3 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)3 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)3 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)3 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)3 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)3 FileReader (java.io.FileReader)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2