Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLADE-738 Blade can not recognized "dxp-2023.q3.1" as a valid product key in product.json file. #315

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
drewbrokke marked this conversation as resolved.
Show resolved Hide resolved
).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
Loading