Skip to content

Commit

Permalink
BLADE-742 support quarter release
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjhy committed Feb 5, 2024
1 parent b0cde64 commit 98ef7f0
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 53 deletions.
4 changes: 2 additions & 2 deletions cli/build.gradle
Original file line number Diff line number Diff line change
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.279"
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
4 changes: 1 addition & 3 deletions cli/src/main/java/com/liferay/blade/cli/BladeCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -982,9 +982,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(
"(\\d{4})\\.q([1234])\\.(\\d+)(-(\\d+))?");
public static final List<String> originalLiferayVersions = Arrays.asList("7.0", "7.1", "7.2", "7.3", "7.4");

}
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+)");

}
20 changes: 16 additions & 4 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 @@ -214,11 +216,21 @@ public void execute() throws Exception {

ProductInfo productInfo = new ProductInfo((Map<String, String>)productInfoObject);

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,11 @@ public String getLiferayVersion(File workspaceDir) {

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

if (productInfo != null) {
baseLiferayVersion = Optional.ofNullable(
productInfo.getTargetPlatformVersion()
).filter(
BladeUtil::isNotEmpty
);
}
baseLiferayVersion = Optional.ofNullable(
productInfo.getTargetPlatformVersion()
).filter(
BladeUtil::isNotEmpty
);
}

if (!baseLiferayVersion.isPresent()) {
Expand Down Expand Up @@ -144,6 +142,13 @@ else if (dockerImageProperty.contains("dxp")) {
}
}
else {
Matcher dxpQuarterlyVersionMatcher = WorkspaceConstants.dxpQuarterReleaseVersionPattern.matcher(
targetPlatformVersion);

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

Version version = Version.parseVersion(targetPlatformVersion.replaceAll("-", "."));

int microVersion = version.getMicro();
Expand Down
9 changes: 3 additions & 6 deletions cli/src/main/java/com/liferay/blade/cli/util/NodeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.nio.file.attribute.PosixFilePermissions;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

Expand Down Expand Up @@ -111,9 +112,7 @@ public static int runLiferayCli(String liferayVersion, File dir, String[] args,
commands.add(nodePath.toString());
commands.add(liferayPath.toString());

for (String arg : args) {
commands.add(arg);
}
Collections.addAll(commands, args);
}
else {
Path nodePath = nodeDirPath.resolve("bin/node");
Expand Down Expand Up @@ -192,9 +191,7 @@ public static int runYo(String liferayVersion, File dir, String[] args, boolean
commands.add(nodePath.toString());
commands.add(yoPath.toString());

for (String arg : args) {
commands.add(arg);
}
Collections.addAll(commands, args);
}
else {
Path nodePath = nodeDirPath.resolve("bin/node");
Expand Down
6 changes: 3 additions & 3 deletions cli/src/test/java/com/liferay/blade/cli/BladeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public class BladeTest extends BladeCLI {

public static final String PRODUCT_VERSION_DXP_74_U72 = "dxp-7.4-u72";

public static final String PRODUCT_VERSION_PORTAL_71 = "portal-7.1-ga4";

public static final String PRODUCT_VERSION_PORTAL_73 = "portal-7.3-ga8";

public static final String PRODUCT_VERSION_PORTAL_74 = "portal-7.4-ga4";

public static final String PRODUCT_VERSION_PORTAL_QUARTER_RELEASE = "dxp-2023.q4.2";

public static BladeTestBuilder builder() {
return new BladeTestBuilder();
}
Expand Down Expand Up @@ -119,7 +119,7 @@ public void run(String[] args) throws Exception {
while (scanner.hasNextLine() && !bridj) {
String line = scanner.nextLine();

if ((line != null) && (line.length() > 0)) {
if ((line != null) && !line.isEmpty()) {
if (line.contains("org/bridj/Platform$DeleteFiles")) {
bridj = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -457,6 +458,34 @@ public void testCreateMVCPortletInteractive() throws Exception {
_checkGradleBuildFiles(projectDir.getAbsolutePath());
}

@Ignore
@Test
public void testCreateMVCPortletQuarterRelease() throws Exception {
File workspace = new File(_rootDir, "workspace");

_makeWorkspaceVersion(workspace, BladeTest.PRODUCT_VERSION_PORTAL_QUARTER_RELEASE);

String[] gradleArgs = {"create", "--base", workspace.getAbsolutePath(), "-t", "mvc-portlet", "foo"};

File projectDir = new File(workspace, "modules/foo");

String projectPath = projectDir.getAbsolutePath();

TestUtil.runBlade(workspace, _extensionsDir, gradleArgs);

_checkGradleBuildFiles(projectPath);

_contains(
_checkFileExists(projectPath + "/src/main/java/foo/portlet/FooPortlet.java"),
".*^public class FooPortlet extends MVCPortlet.*$");

_checkFileExists(projectPath + "/build.gradle");

_checkFileExists(projectPath + "/src/main/resources/META-INF/resources/view.jsp");

_checkFileExists(projectPath + "/src/main/resources/META-INF/resources/init.jsp");
}

@Test
public void testCreateNpmAngular71() throws Exception {
File workspace = new File(_rootDir, "workspace");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -121,6 +122,20 @@ public void testBladeInitEmptyDirectoryHandleTwoDots() throws Exception {
Assert.assertNotNull(bladeTest.getWorkspaceProvider(emptyDir));
}

@Ignore
@Test
public void testBladeInitQuarterRelease() throws Exception {
File emptyDir = temporaryFolder.newFolder();

String[] args = {"--base", emptyDir.getPath(), "init", "-v", BladeTest.PRODUCT_VERSION_PORTAL_QUARTER_RELEASE};

BladeTest bladeTest = _getBladeTestCustomWorkspace(emptyDir);

bladeTest.run(args);

Assert.assertNotNull(bladeTest.getWorkspaceProvider(emptyDir));
}

@Test
public void testBladeInitUpgradePluginsSDKTo70() throws Exception {
File testdir = new File(temporaryFolder.getRoot(), "build/testUpgradePluginsSDKTo70");
Expand Down Expand Up @@ -347,7 +362,7 @@ public void testInitCommandListPromoted() throws Exception {

String firstLine = lines.get(0);

Assert.assertTrue(firstLine, firstLine.contains("dxp-7.4-"));
Assert.assertTrue(firstLine, firstLine.contains("dxp-"));
}

@Test
Expand Down Expand Up @@ -668,7 +683,7 @@ private void _verifyGradleBuild() throws Exception {
GradleRunnerUtil.verifyBuildOutput(projectPath.toString(), "foo-1.0.0.jar");
}

private static final String _GRADLE_PLUGINS_WORKSPACE_VERSION = "9.0.12";
private static final String _GRADLE_PLUGINS_WORKSPACE_VERSION = "9.0.19";

private File _extensionsDir = null;
private File _workspaceDir = null;
Expand Down
Loading

0 comments on commit 98ef7f0

Please sign in to comment.