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 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
10 changes: 8 additions & 2 deletions cli/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Bundle-Version: ${project.version}.${tstamp}
JPM-Command: blade
Main-Class: com.liferay.blade.cli.BladeCLI
Private-Package:\
aQute.bnd.header;-split-package:=merge-first,\
aQute.bnd.maven;-split-package:=merge-first,\
aQute.bnd.osgi;-split-package:=merge-first,\
aQute.bnd.service;-split-package:=merge-first,\
Expand All @@ -18,6 +17,13 @@ Private-Package:\
\
aQute.service.reporter;-split-package:=merge-first,\
\
com.google.gson,\
com.google.gson.stream,\
com.google.gson.internal.bind,\
com.google.gson.internal,\
com.google.gson.reflect,\
com.google.gson.internal.sql,\
\
com.liferay.blade.gradle.tooling,\
\
groovy.json,\
Expand Down Expand Up @@ -323,6 +329,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
16 changes: 9 additions & 7 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 @@ -76,8 +76,9 @@ createWrapperZip {

dependencies {
api group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "5.3.0"
api group: "com.google.code.gson", name: "gson", version: "2.9.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 +103,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 All @@ -111,7 +112,7 @@ dependencies {
api name: "org.objectweb.asm.tree-6.0.0"
api name: "org.objectweb.asm.util-6.0.0"

bladeExtensions group: "com.liferay.blade", name: "com.liferay.blade.extensions.maven.profile", version: "1.0.39-SNAPSHOT"
bladeExtensions group: "com.liferay.blade", name: "com.liferay.blade.extensions.maven.profile", version: "1.0.40-SNAPSHOT"
bladeExtensions group: "com.liferay.blade", name: "com.liferay.project.templates.client.extension", version: "1.0.6-SNAPSHOT"
bladeExtensions group: "com.liferay.blade", name: "com.liferay.project.templates.js.theme", version: "1.0.22-SNAPSHOT"
bladeExtensions group: "com.liferay.blade", name: "com.liferay.project.templates.js.widget", version: "1.0.23-SNAPSHOT"
Expand Down Expand Up @@ -139,16 +140,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 Expand Up @@ -213,6 +214,7 @@ if (project.hasProperty("release") || project.hasProperty("snapshots")) {
}

repositories {
mavenLocal()
flatDir {
dirs "${rootProject.projectDir}/libs"
}
Expand Down
20 changes: 12 additions & 8 deletions cli/src/main/java/com/liferay/blade/cli/BladeCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
import com.liferay.blade.cli.util.FileUtil;
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 com.liferay.blade.cli.util.ReleaseInfo;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -99,7 +100,7 @@ public static Map<String, BaseCommand<? extends BaseArgs>> getCommandMapByClassL

boolean profileNameIsPresent = false;

if ((profileName != null) && (profileName.length() > 0)) {
if ((profileName != null) && !profileName.isEmpty()) {
profileNameIsPresent = true;
}

Expand Down Expand Up @@ -862,16 +863,21 @@ private Map<String, String> _buildMavenPossibleValuesMap(

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

Map<String, Object> productInfos = BladeUtil.getProductInfos(true, error());
Map<String, Object> releaseKeyInfos = BladeUtil.getReleaseKeyInfos(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>)releaseKeyInfos.get(option));

optionsMap.put(String.valueOf(x), productInfo.getTargetPlatformVersion());
ReleaseInfo releaseInfo = new ReleaseInfo(
productKeyInfo,
BladeUtil.getReleaseProperties(productKeyInfo.getProduct(), productKeyInfo.getProductKey()));

optionsMap.put(String.valueOf(x), releaseInfo.getTargetPlatformVersion());
}

return optionsMap;
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 @@ -20,6 +20,9 @@ public BaseCommand(BladeCLI blade, T args) {
_args = args;
}

public void commandPostAction() throws Exception {
}

public abstract void execute() throws Exception;

public T getArgs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.liferay.blade.cli.util.CopyDirVisitor;
import com.liferay.blade.cli.util.FileUtil;
import com.liferay.blade.cli.util.ListUtil;
import com.liferay.blade.cli.util.ProductInfo;
import com.liferay.blade.cli.util.ReleaseInfo;
import com.liferay.blade.cli.util.StringUtil;
import com.liferay.blade.gradle.model.GradleDependency;
import com.liferay.project.templates.extensions.ProjectTemplatesArgs;
Expand Down Expand Up @@ -1211,14 +1211,12 @@ 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();
ReleaseInfo releaseInfo = BladeUtil.getReleaseInfo(productKey);

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

return Optional.of(productInfo.getTargetPlatformVersion());
return Optional.of(releaseInfo.getTargetPlatformVersion());
}

JSONObject jsonObject = new JSONObject(new String(Files.readAllBytes(productInfoPath.normalize())));
Expand Down
59 changes: 44 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 @@ -17,6 +17,7 @@
import com.liferay.blade.cli.WorkspaceProvider;
import com.liferay.blade.cli.gradle.GradleWorkspaceProvider;
import com.liferay.blade.cli.util.BladeUtil;
import com.liferay.blade.cli.util.ReleaseInfo;
import com.liferay.blade.cli.util.StringUtil;
import com.liferay.project.templates.ProjectTemplates;
import com.liferay.project.templates.extensions.ProjectTemplatesArgs;
Expand Down Expand Up @@ -179,10 +180,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 +346,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 +363,26 @@ protected ProjectTemplatesArgs getProjectTemplateArgs(

projectTemplatesArgs.setTemplate(template);

ReleaseInfo releaseInfo = BladeUtil.getReleaseInfo(liferayVersion.get());

if (releaseInfo.getProductKey(
).isQuarterly() && 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 +494,16 @@ private String _checkTemplateVersionRange(File templateFile, ProjectTemplatesArg
try (InputStream fileInputStream = Files.newInputStream(templateFile.toPath(), StandardOpenOption.READ);
JarInputStream in = new JarInputStream(fileInputStream)) {

String versionString = projectTemplatesArgs.getLiferayVersion();

ReleaseInfo releaseInfo = BladeUtil.getReleaseInfo(versionString);

if (releaseInfo.getProductKey(
).isPromoted()) {

return "";
}

Manifest manifest = in.getManifest();

Attributes attributes = manifest.getMainAttributes();
Expand All @@ -483,17 +512,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 +671,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+)");

}
Loading
Loading