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-742 support quarter release #319

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion cli/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,6 @@ Private-Package:\
@jansi-*.jar,\
${project.buildDir}/tooling.zip,\
${project.buildDir}/wrapper.zip,\
${project.buildDir}/.product_info.json,\
${project.buildDir}/releases.json,\
mvnw.cmd
-sources: false
12 changes: 6 additions & 6 deletions cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tasks.register('copyMavenProfileJar', Copy)
tasks.register('createToolingZip', Zip)
tasks.register('createWrapperZip', Zip)
tasks.register('downloadPortal', Download)
tasks.register('downloadProductInfo', Download)
tasks.register('downloadReleasesInfo', Download)
tasks.register('unzipManifest', Copy)
tasks.register('unzipPortal', Copy)

Expand Down Expand Up @@ -77,7 +77,7 @@ createWrapperZip {
dependencies {
api group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "5.3.0"
api group: "com.liferay", name: "com.liferay.gogo.shell.client", version: "1.0.0"
api group: "com.liferay", name: "com.liferay.project.templates", version: "5.0.269"
api group: "com.liferay", name: "com.liferay.project.templates", version: "5.0.283"
api group: "commons-io", name: "commons-io", version: "2.7"
api group: "commons-lang", name: "commons-lang", version: "2.6"
api group: "org.apache.ant", name: "ant", version: "1.10.11"
Expand All @@ -102,7 +102,7 @@ dependencies {
api group: "org.gradle", name: "gradle-base-services-groovy", version: "5.6.4"
api group: "org.gradle", name: "gradle-core", version: "5.6.4"
api group: "org.gradle", name: "gradle-tooling-api", version: "5.6.4"
api group: "org.json", name: "json", version: "20230227"
api group: "org.json", name: "json", version: "20231013"
api group: "org.jsoup", name: "jsoup", version: "1.15.3"
api group: "org.tukaani", name: "xz", version: "1.6"
api name: "org.objectweb.asm-6.0.0"
Expand Down Expand Up @@ -139,16 +139,16 @@ downloadPortal {
onlyIfNewer true
}

downloadProductInfo {
src "https://releases-cdn.liferay.com/tools/workspace/.product_info.json"
downloadReleasesInfo {
src "http://localhost:3000/releases.json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The releases.json should be available on a real server somewhere before we merge this. Otherwise the tests won't be valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gamerson Thanks a lot. This is just a test url before we get the final descision for release info. Because we don't have the completely relases.json, I just put here to let you and drew to do some review. I will do other changes base on your review comments.

dest buildDir
onlyIfNewer true
}

jar {
dependsOn("unzipPortal")
archiveFileName.set("blade.jar")
from createToolingZip, createWrapperZip, downloadProductInfo
from createToolingZip, createWrapperZip, downloadReleasesInfo
}

processResources {
Expand Down
14 changes: 9 additions & 5 deletions cli/src/main/java/com/liferay/blade/cli/BladeCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.liferay.blade.cli.util.Pair;
import com.liferay.blade.cli.util.ProcessesUtil;
import com.liferay.blade.cli.util.ProductInfo;
import com.liferay.blade.cli.util.ProductKeyInfo;
import com.liferay.blade.cli.util.Prompter;

import java.io.BufferedReader;
Expand Down Expand Up @@ -862,14 +863,19 @@ private Map<String, String> _buildMavenPossibleValuesMap(

Iterator<String> it = options.iterator();

Map<String, Object> productInfos = BladeUtil.getProductInfos(true, error());
Map<String, Object> releasesInfos = BladeUtil.getReleasesInfos(true, error());

Map<String, String> optionsMap = new LinkedHashMap<>();

for (int x = 1; it.hasNext(); x++) {
String option = it.next();

ProductInfo productInfo = new ProductInfo((Map<String, String>)productInfos.get(option));
ProductKeyInfo productKeyInfo = new ProductKeyInfo(
option, (Map<String, String>)releasesInfos.get(option));

ProductInfo productInfo = new ProductInfo(
productKeyInfo,
BladeUtil.getReleaseProperties(productKeyInfo.getProduct(), productKeyInfo.getProductKey()));

optionsMap.put(String.valueOf(x), productInfo.getTargetPlatformVersion());
}
Expand Down Expand Up @@ -982,9 +988,7 @@ private String _getCommandProfile(String[] args) throws MissingCommandException
for (String arg : args) {
String[] argSplit = arg.split(" ");

for (String argEach : argSplit) {
argsCollection.add(argEach);
}
Collections.addAll(argsCollection, argSplit);
}

String[] argsArray = argsCollection.toArray(new String[0]);
Expand Down
5 changes: 2 additions & 3 deletions cli/src/main/java/com/liferay/blade/cli/Extensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -296,9 +297,7 @@ private static Collection<String> _getFlags(Class<? extends BaseArgs> clazz, boo
if ((withArguments && !type.equals(boolean.class)) ||
(!withArguments && type.equals(boolean.class))) {

for (String name : names) {
flags.add(name);
}
Collections.addAll(flags, names);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

/**
* @author David Truong
Expand Down Expand Up @@ -50,6 +51,8 @@ public class WorkspaceConstants {

public static final String DEFAULT_WORKSPACE_PRODUCT_PROPERTY = "liferay.workspace.product";

public static final Pattern dxpQuarterReleaseVersionPattern = Pattern.compile(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just asking to be broken in the future. Can we do without this pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we could. I will change it.

"^(?<product>dxp)-(?<major>2\\d{3})\\.(?<minor>q[1234])\\.(?<micro>\\d+)$");
public static final List<String> originalLiferayVersions = Arrays.asList("7.0", "7.1", "7.2", "7.3", "7.4");

}
Original file line number Diff line number Diff line change
Expand Up @@ -1211,12 +1211,10 @@ private Optional<String> _getTargetPlatformVersionFromProduct(String productKey)

Path userHomePath = userHomeDir.toPath();

Path productInfoPath = userHomePath.resolve(".liferay/workspace/.product_info.json");
Path productInfoPath = userHomePath.resolve(".liferay/workspace/releases.json");

if (!Files.exists(productInfoPath)) {
Map<String, Object> productInfos = BladeUtil.getProductInfos();

ProductInfo productInfo = new ProductInfo((Map<String, String>)productInfos.get(productKey));
ProductInfo productInfo = BladeUtil.getProductInfo(productKey);

return Optional.of(productInfo.getTargetPlatformVersion());
}
Expand Down
56 changes: 41 additions & 15 deletions cli/src/main/java/com/liferay/blade/cli/command/CreateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ else if (defaultModulesDirSet) {
return;
}

String templateValidateStrig = _checkTemplateVersionRange(templateFile, projectTemplatesArgs);
String templateValidateString = _checkTemplateVersionRange(templateFile, projectTemplatesArgs);

if (!StringUtil.isNullOrEmpty(templateValidateStrig)) {
getBladeCLI().error(templateValidateStrig);
if (!StringUtil.isNullOrEmpty(templateValidateString)) {
getBladeCLI().error(templateValidateString);

return;
}
Expand Down Expand Up @@ -345,16 +345,14 @@ protected ProjectTemplatesArgs getProjectTemplateArgs(
WorkspaceProvider workspaceProvider = bladeCLI.getWorkspaceProvider(dir);

projectTemplatesArgs.setDependencyManagementEnabled(
(workspaceProvider != null) ? workspaceProvider.isDependencyManagementEnabled(dir) : false);
(workspaceProvider != null) && workspaceProvider.isDependencyManagementEnabled(dir));

Optional<String> liferayVersion = _getLiferayVersion(workspaceProvider, createArgs);

if (!liferayVersion.isPresent()) {
throw new IOException("Cannot determine Liferay Version. Please enter a valid value for Liferay Version.");
}

projectTemplatesArgs.setLiferayVersion(liferayVersion.get());

projectTemplatesArgs.setName(name);
projectTemplatesArgs.setPackageName(createArgs.getPackageName());

Expand All @@ -364,6 +362,25 @@ protected ProjectTemplatesArgs getProjectTemplateArgs(

projectTemplatesArgs.setTemplate(template);

Matcher dxpQuarterlyVersionMatcher = WorkspaceConstants.dxpQuarterReleaseVersionPattern.matcher(
liferayVersion.get());

if (dxpQuarterlyVersionMatcher.matches() && product.isPresent() && Objects.equals(product.get(), "dxp")) {
String projectTemplate = projectTemplatesArgs.getTemplate();

switch (projectTemplate) {
case _TEMPLATE_PORTLET_PROVIDER_NAME:
projectTemplatesArgs.setLiferayVersion("7.4.13.u86");
case _TEMPLATE_SIMULATION_PANEL_NAME:
projectTemplatesArgs.setLiferayVersion("7.4.13.u72");
default:
projectTemplatesArgs.setLiferayVersion("7.4");
}
}
else {
projectTemplatesArgs.setLiferayVersion(liferayVersion.get());
}

return projectTemplatesArgs;
}

Expand Down Expand Up @@ -475,6 +492,15 @@ private String _checkTemplateVersionRange(File templateFile, ProjectTemplatesArg
try (InputStream fileInputStream = Files.newInputStream(templateFile.toPath(), StandardOpenOption.READ);
JarInputStream in = new JarInputStream(fileInputStream)) {

String versionString = projectTemplatesArgs.getLiferayVersion();

Matcher dxpQuarterlyVersionMatcher = WorkspaceConstants.dxpQuarterReleaseVersionPattern.matcher(
versionString);

if (dxpQuarterlyVersionMatcher.matches()) {
return "";
}

Manifest manifest = in.getManifest();

Attributes attributes = manifest.getMainAttributes();
Expand All @@ -483,17 +509,13 @@ private String _checkTemplateVersionRange(File templateFile, ProjectTemplatesArg

VersionRange versionRange = new VersionRange(versionRangeValue);

String versionString = projectTemplatesArgs.getLiferayVersion();

String liferayVersionString = new String(
String.valueOf(VersionUtil.getMajorVersion(versionString)) + "." +
String.valueOf(VersionUtil.getMinorVersion(versionString)));
String liferayVersionString =
VersionUtil.getMajorVersion(versionString) + "." + VersionUtil.getMinorVersion(versionString);

if (!versionRange.includes(Version.parseVersion(liferayVersionString))) {
return new String(
"Error: The " + projectTemplatesArgs.getTemplate() +
" project can only be created in liferay version range: " + versionRange +
", current liferay version is " + liferayVersionString + ".");
return "Error: The " + projectTemplatesArgs.getTemplate() +
" project can only be created in liferay version range: " + versionRange +
", current liferay version is " + liferayVersionString + ".";
}
}
catch (Exception exception) {
Expand Down Expand Up @@ -646,6 +668,10 @@ private boolean _isWorkspaceDir(File dir) {
return bladeCLI.isWorkspaceDir(dir);
}

private static final String _TEMPLATE_PORTLET_PROVIDER_NAME = "portlet-provider";

private static final String _TEMPLATE_SIMULATION_PANEL_NAME = "simulation-panel-entry";

private Pattern _inValidNamePattern = Pattern.compile("((-)\\2+)");

}
61 changes: 34 additions & 27 deletions cli/src/main/java/com/liferay/blade/cli/command/InitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.liferay.blade.cli.BladeCLI;
import com.liferay.blade.cli.BladeSettings;
import com.liferay.blade.cli.WorkspaceConstants;
import com.liferay.blade.cli.WorkspaceProvider;
import com.liferay.blade.cli.gradle.GradleExec;
import com.liferay.blade.cli.util.BladeUtil;
Expand Down Expand Up @@ -36,6 +37,7 @@
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;

/**
* @author Gregory Amerson
Expand Down Expand Up @@ -191,7 +193,7 @@ public void execute() throws Exception {
String liferayVersion;
String workspaceProductKey;

Map<String, Object> productInfos = BladeUtil.getProductInfos(initArgs.isTrace(), bladeCLI.error());
Map<String, Object> releasesInfos = BladeUtil.getReleasesInfos(initArgs.isTrace(), bladeCLI.error());

if (!mavenBuild) {
workspaceProductKey = _getDefaultProductKey(initArgs);
Expand All @@ -204,29 +206,39 @@ public void execute() throws Exception {
return;
}

Object productInfoObject = productInfos.get(workspaceProductKey);
Object productInfoObject = releasesInfos.get(workspaceProductKey);

if (productInfoObject == null) {
_addError("Unable to get product info for selected version " + workspaceProductKey);

return;
}

ProductInfo productInfo = new ProductInfo((Map<String, String>)productInfoObject);
ProductInfo productInfo = BladeUtil.getProductInfo(workspaceProductKey);

Version targetPlatformVersion = _makeCompatibleVersion(productInfo.getTargetPlatformVersion());
String targetPlatformVersion = productInfo.getTargetPlatformVersion();

liferayVersion = new String(
targetPlatformVersion.getMajor() + "." + targetPlatformVersion.getMinor() + "." +
targetPlatformVersion.getMicro());
Matcher targetPlatformMatcher = WorkspaceConstants.dxpQuarterReleaseVersionPattern.matcher(
targetPlatformVersion);

if (targetPlatformMatcher.matches()) {
liferayVersion = "7.4";
}
else {
Version normalTargetPlatformVersion = _makeCompatibleVersion(targetPlatformVersion);

liferayVersion =
normalTargetPlatformVersion.getMajor() + "." + normalTargetPlatformVersion.getMinor() + "." +
normalTargetPlatformVersion.getMicro();
}
}
else {
workspaceProductKey = _setProductAndVersionForMaven(productInfos, initArgs);
workspaceProductKey = _setProductAndVersionForMaven(releasesInfos, initArgs);

liferayVersion = initArgs.getLiferayVersion();
}

Object productInfoObject = productInfos.get(workspaceProductKey);
Object productInfoObject = releasesInfos.get(workspaceProductKey);

if (productInfoObject == null) {
_addError("Unable to get product info for selected version " + workspaceProductKey);
Expand Down Expand Up @@ -487,33 +499,28 @@ private String _setProductAndVersionForMaven(Map<String, Object> productInfos, I
if (possibleProductKey.startsWith("portal") || possibleProductKey.startsWith("dxp") ||
possibleProductKey.startsWith("commerce")) {

Object productInfoObject = productInfos.get(possibleProductKey);

if (Objects.nonNull(productInfoObject)) {
ProductInfo productInfo = new ProductInfo((Map<String, String>)productInfoObject);
ProductInfo productInfo = BladeUtil.getProductInfo(possibleProductKey);

initArgs.setLiferayVersion(productInfo.getTargetPlatformVersion());
initArgs.setLiferayVersion(productInfo.getTargetPlatformVersion());

String[] productKeyValues = possibleProductKey.split("-");
String[] productKeyValues = possibleProductKey.split("-");

initArgs.setLiferayProduct(productKeyValues[0]);
initArgs.setLiferayProduct(productKeyValues[0]);

return possibleProductKey;
}
return possibleProductKey;
}
else {
for (Map.Entry<String, Object> entryKey : productInfos.entrySet()) {
ProductInfo productInfo = new ProductInfo((Map<String, String>)entryKey.getValue());

if (Objects.equals(possibleProductKey, productInfo.getTargetPlatformVersion())) {
possibleProductKey = entryKey.getKey();
for (Map.Entry<String, Object> entryKey : productInfos.entrySet()) {
ProductInfo productInfo = BladeUtil.getProductInfo(entryKey.getKey());

if (Objects.equals(possibleProductKey, productInfo.getTargetPlatformVersion())) {
possibleProductKey = entryKey.getKey();

String[] productKeyValues = possibleProductKey.split("-");
String[] productKeyValues = possibleProductKey.split("-");

initArgs.setLiferayProduct(productKeyValues[0]);
initArgs.setLiferayProduct(productKeyValues[0]);

return possibleProductKey;
}
return possibleProductKey;
}
}

Expand Down
Loading
Loading