From 49dba7b3f03b69cb30fba8c494f2adf4c818195d Mon Sep 17 00:00:00 2001 From: drewbrokke Date: Wed, 31 Jul 2024 11:44:44 -0500 Subject: [PATCH] LPD-32781 cli: use string matching on the docker property to get the target platform version from the docker image property This will be VERY SLOW the first time it runs since it will download a lot of releases.properties files. However, this is acceptable in the short term because: - It is generally only going to be slow the first time when the user's local properties files are not populated. - This condition is relatively rare fallback. Usually there is a product key or target platform, this is a last-resort fallback. - We will be inlining those properties into the JSON file once all the tooling is ready (very near future). Once we do this operation will be very fast. --- .../cli/gradle/GradleWorkspaceProvider.java | 72 ++++++++----------- 1 file changed, 31 insertions(+), 41 deletions(-) diff --git a/cli/src/main/java/com/liferay/blade/cli/gradle/GradleWorkspaceProvider.java b/cli/src/main/java/com/liferay/blade/cli/gradle/GradleWorkspaceProvider.java index c0ac14929..d0d0bfbe5 100644 --- a/cli/src/main/java/com/liferay/blade/cli/gradle/GradleWorkspaceProvider.java +++ b/cli/src/main/java/com/liferay/blade/cli/gradle/GradleWorkspaceProvider.java @@ -63,59 +63,49 @@ public File getGradlePropertiesFile(File dir) { @Override @SuppressWarnings("unchecked") public String getLiferayVersion(File workspaceDir) { - try { - Properties gradleProperties = getGradleProperties(workspaceDir); + Properties gradleProperties = getGradleProperties(workspaceDir); + + Optional baseLiferayVersion = Optional.ofNullable( + gradleProperties.getProperty(WorkspaceConstants.DEFAULT_TARGET_PLATFORM_VERSION_PROPERTY) + ).filter( + BladeUtil::isNotEmpty + ); - Optional baseLiferayVersion = Optional.ofNullable( - gradleProperties.getProperty(WorkspaceConstants.DEFAULT_TARGET_PLATFORM_VERSION_PROPERTY) + if (!baseLiferayVersion.isPresent()) { + String productKey = gradleProperties.getProperty(WorkspaceConstants.DEFAULT_WORKSPACE_PRODUCT_PROPERTY); + + String targetPlatformVersion = ReleaseUtil.getFromReleaseEntry( + productKey, ReleaseEntry::getTargetPlatformVersion); + + baseLiferayVersion = Optional.ofNullable( + targetPlatformVersion ).filter( BladeUtil::isNotEmpty ); + } - if (!baseLiferayVersion.isPresent()) { - String productKey = gradleProperties.getProperty(WorkspaceConstants.DEFAULT_WORKSPACE_PRODUCT_PROPERTY); - - String targetPlatformVersion = ReleaseUtil.getFromReleaseEntry( - productKey, ReleaseEntry::getTargetPlatformVersion); + if (!baseLiferayVersion.isPresent()) { + String dockerImageProperty = gradleProperties.getProperty( + WorkspaceConstants.DEFAULT_LIFERAY_DOCKER_IMAGE_PROPERTY); - baseLiferayVersion = Optional.ofNullable( - targetPlatformVersion - ).filter( - BladeUtil::isNotEmpty - ); + if (BladeUtil.isEmpty(dockerImageProperty)) { + return null; } - if (!baseLiferayVersion.isPresent()) { - String dockerImageProperty = gradleProperties.getProperty( - WorkspaceConstants.DEFAULT_LIFERAY_DOCKER_IMAGE_PROPERTY); - - if (BladeUtil.isEmpty(dockerImageProperty)) { - return null; - } - - Matcher matcher = patternDockerImageLiferayVersion.matcher(dockerImageProperty); - - if (matcher.find()) { - baseLiferayVersion = Optional.of(matcher.group(1)); - - if (dockerImageProperty.contains("dxp")) { - baseLiferayVersion = Optional.of(baseLiferayVersion.get() + ".10"); - } - else { - baseLiferayVersion = Optional.of(baseLiferayVersion.get() + ".0"); - } - } - } + Matcher matcher = patternDockerImageLiferayVersion.matcher(dockerImageProperty); - if (baseLiferayVersion.isPresent()) { - return baseLiferayVersion.get(); + if (matcher.find()) { + baseLiferayVersion = ReleaseUtil.getReleaseEntryStream( + ).filter( + releaseEntry -> dockerImageProperty.startsWith(releaseEntry.getLiferayDockerImage()) + ).findFirst( + ).map( + ReleaseEntry::getTargetPlatformVersion + ); } } - catch (Exception exception) { - BladeCLI.instance.error(exception); - } - return null; + return baseLiferayVersion.orElse(null); } @Override