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;
}
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;
}
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.");
}
}
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);
}
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();
}
Aggregations