Search in sources :

Example 6 with ComparableVersion

use of org.apache.maven.artifact.versioning.ComparableVersion in project tbd-studio-se by Talend.

the class AbstractDependencyResolver method getVersionByHadoopVersion.

protected String getVersionByHadoopVersion(List<String> versionRange, String hadoopVersion) throws Exception {
    List<Pattern> patterns = getDistributionPatterns();
    String result = null;
    for (String version : versionRange) {
        for (Pattern pattern : patterns) {
            Matcher matcher = pattern.matcher(version);
            if (matcher.find()) {
                String group = matcher.group(1);
                if (group.equals(hadoopVersion)) {
                    // Exact match
                    return version;
                } else if (matcher.groupCount() > 1) {
                    // Fuzzy match - Computing the newest version found for the same Major.Minor.Patch
                    // $NON-NLS-1$ //$NON-NLS-2$
                    String majorMinorPatchVersion = matcher.group(2).replaceFirst(".$", "");
                    if (hadoopVersion.startsWith(majorMinorPatchVersion)) {
                        if (result == null || new ComparableVersion(version).compareTo(new ComparableVersion(result)) > 0) {
                            result = version;
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion)

Example 7 with ComparableVersion

use of org.apache.maven.artifact.versioning.ComparableVersion in project sling by apache.

the class MavenBundlePluginProjectConfigurator method isSupportingM2eIncrementalBuild.

@Override
protected boolean isSupportingM2eIncrementalBuild(MavenProject mavenProject, Logger logger) {
    Plugin bundlePlugin = mavenProject.getPlugin(MAVEN_BUNDLE_PLUGIN_KEY);
    if (bundlePlugin == null) {
        logger.warn("maven-bundle-plugin not configured!");
        return false;
    } else {
        // check if m2elipse-tycho is already installed (which supports incremental builds for "bundle" packagings
        if (LifecycleMappingFactory.createProjectConfigurator(M2E_TYCHO_EXTENSION_PROJECT_CONFIGURATOR_ID) != null) {
            logger.trace("Project configurator with id '" + M2E_TYCHO_EXTENSION_PROJECT_CONFIGURATOR_ID + "' found -> m2e-tycho installed.");
            return true;
        }
        String version = bundlePlugin.getVersion();
        if (version == null) {
            logger.warn("Could not retrieve used version of maven-bundle-plugin!");
            return false;
        }
        ComparableVersion comparableVersion = new ComparableVersion(version);
        // with https://issues.apache.org/jira/browse/FELIX-4009 m2e support for incremental builds was added to maven-bundle-plugin in version 3.2.0
        if (comparableVersion.compareTo(new ComparableVersion("3.2.0")) >= 0) {
            // therefore check configuration
            for (PluginExecution pluginExecution : bundlePlugin.getExecutions()) {
                if (!pluginExecution.getGoals().contains("manifest")) {
                    continue;
                }
                Xpp3Dom configuration = (Xpp3Dom) pluginExecution.getConfiguration();
                Xpp3Dom supportIncrementalBuildConfiguration = configuration.getChild("supportIncrementalBuild");
                // https://issues.apache.org/jira/browse/FELIX-3324
                Xpp3Dom exportScrConfiguration = configuration.getChild("exportScr");
                if (supportIncrementalBuildConfiguration == null || !Boolean.parseBoolean(supportIncrementalBuildConfiguration.getValue())) {
                    logger.warn("Although using maven-bundle-plugin in a version >= 3.2.0, the incremental build support was not enabled.");
                } else if (exportScrConfiguration == null || !Boolean.parseBoolean(exportScrConfiguration.getValue())) {
                    logger.warn("Although using maven-bundle-plugin in a version >= 3.2.0 with incremental build support enabled, component descriptors are not exported (exportScr=false) .");
                } else {
                    logger.trace("Using maven-bundle-plugin in a version >= 3.2.0 with the incremental build support correctly enabled.");
                    return true;
                }
            }
        } else {
            logger.warn("maven-bundle-plugin in a version < 3.2.0 does not natively support incremental builds.");
        }
    }
    return false;
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) Plugin(org.apache.maven.model.Plugin)

Example 8 with ComparableVersion

use of org.apache.maven.artifact.versioning.ComparableVersion in project embulk by embulk.

the class EmbulkMigrate method migratePlugin.

public void migratePlugin(final Path path, final String thisEmbulkVersion) throws IOException {
    final Migrator migrator = new Migrator(path);
    List<Matcher> matchedEmbulkCoreInGradle = migrator.matchersRecursive("build.gradle", EMBULK_CORE_IN_GRADLE);
    List<Matcher> matchedNewEmbulkInGemspec = migrator.matchersRecursive("*.gemspec", NEW_EMBULK_IN_GEMSPEC);
    List<Matcher> matchedOldEmbulkInGemspec = migrator.matchersRecursive("*.gemspec", OLD_EMBULK_IN_GEMSPEC);
    final Language language;
    final ComparableVersion fromVersion;
    if (!matchedEmbulkCoreInGradle.isEmpty()) {
        language = Language.JAVA;
        fromVersion = new ComparableVersion(matchedEmbulkCoreInGradle.get(0).group(1).replace("+", "0"));
        System.out.printf("Detected Java plugin for Embulk %s...\n", fromVersion.toString());
    } else if (!matchedNewEmbulkInGemspec.isEmpty()) {
        language = Language.RUBY;
        fromVersion = new ComparableVersion(matchedNewEmbulkInGemspec.get(0).group(1));
        System.out.printf("Detected Ruby plugin for Embulk %s...\n", fromVersion.toString());
    } else if (!matchedOldEmbulkInGemspec.isEmpty()) {
        language = Language.RUBY;
        fromVersion = new ComparableVersion("0.1.0");
        System.out.println("Detected Ruby plugin for unknown Embulk version...");
    } else {
        throw new RuntimeException("Failed to detect plugin language and dependency version");
    }
    switch(language) {
        case JAVA:
            migrateJavaPlugin(migrator, fromVersion, thisEmbulkVersion);
            break;
        case RUBY:
            migrateRubyPlugin(migrator, fromVersion, thisEmbulkVersion);
            break;
        // Never default as all enums are listed.
        default:
    }
    if (migrator.getModifiedFiles().isEmpty()) {
        System.out.println("Done. No files are modified.");
    } else {
        System.out.println("Done. Please check modified files.");
    }
}
Also used : Matcher(java.util.regex.Matcher) PathMatcher(java.nio.file.PathMatcher) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion)

Example 9 with ComparableVersion

use of org.apache.maven.artifact.versioning.ComparableVersion in project hazelcast by hazelcast.

the class SpringSchemasValidityTest method testPermaLinkIsLatestVersion.

@Test
public void testPermaLinkIsLatestVersion() {
    Pattern pattern = Pattern.compile("hazelcast-spring-([0-9\\.]+)\\.xsd");
    ComparableVersion latestVersion = null;
    String latestVersionXsdFile = null;
    for (Object o : prop.values()) {
        String xsd = o.toString();
        Matcher matcher = pattern.matcher(xsd);
        assertTrue(matcher.matches());
        String versionCode = matcher.group(1);
        if (latestVersion == null) {
            latestVersion = new ComparableVersion(versionCode);
            latestVersionXsdFile = xsd;
        } else {
            ComparableVersion current = new ComparableVersion(versionCode);
            if (current.compareTo(latestVersion) > 0) {
                latestVersion = current;
                latestVersionXsdFile = xsd;
            }
        }
    }
    String latestBySpringSchemas = prop.getProperty("https://www.hazelcast.com/schema/spring/hazelcast-spring.xsd");
    assertEquals(latestVersionXsdFile, latestBySpringSchemas);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with ComparableVersion

use of org.apache.maven.artifact.versioning.ComparableVersion in project MinecraftForge by MinecraftForge.

the class VersionChecker method startVersionCheck.

public static void startVersionCheck() {
    new Thread("Forge Version Check") {

        private HttpClient client;

        @Override
        public void run() {
            if (!FMLConfig.runVersionCheck()) {
                LOGGER.info("Global Forge version check system disabled, no further processing.");
                return;
            }
            client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(HTTP_TIMEOUT_SECS)).build();
            gatherMods().forEach(this::process);
        }

        /**
         * Returns the response body as a String for the given URL while following redirects
         */
        private String openUrlString(URL url) throws IOException, URISyntaxException, InterruptedException {
            URL currentUrl = url;
            for (int redirects = 0; redirects < MAX_HTTP_REDIRECTS; redirects++) {
                var request = HttpRequest.newBuilder().uri(currentUrl.toURI()).timeout(Duration.ofSeconds(HTTP_TIMEOUT_SECS)).setHeader("Accept-Encoding", "gzip").GET().build();
                final HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
                int responseCode = response.statusCode();
                if (responseCode >= 300 && responseCode <= 399) {
                    String newLocation = response.headers().firstValue("Location").orElseThrow(() -> new IOException("Got a 3xx response code but Location header was null while trying to fetch " + url));
                    currentUrl = new URL(currentUrl, newLocation);
                    continue;
                }
                final boolean isGzipEncoded = response.headers().firstValue("Content-Encoding").orElse("").equals("gzip");
                final String bodyStr;
                try (InputStream inStream = isGzipEncoded ? new GZIPInputStream(response.body()) : response.body()) {
                    try (var bufferedReader = new BufferedReader(new InputStreamReader(inStream))) {
                        bodyStr = bufferedReader.lines().collect(Collectors.joining("\n"));
                    }
                }
                return bodyStr;
            }
            throw new IOException("Too many redirects while trying to fetch " + url);
        }

        private void process(IModInfo mod) {
            Status status = PENDING;
            ComparableVersion target = null;
            Map<ComparableVersion, String> changes = null;
            String display_url = null;
            try {
                if (mod.getUpdateURL().isEmpty())
                    return;
                URL url = mod.getUpdateURL().get();
                LOGGER.info("[{}] Starting version check at {}", mod.getModId(), url.toString());
                String data = openUrlString(url);
                LOGGER.debug("[{}] Received version check data:\n{}", mod.getModId(), data);
                @SuppressWarnings("unchecked") Map<String, Object> json = new Gson().fromJson(data, Map.class);
                @SuppressWarnings("unchecked") Map<String, String> promos = (Map<String, String>) json.get("promos");
                display_url = (String) json.get("homepage");
                var mcVersion = FMLLoader.versionInfo().mcVersion();
                String rec = promos.get(mcVersion + "-recommended");
                String lat = promos.get(mcVersion + "-latest");
                ComparableVersion current = new ComparableVersion(mod.getVersion().toString());
                if (rec != null) {
                    ComparableVersion recommended = new ComparableVersion(rec);
                    int diff = recommended.compareTo(current);
                    if (diff == 0)
                        status = UP_TO_DATE;
                    else if (diff < 0) {
                        status = AHEAD;
                        if (lat != null) {
                            ComparableVersion latest = new ComparableVersion(lat);
                            if (current.compareTo(latest) < 0) {
                                status = OUTDATED;
                                target = latest;
                            }
                        }
                    } else {
                        status = OUTDATED;
                        target = recommended;
                    }
                } else if (lat != null) {
                    ComparableVersion latest = new ComparableVersion(lat);
                    if (current.compareTo(latest) < 0)
                        status = BETA_OUTDATED;
                    else
                        status = BETA;
                    target = latest;
                } else
                    status = BETA;
                LOGGER.info("[{}] Found status: {} Current: {} Target: {}", mod.getModId(), status, current, target);
                changes = new LinkedHashMap<>();
                @SuppressWarnings("unchecked") Map<String, String> tmp = (Map<String, String>) json.get(mcVersion);
                if (tmp != null) {
                    List<ComparableVersion> ordered = new ArrayList<>();
                    for (String key : tmp.keySet()) {
                        ComparableVersion ver = new ComparableVersion(key);
                        if (ver.compareTo(current) > 0 && (target == null || ver.compareTo(target) < 1)) {
                            ordered.add(ver);
                        }
                    }
                    Collections.sort(ordered);
                    for (ComparableVersion ver : ordered) {
                        changes.put(ver, tmp.get(ver.toString()));
                    }
                }
            } catch (Exception e) {
                LOGGER.warn("Failed to process update information", e);
                status = FAILED;
            }
            results.put(mod, new CheckResult(status, target, changes, display_url));
        }
    }.start();
}
Also used : Status(net.minecraftforge.fml.VersionChecker.Status) InputStreamReader(java.io.InputStreamReader) IModInfo(net.minecraftforge.forgespi.language.IModInfo) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) HttpResponse(java.net.http.HttpResponse) Gson(com.google.gson.Gson) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) GZIPInputStream(java.util.zip.GZIPInputStream) HttpClient(java.net.http.HttpClient) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

ComparableVersion (org.apache.maven.artifact.versioning.ComparableVersion)13 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Matcher (java.util.regex.Matcher)4 File (java.io.File)3 List (java.util.List)3 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)2 URL (java.net.URL)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors (java.util.stream.Collectors)2 ProjectDependency (meghanada.project.ProjectDependency)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 DomainObjectSet (org.gradle.tooling.model.DomainObjectSet)2