Skip to content

Commit

Permalink
LPD-32781 cli: use string matching on the docker property to get the …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
drewbrokke committed Jul 31, 2024
1 parent 57243dd commit 49dba7b
Showing 1 changed file with 31 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> baseLiferayVersion = Optional.ofNullable(
gradleProperties.getProperty(WorkspaceConstants.DEFAULT_TARGET_PLATFORM_VERSION_PROPERTY)
).filter(
BladeUtil::isNotEmpty
);

Optional<String> 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
Expand Down

0 comments on commit 49dba7b

Please sign in to comment.