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