Skip to content

Commit

Permalink
Merge pull request #315 from drewbrokke/BLADE-738-BUG-v1-product-key-…
Browse files Browse the repository at this point in the history
…comparator-to-send

BLADE-738 Blade can not recognized "dxp-2023.q3.1" as a valid product key in product.json file.
  • Loading branch information
drewbrokke committed Nov 14, 2023
2 parents b82b34b + a394703 commit c115d1c
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 268 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.liferay.blade.cli.WorkspaceConstants;
import com.liferay.blade.cli.util.BladeUtil;
import com.liferay.blade.cli.util.ProductKeyUtil;
import com.liferay.project.templates.extensions.util.VersionUtil;

import java.util.ArrayList;
Expand All @@ -34,8 +35,8 @@ public void validate(String name, String value) throws ParameterException {
possibleValues.addAll(WorkspaceConstants.originalLiferayVersions);

if ((!possibleValues.contains(value) && !allTargetPlatformVersions.contains(value)) ||
(!BladeUtil.verifyPortalDxpWorkspaceProduct(value) && !VersionUtil.isLiferayVersion(value) &&
!BladeUtil.verifyCommerceWorkspaceProduct(value))) {
(!ProductKeyUtil.verifyPortalDxpWorkspaceProduct(value) && !VersionUtil.isLiferayVersion(value) &&
!ProductKeyUtil.verifyCommerceWorkspaceProduct(value))) {

throw new ParameterException(value + " is not a valid value.");
}
Expand Down

This file was deleted.

70 changes: 13 additions & 57 deletions cli/src/main/java/com/liferay/blade/cli/util/BladeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.liferay.blade.cli.BladeCLI;
import com.liferay.blade.cli.Extensions;
import com.liferay.blade.cli.command.SamplesCommand;
import com.liferay.blade.cli.command.validator.WorkspaceProductComparator;
import com.liferay.project.templates.ProjectTemplates;
import com.liferay.project.templates.extensions.util.ProjectTemplatesUtil;

Expand Down Expand Up @@ -86,8 +85,6 @@

import org.gradle.internal.impldep.com.google.common.base.Strings;

import org.osgi.framework.Version;

/**
* @author Gregory Amerson
* @author David Truong
Expand Down Expand Up @@ -116,34 +113,6 @@ public static boolean canConnect(String host, int port) {
return _canConnect(localAddress, remoteAddress);
}

public static int compareVersions(Version v1, Version v2) {
if (v2 == v1) {
return 0;
}

int result = v1.getMajor() - v2.getMajor();

if (result != 0) {
return result;
}

result = v1.getMinor() - v2.getMinor();

if (result != 0) {
return result;
}

result = v1.getMicro() - v2.getMicro();

if (result != 0) {
return result;
}

String s1 = v1.getQualifier();

return s1.compareTo(v2.getQualifier());
}

public static Path downloadFile(String urlString, Path cacheDirPath, String targetFileName) throws Exception {
URL downladURL = new URL(urlString);

Expand Down Expand Up @@ -428,19 +397,22 @@ public static List<String> getWorkspaceProductKeys(boolean promoted) {
).stream(
).filter(
key -> Objects.nonNull(productInfos.get(key))
).map(
key -> new Pair<>(key, new ProductInfo((Map<String, String>)productInfos.get(key)))
).filter(
pair -> {
ProductInfo productInfo = pair.second();
key -> {
ProductInfo productInfo = new ProductInfo((Map<String, String>)productInfos.get(key));

if (productInfo.getTargetPlatformVersion() == null) {
return false;
}

return Objects.nonNull(productInfo.getTargetPlatformVersion()) &&
(!promoted || productInfo.isPromoted());
if (promoted && !productInfo.isPromoted()) {
return false;
}

return true;
}
).sorted(
new WorkspaceProductComparator()
).map(
Pair::first
ProductKeyUtil.comparator
).collect(
Collectors.toList()
);
Expand All @@ -455,7 +427,7 @@ public static Set<String> getWorkspaceProductTargetPlatformVersions(boolean prom
).filter(
entry -> Objects.nonNull(productInfos.get(entry.getKey()))
).map(
entry -> new ProductInfo((Map<String, String>)productInfos.get(entry.getKey()))
entry -> new ProductInfo((Map<String, String>)entry.getValue())
).filter(
product -> Objects.nonNull(product.getTargetPlatformVersion()) && (!promoted || product.isPromoted())
).map(
Expand Down Expand Up @@ -745,18 +717,6 @@ public static void tail(Path path, PrintStream printStream) throws IOException {
}
}

public static boolean verifyCommerceWorkspaceProduct(String product) {
Matcher matcher = _productCommerceVersionPattern.matcher(product);

return matcher.matches();
}

public static boolean verifyPortalDxpWorkspaceProduct(String product) {
Matcher matcher = _productPortalDXPVersionPattern.matcher(product);

return matcher.matches();
}

public static void writePropertyValue(File propertyFile, String key, String value) throws Exception {
String property = System.lineSeparator() + key + "=" + value;

Expand Down Expand Up @@ -900,11 +860,7 @@ private static Path _downloadFile(
private static final String _PRODUCT_INFO_URL = "https://releases.liferay.com/tools/workspace/.product_info.json";

private static final Pattern _microPattern = Pattern.compile("((([efs])p)|(ga)|(u))([0-9]+)(-[0-9]+)?");
private static final Pattern _productCommerceVersionPattern = Pattern.compile(
"^(commerce)-([1-9]\\d|[0-9])\\.([0-9]\\d|\\d).([0-9]\\d|\\d)(-(([1-9]\\d|[0-9])\\.([1-9]\\d|[0-9])$)+)*");
private static Map<String, Object> _productInfoMap = Collections.emptyMap();
private static final Pattern _productPortalDXPVersionPattern = Pattern.compile(
"^(portal|dxp)-([1-9]\\d|[0-9])\\.([0-9]\\d|\\d)-(((([efsd])([pe]))|u|ga)([0-9]\\d*)$)+");
private static final File _workspaceCacheDir = new File(
System.getProperty("user.home"), _DEFAULT_WORKSPACE_CACHE_DIR_NAME);

Expand Down
88 changes: 88 additions & 0 deletions cli/src/main/java/com/liferay/blade/cli/util/ProductKeyInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/

package com.liferay.blade.cli.util;

import java.util.Comparator;

/**
* @author Drew Brokke
*/
public class ProductKeyInfo implements Comparable<ProductKeyInfo> {

@Override
public int compareTo(final ProductKeyInfo keyInfo) {
return Comparator.comparing(
ProductKeyInfo::getProductRank
).thenComparing(
ProductKeyInfo::isQuarterly
).thenComparing(
ProductKeyInfo::getMajorProductKeyVersion
).thenComparing(
ProductKeyInfo::getMinorProductKeyVersion
).thenComparing(
ProductKeyInfo::getMicroProductKeyVersion
).reversed(
).compare(
this, keyInfo
);
}

public ProductKeyVersion getMajorProductKeyVersion() {
return _majorProductKeyVersion;
}

public ProductKeyVersion getMicroProductKeyVersion() {
return _microProductKeyVersion;
}

public ProductKeyVersion getMinorProductKeyVersion() {
return _minorProductKeyVersion;
}

public String getProduct() {
return _product;
}

public int getProductRank() {
return _productRank;
}

public boolean isQuarterly() {
return _quarterly;
}

public void setMajorProductKeyVersion(ProductKeyVersion majorProductKeyVersion) {
_majorProductKeyVersion = majorProductKeyVersion;
}

public void setMicroProductKeyVersion(ProductKeyVersion microProductKeyVersion) {
_microProductKeyVersion = microProductKeyVersion;
}

public void setMinorProductKeyVersion(ProductKeyVersion minorProductKeyVersion) {
_minorProductKeyVersion = minorProductKeyVersion;
}

public void setProduct(String product) {
_product = product;
}

public void setProductRank(int productRank) {
_productRank = productRank;
}

public void setQuarterly(boolean quarterly) {
_quarterly = quarterly;
}

private ProductKeyVersion _majorProductKeyVersion = ProductKeyVersion.BLANK;
private ProductKeyVersion _microProductKeyVersion = ProductKeyVersion.BLANK;
private ProductKeyVersion _minorProductKeyVersion = ProductKeyVersion.BLANK;
private String _product;
private int _productRank = -1;
private boolean _quarterly = false;

}
Loading

0 comments on commit c115d1c

Please sign in to comment.