diff --git a/cli/build.gradle b/cli/build.gradle index f57e46948..7ebe9d8bd 100644 --- a/cli/build.gradle +++ b/cli/build.gradle @@ -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" @@ -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" diff --git a/cli/src/main/java/com/liferay/blade/cli/BladeCLI.java b/cli/src/main/java/com/liferay/blade/cli/BladeCLI.java index 3c2be9d3a..a9d5b1424 100644 --- a/cli/src/main/java/com/liferay/blade/cli/BladeCLI.java +++ b/cli/src/main/java/com/liferay/blade/cli/BladeCLI.java @@ -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]); diff --git a/cli/src/main/java/com/liferay/blade/cli/Extensions.java b/cli/src/main/java/com/liferay/blade/cli/Extensions.java index bbb3a2503..7b435951b 100644 --- a/cli/src/main/java/com/liferay/blade/cli/Extensions.java +++ b/cli/src/main/java/com/liferay/blade/cli/Extensions.java @@ -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; @@ -296,9 +297,7 @@ private static Collection _getFlags(Class clazz, boo if ((withArguments && !type.equals(boolean.class)) || (!withArguments && type.equals(boolean.class))) { - for (String name : names) { - flags.add(name); - } + Collections.addAll(flags, names); } } } diff --git a/cli/src/main/java/com/liferay/blade/cli/WorkspaceConstants.java b/cli/src/main/java/com/liferay/blade/cli/WorkspaceConstants.java index a2b2a0c35..7660fbd80 100644 --- a/cli/src/main/java/com/liferay/blade/cli/WorkspaceConstants.java +++ b/cli/src/main/java/com/liferay/blade/cli/WorkspaceConstants.java @@ -7,6 +7,7 @@ import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; /** * @author David Truong @@ -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 originalLiferayVersions = Arrays.asList("7.0", "7.1", "7.2", "7.3", "7.4"); } \ No newline at end of file diff --git a/cli/src/main/java/com/liferay/blade/cli/command/CreateCommand.java b/cli/src/main/java/com/liferay/blade/cli/command/CreateCommand.java index ce24ea41b..d4d98c1b1 100644 --- a/cli/src/main/java/com/liferay/blade/cli/command/CreateCommand.java +++ b/cli/src/main/java/com/liferay/blade/cli/command/CreateCommand.java @@ -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; } @@ -345,7 +345,7 @@ protected ProjectTemplatesArgs getProjectTemplateArgs( WorkspaceProvider workspaceProvider = bladeCLI.getWorkspaceProvider(dir); projectTemplatesArgs.setDependencyManagementEnabled( - (workspaceProvider != null) ? workspaceProvider.isDependencyManagementEnabled(dir) : false); + (workspaceProvider != null) && workspaceProvider.isDependencyManagementEnabled(dir)); Optional liferayVersion = _getLiferayVersion(workspaceProvider, createArgs); @@ -353,8 +353,6 @@ protected ProjectTemplatesArgs getProjectTemplateArgs( 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()); @@ -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; } @@ -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(); @@ -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) { @@ -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+)"); } \ No newline at end of file diff --git a/cli/src/main/java/com/liferay/blade/cli/command/InitCommand.java b/cli/src/main/java/com/liferay/blade/cli/command/InitCommand.java index 35f602619..38de9f971 100644 --- a/cli/src/main/java/com/liferay/blade/cli/command/InitCommand.java +++ b/cli/src/main/java/com/liferay/blade/cli/command/InitCommand.java @@ -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; @@ -36,6 +37,7 @@ import java.util.Optional; import java.util.Properties; import java.util.Set; +import java.util.regex.Matcher; /** * @author Gregory Amerson @@ -214,11 +216,21 @@ public void execute() throws Exception { ProductInfo productInfo = new ProductInfo((Map)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); diff --git a/cli/src/main/java/com/liferay/blade/cli/gradle/GradleWorkspaceProvider.java b/cli/src/main/java/com/liferay/blade/cli/gradle/GradleWorkspaceProvider.java index fd7b24ce3..c8461a419 100644 --- a/cli/src/main/java/com/liferay/blade/cli/gradle/GradleWorkspaceProvider.java +++ b/cli/src/main/java/com/liferay/blade/cli/gradle/GradleWorkspaceProvider.java @@ -79,13 +79,11 @@ public String getLiferayVersion(File workspaceDir) { ProductInfo productInfo = new ProductInfo((Map)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()) { @@ -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(); diff --git a/cli/src/main/java/com/liferay/blade/cli/util/NodeUtil.java b/cli/src/main/java/com/liferay/blade/cli/util/NodeUtil.java index 86098f2cf..ac385d4a7 100644 --- a/cli/src/main/java/com/liferay/blade/cli/util/NodeUtil.java +++ b/cli/src/main/java/com/liferay/blade/cli/util/NodeUtil.java @@ -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; @@ -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"); @@ -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"); diff --git a/cli/src/test/java/com/liferay/blade/cli/BladeTest.java b/cli/src/test/java/com/liferay/blade/cli/BladeTest.java index 19f6c2514..5baeb2158 100644 --- a/cli/src/test/java/com/liferay/blade/cli/BladeTest.java +++ b/cli/src/test/java/com/liferay/blade/cli/BladeTest.java @@ -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(); } @@ -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; } diff --git a/cli/src/test/java/com/liferay/blade/cli/command/CreateCommandTest.java b/cli/src/test/java/com/liferay/blade/cli/command/CreateCommandTest.java index d43acab3c..78cf63bcb 100644 --- a/cli/src/test/java/com/liferay/blade/cli/command/CreateCommandTest.java +++ b/cli/src/test/java/com/liferay/blade/cli/command/CreateCommandTest.java @@ -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; @@ -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"); diff --git a/cli/src/test/java/com/liferay/blade/cli/command/InitCommandTest.java b/cli/src/test/java/com/liferay/blade/cli/command/InitCommandTest.java index e6bcabf47..f8e5affd9 100644 --- a/cli/src/test/java/com/liferay/blade/cli/command/InitCommandTest.java +++ b/cli/src/test/java/com/liferay/blade/cli/command/InitCommandTest.java @@ -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; @@ -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"); @@ -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 @@ -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.1.3"; private File _extensionsDir = null; private File _workspaceDir = null; diff --git a/cli/src/test/java/com/liferay/blade/cli/command/JavaProcesses.java b/cli/src/test/java/com/liferay/blade/cli/command/JavaProcesses.java index 2202b35ab..14a4feb10 100644 --- a/cli/src/test/java/com/liferay/blade/cli/command/JavaProcesses.java +++ b/cli/src/test/java/com/liferay/blade/cli/command/JavaProcesses.java @@ -179,10 +179,7 @@ public static void main(String[] args) { tomcatFilter ).findAny(); - System.out.println( - "tomcatProcess = " + - tomcatProcess.get( - ).getId()); + tomcatProcess.ifPresent(javaProcess -> System.out.println("tomcatProcess = " + javaProcess.getId())); } public static int maxProcessId() { diff --git a/cli/src/test/java/com/liferay/blade/cli/command/ServerStartCommandTest.java b/cli/src/test/java/com/liferay/blade/cli/command/ServerStartCommandTest.java index 91897a25f..d6f742a53 100644 --- a/cli/src/test/java/com/liferay/blade/cli/command/ServerStartCommandTest.java +++ b/cli/src/test/java/com/liferay/blade/cli/command/ServerStartCommandTest.java @@ -501,7 +501,7 @@ private String[] _getDebugArgs(String[] serverStartArgs) { private void _initBladeWorkspace() throws Exception { String[] initArgs = { - "--base", _testWorkspacePath.toString(), "init", "-v", BladeTest.PRODUCT_VERSION_PORTAL_71 + "--base", _testWorkspacePath.toString(), "init", "-v", BladeTest.PRODUCT_VERSION_PORTAL_74 }; TestUtil.runBlade(_testWorkspacePath, _extensionsPath, initArgs); diff --git a/extensions/maven-profile/src/main/java/com/liferay/blade/extensions/maven/profile/MavenWorkspaceProvider.java b/extensions/maven-profile/src/main/java/com/liferay/blade/extensions/maven/profile/MavenWorkspaceProvider.java index 698e747dd..8cbabe215 100644 --- a/extensions/maven-profile/src/main/java/com/liferay/blade/extensions/maven/profile/MavenWorkspaceProvider.java +++ b/extensions/maven-profile/src/main/java/com/liferay/blade/extensions/maven/profile/MavenWorkspaceProvider.java @@ -7,6 +7,7 @@ import aQute.bnd.version.Version; +import com.liferay.blade.cli.WorkspaceConstants; import com.liferay.blade.cli.WorkspaceProvider; import com.liferay.blade.cli.util.BladeUtil; import com.liferay.blade.extensions.maven.profile.internal.MavenUtil; @@ -14,6 +15,7 @@ import java.io.File; import java.util.Properties; +import java.util.regex.Matcher; /** * @author Christopher Bryan Boyd @@ -35,6 +37,13 @@ public String getProduct(File workspaceDir) { return "portal"; } + Matcher dxpQuarterlyVersionMatcher = WorkspaceConstants.dxpQuarterReleaseVersionPattern.matcher( + targetPlatformVersion); + + if (dxpQuarterlyVersionMatcher.matches()) { + return "dxp"; + } + try { Version version = Version.parseVersion(targetPlatformVersion.replaceAll("-", ".")); diff --git a/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/LXCUtil.java b/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/LXCUtil.java index aa35dddba..c900a7b0c 100644 --- a/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/LXCUtil.java +++ b/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/LXCUtil.java @@ -25,6 +25,7 @@ import java.security.MessageDigest; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -126,9 +127,7 @@ public static int run(Path dir, String[] args, Map env, boolean commands.add("/c"); commands.add(lxcPath.toString()); - for (String arg : args) { - commands.add(arg); - } + Collections.addAll(commands, args); } else { commands.add("sh");