Search in sources :

Example 1 with DependencyArtifact

use of com.microsoft.azure.toolkit.intellij.springcloud.dependency.DependencyArtifact 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 2 with DependencyArtifact

use of com.microsoft.azure.toolkit.intellij.springcloud.dependency.DependencyArtifact in project azure-tools-for-java by Microsoft.

the class SpringCloudDependencyManager method collectDependencyVersionsFromNodes.

private static void collectDependencyVersionsFromNodes(List<Node> nodes, Map<String, DependencyArtifact> versionMap) {
    for (Node node : nodes) {
        String groupId = ((Element) node).elementTextTrim("groupId");
        String artifactId = ((Element) node).elementTextTrim("artifactId");
        DependencyArtifact artifact = new DependencyArtifact(groupId, artifactId, ((Element) node).elementTextTrim("version"));
        versionMap.put(artifact.getKey(), artifact);
    }
}
Also used : DependencyArtifact(com.microsoft.azure.toolkit.intellij.springcloud.dependency.DependencyArtifact) Node(org.dom4j.Node) Element(org.dom4j.Element)

Aggregations

DependencyArtifact (com.microsoft.azure.toolkit.intellij.springcloud.dependency.DependencyArtifact)2 AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)1 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)1 Element (org.dom4j.Element)1 Node (org.dom4j.Node)1