From 1a8e5b46bbe008fd06c36a59a69b9530fa608904 Mon Sep 17 00:00:00 2001 From: drewbrokke Date: Thu, 11 Jul 2024 14:11:36 -0500 Subject: [PATCH 1/4] INTELLIJ-288 LiferayWorkspaceSupprt: adds multiple fallback conditions for finding a ReleaseEntry by product and version --- .../idea/util/LiferayWorkspaceSupport.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/liferay/ide/idea/util/LiferayWorkspaceSupport.java b/src/main/java/com/liferay/ide/idea/util/LiferayWorkspaceSupport.java index 46e473d4..8717813c 100644 --- a/src/main/java/com/liferay/ide/idea/util/LiferayWorkspaceSupport.java +++ b/src/main/java/com/liferay/ide/idea/util/LiferayWorkspaceSupport.java @@ -21,12 +21,12 @@ import com.liferay.release.util.ReleaseUtil; import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -175,13 +175,31 @@ public static String[] getProductVersions(boolean showAll) { } @Nullable - public static ReleaseEntry getReleaseEntry(String product, String targetPlatform) throws IOException { - Stream releaseEntryStream = getReleaseEntryStream(); + public static ReleaseEntry getReleaseEntry(String version) { + return getReleaseEntry(null, version); + } - return releaseEntryStream.filter( - releaseEntry -> Objects.equals(releaseEntry.getProduct(), product) + @Nullable + public static ReleaseEntry getReleaseEntry(String product, String version) { + Predicate productGroupVersionPredicate = releaseEntry -> Objects.equals( + releaseEntry.getProductGroupVersion(), version); + Predicate productPredicate = releaseEntry -> Objects.equals(releaseEntry.getProduct(), product); + Predicate releaseKeyPredicate = releaseEntry -> Objects.equals( + releaseEntry.getReleaseKey(), version); + Predicate targetPlatformVersionPredicate = releaseEntry -> Objects.equals( + releaseEntry.getTargetPlatformVersion(), version); + + return ReleaseUtil.getReleaseEntryStream( ).filter( - releaseEntry -> Objects.equals(releaseEntry.getTargetPlatformVersion(), targetPlatform) + releaseKeyPredicate.or( + productPredicate.and(targetPlatformVersionPredicate) + ).or( + productPredicate.and(productGroupVersionPredicate) + ).or( + targetPlatformVersionPredicate + ).or( + productGroupVersionPredicate + ) ).findFirst( ).orElse( null From 7f1f34634c2e8e6b17d46dd535aaa8b42e5df9a3 Mon Sep 17 00:00:00 2001 From: drewbrokke Date: Thu, 11 Jul 2024 14:07:45 -0500 Subject: [PATCH 2/4] INTELLIJ-288 BladeCli: updates methods to make constructing arguments easier --- .../java/com/liferay/ide/idea/util/BladeCLI.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/liferay/ide/idea/util/BladeCLI.java b/src/main/java/com/liferay/ide/idea/util/BladeCLI.java index 07657d8e..98cf1c9b 100755 --- a/src/main/java/com/liferay/ide/idea/util/BladeCLI.java +++ b/src/main/java/com/liferay/ide/idea/util/BladeCLI.java @@ -16,6 +16,8 @@ import java.nio.file.Files; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Objects; import java.util.Properties; @@ -41,6 +43,10 @@ public class BladeCLI { public static final String BLADE_LATEST = "blade-latest.jar"; + public static String[] execute(File bladeJar, Collection args) { + return execute(bladeJar, String.join(" ", args)); + } + public static String[] execute(File bladeJar, String args) { Project project = new Project(); Java javaTask = new Java(); @@ -149,11 +155,11 @@ else if (hasErrors) { return lines.toArray(new String[0]); } - public static String[] execute(com.intellij.openapi.project.Project liferayProject, String args) { + public static String[] execute(com.intellij.openapi.project.Project liferayProject, Collection args) { return execute(getBladeJar(getBladeJarVersion(liferayProject)), args); } - public static String[] executeWithLatestBlade(String args) { + public static String[] executeWithLatestBlade(Collection args) { return execute(getBladeJar(BLADE_LATEST), args); } @@ -220,7 +226,7 @@ public static synchronized String getBladeJarVersion(com.intellij.openapi.projec public static synchronized String[] getProjectTemplates(com.intellij.openapi.project.Project liferayProject) { List templateNames = new ArrayList<>(); - String[] executeResult = execute(liferayProject, "create -l"); + String[] executeResult = execute(liferayProject, Arrays.asList("create", "-l")); for (String name : executeResult) { String trimmedName = name.trim(); @@ -236,6 +242,10 @@ public static synchronized String[] getProjectTemplates(com.intellij.openapi.pro return templateNames.toArray(new String[0]); } + public static String quote(String s) { + return "\"" + s + "\""; + } + private static String _getBladeVersion(InputStream inputStream) { try (ZipInputStream zipInput = new ZipInputStream(inputStream)) { ZipEntry zipEntry; From b5442bf26f167d5daf31c73e80d588bfc790c9d2 Mon Sep 17 00:00:00 2001 From: drewbrokke Date: Thu, 11 Jul 2024 14:09:39 -0500 Subject: [PATCH 3/4] INTELLIJ-288 uses new BladeCli args methods --- .../idea/ui/modules/LiferayModuleBuilder.java | 59 ++++++++----------- .../ui/modules/LiferayWorkspaceBuilder.java | 28 ++++----- .../modules/ext/LiferayModuleExtBuilder.java | 33 +++++------ .../SpringMVCPortletModuleBuilder.java | 57 ++++++++---------- 4 files changed, 78 insertions(+), 99 deletions(-) diff --git a/src/main/java/com/liferay/ide/idea/ui/modules/LiferayModuleBuilder.java b/src/main/java/com/liferay/ide/idea/ui/modules/LiferayModuleBuilder.java index d4c55fff..7fb48826 100755 --- a/src/main/java/com/liferay/ide/idea/ui/modules/LiferayModuleBuilder.java +++ b/src/main/java/com/liferay/ide/idea/ui/modules/LiferayModuleBuilder.java @@ -176,71 +176,62 @@ public void setupRootModel(@NotNull ModifiableRootModel modifiableRootModel) { VirtualFile moduleParentDir = moduleDir.getParent(); - StringBuilder sb = new StringBuilder(); + List args = new ArrayList<>(); - sb.append("create "); - sb.append("-d \""); - sb.append(moduleParentDir.getPath()); - sb.append("\" "); - sb.append("--base \""); - sb.append(project.getProjectFilePath()); - sb.append("\" "); + args.add("create"); + + args.add("-d"); + args.add(BladeCLI.quote(moduleParentDir.getPath())); + + args.add("--base"); + args.add(BladeCLI.quote(project.getProjectFilePath())); String typeId = liferayProjectType.getId(); if (Objects.equals(typeId, LiferayProjectType.LIFERAY_MAVEN_WORKSPACE)) { - sb.append("-b "); - sb.append("maven "); + args.add("-b"); + args.add("maven"); } String targetPlatformVersion = LiferayWorkspaceSupport.getTargetPlatformVersion(project); if (targetPlatformVersion != null) { - sb.append("-v "); - sb.append(targetPlatformVersion); + args.add("-v"); + args.add(targetPlatformVersion); } - sb.append(" "); - sb.append("-t "); - sb.append(_type); - sb.append(" "); + args.add("-t"); + args.add(_type); if (!CoreUtil.isNullOrEmpty(_className)) { - sb.append("-c "); - sb.append(_className); - sb.append(" "); + args.add("-c"); + args.add(_className); } if (!CoreUtil.isNullOrEmpty(_packageName)) { - sb.append("-p "); - sb.append(_packageName); - sb.append(" "); + args.add("-p"); + args.add(_packageName); } if (_type.equals("theme-contributor")) { - sb.append("-C "); + args.add("-C"); if (!CoreUtil.isNullOrEmpty(_contributorType)) { - sb.append(_contributorType); + args.add(_contributorType); } else { - sb.append(moduleDir.getName()); + args.add(moduleDir.getName()); } - - sb.append(" "); } if ((_type.equals("service") || _type.equals("service-wrapper")) && !CoreUtil.isNullOrEmpty(_serviceName)) { - sb.append("-s "); - sb.append(_serviceName); - sb.append(" "); + args.add("-s"); + args.add(_serviceName); } - sb.append("\""); - sb.append(moduleDir.getName()); - sb.append("\" "); + args.add(BladeCLI.quote(moduleDir.getName())); - BladeCLI.execute(project, sb.toString()); + BladeCLI.execute(project, args); modifiableRootModel.addContentEntry(moduleDir); diff --git a/src/main/java/com/liferay/ide/idea/ui/modules/LiferayWorkspaceBuilder.java b/src/main/java/com/liferay/ide/idea/ui/modules/LiferayWorkspaceBuilder.java index 8edce8d2..75cf2cf1 100644 --- a/src/main/java/com/liferay/ide/idea/ui/modules/LiferayWorkspaceBuilder.java +++ b/src/main/java/com/liferay/ide/idea/ui/modules/LiferayWorkspaceBuilder.java @@ -34,6 +34,8 @@ import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import java.util.Properties; import java.util.stream.Stream; @@ -179,35 +181,33 @@ public boolean validate() throws com.intellij.openapi.options.ConfigurationExcep } protected void initWorkspace(Project project) { - StringBuilder sb = new StringBuilder(); + List args = new ArrayList<>(); - sb.append("--base "); - sb.append("\""); - sb.append(project.getBasePath()); - sb.append("\" "); - sb.append("init "); - sb.append("-v "); + args.add("--base"); + args.add(BladeCLI.quote(project.getBasePath())); + args.add("init"); + args.add("-v"); if (_liferayProjectType.equals(LiferayProjectType.LIFERAY_MAVEN_WORKSPACE)) { - sb.append(_targetPlatform); + args.add(_targetPlatform); } else if (_liferayProjectType.equals(LiferayProjectType.LIFERAY_GRADLE_WORKSPACE)) { - sb.append(_productVersion); + args.add(_productVersion); } - sb.append(" "); - sb.append("-f "); + args.add("-f"); if (_liferayProjectType.equals(LiferayProjectType.LIFERAY_MAVEN_WORKSPACE)) { - sb.append("-b "); - sb.append("maven"); + args.add("-b"); + args.add("maven"); + } } PropertiesComponent component = PropertiesComponent.getInstance(project); component.setValue(WorkspaceConstants.WIZARD_LIFERAY_VERSION_FIELD, _liferayProductGroupVersion); - BladeCLI.executeWithLatestBlade(sb.toString()); + BladeCLI.executeWithLatestBlade(args); if (_liferayProjectType.equals(LiferayProjectType.LIFERAY_GRADLE_WORKSPACE)) { try { diff --git a/src/main/java/com/liferay/ide/idea/ui/modules/ext/LiferayModuleExtBuilder.java b/src/main/java/com/liferay/ide/idea/ui/modules/ext/LiferayModuleExtBuilder.java index be99c621..44bba6b7 100644 --- a/src/main/java/com/liferay/ide/idea/ui/modules/ext/LiferayModuleExtBuilder.java +++ b/src/main/java/com/liferay/ide/idea/ui/modules/ext/LiferayModuleExtBuilder.java @@ -163,29 +163,26 @@ private VirtualFile _createAndGetContentEntry() { private void _createProject(VirtualFile projectRoot, Project project) { VirtualFile virtualFile = projectRoot.getParent(); - StringBuilder sb = new StringBuilder(); - - sb.append("create -d \""); - sb.append(virtualFile.getPath()); - sb.append("\" "); - sb.append("--base \""); - sb.append(project.getBasePath()); - sb.append("\" -t "); - sb.append("modules-ext "); - sb.append("-m "); - sb.append(_originalModuleName); + + List args = new ArrayList<>(); + + args.add("create -d"); + args.add(BladeCLI.quote(virtualFile.getPath())); + args.add("--base"); + args.add(BladeCLI.quote(project.getBasePath())); + args.add("-t"); + args.add("modules-ext"); + args.add("-m"); + args.add(_originalModuleName); if (Objects.nonNull(project) && !LiferayWorkspaceSupport.isFlexibleLiferayWorkspace(project)) { - sb.append(" -M "); - sb.append(_originalModuleVersion); + args.add("-M"); + args.add(_originalModuleVersion); } - sb.append(" "); - sb.append("\""); - sb.append(projectRoot.getName()); - sb.append("\""); + args.add(BladeCLI.quote(projectRoot.getName())); - BladeCLI.execute(project, sb.toString()); + BladeCLI.execute(project, args); } private void _refreshProject(Project project) { diff --git a/src/main/java/com/liferay/ide/idea/ui/modules/springmvcportlet/SpringMVCPortletModuleBuilder.java b/src/main/java/com/liferay/ide/idea/ui/modules/springmvcportlet/SpringMVCPortletModuleBuilder.java index af3c2321..7521793b 100644 --- a/src/main/java/com/liferay/ide/idea/ui/modules/springmvcportlet/SpringMVCPortletModuleBuilder.java +++ b/src/main/java/com/liferay/ide/idea/ui/modules/springmvcportlet/SpringMVCPortletModuleBuilder.java @@ -187,55 +187,46 @@ private VirtualFile _createAndGetContentEntry() { private void _createProject(VirtualFile projectRoot, Project project, String typeId) { VirtualFile virtualFile = projectRoot.getParent(); - StringBuilder sb = new StringBuilder(); - sb.append("create -d \""); - sb.append(virtualFile.getPath()); - sb.append("\""); - sb.append(" "); + List args = new ArrayList<>(); + + args.add("create -d"); + args.add(BladeCLI.quote(virtualFile.getPath())); if (Objects.equals(typeId, LiferayProjectType.LIFERAY_MAVEN_WORKSPACE)) { - sb.append("-b "); - sb.append("maven "); + args.add("-b"); + args.add("maven"); String targetPlatformVersion = LiferayWorkspaceSupport.getTargetPlatformVersion(project); if (targetPlatformVersion != null) { - sb.append("-v "); - sb.append(targetPlatformVersion); - sb.append(" "); + args.add("-v"); + args.add(targetPlatformVersion); } } else { - sb.append("-v "); - sb.append(_liferayProductGroupVersion); - sb.append(" "); + args.add("-v"); + args.add(_liferayProductGroupVersion); } - sb.append("--base \""); - sb.append(project.getBasePath()); - sb.append("\" -t "); - sb.append("spring-mvc-portlet "); - sb.append("\""); - sb.append(projectRoot.getName()); - sb.append("\""); - sb.append(" "); - sb.append("--framework "); - sb.append(_framework); - sb.append(" "); - sb.append("--framework-dependencies "); - sb.append(_frameworkDependencies); - sb.append(" "); - sb.append("--view-type "); - sb.append(_viewType); + args.add("--base"); + args.add(BladeCLI.quote(project.getBasePath())); + args.add("-t"); + args.add("spring-mvc-portlet"); + args.add(BladeCLI.quote(projectRoot.getName())); + args.add("--framework"); + args.add(_framework); + args.add("--framework-dependencies"); + args.add(_frameworkDependencies); + args.add("--view-type"); + args.add(_viewType); if (!CoreUtil.isNullOrEmpty(_packageName)) { - sb.append(" "); - sb.append("-p "); - sb.append(_packageName); + args.add("-p"); + args.add(_packageName); } - BladeCLI.execute(project, sb.toString()); + BladeCLI.execute(project, args); } private void _refreshProject(Project project) { From af5c4878db6a2eaf04b9332c228fcd37d1b13988 Mon Sep 17 00:00:00 2001 From: drewbrokke Date: Thu, 11 Jul 2024 14:14:36 -0500 Subject: [PATCH 4/4] INTELLIJ-288 includes the product in Blade invocations --- .../ide/idea/ui/modules/LiferayModuleBuilder.java | 8 ++++++++ .../idea/ui/modules/LiferayWorkspaceBuilder.java | 10 +++++++--- .../SpringMVCPortletModuleBuilder.java | 14 ++++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/liferay/ide/idea/ui/modules/LiferayModuleBuilder.java b/src/main/java/com/liferay/ide/idea/ui/modules/LiferayModuleBuilder.java index 7fb48826..a3c06c81 100755 --- a/src/main/java/com/liferay/ide/idea/ui/modules/LiferayModuleBuilder.java +++ b/src/main/java/com/liferay/ide/idea/ui/modules/LiferayModuleBuilder.java @@ -31,6 +31,7 @@ import com.liferay.ide.idea.util.CoreUtil; import com.liferay.ide.idea.util.IntellijUtil; import com.liferay.ide.idea.util.LiferayWorkspaceSupport; +import com.liferay.release.util.ReleaseEntry; import java.io.File; @@ -200,6 +201,13 @@ public void setupRootModel(@NotNull ModifiableRootModel modifiableRootModel) { args.add(targetPlatformVersion); } + ReleaseEntry releaseEntry = LiferayWorkspaceSupport.getReleaseEntry("portal", targetPlatformVersion); + + if (releaseEntry != null) { + args.add("--liferay-product"); + args.add(releaseEntry.getProduct()); + } + args.add("-t"); args.add(_type); diff --git a/src/main/java/com/liferay/ide/idea/ui/modules/LiferayWorkspaceBuilder.java b/src/main/java/com/liferay/ide/idea/ui/modules/LiferayWorkspaceBuilder.java index 75cf2cf1..c87f74e6 100644 --- a/src/main/java/com/liferay/ide/idea/ui/modules/LiferayWorkspaceBuilder.java +++ b/src/main/java/com/liferay/ide/idea/ui/modules/LiferayWorkspaceBuilder.java @@ -195,13 +195,19 @@ else if (_liferayProjectType.equals(LiferayProjectType.LIFERAY_GRADLE_WORKSPACE) args.add(_productVersion); } + ReleaseEntry releaseEntry = LiferayWorkspaceSupport.getReleaseEntry("portal", _targetPlatform); + + if (releaseEntry != null) { + args.add("--liferay-product"); + args.add(releaseEntry.getProduct()); + } + args.add("-f"); if (_liferayProjectType.equals(LiferayProjectType.LIFERAY_MAVEN_WORKSPACE)) { args.add("-b"); args.add("maven"); } - } PropertiesComponent component = PropertiesComponent.getInstance(project); @@ -235,8 +241,6 @@ else if (_liferayProjectType.equals(LiferayProjectType.LIFERAY_MAVEN_WORKSPACE)) properties.setProperty(WorkspaceConstants.WORKSPACE_BOM_VERSION, _targetPlatform); - ReleaseEntry releaseEntry = LiferayWorkspaceSupport.getReleaseEntry("portal", _targetPlatform); - if (Objects.nonNull(releaseEntry)) { properties.setProperty(WorkspaceConstants.BUNDLE_URL_PROPERTY, releaseEntry.getBundleURL()); diff --git a/src/main/java/com/liferay/ide/idea/ui/modules/springmvcportlet/SpringMVCPortletModuleBuilder.java b/src/main/java/com/liferay/ide/idea/ui/modules/springmvcportlet/SpringMVCPortletModuleBuilder.java index 7521793b..03c4ddaa 100644 --- a/src/main/java/com/liferay/ide/idea/ui/modules/springmvcportlet/SpringMVCPortletModuleBuilder.java +++ b/src/main/java/com/liferay/ide/idea/ui/modules/springmvcportlet/SpringMVCPortletModuleBuilder.java @@ -32,6 +32,7 @@ import com.liferay.ide.idea.util.CoreUtil; import com.liferay.ide.idea.util.IntellijUtil; import com.liferay.ide.idea.util.LiferayWorkspaceSupport; +import com.liferay.release.util.ReleaseEntry; import java.io.File; @@ -193,12 +194,12 @@ private void _createProject(VirtualFile projectRoot, Project project, String typ args.add("create -d"); args.add(BladeCLI.quote(virtualFile.getPath())); + String targetPlatformVersion = LiferayWorkspaceSupport.getTargetPlatformVersion(project); + if (Objects.equals(typeId, LiferayProjectType.LIFERAY_MAVEN_WORKSPACE)) { args.add("-b"); args.add("maven"); - String targetPlatformVersion = LiferayWorkspaceSupport.getTargetPlatformVersion(project); - if (targetPlatformVersion != null) { args.add("-v"); args.add(targetPlatformVersion); @@ -209,6 +210,15 @@ private void _createProject(VirtualFile projectRoot, Project project, String typ args.add(_liferayProductGroupVersion); } + if (targetPlatformVersion != null) { + ReleaseEntry releaseEntry = LiferayWorkspaceSupport.getReleaseEntry("portal", targetPlatformVersion); + + if (releaseEntry != null) { + args.add("--liferay-product"); + args.add(releaseEntry.getProduct()); + } + } + args.add("--base"); args.add(BladeCLI.quote(project.getBasePath())); args.add("-t");