From 3bf3fc9954660f540a88a198cf4d1f31633ac14a Mon Sep 17 00:00:00 2001 From: Simon Jiang Date: Tue, 26 Dec 2023 18:27:19 +0800 Subject: [PATCH] BLADE-742 replace product_info.json with releases.json --- cli/bnd.bnd | 2 +- cli/build.gradle | 12 +- .../java/com/liferay/blade/cli/BladeCLI.java | 14 +- .../com/liferay/blade/cli/Extensions.java | 5 +- .../liferay/blade/cli/WorkspaceConstants.java | 3 + .../blade/cli/command/ConvertCommand.java | 6 +- .../blade/cli/command/CreateCommand.java | 56 ++++++-- .../blade/cli/command/InitCommand.java | 61 ++++---- .../LiferayMoreVersionValidator.java | 22 ++- .../cli/gradle/GradleWorkspaceProvider.java | 24 ++-- .../com/liferay/blade/cli/util/BladeUtil.java | 130 ++++++++++++------ .../com/liferay/blade/cli/util/NodeUtil.java | 9 +- .../liferay/blade/cli/util/ProductInfo.java | 40 ++---- .../blade/cli/util/ProductKeyInfo.java | 104 +++++++++----- .../blade/cli/util/ProductKeyUtil.java | 108 +-------------- .../blade/cli/util/ProductKeyVersion.java | 11 -- .../java/com/liferay/blade/cli/BladeTest.java | 6 +- .../blade/cli/command/CreateCommandTest.java | 29 ++++ .../blade/cli/command/InitCommandTest.java | 19 ++- .../blade/cli/command/JavaProcesses.java | 5 +- .../cli/command/ServerStartCommandTest.java | 2 +- .../maven/profile/MavenWorkspaceProvider.java | 9 ++ ...entExtensionProjectTemplateCustomizer.java | 57 ++++---- .../client/extension/internal/LXCUtil.java | 5 +- 24 files changed, 396 insertions(+), 343 deletions(-) diff --git a/cli/bnd.bnd b/cli/bnd.bnd index cb130d5ee..483bb0b20 100644 --- a/cli/bnd.bnd +++ b/cli/bnd.bnd @@ -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 \ No newline at end of file diff --git a/cli/build.gradle b/cli/build.gradle index f57e46948..98deb8d44 100644 --- a/cli/build.gradle +++ b/cli/build.gradle @@ -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) @@ -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" @@ -139,8 +139,8 @@ downloadPortal { onlyIfNewer true } -downloadProductInfo { - src "https://releases-cdn.liferay.com/tools/workspace/.product_info.json" +downloadReleasesInfo { + src "http://localhost:3000/releases.json" dest buildDir onlyIfNewer true } @@ -148,7 +148,7 @@ downloadProductInfo { jar { dependsOn("unzipPortal") archiveFileName.set("blade.jar") - from createToolingZip, createWrapperZip, downloadProductInfo + from createToolingZip, createWrapperZip, downloadReleasesInfo } processResources { 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..624f48dbb 100644 --- a/cli/src/main/java/com/liferay/blade/cli/BladeCLI.java +++ b/cli/src/main/java/com/liferay/blade/cli/BladeCLI.java @@ -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; @@ -862,14 +863,19 @@ private Map _buildMavenPossibleValuesMap( Iterator it = options.iterator(); - Map productInfos = BladeUtil.getProductInfos(true, error()); + Map releasesInfos = BladeUtil.getReleasesInfos(true, error()); Map optionsMap = new LinkedHashMap<>(); for (int x = 1; it.hasNext(); x++) { String option = it.next(); - ProductInfo productInfo = new ProductInfo((Map)productInfos.get(option)); + ProductKeyInfo productKeyInfo = new ProductKeyInfo( + option, (Map)releasesInfos.get(option)); + + ProductInfo productInfo = new ProductInfo( + productKeyInfo, + BladeUtil.getReleaseProperties(productKeyInfo.getProduct(), productKeyInfo.getProductKey())); optionsMap.put(String.valueOf(x), productInfo.getTargetPlatformVersion()); } @@ -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]); 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..efa016188 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( + "^(?dxp)-(?2\\d{3})\\.(?q[1234])\\.(?\\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/ConvertCommand.java b/cli/src/main/java/com/liferay/blade/cli/command/ConvertCommand.java index 00f63c769..093669ccf 100644 --- a/cli/src/main/java/com/liferay/blade/cli/command/ConvertCommand.java +++ b/cli/src/main/java/com/liferay/blade/cli/command/ConvertCommand.java @@ -1211,12 +1211,10 @@ private Optional _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 productInfos = BladeUtil.getProductInfos(); - - ProductInfo productInfo = new ProductInfo((Map)productInfos.get(productKey)); + ProductInfo productInfo = BladeUtil.getProductInfo(productKey); return Optional.of(productInfo.getTargetPlatformVersion()); } 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..744df54e6 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 @@ -191,7 +193,7 @@ public void execute() throws Exception { String liferayVersion; String workspaceProductKey; - Map productInfos = BladeUtil.getProductInfos(initArgs.isTrace(), bladeCLI.error()); + Map releasesInfos = BladeUtil.getReleasesInfos(initArgs.isTrace(), bladeCLI.error()); if (!mavenBuild) { workspaceProductKey = _getDefaultProductKey(initArgs); @@ -204,7 +206,7 @@ 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); @@ -212,21 +214,31 @@ public void execute() throws Exception { return; } - ProductInfo productInfo = new ProductInfo((Map)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); @@ -487,33 +499,28 @@ private String _setProductAndVersionForMaven(Map 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)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 entryKey : productInfos.entrySet()) { - ProductInfo productInfo = new ProductInfo((Map)entryKey.getValue()); - if (Objects.equals(possibleProductKey, productInfo.getTargetPlatformVersion())) { - possibleProductKey = entryKey.getKey(); + for (Map.Entry 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; } } diff --git a/cli/src/main/java/com/liferay/blade/cli/command/validator/LiferayMoreVersionValidator.java b/cli/src/main/java/com/liferay/blade/cli/command/validator/LiferayMoreVersionValidator.java index b43158c1c..7f5c88bff 100644 --- a/cli/src/main/java/com/liferay/blade/cli/command/validator/LiferayMoreVersionValidator.java +++ b/cli/src/main/java/com/liferay/blade/cli/command/validator/LiferayMoreVersionValidator.java @@ -9,11 +9,12 @@ 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 com.liferay.blade.cli.util.ProductKeyInfo; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.Set; /** @@ -30,15 +31,22 @@ public List get() { public void validate(String name, String value) throws ParameterException { List possibleValues = new ArrayList<>(get()); - Set allTargetPlatformVersions = BladeUtil.getWorkspaceProductTargetPlatformVersions(false); + Map workspaceProductTargetPlatformVersions = + BladeUtil.getWorkspaceProductTargetPlatformVersions(false); possibleValues.addAll(WorkspaceConstants.originalLiferayVersions); - if ((!possibleValues.contains(value) && !allTargetPlatformVersions.contains(value)) || - (!ProductKeyUtil.verifyPortalDxpWorkspaceProduct(value) && !VersionUtil.isLiferayVersion(value) && - !ProductKeyUtil.verifyCommerceWorkspaceProduct(value))) { + Set allTargetPlatformVersions = workspaceProductTargetPlatformVersions.keySet(); - throw new ParameterException(value + " is not a valid value."); + if (!possibleValues.contains(value) && !allTargetPlatformVersions.contains(value)) { + ProductKeyInfo productKeyInfo = workspaceProductTargetPlatformVersions.get(value); + + if (!productKeyInfo.isQuarterly() && + !(Objects.equals(productKeyInfo.getProduct(), "dxp") || + Objects.equals(productKeyInfo.getProduct(), "portal"))) { + + throw new ParameterException(value + " is not a valid value."); + } } } 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..18278e1c9 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 @@ -17,7 +17,6 @@ import java.io.File; import java.io.FilenameFilter; -import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Properties; @@ -75,17 +74,13 @@ public String getLiferayVersion(File workspaceDir) { if (!baseLiferayVersion.isPresent()) { String productKey = gradleProperties.getProperty(WorkspaceConstants.DEFAULT_WORKSPACE_PRODUCT_PROPERTY); - Map productInfoMap = BladeUtil.getProductInfos(); + ProductInfo productInfo = BladeUtil.getProductInfo(productKey); - 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 +139,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/BladeUtil.java b/cli/src/main/java/com/liferay/blade/cli/util/BladeUtil.java index a749b28d5..682d4123c 100644 --- a/cli/src/main/java/com/liferay/blade/cli/util/BladeUtil.java +++ b/cli/src/main/java/com/liferay/blade/cli/util/BladeUtil.java @@ -37,6 +37,8 @@ import java.security.CodeSource; import java.security.ProtectionDomain; +import java.text.MessageFormat; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -49,7 +51,6 @@ import java.util.Objects; import java.util.Properties; import java.util.Scanner; -import java.util.Set; import java.util.function.Predicate; import java.util.jar.Attributes; import java.util.jar.JarFile; @@ -318,23 +319,71 @@ public static String getManifestProperty(Path pathToJar, String propertyName) th } } - public static Map getProductInfos() { - return getProductInfos(false, null); + @SuppressWarnings("unchecked") + public static ProductInfo getProductInfo(String productKey) { + Map releasesInfos = getReleasesInfos(); + + ProductKeyInfo productKeyInfo = new ProductKeyInfo( + productKey, (Map)releasesInfos.get(productKey)); + + return new ProductInfo( + productKeyInfo, getReleaseProperties(productKeyInfo.getProduct(), productKeyInfo.getProductKey())); + } + + public static Properties getProperties(File file) { + Properties properties = new Properties(); + + try (InputStream inputStream = Files.newInputStream(file.toPath())) { + properties.load(inputStream); + } + catch (Exception exception) { + } + + return properties; + } + + public static Properties getReleaseProperties(String product, String productKey) { + Properties properties = new Properties(); + + File productDest = new File(_workspaceCacheDir, product); + + File releasePropertiesDest = new File(productDest, productKey); + + try { + String actualReleasePropertiesUrl = MessageFormat.format(_RELEASE_PROPERTIES_URL, product, productKey); + + Path releasesPropertiesPath = downloadFile( + actualReleasePropertiesUrl, releasePropertiesDest.toPath(), "release.properties"); + + if (Files.exists(releasesPropertiesPath)) { + try (InputStream input = Files.newInputStream(releasesPropertiesPath)) { + properties.load(input); + } + } + } + catch (Exception exception) { + } + + return properties; + } + + public static Map getReleasesInfos() { + return getReleasesInfos(false, null); } @SuppressWarnings("unchecked") - public static synchronized Map getProductInfos(boolean trace, PrintStream printStream) { - if (!_productInfoMap.isEmpty()) { - return _productInfoMap; + public static synchronized Map getReleasesInfos(boolean trace, PrintStream printStream) { + if (!_releasesInfoMap.isEmpty()) { + return _releasesInfoMap; } JsonSlurper jsonSlurper = new JsonSlurper(); try { - Path productInfoPath = downloadFile(_PRODUCT_INFO_URL, _workspaceCacheDir.toPath(), ".product_info.json"); + Path releasesInfoPath = downloadFile(_RELEASE_INFO_URL, _workspaceCacheDir.toPath(), "releases.json"); - try (BufferedReader reader = Files.newBufferedReader(productInfoPath)) { - _productInfoMap = (Map)jsonSlurper.parse(reader); + try (BufferedReader reader = Files.newBufferedReader(releasesInfoPath)) { + _releasesInfoMap = (Map)jsonSlurper.parse(reader); } } catch (Exception exception1) { @@ -342,8 +391,8 @@ public static synchronized Map getProductInfos(boolean trace, Pr exception1.printStackTrace(printStream); } - try (InputStream resourceAsStream = BladeUtil.class.getResourceAsStream("/.product_info.json")) { - _productInfoMap = (Map)jsonSlurper.parse(resourceAsStream); + try (InputStream resourceAsStream = BladeUtil.class.getResourceAsStream("/releases.json")) { + _releasesInfoMap = (Map)jsonSlurper.parse(resourceAsStream); } catch (Exception exception2) { if (trace && (printStream != null)) { @@ -352,19 +401,7 @@ public static synchronized Map getProductInfos(boolean trace, Pr } } - return _productInfoMap; - } - - public static Properties getProperties(File file) { - Properties properties = new Properties(); - - try (InputStream inputStream = Files.newInputStream(file.toPath())) { - properties.load(inputStream); - } - catch (Exception exception) { - } - - return properties; + return _releasesInfoMap; } public static Collection getTemplateNames(BladeCLI blade) throws Exception { @@ -391,25 +428,29 @@ public static Map getTemplates(BladeCLI bladeCLI) throws Excepti @SuppressWarnings("unchecked") public static List getWorkspaceProductKeys(boolean promoted) { - Map productInfos = getProductInfos(); + Map releasesInfos = getReleasesInfos(); - return productInfos.keySet( + return releasesInfos.keySet( ).stream( ).filter( - key -> Objects.nonNull(productInfos.get(key)) + key -> Objects.nonNull(releasesInfos.get(key)) ).filter( key -> { - ProductInfo productInfo = new ProductInfo((Map)productInfos.get(key)); + ProductKeyInfo productKeyInfo = new ProductKeyInfo(key, (Map)releasesInfos.get(key)); - if (productInfo.getTargetPlatformVersion() == null) { + if (productKeyInfo.getProduct() == null) { return false; } - if (promoted && !productInfo.isPromoted()) { + if (!promoted || productKeyInfo.isPromoted()) { + return true; + } + + if (productKeyInfo.getReleaseDate() == null) { return false; } - return true; + return productKeyInfo.getLiferayProductVersion() != null; } ).sorted( ProductKeyUtil.comparator @@ -419,21 +460,24 @@ public static List getWorkspaceProductKeys(boolean promoted) { } @SuppressWarnings("unchecked") - public static Set getWorkspaceProductTargetPlatformVersions(boolean promoted) { - Map productInfos = getProductInfos(); + public static Map getWorkspaceProductTargetPlatformVersions(boolean promoted) { + Map releasesInfos = getReleasesInfos(); - return productInfos.entrySet( + return releasesInfos.entrySet( ).stream( ).filter( - entry -> Objects.nonNull(productInfos.get(entry.getKey())) + entry -> Objects.nonNull(releasesInfos.get(entry.getKey())) ).map( - entry -> new ProductInfo((Map)entry.getValue()) + entry -> new ProductKeyInfo(entry.getKey(), (Map)entry.getValue()) ).filter( - product -> Objects.nonNull(product.getTargetPlatformVersion()) && (!promoted || product.isPromoted()) + productKeyInfo -> !promoted || productKeyInfo.isPromoted() ).map( - ProductInfo::getTargetPlatformVersion + productKeyInfo -> new ProductInfo( + productKeyInfo, getReleaseProperties(productKeyInfo.getProduct(), productKeyInfo.getProductKey())) + ).filter( + productInfo -> Objects.nonNull(productInfo.getTargetPlatformVersion()) ).collect( - Collectors.toSet() + Collectors.toMap(ProductInfo::getTargetPlatformVersion, ProductInfo::getProductKey) ); } @@ -857,10 +901,14 @@ private static Path _downloadFile( private static final String _GRADLEW_WINDOWS_FILE_NAME = "gradlew.bat"; - private static final String _PRODUCT_INFO_URL = "https://releases.liferay.com/tools/workspace/.product_info.json"; + //private static final String _PRODUCT_INFO_URL = "https://releases.liferay.com/tools/workspace/.product_info.json"; + + private static final String _RELEASE_INFO_URL = "http://localhost:3000/releases.json"; + + private static final String _RELEASE_PROPERTIES_URL = "http://localhost:3000/{0}/{1}/release.properties"; private static final Pattern _microPattern = Pattern.compile("((([efs])p)|(ga)|(u))([0-9]+)(-[0-9]+)?"); - private static Map _productInfoMap = Collections.emptyMap(); + private static Map _releasesInfoMap = Collections.emptyMap(); private static final File _workspaceCacheDir = new File( System.getProperty("user.home"), _DEFAULT_WORKSPACE_CACHE_DIR_NAME); 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/main/java/com/liferay/blade/cli/util/ProductInfo.java b/cli/src/main/java/com/liferay/blade/cli/util/ProductInfo.java index ba99a8818..3502c2522 100644 --- a/cli/src/main/java/com/liferay/blade/cli/util/ProductInfo.java +++ b/cli/src/main/java/com/liferay/blade/cli/util/ProductInfo.java @@ -5,8 +5,7 @@ package com.liferay.blade.cli.util; -import java.util.Map; -import java.util.Optional; +import java.util.Properties; /** * @author Simon Jiang @@ -14,14 +13,15 @@ */ public class ProductInfo { - public ProductInfo(Map productMap) { - _appServerTomcatVersion = _safeGet(productMap, "appServerTomcatVersion", ""); - _bundleUrl = _safeGet(productMap, "bundleUrl", ""); - _liferayDockerImage = _safeGet(productMap, "liferayDockerImage", ""); - _liferayProductVersion = _safeGet(productMap, "liferayProductVersion", ""); - _releaseDate = _safeGet(productMap, "releaseDate", ""); - _targetPlatformVersion = _safeGet(productMap, "targetPlatformVersion", ""); - _promoted = Boolean.parseBoolean(_safeGet(productMap, "promoted", "false")); + public ProductInfo(ProductKeyInfo productKeyInfo, Properties releaseProperties) { + _productKeyInfo = productKeyInfo; + + _appServerTomcatVersion = releaseProperties.getProperty("app.server.tomcat.version"); + _bundleUrl = releaseProperties.getProperty("bundle.url"); + _liferayDockerImage = releaseProperties.getProperty("liferay.docker.image"); + _liferayProductVersion = releaseProperties.getProperty("liferay.product.version"); + _releaseDate = releaseProperties.getProperty("release.date"); + _targetPlatformVersion = releaseProperties.getProperty("target.platform.version"); } public String getAppServerTomcatVersion() { @@ -40,6 +40,10 @@ public String getLiferayProductVersion() { return _liferayProductVersion; } + public ProductKeyInfo getProductKey() { + return _productKeyInfo; + } + public String getReleaseDate() { return _releaseDate; } @@ -48,25 +52,11 @@ public String getTargetPlatformVersion() { return _targetPlatformVersion; } - public boolean isPromoted() { - return _promoted; - } - - private String _safeGet(Map map, String key, String defVal) { - return Optional.ofNullable( - map - ).map( - m -> m.get(key) - ).orElse( - defVal - ); - } - private String _appServerTomcatVersion; private String _bundleUrl; private final String _liferayDockerImage; private final String _liferayProductVersion; - private Boolean _promoted = false; + private ProductKeyInfo _productKeyInfo; private final String _releaseDate; private String _targetPlatformVersion; diff --git a/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyInfo.java b/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyInfo.java index 15f13c4a9..944b1b93c 100644 --- a/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyInfo.java +++ b/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyInfo.java @@ -5,84 +5,114 @@ package com.liferay.blade.cli.util; +import java.text.SimpleDateFormat; + import java.util.Comparator; +import java.util.Date; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Function; /** * @author Drew Brokke + * @author Simon Jiang */ public class ProductKeyInfo implements Comparable { + public ProductKeyInfo(String productKey, Map releaseMap) { + _productKey = productKey; + + _releaseDate = _safeGet(releaseMap, "releaseDate", ""); + _liferayProductVersion = _safeGet(releaseMap, "liferayProductVersion", ""); + _product = _safeGet(releaseMap, "product", ""); + + _promoted = Boolean.parseBoolean(_safeGet(releaseMap, "promoted", "false")); + _quarterly = Boolean.parseBoolean(_safeGet(releaseMap, "quarterly", "false")); + } + @Override - public int compareTo(final ProductKeyInfo keyInfo) { + public int compareTo(ProductKeyInfo keyInfo) { return Comparator.comparing( - ProductKeyInfo::getProductRank - ).thenComparing( - ProductKeyInfo::isQuarterly + (Function)productKeyInfo -> { + if (Objects.equals(productKeyInfo.getProduct(), "dxp")) { + return 1; + } + + return -1; + } ).thenComparing( - ProductKeyInfo::getMajorProductKeyVersion + productKeyInfo -> { + if (productKeyInfo.isQuarterly()) { + return 1; + } + + return -1; + } ).thenComparing( - ProductKeyInfo::getMinorProductKeyVersion + productKeyInfo -> ProductKeyUtil.createProductKeyVersion(productKeyInfo.getLiferayProductVersion()) ).thenComparing( - ProductKeyInfo::getMicroProductKeyVersion + ProductKeyInfo::getReleaseDate ).reversed( ).compare( this, keyInfo ); } - public ProductKeyVersion getMajorProductKeyVersion() { - return _majorProductKeyVersion; - } - - public ProductKeyVersion getMicroProductKeyVersion() { - return _microProductKeyVersion; - } - - public ProductKeyVersion getMinorProductKeyVersion() { - return _minorProductKeyVersion; + public String getLiferayProductVersion() { + return _liferayProductVersion; } public String getProduct() { return _product; } - public int getProductRank() { - return _productRank; + public String getProductKey() { + return _productKey; } - public boolean isQuarterly() { - return _quarterly; - } + public Date getReleaseDate() { + try { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - public void setMajorProductKeyVersion(ProductKeyVersion majorProductKeyVersion) { - _majorProductKeyVersion = majorProductKeyVersion; + return format.parse(_releaseDate); + } + catch (Exception exception) { + return null; + } } - public void setMicroProductKeyVersion(ProductKeyVersion microProductKeyVersion) { - _microProductKeyVersion = microProductKeyVersion; + public boolean isPromoted() { + return _promoted; } - public void setMinorProductKeyVersion(ProductKeyVersion minorProductKeyVersion) { - _minorProductKeyVersion = minorProductKeyVersion; + public boolean isQuarterly() { + return _quarterly; } 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 _safeGet(Map map, String key, String defVal) { + return Optional.ofNullable( + map + ).map( + m -> m.get(key) + ).orElse( + defVal + ); + } + + private String _liferayProductVersion; private String _product; - private int _productRank = -1; - private boolean _quarterly = false; + private String _productKey; + private Boolean _promoted = false; + private Boolean _quarterly = false; + private String _releaseDate; } \ No newline at end of file diff --git a/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyUtil.java b/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyUtil.java index 8011dbb6c..092abcf5d 100644 --- a/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyUtil.java +++ b/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyUtil.java @@ -5,14 +5,8 @@ package com.liferay.blade.cli.util; -import java.util.Arrays; -import java.util.Collections; import java.util.Comparator; -import java.util.List; -import java.util.Objects; -import java.util.function.Consumer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.Map; /** * @author Drew Brokke @@ -20,14 +14,6 @@ public class ProductKeyUtil { public static final Comparator comparator = ProductKeyUtil::compare; - public static final Pattern productKeyCommercePattern = Pattern.compile( - "^(?commerce)-(?[1-9]\\.\\d\\.\\d)(?:-(?[1-9]\\.\\d))?$"); - public static final Pattern productKeyDXPNonquarterlyPattern = Pattern.compile( - "^(?dxp)-(?[1-9]\\.\\d)-(?(?:de|ep|fp|ga|sp|u)\\d+)$"); - public static final Pattern productKeyDXPQuarterlyPattern = Pattern.compile( - "^(?dxp)-(?2\\d{3})\\.(?q[1234])\\.(?\\d+)$"); - public static final Pattern productKeyPortalPattern = Pattern.compile( - "^(?portal)-(?[1-9]\\.\\d)-(?ga\\d+)$"); public static int compare(String productKey1, String productKey2) { ProductKeyInfo keyInfo1 = createProductKeyInfo(productKey1); @@ -35,115 +21,29 @@ public static int compare(String productKey1, String productKey2) { return keyInfo1.compareTo(createProductKeyInfo(productKey2)); } + @SuppressWarnings("unchecked") public static ProductKeyInfo createProductKeyInfo(String productKey) { - Matcher matcher = _getFirstMatchingMatcher( - productKey, productKeyDXPQuarterlyPattern, productKeyDXPNonquarterlyPattern, productKeyPortalPattern, - productKeyCommercePattern); + Map releasesInfos = BladeUtil.getReleasesInfos(); - if (matcher == null) { - throw new IllegalArgumentException(String.format("%s is not a valid Liferay product key\n", productKey)); - } - - ProductKeyInfo productKeyInfo = new ProductKeyInfo(); - - _withGroup( - matcher, "product", - group -> { - productKeyInfo.setProduct(group); - - productKeyInfo.setProductRank(_getProductRank(group)); - }); - _withGroup(matcher, "major", group -> productKeyInfo.setMajorProductKeyVersion(createProductKeyVersion(group))); - _withGroup( - matcher, "minor", - group -> { - ProductKeyVersion minorProductKeyVersion = createProductKeyVersion(group); - - productKeyInfo.setMinorProductKeyVersion(minorProductKeyVersion); - - if (Objects.equals(productKeyInfo.getProduct(), "dxp") && - Objects.equals(minorProductKeyVersion.getType(), "q")) { - - productKeyInfo.setQuarterly(true); - } - }); - _withGroup(matcher, "micro", group -> productKeyInfo.setMicroProductKeyVersion(createProductKeyVersion(group))); - - return productKeyInfo; + return new ProductKeyInfo(productKey, (Map)releasesInfos.get(productKey)); } public static ProductKeyVersion createProductKeyVersion(String versionString) { ProductKeyVersion productKeyVersion = new ProductKeyVersion(); StringBuilder numberStringBuilder = new StringBuilder(); - StringBuilder typeStringBuilder = new StringBuilder(); for (char c : versionString.toCharArray()) { if (Character.isDigit(c)) { numberStringBuilder.append(c); } - else if (Character.isAlphabetic(c)) { - typeStringBuilder.append(c); - } } if (numberStringBuilder.length() > 0) { productKeyVersion.setNumber(Integer.parseInt(numberStringBuilder.toString())); } - productKeyVersion.setType(typeStringBuilder.toString()); - return productKeyVersion; } - public static boolean verifyCommerceWorkspaceProduct(String product) { - return _matchesAny(product, productKeyCommercePattern); - } - - public static boolean verifyPortalDxpWorkspaceProduct(String product) { - return _matchesAny( - product, productKeyDXPQuarterlyPattern, productKeyDXPNonquarterlyPattern, productKeyPortalPattern); - } - - private static Matcher _getFirstMatchingMatcher(String s, Pattern... patterns) { - for (Pattern pattern : patterns) { - Matcher matcher = pattern.matcher(s); - - if (matcher.matches()) { - return matcher; - } - } - - return null; - } - - private static int _getProductRank(String name) { - return _orderedProducts.size() - _orderedProducts.indexOf(name); - } - - private static boolean _matchesAny(String s, Pattern... patterns) { - Matcher matcher = _getFirstMatchingMatcher(s, patterns); - - if (matcher != null) { - return true; - } - - return false; - } - - private static void _withGroup(Matcher matcher, String groupName, Consumer consumer) { - try { - String group = matcher.group(groupName); - - if (group != null) { - consumer.accept(group); - } - } - catch (Exception exception) { - } - } - - private static final List _orderedProducts = Collections.unmodifiableList( - Arrays.asList("dxp", "portal", "commerce")); - } \ No newline at end of file diff --git a/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyVersion.java b/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyVersion.java index 38b7f32ca..64a9f5d4b 100644 --- a/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyVersion.java +++ b/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyVersion.java @@ -18,8 +18,6 @@ public class ProductKeyVersion implements Comparable { public int compareTo(final ProductKeyVersion version) { return Comparator.comparingInt( ProductKeyVersion::getNumber - ).thenComparing( - ProductKeyVersion::getType ).compare( this, version ); @@ -29,19 +27,10 @@ public int getNumber() { return _number; } - public String getType() { - return _type; - } - public void setNumber(int number) { _number = number; } - public void setType(String type) { - _type = type; - } - private int _number = 0; - private String _type; } \ No newline at end of file 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/ClientExtensionProjectTemplateCustomizer.java b/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/ClientExtensionProjectTemplateCustomizer.java index f9b511998..b85d204bf 100644 --- a/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/ClientExtensionProjectTemplateCustomizer.java +++ b/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/ClientExtensionProjectTemplateCustomizer.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Optional; import org.apache.maven.archetype.ArchetypeGenerationRequest; @@ -82,28 +81,7 @@ public void onBeforeGenerateProject( String projectName = projectTemplatesArgs.getName(); - List args = new ArrayList<>(); - - args.add("generate"); - args.add("-i"); - args.add(projectName); - - ClientExtensionProjectTemplatesArgsExt clientExtensionTemplateExt = - (ClientExtensionProjectTemplatesArgsExt)projectTemplatesArgs.getProjectTemplatesArgsExt(); - - String extensionName = clientExtensionTemplateExt.getExtensionName(); - - if (extensionName != null) { - args.add("-n"); - args.add(extensionName); - } - - String extensionType = clientExtensionTemplateExt.getExtensionType(); - - if (extensionType != null) { - args.add("-t"); - args.add(extensionType); - } + List args = _getProjectTemplatesArgs(projectTemplatesArgs, projectName); File destinationDir = projectTemplatesArgs.getDestinationDir(); @@ -153,12 +131,10 @@ private static 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 productInfos = BladeUtil.getProductInfos(); - - ProductInfo productInfo = new ProductInfo((Map)productInfos.get(productKey)); + ProductInfo productInfo = BladeUtil.getProductInfo(productKey); return productInfo.getTargetPlatformVersion(); } @@ -183,6 +159,33 @@ private static String _getTargetPlatformVersionFromProduct(String productKey) { return null; } + private List _getProjectTemplatesArgs(ProjectTemplatesArgs projectTemplatesArgs, String projectName) { + List args = new ArrayList<>(); + + args.add("generate"); + args.add("-i"); + args.add(projectName); + + ClientExtensionProjectTemplatesArgsExt clientExtensionTemplateExt = + (ClientExtensionProjectTemplatesArgsExt)projectTemplatesArgs.getProjectTemplatesArgsExt(); + + String extensionName = clientExtensionTemplateExt.getExtensionName(); + + if (extensionName != null) { + args.add("-n"); + args.add(extensionName); + } + + String extensionType = clientExtensionTemplateExt.getExtensionType(); + + if (extensionType != null) { + args.add("-t"); + args.add(extensionType); + } + + return args; + } + private static final String _BASE_BOM_URL = "https://repository.liferay.com/nexus/content/groups/public/com/liferay/portal/"; 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");