Search in sources :

Example 1 with VersionComparator

use of com.google.cloud.tools.opensource.dependencies.VersionComparator in project java-cloud-bom by googleapis.

the class DashboardMain method generateAllVersions.

private static void generateAllVersions(String versionlessCoordinates) throws IOException, TemplateException, RepositoryException, URISyntaxException, MavenRepositoryException {
    List<String> elements = Splitter.on(':').splitToList(versionlessCoordinates);
    checkArgument(elements.size() == 2, "The versionless coordinates should have one colon character: " + versionlessCoordinates);
    String groupId = elements.get(0);
    String artifactId = elements.get(1);
    RepositorySystem repositorySystem = RepositoryUtility.newRepositorySystem();
    ImmutableList<String> versions = RepositoryUtility.findVersions(repositorySystem, groupId, artifactId);
    for (String version : versions) {
        if (version.contains("alpha")) {
            continue;
        }
        bomVersions.add(version);
    }
    // Reverse the ordering, placing higher versions first
    VersionComparator comparator = new VersionComparator();
    Collections.sort(bomVersions, (b1, b2) -> comparator.compare(b2, b1));
    bomVersions.add(VersionData.ALL_VERSIONS_NAME);
    for (String version : bomVersions) {
        // are used to collect data for the 'All Versions' page.
        if (!VersionData.ALL_VERSIONS_NAME.equals(version)) {
            generate(Bom.readBom(String.format("%s:%s:%s", groupId, artifactId, version)));
        }
    }
    generateAllVersionsDashboard();
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) VersionComparator(com.google.cloud.tools.opensource.dependencies.VersionComparator)

Example 2 with VersionComparator

use of com.google.cloud.tools.opensource.dependencies.VersionComparator in project cloud-opensource-java by GoogleCloudPlatform.

the class DashboardMain method collectLatestVersions.

private static Map<String, String> collectLatestVersions(List<DependencyGraph> globalDependencies) {
    Map<String, String> latestArtifacts = new TreeMap<>();
    VersionComparator comparator = new VersionComparator();
    if (globalDependencies != null) {
        for (DependencyGraph graph : globalDependencies) {
            Map<String, String> map = graph.getHighestVersionMap();
            for (String key : map.keySet()) {
                String newVersion = map.get(key);
                String oldVersion = latestArtifacts.get(key);
                if (oldVersion == null || comparator.compare(newVersion, oldVersion) > 0) {
                    latestArtifacts.put(key, map.get(key));
                }
            }
        }
    }
    return latestArtifacts;
}
Also used : VersionComparator(com.google.cloud.tools.opensource.dependencies.VersionComparator) DependencyGraph(com.google.cloud.tools.opensource.dependencies.DependencyGraph) TreeMap(java.util.TreeMap)

Example 3 with VersionComparator

use of com.google.cloud.tools.opensource.dependencies.VersionComparator in project cloud-opensource-java by GoogleCloudPlatform.

the class DashboardMain method findUpperBoundsFailures.

private static Map<Artifact, Artifact> findUpperBoundsFailures(Map<String, String> expectedVersionMap, DependencyGraph transitiveDependencies) {
    Map<String, String> actualVersionMap = transitiveDependencies.getHighestVersionMap();
    VersionComparator comparator = new VersionComparator();
    Map<Artifact, Artifact> upperBoundFailures = new LinkedHashMap<>();
    for (String id : expectedVersionMap.keySet()) {
        String expectedVersion = expectedVersionMap.get(id);
        String actualVersion = actualVersionMap.get(id);
        // In both cases, no action is needed.
        if (actualVersion != null && comparator.compare(actualVersion, expectedVersion) < 0) {
            // Maven did not choose highest version
            DefaultArtifact lower = new DefaultArtifact(id + ":" + actualVersion);
            DefaultArtifact upper = new DefaultArtifact(id + ":" + expectedVersion);
            upperBoundFailures.put(lower, upper);
        }
    }
    return upperBoundFailures;
}
Also used : VersionComparator(com.google.cloud.tools.opensource.dependencies.VersionComparator) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with VersionComparator

use of com.google.cloud.tools.opensource.dependencies.VersionComparator in project java-cloud-bom by googleapis.

the class DashboardMain method findUpperBoundsFailures.

private static Map<Artifact, Artifact> findUpperBoundsFailures(Map<String, String> expectedVersionMap, DependencyGraph transitiveDependencies) {
    Map<String, String> actualVersionMap = transitiveDependencies.getHighestVersionMap();
    VersionComparator comparator = new VersionComparator();
    Map<Artifact, Artifact> upperBoundFailures = new LinkedHashMap<>();
    for (String id : expectedVersionMap.keySet()) {
        String expectedVersion = expectedVersionMap.get(id);
        String actualVersion = actualVersionMap.get(id);
        // In both cases, no action is needed.
        if (actualVersion != null && comparator.compare(actualVersion, expectedVersion) < 0) {
            // Maven did not choose highest version
            DefaultArtifact lower = new DefaultArtifact(id + ":" + actualVersion);
            DefaultArtifact upper = new DefaultArtifact(id + ":" + expectedVersion);
            upperBoundFailures.put(lower, upper);
        }
    }
    return upperBoundFailures;
}
Also used : VersionComparator(com.google.cloud.tools.opensource.dependencies.VersionComparator) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

VersionComparator (com.google.cloud.tools.opensource.dependencies.VersionComparator)4 LinkedHashMap (java.util.LinkedHashMap)2 Artifact (org.eclipse.aether.artifact.Artifact)2 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)2 DependencyGraph (com.google.cloud.tools.opensource.dependencies.DependencyGraph)1 TreeMap (java.util.TreeMap)1 RepositorySystem (org.eclipse.aether.RepositorySystem)1